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