summaryrefslogtreecommitdiff
path: root/cad/src/commands/InsertGraphene/Graphene_EditCommand.py
blob: 654988ec721c2a60ee03bef436e9c750d0da3687 (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
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""
Graphene_EditCommand.py

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

History:
2008-07-22: Ported the old graphene generator to the Editcommand API

TODO:
- Needs cleanup after command sequencer refactoring. The graphene generator
was ported to EditCommand API to help the commandSequencer refactoring project.
"""


from utilities.Log  import greenmsg
from command_support.EditCommand import EditCommand
from commands.InsertGraphene.GrapheneGenerator import GrapheneGenerator
from utilities.constants import gensym
from commands.SelectChunks.SelectChunks_GraphicsMode import SelectChunks_GraphicsMode
from ne1_ui.toolbars.Ui_GrapheneFlyout import GrapheneFlyout
from commands.InsertGraphene.GrapheneGeneratorPropertyManager import GrapheneGeneratorPropertyManager

_superclass = EditCommand
class Graphene_EditCommand(EditCommand):

    GraphicsMode_class = SelectChunks_GraphicsMode

    #Property Manager
    PM_class = GrapheneGeneratorPropertyManager

    #Flyout Toolbar
    FlyoutToolbar_class = GrapheneFlyout

    cmd              =  greenmsg("Build Graphene: ")
    prefix           =  'Graphene'   # used for gensym
    cmdname          = 'Build Graphene'

    commandName      = 'BUILD_GRAPHENE'
    featurename      = "Build Graphene"
    from utilities.constants import CL_ENVIRONMENT_PROVIDING
    command_level = CL_ENVIRONMENT_PROVIDING # for now; later might be subcommand of Build Nanotube??

    create_name_from_prefix  =  True

    flyoutToolbar = None



    def _gatherParameters(self):
        """
        Return the parameters from the property manager.
        """
        return self.propMgr.getParameters()

    def runCommand(self):
        """
        Overrides EditCommand.runCommand
        """
        self.struct = None

    def _createStructure(self):
        """
        Build a graphene sheet from the parameters in the Property Manager.
        """

        # self.name needed for done message
        if self.create_name_from_prefix:
            # create a new name
            name = self.name = gensym(self.prefix, self.win.assy) # (in _build_struct)
            self._gensym_data_for_reusing_name = (self.prefix, name)
        else:
            # use externally created name
            self._gensym_data_for_reusing_name = None
                # (can't reuse name in this case -- not sure what prefix it was
                #  made with)
            name = self.name


        params = self._gatherParameters()

        #
        self.win.assy.part.ensure_toplevel_group()

        structGenerator = GrapheneGenerator()

        struct = structGenerator.make(self.win.assy,
                                      name,
                                      params,
                                      editCommand = self)


        self.win.assy.part.topnode.addmember(struct)
        self.win.win_update()
        return struct


    def _modifyStructure(self, params):
        """
        Modify the structure based on the parameters specified.
        Overrides EditCommand._modifystructure. This method removes the old
        structure and creates a new one using self._createStructure.
        See more comments in this method.
        """

        #@NOTE: Unlike editcommands such as Plane_EditCommand or
        #DnaSegment_EditCommand this  actually removes the structure and
        #creates a new one when its modified.
        #TODO: Change this implementation to make it similar to whats done
        #iin DnaSegment resize. (see DnaSegment_EditCommand)
        self._removeStructure()

        self.previousParams = params

        self.struct = self._createStructure()


    def _getStructureType(self):
        """
        Subclasses override this method to define their own structure type.
        Returns the type of the structure this editCommand supports.
        This is used in isinstance test.
        @see: EditCommand._getStructureType() (overridden here)
        """
        return self.win.assy.Chunk