HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP3D_InputSelector.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_InputSelector.h
7  *
8  * COMMENTS:
9  * This descendant of BM_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_InputSelector_h__
15 #define __OP3D_InputSelector_h__
16 
17 #include "OP3D_API.h"
18 #include "OP3D_InputSelectorBase.h"
19 #include "OP3D_SelectionManager.h"
20 #include "OP3D_GUSelectionSet.h"
21 #include <UI/UI_HotkeyHelper.h>
22 #include <OP/OP_DataTypes.h>
23 #include <PI/PI_ClassManager.h>
24 #include <GEO/GEO_PrimTypeCompat.h>
25 #include <GU/GU_SelectionSet.h>
27 #include <UT/UT_Rect.h>
28 #include <UT/UT_Map.h>
29 
30 class GU_SelectResult;
31 class GUI_DisplayOption;
32 class OP_Network;
33 class DM_HeldHotkeyCache;
34 class OP3D_InputSelectorUndoWorker;
35 class OP3D_EdgeLoopHelper;
36 class OP3D_PatternSelectHelper;
37 class SOP_Node;
38 class GA_Attribute;
39 class GR_DisplayOption;
40 
41 typedef bool (*OP3D_ValidForPickFilter)(void *data, GUI_DetailLook *look);
42 
44 {
49 };
50 
52 {
54  myGeoIndex(-1), myOpId(-1),
55  myIsSelectionSetOwner(false),
56  myIsSelected(false), myIsLocalScope(true) {}
57 
59  { return mySelectionSet->selection(myActiveType); }
61  { return myActiveType; }
62 
63  void updateProxy(GU_SelectionHandle sel, bool create);
64  GUI_DetailLook *getLook() const;
65 
66 
68  int myOpId;
69  // The index within the geolook.
70  // TODO: The DOP data name is probably more useful.
72 
75 
76  // The auto converted selection is set if we had to convert to an allowed
77  // selection type in selectorFinished() and should be cleared whenever we
78  // respond to a selection type change event.
80 
83 
84  // Proxy which represents the binding between the GUI_DetailLook and
85  // our selection. Manages our reference to the GUI_DetailLook, and
86  // the look's reference to the active selection.
88 
92 };
93 
95 {
96 public:
97 
98  OP3D_InputSelector(OP3D_View &viewer, PI_SelectorTemplate &templ);
99  ~OP3D_InputSelector() override;
100 
101  const char *className() const override;
102 
103  // This selector has the ability to locate components.
104  int hasLocates() const override
105  { return 1; }
106 
107  // The selector handles mouse events and modifies the selection
108  // accordingly. Return 1 if the event was consumed and 0 otherwise.
109  int handleMouseEvent(UI_Event *event) override;
110 
111  // Handle double-click events. Returns true if handled.
112  bool handleDoubleClickEvent(UI_Event *event) override;
113 
114  void getKeyResolveInfo(UI_KeyResolveInfo &info) override;
115 
116  // Selectors respond to keyboard events to know when to finish a selection
117  // stage and possibly enter the next.
118  int handleKeyEvent(int key, UI_Event *event,
119  DM_Viewport &viewport) override;
120  bool handleTransitoryKey(const UI_Event &event,
121  int hotkey_id) override;
122  bool willHandleKeyEvent(int key, UI_Event *event);
123 
124  // Is the selector required to attach an input node to the current
125  // node? If it is but nothing was selected, an empty model sop will
126  // be attached. By default, an input is not required.
127  bool inputRequired() const { return myInputRequiredFlag; }
128  void setInputRequired(bool onoff)
129  { myInputRequiredFlag = onoff; }
130 
131  // Some sops (eg. group and delete) need a '*' in the input field if
132  // everything is selected. Other sops will operate on everything if
133  // the input field is blank.
135  { return myUseAsteriskToSelectAll; }
136  void setUseAsteriskToSelectAll(bool onoff)
137  { myUseAsteriskToSelectAll = onoff;}
138 
139  // Specifies whether or not to use primitive id's when selecting edges.
140  // This setting allows the selector to distinguish between a general edge
141  // (e.g p0-1) and an edge on a primitive (e.g. 0e1)
142  void setUsePrimsInEdgeSelections(bool use_prims)
143  { myUsePrimsInEdgeSelectionFlag = use_prims; }
144 
145  // Specifies whether the selector can guess and return edge rings based
146  // on the choice of end elements or should always stick to edge loops.
147  void setAllowEdgeRingSelection(bool allow)
148  { myAllowEdgeRingSelection = allow; }
149 
150  // Specifies whether the selector can guess and return edge rings based
151  // on the choice of end elements or should always stick to edge loops.
153  { myOffsetVertexMarkersOverride = offset; }
154 
155  // Get or set the primitive mask used for picking. The virtual primMask
156  // overrides DM_InputSelector which allows DM_Viewport to access the
157  // primitive mask for pre-selection highlighting.
159  primMask() const override
160  { return myPrimMask; }
162  { myPrimMask = primmask; }
163 
164  // A selector can optionally be "sloppy" whereby the user can initially
165  // pick any of the component types allowed by getSelectionAllowedTypes(),
166  // regardless of the selection type UI value. Once a component has been
167  // picked in this mode, only components of that type can be picked until
168  // the selections are cleared or a pick occurs as a GU_ReplaceSelect.
169  //
170  // The component type of area select operations when a component has not
171  // yet been picked is determined by the selection type UI value.
172  //
173  // The selection type UI values can be used in this mode to convert the
174  // current selection and are also automatically updated by the selector
175  // as the user picks different component types.
176  //
177  // NB: setSloppy() should be called after setSelectionAllowedTypes().
178  void setSloppyPick(bool on);
179  bool getSloppyPick() const
180  { return mySloppyPick; }
181 
182  // Restrict sloppy picks to a subset of getSelectionAllowedTypes(). Must
183  // be called after setSloppyPick(true) in order to have an effect.
184  //
185  // Note that this only restricts the subset of component types allowed for
186  // sloppy picks and will not affect the current selection, even when it is
187  // of a type we're excluding.
188  bool restrictSloppyAllowedTypesToSubset(
189  const PI_GeometryTypeArray &types);
190 
191  // Some selectors allow picking components at the object level.
192  void setPickAtObjLevel(bool flag)
193  { myPickAtObjLevelFlag = flag; }
194  bool getPickAtObjLevel() const
195  { return myPickAtObjLevelFlag; }
196 
197  // The selector needs to be notified when it starts/stops selecting
198  // so it can add/remove interests (the selection type, etc.).
199  void startSelecting() override;
200  void stopSelecting() override;
201  void restartWithStashedSelection();
202 
203  // Commit the pre-selection in the viewport to a geometry selection.
205  GU_SelectionRule sel_rule) override;
206 
207  // Return a list of looks from which we can select.
208  void getSelectableLooks(GUI_DetailList &looklist) override;
209 
210  // Add the cook selection, if any, from the specified SOP to our current
211  // selection.
212  bool addCookedSelection(SOP_Node *sop);
213 
214  // The selector needs to know the node for which it is reselecting so that
215  // it can properly place visibility operators.
216  void nodeIdForReselecting(int node_id)
217  { myNodeIdForReselecting = node_id; }
218 
219  // Clear the selections of the selection. This method is called when,
220  // for example, the selection stages are aborted.
221  virtual void clearSelections();
222 
223  // Consume the user selections made for this selector by clearing any
224  // correponding selections stashed in the selection manager/cache and
225  // clear our selection infos.
226  virtual void consumeSelections();
227 
228  // Remove the selections we assigned to detail looks.
229  void removeSelectionsFromDetailLooks();
230 
231  // This method allows the resource manager can set the workbench to
232  // something different if a selector is reused. It should not be used
233  // otherwise. A nil pointer is allowed so the select can remove any
234  // of its interests. However, methods of the selector should never be
235  // called when its workbench is nil. The method is virtual so
236  // descendants can also have a chance to clean up.
237  void setViewer(BM_View *viewer) override;
238 
239  // This method must be called after retrieving a new/recycled selector
240  // from the resource manager.
241  void setSelectionUIValues(UI_Value *sel_type,
242  UI_Value *sel_rule,
243  UI_Value *sel_style,
244  UI_Value *sel_visible,
245  UI_Value *sel_contained,
246  UI_Value *sel_full,
247  UI_Value *locate_always,
248  UI_Value *finished,
249  UI_Value *located=nullptr);
250 
251  // Any nodes created by this selector are tagged with the creator state's
252  // name.
253  void setCreatorStateName(const char *state_name)
254  { myCreatorStateName.harden(state_name); }
256  { return myCreatorStateName; }
257 
258  // Can this selector use a box or lasso for picking, or just click picks?
259  void setAllowDragSelect(bool allow_drag)
260  { myAllowDragSelFlag = allow_drag; }
261 
262  // Should this selector only select the full geometry?
263  void setSelectFullGeometry(bool select_full)
264  { myFullSelFlag = select_full; }
265 
266  // Should this selector start with the existing selection, if any? The
267  // cook group will be used for the chosen SOP if true and there is no
268  // applicable pending temporary selection. In some cases, you'll want
269  // to control whether we use existing temp or cook selections separately.
270  void setUseExistingSelection(bool use_existing)
271  {
272  setUseExistingTempSelection(use_existing);
273  setUseExistingCookSelection(use_existing);
274  }
275  bool useExistingSelection() const
276  {
277  return useExistingTempSelection() ||
278  useExistingCookSelection();
279  }
280 
281  // Should this selector start with the existing temporary selection,
282  // if any?
283  void setUseExistingTempSelection(bool use_existing)
284  { myUseExistingTempSelection = use_existing; }
286  { return myUseExistingTempSelection; }
287 
288  // Should this selector start with the cook selection for the chosen SOP
289  // either if useExistTempSelection() is false or there was no applicable
290  // pending temporary selection.
291  void setUseExistingCookSelection(bool use_existing)
292  { myUseExistingCookSelection = use_existing; }
294  { return myUseExistingCookSelection; }
295 
296  // TODO: Rename to setExportUserSelectionOnFinish().
297  void setStashSelectionOnFinish(bool stash)
298  { myStashSelectionOnFinish = stash; }
300  { return myStashSelectionOnFinish; }
301 
302  void setAllowMultiPickLoopStart(bool allow)
303  { myAllowMultiPickLoopStart = allow; }
304 
305  // Set an initial selection for the given op path.
306  //
307  // If useExistingTempSelection() or useExistingCookSelection() is true,
308  // then this initial selection will be in addition to those selections,
309  // and may even overwrite them entirely. Any number of op paths can be
310  // set. Only the op paths that exist within the selector context will
311  // have their initial selection set.
312  void setInitialSelection(const char *op_path,
314  const char *selection_string);
315 
316  // Should this selector save undo information?
317  void setSaveUndos(bool yesno) { mySaveUndosFlag = yesno; }
318  bool saveUndos() const { return mySaveUndosFlag; }
319 
320  // Generate merge(s) and connect them to the given op, filling in the
321  // specified input parm with the selection. If there is a menu in the
322  // op that needs to be set and menu_idx is not null, the value menu_idx
323  // points to will be set to a non-negative index into the menu. If menu_idx
324  // is not null but there is no menu, *menu_idx = -1.
325  // If the selection consists of the entire gdp, the group field
326  // is filled with an empty string. To force it to be filled
327  // with a string (even for the entire gdp), use force_selection_string.
328  // An array of the previous input nodes may optionally be provided to
329  // suppress the automatic repositioning of new_node when it is simply
330  // reconnected to the same inputs.
331  bool connectOps(OP_Node &new_node, int op_input_index,
332  const UT_String &input_parm,
333  int *menu_idx = 0,
334  bool branch_off = false,
335  bool multi_input = false,
336  bool force_selection_string = false,
337  bool force_numeric = false,
338  const UT_IntArray *prev_input_nodes = 0);
339 
340  /// Some convenience methods for managing mySelectedInfoIndices.
341  void addSelectedInfo(int info_i, bool set_pick_order=true);
342  void removeSelectedInfo(int info_i);
343 
344  /// Update our internal selection cache and the detail look, if any, with
345  /// the provided selection.
346  int updateSelection(const char *path, OP_Node *node,
347  GUI_DetailLook *look, int geo_idx,
349  const GU_Detail &gdp);
350 
351  /// Returns the current set of ops that have selections on them using this
352  /// selector. The size of the array matches that of the array returned by
353  /// \c selectedselections and \c selectedAutoConvertedSelections.
354  UT_StringArray selectedOpPaths() const;
355 
356  /// Returns the current set of selection objects used to mark the
357  /// component selection for each op used for selection. The size of this
358  /// array matches that of the array returned by \c selectedOpPaths.
359  ///
360  /// In many cases you should use \c selectedAutoConvertedSelections
361  /// instead of this method.
362  OP3D_SelectionHandles selectedSelections() const;
363 
364  /// Returns the current set of auto converted (to the best allowed
365  /// selection type) selection objects for each op used for selection.
366  /// The size of this array matches that of the array returned by
367  /// \c selectedOpPaths.
368  //
369  /// The conversion is done in selectorFinished(), so if this method is
370  /// called before this it is identical to calling selectedSelections().
371  /// Typically you'll want to use this method wherever you call either
372  /// getGeometryTypeAtFinish() or getGroupTypeMenuValAtFinish(). Unlike
373  /// selectedSelections(), entries may be empty or even NULL.
374  OP3D_SelectionHandles selectedAutoConvertedSelections() const;
375 
376  /// Returns a selection handle, given an op path. If the selector is not
377  /// holding a matching op path, then an empty handle is returned.
378  GU_SelectionHandle selectionFromOpPath(UT_StringRef path,
379  bool only_selected=true) const;
380 
381  /// Returns a selection handle, given an info key. If the selector is not
382  /// holding a matching info, then an empty handle is returned.
383  class InfoKey;
384  GU_SelectionHandle selectionFromInfoKey(const InfoKey &key,
385  bool only_selected=true) const;
386 
387  // Returns whether this selector has a non-empty selection instance.
388  bool hasNonEmptySelection() const;
389 
390  // Return the stored selection for the specified geometry, or, if none,
391  // return the selection of the specified type passed in new_selection,
392  // if any, or return an entirely new selection of the specified type
393  // and set new_selection to point to it.
394  GU_SelectionHandle getOrCreateSelection(int node_id, int detail_index,
395  int &info_i,
396  GU_SelectionHandle &new_selection,
397  GA_GroupType sel_type);
398  GU_SelectionHandle getExistingSelection(int node_id, int detail_index,
399  int &info_i,
400  GA_GroupType sel_type);
401 
402  // The state needs to be able to get the current prompt and set the default
403  // prompt. The custom message is for the selector, and the default message
404  // is displayed by the state. The default prompt is passed on by the state
405  // and should not be changed. If you make the const versions public and
406  // the non-const versions private it won't compile, so they're all public.
407  const UT_String &currentPrompt() const { return myCurrentPrompt; }
408  UT_String &currentPrompt() { return myCurrentPrompt; }
409  const UT_String &defaultPrompt() const { return myDefaultPrompt; }
410  UT_String &defaultPrompt() { return myDefaultPrompt; }
411 
412  // Clean up when selector is about to transmit done event. If drag is
413  // true, the selector indicates to the state that the selection should
414  // be dragged right away.
415  void selectorFinished(bool drag = false);
416 
417  // Create an object merge for the given object-sop combination, or combine
418  // the given path into the network if do_combine is true. In that case,
419  // the sop path and selection instance is updated to point to the moved
420  // sop.
421  static SOP_Node *createObjectMerge(OP_Network *network,
422  UT_String &path,
424  const UT_String &creator_state_name,
425  bool keep_original_objects,
426  bool display_origina_objects);
427 
428  // Override the undo worker that gets used for undos. Pass in NULL to use
429  // a default worker.
430  void setUndoWorker(OP3D_InputSelectorUndoWorker *worker=0);
431  // Sets and returns a default undo worker.
432  OP3D_InputSelectorUndoWorker *getDefaultUndoWorker();
433 
434  // Return the feel containing the RMB menu.
435  UI_Menu *getSelectorMenu() const override;
436  UI_Menu *getSelectorHotkeyMenu() const override;
437 
438  void setValidForPickFilter(void *data,
440 
441  // Get or set the current selection type or selection rule explicitly.
442  // Setting the selection type will change the selection type for all
443  // displayed geometry and all geometry that has been selected.
444  void setGeometryType(PI_GeometryType geo_type,
445  bool update_buttons);
446  GA_GroupType selectionType() const;
447 
448  // Get the component type as it was set when the selection was completed.
449  PI_GeometryType getGeometryTypeAtFinish() const;
450  int getGroupTypeMenuValAtFinish() const;
451  bool getKeepOriginalObjects() const;
452 
453  // Query if the selector is currently updating the geometry selection
454  // type button. This can be useful in determining if the selector is
455  // responsible for a given selection type change notification sent by
456  // the workbench.
457  bool currentlyUpdatingGeometryTypeButtons() const;
458 
459  const PI_GeometryTypeArray &getSelectionAllowedTypes() const;
460  void setSelectionAllowedTypes(
461  const PI_GeometryTypeArray &allowedtypes);
462 
463  // Call this method to query the next best allowed selection type when the
464  // given type is not allowed. Returns PI_GEOTYPE_INVALID when we have no
465  // explicit preference among the allowed selection types.
466  PI_GeometryType getNextBestAllowedType(
467  PI_GeometryType disallowed_type) const;
468 
469  // Call this method to query the allowed selection type to use for the
470  // given type. The failure_type is returned if there are no preferred
471  // allowed selection types for the given type.
472  PI_GeometryType mapToAllowedType(
474  PI_GeometryType failure_type
475  = PI_GEOTYPE_INVALID) const;
476 
477  // This function uses the below static function to generate a single
478  // selection string for all selections merged into a single detail.
479  //
480  // If consume_selections is true, the selections will be removed from
481  // this selector and the viewer's selection cache.
482  void generateAllSelectionStrings(UT_String &sel_string,
483  bool only_one_gdp,
484  bool force_numeric,
485  bool consume_selections) override;
486  static void generateMergedSelectionString(UT_String &sel_string,
487  UT_StringArray &paths,
488  OP3D_SelectionHandles &selections,
489  bool ordered,
490  bool collapse,
491  bool use_ast_to_select_all,
492  bool force_numeric);
493 
494  // A utility method to get a pick record representing the current loop
495  // start pick with the component indices mapped into a detail composed
496  // by merging all the selected details. Returns true on success, false
497  // otherwise. The record will be cleared on failure. The look ID and
498  // detail index returned in the GR_PickRecord are meaningless. We are
499  // unable to export the component info when myLoopStartPickPath is not
500  // in the list of selected paths.
501  bool getPostMergeLoopStart(GR_PickRecord &pick);
502 
503  // A method for bootstrapping the current loop start pick, typically with
504  // a pick derived from an earlier selector. Only the geometry component
505  // data is relevant in the supplied GR_PickRecord.
506  void bootstrapLoopStart(const char *path,
507  const GR_PickRecord &pick,
508  bool only_selected_path);
509 
510  // This method is used by HOM to replace the current selection for a
511  // particular component type.
512  void scriptReplaceSelection(
513  PI_GeometryType geo_type,
514  const UT_StringArray &paths,
515  OP3D_SelectionHandles &selections);
516 
517  // Convert to a particular geometry selection from the given list of
518  // objects
519  static bool createSelectionFromObjects(
520  const OP_NodeList &objects,
521  DM_Viewport &viewport,
522  PI_GeometryType geo_type,
523  UT_StringArray &paths,
524  OP3D_SelectionHandles &selections);
525 
526  bool getStateParmNames(
527  UT_StringArray &ret,
528  const char* prefix = nullptr) override;
529  bool evalStateParm(
530  const char *name,
531  UT_StringHolder &ret) override;
532  bool setStateParm(
533  const char *name,
534  const UT_StringHolder &val) override;
535  bool pressStateButton(const char *name) override;
536 
537  // Override to allow rendering widgets.
538  void doRender(RE_Render *r, int x, int y,
539  int ghost) override;
540 
541 
543  {
544  public:
545  InfoKey(int node_id, int detail_index)
546  : myNodeId(node_id), myDetailIndex(detail_index)
547  {
548  }
549  bool operator==(const InfoKey &key) const
550  {
551  return myNodeId == key.myNodeId &&
552  myDetailIndex == key.myDetailIndex;
553  }
554  int getNodeId() const { return myNodeId; }
555  int getDetailIndex() const { return myDetailIndex; }
556 
557  private:
558  int myNodeId;
559  int myDetailIndex;
560  };
561 
562  using LocateFilter = std::function<bool(DM_Viewport *)>;
564  { myLocateFilter = filter; }
565 
567  HeldHotkeyCacheUPtr &getHeldHotkeyCache() { return myHeldHotkeyCache; }
568 
569 protected:
570  // React to the user pressing a button to change the component type.
571  virtual void handleSelectionTypeChange(UI_Event *event);
572 
573  /// Called when selection finishes and we need to stash away the group
574  /// menu index that gets set for the target operator of this selector.
575  virtual void updateGroupMenuValue(PI_GeometryType geo_type,
576  int &group_menu_type) = 0;
577 
578  // Called when the selection changes and nothing is removed. Added_geo is
579  // a pointer to the added geometry, allowing derived classes to process it
580  // if they so wish.
582  const char *path,
583  GU_SelectionHandle sel,
584  GU_SelectResult &added_geo)
585  { }
586 
587  // Handle a pick during which nothing was selected. Return true if
588  // any changes were made to the existing selections.
589  virtual bool handleNoPick(UI_Event *event);
590 
591  // Insert additional nodes between the last created node and the
592  // state's node.
593  virtual void appendToLastNode(SOP_Node *&/*input_node*/,
594  const UT_String &/*creator_state_name*/,
595  bool /*branch_off*/) {}
596 
597  // Add additional input nodes for the new node.
598  virtual void generateAdditionalInputNodes(SOP_Node & /*new_node*/,
599  SOP_Node * /*last_selected_node */,
600  const UT_String & /*sel_string*/,
601  const UT_String & /*creator_state_name*/) {}
602 
603  // Modify default parameters if necessary.
604  virtual void setNodeParameters(OP_Node &) {}
605 
606  // Return the pick masks to be used for single or area picks. These masks
607  // are a function of the current selection type for all non-sloppy (normal)
608  // selectors, and both the current selection type and the current selection
609  // state for sloppy selectors. These are the masks used to select entities
610  // that the selection knows how to handle.
611  int singlePickMask(GU_SelectionRule sel_rule) const;
612  int areaPickMask(GU_SelectionRule sel_rule) const;
613 
614  // Return the pick mask to be set in the workbench to control the automatic
615  // display of useful visual markers.
616  int displayPickMask() const;
617 
618  // THESE TWO METHODS ARE DEPRECATED.
619  // Overriding selection type in this manner is dangerous as there
620  // is no guarantee the button bar will remain disabled.
621  // If you find yourself wanting to use this (ie: MSS_JoinSelector)
622  // your selector is likely a state in disguise.
623 
624  // This method is called to overwrite UI values. Disables the
625  // toolbox which allows the user to change the values.
626  void overrideSelectionValues(int sel_type, int sel_rule,
627  int sel_style, int sel_full,
628  int locate);
629  // Restore the values indicated by the UI.
630  void restoreSelectionValues();
631 
632  // Save the contents of the selector so later changes can be undone/redone.
633  void saveForUndo() override;
634 
635  // Implements the getPickName function to return the string representation
636  // of a pick id.
637  bool getPickName(const OP3D_PickId &pickid,
638  UT_String &name,
639  bool descriptivename) const override;
640 
641  // Override the base class needObjectPick() method to add support for our
642  // getPickAtObjLevel() flag.
643  bool needObjectPick() const override;
644 
645  // Clear the selections of all the gdp's with selections in them.
646  // This method is called when failing to select something at all.
647  bool emptySelections(const char *path_to_skip = 0,
648  bool refresh = true);
649 
650  // Delay the selection dirty opChanged calls
652  {
653  public:
654  virtual ~DirtySelectionScope();
655  void delayDirtySelection(SOP_Node *s);
656 
657  private:
659  };
660  // Mark this selection as dirty so that the SOP node and the viewport
661  // will be properly refreshed with the new selection state.
662  void dirtySelection(SOP_Node *sop_node, DirtySelectionScope *scope);
663  void dirtySelection(const GUI_DetailLook &geo_look, int geo_idx, DirtySelectionScope *scope);
664  void dirtySelection(const OP3D_SelectionInfo &sel_info, DirtySelectionScope *scope);
665 
666 
667 
668  // Clear mySelectionInfos as well as mySelectedInfoIndices.
669  void clearSelectionInfos();
670 
671  // Clear mySelectedInfoIndices, but keep mySelectionInfos.
672  void clearSelectedInfoIndices();
673 
674  // Utility method to compute the next unused pick order from our current
675  // selections.
676  int computeNextPickOrder(GA_GroupType sel_type) const;
677 
678  int findInfo(int node_id, int detail_index) const;
679  int findInfo(const char *path) const;
680 
681 
682 private:
683  void handleStartSelecting(UI_Event *event);
684 
685  // Rather than putting the undo code in this file, it's in a friend class.
686  friend class OP3D_InputSelectorUndo;
687 
688  void getPickableGeometry(GUI_DetailList &geos,
689  bool objects_only) const;
690 
691  // Return true if the selection has changed and false otherwise.
692  bool singleSelectGeometry(UI_Event *event,
693  bool save_undo,
694  bool selecting_loop,
696  bool boxSelectGeometry(UI_Event *event,
697  int xcenter, int ycenter,
698  int xsize, int ysize);
699  bool lassoSelectGeometry(UI_Event *event,
700  int *lasso_points);
701  bool brushSelectGeometry(UI_Event *event,
702  uint8 *enablemap,
703  int minx, int miny,
704  int maxx, int maxy,
705  bool visible_only,
706  bool contained_only);
707  bool singleSelectObject(UI_Event *event,
708  UT_Array<GR_PickRecord> &pick_records);
709 
710  // Use the contents of the pick buffer to modify the selections. Return
711  // true if the selection has changed and false otherwise.
712  bool modifySelections(UI_Event *event,
713  const UT_Array<GR_PickRecord> &pick_records,
714  GU_SelectionRule sel_rule);
715 
716  /// Handles a toggle from the "Select Whole Geometry" menu option
717  void fullSelectionChanged(UI_Event *);
718 
719  // Select everything that's visible in the viewport, select nothing, or
720  // toggle the selections of everything in the viewport.
721  void selectAllOrNoneOrToggle(OP3D_SelectionAction action,
722  DM_Viewport &viewport);
723 
724  // Revert the current selection to only the cook selection on the current
725  // node.
726  void revertToCookSelection(DM_Viewport &viewport);
727 
728  // Select the boundary of the current selection. This means
729  // everything which is selected and has a neighbour which is
730  // unselected.
731  void selectBoundary(DM_Viewport &viewport);
732  void selectEdgeBoundary(DM_Viewport &viewport);
733  void shrinkSelection(DM_Viewport &viewport);
734  void growSelection(DM_Viewport &viewport);
735  void selectPrimitivesWithVertexCount(
736  DM_Viewport &viewport,
737  const char *command_name,
738  GA_Size min_vtx, GA_Size max_vtx);
739 
740  using PatternExpandFunc = bool (OP3D_PatternSelectHelper::*)
741  (const GU_Detail &,
744  void patternSet(DM_Viewport &viewport);
745  void patternExpand(DM_Viewport &viewport,
746  PatternExpandFunc func,
748 
749  // Select everything that's visible in the uv viewport, but only if the
750  // face has a specific winding (orientation).
751  void uvSelectAllByWinding(DM_Viewport &viewport,
752  bool front_facing,
753  bool back_facing);
754 
755  void convertSelection(DM_Viewport &viewport,
756  GA_GroupType target_type);
757 
758  bool handlePick(UI_Event *event,
759  const UT_Array<GR_PickRecord> &in_pick_records,
760  GU_SelectionRule sel_rule,
761  bool &added_something);
762 
763  void handleBoxPick(UI_Event *event) override;
764  void activeBoxPick(UI_Event *event) override;
765  void handleLassoPick(UI_Event *event) override;
766  void activeLassoPick(UI_Event *event) override;
767  void handleBrushPick(UI_Event *event) override;
768  void activeBrushPick(UI_Event *event) override;
769  void handleLaserPick(UI_Event *event) override;
770  void activeLaserPick(UI_Event *event) override;
771 
772  // Respond to the user using the selection visibility menu in the toolbar.
773  void handleSelectionHideOrExpose(UI_Event *event);
774 
775  // Should we allow picking from this GUI_DetailLook? (eg. Templates
776  // can't be picked from, and ordered selectors need to pick from the
777  // merges, even if the inputs of the merges are displayed.)
778  bool validForPickRender(GUI_DetailLook *detail,
779  const GUI_DisplayOption &dopt) const;
780 
781  // A higher level method than validForPickRender(), used to consolidate
782  // additional common restrictions.
783  //
784  // TODO: Merge with validForPickRender().
785  bool allowPickOperation(GUI_DetailLook *detail,
786  const GUI_DisplayOption &dopt) const;
787 
788  UT_Array<const OP3D_SelectionInfo *> getNonEmptySelectedInfos() const;
789 
790  // Is any of the geometry visible on the screen selected?
791  bool isAnythingSelected();
792 
793  // Create and connect a visibility sop to modify the visibility of geometry
794  // in the specified sop. Returns the newly created sop, if any, and a flag
795  // indicating whether the visibility sop was inserted above the specified
796  // sop instead of below.
797  SOP_Node *createAndConnectVisibilitySop(SOP_Node *sop,
798  bool *inserted_above);
799 
800  // Set the parameters in the visibility sop to match the action being
801  // performed.
802  void setVisibilitySopParameters(SOP_Node &visibility_sop,
803  bool exposing,
804  bool applying_to_selection,
805  bool cumulative,
806  const UT_String &sel_string);
807 
808  OP3D_EdgeLoopHelper &getEdgeLoopHelper();
809 
810  OP3D_PatternSelectHelper &getPatternSelectHelper(int sop_node_id,
811  int geo_idx);
812 
813  SOP_Node *getChosenSOP() const;
814 
815  SOP_Node * findChosenSop(bool &need_object_pick);
816  void handleSwitchToChosenOp(UI_Event *event);
817 
818  void doneNormalSelection();
819 
820  bool areaSelectGeometry(UI_Event *e,
821  const UT_DimRect &area,
822  uint8 *mask,
823  unsigned pick_mask,
825  bool visible_only,
826  bool contained,
827  bool add_to_existing_picks);
828 
829  // A wrapper around DM_Viewport::adoptLocatedItems() that also handles any
830  // necessary communication with DM_GroupInfo.
831  //
832  // Returns if the viewport located items have changed.
833  bool adoptLocatedItems(DM_Viewport *viewport,
835  UT_Array<GR_PickRecord> &faded_items,
836  bool force_locate = false);
837 
838  // Add any pending (i.e. saved temporary selections) for visible (and
839  // pickable) geometry in the viewer. Returns whether any non-empty
840  // selections were added. We also set have_chosen_sop_temp_sel flag
841  // to indicate if we found any non-null pending selection for the chosen
842  // SOP, including an empty one.
843  bool initWithPendingSelectionForVisibleOps(
844  SOP_Node *chosen_sop,
845  bool &have_chosen_sop_temp_sel);
846  void stashPendingSelection();
847 
848  void autoConvertToFinishGeometryType();
849 
850  void addInitialSelections();
851 
852  void handleGeoChanged(UI_Event *event);
853 
854  void updateSelectMask();
855 
856  // Reset mySloppyPickMask from myAllowedTypes.
857  void resetSloppyPickMask();
858 
859  // Update the set sloppy selection type, if any, to the specified type.
860  void updateExistingSloppySelectionType(
861  GA_GroupType sel_type);
862 
863  // Initialize an unset sloppy selection type from the given pick records
864  // and selection rule.
865  void initSloppySelectionType(
866  const UT_Array<GR_PickRecord> &pick_records,
867  GU_SelectionRule sel_rule);
868 
869  // Set the sloppy selection type to the specified type along with any
870  // extra book-keeping.
871  void setSloppySelectionType(
872  GA_GroupType sel_type);
873 
874  static OP_Node * mergeViaCombine(fpreal t,
875  OP_Network *network,
876  UT_String &path,
878  const UT_String &creator_state_name);
879 
880  bool acceptKey(int key, UI_Event *event);
881  bool fullSelectionKey(int key, UI_Event *event);
882  bool selectByNormalKey(int key, UI_Event *event);
883  bool keepOriginalObjKey(int key, UI_Event *event);
884  bool locateKey(int key, UI_Event *event);
885  bool selectAllKey(int key, UI_Event *event);
886  bool invertSelectionKey(int key, UI_Event *event);
887  bool selectNoneKey(int key, UI_Event *event);
888  bool revertToCookSelectionKey(int key, UI_Event *event);
889  bool selectBoundaryKey(int key, UI_Event *event);
890  bool selectEdgeBoundaryKey(int key, UI_Event *event);
891  bool shrinkSelectionKey(int key, UI_Event *event);
892  bool growSelectionKey(int key, UI_Event *event);
893  bool patternSetKey(int key, UI_Event *event);
894  bool patternForwardKey(int key, UI_Event *event);
895  bool patternBackwardKey(int key, UI_Event *event);
896  bool patternLeftKey(int key, UI_Event *event);
897  bool patternRightKey(int key, UI_Event *event);
898  bool patternForwardToEndKey(int key, UI_Event *event);
899  bool patternBackwardToEndKey(int key, UI_Event *event);
900  bool patternLeftToEndKey(int key, UI_Event *event);
901  bool patternRightToEndKey(int key, UI_Event *event);
902  bool selectUVSelectAllFrontKey(int key, UI_Event *event);
903  bool selectUVSelectAllBackKey(int key, UI_Event *event);
904  bool visibleSelectToggleKey(int key, UI_Event *event);
905  bool containedSelectToggleKey(int key, UI_Event *event);
906  bool doubleClickJumpToObjectKey(int key, UI_Event *event);
907  bool redoSelectionKey(int key, UI_Event *event);
908  bool selectNextGroupKey(int key, UI_Event *event);
909  bool selectPrevGroupKey(int key, UI_Event *event);
910  bool copyCurrentGroupNameKey(int key, UI_Event *event);
911  bool copyCurrentSelectionKey(int key, UI_Event *event);
912 
913  bool selectionConvertPointKey(int key, UI_Event *event);
914  bool selectionConvertEdgeKey(int key, UI_Event *event);
915  bool selectionConvertPrimitiveKey(int key, UI_Event *event);
916  bool selectionConvertVertexKey(int key, UI_Event *event);
917  bool selectionConvertBreakpointKey(int key,
918  UI_Event *event);
919 
920  bool selectPrimitiveTrianglesKey(int key, UI_Event *event);
921  bool selectPrimitiveQuadsKey(int key, UI_Event *event);
922  bool selectPrimitiveNgonsKey(int key, UI_Event *event);
923 
924  void handleLocatedPickComplete(UI_Event *event);
925  void handleMouseActionComplete();
926 
927  // Use a seed pick to expand to new picks by normal. Adds new
928  // components to the pick if its normal is within the spread angle
929  // tolerance from the normal of the base pick.
930  void expandPickByNormal(
931  UT_Array<GR_PickRecord> &new_picks,
932  const GR_PickRecord &base_pick,
933  const GU_Detail &gdp,
934  fpreal spread_angle,
935  bool pick_all_matching_normals,
936  bool use_static_reference_normal,
937  const GU_SelectionHandle & prev_selection);
938 
939  // Use a seed pick to expand to new picks by flood filling. Finds
940  // islands of unselected geometry for selection, and/or islands of
941  // selected geometry for deselection.
942  void expandPickByFloodFill(
943  UT_Array<GR_PickRecord> &new_picks,
944  const UT_Array<GR_PickRecord> &seed_picks,
945  const GU_Detail &gdp,
947  GU_SelectionRule rule);
948 
949  // Utility method to update myLoopStartPick to refer to the detail look
950  // corresponding to myLoopStartPickPath when necessary, and, optionally,
951  // note the fact that we've done this in myLoopStartPickRecordMatchesPath
952  // when we expect it to remain synchronized over an extended operation.
953  void updateLoopStartPickRecordFromPath(
954  bool record_match_state);
955 
956  bool selectFromSingleRecord(UI_Event *event,
957  const GR_PickRecord &pick,
958  GU_SelectionRule sel_rule);
959 
960  void addInfoLookup(const OP3D_SelectionInfo &sel_info,
961  int sel_info_index);
962 
963  const GA_Attribute *getUVAttrib(const GU_Detail *gdp);
964  bool areVerticesOfSamePoint(
965  const UT_Array<GR_PickRecord> &pick_records);
966 
967  void extendVertexPickRecords(
968  const UT_Array<GR_PickRecord> &pick_records,
969  UT_Array<GR_PickRecord> &extended_pick_records);
970 
971  // Drawable selection related methods
972  void pickRender(
973  RE_Render * r,
974  const GR_DisplayOption * /*opt*/,
975  unsigned int /*pick_type*/,
976  GR_PickStyle /*pick_style*/,
977  bool /*has_pick_map*/,
978  UT_Array<GR_PickRecord> * /*records*/);
979 
980  // Hotkey methods
981  static UI_HotkeyHelper::Entry theHotkeyList[];
982 
983  UI_HotkeyHelper myHotkeyHelper;
984  DM_Viewport *myHotkeyViewport;
985 
986  UT_String myCurrentPrompt;
987  UT_String myDefaultPrompt;
988 
989  UT_String myCreatorStateName;
990 
991  UI_Value *myGeoChangedValue;
992  UI_Value *mySelectionTypeValue; // prims, points, etc.
993  UI_Value *myFullSelection; // select whole gdp
994  UI_Value *myAlwaysLocate; // always do locating
995 
996  // A selector can optionally be "sloppy" as described in the comment for
997  // setSloppyPick(), whereby the user can pick any of the component types
998  // allowed by mySloppyPickMask (automatically built from myAllowedTypes).
999  // Once a component is picked in this mode, mySloppySelectionType will be
1000  // set and only components of that type can be selected until selections
1001  // are cleared.
1002  unsigned mySloppyPickMask;
1003  GA_GroupType mySloppySelectionType;
1004  GA_GroupType mySloppyFallbackSelectionType;
1005  bool mySloppyPick;
1006  bool mySloppySelectionTypeIsSet;
1007 
1008  // When overriding the values indicated by the UI buttons for the
1009  // above, keep previous values so we can restore.
1010  bool myCustomSelValFlag;
1011  int mySavedSelType;
1012  int mySavedSelRule;
1013  int mySavedSelStyle;
1014  int mySavedFullSel;
1015  int mySavedAlwaysLocate;
1016 
1017  GEO_PrimTypeCompat::TypeMask myPrimMask; // polygon, nurbs, etc.
1018 
1019  // NB: The relative order of the selection infos only matters when the
1020  // individual selections have the same pick order set.
1021  UT_Array<OP3D_SelectionInfo> mySelectionInfos;
1022  UT_Map<InfoKey, int> mySelectionInfoLookup;
1023 
1024  UT_IntArray mySelectedInfoIndices;
1025  int myNextPickOrder;
1026 
1028  ScopeKey myScope;
1029 
1030  int myLastMouseDown; // needed for changed events
1031  int myLastMouseStartX; // " " " "
1032  int myLastMouseStartY; // " " " "
1033 
1034  bool myResizingCursor; // Cursor resize drag active.
1035 
1036  int myNodeIdForReselecting;// reselecting for this node
1037 
1038  bool myUseExistingTempSelection;
1039  bool myUseExistingCookSelection;
1040  bool myStashSelectionOnFinish;
1041  bool myInputRequiredFlag; // is an input op required?
1042  bool myAllowDragSelFlag; // allow box/lasso selecting?
1043  bool myFullSelFlag; // do only full selections?
1044  bool mySaveUndosFlag; // save undo information?
1045  bool myUseAsteriskToSelectAll; // use '*' to select all?
1046  bool myUsePrimsInEdgeSelectionFlag; // use primitives when
1047  // selecting edges (e.g. 0e1)
1048  bool myPickAtObjLevelFlag; // pick geo at OBJ level
1049  bool myAllowEdgeRingSelection;
1050  int myOffsetVertexMarkersOverride;
1051  int myOffsetVertexMarkersSaved;
1052 
1053  // Flag to track whether the auto converted selections stored in the
1054  // selection info have been set.
1055  bool myAutoConvertedSelectionsFlag;
1056 
1057  // After we finish selecting we must remember our type.
1058  PI_GeometryType myFinishGeometryType;
1059  int myFinishGroupTypeMenuVal;
1060 
1061  // Component type of current selection.
1062  PI_GeometryType myCurrentComponentType;
1063 
1064  // A flag to track whether this selector is currently updating the geometry
1065  // type buttons in setGeometryType().
1066  bool myUpdatingGeometryTypeButtons;
1067 
1068  bool myHadDoubleClick;
1069 
1070  struct InitialSelection
1071  {
1073  int index;
1074  UT_StringHolder selection_string;
1075  };
1076  UT_StringMap<InitialSelection> myInitialSelections;
1077 
1078  OP3D_InputSelectorUndoWorker *myUndoWorker;
1079  bool myOwnUndoWorker;
1080  PI_GeometryTypeArray myAllowedTypes;
1081 
1082  HeldHotkeyCacheUPtr myHeldHotkeyCache;
1083 
1084  // Utility for edge loops. The loop start pick is persistent across
1085  // multiple locate events, and so myLoopStartPickPath should be used
1086  // to identify the geometry to use with myLoopStartPick instead of
1087  // myLoopStartPick.getLookId() and myLoopStartPick.getDetailIndex().
1088  // To help avoid unnecessary lookups using the path, we track when
1089  // we've already updated the myLoopStartPick record to match the path
1090  // across extended operations in myLoopStartPickRecordMatchesPath.
1091  OP3D_EdgeLoopHelper *myEdgeLoopHelper;
1092  UT_String myLoopStartPickPath;
1093  GR_PickRecord myLoopStartPick;
1094  GR_PickRecord myLoopPrevPick;
1095  bool myLoopStartPickOnlyLocated;
1096  bool myLoopStartPickRecordMatchesPath;
1097  OP3D_ValidForPickFilter myValidForPickFilter;
1098  void *myValidForPickFilterData;
1099 
1100  LocateFilter myLocateFilter = nullptr;
1101  bool myAllowMultiPickLoopStart = false;
1102 
1103  // A map from SOP node ID and detail handle index to a helper class for
1104  // pattern selections.
1105  UT_Map<std::pair<int, int>, OP3D_PatternSelectHelper*> myPatternHelpers;
1106 
1107  // Drawable selection
1108  GUI_DetailLookPtr myDrawablePicker;
1109 };
1110 
1111 #endif
GT_API const UT_StringHolder selection
const UT_String & creatorStateName()
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
UT_StringHolder myOpPath
myNodes
Definition: UT_RTreeImpl.h:708
GUI_GUSelectionProxyHandle myProxy
Unsorted map container.
Definition: UT_Map.h:107
bool operator==(const InfoKey &key) const
GU_SelectionHandle selection() const
virtual void generateAllSelectionStrings(UT_String &sel_string, bool only_one_gdp, bool force_numeric, bool consume_selections)
void startSelecting() override
virtual UI_Menu * getSelectorHotkeyMenu() const
UT_SharedPtr< GUI_GUSelectionProxy > GUI_GUSelectionProxyHandle
GLboolean * data
Definition: glcorearb.h:131
std::function< bool(DM_Viewport *)> LocateFilter
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual bool handleDoubleClickEvent(UI_Event *event)
OP3D_SelectionAction
bool useExistingTempSelection() const
HeldHotkeyCacheUPtr & getHeldHotkeyCache()
void setAllowEdgeRingSelection(bool allow)
GLdouble s
Definition: glad.h:3009
void setUseAsteriskToSelectAll(bool onoff)
PI_GeometryType
GLint y
Definition: glcorearb.h:103
void stopSelecting() override
bool handleTransitoryKey(const UI_Event &event, int hotkey_id) override
void setSaveUndos(bool yesno)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
void updateProxy(GU_SelectionHandle sel, bool create)
virtual int handleMouseEvent(UI_Event *event)
GA_GroupType myActiveType
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
struct _cl_event * event
Definition: glcorearb.h:2961
bool inputRequired() const
unsigned char uint8
Definition: SYS_Types.h:36
void setInputRequired(bool onoff)
virtual void generateAdditionalInputNodes(SOP_Node &, SOP_Node *, const UT_String &, const UT_String &)
virtual int handleKeyEvent(int key, UI_Event *event, DM_Viewport &viewport)=0
void nodeIdForReselecting(int node_id)
GLintptr offset
Definition: glcorearb.h:665
bool setStateParm(const char *name, const UT_StringHolder &val) override
GU_SelectionRule
Definition: GU_SelectType.h:40
void setPrimMask(GEO_PrimTypeCompat::TypeMask primmask)
void setViewer(BM_View *viewer) override
void setUseExistingTempSelection(bool use_existing)
void doRender(RE_Render *r, int x, int y, int ghost) override
GLint GLuint mask
Definition: glcorearb.h:124
UT_String & currentPrompt()
UT_String & defaultPrompt()
virtual UI_Menu * getSelectorMenu() const =0
GA_API const UT_StringHolder drag
GLuint const GLchar * name
Definition: glcorearb.h:786
int hasLocates() const override
void setStashSelectionOnFinish(bool stash)
void setPickAtObjLevel(bool flag)
GLint GLenum GLint x
Definition: glcorearb.h:409
UT_SharedPtr< GU_Selection > GU_SelectionHandle
InfoKey(int node_id, int detail_index)
GLdouble t
Definition: glad.h:2397
void setUseExistingCookSelection(bool use_existing)
void setUseExistingSelection(bool use_existing)
Contains transitional objects to provide some backward compatibility for code that references old GEO...
GUI_DetailLook * getLook() const
virtual void addToSelection(UI_Event *event, const char *path, GU_SelectionHandle sel, GU_SelectResult &added_geo)
GLenum func
Definition: glcorearb.h:783
bool pressStateButton(const char *name) override
fpreal64 fpreal
Definition: SYS_Types.h:277
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:160
OP3D_PatternDirection
void setOffsetVertexMarkersOverride(bool offset)
virtual void commitViewportPreSelection(UI_Event *event, GU_SelectionRule sel_rule)
bool getStashSelectionOnFinish() const
const UT_String & currentPrompt() const
void setUsePrimsInEdgeSelections(bool use_prims)
GLuint GLfloat * val
Definition: glcorearb.h:1608
GA_GroupType selectionType() const
UT_UniquePtr< DM_HeldHotkeyCache > HeldHotkeyCacheUPtr
bool getPickAtObjLevel() const
virtual void appendToLastNode(SOP_Node *&, const UT_String &, bool)
#define OP3D_API
Definition: OP3D_API.h:10
OP3D_SelectionManager::ComponentScopeKey ScopeKey
UT_SharedPtr< OP3D_GUSelectionSet > OP3D_GUSelectionSetHandle
const char * className() const override
virtual void setNodeParameters(OP_Node &)
void setAllowDragSelect(bool allow_drag)
GEO_PrimTypeCompat::TypeMask primMask() const override
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
GLboolean r
Definition: glcorearb.h:1222
const UT_String & defaultPrompt() const
GU_SelectionHandle myAutoConvertedSelection
void setLocateFilter(LocateFilter filter)
virtual void getKeyResolveInfo(UI_KeyResolveInfo &info)=0
virtual void getSelectableLooks(GUI_DetailList &look_list)
bool useExistingSelection() const
type
Definition: core.h:1059
OP3D_GUSelectionSetHandle mySelectionSet
bool getSloppyPick() const
void setCreatorStateName(const char *state_name)
bool evalStateParm(const char *name, UT_StringHolder &ret) override
void setAllowMultiPickLoopStart(bool allow)
Definition: format.h:895
GA_API const UT_StringHolder area
bool useAsteriskToSelectAll() const
bool getStateParmNames(UT_StringArray &ret, const char *prefix=nullptr) override
bool(* OP3D_ValidForPickFilter)(void *data, GUI_DetailLook *look)
bool useExistingCookSelection() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GR_PickStyle
Definition: GR_Defines.h:240
void setSelectFullGeometry(bool select_full)