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