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 
138  { return myAllowEmptyQuickSelect; }
140  { myAllowEmptyQuickSelect = on; }
141 
142  /// Tells the selector about previous selection information that we still
143  /// want to display in the viewport, but which is not part of the current
144  /// selection operation.
145  void setPriorSelections(const UT_StringArray &paths,
146  const UT_StringArray &ids,
147  const OP3D_SelectionHandles &selections);
148 
149  // Did the selector just change the display flag? The selector sets
150  // this flag when it creates a sop (eg. a hide or a group sop) and
151  // sets its display flag. The state will check this flag when the state
152  // controller asks it if it just changed the display flag. This way,
153  // the selector can change the display flag without exiting the current
154  // state.
155  bool justDisplayedOp() const
156  { return myJustDisplayedOpFlag; }
157  void setJustDisplayedOp(bool on)
158  { myJustDisplayedOpFlag = on; }
159 
160  // Selectors resize the brush radius with the mouse wheel when appropriate.
161  virtual int handleMouseWheelEvent(UI_Event *event);
162 
163  // Handle transitory keys to change the mouse cursor according to our
164  // selection mode.
165  virtual bool handleTransitoryKey(const UI_Event &event);
166 
167  virtual const char *cursor() const;
168 
169  void handleSelectionStyleChange(UI_Event *event);
170 
171  // Methods for setting user preferences
172  static bool getPickingMenuOn() { return thePickingMenuOn; }
173  static void setPickingMenuOn(bool val) { thePickingMenuOn = val; }
175  { return theAllowUseExistingSelection; }
177  { theAllowUseExistingSelection = val; }
178  static bool getSelectFullLoops()
179  { return theSelectFullLoops; }
180  static void setSelectFullLoops(bool val)
181  { theSelectFullLoops = val; }
182 
183 
184  // Converts a string to a GU_Detail pointer. The string will either be
185  // an object or sop path, or a path to a specific DOP simulation data.
186  static GU_ConstDetailHandle getGeometryFromPath(const char *path);
187  static OP_Node *getNodeFromPath(const char *path);
188  static const SIM_Object *getSimObjectFromPath(const char *path);
189  static const SIM_Data *getSimModifierFromPath(const char *path);
190 
191  // A utility method to get the string representation of the flood fill
192  // selection hotkey, if any is set.
193  static const char *getFloodFillSelectionHotkeyStringRepr();
194  // A utility method to get the string representation of the loop selection
195  // hotkey, if any is set.
196  static const char *getLoopSelectionHotkeyStringRepr();
197 
198  // A utility method to determine if a particular transitory key is bound
199  // as a loop selection hotkey.
200  static bool isTransitoryLoopSelectionHotkey(
201  const UI_DeviceEvent &state);
202 
203  // A utility method to determine if the loop selection hotkey is pressed
204  // in the specified viewport.
205  static bool isTransitoryLoopSelectionHotkeyPressed(
206  DM_Viewport *viewport);
207 
208  // A utility method to show the loop selection hotkey message in the given
209  // workbench.
210  static void showLoopSelectionMessage(
211  DM_Workbench &workbench);
212 
213  static void showSelectionHintsMessage(
214  DM_Workbench &workbench);
215 
216  virtual bool getStateParmNames(UT_StringArray &ret, const char* prefix=nullptr );
217  virtual bool evalStateParm(const char *name, UT_StringHolder &ret);
218  virtual bool setStateParm(const char *name, const UT_StringHolder &val);
219  virtual bool pressStateButton(const char *name);
220 
221  class Proxy;
224 
225 protected:
226  OP3D_View &viewer() { return (OP3D_View &)baseViewer(); }
227  const OP3D_View &viewer() const { return (OP3D_View &)baseViewer(); }
228 
229  DM_Workbench &workbench() { return *myWorkbench; }
230  const DM_Workbench &workbench() const { return *myWorkbench; }
231 
232  void setFinishedValuePtr(UI_Value *new_value)
233  { myFinishedValue = new_value; }
235  { return myFinishedValue; }
236 
238  { mySelectionStyle = new_value; }
240  { return mySelectionStyle; }
242  {
243  if (mySelectionStyle)
244  return (DM_SelectionStyle)
245  (int)*mySelectionStyle;
246  else
247  return DM_STYLE_UNKNOWN;
248  }
249  void setVisiblePickPtr(UI_Value *new_value)
250  { myVisiblePickValue = new_value; }
252  { return myVisiblePickValue; }
253  bool getVisiblePick() const
254  {
255  if(myVisiblePickValue)
256  return (bool) *myVisiblePickValue;
257  return true;
258  }
259 
260  void setContainedPickPtr(UI_Value *new_value)
261  { myContainedPickValue = new_value; }
263  { return myContainedPickValue; }
264  bool getContainedPick() const
265  {
266  if(myContainedPickValue)
267  return (bool) *myContainedPickValue;
268  return false;
269  }
270 
271  void setSelectionRulePtr(UI_Value *new_value)
272  { mySelectionRule = new_value; }
274  { return mySelectionRule; }
276  {
277  if (mySelectionRule)
278  return (GU_SelectionRule)
279  (int)*mySelectionRule;
280  else
281  return GU_ReplaceSelect;
282  }
284  {
285  if (mySelectionRule)
286  *mySelectionRule = (int)srule;
287  }
288 
289  SI_Brush * getPickBrushPtr() const { return myPickBrush; }
290  SI_Brush * getPickLaserPtr() const { return myPickLaser; }
291  SI_Lasso * getPickLassoPtr() const { return myPickLasso; }
292 
293 
294  // returns true if box, lasso or paint selection is active.
295  bool isDragSelectActive() const;
296 
297  // Returns true if the selector needs to make an object selection because
298  // the viewer isn't currently pointed at the right network level.
299  virtual bool needObjectPick() const;
300 
301  // Checks whether our selector knows how to handle selections in the
302  // context of the current chosen op.
303  bool selectModeMatchesTemplateType();
304 
305  // Given a pick buffer (where the first entry of each pick is an op
306  // node id), set the viewer chosen op to the first picked node.
307  bool pickChosenOp(UT_Array<GR_PickRecord> &pick_records,
308  bool *changed = nullptr);
309 
310  // Given a pick record, return the GU_Detail that it refers to, and
311  // (optionally), the corresponding detail look.
312  GU_ConstDetailHandle getGeometryFromPickRecord(const GR_PickRecord &pick,
313  GUI_DetailLook **detail_look = nullptr);
314 
315  // Make the specified node into the chosen op for the viewer. Used by
316  // pickChosenOp. Made the function virtual so subclasses can do extra
317  // work once the switch is complete. Returns the new chosen op.
318  // Sets @c changed to @c true if the operator chosen is different from
319  // the one that was selected going in.
320  virtual OP_Node *switchToChosenOp(OP_Node *parent,
321  bool *changed = nullptr);
322 
323  // Save our state for undo.
324  virtual void saveForUndo();
325 
326  // Given a pick number (the first number in a pick buffer), return
327  // the name in name. Returns true if the pick number was able to
328  // be associated with a name, false otherwise.
329  virtual bool getPickName(const OP3D_PickId &pickid,
330  UT_String &name,
331  bool descriptivename) const = 0;
332 
333  // Enable box picking or lasso picking, depending on what's currently
334  // selected.
335  void enablePicker(UI_Event *event);
336  void disablePicker();
337 
338  void disableActivePicking() { myActivePicking = false; }
339  bool isActivePicking() const { return myActivePicking; }
340 
341  virtual void handleBoxPick(UI_Event *event);
342  virtual void activeBoxPick(UI_Event *event);
343  virtual void handleLassoPick(UI_Event *event);
344  virtual void activeLassoPick(UI_Event *event);
345  virtual void handleBrushPick(UI_Event *event);
346  virtual void activeBrushPick(UI_Event *event);
347  virtual void handleLaserPick(UI_Event *event);
348  virtual void activeLaserPick(UI_Event *event);
349  bool visibleSelectToggle(UI_Event *event,
350  const char *echo_hotkey);
351  bool containedSelectToggle(UI_Event *event,
352  const char *echo_hotkey);
353 
354  // Gets the current time from the OP_Director.
355  static fpreal getTime();
356 
357  /// @{
358  /// Obtains the proxy representative used as a reference holder to this
359  /// selector. This proxy gets invalidated when the selector gets deleted.
360  /// Invalidation clears the proxy's pointer to NULL, but the proxy's memory
361  /// stays valid, unlike the memory of this selector object.
362  ///
363  /// Sample usage:
364  /// void Subclass::method()
365  /// {
366  /// ProxyHandle this_proxy(getProxy());
367  /// methodThatMayDeleteThis();
368  /// if( !this_proxy->isValid() )
369  /// return; // abort
370  /// }
371  ProxyHandle getProxy() { return ProxyHandle(myProxy); }
372  ConstProxyHandle getProxy() const { return ConstProxyHandle(myProxy); }
373  /// @}
374 
375 private:
376  Proxy *myProxy;
377  DM_Workbench *myWorkbench;
378 
379  UI_Value *myFinishedValue;
380  UI_Value *mySelectionStyle;
381  UI_Value *myVisiblePickValue;
382  UI_Value *myContainedPickValue;
383  UI_Value *mySelectionRule;
384 
385  SI_RubberBox *myPickBox; // for box selection
386  SI_Lasso *myPickLasso; // for lasso selection
387  SI_Brush *myPickBrush; // for brush selection
388  SI_Brush *myPickLaser; // for laser selection
389 
390  DM_SelectMode myPreferredSelectMode;
391  bool myAllowDragging;
392  bool myAllowFinishingFlag;
393  bool myAllowFinishWithExistingSelection;
394  bool myAllowQuickSelect;
395  bool myAllowEmptyQuickSelect;
396  bool myJustDisplayedOpFlag;
397  bool myActivePicking;
398 
399  UT_StringMap<UT_IntArray> myPriorObjSelections;
400  bool myCreatedPriorSelections;
401 
402  static bool thePickingMenuOn;
403  static bool theAllowUseExistingSelection;
404  static bool theSelectFullLoops;
405 };
406 
407 /// This reference counted proxy class allows code to check whether a
408 /// particular selector has been destroyed.
409 ///
410 /// See OP3D_InputSelectorBase::getProxy() for usage details.
411 class OP3D_API OP3D_InputSelectorBase::Proxy
412 {
413 public:
414  /// Returns true if the proxy is still pointing to a valid selector.
415  bool isValid() const
416  { return mySelector != NULL; }
417 
418  /// @private
419  /// This interface should only be used by the intrusive pointer handles
420  inline void intrusive_ptr_add_ref() const { incref(); }
421  inline void intrusive_ptr_release() const { decref(); }
422  /// @}
423 private:
424  explicit Proxy(OP3D_InputSelectorBase *selector);
425  ~Proxy();
426 
427  /// Makes the selector reference invalid. This is necessary to do when the
428  /// selector gets deleted.
429  void invalidate(); // only GA_AttributeSet calls it
430  /// Ask the proxy to register a new reference, which essentially
431  /// increments the reference counter.
432  void incref() const;
433  /// Ask the proxy to unregister a reference, which essentially
434  /// decrements the reference counter. When the reference decreases to
435  /// zero the proxy object gets deleted.
436  void decref() const;
437 
438  OP3D_InputSelectorBase *mySelector;
439  mutable SYS_AtomicInt32 myReferenceCount;
440 
442 };
443 
444 /// @{
445 /// Boost function callbacks for referencing and unreferencing the proxy.
446 static inline void
447 intrusive_ptr_add_ref(const OP3D_InputSelectorBase::Proxy *proxy)
448 {
449  proxy->intrusive_ptr_add_ref();
450 }
451 
452 static inline void
453 intrusive_ptr_release(const OP3D_InputSelectorBase::Proxy *proxy)
454 {
455  proxy->intrusive_ptr_release();
456 }
457 /// @}
458 
459 #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:113
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: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:13589
virtual const char * cursor() const