summaryrefslogtreecommitdiff
path: root/cad/src/ne1_ui/toolbars/Ui_BuildAtomsFlyout.py
blob: 8c6efe12be55d0e1b1976a97c74a336c2916d0a3 (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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""

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

History:
- 2008-07-29 created. Moved related code from BuildAtoms_Command to this new class
NOTE THAT THIS CLASS IS NOT YET USED ANYWHERE. As of 2008-07-29,
BuildAtoms_Command continues to use its own methods to update the flyout toolbar
Eventually this class will be used to do that part.


TODO:

- This may be revised heavily during the command toolbar cleanup project.
The current class refactors the related code from class BuildAtoms_Command

@Note: The class name is BuildAtomsFlyout -- this provides the flyout toolbar
for class BuildAtoms_Command

"""
from ne1_ui.NE1_QWidgetAction import NE1_QWidgetAction
from PyQt4.Qt import SIGNAL
from PyQt4.Qt import QAction
from PyQt4.Qt import QActionGroup


from utilities.icon_utilities import geticon

from ne1_ui.toolbars.Ui_AbstractFlyout import Ui_AbstractFlyout
from utilities.debug import print_compact_stack

_superclass = Ui_AbstractFlyout

class BuildAtomsFlyout(Ui_AbstractFlyout):

    def _action_in_controlArea_to_show_this_flyout(self):
        """
        Required action in the 'Control Area' as a reference for this
        flyout toolbar. See superclass method for documentation and todo note.
        """
        return self.win.toolsDepositAtomAction


    def _getExitActionText(self):
        """
        Overrides superclass method.
        @see: self._createActions()
        """
        return "Exit Atoms"


    def getFlyoutActionList(self):
        """
        Returns a tuple that contains mode spcific actionlists in the
        added in the flyout toolbar of the mode.
        CommandToolbar._createFlyoutToolBar method calls this
        @return: params: A tuple that contains 3 lists:
        (subControlAreaActionList, commandActionLists, allActionsList)
        """

        #ninad070330 This implementation may change in future.

        #'allActionsList' returns all actions in the flyout toolbar
        #including the subcontrolArea actions.
        allActionsList = []
        #Action List for  subcontrol Area buttons.
        #For now this list is just used to set a different palette to thisaction
        #buttons in the toolbar
        subControlAreaActionList =[]


        #Append subcontrol area actions to  subControlAreaActionList
        #The 'Exit button' althought in the subcontrol area, would
        #look as if its in the Control area because of the different color
        #palette
        #and the separator after it. This is intentional.
        subControlAreaActionList.append(self.exitModeAction)
        separator1 = QAction(self.win)
        separator1.setSeparator(True)
        subControlAreaActionList.append(separator1)

        subControlAreaActionList.append(self.atomsToolAction)
        subControlAreaActionList.append(self.bondsToolAction)
        separator = QAction(self.win)
        separator.setSeparator(True)
        subControlAreaActionList.append(separator)

        #Also add the subcontrol Area actions to the 'allActionsList'
        for a in subControlAreaActionList:
            allActionsList.append(a)
        ##actionlist.append(self.win.modifyAdjustSelAction)
        ##actionlist.append(self.win.modifyAdjustAllAction)

        #Ninad 070330:
        #Command Actions : These are the actual actions that will respond the
        #a button pressed in the 'subControlArea (if present).
        #Each Subcontrol area button can have its own 'command list'
        #The subcontrol area buuton and its command list form a 'key:value pair
        #in a python dictionary object
        #In Build mode, as of 070330 we have 3 subcontrol area buttons
        #(or 'actions)'
        commandActionLists = []

        #Append empty 'lists' in 'commandActionLists equal to the
        #number of actions in subControlArea
        for i in range(len(subControlAreaActionList)):
            lst = []
            commandActionLists.append(lst)

        #Command list for the subcontrol area button 'Atoms Tool'
        #For others, this list will remain empty for now -- ninad070330
        depositAtomsCmdLst = []
        depositAtomsCmdLst.append(self.win.modifyHydrogenateAction)
        depositAtomsCmdLst.append(self.win.modifyDehydrogenateAction)
        depositAtomsCmdLst.append(self.win.modifyPassivateAction)
        separatorAfterPassivate = QAction(self.win)
        separatorAfterPassivate.setSeparator(True)
        depositAtomsCmdLst.append(separatorAfterPassivate)
        depositAtomsCmdLst.append(self.transmuteAtomsAction)
        separatorAfterTransmute = QAction(self.win)
        separatorAfterTransmute.setSeparator(True)
        depositAtomsCmdLst.append(separatorAfterTransmute)
        depositAtomsCmdLst.append(self.win.modifyDeleteBondsAction)
        depositAtomsCmdLst.append(self.win.modifySeparateAction)
        depositAtomsCmdLst.append(self.win.makeChunkFromSelectedAtomsAction)

        commandActionLists[2].extend(depositAtomsCmdLst)

        ##for action in self.win.buildToolsMenu.actions():
            ##commandActionLists[2].append(action)

        # Command list for the subcontrol area button 'Bonds Tool'
        # For others, this list will remain empty for now -- ninad070405
        bondsToolCmdLst = []
        bondsToolCmdLst.append(self.bond1Action)
        bondsToolCmdLst.append(self.bond2Action)
        bondsToolCmdLst.append(self.bond3Action)
        bondsToolCmdLst.append(self.bondaAction)
        bondsToolCmdLst.append(self.bondgAction)
        bondsToolCmdLst.append(self.cutBondsAction)
        commandActionLists[3].extend(bondsToolCmdLst)

        params = (subControlAreaActionList, commandActionLists, allActionsList)

        return params


    def _createActions(self, parentWidget):
        """
        Define flyout toolbar actions for this mode.
        """
        #@NOTE: In Build mode, some of the actions defined in this method are also
        #used in Build Atoms PM. (e.g. bond actions) So probably better to rename
        #it as _init_modeActions. Not doing that change in mmkit code cleanup
        #commit(other modes still implement a method by same name)-ninad20070717

        _superclass._createActions(self, parentWidget)

        # The subControlActionGroup is the parent of all flyout QActions.
        self.subControlActionGroup = QActionGroup(parentWidget)
            # Shouldn't the parent be self.win?
            # Isn't parentWidget = BuildAtomsPropertyManager.
            # Ask Bruce about this. --Mark 2008-12-07.

        self.subControlActionGroup.setExclusive(True)

        #Following Actions are added in the Flyout toolbar.
        #Defining them outside that method as those are being used
        #by the subclasses of deposit mode (testmode.py as of 070410) -- ninad

        self.atomsToolAction = \
            NE1_QWidgetAction(self.subControlActionGroup, win = self.win)
        self.atomsToolAction.setText("Atoms Tool")
        self.atomsToolAction.setIcon(geticon(
            "ui/actions/Command Toolbar/BuildAtoms/AtomsTool.png"))
        self.atomsToolAction.setCheckable(True)
        self.atomsToolAction.setChecked(True)
        self.atomsToolAction.setObjectName('ACTION_ATOMS_TOOL')


        self.bondsToolAction = \
            NE1_QWidgetAction(self.subControlActionGroup, win = self.win)
        self.bondsToolAction.setText("Bonds Tool")
        self.bondsToolAction.setIcon(geticon(
            "ui/actions/Command Toolbar/BuildAtoms/BondsTool.png"))
        self.bondsToolAction.setCheckable(True)
        self.bondsToolAction.setObjectName('ACTION_BOND_TOOL')


        self.subControlActionGroup.addAction(self.atomsToolAction)
        self.subControlActionGroup.addAction(self.bondsToolAction)

        self.transmuteAtomsAction = \
            NE1_QWidgetAction(self.subControlActionGroup, win = self.win)
        self.transmuteAtomsAction.setText("Transmute Atoms")
        self.transmuteAtomsAction.setIcon(geticon(
            "ui/actions/Command Toolbar/BuildAtoms/TransmuteAtoms.png"))
        self.transmuteAtomsAction.setCheckable(False)


        self._createBondToolActions(parentWidget)

    def _createBondToolActions(self, parentWidget):
        """
        Create the actions to be included in flyout toolbar , when the 'bonds
        tool' is active. Note that the object names of these action will be
        be used to find the Bond Tool type to which each action corresponds to.

        @see: self._createActions() where this is called.
        """
        self.bondToolsActionGroup = QActionGroup(parentWidget)
        self.bondToolsActionGroup.setExclusive(True)

        self.bond1Action = \
            NE1_QWidgetAction(self.bondToolsActionGroup, win = self.win)
        self.bond1Action.setText("Single")
        self.bond1Action.setIcon(geticon("ui/actions/Command Toolbar/BuildAtoms/SingleBond.png"))
        self.bond1Action.setObjectName('ACTION_SINGLE_BOND_TOOL')

        self.bond2Action = \
            NE1_QWidgetAction(self.bondToolsActionGroup, win = self.win)
        self.bond2Action.setText("Double")
        self.bond2Action.setIcon(geticon("ui/actions/Command Toolbar/BuildAtoms/DoubleBond.png"))
        self.bond2Action.setObjectName('ACTION_DOUBLE_BOND_TOOL')

        self.bond3Action = \
            NE1_QWidgetAction(self.bondToolsActionGroup, win = self.win)
        self.bond3Action.setText("Triple")
        self.bond3Action.setIcon(geticon("ui/actions/Command Toolbar/BuildAtoms/TripleBond.png"))
        self.bond3Action.setObjectName('ACTION_TRIPLE_BOND_TOOL')

        self.bondaAction = \
            NE1_QWidgetAction(self.bondToolsActionGroup, win = self.win)
        self.bondaAction.setText("Aromatic")
        self.bondaAction.setIcon(geticon("ui/actions/Command Toolbar/BuildAtoms/AromaticBond.png"))
        self.bondaAction.setObjectName('ACTION_AROMATIC_BOND_TOOL')

        self.bondgAction = \
            NE1_QWidgetAction(self.bondToolsActionGroup, win = self.win)
        self.bondgAction.setText("Graphitic")
        self.bondgAction.setIcon(geticon("ui/actions/Command Toolbar/BuildAtoms/GraphiticBond.png"))
        self.bondgAction.setObjectName('ACTION_GRAPHITIC_BOND_TOOL')

        self.cutBondsAction = \
            NE1_QWidgetAction(self.bondToolsActionGroup, win = self.win)
        self.cutBondsAction.setText("Cut Bonds")
        self.cutBondsAction.setIcon(geticon("ui/actions/Command Toolbar/BuildAtoms/CutBonds.png"))
        self.cutBondsAction.setObjectName('ACTION_DELETE_BOND_TOOL')

        for action in [self.bond1Action,
                       self.bond2Action,
                       self.bond3Action,
                       self.bondaAction,
                       self.bondgAction,
                       self.cutBondsAction
                       ]:
            self.bondToolsActionGroup.addAction(action)
            action.setCheckable(True)

        return

    def _addWhatsThisText(self):
        """
        Add 'What's This' help text for all actions on toolbar.
        """
        from ne1_ui.WhatsThisText_for_CommandToolbars import whatsThisTextForAtomsCommandToolbar
        whatsThisTextForAtomsCommandToolbar(self)
        return

    def _addToolTipText(self):
        """
        Add 'Tool tip' help text for all actions on toolbar.
        """
        from ne1_ui.ToolTipText_for_CommandToolbars import toolTipTextForAtomsCommandToolbar
        toolTipTextForAtomsCommandToolbar(self)
        return


    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        This can be overridden in subclasses. By default it does nothing.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean

        @see: self.activateFlyoutToolbar, self.deActivateFlyoutToolbar
        """
        if isConnect:
            change_connect = self.win.connect
        else:
            change_connect = self.win.disconnect

        #Ui_AbstractFlyout connects the self.exitmodeAction, so call it first.
        _superclass.connect_or_disconnect_signals(self, isConnect)

        #Atom , Bond Tools Groupbox
        change_connect(self.bondToolsActionGroup,
                       SIGNAL("triggered(QAction *)"),
                       self.command.changeBondTool)

        change_connect(self.transmuteAtomsAction,
                        SIGNAL("triggered()"),self.command.transmutePressed)

        change_connect(self.subControlActionGroup,
                       SIGNAL("triggered(QAction *)"),
                       self.updateCommandToolbar)

        change_connect(self.bondsToolAction,
                       SIGNAL("triggered()"),
                       self._activateBondsTool)

        change_connect(self.atomsToolAction,
                       SIGNAL("triggered()"),
                       self._activateAtomsTool)


    def get_cursor_id_for_active_tool(self):
        """
        Provides a cursor id (int) for updating cursor in graphics mode,
        based on the checked action in its flyout toolbar. (i.e. based on the
        active tool)
        @see: BuildAtoms_GraphicsMode.update_cursor_for_no_MB_selection_filter_disabled
        """
        if self.atomsToolAction.isChecked():
            cursor_id = 0
        elif self.bond1Action.isChecked():
            cursor_id = 1
        elif self.bond2Action.isChecked():
            cursor_id = 2
        elif self.bond3Action.isChecked():
            cursor_id = 3
        elif self.bondaAction.isChecked():
            cursor_id = 4
        elif self.bondgAction.isChecked():
            cursor_id = 5
        elif self.cutBondsAction.isChecked():
            cursor_id = 6
        else:
            cursor_id = 0

        return cursor_id


    def _activateAtomsTool(self):
        """
        Activate the atoms tool of the Build Atoms mode
        hide only the Atoms Tools groupbox in the Build Atoms Property manager
        and show all others the others.
        """
        self.command.activateAtomsTool()


    def _activateBondsTool(self):
        """
        Activate the bond tool of the Build Atoms mode
        Show only the Bond Tools groupbox in the Build Atoms Property manager
        and hide the others.
        @see:self._convert_bonds_bet_selected_atoms()
        """
        self.command.activateBondsTool()


    def getBondToolActions(self):
        return self.bondToolsActionGroup.actions()

    def getCheckedBondToolAction(self):
        return self.bondToolsActionGroup.checkedAction()

    def resetStateOfActions(self):
        """
        Default implementation does nothing. Overridden in subclasses.

        R Resets the state of actions in the flyout toolbar.
        Generally, it unchecks all the actions except the ExitModeAction.
        This is called while resuming a command.


        Example: if exits is in Insert > Dna command,
        the Build > Dna command is resumed. When this happens, program needs to
        make sure that the Insert > dna button in the flyout is unchecked.
        It is done by using this method.

        @see: self.deActivateFlyoutToolbar()
        @see: self.activateBreakStrands_Command()

        @see: baseCommand.command_update_flyout() which calls this method.
        @see: BuildAtoms_Command.command_update_state()
        @see: BuildAtoms_Command.activateAtomsTool()
        """
        self.atomsToolAction.setChecked(True)
        ##self.bondsToolAction.setChecked(False)
        for action in self.bondToolsActionGroup.actions():
            action.setChecked(False)