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