1 // Created on: 1998-04-16
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-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.
17 #ifndef _Select3D_SensitiveGroup_HeaderFile
18 #define _Select3D_SensitiveGroup_HeaderFile
20 #include <Select3D_EntitySequence.hxx>
21 #include <Select3D_IndexedMapOfEntity.hxx>
22 #include <Select3D_SensitiveEntity.hxx>
23 #include <Select3D_SensitiveSet.hxx>
24 #include <SelectMgr_SelectingVolumeManager.hxx>
26 //! A framework to define selection of a sensitive group
27 //! by a sensitive entity which is a set of 3D sensitive entities.
28 //! Remark: 2 modes are possible for rectangle selection
29 //! the group is considered selected
30 //! 1) when all the entities inside are selected in the rectangle
31 //! 2) only one entity inside is selected by the rectangle
32 //! By default the "Match All entities" mode is set.
33 class Select3D_SensitiveGroup : public Select3D_SensitiveSet
35 DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveGroup, Select3D_SensitiveSet)
38 //! Constructs an empty sensitive group object.
39 //! This is a set of sensitive 3D entities. The sensitive
40 //! entities will be defined using the function Add to fill
41 //! the entity owner OwnerId. If MatchAll is false, nothing can be added.
42 Standard_EXPORT Select3D_SensitiveGroup (const Handle(SelectBasics_EntityOwner)& theOwnerId,
43 const Standard_Boolean theIsMustMatchAll = Standard_True);
45 //! Constructs a sensitive group object defined by the list
46 //! TheList and the entity owner OwnerId. If MatchAll is false, nothing is done.
47 Standard_EXPORT Select3D_SensitiveGroup (const Handle(SelectBasics_EntityOwner)& theOwnerId,
48 Select3D_EntitySequence& theEntities,
49 const Standard_Boolean theIsMustMatchAll = Standard_True);
51 //! Gets group content
52 const Select3D_IndexedMapOfEntity& Entities() const { return myEntities; }
54 //! Access entity by index [1, NbSubElements()].
55 const Handle(Select3D_SensitiveEntity)& SubEntity (const Standard_Integer theIndex) const
57 return myEntities.FindKey (theIndex);
60 //! Return last detected entity.
61 Handle(Select3D_SensitiveEntity) LastDetectedEntity() const
63 const Standard_Integer anIndex = LastDetectedEntityIndex();
64 return anIndex != -1 ? myEntities.FindKey (anIndex) : Handle(Select3D_SensitiveEntity)();
67 //! Return index of last detected entity.
68 Standard_Integer LastDetectedEntityIndex() const { return myDetectedIdx != -1 ? myBVHPrimIndexes.Value (myDetectedIdx) : -1; }
70 //! Adds the list of sensitive entities LL to the empty
71 //! sensitive group object created at construction time.
72 Standard_EXPORT void Add (Select3D_EntitySequence& theEntities);
74 //! Adds the sensitive entity aSensitive to the non-empty
75 //! sensitive group object created at construction time.
76 Standard_EXPORT void Add (const Handle(Select3D_SensitiveEntity)& theSensitive);
78 Standard_EXPORT void Remove (const Handle(Select3D_SensitiveEntity)& theSensitive);
80 //! Removes all sensitive entities from the list used at the
81 //! time of construction, or added using the function Add.
82 Standard_EXPORT void Clear() Standard_OVERRIDE;
84 //! Returns true if the sensitive entity aSensitive is in
85 //! the list used at the time of construction, or added using the function Add.
86 Standard_EXPORT Standard_Boolean IsIn (const Handle(Select3D_SensitiveEntity)& theSensitive) const;
88 //! Sets the requirement that all sensitive entities in the
89 //! list used at the time of construction, or added using
90 //! the function Add must be matched.
91 void SetMatchType (const Standard_Boolean theIsMustMatchAll) { myMustMatchAll = theIsMustMatchAll; }
93 //! Returns true if all sensitive entities in the list used
94 //! at the time of construction, or added using the function Add must be matched.
95 Standard_Boolean MustMatchAll() const { return myMustMatchAll; }
97 //! Returns TRUE if all sensitive entities should be checked within rectangular/polygonal selection, FALSE by default.
98 //! Can be useful for sensitive entities holding detection results as class property.
99 Standard_Boolean ToCheckOverlapAll() const
101 return myToCheckOverlapAll;
104 //! Returns TRUE if all sensitive entities should be checked within rectangular/polygonal selection, FALSE by default.
105 //! Can be useful for sensitive entities holding detection results as class property.
106 void SetCheckOverlapAll (Standard_Boolean theToCheckAll)
108 myToCheckOverlapAll = theToCheckAll;
111 //! Checks whether the group overlaps current selecting volume
112 Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
113 SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
115 //! Returns the amount of sub-entities
116 Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
118 Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
120 //! Sets the owner for all entities in group
121 Standard_EXPORT void Set (const Handle(SelectBasics_EntityOwner)& theOwnerId) Standard_OVERRIDE;
123 //! Returns bounding box of the group. If location transformation
124 //! is set, it will be applied
125 Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
127 //! Returns center of entity set. If location transformation
128 //! is set, it will be applied
129 Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
131 //! Returns bounding box of sensitive entity with index theIdx
132 Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
134 //! Returns geometry center of sensitive entity index theIdx in
135 //! the vector along the given axis theAxis
136 Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
137 const Standard_Integer theAxis) const Standard_OVERRIDE;
139 //! Swaps items with indexes theIdx1 and theIdx2 in the vector
140 Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
141 const Standard_Integer theIdx2) Standard_OVERRIDE;
143 //! Returns the length of vector of sensitive entities
144 Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
148 //! Checks whether the entity with index theIdx overlaps the current selecting volume
149 virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult,
150 SelectBasics_SelectingVolumeManager& theMgr,
151 Standard_Integer theElemIdx,
152 Standard_Boolean theIsFullInside) Standard_OVERRIDE;
154 //! Checks whether the entity with index theIdx is inside the current selecting volume
155 virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
156 Standard_Integer theElemIdx,
157 Standard_Boolean theIsFullInside) Standard_OVERRIDE;
159 //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
160 virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
164 Select3D_IndexedMapOfEntity myEntities; //!< Grouped sensitive entities
165 Standard_Boolean myMustMatchAll; //!< Determines whether all entities in the group should be overlapped or not
166 Standard_Boolean myToCheckOverlapAll; //!< flag to check overlapping with all entities within rectangular/polygonal selection
167 gp_Pnt myCenter; //!< Center of geometry of the group
168 mutable Select3D_BndBox3d myBndBox; //!< Bounding box of the group
169 NCollection_Vector<Standard_Integer> myBVHPrimIndexes; //!< Vector of sub-entities indexes for BVH tree build
172 DEFINE_STANDARD_HANDLE(Select3D_SensitiveGroup, Select3D_SensitiveEntity)
174 #endif // _Select3D_SensitiveGroup_HeaderFile