summaryrefslogtreecommitdiff
path: root/cad/src/graphics/drawables/RotationHandle.py
blob: 42e487e8e2785429fc7f25579862868aad71496c (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
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details. 
"""
@author:    Ninad
@copyright: 2008 Nanorex, Inc.  See LICENSE file for details.
@version:   $Id$
@license:   GPL

TODO: 
To be revised. This handle can't be dragged. (need modifications in 
DragBehavior_AlongCircle). Also the handle appearance 
needs to be changed. 

"""
from exprs.attr_decl_macros import Option
from exprs.attr_decl_macros import State
from exprs.Set              import Action
from exprs.__Symbols__      import _self

from exprs.Overlay          import Overlay
from exprs.ExprsConstants   import Drawable
from exprs.ExprsConstants   import Color
from exprs.ExprsConstants   import ORIGIN, DX , DY

from exprs.dna_ribbon_view  import Cylinder
from exprs.Rect             import Sphere
   
import foundation.env as env
from utilities.prefs_constants import hoverHighlightingColor_prefs_key
from utilities.prefs_constants import selectionColor_prefs_key
from utilities.constants import white, purple

from geometry.VQT import V
from exprs.DraggableHandle_AlongCircle import DraggableHandle_AlongCircle

#Use this flag to test some 'fancy handle drawings' (the default apaprearance is
#'sphere'
DEBUG_FANCY_HANDLES = True


class RotationHandle(DraggableHandle_AlongCircle):
    """
    Provides a resize handle for editing the length of an existing DnaSegment. 
    """
    #Handle color will be changed depending on whether the the handle is grabbed
    #So this is a 'State variable and its value is used in 'appearance' 
    #(given as an optional argument to 'Sphere')
    handleColor = State( Color, purple)
    
    if DEBUG_FANCY_HANDLES:           
    
        appearance = Overlay(
            Sphere(1.2, handleColor, center = ORIGIN + _self.axis*3*DX), 
            Cylinder((ORIGIN, ORIGIN + _self.axis*2*DX), 0.5 ,handleColor))
        
        HHColor = env.prefs[hoverHighlightingColor_prefs_key]
        appearance_highlighted = Option(
            Drawable,
            Overlay(
                Sphere(1.2, HHColor, center = ORIGIN + _self.axis*3*DX),
                Cylinder((ORIGIN,  ORIGIN + _self.axis*2*DX), 0.5 , HHColor)),
                doc = "handle appearance when highlighted")
    else:           
        
        #Appearance of the handle. (note that it uses all the code from exprs module
        # and needs more documentation there). 
        #See exprs.Rect.Sphere for definition of a drawable 'Sphere' object. 
        appearance1 = Option( Drawable,
                             Sphere(1.2, handleColor),
                             doc = "handle appearance when not highlighted")
    
        #Handle appearance when highlighted
        appearance_highlighted1 = Option( Drawable,
                                         Sphere(1.2, yellow),
                                         doc = "handle appearance when highlighted")
    
    #Stateusbar text. Variable needs to be renamed in superclass. 
    sbar_text = Option(str, 
                       "Drag the handle to rotate the segment around axis", 
                       doc = "Statusbar text on mouseover")
    
    #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')
    
  
    
    def on_press(self):  
        """
        Actions when handle is pressed (grabbed, during leftDown event)
        @see: B{SelectChunks.GraphicsMode.leftDown}
        @see: B{DnaSegment_EditCommand.grabbedHandle}
        @see: B{DnaSegment_GraphicsMode.Draw} (which uses some attributes of 
             the current grabbed handle of the command. 
        @see: B{DragHandle_API}
        """
        #Change the handle color when handle is grabbed. See declaration of 
        #self.handleColor in the class definition. 
        self.handleColor = env.prefs[selectionColor_prefs_key]
        
        #assign 'self' as the curent grabbed handle of the command. 
        self.command.grabbedHandle = self
    
    def on_drag(self):
        """
        Method called while dragging this handle .
        @see: B{DragHandle_API}
        """
        #Does nothing at the moment. 
        pass
    
    def on_release(self):
        """
        This method gets called during leftUp (when the handle is released)
        @see: B{DnaSegment_EditCommand.modifyStructure}
        @see: self.on_press
        @see: B{SelectChunks.GraphicsMode.leftUp}
        @see: B{DragHandle_API}
        """
        self.handleColor = purple
        if self.command:
            #Clear the grabbed handle attribute (the handle is no longer 
            #grabbed)
            self.command.grabbedHandle = None