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