f751596e |
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 |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
f751596e |
17 | #ifndef _Select3D_SensitiveGroup_HeaderFile |
18 | #define _Select3D_SensitiveGroup_HeaderFile |
19 | |
f751596e |
20 | #include <Select3D_EntitySequence.hxx> |
7f5945d6 |
21 | #include <Select3D_IndexedMapOfEntity.hxx> |
f751596e |
22 | #include <Select3D_SensitiveEntity.hxx> |
23 | #include <Select3D_SensitiveSet.hxx> |
f751596e |
24 | #include <SelectMgr_SelectingVolumeManager.hxx> |
25 | |
f751596e |
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 |
34 | { |
0609d8ee |
35 | DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveGroup, Select3D_SensitiveSet) |
f751596e |
36 | public: |
37 | |
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. |
0ef04197 |
42 | Standard_EXPORT Select3D_SensitiveGroup (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
f751596e |
43 | const Standard_Boolean theIsMustMatchAll = Standard_True); |
44 | |
45 | //! Constructs a sensitive group object defined by the list |
46 | //! TheList and the entity owner OwnerId. If MatchAll is false, nothing is done. |
0ef04197 |
47 | Standard_EXPORT Select3D_SensitiveGroup (const Handle(SelectMgr_EntityOwner)& theOwnerId, |
f751596e |
48 | Select3D_EntitySequence& theEntities, |
49 | const Standard_Boolean theIsMustMatchAll = Standard_True); |
50 | |
a228288f |
51 | //! Gets group content |
7f5945d6 |
52 | const Select3D_IndexedMapOfEntity& Entities() const { return myEntities; } |
a228288f |
53 | |
54 | //! Access entity by index [1, NbSubElements()]. |
55 | const Handle(Select3D_SensitiveEntity)& SubEntity (const Standard_Integer theIndex) const |
56 | { |
7f5945d6 |
57 | return myEntities.FindKey (theIndex); |
a228288f |
58 | } |
59 | |
60 | //! Return last detected entity. |
61 | Handle(Select3D_SensitiveEntity) LastDetectedEntity() const |
62 | { |
63 | const Standard_Integer anIndex = LastDetectedEntityIndex(); |
7f5945d6 |
64 | return anIndex != -1 ? myEntities.FindKey (anIndex) : Handle(Select3D_SensitiveEntity)(); |
a228288f |
65 | } |
66 | |
67 | //! Return index of last detected entity. |
68 | Standard_Integer LastDetectedEntityIndex() const { return myDetectedIdx != -1 ? myBVHPrimIndexes.Value (myDetectedIdx) : -1; } |
69 | |
f751596e |
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); |
73 | |
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); |
77 | |
78 | Standard_EXPORT void Remove (const Handle(Select3D_SensitiveEntity)& theSensitive); |
79 | |
80 | //! Removes all sensitive entities from the list used at the |
81 | //! time of construction, or added using the function Add. |
79104795 |
82 | Standard_EXPORT void Clear() Standard_OVERRIDE; |
f751596e |
83 | |
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; |
87 | |
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. |
0609d8ee |
91 | void SetMatchType (const Standard_Boolean theIsMustMatchAll) { myMustMatchAll = theIsMustMatchAll; } |
f751596e |
92 | |
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. |
0609d8ee |
95 | Standard_Boolean MustMatchAll() const { return myMustMatchAll; } |
f751596e |
96 | |
a228288f |
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 |
100 | { |
101 | return myToCheckOverlapAll; |
102 | } |
103 | |
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) |
107 | { |
108 | myToCheckOverlapAll = theToCheckAll; |
109 | } |
110 | |
f751596e |
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; |
114 | |
115 | //! Returns the amount of sub-entities |
fe758dbe |
116 | Standard_EXPORT virtual Standard_Integer NbSubElements() const Standard_OVERRIDE; |
f751596e |
117 | |
118 | Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE; |
119 | |
120 | //! Sets the owner for all entities in group |
0ef04197 |
121 | Standard_EXPORT void Set (const Handle(SelectMgr_EntityOwner)& theOwnerId) Standard_OVERRIDE; |
f751596e |
122 | |
f751596e |
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; |
126 | |
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; |
130 | |
131 | //! Returns bounding box of sensitive entity with index theIdx |
132 | Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE; |
133 | |
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; |
138 | |
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; |
142 | |
143 | //! Returns the length of vector of sensitive entities |
144 | Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE; |
145 | |
bc73b006 |
146 | //! Dumps the content of me into the stream |
147 | Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; |
148 | |
25333d45 |
149 | protected: |
f751596e |
150 | |
151 | //! Checks whether the entity with index theIdx overlaps the current selecting volume |
25333d45 |
152 | Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult, |
153 | SelectBasics_SelectingVolumeManager& theMgr, |
154 | Standard_Integer theElemIdx, |
155 | Standard_Boolean theIsFullInside) Standard_OVERRIDE; |
f751596e |
156 | |
2157d6ac |
157 | //! Checks whether the entity with index theIdx is inside the current selecting volume |
25333d45 |
158 | Standard_EXPORT virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr, |
159 | Standard_Integer theElemIdx, |
160 | Standard_Boolean theIsFullInside) Standard_OVERRIDE; |
2157d6ac |
161 | |
f751596e |
162 | //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry |
25333d45 |
163 | Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE; |
f751596e |
164 | |
165 | private: |
166 | |
7f5945d6 |
167 | Select3D_IndexedMapOfEntity myEntities; //!< Grouped sensitive entities |
f751596e |
168 | Standard_Boolean myMustMatchAll; //!< Determines whether all entities in the group should be overlapped or not |
a228288f |
169 | Standard_Boolean myToCheckOverlapAll; //!< flag to check overlapping with all entities within rectangular/polygonal selection |
f751596e |
170 | gp_Pnt myCenter; //!< Center of geometry of the group |
171 | mutable Select3D_BndBox3d myBndBox; //!< Bounding box of the group |
172 | NCollection_Vector<Standard_Integer> myBVHPrimIndexes; //!< Vector of sub-entities indexes for BVH tree build |
173 | }; |
174 | |
175 | DEFINE_STANDARD_HANDLE(Select3D_SensitiveGroup, Select3D_SensitiveEntity) |
176 | |
f751596e |
177 | #endif // _Select3D_SensitiveGroup_HeaderFile |