summaryrefslogtreecommitdiff
path: root/cad/src/dna/commands/MakeCrossovers/MakeCrossovers_Handle.py
blob: 9890cf72bc7660f830c6ec5682467dadc2ffbb48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""

@author: Ninad
@copyright: 2008 Nanorex, Inc.  See LICENSE file for details.
@version:$Id$

History:
2008-05-21 - 2008-06-01 Created and further refactored and modified
@See: ListWidgetItems_Command_Mixin,
      ListWidgetItems_GraphicsMode_Mixin
      ListWidgetItems_PM_Mixin,
      CrossoverSite_Marker
      MakeCrossovers_GraphicsMode


TODO  2008-06-01 :
- See class CrossoverSite_Marker for details
- more Documentation
"""

from exprs.If_expr import If_expr
from exprs.instance_helpers import DelegatingInstanceOrExpr
from exprs.Arrow           import Arrow
from exprs.ExprsConstants   import ORIGIN
from exprs.Highlightable    import Highlightable

from exprs.attr_decl_macros import Instance, Option, Arg
from exprs.ExprsConstants import Point
from utilities.constants import black, banana, copper, silver
from exprs.Set import Action
from exprs.__Symbols__ import _self
from exprs.attr_decl_macros import State
from exprs.__Symbols__ import Anything
from exprs.dna_ribbon_view import Cylinder
from exprs.ExprsConstants import Vector
from exprs.Overlay          import Overlay
from exprs.Exprs import call_Expr

class MakeCrossovers_Handle(DelegatingInstanceOrExpr):

    should_draw = State(bool, True)
    radius = 0.8

    point1 = Arg(Point)
    point2 = Arg(Point)

    scale = Arg(float)

    crossoverSite_marker =  Option(
        Action,
        doc = 'The CrossoverSite Marker class which instantiates this handle')

    #Command object specified as an 'Option' during instantiation of the class
    #see DnaSegment_EditCommand class definition.
    command =  Option(Action,
                      doc = 'The Command which instantiates this handle')



    crossoverPairs = Option(tuple, ())


    #Stateusbar text. Variable needs to be renamed in superclass.
    sbar_text = Option(str,
                       "Click on the handle to create this crossover",
                       doc = "Statusbar text on mouseover")


    delegate = If_expr(_self.should_draw,
                       Highlightable(
                           Overlay (
                               Cylinder((call_Expr(_self.crossoverPairs[0].posn),
                                         call_Expr(_self.crossoverPairs[3].posn)),
                                             radius = radius,
                                             color = silver),

                               Cylinder((call_Expr(_self.crossoverPairs[1].posn),
                                         call_Expr(_self.crossoverPairs[2].posn)),
                                             radius = radius,
                                             color = silver)),

                           Overlay (
                               Cylinder((call_Expr(_self.crossoverPairs[0].posn),
                                         call_Expr(_self.crossoverPairs[3].posn)),
                                             radius = radius,
                                             color = banana),

                               Cylinder((call_Expr(_self.crossoverPairs[1].posn),
                                         call_Expr(_self.crossoverPairs[2].posn)),
                                             radius = radius,
                                             color = banana)),

                           on_press = _self.on_press,
                           on_release = _self.on_release,
                           sbar_text = sbar_text
                           ))

    ##delegate = If_expr(_self.should_draw,
                       ##Highlightable(Cylinder((point1, point2),
                                              ##radius = radius,
                                              ##color = silver),
                                     ##Cylinder((point1, point2),
                                              ##radius = radius,
                                              ##color = banana),
                                     ##on_press = _self.on_press,
                                     ##on_release = _self.on_release))


    ##delegate = \
        ##If_expr(
            ##_self.should_draw,
            ##Highlightable(Arrow(
                ##color = silver,
                ##arrowBasePoint = point1,
                ####tailPoint = norm(vector)*1.0,
                ##tailPoint = point2,
                ##radius = radius,
                ##scale = scale),

                ##Arrow(
                ##color = banana,
                ##arrowBasePoint =  point1,
                ####tailPoint = norm(vector)*1.0,
                ##tailPoint =  point2,
                ##radius = radius,
                ##scale = scale),
                ##on_press = _self.on_press,
                ##on_release = _self.on_release ) ) #

    def hasValidParamsForDrawing(self):
        """
        Overridden in subclasses. Default implementation returns True
        if this object (the highlightable) can be drawn without any known
        issues
        @see: DnaStrand_ResizeHandle.hasValidParamsForDrawing for more notes.
        """
        ##self.should_draw = True
        return self.should_draw

    def on_press(self):
        pass

    def on_release(self):
        self.command.makeCrossover(self.crossoverPairs)
        self.crossoverSite_marker.removeHandle(self)