1 // Created on: 1995-02-15
2 // Created by: Roberc Coublanc
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 // ROB JAN/07/98 : Improve Storage of detected entities
19 // AGV OCT/23/03 : Optimize the method SortResult() (OCC4201)
21 #ifndef _SelectMgr_ViewerSelector_HeaderFile
22 #define _SelectMgr_ViewerSelector_HeaderFile
24 #include <MMgt_TShared.hxx>
25 #include <NCollection_Handle.hxx>
26 #include <NCollection_DataMap.hxx>
27 #include <OSD_Chronometer.hxx>
28 #include <TColStd_SequenceOfInteger.hxx>
29 #include <Handle_TColStd_HArray1OfInteger.hxx>
31 #include <Standard.hxx>
32 #include <Standard_DefineHandle.hxx>
34 #include <SelectMgr_IndexedDataMapOfOwnerCriterion.hxx>
35 #include <SelectMgr_SelectingVolumeManager.hxx>
36 #include <SelectMgr_Selection.hxx>
37 #include <SelectMgr_SelectableObject.hxx>
38 #include <SelectMgr_SelectableObjectSet.hxx>
39 #include <Handle_SelectMgr_EntityOwner.hxx>
40 #include <SelectMgr_StateOfSelection.hxx>
41 #include <Standard_OStream.hxx>
42 #include <Handle_SelectBasics_SensitiveEntity.hxx>
44 class TColStd_HArray1OfInteger;
45 class SelectMgr_SelectionManager;
46 class SelectMgr_Selection;
47 class SelectMgr_SensitiveEntitySet;
48 class SelectMgr_EntityOwner;
49 class TColStd_ListOfInteger;
50 class TCollection_AsciiString;
51 class SelectBasics_SensitiveEntity;
52 class SelectMgr_SelectableObjectSet;
54 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SensitiveEntitySet> > SelectMgr_MapOfObjectSensitives;
55 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SensitiveEntitySet> >::Iterator SelectMgr_MapOfObjectSensitivesIterator;
57 typedef NCollection_DataMap<Handle(SelectMgr_EntityOwner), Standard_Integer> SelectMgr_MapOfOwnerDetectedEntities;
58 typedef NCollection_DataMap<Handle(SelectMgr_EntityOwner), Standard_Integer>::Iterator SelectMgr_MapOfOwnerDetectedEntitiesIterator;
60 class SelectMgr_ToleranceMap
64 SelectMgr_ToleranceMap();
66 Standard_EXPORT ~SelectMgr_ToleranceMap();
68 Standard_EXPORT void Add (const Standard_Real& theTolerance);
70 Standard_EXPORT void Decrement (const Standard_Real& theTolerance);
72 Standard_EXPORT Standard_Real Largest();
75 NCollection_DataMap<Standard_Real, Standard_Integer> myTolerances;
76 Standard_Real myLargestKey;
79 //! A framework to define finding, sorting the sensitive
80 //! primitives in a view. Services are also provided to
81 //! define the return of the owners of those primitives
82 //! selected. The primitives are sorted by criteria such
83 //! as priority of the primitive or its depth in the view
84 //! relative to that of other primitives.
85 //! Note that in 3D, the inheriting framework
86 //! StdSelect_ViewerSelector3d is only to be used
87 //! if you do not want to use the services provided by
89 //! Two tools are available to find and select objects
90 //! found at a given position in the view. If you want to
91 //! select the owners of all the objects detected at
92 //! point x,y,z you use the Init - More - Next - Picked
93 //! loop. If, on the other hand, you want to select only
94 //! one object detected at that point, you use the Init -
95 //! More - OnePicked loop. In this iteration, More is
96 //! used to see if an object was picked and
97 //! OnePicked, to get the object closest to the pick position.
98 //! Viewer selectors are driven by
99 //! SelectMgr_SelectionManager, and manipulate
100 //! the SelectMgr_Selection objects given to them by
101 //! the selection manager.
102 class SelectMgr_ViewerSelector : public MMgt_TShared
106 //! Empties all the tables, removes all selections...
107 Standard_EXPORT void Clear();
109 //! returns the Sensitivity of picking
110 Standard_Real Sensitivity() const;
112 //! Sorts the detected entites by priority and distance.
113 //! to be redefined if other criterion are used...
114 Standard_EXPORT void SortResult();
116 //! Begins an iteration scanning for the owners detected at a position in the view.
119 //! Continues the interation scanning for the owners
120 //! detected at a position in the view, or
121 //! - continues the iteration scanning for the owner
122 //! closest to the position in the view.
123 Standard_EXPORT Standard_Boolean More();
125 //! Returns the next owner found in the iteration. This is
126 //! a scan for the owners detected at a position in the view.
129 //! Returns the current selected entity detected by the selector;
130 Standard_EXPORT Handle_SelectMgr_EntityOwner Picked() const;
132 //! Returns the picked element with the highest priority,
133 //! and which is the closest to the last successful mouse position.
134 Standard_EXPORT Handle_SelectMgr_EntityOwner OnePicked();
136 //! Set preference of selecting one object for OnePicked() method:
137 //! - If True, objects with less depth (distance fron the view plane) are
138 //! preferred regardless of priority (priority is used then to choose among
139 //! objects with similar depth),
140 //! - If False, objects with higher priority are preferred regardless of the
141 //! depth which is used to choose among objects of the same priority.
142 void SetPickClosest (const Standard_Boolean preferClosest);
144 //! Returns the number of owners found at a position in
145 //! the view by the Init - More - Next - Picked iteration.
146 Standard_EXPORT Standard_Integer NbPicked() const;
148 //! Returns the entity which is at rank <aRank>
149 //! in the list of stored ones.
150 Standard_EXPORT Handle_SelectMgr_EntityOwner Picked (const Standard_Integer aRank) const;
152 Standard_EXPORT Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const;
154 //! Returns the list of selection modes ModeList found in
155 //! this selector for the selectable object aSelectableObject.
156 //! Returns true if aSelectableObject is referenced inside
157 //! this selector; returns false if the object is not present
158 //! in this selector.
159 Standard_EXPORT Standard_Boolean Modes (const Handle(SelectMgr_SelectableObject)& theSelectableObject,
160 TColStd_ListOfInteger& theModeList,
161 const SelectMgr_StateOfSelection theWantedState = SelectMgr_SOS_Any) const;
163 //! Returns true if the selectable object
164 //! aSelectableObject having the selection mode aMode
165 //! is active in this selector.
166 Standard_EXPORT Standard_Boolean IsActive (const Handle(SelectMgr_SelectableObject)& theSelectableObject,
167 const Standard_Integer theMode) const;
169 //! Returns true if the selectable object
170 //! aSelectableObject having the selection mode aMode
171 //! is in this selector.
172 Standard_EXPORT Standard_Boolean IsInside (const Handle(SelectMgr_SelectableObject)& theSelectableObject,
173 const Standard_Integer theMode) const;
175 //! Returns the selection status Status of the selection aSelection.
176 Standard_EXPORT SelectMgr_StateOfSelection Status (const Handle(SelectMgr_Selection)& theSelection) const;
178 Standard_EXPORT TCollection_AsciiString Status (const Handle(SelectMgr_SelectableObject)& theSelectableObject) const;
180 //! Returns the list of active entity owners
181 Standard_EXPORT NCollection_List<Handle(SelectBasics_EntityOwner)> ActiveOwners() const;
183 //! Adds new object to the map of selectable objects
184 Standard_EXPORT void AddSelectableObject (const Handle(SelectMgr_SelectableObject)& theObject);
186 //! Adds new selection to the object and builds its BVH tree
187 Standard_EXPORT void AddSelectionToObject (const Handle(SelectMgr_SelectableObject)& theObject,
188 const Handle(SelectMgr_Selection)& theSelection);
190 //! Removes selectable object from map of selectable ones
191 Standard_EXPORT void RemoveSelectableObject (const Handle(SelectMgr_SelectableObject)& theObject);
193 //! Removes selection of the object and marks its BVH tree for rebuild
194 Standard_EXPORT void RemoveSelectionOfObject (const Handle(SelectMgr_SelectableObject)& theObject,
195 const Handle(SelectMgr_Selection)& theSelection);
197 //! Marks BVH of selectable objects for rebuild. Parameter theIsForce set as true
198 //! guarantees that 1st level BVH for the viewer selector will be rebuilt during this call
199 Standard_EXPORT void RebuildObjectsTree (const Standard_Boolean theIsForce = Standard_False);
201 //! Marks BVH of sensitive entities of particular selectable object for rebuild. Parameter
202 //! theIsForce set as true guarantees that 2nd level BVH for the object given will be
203 //! rebuilt during this call
204 Standard_EXPORT void RebuildSensitivesTree (const Handle(SelectMgr_SelectableObject)& theObject,
205 const Standard_Boolean theIsForce = Standard_False);
207 //! Initializes internal iterator for stored detected sensitive entities
208 Standard_EXPORT void InitDetected();
210 //! Makes a step along the map of detected sensitive entities and their owners
211 Standard_EXPORT void NextDetected();
213 //! Returns true if iterator of map of detected sensitive entities has reached
215 Standard_EXPORT Standard_Boolean MoreDetected();
217 //! Returns sensitive entity that was detected during the previous run of
218 //! selection algorithm
219 Standard_EXPORT const Handle(SelectBasics_SensitiveEntity)& DetectedEntity() const;
221 //! Returns instance of selecting volume manager of the viewer selector
222 Standard_EXPORT SelectMgr_SelectingVolumeManager& GetManager();
224 friend class SelectMgr_SelectionManager;
226 DEFINE_STANDARD_RTTI(SelectMgr_ViewerSelector)
230 Standard_EXPORT SelectMgr_ViewerSelector();
232 //! Traverses BVH containing all added selectable objects and
233 //! finds candidates for further search of overlap
234 Standard_EXPORT void TraverseSensitives();
236 //! Returns True if the owner provides clipping by depth
237 //! for its sensitives. Override this method to tell the selector
238 //! to use the DepthClipping method for the owner.
239 //! Default implementation returns False for every owner.
240 //! @param theOwner [in] the onwer to check.
241 //! @return True if owner provides depth limits for sensitive clipping.
242 Standard_EXPORT virtual Standard_Boolean HasDepthClipping (const Handle(SelectMgr_EntityOwner)& theOwner) const;
244 //! Internal function that checks if there is possible overlap
245 //! between some entity of selectable object theObject and
246 //! current selecting volume
247 void traverseObject (const Handle(SelectMgr_SelectableObject)& theObject);
249 //! Internal function that checks if a particular sensitive
250 //! entity theEntity overlaps current selecting volume precisely
251 void checkOverlap (const Handle(SelectBasics_SensitiveEntity)& theEntity,
252 const Standard_Integer theEntityIdx,
253 SelectMgr_SelectingVolumeManager& theMgr);
255 //! Marks all added sensitive entities of all objects as non-selectable
256 void resetSelectionActivationStatus();
260 void Activate (const Handle(SelectMgr_Selection)& theSelection);
262 void Deactivate (const Handle(SelectMgr_Selection)& theSelection);
264 //! removes a Selection from the Selector
265 void Remove (const Handle(SelectMgr_Selection)& aSelection);
269 Standard_Boolean preferclosest;
270 Standard_Real mytolerance;
271 Standard_Boolean myToUpdateTolerance;
272 SelectMgr_IndexedDataMapOfOwnerCriterion mystored;
273 SelectMgr_SelectingVolumeManager mySelectingVolumeMgr;
274 mutable NCollection_Handle<SelectMgr_SelectableObjectSet> mySelectableObjects;
275 SelectMgr_ToleranceMap myTolerances;
279 Handle_TColStd_HArray1OfInteger myIndexes;
280 Standard_Integer myCurRank;
281 Standard_Boolean myIsLeftChildQueuedFirst;
282 Standard_Integer myEntityIdx;
283 SelectMgr_MapOfObjectSensitives myMapOfObjectSensitives;
284 SelectMgr_MapOfOwnerDetectedEntities myMapOfDetected;
285 SelectMgr_MapOfOwnerDetectedEntitiesIterator myDetectedIter;
288 DEFINE_STANDARD_HANDLE(SelectMgr_ViewerSelector, MMgt_TShared)
290 #include <SelectMgr_ViewerSelector.lxx>