HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  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  // Selectors respond to keyboard events to know when to finish a selection
155  // stage and possibly enter the next.
156  virtual int handleKeyEvent(UI_Event *event,
157  DM_Viewport &viewport) = 0;
158 
159  // Handle transitory keys to change the mouse cursor according to our
160  // selection mode.
161  virtual bool handleTransitoryKey(const UI_Event &event);
162 
163  // Return the feel containing the RMB menu. Subclasses implement this.
164  virtual UI_Menu *getSelectorMenu() const = 0;
165  virtual UI_Menu *getSelectorHotkeyMenu() const
166  { return 0; }
167 
168  virtual const char *cursor() const;
169 
170  void handleSelectionStyleChange(UI_Event *event);
171 
172  // Methods for setting user preferences
173  static bool getPickingMenuOn() { return thePickingMenuOn; }
174  static void setPickingMenuOn(bool val) { thePickingMenuOn = val; }
176  { return theAllowUseExistingSelection; }
178  { theAllowUseExistingSelection = val; }
179  static bool getSelectFullLoops()
180  { return theSelectFullLoops; }
181  static void setSelectFullLoops(bool val)
182  { theSelectFullLoops = val; }
183 
184 
185  // Converts a string to a GU_Detail pointer. The string will either be
186  // an object or sop path, or a path to a specific DOP simulation data.
187  static GU_Detail *getGeometryFromPath(const char *path);
188  static OP_Node *getNodeFromPath(const char *path);
189  static const SIM_Object *getSimObjectFromPath(const char *path);
190  static const SIM_Data *getSimModifierFromPath(const char *path);
191 
192  // A utility method to get the string representation of the loop selection
193  // hotkey, if any is set.
194  static const char *getLoopSelectionHotkeyStringRepr();
195 
196  // A utility method to determine if a particular transitory key is bound
197  // as a loop selection hotkey.
198  static bool isTransitoryLoopSelectionHotkey(
199  const UI_DeviceEvent &state);
200 
201  // A utility method to determine if the loop selection hotkey is pressed
202  // in the specified viewport.
203  static bool isTransitoryLoopSelectionHotkeyPressed(
204  DM_Viewport *viewport);
205 
206  // A utility method to show the loop selection hotkey message in the given
207  // workbench.
208  static void showLoopSelectionMessage(
209  DM_Workbench &workbench);
210 
211 protected:
212  OP3D_View &viewer() { return (OP3D_View &)baseViewer(); }
213  const OP3D_View &viewer() const { return (OP3D_View &)baseViewer(); }
214 
215  DM_Workbench &workbench() { return *myWorkbench; }
216  const DM_Workbench &workbench() const { return *myWorkbench; }
217 
218  void setFinishedValuePtr(UI_Value *new_value)
219  { myFinishedValue = new_value; }
221  { return myFinishedValue; }
222 
224  { mySelectionStyle = new_value; }
226  { return mySelectionStyle; }
228  {
229  if (mySelectionStyle)
230  return (DM_SelectionStyle)
231  (int)*mySelectionStyle;
232  else
233  return DM_STYLE_UNKNOWN;
234  }
235  void setVisiblePickPtr(UI_Value *new_value)
236  { myVisiblePickValue = new_value; }
238  { return myVisiblePickValue; }
239  bool getVisiblePick() const
240  {
241  if(myVisiblePickValue)
242  return (bool) *myVisiblePickValue;
243  return true;
244  }
245 
246  void setContainedPickPtr(UI_Value *new_value)
247  { myContainedPickValue = new_value; }
249  { return myContainedPickValue; }
250  bool getContainedPick() const
251  {
252  if(myContainedPickValue)
253  return (bool) *myContainedPickValue;
254  return false;
255  }
256 
257  void setSelectionRulePtr(UI_Value *new_value)
258  { mySelectionRule = new_value; }
260  { return mySelectionRule; }
262  {
263  if (mySelectionRule)
264  return (GU_SelectionRule)
265  (int)*mySelectionRule;
266  else
267  return GU_ReplaceSelect;
268  }
270  {
271  if (mySelectionRule)
272  *mySelectionRule = (int)srule;
273  }
274 
275  SI_Brush * getPickBrushPtr() const { return myPickBrush; }
276  SI_Brush * getPickLaserPtr() const { return myPickLaser; }
277  SI_Lasso * getPickLassoPtr() const { return myPickLasso; }
278 
279 
280  // returns true if box, lasso or paint selection is active.
281  bool isDragSelectActive() const;
282 
283  // Returns true if the selector needs to make an object selection because
284  // the viewer isn't currently pointed at the right network level.
285  virtual bool needObjectPick() const;
286 
287  // Checks whether our selector knows how to handle selections in the
288  // context of the current chosen op.
289  bool selectModeMatchesTemplateType();
290 
291  // Given a pick buffer (where the first entry of each pick is an op
292  // node id), set the viewer chosen op to the first picked node.
293  bool pickChosenOp(UT_Array<GR_PickRecord> &pick_records,
294  bool *changed = nullptr);
295 
296  // Given a pick record, return the GU_Detail that it refers to, and
297  // (optionally), the corresponding detail look.
298  const GU_Detail *getGeometryFromPickRecord(const GR_PickRecord &pick,
299  GUI_DetailLook **detail_look = nullptr);
300 
301  // Make the specified node into the chosen op for the viewer. Used by
302  // pickChosenOp. Made the function virtual so subclasses can do extra
303  // work once the switch is complete. Returns the new chosen op.
304  // Sets @c changed to @c true if the operator chosen is different from
305  // the one that was selected going in.
306  virtual OP_Node *switchToChosenOp(OP_Node *parent,
307  bool *changed = nullptr);
308 
309  // Save our state for undo.
310  virtual void saveForUndo();
311 
312  // Given a pick number (the first number in a pick buffer), return
313  // the name in name. Returns true if the pick number was able to
314  // be associated with a name, false otherwise.
315  virtual bool getPickName(const OP3D_PickId &pickid,
316  UT_String &name,
317  bool descriptivename) const = 0;
318 
319  // Enable box picking or lasso picking, depending on what's currently
320  // selected.
321  void enablePicker(UI_Event *event);
322  void disablePicker();
323 
324  void disableActivePicking() { myActivePicking = false; }
325  bool isActivePicking() const { return myActivePicking; }
326 
327  virtual void handleBoxPick(UI_Event *event);
328  virtual void activeBoxPick(UI_Event *event);
329  virtual void handleLassoPick(UI_Event *event);
330  virtual void activeLassoPick(UI_Event *event);
331  virtual void handleBrushPick(UI_Event *event);
332  virtual void activeBrushPick(UI_Event *event);
333  virtual void handleLaserPick(UI_Event *event);
334  virtual void activeLaserPick(UI_Event *event);
335  bool visibleSelectToggle(UI_Event *event);
336  bool containedSelectToggle(UI_Event *event);
337 
338  // Gets the current time from the OP_Director.
339  static fpreal getTime();
340 
341 private:
342  DM_Workbench *myWorkbench;
343 
344  UI_Value *myFinishedValue;
345  UI_Value *mySelectionStyle;
346  UI_Value *myVisiblePickValue;
347  UI_Value *myContainedPickValue;
348  UI_Value *mySelectionRule;
349 
350  SI_RubberBox *myPickBox; // for box selection
351  SI_Lasso *myPickLasso; // for lasso selection
352  SI_Brush *myPickBrush; // for brush selection
353  SI_Brush *myPickLaser; // for laser selection
354 
355  DM_SelectMode myPreferredSelectMode;
356  bool myAllowDragging;
357  bool myAllowFinishingFlag;
358  bool myAllowFinishWithExistingSelection;
359  bool myAllowQuickSelect;
360  bool myJustDisplayedOpFlag;
361  bool myActivePicking;
362 
363  UT_StringMap<UT_IntArray> myPriorObjSelections;
364  bool myCreatedPriorSelections;
365 
366  static bool thePickingMenuOn;
367  static bool theAllowUseExistingSelection;
368  static bool theSelectFullLoops;
369 };
370 
371 #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)
GLint y
Definition: glcorearb.h:102
GLuint * ids
Definition: glcorearb.h:651
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 UI_Menu * getSelectorHotkeyMenu() const
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:108
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:263
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()
GLboolean r
Definition: glcorearb.h:1221
virtual void stopSelecting()
static bool getAllowUseExistingSelection()
void setSelectionRulePtr(UI_Value *new_value)
SI_Brush * getPickLaserPtr() const
static void setSelectFullLoops(bool val)
DM_SelectionStyle
Definition: DM_Defines.h:49
virtual void doRender(RE_Render *r, int x, int y, int ghost)
virtual const char * cursor() const