summaryrefslogtreecommitdiff
path: root/cad/src/command_support/modes.py
blob: 3338de9e4b1463f5d90e75ed6234a5e079219ee8 (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
# Copyright 2004-2008 Nanorex, Inc.  See LICENSE file for details.
"""
modes.py -- provides basicMode, the superclass for old modes
which haven't yet been split into subclasses of Command and GraphicsMode.

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

History:

(For earlier history see modes.py docstring before the split of 071009.)

bruce 050507 moved Hydrogenate and Dehydrogenate into another file

bruce 071009 moved modeMixin [now CommandSequencer] into its own file

bruce 071009 split modes.py into Command.py and GraphicsMode.py,
leaving only temporary compatibility mixins in modes.py.

TODO:

Sometime, separate public (API) and private methods within each of
Command.py and GraphicsMode.py (see their module docstrings for details).

Refactor the subclasses of basicMode, then get rid of it.
Same with the other classes in this file.

Notes on how we'll do that [later: some of this has been done]:

At some point soon we'll have one currentCommand attr in glpane,
later moved to a separate object, the command sequencer.
And glpane.mode will be deprecated, but glpane.graphicsMode will
refer to a derived object which the current command can return,
perhaps self (for old code) or not (for new code).
(The null object we store in there can then also be a joint or
separate object, independently from everything else. For now
it's still called nullMode (and it's created and stored by CommandSequencer)
but that will be revised.)

But that doesn't remove the fact that generators (maybe even when based
on EditCommand [update 071228 - this issue was recently fixed for EditCommand)
still sort of treat their PM as a guest in some mode and as the "current
command". So "make generators their own command" will be a refactoring we
need soon, perhaps before "split old modes into their Command and
GraphicsMode pieces". [update 071228 - Ninad was able to split them
before fixing this, and has then fixed this for EditCommand, though
not yet for GeneratorBaseClass.]

But when we "make generators their own command", what GM will they use?
We might have to split one out of the old modes for that purpose
even though it can't yet replace the ones it splits out of.
[update 071228 - they can probably use one of Select*_GraphicsMode
since those are all split now.]
"""

from command_support.Command import anyCommand, nullCommand, basicCommand

from command_support.GraphicsMode import nullGraphicsMode, basicGraphicsMode

from command_support.GraphicsMode_API import GraphicsMode_API

# ==

### TODO: fill these in, especially __init__ methods; remove the ones we don't need

class anyMode(anyCommand, GraphicsMode_API):
    # used only in this file (where it provides some default methods and attrs
    # to the classes here, but surely redundantly with their other
    # superclasses, so it's probably not needed),
    # and in old comments in other files.
    pass

class nullMode(nullCommand, nullGraphicsMode, anyMode):
    # used in CommandSequencer and test_commands
    # see discussion in this module's docstring

    # duplicated properties in nullMode and basicMode, except for debug prints:

    def __get_command(self):
        print "\n * * * nullMode.__get_command, should probably never happen\n"
            # happens?? never yet seen, should probably never happen
        return self

    command = property(__get_command)

    def __get_graphicsMode(self):
        # print "\n * * * nullMode.__get_graphicsMode, remove when seen often\n"
            # should happen often, did happen at least once;
            # happens a few times when you enter Extrude
        return self

    graphicsMode = property(__get_graphicsMode)
    pass

class basicMode(basicCommand, basicGraphicsMode, anyMode):
    """
    Compatibility mixture of Command and GraphicsMode
    for old code which uses one object for both.
    """
    def __init__(self, commandSequencer):
        glpane = commandSequencer.assy.glpane #bruce 080813 revised this

        basicCommand.__init__(self, commandSequencer)

        basicGraphicsMode.__init__(self, glpane)
            # no need to pass self as command, due to property below

        return

    # duplicated properties in nullMode and basicMode, except for debug prints:

    def __get_command(self):
        ## print "basicMode.__get_command, remove when seen" # should happen often, and does
        return self

    command = property(__get_command)

    def __get_graphicsMode(self):
        ## print "basicMode.__get_graphicsMode, remove when seen" # should happen often, and does
        return self

    graphicsMode = property(__get_graphicsMode)

    pass # end of class basicMode

# end