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