summaryrefslogtreecommitdiff
path: root/cad/src/cnt/commands/BuildNanotube/BuildNanotube_GraphicsMode.py
blob: 0a7b9b9a9ff9e256f92d17701389dce2550722c9 (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
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""
BuildNanotube_GraphicsMode.py

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

History:

TODO as of 2008-05-06:
Needs Refactoring. It was originally duplicated from BuildDna_GraphicsMode
(for an experimental implementation of new Nanotube command)
There needs to be a common superclass for Build'Structure' mode and
all the edit structure modes (commands) such as DnaSegment,
DnaStrand_GraphicsMode, EditNanotube_GraphicsMode etc
"""

from commands.SelectChunks.SelectChunks_GraphicsMode import SelectChunks_GraphicsMode
from cnt.model.NanotubeSegment import NanotubeSegment
from commands.Select.Select_GraphicsMode import DRAG_STICKINESS_LIMIT

DEBUG_CLICK_ON_OBJECT_ENTERS_ITS_EDIT_COMMAND = True

_superclass = SelectChunks_GraphicsMode
class BuildNanotube_GraphicsMode(SelectChunks_GraphicsMode):
    """
    Graphics mode for the Build Nanotube command.
    """

    def chunkLeftUp(self, aChunk, event):
        """
        Upon chunkLeftUp, it enters the nanotube edit command.
        This is an alternative implementation. As of 2008-03-03,
        we have decided to change this implementation. Keeping the
        related methods alive if, in future, we want to switch to this
        implementation and/or add a user preference to do this.
        """

        _superclass.chunkLeftUp(self, aChunk, event)

        if self.glpane.modkeys is not None:
            #Don't go further if some modkey is pressed. We will call the
            #edit method of the nanotube only if no modifier key is
            #pressed

            return

        if not self.mouse_within_stickiness_limit(event, DRAG_STICKINESS_LIMIT):
            return

        #@TODO: If the object under mouse was double clicked, don't enter the
        #edit mode, instead do appropriate operation such as expand selection or
        #contract selection (done in superclass)
        #Note: when the object is just single clicked, it becomes editable).

        if self.editObjectOnSingleClick():
            if aChunk.picked:
                segmentGroup = aChunk.parent_node_of_class(NanotubeSegment)
                if segmentGroup is not None:
                    segmentGroup.edit()
        return

    def editObjectOnSingleClick(self):
        """
        Subclasses can override this method. If this method returns True,
        when you left click on a DnaSegment or a DnaStrand, it becomes editable
        (i.e. program enters the edit command of that particular object if
        that object is editable)
        @see: MakeCrossover_GraphicsMode.editObjectOnSingleClick()
        """
        if DEBUG_CLICK_ON_OBJECT_ENTERS_ITS_EDIT_COMMAND:
            return True
        return False

    def _drawCursorText(self):
        """
        Draw the text near the cursor. It gives information about length of
        the nanotube.
        """
        if hasattr(self.command, 'grabbedHandle') and \
           hasattr(self.command, 'getCursorText'):
            if self.command.grabbedHandle is not None:
                #Draw the text next to the cursor that gives info about
                #nanotube length, etc.
                text , textColor = self.command.getCursorText()
                self.glpane.renderTextNearCursor(text,
                                                 offset = 30,
                                                 textColor = textColor)
                pass
            pass
        return

    pass