0024623: Visualization - improve selection mechanism
[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
17
18#ifndef _Select3D_SensitiveGroup_HeaderFile
19#define _Select3D_SensitiveGroup_HeaderFile
20
21#include <Standard.hxx>
22#include <Standard_DefineHandle.hxx>
23#include <Standard_Type.hxx>
24
25#include <Select3D_EntitySequence.hxx>
26#include <Select3D_SensitiveEntity.hxx>
27#include <Select3D_SensitiveSet.hxx>
28#include <Handle_SelectBasics_EntityOwner.hxx>
29#include <SelectMgr_SelectingVolumeManager.hxx>
30
31class SelectBasics_EntityOwner;
32class TopLoc_Location;
33
34
35//! A framework to define selection of a sensitive group
36//! by a sensitive entity which is a set of 3D sensitive entities.
37//! Remark: 2 modes are possible for rectangle selection
38//! the group is considered selected
39//! 1) when all the entities inside are selected in the rectangle
40//! 2) only one entity inside is selected by the rectangle
41//! By default the "Match All entities" mode is set.
42class Select3D_SensitiveGroup : public Select3D_SensitiveSet
43{
44public:
45
46 //! Constructs an empty sensitive group object.
47 //! This is a set of sensitive 3D entities. The sensitive
48 //! entities will be defined using the function Add to fill
49 //! the entity owner OwnerId. If MatchAll is false, nothing can be added.
50 Standard_EXPORT Select3D_SensitiveGroup (const Handle(SelectBasics_EntityOwner)& theOwnerId,
51 const Standard_Boolean theIsMustMatchAll = Standard_True);
52
53 //! Constructs a sensitive group object defined by the list
54 //! TheList and the entity owner OwnerId. If MatchAll is false, nothing is done.
55 Standard_EXPORT Select3D_SensitiveGroup (const Handle(SelectBasics_EntityOwner)& theOwnerId,
56 Select3D_EntitySequence& theEntities,
57 const Standard_Boolean theIsMustMatchAll = Standard_True);
58
59 //! Adds the list of sensitive entities LL to the empty
60 //! sensitive group object created at construction time.
61 Standard_EXPORT void Add (Select3D_EntitySequence& theEntities);
62
63 //! Adds the sensitive entity aSensitive to the non-empty
64 //! sensitive group object created at construction time.
65 Standard_EXPORT void Add (const Handle(Select3D_SensitiveEntity)& theSensitive);
66
67 Standard_EXPORT void Remove (const Handle(Select3D_SensitiveEntity)& theSensitive);
68
69 //! Removes all sensitive entities from the list used at the
70 //! time of construction, or added using the function Add.
71 Standard_EXPORT void Clear();
72
73 //! Returns true if the sensitive entity aSensitive is in
74 //! the list used at the time of construction, or added using the function Add.
75 Standard_EXPORT Standard_Boolean IsIn (const Handle(Select3D_SensitiveEntity)& theSensitive) const;
76
77 //! Sets the requirement that all sensitive entities in the
78 //! list used at the time of construction, or added using
79 //! the function Add must be matched.
80 void SetMatchType (const Standard_Boolean theIsMustMatchAll);
81
82 //! Returns true if all sensitive entities in the list used
83 //! at the time of construction, or added using the function Add must be matched.
84 Standard_Boolean MustMatchAll() const;
85
86 //! Checks whether the group overlaps current selecting volume
87 Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
88 SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
89
90 //! Returns the amount of sub-entities
91 Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
92
93 Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
94
95 //! Sets the owner for all entities in group
96 Standard_EXPORT void Set (const Handle(SelectBasics_EntityOwner)& theOwnerId);
97
98 //! Gets group content
99 const Select3D_EntitySequence& GetEntities() const;
100
101 //! Returns bounding box of the group. If location transformation
102 //! is set, it will be applied
103 Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
104
105 //! Returns center of entity set. If location transformation
106 //! is set, it will be applied
107 Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
108
109 //! Returns bounding box of sensitive entity with index theIdx
110 Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
111
112 //! Returns geometry center of sensitive entity index theIdx in
113 //! the vector along the given axis theAxis
114 Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
115 const Standard_Integer theAxis) const Standard_OVERRIDE;
116
117 //! Swaps items with indexes theIdx1 and theIdx2 in the vector
118 Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
119 const Standard_Integer theIdx2) Standard_OVERRIDE;
120
121 //! Returns the length of vector of sensitive entities
122 Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
123
124 DEFINE_STANDARD_RTTI(Select3D_SensitiveGroup)
125
126private:
127
128 //! Checks whether the entity with index theIdx overlaps the current selecting volume
129 virtual Standard_Boolean overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
130 Standard_Integer theElemIdx,
131 Standard_Real& theMatchDepth) Standard_OVERRIDE;
132
133 //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
134 virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
135
136private:
137
138 Select3D_EntitySequence myEntities; //!< Grouped sensitive entities
139 Standard_Boolean myMustMatchAll; //!< Determines whether all entities in the group should be overlapped or not
140 gp_Pnt myCenter; //!< Center of geometry of the group
141 mutable Select3D_BndBox3d myBndBox; //!< Bounding box of the group
142 NCollection_Vector<Standard_Integer> myBVHPrimIndexes; //!< Vector of sub-entities indexes for BVH tree build
143};
144
145DEFINE_STANDARD_HANDLE(Select3D_SensitiveGroup, Select3D_SensitiveEntity)
146
147#include <Select3D_SensitiveGroup.lxx>
148
149#endif // _Select3D_SensitiveGroup_HeaderFile