HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP3D_InputSelectorBase.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: OP3D_InputSelectorBase.h
7  *
8  * COMMENTS:
9  * This descendant of DM_InputSelector knows about the viewer. It uses
10  * the viewer to find out display/current sop and to use the viewer's
11  * selection type buttons.
12  */
13 
14 #ifndef __OP3D_InputSelectorBase_h__
15 #define __OP3D_InputSelectorBase_h__
16 
17 #include "OP3D_API.h"
18 
19 #include <DM/DM_InputSelector.h>
20 #include <DM/DM_Defines.h>
21 #include <GR/GR_PickRecord.h>
22 #include <GU/GU_SelectType.h>
23 #include <GU/GU_DetailHandle.h>
24 #include <UI/UI_Value.h>
25 #include <UT/UT_String.h>
26 #include <UT/UT_IntrusivePtr.h>
27 #include <SYS/SYS_AtomicInt.h>
28 #include <GA/GA_Types.h>
29 
30 class SIM_Data;
31 class SIM_Object;
32 class GU_Detail;
33 class OP_Node;
35 class UI_Menu;
36 class UI_Feel;
37 class UI_Event;
38 class SI_RubberBox;
39 class SI_Lasso;
40 class SI_Brush;
41 class DM_Viewport;
42 class DM_Workbench;
43 class GUI_DetailLook;
44 class OP3D_View;
45 
47 {
51 };
52 
54 {
55 public:
56  OP3D_PickId();
57  OP3D_PickId(int lookindex, int detailindex);
58  ~OP3D_PickId();
59 
60  bool operator==(const OP3D_PickId &cmp) const;
61  bool operator!=(const OP3D_PickId &cmp) const;
62  static int compare(const OP3D_PickId *id1, const OP3D_PickId *id2);
63 
66 };
67 
70 
72 {
73 public:
74  OP3D_InputSelectorBase(OP3D_View &viewer,
75  PI_SelectorTemplate &templ);
76  virtual ~OP3D_InputSelectorBase();
77 
78  // This method allows the resource manager can set the workbench to
79  // something different if a selector is reused. It should not be used
80  // otherwise. A nil pointer is allowed so the select can remove any
81  // of its interests. However, methods of the selector should never be
82  // called when its workbench is nil. The method is virtual so
83  // descendants can also have a chance to clean up.
84  //
85  // Note that setSelectionUIValues must be called after calling setViewer()
86  virtual void setViewer(BM_View *viewer);
87 
88  // The selector needs to be notified when it starts/stops selecting
89  // so it can add/remove interests (the selection type, etc.).
90  virtual void startSelecting();
91  virtual void stopSelecting();
92 
93  // Use this opportunity to render prior object selections.
94  virtual void doRender(RE_Render *r, int x, int y, int ghost);
95 
96  // This UI value changes when the selector has finished selecting. The
97  // state that owns the selector adds an interest in this event to know
98  // when the selector is finished.
100  { return *myFinishedValue; }
101  const UI_Value &finishedValue() const
102  { return *myFinishedValue; }
103 
104  virtual UI_Feel *getCustomToolbox() const;
105 
107  { myPreferredSelectMode = selmode; }
109  { return myPreferredSelectMode; }
110 
111  // If the selector allows dragging, then it must wrap up and give up
112  // control when the user starts dragging. This enables us to implement
113  // the pick and drag functionality frequently used in modeling.
114  bool allowDragging() const
115  { return myAllowDragging; }
116  void setAllowDragging(bool on)
117  { myAllowDragging = on; }
118 
119  // Some states (like the select state) don't ever want their selector
120  // to finish.
121  bool allowFinishing() const
122  { return myAllowFinishingFlag; }
123  void setAllowFinishing(bool allow_finishing)
124  { myAllowFinishingFlag = allow_finishing;}
125 
126  // Some selector can finish with whatever selection exists already.
127  bool allowFinishWithExistingSelection() const;
128  void setAllowFinishWithExistingSelection(bool allow);
129 
130  // If quick select is on, then the selection is immediately finished
131  // if we have secure selection off
132  bool allowQuickSelect() const
133  { return myAllowQuickSelect; }
134  void setAllowQuickSelect(bool on)
135  { myAllowQuickSelect = on; }
136 
137  /// Tells the selector about previous selection information that we still
138  /// want to display in the viewport, but which is not part of the current
139  /// selection operation.
140  void setPriorSelections(const UT_StringArray &paths,
141  const UT_StringArray &ids,
142  const OP3D_SelectionHandles &selections);
143 
144  // Did the selector just change the display flag? The selector sets
145  // this flag when it creates a sop (eg. a hide or a group sop) and
146  // sets its display flag. The state will check this flag when the state
147  // controller asks it if it just changed the display flag. This way,
148  // the selector can change the display flag without exiting the current
149  // state.
150  bool justDisplayedOp() const
151  { return myJustDisplayedOpFlag; }
152  void setJustDisplayedOp(bool on)
153  { myJustDisplayedOpFlag = on; }
154 
155  // Selectors resize the brush radius with the mouse wheel when appropriate.
156  virtual int handleMouseWheelEvent(UI_Event *event);
157 
158  // Handle transitory keys to change the mouse cursor according to our
159  // selection mode.
160  virtual bool handleTransitoryKey(const UI_Event &event);
161 
162  virtual const char *cursor() const;
163 
164  void handleSelectionStyleChange(UI_Event *event);
165 
166  // Methods for setting user preferences
167  static bool getPickingMenuOn() { return thePickingMenuOn; }
168  static void setPickingMenuOn(bool val) { thePickingMenuOn = val; }
170  { return theAllowUseExistingSelection; }
172  { theAllowUseExistingSelection = val; }
173  static bool getSelectFullLoops()
174  { return theSelectFullLoops; }
175  static void setSelectFullLoops(bool val)
176  { theSelectFullLoops = val; }
177 
178 
179  // Converts a string to a GU_Detail pointer. The string will either be
180  // an object or sop path, or a path to a specific DOP simulation data.
181  static GU_ConstDetailHandle getGeometryFromPath(const char *path);
182  static OP_Node *getNodeFromPath(const char *path);
183  static const SIM_Object *getSimObjectFromPath(const char *path);
184  static const SIM_Data *getSimModifierFromPath(const char *path);
185 
186  // A utility method to get the string representation of the flood fill
187  // selection hotkey, if any is set.
188  static const char *getFloodFillSelectionHotkeyStringRepr();
189  // A utility method to get the string representation of the loop selection
190  // hotkey, if any is set.
191  static const char *getLoopSelectionHotkeyStringRepr();
192 
193  // A utility method to determine if a particular transitory key is bound
194  // as a loop selection hotkey.
195  static bool isTransitoryLoopSelectionHotkey(
196  const UI_DeviceEvent &state);
197 
198  // A utility method to determine if the loop selection hotkey is pressed
199  // in the specified viewport.
200  static bool isTransitoryLoopSelectionHotkeyPressed(
201  DM_Viewport *viewport);
202 
203  // A utility method to show the loop selection hotkey message in the given
204  // workbench.
205  static void showLoopSelectionMessage(
206  DM_Workbench &workbench);
207 
208  static void showSelectionHintsMessage(
209  DM_Workbench &workbench);
210 
211  virtual bool getStateParmNames(UT_StringArray &ret, const char* prefix=nullptr );
212  virtual bool evalStateParm(const char *name, UT_StringHolder &ret);
213  virtual bool setStateParm(const char *name, const UT_StringHolder &val);
214  virtual bool pressStateButton(const char *name);
215 
216  class Proxy;
219 
220 protected:
221  OP3D_View &viewer() { return (OP3D_View &)baseViewer(); }
222  const OP3D_View &viewer() const { return (OP3D_View &)baseViewer(); }
223 
224  DM_Workbench &workbench() { return *myWorkbench; }
225  const DM_Workbench &workbench() const { return *myWorkbench; }
226 
227  void setFinishedValuePtr(UI_Value *new_value)
228  { myFinishedValue = new_value; }
230  { return myFinishedValue; }
231 
233  { mySelectionStyle = new_value; }
235  { return mySelectionStyle; }
237  {
238  if (mySelectionStyle)
239  return (DM_SelectionStyle)
240  (int)*mySelectionStyle;
241  else
242  return DM_STYLE_UNKNOWN;
243  }
244  void setVisiblePickPtr(UI_Value *new_value)
245  { myVisiblePickValue = new_value; }
247  { return myVisiblePickValue; }
248  bool getVisiblePick() const
249  {
250  if(myVisiblePickValue)
251  return (bool) *myVisiblePickValue;
252  return true;
253  }
254 
255  void setContainedPickPtr(UI_Value *new_value)
256  { myContainedPickValue = new_value; }
258  { return myContainedPickValue; }
259  bool getContainedPick() const
260  {
261  if(myContainedPickValue)
262  return (bool) *myContainedPickValue;
263  return false;
264  }
265 
266  void setSelectionRulePtr(UI_Value *new_value)
267  { mySelectionRule = new_value; }
269  { return mySelectionRule; }
271  {
272  if (mySelectionRule)
273  return (GU_SelectionRule)
274  (int)*mySelectionRule;
275  else
276  return GU_ReplaceSelect;
277  }
279  {
280  if (mySelectionRule)
281  *mySelectionRule = (int)srule;
282  }
283 
284  SI_Brush * getPickBrushPtr() const { return myPickBrush; }
285  SI_Brush * getPickLaserPtr() const { return myPickLaser; }
286  SI_Lasso * getPickLassoPtr() const { return myPickLasso; }
287 
288 
289  // returns true if box, lasso or paint selection is active.
290  bool isDragSelectActive() const;
291 
292  // Returns true if the selector needs to make an object selection because
293  // the viewer isn't currently pointed at the right network level.
294  virtual bool needObjectPick() const;
295 
296  // Checks whether our selector knows how to handle selections in the
297  // context of the current chosen op.
298  bool selectModeMatchesTemplateType();
299 
300  // Given a pick buffer (where the first entry of each pick is an op
301  // node id), set the viewer chosen op to the first picked node.
302  bool pickChosenOp(UT_Array<GR_PickRecord> &pick_records,
303  bool *changed = nullptr);
304 
305  // Given a pick record, return the GU_Detail that it refers to, and
306  // (optionally), the corresponding detail look.
307  GU_ConstDetailHandle getGeometryFromPickRecord(const GR_PickRecord &pick,
308  GUI_DetailLook **detail_look = nullptr);
309 
310  // Make the specified node into the chosen op for the viewer. Used by
311  // pickChosenOp. Made the function virtual so subclasses can do extra
312  // work once the switch is complete. Returns the new chosen op.
313  // Sets @c changed to @c true if the operator chosen is different from
314  // the one that was selected going in.
315  virtual OP_Node *switchToChosenOp(OP_Node *parent,
316  bool *changed = nullptr);
317 
318  // Save our state for undo.
319  virtual void saveForUndo();
320 
321  // Given a pick number (the first number in a pick buffer), return
322  // the name in name. Returns true if the pick number was able to
323  // be associated with a name, false otherwise.
324  virtual bool getPickName(const OP3D_PickId &pickid,
325  UT_String &name,
326  bool descriptivename) const = 0;
327 
328  // Enable box picking or lasso picking, depending on what's currently
329  // selected.
330  void enablePicker(UI_Event *event);
331  void disablePicker();
332 
333  void disableActivePicking() { myActivePicking = false; }
334  bool isActivePicking() const { return myActivePicking; }
335 
336  virtual void handleBoxPick(UI_Event *event);
337  virtual void activeBoxPick(UI_Event *event);
338  virtual void handleLassoPick(UI_Event *event);
339  virtual void activeLassoPick(UI_Event *event);
340  virtual void handleBrushPick(UI_Event *event);
341  virtual void activeBrushPick(UI_Event *event);
342  virtual void handleLaserPick(UI_Event *event);
343  virtual void activeLaserPick(UI_Event *event);
344  bool visibleSelectToggle(UI_Event *event,
345  const char *echo_hotkey);
346  bool containedSelectToggle(UI_Event *event,
347  const char *echo_hotkey);
348 
349  // Gets the current time from the OP_Director.
350  static fpreal getTime();
351 
352  /// @{
353  /// Obtains the proxy representative used as a reference holder to this
354  /// selector. This proxy gets invalidated when the selector gets deleted.
355  /// Invalidation clears the proxy's pointer to NULL, but the proxy's memory
356  /// stays valid, unlike the memory of this selector object.
357  ///
358  /// Sample usage:
359  /// void Subclass::method()
360  /// {
361  /// ProxyHandle this_proxy(getProxy());
362  /// methodThatMayDeleteThis();
363  /// if( !this_proxy->isValid() )
364  /// return; // abort
365  /// }
366  ProxyHandle getProxy() { return ProxyHandle(myProxy); }
367  ConstProxyHandle getProxy() const { return ConstProxyHandle(myProxy); }
368  /// @}
369 
370 private:
371  Proxy *myProxy;
372  DM_Workbench *myWorkbench;
373 
374  UI_Value *myFinishedValue;
375  UI_Value *mySelectionStyle;
376  UI_Value *myVisiblePickValue;
377  UI_Value *myContainedPickValue;
378  UI_Value *mySelectionRule;
379 
380  SI_RubberBox *myPickBox; // for box selection
381  SI_Lasso *myPickLasso; // for lasso selection
382  SI_Brush *myPickBrush; // for brush selection
383  SI_Brush *myPickLaser; // for laser selection
384 
385  DM_SelectMode myPreferredSelectMode;
386  bool myAllowDragging;
387  bool myAllowFinishingFlag;
388  bool myAllowFinishWithExistingSelection;
389  bool myAllowQuickSelect;
390  bool myJustDisplayedOpFlag;
391  bool myActivePicking;
392 
393  UT_StringMap<UT_IntArray> myPriorObjSelections;
394  bool myCreatedPriorSelections;
395 
396  static bool thePickingMenuOn;
397  static bool theAllowUseExistingSelection;
398  static bool theSelectFullLoops;
399 };
400 
401 /// This reference counted proxy class allows code to check whether a
402 /// particular selector has been destroyed.
403 ///
404 /// See OP3D_InputSelectorBase::getProxy() for usage details.
405 class OP3D_API OP3D_InputSelectorBase::Proxy
406 {
407 public:
408  /// Returns true if the proxy is still pointing to a valid selector.
409  bool isValid() const
410  { return mySelector != NULL; }
411 
412  /// @private
413  /// This interface should only be used by the intrusive pointer handles
414  inline void intrusive_ptr_add_ref() const { incref(); }
415  inline void intrusive_ptr_release() const { decref(); }
416  /// @}
417 private:
418  explicit Proxy(OP3D_InputSelectorBase *selector);
419  ~Proxy();
420 
421  /// Makes the selector reference invalid. This is necessary to do when the
422  /// selector gets deleted.
423  void invalidate(); // only GA_AttributeSet calls it
424  /// Ask the proxy to register a new reference, which essentially
425  /// increments the reference counter.
426  void incref() const;
427  /// Ask the proxy to unregister a reference, which essentially
428  /// decrements the reference counter. When the reference decreases to
429  /// zero the proxy object gets deleted.
430  void decref() const;
431 
432  OP3D_InputSelectorBase *mySelector;
433  mutable SYS_AtomicInt32 myReferenceCount;
434 
436 };
437 
438 /// @{
439 /// Boost function callbacks for referencing and unreferencing the proxy.
440 static inline void
441 intrusive_ptr_add_ref(const OP3D_InputSelectorBase::Proxy *proxy)
442 {
443  proxy->intrusive_ptr_add_ref();
444 }
445 
446 static inline void
447 intrusive_ptr_release(const OP3D_InputSelectorBase::Proxy *proxy)
448 {
449  proxy->intrusive_ptr_release();
450 }
451 /// @}
452 
453 #endif
BM_View & baseViewer()
static int compare(const OP3D_PickId *id1, const OP3D_PickId *id2)
void setSelectionStylePtr(UI_Value *new_value)
GLuint const GLchar * name
Definition: glew.h:1814
virtual void setViewer(BM_View *viewer)
UT_Array< GU_SelectionHandle > OP3D_SelectionHandles
UI_Value * getSelectionRulePtr() const
GLuint const GLfloat * val
Definition: glew.h:2794
UI_Value * getVisiblePickPtr() const
OP3D_SelectionAction
UI_Value * getFinishedValuePtr() const
virtual bool handleTransitoryKey(const UI_Event &event)
DM_SelectMode getPreferredSelectMode() const
void setAllowFinishing(bool allow_finishing)
virtual bool getStateParmNames(UT_StringArray &ret, const char *prefix=nullptr)
const UI_Value & finishedValue() const
const OP3D_View & viewer() const
UT_Array< OP3D_PickId > OP3D_PickIdArray
ConstProxyHandle getProxy() const
bool isValid() const
Returns true if the proxy is still pointing to a valid selector.
virtual bool setStateParm(const char *name, const UT_StringHolder &val)
void setFinishedValuePtr(UI_Value *new_value)
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
void setPreferredSelectMode(DM_SelectMode selmode)
GU_SelectionRule
Definition: GU_SelectType.h:40
UI_Value * getContainedPickPtr() const
Wrapper around hboost::intrusive_ptr.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
static void setPickingMenuOn(bool val)
DM_SelectMode
Definition: DM_Defines.h:110
static void setAllowUseExistingSelection(bool val)
bool operator==(const OP3D_PickId &cmp) const
SI_Brush * getPickBrushPtr() const
virtual int handleMouseWheelEvent(UI_Event *event)
const DM_Workbench & workbench() const
void setContainedPickPtr(UI_Value *new_value)
bool operator!=(const OP3D_PickId &cmp) const
int cmp(T a, T b)
Definition: ImathFun.h:119
DM_SelectionStyle selectionStyle() const
GLsizei const GLchar *const * path
Definition: glew.h:6461
double fpreal
Definition: SYS_Types.h:276
cl_event event
Definition: glew.h:3695
void setVisiblePickPtr(UI_Value *new_value)
UI_Value * getSelectionStylePtr() const
void selectionRule(GU_SelectionRule srule)
SI_Lasso * getPickLassoPtr() const
GU_SelectionRule selectionRule() const
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
#define OP3D_API
Definition: OP3D_API.h:10
const GLuint * ids
Definition: glew.h:1684
virtual void startSelecting()
UT_IntrusivePtr< Proxy > ProxyHandle
virtual UI_Feel * getCustomToolbox() const
virtual void stopSelecting()
static bool getAllowUseExistingSelection()
void setSelectionRulePtr(UI_Value *new_value)
virtual bool evalStateParm(const char *name, UT_StringHolder &ret)
SI_Brush * getPickLaserPtr() const
static void setSelectFullLoops(bool val)
UT_IntrusivePtr< const Proxy > ConstProxyHandle
DM_SelectionStyle
Definition: DM_Defines.h:51
virtual void doRender(RE_Render *r, int x, int y, int ghost)
virtual bool pressStateButton(const char *name)
GLenum const void * paths
Definition: glew.h:13589
virtual const char * cursor() const