summaryrefslogtreecommitdiff
path: root/cad/src/dna/temporary_commands/DnaLineMode.py
blob: f9b1fea6c3f192ae0a3b5c374aa3e5e202dcdcb8 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Copyright 2007-2009 Nanorex, Inc.  See LICENSE file for details.
"""
@author:    Ninad
@copyright: 2007-2009 Nanorex, Inc.  See LICENSE file for details.
@version:   $Id$
@license:   GPL

TODO:
- User Preferences for different rubberband line display styles
"""

from utilities.constants import black, white

from utilities.prefs_constants import dnaDefaultStrand1Color_prefs_key
from utilities.prefs_constants import dnaDefaultStrand2Color_prefs_key

import foundation.env as env

from graphics.drawing.drawDnaLadder import drawDnaLadder
from graphics.drawing.drawDnaRibbons import drawDnaRibbons

from temporary_commands.LineMode.Line_Command import Line_Command
from temporary_commands.LineMode.Line_GraphicsMode import Line_GraphicsMode


# == GraphicsMode part

_superclass_for_GM = Line_GraphicsMode

class DnaLine_GM( Line_GraphicsMode ):
    """
    Custom GraphicsMode for use as a component of DnaLineMode.
    @see: L{DnaLineMode} for more comments.
    @see: InsertDna_EditCommand where this is used as a GraphicsMode class.
          The default command part in this file is a Default class
          implementation  of self.command (see class DnaLineMode)
    """
    # The following valuse are used in drawing the 'sphere' that represent the
    #first endpoint of the line. See Line_GraphicsMode.Draw_other for details.
    endPoint1_sphereColor = white
    endPoint1_sphereOpacity = 1.0

    text = ''

    def __init__(self, command):
        """
        """
        _superclass_for_GM.__init__(self, command)


    def leftUp(self, event):
        """
        Left up method
        """
        if self.isSpecifyPlaneToolActive():
            _superclass_for_GM.leftUp(self, event)
            return

        if  self.command.mouseClickLimit is None:
            if len(self.command.mouseClickPoints) == 2:
                self.endPoint2 = None
                self.command.createStructure()
                self.glpane.gl_update()

            return

    def snapLineEndPoint(self):
        """
        Snap the line to the specified constraints.
        To be refactored and expanded.
        @return: The new endPoint2 i.e. the moving endpoint of the rubberband
                 line . This value may be same as previous or snapped so that it
                 lies on a specified vector (if one exists)
        @rtype: B{A}
        """

        if self.command.callbackForSnapEnabled() == 1:
            endPoint2  = _superclass_for_GM.snapLineEndPoint(self)
        else:
            endPoint2 = self.endPoint2

        return endPoint2

    def Draw_other(self):
        """
        Draw the DNA rubberband line (a ladder representation)
        """
        #The rubberband line display needs to be a user preference.
        #Example: There could be 3 radio buttons in the duplex PM that allows
        #you to draw the rubberband line as a simple line, a line with points
        #that indicate duplexrise, a dna ladder with arrow heads. Drawing it as
        #a ladder with arrow heads for the beams is the current implementation
        # -Ninad 2007-10-30

        #@see: Line_GraphicsMode class definition about this flag. Basically we suppress
        #cursor text drawing in the superclass and draw later in this method
        #after everyting is drawn.
        # [update, bruce 090310. This could use refactoring. Not urgent.]
        self._ok_to_render_cursor_text = False
        _superclass_for_GM.Draw_other(self)
        self._ok_to_render_cursor_text = True

        #This fixes NFR bug  2803
        #Don't draw the Dna rubberband line if the cursor is over the confirmation
        #corner. But make sure to call superclass.Draw_other method before doing this
        #check because we need to draw the rest of the model in the graphics
        #mode!. @see: Line_GraphicsMode.Draw_other
        # [update, bruce 090310: that superclass call no longer draws the model,
        #  but might still be needed for other reasons. Also, how this is implemented
        #  is questionable; see longer review comment in the superclass.]
        handler = self.o.mouse_event_handler
        if handler is not None and handler is self._ccinstance:
            return

        if self.endPoint2 is not None and \
           self.endPoint1 is not None:

            #Draw the ladder.
            #Convention:
            # The red band(beam) of the
            # ladder is always the 'leading edge' of the ladder. i.e. the red
            # band arrow head is always at the moving end of the mouse
            #(endpoint2).

            # A General Note/ FYI to keep in mind:
            # Consider a double stranded DNA and focus on the 'twin peaks'
            #(say, two consecutive helices in the middle of the dna duplex)
            # From the "mountain" with twin peaks that is the minor groove,
            # the DNA flows downhill 5' to 3'
            # Or in other words,
            # - For the 'mountain peak' on the right ,
            #    the 5' to 3' flows downhill, from left to right.
            # - For the 'mountain peak' on the left,
            #   the 3' to 5' flows downhill, from right to left
            #
            # Thus, the red beam of the ladder, can either become the
            # 'left mountain' or the 'right mountain' depending on the
            # orientation while drawing the ladder

            if self.command.callback_rubberbandLineDisplay() == 'Ladder':
                # Note: there needs to be a radio button to switch on the
                # rubberband ladder display for a dna line. At the moment it is
                # disabled and is superseded by the ribbons ruberband display.

                drawDnaLadder(self.endPoint1,
                              self.endPoint2,
                              self.command.duplexRise,
                              self.glpane.scale,
                              self.glpane.lineOfSight,
                              beamThickness = 4.0,
                              beam1Color = env.prefs[dnaDefaultStrand1Color_prefs_key],
                              beam2Color = env.prefs[dnaDefaultStrand2Color_prefs_key],
                              )
            elif self.command.callback_rubberbandLineDisplay() ==  'Ribbons':
                #Default dna rubberband line display style
                drawDnaRibbons(self.glpane,
                               self.endPoint1,
                               self.endPoint2,
                               self.command.basesPerTurn,
                               self.command.duplexRise,
                               self.glpane.scale,
                               self.glpane.lineOfSight,
                               self.glpane.displayMode,
                               ribbonThickness = 4.0,
                               ribbon1Color = env.prefs[dnaDefaultStrand1Color_prefs_key],
                               ribbon2Color = env.prefs[dnaDefaultStrand2Color_prefs_key],
                               )
            else:
                pass

            self._drawCursorText()
            pass
        return

    pass # end of class DnaLine_GM

# == Command part

class DnaLineMode(Line_Command): # not used as of 080111, see docstring
    """
    [no longer used as of 080111, see details below]
    Encapsulates the Line_Command functionality.
    @see: L{Line_Command}
    @see: InsertDna_EditCommand.getCursorText

    NOTE: [2008-01-11]
    The default DnaLineMode (command) part is not used as of 2008-01-11
    Instead, the interested commands use its GraphicsMode class.
    However, it's still possible to use and implement the default command
    part. (The old implementation of generating Dna using endpoints of a
    line used this default command class (DnaLineMode). so the method in this
    class  such as self.createStructure does nothing .
    @see: InsertDna_EditCommand where the GraphicsMode class of this command is
          used
    """

    # class constants
    commandName = 'DNA_LINE_MODE'
    featurename = "DNA Line Mode"
        # (This featurename is sometimes user-visible,
        #  but is probably not useful. See comments in Line_Command
        #  for more info and how to fix. [bruce 071227])
    from utilities.constants import CL_UNUSED
    command_level = CL_UNUSED

    GraphicsMode_class = DnaLine_GM

    def setParams(self, params):
        assert len(params) == 5
        self.mouseClickLimit, \
            self.duplexRise, \
            self.callbackMethodForCursorTextString, \
            self.callbackForSnapEnabled, \
            self.callback_rubberbandLineDisplay = params

    def createStructure(self):
        """
        Does nothing.
        @see: DnaLineMode_GM.leftUp
        @see: comment at the beginning of the class

        """
        pass

    pass

# end