HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSS_SingleOpState.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: MSS_SingleOpState.h
7  *
8  * COMMENTS:
9  * This is an "automated" state that links handles with op
10  * parameters.
11  */
12 
13 #ifndef __MSS_SingleOpState_H__
14 #define __MSS_SingleOpState_H__
15 
16 #include "MSS_API.h"
17 #include <UT/UT_ValArray.h>
18 #include <UT/UT_String.h>
19 #include <GU/GU_Selection.h>
20 #include <UI/UI_Value.h>
21 #include <UI/UI_Event.h>
22 #include <BM/BM_ResourceManager.h>
23 #include "MSS_SingleOpBaseState.h"
24 
25 class UT_String;
26 class PRM_Template;
27 class DM_Workbench;
28 class OP3D_View;
29 class JEDI_View;
30 class OP3D_InputSelector;
31 class DM_Viewport;
32 
33 class mss_InputSelectorUndoWorker;
34 class mss_UndoClearHandles;
35 
37 {
38  friend class mss_UndoClearHandles;
39  friend class mss_UndoCreateHandles;
40  friend class mss_InputSelectorUndoWorker;
41 
42 public:
43  // Class constructor and destructor.
44  MSS_SingleOpState(JEDI_View &view, PI_StateTemplate &templ,
45  BM_SceneManager *scene, const char *cursor);
46  ~MSS_SingleOpState() override;
47 
48  // This constructor and parameter template list go into the
49  // DM_StateTemplate for this state.
50  static BM_State *ourConstructor(BM_View &view, PI_StateTemplate &templ,
51  BM_SceneManager *scene);
53 
54  // The name and type of this class:
55  const char *className() const override;
56 
57  void initApplication(UI_Manager * ui_mgr, int count, const char ** vargs) override;
58 
59  // Enter or exit this state.
60  int enter(BM_SimpleState::BM_EntryType how) override;
61  void exit() override;
62  void restart() override;
64  const GenerateParms &parms) override;
65 
66  int hasLocates() const override;
67 
68  // Check if we have to do anything if this node is deleted. Return -1 if
69  // we can't handle it, 0 otherwise.
70  int handleNodeDeleted(OP_Node &node) override;
71 
72  // Called whenever the current detail look, or the geometry in it, changes.
73  // See needsGeoChangedInterest() to control when this interest is added.
74  void handleGeoChangedEvent(UI_Event *) override;
75 
76  // If a state generates a sop and displays it (eg. a hide sop), it
77  // will want the state controller to ignore the change so the state
78  // doesn't exit.
79  bool ignoreDisplayFlagChange() const override;
80 
81  void undoReselecting();
82 
83  // Return the feel for the RMB menu.
84  UI_Menu *getSelectorMenu() override;
85 
86  // Return the menu feel for others to use:
87  UI_Menu *getExtraStateMenu() override;
88 
89  // Methods to query whether or not this state is allowed to change the
90  // current selection type to match the cook selection of our node when
91  // the corresponding global user preference allows it. Defaults to false
92  // for all sub-classes and true for instances created by this class's
93  // ourConstructor().
95  { return myAllowExportingCookSelectionType; }
97  { myAllowExportingCookSelectionType = on; }
98 
99  // Returns true when this state allows changing the current selection type
100  // to match that of the cook selection and the corresponding global user
101  // preference allows it to do so.
102  bool canExportCookSelectionType() const;
103 
104  // Handle selection changes.
105  void handleVolatileChanges() override;
106 
107  class PrefTokens;
108 
109 protected:
110  // Quickly generate a node, connect it to the network if needed,
111  // and stop generating. This method is called from generate().
112  void doGenerate() override;
113 
114  // calls the selector render, if any
115  void doRender(RE_Render *r, int, int, int ghost) override;
116 
117  void getKeyResolveInfo(UI_KeyResolveInfo &info) override;
118 
119  // Respond to mouse and keyboard events.
120  int handleMouseEvent(UI_Event *event) override;
121  int handleMouseWheelEvent(UI_Event *event) override;
122  bool handleDoubleClickEvent(UI_Event *event) override;
123  int handleKeyTypeEvent(int key, UI_Event *event,
124  BM_Viewport &) override;
125  bool handleTransitoryKey(const UI_Event &event,
126  int hotkey_id) override;
127 
128  // This depends on the secure selection button and
129  // whether a selector is active.
130  bool isSelecting() const override;
131 
132  // Interrupt this state or resume its activity. These methods should
133  // be called by overlay states when entering and exiting respectively.
134  // Interrupt will leave the state in limbo and will usually turn off
135  // the feed from the app; resume will do the opposite. interrupt()
136  // should not change the modeler's current state. If 'state' is given, it
137  // is the state that has interrupted/resumed us. This may be particularly
138  // useful if we are interrupted by a handle (possibly ours).
139  void interrupt(BM_SimpleState *state = 0) override;
140  void resume(BM_SimpleState *state = 0) override;
141 
142  // Generate the necessary nodes and connect them
143  virtual bool generateAllNodes();
144 
145  // We're done selecting and we've been successful. In this class we simply
146  // clear the display.
147  virtual void doneSelecting();
148 
149  // If this state is reselecting and it tries to reselect within the same
150  // node then that node's unique id is returned. Otherwise, 0 is returned.
151  virtual int nodeIdToReselectWithin() const { return 0; }
152 
153  // Access to the list of selectors
155  {
156  UT_ASSERT(idx >= 0);
157  UT_ASSERT(idx < mySelectors.entries());
158  return mySelectors(idx).mySelector;
159  }
160  int getNumSelectors() const
161  {
162  return mySelectors.entries();
163  }
164 
165  virtual bool isSelectorActive() const
166  { return (myCurrentSelector != 0); }
167 
168  int getToolboxCount() const override;
169  UI_Feel *getToolbox(int idx) const override;
170 
171  virtual void handleSelectorDone(UI_Event *);
172 
173  // Override in subclasses to disable selector starting
174  // by this class.
175  virtual bool canStartSelectors() const { return true; }
176 
177  virtual const PI_BindingSelectorInfo *findNextParmWithSelector(int idx) const;
178 
179  void addAnyReselectionUndos() override;
180 
181  virtual void updateCurrentSelector(OP3D_InputSelector * /*cur_sel*/,
182  const PI_BindingSelectorInfo * /*selector_info*/)
183  { }
184 
185  virtual bool getSelectionBoundingBox( DM_Viewport &vport,
186  UT_BoundingBox &bbox );
187 
188  // Override this method to return false if you don't want this base class
189  // to start a non-secure selector on you. Typically a subclass will do
190  // this when it wants to inherit the bound selector behavior from this
191  // base class, but wants to handle its own selections after that.
192  virtual bool canStartNonSecureSelector() const { return true; }
193 
194  virtual bool getAllowQuickSelect() const { return false; }
195 
196  // Override this method to return false if you don't want this base class
197  // to copy the cooked selection when starting the first selector.
199  { return true; }
200 
201  // Override this method to return false if you don't want this base class
202  // to create myHotkeySelector and myHotkeySelectorMenu.
203  virtual bool usesHotkeySelector() const { return true; }
204 
205  virtual bool usesSloppySopSelectorToolbox() const { return false; }
206 
207  virtual const char *getTemplateName() const
208  { return (const char *)getTemplate().name(); }
209 
210  const char *getOperatorName() const override
211  {
212  return getTemplateName();
213  }
214 
216  { return myFirstSelectionFlag; }
218  { myFirstSelectionFlag = first; }
219 
220  virtual void handleSelectionTypeChange(UI_Event *event);
221 
222  void updateStashedSelectorActiveCoords(UI_Event *event);
223 
224  void createHotkeySelector();
225  void destroyHotkeySelectorIfNeeded();
226 
227  // This base class will add an interest in DM_SceneManager::newGeoValue()
228  // on enter()/generate() if this method returns true. The virtual method
229  // handleGeoChangedEvent() handles events from this value.
230  virtual bool needsGeoChangedInterest() const;
231 
232 private:
233  // Append the specified node to the currently displayed sop.
234  void appendNodeToDisplay(OP_Node &newnode);
235 
236  bool usesSelectors() const;
237 
238  void deleteSelectors();
239  void setCurrentSelector(const PI_BindingSelectorInfo *
240  selector_info);
241  void clearReselectLists();
242 
243  // When reselecting, store the selections on the input nodes.
244  void storeSelectionsOfInputNodes();
245  // Restore the selections on our inputs from the information stored above.
246  void restoreCurrentSelectorSelections();
247 
248  GA_GroupType getSelectionTypeForCurNode();
249 
250  /// Given a selection string, attempt to figure out which of the selector-
251  /// assigned group types best apply, in order of declaration.
252  GA_GroupType getSelectionTypeFromString(const char *sel_str) const;
253 
254  void startNonSecureSelector();
255  void undoStartNonSecureSelector();
256 
257  bool finishSelector();
258 
259  bool isRapidFire() const;
260 
261  void handleFinishUndoEvent(UI_Event *event = 0);
262 
263  // This class contains information about the input field to which a
264  // selector is bound.
265  class MSS_API MSS_SelectorBind
266  {
267  public:
268  MSS_SelectorBind()
269  : mySelector(0), mySelectorInfo(0)
270  { }
271  ~MSS_SelectorBind()
272  {
273  // It's possible that the resource manager doesn't exist
274  // if we're being deleted because of an exit callback.
275  if( mySelector && PIresourceManagerExists() )
277  (BM_InputSelector *)mySelector);
278  }
279  OP3D_InputSelector *mySelector;
280  const PI_BindingSelectorInfo *mySelectorInfo;
281  };
282 
283  // info about selectors
284  UT_Array<MSS_SelectorBind> mySelectors;
285  OP3D_InputSelector *myCurrentSelector;
286  const PI_BindingSelectorInfo *myCurrentSelectorInfo;
287 
288  // Selector used for selector hotkeys when in quickselect mode and
289  // secure selection is turned off.
290  OP3D_InputSelector *myHotkeySelector;
291  UI_Menu * myHotkeySelectorMenu;
292 
293  // The selector index is the index of the current selector in the list of
294  // selectors provided for this state. It coincides with the index into
295  // the gdp's set of temporary selections.
296  int mySelectorIndex;
297 
298  UT_ValArray<UT_StringArray *> myReselectPathLists;
299  UT_StringArray myReselectSelectionStrings;
300  UT_Array<GA_GroupType> myReselectSelectionTypes;
301 
302  UI_Value mySelFinishedValue;
303 
304  float mySelectorActiveCoords[2];
305  UI_Event myRapidFireActiveEvent;
306  UI_Value myRapidFireActiveEventValue;
307 
308  mss_InputSelectorUndoWorker * mySelectorUndoWorker;
309 
310  int mySelectableFlag; // uses selectors?
311  unsigned myMouseTakenFlag:1; // can rapid-fire?
312  bool myFirstSelectionFlag;
313  bool myInNonSecureUndo;
314  bool myInNonSecureSelector;
315  bool myAllowExportingCookSelectionType;
316  bool myHasGeoChangedInterest;
317 
318  int myDoubleClickUndoLevel;
319 };
320 
321 /// Essentially a namespace containing static methods for querying various
322 /// global preference tokens.
323 class MSS_API MSS_SingleOpState::PrefTokens
324 {
325 public:
326  // T global user preference for allowing states to change the current
327  // selection type to match that of the cook selection.
328  static const char *exportCookSelectionType();
329 };
330 
331 #endif
virtual void updateCurrentSelector(OP3D_InputSelector *, const PI_BindingSelectorInfo *)
const UT_String & name() const
virtual bool isSelecting() const
int getNumSelectors() const
virtual bool ignoreDisplayFlagChange() const
Definition: BM_State.h:304
int handleMouseWheelEvent(UI_Event *event) override
virtual bool usesSloppySopSelectorToolbox() const
int handleNodeDeleted(OP_Node &node) override
GLint first
Definition: glcorearb.h:405
void deleteSelector(BM_InputSelector *selector)
int handleKeyTypeEvent(int key, UI_Event *event, BM_Viewport &) override
Respond to keyboard events.
void setFirstSelectionFlag(bool first)
virtual void doRender(RE_Render *r, int x, int y, int ghost)
virtual void doGenerate()
const char * className() const override
virtual void addAnyReselectionUndos()
UI_Feel * getToolbox(int index) const override
virtual bool usesHotkeySelector() const
void restart() override
int getToolboxCount() const override
PI_API bool PIresourceManagerExists()
#define MSS_API
Definition: MSS_API.h:10
virtual bool canStartNonSecureSelector() const
bool getAllowExportingCookSelectionType() const
bool getFirstSelectionFlag() const
void initApplication(UI_Manager *, int, const char **) override
struct _cl_event * event
Definition: glcorearb.h:2961
virtual bool handleDoubleClickEvent(UI_Event *)
virtual UI_Menu * getSelectorMenu()
void exit() override
int generate(BM_SimpleState::BM_EntryType how, const GenerateParms &parms) override
void setAllowExportingCookSelectionType(bool on)
virtual const char * getTemplateName() const
const char * getOperatorName() const override
int handleMouseEvent(UI_Event *event) override
virtual bool isSelectorActive() const
GLint GLsizei count
Definition: glcorearb.h:405
Parent class for SOP custom states.
BM_API BM_ResourceManager * BMgetResourceManager()
virtual bool canStartSelectors() const
void resume(BM_SimpleState *=0) override
OP3D_InputSelector * selector(int idx)
virtual bool getAllowQuickSelect() const
const PI_StateTemplate & getTemplate() const
Definition: BM_State.h:337
void getKeyResolveInfo(UI_KeyResolveInfo &info) override
int enter(BM_SimpleState::BM_EntryType how) override
static PRM_Template * ourTemplateList
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:159
bool handleTransitoryKey(const UI_Event &event, int hotkey_id) override
virtual UI_Menu * getExtraStateMenu()
Definition: core.h:982
virtual int nodeIdToReselectWithin() const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:153
virtual void handleVolatileChanges()
Definition: BM_State.h:131
void interrupt(BM_SimpleState *=0) override
GLboolean r
Definition: glcorearb.h:1222
virtual int hasLocates() const
Definition: BM_State.h:267
virtual void handleGeoChangedEvent(UI_Event *)
virtual bool copyCookedSelectionForFirstSelector() const