summaryrefslogtreecommitdiff
path: root/cad/src/commands/Fuse/FusePropertyManager.py
blob: ba08e8c4ecd534b67f15cfe4da4866491ec71bb6 (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
# Copyright 2004-2007 Nanorex, Inc.  See LICENSE file for details.
"""
FusePropertyManager.py
@author: Ninad
@version: $Id$
@copyright:2004-2007 Nanorex, Inc.  All rights reserved.

History:
ninad070425 :1) Moved Fuse dashboard to Property manager
             2) Implemented Translate/ Rotate enhancements

ninad20070723: code cleanup to define a fusePropMgr object. This was a
prerequisite for 'command sequencer' and also needed to resolve potential
multiple inheritance issues.

TODO: ninad20070723--
See if the signals can be connected in the
fuseMde.connect_disconnect_signals OR better to call
propMgr.connect_disconnect_signals in the fuseMde.connect_disconnect_signals?
I think the latter will help decoupling ui elements from fuseMode. Same thing
applies to other modes and Propert Managers (e.g. Move mode, Build Atoms mode)
"""

from PyQt4.Qt import SIGNAL
from PyQt4.Qt import Qt

from PM.PM_GroupBox        import PM_GroupBox
from PM.PM_ComboBox        import PM_ComboBox
from PM.PM_PushButton      import PM_PushButton
from PM.PM_CheckBox        import PM_CheckBox
from PM.PM_Slider          import PM_Slider

from commands.Move.MovePropertyManager import MovePropertyManager

class FusePropertyManager(MovePropertyManager):

    # <title> - the title that appears in the property manager header.
    title = "Fuse Chunks"
    # <iconPath> - full path to PNG file that appears in the header.
    iconPath = "ui/actions/Tools/Build Tools/Fuse_Chunks.png"

    def __init__(self, command):
        """
        Constructor for Fuse Property manager.
        @param command: The parent mode for this property manager
        @type  command: L{fuseChunksmode}
        """

        self.command = command
        MovePropertyManager.__init__(self, self.command)

        self.activate_translateGroupBox_in_fuse_PM()

    def _addGroupBoxes(self):
        """
        Add various groupboxes to Fuse property manager.
        """

        self.fuseOptionsGroupBox = PM_GroupBox( self,
                                         title = "Fuse Options")
        self._loadFuseOptionsGroupBox(self.fuseOptionsGroupBox)

        MovePropertyManager._addGroupBoxes(self)

    def _loadFuseOptionsGroupBox(self, inPmGroupBox):
        """
        Load the widgets inside the Fuse Options groupbox.
        """

        #@ Warning: If you change fuseChoices, you must also change the
        #  constants MAKEBONDS and FUSEATOMS in FuseChunks_Command.py.
        #  This implementation is fragile and should be fixed. Mark 2008-07-16

        fuseChoices = ['Make bonds between chunks',
                       'Fuse overlapping atoms']

        self.fuseComboBox = \
            PM_ComboBox( inPmGroupBox,
                         label        = '',
                         choices      = fuseChoices,
                         index        = 0,
                         setAsDefault = False,
                         spanWidth    = True)

        self.connect(self.fuseComboBox,
                     SIGNAL("activated(const QString&)"),
                     self.command.change_fuse_mode)

        self.fusePushButton = PM_PushButton( inPmGroupBox,
                                             label     = "",
                                             text      = "Make Bonds",
                                             spanWidth = True )

        self.connect( self.fusePushButton,
                      SIGNAL("clicked()"),
                      self.command.fuse_something)

        self.toleranceSlider =  PM_Slider( inPmGroupBox,
                                           currentValue = 100,
                                           minimum      = 0,
                                           maximum      = 300,
                                           label        = \
                                           'Tolerance:100% => 0 bondable pairs'
                                         )
        self.connect(self.toleranceSlider,
                       SIGNAL("valueChanged(int)"),
                       self.command.tolerance_changed)

        self.mergeChunksCheckBox = PM_CheckBox( inPmGroupBox,
                                                text         = 'Merge chunks',
                                                widgetColumn = 0,
                                                state        = Qt.Checked )


    def activate_translateGroupBox_in_fuse_PM(self):
        """
        Show contents of translate groupbox, deactivae the rotate groupbox.
        Also check the action that was checked when this groupbox  was active
        last time. (if applicable). This method is called only when move
        groupbox button is clicked.
        @see: L{self.activate_translateGroupBox_in_fuse_PM}
        """

        self.command.switchGraphicsModeTo(newGraphicsMode = 'TRANSLATE_CHUNKS')

        self.toggle_translateGroupBox()
        self.deactivate_rotateGroupBox()

        buttonToCheck = self.getTranslateButtonToCheck()

        if buttonToCheck:
            buttonToCheck.setChecked(True)
        else:
            buttonToCheck = self.transFreeButton
            buttonToCheck.setChecked(True)

        self.changeMoveOption(buttonToCheck)

        self.isTranslateGroupBoxActive = True
        self.command.graphicsMode.update_cursor()

    def activate_rotateGroupBox_in_fuse_PM(self):
        """
        Show contents of rotate groupbox (in fuse PM), deactivae the
        translate groupbox.
        Also check the action that was checked when this groupbox  was active
        last time. (if applicable). This method is called only when rotate
        groupbox button is clicked.
        @see: L{activate_rotateGroupBox_in_fuse_PM}
        """
        self.command.switchGraphicsModeTo(newGraphicsMode = 'TRANSLATE_CHUNKS')

        self.toggle_rotateGroupBox()
        self.deactivate_translateGroupBox()

        buttonToCheck = self.getRotateButtonToCheck()

        if buttonToCheck:
            buttonToCheck.setChecked(True)
        else:
            buttonToCheck = self.rotateFreeButton
            buttonToCheck.setChecked(True)

        self.changeRotateOption(buttonToCheck)

        self.isTranslateGroupBoxActive = False
        self.command.graphicsMode.update_cursor()
        return

    def updateMessage(self, msg = ''):
        """
        Updates the message box with an informative message.

        @param msg: The message to display. If msg is an empty string,
                    a default message is displayed.
        @type  msg: string
        Overrides the MovePropertyManager.updateMessage method
        @see: MovePropertyManager.updateMessage
        """
        #@bug: BUG: The message box height is fixed. The verticle scrollbar
        # appears as the following message is long. It however tries to make the
        # cursor visible within the message box . This results in scrolling the
        # msg box to the last line and thus doesn't look good.-- ninad 20070723

        if msg:
            self.MessageGroupBox.insertHtmlMessage( msg, setAsDefault = True )
            return

        if self.fuseComboBox.currentIndex() == 0:
            #i.e. 'Make Bonds Between Chunks'
            msg = "To <b> make bonds</b> between two or more chunks, "\
            "drag the selected chunk(s) such that their one or more "\
            "bondpoints overlap with the other chunk(s). Then click the "\
            "<b> Make Bonds </b> button to create bond(s) between them. "
        else:
            msg = "To <b>fuse overlapping atoms</b> in two or more chunks, "\
            "drag the selected chunk(s) such that their one or more atoms "\
            "overlap  with the atoms in the other chunk(s). Then click the "\
            "<b> Fuse Atoms </b>\ button to remove the overlapping atoms of "\
            "unselected chunk. "

        self.MessageGroupBox.insertHtmlMessage( msg, setAsDefault = True )
        return