0027819: Visualization - provide a possibility to redefine SelectMgr_SelectableObject...
[occt.git] / src / SelectMgr / SelectMgr_SelectableObject.hxx
CommitLineData
42cf5bc1 1// Created on: 1995-02-20
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_SelectableObject_HeaderFile
18#define _SelectMgr_SelectableObject_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_Type.hxx>
22
23#include <SelectMgr_SequenceOfSelection.hxx>
24#include <Prs3d_Drawer.hxx>
25#include <Standard_Integer.hxx>
26#include <Standard_Boolean.hxx>
27#include <PrsMgr_PresentableObject.hxx>
28#include <PrsMgr_TypeOfPresentation3d.hxx>
29#include <SelectMgr_Selection.hxx>
30#include <PrsMgr_PresentationManager3d.hxx>
31#include <SelectMgr_SequenceOfOwner.hxx>
32#include <Quantity_NameOfColor.hxx>
33#include <Graphic3d_ZLayerId.hxx>
34#include <SelectMgr_IndexedMapOfOwner.hxx>
35class SelectMgr_EntityOwner;
36class Prs3d_Presentation;
37class Standard_NotImplemented;
38class SelectMgr_SelectionManager;
39class Bnd_Box;
40
41
42class SelectMgr_SelectableObject;
43DEFINE_STANDARD_HANDLE(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
44
45//! A framework to supply the structure of the object to be
46//! selected. At the first pick, this structure is created by
47//! calling the appropriate algorithm and retaining this
48//! framework for further picking.
49//! This abstract framework is inherited in Application
50//! Interactive Services (AIS), notably in AIS_InteractiveObject.
51//! Consequently, 3D selection should be handled by the
52//! relevant daughter classes and their member functions
53//! in AIS. This is particularly true in the creation of new interactive objects.
54class SelectMgr_SelectableObject : public PrsMgr_PresentableObject
55{
56
57public:
58
4c0d97ac 59 //! Clears all selections of the object
60 Standard_EXPORT virtual ~SelectMgr_SelectableObject();
42cf5bc1 61
62 //! Recovers and calculates any sensitive primitive,
63 //! aSelection, available in Shape mode, specified by
64 //! aMode. As a rule, these are sensitive faces.
65 //! This method is defined as virtual. This enables you to
66 //! implement it in the creation of a new class of AIS
67 //! Interactive Object. You need to do this and in so
68 //! doing, redefine this method, if you create a class
69 //! which enriches the list of signatures and types.
70 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) = 0;
71
72 //! Re-computes the sensitive primitives for all modes. IMPORTANT: Do not use
73 //! this method to update selection primitives except implementing custom selection manager!
74 //! This method does not take into account necessary BVH updates, but may invalidate the pointers
75 //! it refers to. TO UPDATE SELECTION properly from outside classes, use method UpdateSelection.
76 Standard_EXPORT void RecomputePrimitives();
77
78 //! Re-computes the sensitive primitives which correspond to the <theMode>th selection mode.
79 //! IMPORTANT: Do not use this method to update selection primitives except implementing custom selection manager!
80 //! selection manager! This method does not take into account necessary BVH updates, but may invalidate
81 //! the pointers it refers to. TO UPDATE SELECTION properly from outside classes, use method UpdateSelection.
82 Standard_EXPORT void RecomputePrimitives (const Standard_Integer theMode);
83
84 //! Adds the selection aSelection with the selection mode
85 //! index aMode to this framework.
86 Standard_EXPORT void AddSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode);
87
88 //! Empties all the selections in the SelectableObject
89 //! <update> parameter defines whether all object's
90 //! selections should be flagged for further update or not.
91 //! This improved method can be used to recompute an
92 //! object's selection (without redisplaying the object
93 //! completely) when some selection mode is activated not for the first time.
94 Standard_EXPORT void ClearSelections (const Standard_Boolean update = Standard_False);
95
96 //! Returns the selection Selection having the selection mode aMode.
97 Standard_EXPORT const Handle(SelectMgr_Selection)& Selection (const Standard_Integer aMode) const;
98
99 //! Returns true if a selection corresponding to the
7411850a 100 //! selection mode theMode was computed for this object.
101 Standard_EXPORT virtual Standard_Boolean HasSelection (const Standard_Integer theMode) const;
42cf5bc1 102
103 //! Begins the iteration scanning for sensitive primitives.
21a2b7cc 104 void Init()
105 {
106 mycurrent = 1;
107 }
108
42cf5bc1 109 //! Continues the iteration scanning for sensitive primitives.
21a2b7cc 110 Standard_Boolean More() const
111 {
112 return mycurrent <= myselections.Length();
113 }
114
42cf5bc1 115 //! Continues the iteration scanning for sensitive primitives.
21a2b7cc 116 void Next()
117 {
118 mycurrent++;
119 }
120
42cf5bc1 121 //! Returns the current selection in this framework.
21a2b7cc 122 const Handle(SelectMgr_Selection)& CurrentSelection() const
123 {
124 return myselections (mycurrent);
125 }
126
42cf5bc1 127 Standard_EXPORT void ResetTransformation() Standard_OVERRIDE;
128
129 //! Recomputes the location of the selection aSelection.
130 Standard_EXPORT virtual void UpdateTransformation() Standard_OVERRIDE;
131
132 //! Updates locations in all sensitive entities from <aSelection>
133 //! and in corresponding entity owners.
134 Standard_EXPORT virtual void UpdateTransformations (const Handle(SelectMgr_Selection)& aSelection);
135
136 //! Method which draws selected owners ( for fast presentation draw )
137 Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager3d)& PM, const SelectMgr_SequenceOfOwner& Seq);
138
139 //! Method which clear all selected owners belonging
140 //! to this selectable object ( for fast presentation draw )
141 Standard_EXPORT virtual void ClearSelected();
142
143 //! Method which hilight an owner belonging to
144 //! this selectable object ( for fast presentation draw )
145 Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
146
147 //! If returns True, the old mechanism for highlighting
148 //! selected objects is used (HilightSelected Method may be empty).
149 //! If returns False, the HilightSelected method will be
150 //! fully responsible for highlighting selected entity
151 //! owners belonging to this selectable object.
152 Standard_EXPORT virtual Standard_Boolean IsAutoHilight() const;
153
154 //! Set AutoHilight property to true or false
155 //! Sets up Transform Persistence Mode for this object
156 Standard_EXPORT virtual void SetAutoHilight (const Standard_Boolean newAutoHilight);
157
158 Standard_EXPORT Handle(Prs3d_Presentation) GetHilightPresentation (const Handle(PrsMgr_PresentationManager3d)& TheMgr);
159
160 Standard_EXPORT Handle(Prs3d_Presentation) GetSelectPresentation (const Handle(PrsMgr_PresentationManager3d)& TheMgr);
161
162 //! Set Z layer ID and update all presentations of the selectable object.
163 //! The layers mechanism allows drawing objects in higher layers in overlay of objects in lower layers.
164 Standard_EXPORT virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
165
166 //! Sets update status FULL to selections of the object. Must be used as the only method of UpdateSelection
167 //! from outer classes to prevent BVH structures from being outdated.
21a2b7cc 168 void UpdateSelection (const Standard_Integer theMode = -1)
169 {
170 updateSelection (theMode);
171 }
172
42cf5bc1 173 //! Returns bounding box of selectable object
174 //! by storing its minimum and maximum 3d coordinates
175 //! to output parameters
176 Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) = 0;
177
178 //! Initializes the drawing tool theDrawer.
179 Standard_EXPORT virtual void SetAttributes (const Handle(Prs3d_Drawer)& theDrawer);
180
181 //! Returns the attributes settings.
21a2b7cc 182 const Handle(Prs3d_Drawer)& Attributes() const
183 {
184 return myDrawer;
185 }
186
42cf5bc1 187 //! Clears settings provided by the drawing tool theDrawer.
188 Standard_EXPORT virtual void UnsetAttributes();
189
190 //! Initializes the hilight drawing tool theDrawer.
191 Standard_EXPORT virtual void SetHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer);
192
193 //! Returns the hilight attributes settings.
21a2b7cc 194 const Handle(Prs3d_Drawer)& HilightAttributes() const
195 {
196 return myHilightDrawer;
197 }
198
42cf5bc1 199 //! Clears settings provided by the hilight drawing tool theDrawer.
200 Standard_EXPORT virtual void UnsetHilightAttributes();
201
202 //! Initializes theDrawer by default hilight settings.
203 Standard_EXPORT static void InitDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer);
204
205 //! Sets common entity owner for assembly sensitive object entities
206 Standard_EXPORT void SetAssemblyOwner (const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Integer theMode = -1);
207
208 //! Returns common entity owner if the object is an assembly
209 Standard_EXPORT const Handle(SelectMgr_EntityOwner)& GetAssemblyOwner() const;
210
211 //! Returns a bounding box of sensitive entities with the owners given
212 //! if they are a part of activated selection
213 Standard_EXPORT Bnd_Box BndBoxOfSelected (Handle(SelectMgr_IndexedMapOfOwner)& theOwners);
214
c3282ec1 215 //! Returns the mode for selection of object as a whole
21a2b7cc 216 Standard_Integer GlobalSelectionMode() const
217 {
218 return myGlobalSelMode;
219 }
c3282ec1 220
221 //! Returns the owner of mode for selection of object as a whole
222 Standard_EXPORT virtual Handle(SelectMgr_EntityOwner) GlobalSelOwner() const;
223
42cf5bc1 224
225friend class SelectMgr_SelectionManager;
226
227
92efcf78 228 DEFINE_STANDARD_RTTIEXT(SelectMgr_SelectableObject,PrsMgr_PresentableObject)
42cf5bc1 229
230protected:
231
42cf5bc1 232 Standard_EXPORT SelectMgr_SelectableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
233
21a2b7cc 234 void setGlobalSelMode (const Standard_Integer theMode)
235 {
236 myGlobalSelMode = theMode > 0 ? theMode : 0;
237 }
238
239 Standard_EXPORT virtual void updateSelection (const Standard_Integer theMode);
240
241protected:
c3282ec1 242
42cf5bc1 243 SelectMgr_SequenceOfSelection myselections;
244 Handle(Prs3d_Drawer) myDrawer;
245 Handle(Prs3d_Drawer) myHilightDrawer;
246 Handle(SelectMgr_EntityOwner) myAssemblyOwner;
21a2b7cc 247 Standard_Boolean myAutoHilight;
42cf5bc1 248
249private:
250
42cf5bc1 251 Standard_Integer mycurrent;
42cf5bc1 252 Handle(Prs3d_Presentation) mySelectionPrs;
253 Handle(Prs3d_Presentation) myHilightPrs;
c3282ec1 254 Standard_Integer myGlobalSelMode;
42cf5bc1 255};
256
42cf5bc1 257#endif // _SelectMgr_SelectableObject_HeaderFile