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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _SelectMgr_SelectableObject_HeaderFile
18 #define _SelectMgr_SelectableObject_HeaderFile
20 #include <PrsMgr_PresentableObject.hxx>
21 #include <SelectMgr_IndexedMapOfOwner.hxx>
22 #include <SelectMgr_SequenceOfSelection.hxx>
23 #include <SelectMgr_Selection.hxx>
24 #include <SelectMgr_SequenceOfOwner.hxx>
26 class SelectMgr_EntityOwner;
27 class Prs3d_Presentation;
28 class Standard_NotImplemented;
29 class SelectMgr_SelectionManager;
31 //! A framework to supply the structure of the object to be selected.
32 //! At the first pick, this structure is created by calling the appropriate algorithm and retaining this framework for further picking.
33 //! This abstract framework is inherited in Application Interactive Services (AIS), notably in AIS_InteractiveObject.
34 //! Consequently, 3D selection should be handled by the relevant daughter classes and their member functions in AIS.
35 //! This is particularly true in the creation of new interactive objects.
37 //! Key interface methods to be implemented by every Selectable Object:
38 //! * Presentable Object (PrsMgr_PresentableObject)
39 //! Consider defining an enumeration of supported Display Mode indexes for particular Interactive Object or class of Interactive Objects.
40 //! - AcceptDisplayMode() accepting display modes implemented by this object;
41 //! - Compute() computing presentation for the given display mode index;
42 //! * Selectable Object (SelectMgr_SelectableObject)
43 //! Consider defining an enumeration of supported Selection Mode indexes for particular Interactive Object or class of Interactive Objects.
44 //! - ComputeSelection() computing selectable entities for the given selection mode index.
45 class SelectMgr_SelectableObject : public PrsMgr_PresentableObject
47 DEFINE_STANDARD_RTTIEXT(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
48 friend class SelectMgr_SelectionManager;
51 //! Clears all selections of the object
52 Standard_EXPORT virtual ~SelectMgr_SelectableObject();
54 //! Computes sensitive primitives for the given selection mode - key interface method of Selectable Object.
55 //! @param theSelection selection to fill
56 //! @param theMode selection mode to create sensitive primitives
57 virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
58 const Standard_Integer theMode) = 0;
60 //! Informs the graphic context that the interactive Object may be decomposed into sub-shapes for dynamic selection.
61 //! The most used Interactive Object is AIS_Shape.
62 virtual Standard_Boolean AcceptShapeDecomposition() const { return Standard_False; }
64 //! Re-computes the sensitive primitives for all modes. IMPORTANT: Do not use
65 //! this method to update selection primitives except implementing custom selection manager!
66 //! This method does not take into account necessary BVH updates, but may invalidate the pointers
67 //! it refers to. TO UPDATE SELECTION properly from outside classes, use method UpdateSelection.
68 Standard_EXPORT void RecomputePrimitives();
70 //! Re-computes the sensitive primitives which correspond to the <theMode>th selection mode.
71 //! IMPORTANT: Do not use this method to update selection primitives except implementing custom selection manager!
72 //! selection manager! This method does not take into account necessary BVH updates, but may invalidate
73 //! the pointers it refers to. TO UPDATE SELECTION properly from outside classes, use method UpdateSelection.
74 Standard_EXPORT void RecomputePrimitives (const Standard_Integer theMode);
76 //! Adds the selection aSelection with the selection mode
77 //! index aMode to this framework.
78 Standard_EXPORT void AddSelection (const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode);
80 //! Empties all the selections in the SelectableObject
81 //! <update> parameter defines whether all object's
82 //! selections should be flagged for further update or not.
83 //! This improved method can be used to recompute an
84 //! object's selection (without redisplaying the object
85 //! completely) when some selection mode is activated not for the first time.
86 Standard_EXPORT void ClearSelections (const Standard_Boolean update = Standard_False);
88 //! Returns the selection having specified selection mode or NULL.
89 Standard_EXPORT const Handle(SelectMgr_Selection)& Selection (const Standard_Integer theMode) const;
91 //! Returns true if a selection corresponding to the selection mode theMode was computed for this object.
92 Standard_Boolean HasSelection (const Standard_Integer theMode) const { return !Selection (theMode).IsNull(); }
94 //! Return the sequence of selections.
95 const SelectMgr_SequenceOfSelection& Selections() const { return myselections; }
97 Standard_EXPORT void ResetTransformation() Standard_OVERRIDE;
99 //! Recomputes the location of the selection aSelection.
100 Standard_EXPORT virtual void UpdateTransformation() Standard_OVERRIDE;
102 //! Updates locations in all sensitive entities from <aSelection>
103 //! and in corresponding entity owners.
104 Standard_EXPORT virtual void UpdateTransformations (const Handle(SelectMgr_Selection)& aSelection);
106 //! Method which draws selected owners ( for fast presentation draw )
107 Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
108 const SelectMgr_SequenceOfOwner& theSeq);
110 //! Method which clear all selected owners belonging
111 //! to this selectable object ( for fast presentation draw )
112 Standard_EXPORT virtual void ClearSelected();
114 //! Method that needs to be implemented when the object
115 //! manages selection and dynamic highlighting on its own.
116 //! Clears or invalidates dynamic highlight presentation.
117 //! By default it clears immediate draw of given presentation
119 Standard_EXPORT virtual void ClearDynamicHighlight (const Handle(PrsMgr_PresentationManager)& theMgr);
121 //! Method which hilight an owner belonging to
122 //! this selectable object ( for fast presentation draw )
123 Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& thePM,
124 const Handle(Prs3d_Drawer)& theStyle,
125 const Handle(SelectMgr_EntityOwner)& theOwner);
127 //! If returns True, the old mechanism for highlighting selected objects is used (HilightSelected Method may be empty).
128 //! If returns False, the HilightSelected method will be fully responsible for highlighting selected entity owners belonging to this selectable object.
129 virtual Standard_Boolean IsAutoHilight() const { return myAutoHilight; }
131 //! Set AutoHilight property to true or false.
132 virtual void SetAutoHilight (const Standard_Boolean theAutoHilight) { myAutoHilight = theAutoHilight; }
134 //! Creates or returns existing presentation for highlighting detected object.
135 //! @param thePrsMgr presentation manager to create new presentation
136 //! @return existing or newly created presentation (when thePrsMgr is not NULL)
137 Standard_EXPORT Handle(Prs3d_Presentation) GetHilightPresentation (const Handle(PrsMgr_PresentationManager)& thePrsMgr);
139 //! Creates or returns existing presentation for highlighting selected object.
140 //! @param thePrsMgr presentation manager to create new presentation
141 //! @return existing or newly created presentation (when thePrsMgr is not NULL)
142 Standard_EXPORT Handle(Prs3d_Presentation) GetSelectPresentation (const Handle(PrsMgr_PresentationManager)& thePrsMgr);
144 //! Removes presentations returned by GetHilightPresentation() and GetSelectPresentation().
145 Standard_EXPORT virtual void ErasePresentations (Standard_Boolean theToRemove);
147 //! Set Z layer ID and update all presentations of the selectable object.
148 //! The layers mechanism allows drawing objects in higher layers in overlay of objects in lower layers.
149 Standard_EXPORT virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE;
151 //! Sets update status FULL to selections of the object. Must be used as the only method of UpdateSelection
152 //! from outer classes to prevent BVH structures from being outdated.
153 void UpdateSelection (const Standard_Integer theMode = -1)
155 updateSelection (theMode);
158 //! Sets common entity owner for assembly sensitive object entities
159 Standard_EXPORT void SetAssemblyOwner (const Handle(SelectMgr_EntityOwner)& theOwner, const Standard_Integer theMode = -1);
161 //! Returns a bounding box of sensitive entities with the owners given if they are a part of activated selection
162 Standard_EXPORT Bnd_Box BndBoxOfSelected (const Handle(SelectMgr_IndexedMapOfOwner)& theOwners);
164 //! Returns the mode for selection of object as a whole; 0 by default.
165 Standard_Integer GlobalSelectionMode() const { return myGlobalSelMode; }
167 //! Returns the owner of mode for selection of object as a whole
168 Standard_EXPORT virtual Handle(SelectMgr_EntityOwner) GlobalSelOwner() const;
170 //! Returns common entity owner if the object is an assembly
171 Standard_EXPORT virtual const Handle(SelectMgr_EntityOwner)& GetAssemblyOwner() const;
175 //! Begins the iteration scanning for sensitive primitives.
176 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
177 void Init() { mycurrent = 1; }
179 //! Continues the iteration scanning for sensitive primitives.
180 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
181 Standard_Boolean More() const { return mycurrent <= myselections.Length(); }
183 //! Continues the iteration scanning for sensitive primitives.
184 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
185 void Next() { ++mycurrent; }
187 //! Returns the current selection in this framework.
188 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
189 const Handle(SelectMgr_Selection)& CurrentSelection() const { return myselections (mycurrent); }
193 //! Protected empty constructor.
194 Standard_EXPORT SelectMgr_SelectableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
196 //! Override global selection mode.
197 void setGlobalSelMode (const Standard_Integer theMode)
199 myGlobalSelMode = theMode > 0 ? theMode : 0;
202 //! Update clipping planes state.
203 Standard_EXPORT virtual void UpdateClipping() Standard_OVERRIDE;
205 //! Sets update status FULL to selections of the object.
206 //! Must be used as the only method of UpdateSelection from outer classes to prevent BVH structures from being outdated.
207 Standard_EXPORT virtual void updateSelection (const Standard_Integer theMode);
211 SelectMgr_SequenceOfSelection myselections; //!< list of selections
212 Handle(Prs3d_Presentation) mySelectionPrs; //!< optional presentation for highlighting selected object
213 Handle(Prs3d_Presentation) myHilightPrs; //!< optional presentation for highlighting detected object
214 Standard_Integer myGlobalSelMode; //!< global selection mode
215 Standard_Integer mycurrent; //!< [deprecated] iterator value
216 Standard_Boolean myAutoHilight; //!< auto-highlighting flag defining
220 DEFINE_STANDARD_HANDLE(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
222 #endif // _SelectMgr_SelectableObject_HeaderFile