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