1287306fb04d020f82e9bf35e84c755132a0d149
[occt.git] / src / SelectMgr / SelectMgr_Selection.hxx
1 // Created on: 1995-02-16
2 // Created by: Mister rmi
3 // Copyright (c) 1995-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 #ifndef _SelectMgr_Selection_HeaderFile
18 #define _SelectMgr_Selection_HeaderFile
19
20 #include <NCollection_Vector.hxx>
21 #include <SelectMgr_SensitiveEntity.hxx>
22 #include <SelectMgr_StateOfSelection.hxx>
23 #include <SelectMgr_TypeOfBVHUpdate.hxx>
24 #include <SelectMgr_TypeOfUpdate.hxx>
25
26 class Select3D_SensitiveEntity;
27
28 //!  Represents the state of a given selection mode for a
29 //! Selectable Object. Contains all the sensitive entities available for this mode.
30 //! An interactive object can have an indefinite number of
31 //! modes of selection, each representing a
32 //! "decomposition" into sensitive primitives; each
33 //! primitive has an Owner (SelectMgr_EntityOwner)
34 //! which allows us to identify the exact entity which has
35 //! been detected. Each Selection mode is identified by
36 //! an index. The set of sensitive primitives which
37 //! correspond to a given mode is stocked in a
38 //! SelectMgr_Selection object. By Convention, the
39 //! default selection mode which allows us to grasp the
40 //! Interactive object in its entirety will be mode 0.
41 //! AIS_Trihedron : 4 selection modes
42 //! -   mode 0 : selection of a trihedron
43 //! -   mode 1 : selection of the origin of the trihedron
44 //! -   mode 2 : selection of the axes
45 //! -   mode 3 : selection of the planes XOY, YOZ, XOZ
46 //! when you activate one of modes 1 2 3 4 , you pick AIS objects of type:
47 //! -   AIS_Point
48 //! -   AIS_Axis (and information on the type of axis)
49 //! -   AIS_Plane (and information on the type of plane).
50 //!   AIS_PlaneTrihedron offers 3 selection modes:
51 //! -   mode 0 : selection of the whole trihedron
52 //! -   mode 1 : selection of the origin of the trihedron
53 //! -   mode 2 : selection of the axes - same remarks as for the Trihedron.
54 //! AIS_Shape : 7 maximum selection modes, depending
55 //! on the complexity of the shape :
56 //! -   mode 0 : selection of the AIS_Shape
57 //! -   mode 1 : selection of the vertices
58 //! -   mode 2 : selection of the edges
59 //! -   mode 3 : selection of the wires
60 //! -   mode 4 : selection of the faces
61 //! -   mode 5 : selection of the shells
62 //! -   mode 6 :   selection of the constituent solids.
63 class SelectMgr_Selection : public Standard_Transient
64 {
65   DEFINE_STANDARD_RTTIEXT(SelectMgr_Selection, Standard_Transient)
66 public:
67
68   //! Constructs a selection object defined by the selection mode IdMode.
69   //! The default setting 0 is the selection mode for a shape in its entirety.
70   Standard_EXPORT SelectMgr_Selection (const Standard_Integer theModeIdx = 0);
71
72   Standard_EXPORT ~SelectMgr_Selection();
73
74   Standard_EXPORT void Destroy();
75
76   //! Adds the sensitive primitive to the list of stored entities in this object.
77   //! Raises NullObject if the primitive is a null handle.
78   Standard_EXPORT void Add (const Handle(Select3D_SensitiveEntity)& theSensitive);
79
80   //! empties the selection from all the stored entities
81   Standard_EXPORT void Clear();
82
83   //! returns true if no sensitive entity is stored.
84   Standard_Boolean IsEmpty() const { return myEntities.IsEmpty(); }
85
86   //! returns the selection mode represented by this selection
87   Standard_Integer Mode() const { return myMode; }
88
89   //! Return entities.
90   const NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>& Entities() const { return myEntities; }
91
92   //! Return entities.
93   NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>& ChangeEntities() { return myEntities; }
94
95   //! Begins an iteration scanning for sensitive primitives.
96   Standard_DEPRECATED("Deprecated method, Entities() should be used instead")
97   void Init() { myEntityIter = myEntities.Lower(); }
98
99   //! Continues the iteration scanning for sensitive
100   //! primitives with the mode defined in this framework.
101   Standard_DEPRECATED("Deprecated method, Entities() should be used instead")
102   Standard_Boolean More() const { return myEntityIter <= myEntities.Upper(); }
103
104   //! Returns the next sensitive primitive found in the
105   //! iteration. This is a scan for entities with the mode
106   //! defined in this framework.
107   Standard_DEPRECATED("Deprecated method, Entities() should be used instead")
108   void Next() { ++myEntityIter; }
109
110   //! Returns any sensitive primitive in this framework.
111   Standard_DEPRECATED("Deprecated method, Entities() should be used instead")
112   const Handle(SelectMgr_SensitiveEntity)& Sensitive() const { return myEntities.Value (myEntityIter); }
113
114   //! Returns the flag UpdateFlag.
115   //! This flage gives the update status of this framework
116   //! in a ViewerSelector object:
117   //! -   full
118   //! -   partial, or
119   //! -   none.
120   SelectMgr_TypeOfUpdate UpdateStatus() const { return myUpdateStatus; }
121
122   void UpdateStatus (const SelectMgr_TypeOfUpdate theStatus) { myUpdateStatus = theStatus; }
123
124   void UpdateBVHStatus (const SelectMgr_TypeOfBVHUpdate theStatus) { myBVHUpdateStatus = theStatus; }
125
126   SelectMgr_TypeOfBVHUpdate BVHUpdateStatus() const { return myBVHUpdateStatus; }
127
128   //! Returns status of selection
129   SelectMgr_StateOfSelection GetSelectionState() const { return mySelectionState; }
130
131   //! Sets status of selection
132   void SetSelectionState (const SelectMgr_StateOfSelection theState) const { mySelectionState = theState; }
133
134   //! Returns sensitivity of the selection
135   Standard_Integer Sensitivity() const { return mySensFactor; }
136
137   //! Changes sensitivity of the selection and all its entities to the given value.
138   //! IMPORTANT: This method does not update any outer selection structures, so for
139   //! proper updates use SelectMgr_SelectionManager::SetSelectionSensitivity method.
140   Standard_EXPORT void SetSensitivity (const Standard_Integer theNewSens);
141
142 private:
143
144   NCollection_Vector<Handle(SelectMgr_SensitiveEntity)> myEntities;
145   Standard_Integer                                      myEntityIter;
146   Standard_Integer                                      myMode;
147   SelectMgr_TypeOfUpdate                                myUpdateStatus;
148   mutable SelectMgr_StateOfSelection                    mySelectionState;
149   mutable SelectMgr_TypeOfBVHUpdate                     myBVHUpdateStatus;
150   Standard_Integer                                      mySensFactor;
151   Standard_Boolean                                      myIsCustomSens;
152 };
153
154 DEFINE_STANDARD_HANDLE(SelectMgr_Selection, Standard_Transient)
155
156 #endif