summaryrefslogtreecommitdiff
path: root/cad/src/outtakes/model_changed-outtakes.py
blob: 6ce657a537953cac1f2a28b18ab98c0f3cac114d (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
    def selection_changed(self): #bruce 070925 [not used outside this file as of 080731, except in docstrings/comments]
        return

    def selobj_changed(self): #bruce 071116 [not mentioned outside this file as of 080731] 8
        return

    def view_changed(self): #bruce 071116 [not mentioned outside this file as of 080731]8
        return

    def something_changed(self): #bruce 071116 [not used outside this file as of 080731, except in comments]
        return
    







    def selection_changed(self): #bruce 070925 added this to Command API
        """
        Subclasses should extend this (or make sure their self.propMgr defines
        it) to check whether any selection state has changed that should be
        reflected in their UI, and if so, update their UI accordingly.

        """
        ### REVIEW: Decide whether highlighting (selobj) is covered by it
        # (guess yes -- all kinds of selection).
        ### maybe: call when entering/resuming the command, and say so,
        # and document order of call relative to update_gui. And deprecate
        # update_gui or make it more efficient. And add other methods that only
        # use usage-tracked state and are only called as needed.
        if self.propMgr:
            if hasattr( self.propMgr, 'selection_changed'):
                self.propMgr.selection_changed()
        return

    def selobj_changed(self):
        """
        Called whenever the glpane.selobj (object under mouse)
        may have changed, so that self can do UI updates in response to that. 
        """
        if self.propMgr:
            if hasattr( self.propMgr, 'selobj_changed'):
                self.propMgr.selobj_changed()
        return

    def view_changed(self):
        """
        Called whenever the glpane's view (view center, direction, projection)
        may have changed, so that self can do UI updates in response to that.
        """
        # REVIEW: I'm not sure this gets called for Ortho/Perspective change,
        # but it should be! [bruce 071116]
        if self.propMgr:
            if hasattr( self.propMgr, 'view_changed'):
                self.propMgr.view_changed()
        return

    def something_changed(self):
        """
        Called once, immediately after any or all of the methods
        model_changed, selection_changed, selobj_changed, or view_changed
        were called.
        """
        if self.propMgr:
            if hasattr( self.propMgr, 'something_changed'):
                self.propMgr.something_changed()
        return
    
    _last_model_change_counter = None
    _last_selection_change_counter = None
    _last_selobj = -1 # not None, since that's a legal value of selobj
    _last_view_change_counter = None
    
    def state_may_have_changed_OBSOLETE(self): #bruce 070925 added this to command API; update 080731: WILL BE REVISED SOON
        """
        Call whichever we need to of the methods
        model_changed, selection_changed, selobj_changed, view_changed,
        in that order. The need is determined by whether the associated
        change counters or state has changed since this method
        (state_may_have_changed) was last called on self.

        Then if any of those was called, also call something_changed.
        This permits subclasses which just want to update after any change
        to define only one method, and be sure it's not called more than
        once per change. Or they can set specific change flags in the
        specific change methods, and then respond to those all at once
        or in a different order, in something_changed.

        Note: this method should not normally be overridden by subclasses.

        Note: the "only as needed" aspect is NIM, except when an
        experimental debug_pref is set, but it should become the usual case.

        FYI: This is called by env.do_post_event_updates() by a registered
        "post_event_ui_updater" set up by MWsemantics. [still true 080731]
        """
        if debug_pref("call model_changed (etc) only when needed?",
                      Choice_boolean_False,
                      ## non_debug = True,
                          #bruce 080416 hide this since the commands can't yet
                          # handle it properly, so it causes bugs
                          # (this change didn't make it into .rc2)
                      prefs_key = True):
            ### experimental, but will become the usual case soon [bruce 071116]:
            # call each method only when needed, using assy change counters, and a selobj test.
            counters = self.assy.all_change_counters()
            model_change_counter = counters[0] # MAYBE: make assy break them out for us?
            selection_change_counter = counters[1] # note: doesn't cover selobj changes
            view_change_counter = counters[2]
            selobj = self.glpane.selobj
            something_changed = False # will be updated if something changed

            # the following order must be maintained,
            # so that updating methods can assume it:

            if model_change_counter != self._last_model_change_counter:
                self._last_model_change_counter = model_change_counter
                self.model_changed()
                something_changed = True

            if selection_change_counter != self._last_selection_change_counter:
                self._last_selection_change_counter = selection_change_counter
                self.selection_changed()
                something_changed = True

            if selobj is not self._last_selobj:
                self._last_selobj = selobj
                self.selobj_changed() # will be renamed
                something_changed = True

            if view_change_counter != self._last_view_change_counter:
                self._last_view_change_counter = view_change_counter
                self.view_changed()
                something_changed = True

            if something_changed:
                self.something_changed()
            pass
        else:
            # current bad code: always call every method.
            self.model_changed()
            self.selection_changed()
            self.selobj_changed()
            self.view_changed()
            self.something_changed()
        return # end of an OBSOLETE method