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  bool insertmode = true,
65  bool requestnew = false) override;
66 
67  int hasLocates() const override;
68 
69  // Check if we have to do anything if this node is deleted. Return -1 if
70  // we can't handle it, 0 otherwise.
71  int handleNodeDeleted(OP_Node &node) override;
72 
73  // Called whenever the current detail look, or the geometry in it, changes.
74  // See needsGeoChangedInterest() to control when this interest is added.
75  void handleGeoChangedEvent(UI_Event *) override;
76 
77  // If a state generates a sop and displays it (eg. a hide sop), it
78  // will want the state controller to ignore the change so the state
79  // doesn't exit.
80  bool ignoreDisplayFlagChange() const override;
81 
82  void undoReselecting();
83 
84  // Return the feel for the RMB menu.
85  UI_Menu *getSelectorMenu() override;
86 
87  // Return the menu feel for others to use:
88  UI_Menu *getExtraStateMenu() override;
89 
90  // Methods to query whether or not this state is allowed to change the
91  // current selection type to match the cook selection of our node when
92  // the corresponding global user preference allows it. Defaults to false
93  // for all sub-classes and true for instances created by this class's
94  // ourConstructor().
96  { return myAllowExportingCookSelectionType; }
98  { myAllowExportingCookSelectionType = on; }
99 
100  // Returns true when this state allows changing the current selection type
101  // to match that of the cook selection and the corresponding global user
102  // preference allows it to do so.
103  bool canExportCookSelectionType() const;
104 
105  // Handle selection changes.
106  void handleVolatileChanges() override;
107 
108  class PrefTokens;
109 
110 protected:
111  // Quickly generate a node, connect it to the network if needed,
112  // and stop generating. This method is called from generate().
113  void doGenerate() override;
114 
115  // calls the selector render, if any
116  void doRender(RE_Render *r, int, int, int ghost) override;
117 
118  void getKeyResolveInfo(UI_KeyResolveInfo &info) override;
119 
120  // Respond to mouse and keyboard events.
121  int handleMouseEvent(UI_Event *event) override;
122  int handleMouseWheelEvent(UI_Event *event) override;
123  bool handleDoubleClickEvent(UI_Event *event) override;
124  int handleKeyTypeEvent(UI_Event *event, BM_Viewport &) override;
125  bool handleTransitoryKey(const UI_Event &event) override;
126 
127  // This depends on the secure selection button and
128  // whether a selector is active.
129  bool isSelecting() const override;
130 
131  // Interrupt this state or resume its activity. These methods should
132  // be called by overlay states when entering and exiting respectively.
133  // Interrupt will leave the state in limbo and will usually turn off
134  // the feed from the app; resume will do the opposite. interrupt()
135  // should not change the modeler's current state. If 'state' is given, it
136  // is the state that has interrupted/resumed us. This may be particularly
137  // useful if we are interrupted by a handle (possibly ours).
138  void interrupt(BM_SimpleState *state = 0) override;
139  void resume(BM_SimpleState *state = 0) override;
140 
141  // Generate the necessary nodes and connect them
142  virtual bool generateAllNodes();
143 
144  // We're done selecting and we've been successful. In this class we simply
145  // clear the display.
146  virtual void doneSelecting();
147 
148  // If this state is reselecting and it tries to reselect within the same
149  // node then that node's unique id is returned. Otherwise, 0 is returned.
150  virtual int nodeIdToReselectWithin() const { return 0; }
151 
152  // Access to the list of selectors
154  {
155  UT_ASSERT(idx >= 0);
156  UT_ASSERT(idx < mySelectors.entries());
157  return mySelectors(idx).mySelector;
158  }
159  int getNumSelectors() const
160  {
161  return mySelectors.entries();
162  }
163 
164  virtual bool isSelectorActive() const
165  { return (myCurrentSelector != 0); }
166 
167  int getToolboxCount() const override;
168  UI_Feel *getToolbox(int idx) const override;
169 
170  virtual void handleSelectorDone(UI_Event *);
171 
172  // Override in subclasses to disable selector starting
173  // by this class.
174  virtual bool canStartSelectors() const { return true; }
175 
176  virtual const PI_BindingSelectorInfo *findNextParmWithSelector(int idx) const;
177 
178  void addAnyReselectionUndos() override;
179 
180  virtual void updateCurrentSelector(OP3D_InputSelector * /*cur_sel*/,
181  const PI_BindingSelectorInfo * /*selector_info*/)
182  { }
183 
184  virtual bool getSelectionBoundingBox( DM_Viewport &vport,
185  UT_BoundingBox &bbox );
186 
187  // Override this method to return false if you don't want this base class
188  // to start a non-secure selector on you. Typically a subclass will do
189  // this when it wants to inherit the bound selector behavior from this
190  // base class, but wants to handle its own selections after that.
191  virtual bool canStartNonSecureSelector() const { return true; }
192 
193  virtual bool getAllowQuickSelect() const { return false; }
194 
195  // Override this method to return false if you don't want this base class
196  // to copy the cooked selection when starting the first selector.
198  { return true; }
199 
200  // Override this method to return false if you don't want this base class
201  // to create myHotkeySelector and myHotkeySelectorMenu.
202  virtual bool usesHotkeySelector() const { return true; }
203 
204  virtual bool usesSloppySopSelectorToolbox() const { return false; }
205 
206  virtual const char *getTemplateName() const
207  { return (const char *)getTemplate().name(); }
208 
209  const char *getOperatorName() const override
210  {
211  return getTemplateName();
212  }
213 
215  { return myFirstSelectionFlag; }
217  { myFirstSelectionFlag = first; }
218 
219  virtual void handleSelectionTypeChange(UI_Event *event);
220 
221  void updateStashedSelectorActiveCoords(UI_Event *event);
222 
223  void createHotkeySelector();
224  void destroyHotkeySelectorIfNeeded();
225 
226  // This base class will add an interest in DM_SceneManager::newGeoValue()
227  // on enter()/generate() if this method returns true. The virtual method
228  // handleGeoChangedEvent() handles events from this value.
229  virtual bool needsGeoChangedInterest() const;
230 
231 private:
232  // Append the specified node to the currently displayed sop.
233  void appendNodeToDisplay(OP_Node &newnode);
234 
235  bool usesSelectors() const;
236 
237  void deleteSelectors();
238  void setCurrentSelector(const PI_BindingSelectorInfo *
239  selector_info);
240  void clearReselectLists();
241 
242  // When reselecting, store the selections on the input nodes.
243  void storeSelectionsOfInputNodes();
244  // Restore the selections on our inputs from the information stored above.
245  void restoreCurrentSelectorSelections();
246 
247  GA_GroupType getSelectionTypeForCurNode();
248 
249  /// Given a selection string, attempt to figure out which of the selector-
250  /// assigned group types best apply, in order of declaration.
251  GA_GroupType getSelectionTypeFromString(const char *sel_str) const;
252 
253  void startNonSecureSelector();
254  void undoStartNonSecureSelector();
255 
256  bool finishSelector();
257 
258  bool isRapidFire() const;
259 
260  void handleFinishUndoEvent(UI_Event *event = 0);
261 
262  // This class contains information about the input field to which a
263  // selector is bound.
264  class MSS_API MSS_SelectorBind
265  {
266  public:
267  MSS_SelectorBind()
268  : mySelector(0), mySelectorInfo(0)
269  { }
270  ~MSS_SelectorBind()
271  {
272  // It's possible that the resource manager doesn't exist
273  // if we're being deleted because of an exit callback.
274  if( mySelector && PIresourceManagerExists() )
276  (BM_InputSelector *)mySelector);
277  }
278  OP3D_InputSelector *mySelector;
279  const PI_BindingSelectorInfo *mySelectorInfo;
280  };
281 
282  // info about selectors
283  UT_Array<MSS_SelectorBind> mySelectors;
284  OP3D_InputSelector *myCurrentSelector;
285  const PI_BindingSelectorInfo *myCurrentSelectorInfo;
286 
287  // Selector used for selector hotkeys when in quickselect mode and
288  // secure selection is turned off.
289  OP3D_InputSelector *myHotkeySelector;
290  UI_Menu * myHotkeySelectorMenu;
291 
292  // The selector index is the index of the current selector in the list of
293  // selectors provided for this state. It coincides with the index into
294  // the gdp's set of temporary selections.
295  int mySelectorIndex;
296 
297  UT_ValArray<UT_StringArray *> myReselectPathLists;
298  UT_StringArray myReselectSelectionStrings;
299  UT_Array<GA_GroupType> myReselectSelectionTypes;
300 
301  UI_Value mySelFinishedValue;
302 
303  float mySelectorActiveCoords[2];
304  UI_Event myRapidFireActiveEvent;
305  UI_Value myRapidFireActiveEventValue;
306 
307  mss_InputSelectorUndoWorker * mySelectorUndoWorker;
308 
309  int mySelectableFlag; // uses selectors?
310  unsigned myMouseTakenFlag:1; // can rapid-fire?
311  bool myFirstSelectionFlag;
312  bool myInNonSecureUndo;
313  bool myInNonSecureSelector;
314  bool myAllowExportingCookSelectionType;
315  bool myHasGeoChangedInterest;
316 
317  int myDoubleClickUndoLevel;
318 };
319 
320 /// Essentially a namespace containing static methods for querying various
321 /// global preference tokens.
322 class MSS_API MSS_SingleOpState::PrefTokens
323 {
324 public:
325  // T global user preference for allowing states to change the current
326  // selection type to match that of the cook selection.
327  static const char *exportCookSelectionType();
328 };
329 
330 #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:251
int handleMouseWheelEvent(UI_Event *event) override
virtual bool usesSloppySopSelectorToolbox() const
int handleNodeDeleted(OP_Node &node) override
void deleteSelector(BM_InputSelector *selector)
void setFirstSelectionFlag(bool first)
virtual void doRender(RE_Render *r, int x, int y, int ghost)
virtual void doGenerate()
const GLint * first
Definition: glew.h:1528
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
virtual bool handleDoubleClickEvent(UI_Event *)
virtual UI_Menu * getSelectorMenu()
int handleKeyTypeEvent(UI_Event *event, BM_Viewport &) override
Respond to keyboard events.
void exit() 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
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
cl_event event
Definition: glew.h:3695
const PI_StateTemplate & getTemplate() const
Definition: BM_State.h:284
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
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
GLuint GLuint GLsizei count
Definition: glew.h:1253
virtual UI_Menu * getExtraStateMenu()
virtual int nodeIdToReselectWithin() const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
virtual void handleVolatileChanges()
Definition: BM_State.h:119
void interrupt(BM_SimpleState *=0) override
bool handleTransitoryKey(const UI_Event &event) override
virtual int hasLocates() const
Definition: BM_State.h:216
virtual void handleGeoChangedEvent(UI_Event *)
virtual bool copyCookedSelectionForFirstSelector() const
int generate(BM_SimpleState::BM_EntryType how, bool insertmode=true, bool requestnew=false) override