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 <UI/UI_Value.h>
24 #include <UT/UT_String.h>
25 #include <GA/GA_Types.h>
26 
27 class SIM_Data;
28 class SIM_Object;
29 class GU_Detail;
30 class OP_Node;
32 class UI_Menu;
33 class UI_Feel;
34 class UI_Event;
35 class SI_RubberBox;
36 class SI_Lasso;
37 class SI_Brush;
38 class DM_Viewport;
39 class DM_Workbench;
40 class GUI_DetailLook;
41 class OP3D_View;
42 
44 {
48 };
49 
51 {
52 public:
53  OP3D_PickId();
54  OP3D_PickId(int lookindex, int detailindex);
55  ~OP3D_PickId();
56 
57  bool operator==(const OP3D_PickId &cmp) const;
58  bool operator!=(const OP3D_PickId &cmp) const;
59  static int compare(const OP3D_PickId *id1, const OP3D_PickId *id2);
60 
63 };
64 
67 
69 {
70 public:
71  OP3D_InputSelectorBase(OP3D_View &viewer,
72  PI_SelectorTemplate &templ);
73  virtual ~OP3D_InputSelectorBase();
74 
75  // This method allows the resource manager can set the workbench to
76  // something different if a selector is reused. It should not be used
77  // otherwise. A nil pointer is allowed so the select can remove any
78  // of its interests. However, methods of the selector should never be
79  // called when its workbench is nil. The method is virtual so
80  // descendants can also have a chance to clean up.
81  //
82  // Note that setSelectionUIValues must be called after calling setViewer()
83  virtual void setViewer(BM_View *viewer);
84 
85  // The selector needs to be notified when it starts/stops selecting
86  // so it can add/remove interests (the selection type, etc.).
87  virtual void startSelecting();
88  virtual void stopSelecting();
89 
90  // Use this opportunity to render prior object selections.
91  virtual void doRender(RE_Render *r, int x, int y, int ghost);
92 
93  // This UI value changes when the selector has finished selecting. The
94  // state that owns the selector adds an interest in this event to know
95  // when the selector is finished.
97  { return *myFinishedValue; }
98  const UI_Value &finishedValue() const
99  { return *myFinishedValue; }
100 
101  virtual UI_Feel *getCustomToolbox() const;
102 
104  { myPreferredSelectMode = selmode; }
106  { return myPreferredSelectMode; }
107 
108  // If the selector doesn't allow multiple selection, then at most one
109  // object will appear in the pickedNodes() array.
110  bool allowDragging() const
111  { return myAllowDragging; }
112  void setAllowDragging(bool on)
113  { myAllowDragging = on; }
114 
115  // Some states (like the select state) don't ever want their selector
116  // to finish.
117  bool allowFinishing() const
118  { return myAllowFinishingFlag; }
119  void setAllowFinishing(bool allow_finishing)
120  { myAllowFinishingFlag = allow_finishing;}
121 
122  // Some selector can finish with whatever selection exists already.
123  bool allowFinishWithExistingSelection() const;
124  void setAllowFinishWithExistingSelection(bool allow);
125 
126  // If quick select is on, then the selection is immediately finished
127  // if we have secure selection off
128  bool allowQuickSelect() const
129  { return myAllowQuickSelect; }
130  void setAllowQuickSelect(bool on)
131  { myAllowQuickSelect = on; }
132 
133  /// Tells the selector about previous selection information that we still
134  /// want to display in the viewport, but which is not part of the current
135  /// selection operation.
136  void setPriorSelections(const UT_StringArray &paths,
137  const UT_StringArray &ids,
138  const OP3D_SelectionHandles &selections);
139 
140  // Did the selector just change the display flag? The selector sets
141  // this flag when it creates a sop (eg. a hide or a group sop) and
142  // sets its display flag. The state will check this flag when the state
143  // controller asks it if it just changed the display flag. This way,
144  // the selector can change the display flag without exiting the current
145  // state.
146  bool justDisplayedOp() const
147  { return myJustDisplayedOpFlag; }
148  void setJustDisplayedOp(bool on)
149  { myJustDisplayedOpFlag = on; }
150 
151  // Selectors resize the brush radius with the mouse wheel when appropriate.
152  virtual int handleMouseWheelEvent(UI_Event *event);
153 
154  // Handle transitory keys to change the mouse cursor according to our
155  // selection mode.
156  virtual bool handleTransitoryKey(const UI_Event &event);
157 
158  virtual const char *cursor() const;
159 
160  void handleSelectionStyleChange(UI_Event *event);
161 
162  // Methods for setting user preferences
163  static bool getPickingMenuOn() { return thePickingMenuOn; }
164  static void setPickingMenuOn(bool val) { thePickingMenuOn = val; }
166  { return theAllowUseExistingSelection; }
168  { theAllowUseExistingSelection = val; }
169  static bool getSelectFullLoops()
170  { return theSelectFullLoops; }
171  static void setSelectFullLoops(bool val)
172  { theSelectFullLoops = val; }
173 
174 
175  // Converts a string to a GU_Detail pointer. The string will either be
176  // an object or sop path, or a path to a specific DOP simulation data.
177  static GU_Detail *getGeometryFromPath(const char *path);
178  static OP_Node *getNodeFromPath(const char *path);
179  static const SIM_Object *getSimObjectFromPath(const char *path);
180  static const SIM_Data *getSimModifierFromPath(const char *path);
181 
182  // A utility method to get the string representation of the loop selection
183  // hotkey, if any is set.
184  static const char *getLoopSelectionHotkeyStringRepr();
185 
186  // A utility method to determine if a particular transitory key is bound
187  // as a loop selection hotkey.
188  static bool isTransitoryLoopSelectionHotkey(
189  const UI_DeviceEvent &state);
190 
191  // A utility method to determine if the loop selection hotkey is pressed
192  // in the specified viewport.
193  static bool isTransitoryLoopSelectionHotkeyPressed(
194  DM_Viewport *viewport);
195 
196  // A utility method to show the loop selection hotkey message in the given
197  // workbench.
198  static void showLoopSelectionMessage(
199  DM_Workbench &workbench);
200 
201  virtual bool getStateParmNames(UT_StringArray &ret, const char* prefix=nullptr );
202  virtual bool evalStateParm(const char *name, UT_StringHolder &ret);
203  virtual bool setStateParm(const char *name, const UT_StringHolder &val);
204  virtual bool pressStateButton(const char *name);
205 
206 protected:
207  OP3D_View &viewer() { return (OP3D_View &)baseViewer(); }
208  const OP3D_View &viewer() const { return (OP3D_View &)baseViewer(); }
209 
210  DM_Workbench &workbench() { return *myWorkbench; }
211  const DM_Workbench &workbench() const { return *myWorkbench; }
212 
213  void setFinishedValuePtr(UI_Value *new_value)
214  { myFinishedValue = new_value; }
216  { return myFinishedValue; }
217 
219  { mySelectionStyle = new_value; }
221  { return mySelectionStyle; }
223  {
224  if (mySelectionStyle)
225  return (DM_SelectionStyle)
226  (int)*mySelectionStyle;
227  else
228  return DM_STYLE_UNKNOWN;
229  }
230  void setVisiblePickPtr(UI_Value *new_value)
231  { myVisiblePickValue = new_value; }
233  { return myVisiblePickValue; }
234  bool getVisiblePick() const
235  {
236  if(myVisiblePickValue)
237  return (bool) *myVisiblePickValue;
238  return true;
239  }
240 
241  void setContainedPickPtr(UI_Value *new_value)
242  { myContainedPickValue = new_value; }
244  { return myContainedPickValue; }
245  bool getContainedPick() const
246  {
247  if(myContainedPickValue)
248  return (bool) *myContainedPickValue;
249  return false;
250  }
251 
252  void setSelectionRulePtr(UI_Value *new_value)
253  { mySelectionRule = new_value; }
255  { return mySelectionRule; }
257  {
258  if (mySelectionRule)
259  return (GU_SelectionRule)
260  (int)*mySelectionRule;
261  else
262  return GU_ReplaceSelect;
263  }
265  {
266  if (mySelectionRule)
267  *mySelectionRule = (int)srule;
268  }
269 
270  SI_Brush * getPickBrushPtr() const { return myPickBrush; }
271  SI_Brush * getPickLaserPtr() const { return myPickLaser; }
272  SI_Lasso * getPickLassoPtr() const { return myPickLasso; }
273 
274 
275  // returns true if box, lasso or paint selection is active.
276  bool isDragSelectActive() const;
277 
278  // Returns true if the selector needs to make an object selection because
279  // the viewer isn't currently pointed at the right network level.
280  virtual bool needObjectPick() const;
281 
282  // Checks whether our selector knows how to handle selections in the
283  // context of the current chosen op.
284  bool selectModeMatchesTemplateType();
285 
286  // Given a pick buffer (where the first entry of each pick is an op
287  // node id), set the viewer chosen op to the first picked node.
288  bool pickChosenOp(UT_Array<GR_PickRecord> &pick_records,
289  bool *changed = nullptr);
290 
291  // Given a pick record, return the GU_Detail that it refers to, and
292  // (optionally), the corresponding detail look.
293  const GU_Detail *getGeometryFromPickRecord(const GR_PickRecord &pick,
294  GUI_DetailLook **detail_look = nullptr);
295 
296  // Make the specified node into the chosen op for the viewer. Used by
297  // pickChosenOp. Made the function virtual so subclasses can do extra
298  // work once the switch is complete. Returns the new chosen op.
299  // Sets @c changed to @c true if the operator chosen is different from
300  // the one that was selected going in.
301  virtual OP_Node *switchToChosenOp(OP_Node *parent,
302  bool *changed = nullptr);
303 
304  // Save our state for undo.
305  virtual void saveForUndo();
306 
307  // Given a pick number (the first number in a pick buffer), return
308  // the name in name. Returns true if the pick number was able to
309  // be associated with a name, false otherwise.
310  virtual bool getPickName(const OP3D_PickId &pickid,
311  UT_String &name,
312  bool descriptivename) const = 0;
313 
314  // Enable box picking or lasso picking, depending on what's currently
315  // selected.
316  void enablePicker(UI_Event *event);
317  void disablePicker();
318 
319  void disableActivePicking() { myActivePicking = false; }
320  bool isActivePicking() const { return myActivePicking; }
321 
322  virtual void handleBoxPick(UI_Event *event);
323  virtual void activeBoxPick(UI_Event *event);
324  virtual void handleLassoPick(UI_Event *event);
325  virtual void activeLassoPick(UI_Event *event);
326  virtual void handleBrushPick(UI_Event *event);
327  virtual void activeBrushPick(UI_Event *event);
328  virtual void handleLaserPick(UI_Event *event);
329  virtual void activeLaserPick(UI_Event *event);
330  bool visibleSelectToggle(UI_Event *event,
331  const char *echo_hotkey);
332  bool containedSelectToggle(UI_Event *event,
333  const char *echo_hotkey);
334 
335  // Gets the current time from the OP_Director.
336  static fpreal getTime();
337 
338 private:
339  DM_Workbench *myWorkbench;
340 
341  UI_Value *myFinishedValue;
342  UI_Value *mySelectionStyle;
343  UI_Value *myVisiblePickValue;
344  UI_Value *myContainedPickValue;
345  UI_Value *mySelectionRule;
346 
347  SI_RubberBox *myPickBox; // for box selection
348  SI_Lasso *myPickLasso; // for lasso selection
349  SI_Brush *myPickBrush; // for brush selection
350  SI_Brush *myPickLaser; // for laser selection
351 
352  DM_SelectMode myPreferredSelectMode;
353  bool myAllowDragging;
354  bool myAllowFinishingFlag;
355  bool myAllowFinishWithExistingSelection;
356  bool myAllowQuickSelect;
357  bool myJustDisplayedOpFlag;
358  bool myActivePicking;
359 
360  UT_StringMap<UT_IntArray> myPriorObjSelections;
361  bool myCreatedPriorSelections;
362 
363  static bool thePickingMenuOn;
364  static bool theAllowUseExistingSelection;
365  static bool theSelectFullLoops;
366 };
367 
368 #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
virtual bool handleTransitoryKey(const UI_Event &event)
DM_SelectMode getPreferredSelectMode() const
void setAllowFinishing(bool allow_finishing)
GLint y
Definition: glcorearb.h:102
GLuint * ids
Definition: glcorearb.h:651
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
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
static void setPickingMenuOn(bool val)
DM_SelectMode
Definition: DM_Defines.h:110
static void setAllowUseExistingSelection(bool val)
GLuint const GLchar * name
Definition: glcorearb.h:785
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
double fpreal
Definition: SYS_Types.h:270
void setVisiblePickPtr(UI_Value *new_value)
UI_Value * getSelectionStylePtr() const
typedef int
Definition: png.h:1175
void selectionRule(GU_SelectionRule srule)
SI_Lasso * getPickLassoPtr() const
GU_SelectionRule selectionRule() const
GLint GLenum GLint x
Definition: glcorearb.h:408
GLuint GLfloat * val
Definition: glcorearb.h:1607
#define OP3D_API
Definition: OP3D_API.h:10
virtual void startSelecting()
virtual UI_Feel * getCustomToolbox() const
GLboolean r
Definition: glcorearb.h:1221
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)
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)
virtual const char * cursor() const