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 RE_Render;
36 class UI_Menu;
37 class UI_Feel;
38 class UI_Event;
39 class SI_RubberBox;
40 class SI_Lasso;
41 class SI_Brush;
42 class DM_Viewport;
43 class DM_Workbench;
44 class DM_HeldHotkeyCache;
45 class GUI_DetailLook;
46 class OP3D_View;
47 
49 {
53 };
54 
56 {
57 public:
58  OP3D_PickId();
59  OP3D_PickId(int lookindex, int detailindex);
60  ~OP3D_PickId();
61 
62  bool operator==(const OP3D_PickId &cmp) const;
63  bool operator!=(const OP3D_PickId &cmp) const;
64  static int compare(const OP3D_PickId *id1, const OP3D_PickId *id2);
65 
68 };
69 
72 
74 {
75 public:
76  OP3D_InputSelectorBase(OP3D_View &viewer,
77  PI_SelectorTemplate &templ);
78  ~OP3D_InputSelectorBase() override;
79 
80  // This method allows the resource manager can set the workbench to
81  // something different if a selector is reused. It should not be used
82  // otherwise. A nil pointer is allowed so the select can remove any
83  // of its interests. However, methods of the selector should never be
84  // called when its workbench is nil. The method is virtual so
85  // descendants can also have a chance to clean up.
86  //
87  // Note that setSelectionUIValues must be called after calling setViewer()
88  void setViewer(BM_View *viewer) override;
89 
90  // The selector needs to be notified when it starts/stops selecting
91  // so it can add/remove interests (the selection type, etc.).
92  void startSelecting() override;
93  void stopSelecting() override;
94 
95  // Use this opportunity to render prior object selections.
96  void doRender(RE_Render *r, int x, int y,
97  int ghost) override;
98 
99  // This UI value changes when the selector has finished selecting. The
100  // state that owns the selector adds an interest in this event to know
101  // when the selector is finished.
103  { return *myFinishedValue; }
104  const UI_Value &finishedValue() const
105  { return *myFinishedValue; }
106 
107  UI_Feel *getCustomToolbox() const override;
108 
110  { myPreferredSelectMode = selmode; }
112  { return myPreferredSelectMode; }
113 
114  // If the selector allows dragging, then it must wrap up and give up
115  // control when the user starts dragging. This enables us to implement
116  // the pick and drag functionality frequently used in modeling.
117  bool allowDragging() const
118  { return myAllowDragging; }
119  void setAllowDragging(bool on)
120  { myAllowDragging = on; }
121 
122  // Some states (like the select state) don't ever want their selector
123  // to finish.
124  bool allowFinishing() const
125  { return myAllowFinishingFlag; }
126  void setAllowFinishing(bool allow_finishing)
127  { myAllowFinishingFlag = allow_finishing;}
128 
129  // Some selector can finish with whatever selection exists already.
130  bool allowFinishWithExistingSelection() const;
131  void setAllowFinishWithExistingSelection(bool allow);
132 
133  // If quick select is on, then the selection is immediately finished
134  // if we have secure selection off
135  bool allowQuickSelect() const
136  { return myAllowQuickSelect; }
137  void setAllowQuickSelect(bool on)
138  { myAllowQuickSelect = on; }
139 
141  { return myAllowEmptyQuickSelect; }
143  { myAllowEmptyQuickSelect = on; }
144 
145  /// Tells the selector about previous selection information that we still
146  /// want to display in the viewport, but which is not part of the current
147  /// selection operation.
148  void setPriorSelections(const UT_StringArray &paths,
149  const UT_StringArray &ids,
150  const OP3D_SelectionHandles &selections);
151 
152  // Did the selector just change the display flag? The selector sets
153  // this flag when it creates a sop (eg. a hide or a group sop) and
154  // sets its display flag. The state will check this flag when the state
155  // controller asks it if it just changed the display flag. This way,
156  // the selector can change the display flag without exiting the current
157  // state.
158  bool justDisplayedOp() const
159  { return myJustDisplayedOpFlag; }
160  void setJustDisplayedOp(bool on)
161  { myJustDisplayedOpFlag = on; }
162 
163  // Selectors resize the brush radius with the mouse wheel when appropriate.
164  int handleMouseWheelEvent(UI_Event *event) override;
165 
166  // Handle transitory keys to change the mouse cursor according to our
167  // selection mode.
168  bool handleTransitoryKey(const UI_Event &event,
169  int hotkey_id) override;
170 
171  const char *cursor() const override;
172 
173  void handleSelectionStyleChange(UI_Event *event);
174 
175  // Methods for setting user preferences
176  static bool getPickingMenuOn() { return thePickingMenuOn; }
177  static void setPickingMenuOn(bool val) { thePickingMenuOn = val; }
179  { return theAllowUseExistingSelection; }
181  { theAllowUseExistingSelection = val; }
182  static bool getSelectFullLoops()
183  { return theSelectFullLoops; }
184  static void setSelectFullLoops(bool val)
185  { theSelectFullLoops = val; }
186 
187 
188  // Converts a string to a GU_Detail pointer. The string will either be
189  // an object or sop path, or a path to a specific DOP simulation data.
190  static GU_ConstDetailHandle getGeometryFromPath(const char *path);
191  static OP_Node *getNodeFromPath(const char *path);
192  static const SIM_Object *getSimObjectFromPath(const char *path);
193  static const SIM_Data *getSimModifierFromPath(const char *path);
194 
195  // A utility method to get the string representation of a reference to
196  // the flood fill selection hotkey, for replacement by the bound keys.
197  static const char *getFloodFillSelectionHotkeyStringRef(
199  // A utility method to get the string representation of a refernce to
200  // the loop selection hotkey, for replacement by the bound keys.
201  static const char *getLoopSelectionHotkeyStringRef(
203 
204  // A utility method to determine if a particular transitory key is bound
205  // as a loop selection hotkey. The optional hotkey_id parameter is to
206  // allow it to be used transparently if using preemptive resolved events.
207  static bool isTransitoryLoopSelectionHotkey(
208  const UI_DeviceEvent &state,
209  int hotkey_id = 0);
210 
211  // A utility method to determine if the loop selection hotkey is pressed
212  // in the specified viewport.
213  static bool isTransitoryLoopSelectionHotkeyPressed(
214  DM_Viewport *viewport,
216 
217  // A utility method to show the loop selection hotkey message in the given
218  // workbench.
219  static void showLoopSelectionMessage(
220  DM_Workbench &workbench);
221 
222  static void showSelectionHintsMessage(
223  DM_Workbench &workbench);
224 
225  bool getStateParmNames(
226  UT_StringArray &ret,
227  const char* prefix = nullptr) override;
228  bool evalStateParm(
229  const char *name,
230  UT_StringHolder &ret) override;
231  bool setStateParm(
232  const char *name,
233  const UT_StringHolder &val) override;
234  bool pressStateButton(const char *name) override;
235 
236  class Proxy;
239 
240  // Drawable selection
241  bool canSelectDrawables() const override;
242 
243  void enableDrawableSelection(bool select_drawables);
244  void setDrawableMask(UT_StringArray const& drawable_mask);
245 
246 protected:
247  OP3D_View &viewer() { return (OP3D_View &)baseViewer(); }
248  const OP3D_View &viewer() const { return (OP3D_View &)baseViewer(); }
249 
250  DM_Workbench &workbench() { return *myWorkbench; }
251  const DM_Workbench &workbench() const { return *myWorkbench; }
252 
253  void setFinishedValuePtr(UI_Value *new_value)
254  { myFinishedValue = new_value; }
256  { return myFinishedValue; }
257 
258  void setLocatedValuePtr(UI_Value *new_value)
259  { myLocatedValue = new_value; }
261  { return myLocatedValue; }
262 
264  { mySelectionStyle = new_value; }
266  { return mySelectionStyle; }
268  {
269  if (mySelectionStyle)
270  return (DM_SelectionStyle)
271  (int)*mySelectionStyle;
272  else
273  return DM_STYLE_UNKNOWN;
274  }
275  void setVisiblePickPtr(UI_Value *new_value)
276  { myVisiblePickValue = new_value; }
278  { return myVisiblePickValue; }
279  bool getVisiblePick() const
280  {
281  if(myVisiblePickValue)
282  return (bool) *myVisiblePickValue;
283  return true;
284  }
285 
286  void setContainedPickPtr(UI_Value *new_value)
287  { myContainedPickValue = new_value; }
289  { return myContainedPickValue; }
290  bool getContainedPick() const
291  {
292  if(myContainedPickValue)
293  return (bool) *myContainedPickValue;
294  return false;
295  }
296 
297  void setSelectionRulePtr(UI_Value *new_value)
298  { mySelectionRule = new_value; }
300  { return mySelectionRule; }
302  {
303  if (mySelectionRule)
304  return (GU_SelectionRule)
305  (int)*mySelectionRule;
306  else
307  return GU_ReplaceSelect;
308  }
310  {
311  if (mySelectionRule)
312  *mySelectionRule = (int)srule;
313  }
314 
315  SI_Brush * getPickBrushPtr() const { return myPickBrush; }
316  SI_Brush * getPickLaserPtr() const { return myPickLaser; }
317  SI_Lasso * getPickLassoPtr() const { return myPickLasso; }
318 
319 
320  // returns true if box, lasso or paint selection is active.
321  bool isDragSelectActive() const;
322 
323  // Returns true if the selector needs to make an object selection because
324  // the viewer isn't currently pointed at the right network level.
325  virtual bool needObjectPick() const;
326 
327  // Checks whether our selector knows how to handle selections in the
328  // context of the current chosen op.
329  bool selectModeMatchesTemplateType();
330 
331  // Given a pick buffer (where the first entry of each pick is an op
332  // node id), set the viewer chosen op to the first picked node.
333  bool pickChosenOp(UT_Array<GR_PickRecord> &pick_records,
334  bool *changed = nullptr);
335 
336  // Given a pick record, return the GU_Detail that it refers to, and
337  // (optionally), the corresponding detail look.
338  GU_ConstDetailHandle getGeometryFromPickRecord(const GR_PickRecord &pick,
339  GUI_DetailLook **detail_look = nullptr);
340 
341  // Make the specified node into the chosen op for the viewer. Used by
342  // pickChosenOp. Made the function virtual so subclasses can do extra
343  // work once the switch is complete. Returns the new chosen op.
344  // Sets @c changed to @c true if the operator chosen is different from
345  // the one that was selected going in.
346  virtual OP_Node *switchToChosenOp(OP_Node *parent,
347  bool *changed = nullptr);
348 
349  // Save our state for undo.
350  virtual void saveForUndo();
351 
352  // Given a pick number (the first number in a pick buffer), return
353  // the name in name. Returns true if the pick number was able to
354  // be associated with a name, false otherwise.
355  virtual bool getPickName(const OP3D_PickId &pickid,
356  UT_String &name,
357  bool descriptivename) const = 0;
358 
359  // Enable box picking or lasso picking, depending on what's currently
360  // selected.
361  void enablePicker(UI_Event *event);
362  void disablePicker();
363 
364  void disableActivePicking() { myActivePicking = false; }
365  bool isActivePicking() const { return myActivePicking; }
366 
367  virtual void handleBoxPick(UI_Event *event);
368  virtual void activeBoxPick(UI_Event *event);
369  virtual void handleLassoPick(UI_Event *event);
370  virtual void activeLassoPick(UI_Event *event);
371  virtual void handleBrushPick(UI_Event *event);
372  virtual void activeBrushPick(UI_Event *event);
373  virtual void handleLaserPick(UI_Event *event);
374  virtual void activeLaserPick(UI_Event *event);
375  bool visibleSelectToggle(UI_Event *event,
376  const char *echo_hotkey);
377  bool containedSelectToggle(UI_Event *event,
378  const char *echo_hotkey);
379 
380  // Gets the current time from the OP_Director.
381  static fpreal getTime();
382 
383  /// @{
384  /// Obtains the proxy representative used as a reference holder to this
385  /// selector. This proxy gets invalidated when the selector gets deleted.
386  /// Invalidation clears the proxy's pointer to NULL, but the proxy's memory
387  /// stays valid, unlike the memory of this selector object.
388  ///
389  /// Sample usage:
390  /// void Subclass::method()
391  /// {
392  /// ProxyHandle this_proxy(getProxy());
393  /// methodThatMayDeleteThis();
394  /// if( !this_proxy->isValid() )
395  /// return; // abort
396  /// }
397  ProxyHandle getProxy() { return ProxyHandle(myProxy); }
398  ConstProxyHandle getProxy() const { return ConstProxyHandle(myProxy); }
399  /// @}
400 
401  // Drawable selection
402  const UT_StringArray& drawableMask() const override;
403  void onLocateDrawableSelection() override;
404 
405  unsigned drawablePickMask(unsigned pick_mask) const;
406  bool filterDrawable(const char* drawable_name) const;
407 
408 private:
409  Proxy *myProxy;
410  DM_Workbench *myWorkbench;
411 
412  UI_Value *myFinishedValue;
413  UI_Value *myLocatedValue;
414  UI_Value *mySelectionStyle;
415  UI_Value *myVisiblePickValue;
416  UI_Value *myContainedPickValue;
417  UI_Value *mySelectionRule;
418 
419  SI_RubberBox *myPickBox; // for box selection
420  SI_Lasso *myPickLasso; // for lasso selection
421  SI_Brush *myPickBrush; // for brush selection
422  SI_Brush *myPickLaser; // for laser selection
423 
424  DM_SelectMode myPreferredSelectMode;
425  bool myAllowDragging;
426  bool myAllowFinishingFlag;
427  bool myAllowFinishWithExistingSelection;
428  bool myAllowQuickSelect;
429  bool myAllowEmptyQuickSelect;
430  bool myJustDisplayedOpFlag;
431  bool myActivePicking;
432 
433  UT_StringMap<UT_IntArray> myPriorObjSelections;
434  bool myCreatedPriorSelections;
435 
436  static bool thePickingMenuOn;
437  static bool theAllowUseExistingSelection;
438  static bool theSelectFullLoops;
439 
440  // Drawable selection
441  bool myDrawableSelectableFlag;
442  UT_StringArray myDrawableMask;
443 };
444 
445 /// This reference counted proxy class allows code to check whether a
446 /// particular selector has been destroyed.
447 ///
448 /// See OP3D_InputSelectorBase::getProxy() for usage details.
449 class OP3D_API OP3D_InputSelectorBase::Proxy
450 {
451 public:
452  /// Returns true if the proxy is still pointing to a valid selector.
453  bool isValid() const
454  { return mySelector != NULL; }
455 
456  /// @private
457  /// This interface should only be used by the intrusive pointer handles
458  inline void intrusive_ptr_add_ref() const { incref(); }
459  inline void intrusive_ptr_release() const { decref(); }
460  /// @}
461 private:
462  explicit Proxy(OP3D_InputSelectorBase *selector);
463  ~Proxy();
464 
465  /// Makes the selector reference invalid. This is necessary to do when the
466  /// selector gets deleted.
467  void invalidate(); // only GA_AttributeSet calls it
468  /// Ask the proxy to register a new reference, which essentially
469  /// increments the reference counter.
470  void incref() const;
471  /// Ask the proxy to unregister a reference, which essentially
472  /// decrements the reference counter. When the reference decreases to
473  /// zero the proxy object gets deleted.
474  void decref() const;
475 
476  OP3D_InputSelectorBase *mySelector;
477  mutable SYS_AtomicInt32 myReferenceCount;
478 
480 };
481 
482 /// @{
483 /// Boost function callbacks for referencing and unreferencing the proxy.
484 static inline void
485 intrusive_ptr_add_ref(const OP3D_InputSelectorBase::Proxy *proxy)
486 {
487  proxy->intrusive_ptr_add_ref();
488 }
489 
490 static inline void
491 intrusive_ptr_release(const OP3D_InputSelectorBase::Proxy *proxy)
492 {
493  proxy->intrusive_ptr_release();
494 }
495 /// @}
496 
497 #endif
BM_View & baseViewer()
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
static int compare(const OP3D_PickId *id1, const OP3D_PickId *id2)
void setSelectionStylePtr(UI_Value *new_value)
virtual void setViewer(BM_View *viewer)
UT_Array< GU_SelectionHandle > OP3D_SelectionHandles
UI_Value * getSelectionRulePtr() const
UI_Value * getVisiblePickPtr() const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
OP3D_SelectionAction
UI_Value * getFinishedValuePtr() const
DM_SelectMode getPreferredSelectMode() const
void setAllowFinishing(bool allow_finishing)
GLint y
Definition: glcorearb.h:103
virtual const UT_StringArray & drawableMask() const
virtual bool handleTransitoryKey(const UI_Event &event, int)
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
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
Definition: ImathFun.h:84
bool isValid() const
Returns true if the proxy is still pointing to a valid selector.
struct _cl_event * event
Definition: glcorearb.h:2961
virtual bool setStateParm(const char *name, const UT_StringHolder &val)
Definition: core.h:760
virtual bool canSelectDrawables() const
void setFinishedValuePtr(UI_Value *new_value)
void setPreferredSelectMode(DM_SelectMode selmode)
GU_SelectionRule
Definition: GU_SelectType.h:40
UI_Value * getContainedPickPtr() const
Wrapper around hboost::intrusive_ptr.
static void setPickingMenuOn(bool val)
DM_SelectMode
Definition: DM_Defines.h:113
static void setAllowUseExistingSelection(bool val)
GLuint const GLchar * name
Definition: glcorearb.h:786
bool operator==(const OP3D_PickId &cmp) const
SI_Brush * getPickBrushPtr() const
virtual int handleMouseWheelEvent(UI_Event *event)
GLint GLenum GLint x
Definition: glcorearb.h:409
const DM_Workbench & workbench() const
void setContainedPickPtr(UI_Value *new_value)
bool operator!=(const OP3D_PickId &cmp) const
DM_SelectionStyle selectionStyle() const
void setVisiblePickPtr(UI_Value *new_value)
UI_Value * getSelectionStylePtr() const
void selectionRule(GU_SelectionRule srule)
SI_Lasso * getPickLassoPtr() const
fpreal64 fpreal
Definition: SYS_Types.h:277
GU_SelectionRule selectionRule() const
virtual void onLocateDrawableSelection()
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define OP3D_API
Definition: OP3D_API.h:10
virtual void startSelecting()
UT_IntrusivePtr< Proxy > ProxyHandle
virtual UI_Feel * getCustomToolbox() const
GLboolean r
Definition: glcorearb.h:1222
virtual void stopSelecting()
static bool getAllowUseExistingSelection()
void setSelectionRulePtr(UI_Value *new_value)
GLuint * ids
Definition: glcorearb.h:652
virtual bool evalStateParm(const char *name, UT_StringHolder &ret)
SI_Brush * getPickLaserPtr() const
UI_Value * getLocatedValuePtr() const
static void setSelectFullLoops(bool val)
UT_IntrusivePtr< const Proxy > ConstProxyHandle
DM_SelectionStyle
Definition: DM_Defines.h:54
void setLocatedValuePtr(UI_Value *new_value)
virtual void doRender(RE_Render *r, int x, int y, int ghost)
virtual bool pressStateButton(const char *name)
virtual const char * cursor() const