0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[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
42cf5bc1 20#include <PrsMgr_PresentableObject.hxx>
b5cce1ab 21#include <SelectMgr_IndexedMapOfOwner.hxx>
22#include <SelectMgr_SequenceOfSelection.hxx>
42cf5bc1 23#include <SelectMgr_Selection.hxx>
42cf5bc1 24#include <SelectMgr_SequenceOfOwner.hxx>
b5cce1ab 25
42cf5bc1 26class SelectMgr_EntityOwner;
42cf5bc1 27class Standard_NotImplemented;
28class SelectMgr_SelectionManager;
42cf5bc1 29
2b886265 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.
42cf5bc1 44class SelectMgr_SelectableObject : public PrsMgr_PresentableObject
45{
f838dac4 46 DEFINE_STANDARD_RTTIEXT(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
47 friend class SelectMgr_SelectionManager;
42cf5bc1 48public:
49
4c0d97ac 50 //! Clears all selections of the object
51 Standard_EXPORT virtual ~SelectMgr_SelectableObject();
2b886265 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
42cf5bc1 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
b5cce1ab 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
42cf5bc1 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 )
2b886265 106 Standard_EXPORT virtual void HilightSelected (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
107 const SelectMgr_SequenceOfOwner& theSeq);
42cf5bc1 108
109 //! Method which clear all selected owners belonging
110 //! to this selectable object ( for fast presentation draw )
111 Standard_EXPORT virtual void ClearSelected();
731c9b5b 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.
2b886265 118 Standard_EXPORT virtual void ClearDynamicHighlight (const Handle(PrsMgr_PresentationManager)& theMgr);
731c9b5b 119
42cf5bc1 120 //! Method which hilight an owner belonging to
121 //! this selectable object ( for fast presentation draw )
2b886265 122 Standard_EXPORT virtual void HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& thePM,
f838dac4 123 const Handle(Prs3d_Drawer)& theStyle,
8e5fb5ea 124 const Handle(SelectMgr_EntityOwner)& theOwner);
42cf5bc1 125
2b886265 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; }
42cf5bc1 129
2b886265 130 //! Set AutoHilight property to true or false.
131 virtual void SetAutoHilight (const Standard_Boolean theAutoHilight) { myAutoHilight = theAutoHilight; }
42cf5bc1 132
2b886265 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);
905b0e31 142
143 //! Removes presentations returned by GetHilightPresentation() and GetSelectPresentation().
144 Standard_EXPORT virtual void ErasePresentations (Standard_Boolean theToRemove);
145
42cf5bc1 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.
21a2b7cc 152 void UpdateSelection (const Standard_Integer theMode = -1)
153 {
154 updateSelection (theMode);
155 }
156
42cf5bc1 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);
b5cce1ab 159
2b886265 160 //! Returns a bounding box of sensitive entities with the owners given if they are a part of activated selection
02974a19 161 Standard_EXPORT Bnd_Box BndBoxOfSelected (const Handle(SelectMgr_IndexedMapOfOwner)& theOwners);
42cf5bc1 162
2b886265 163 //! Returns the mode for selection of object as a whole; 0 by default.
164 Standard_Integer GlobalSelectionMode() const { return myGlobalSelMode; }
c3282ec1 165
166 //! Returns the owner of mode for selection of object as a whole
167 Standard_EXPORT virtual Handle(SelectMgr_EntityOwner) GlobalSelOwner() const;
168
b5cce1ab 169 //! Returns common entity owner if the object is an assembly
170 Standard_EXPORT virtual const Handle(SelectMgr_EntityOwner)& GetAssemblyOwner() const;
171
2b886265 172public:
173
174 //! Begins the iteration scanning for sensitive primitives.
175 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
176 void Init() { mycurrent = 1; }
177
178 //! Continues the iteration scanning for sensitive primitives.
179 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
180 Standard_Boolean More() const { return mycurrent <= myselections.Length(); }
181
182 //! Continues the iteration scanning for sensitive primitives.
183 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
184 void Next() { ++mycurrent; }
185
186 //! Returns the current selection in this framework.
187 Standard_DEPRECATED("Deprecated method, Selections() should be used instead")
188 const Handle(SelectMgr_Selection)& CurrentSelection() const { return myselections (mycurrent); }
189
42cf5bc1 190protected:
191
2b886265 192 //! Protected empty constructor.
42cf5bc1 193 Standard_EXPORT SelectMgr_SelectableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
194
2b886265 195 //! Override global selection mode.
21a2b7cc 196 void setGlobalSelMode (const Standard_Integer theMode)
197 {
198 myGlobalSelMode = theMode > 0 ? theMode : 0;
199 }
200
e2aba8eb 201 //! Update clipping planes state.
202 Standard_EXPORT virtual void UpdateClipping() Standard_OVERRIDE;
203
2b886265 204 //! Sets update status FULL to selections of the object.
205 //! Must be used as the only method of UpdateSelection from outer classes to prevent BVH structures from being outdated.
21a2b7cc 206 Standard_EXPORT virtual void updateSelection (const Standard_Integer theMode);
207
208protected:
c3282ec1 209
2b886265 210 SelectMgr_SequenceOfSelection myselections; //!< list of selections
211 Handle(Prs3d_Presentation) mySelectionPrs; //!< optional presentation for highlighting selected object
212 Handle(Prs3d_Presentation) myHilightPrs; //!< optional presentation for highlighting detected object
213 Standard_Integer myGlobalSelMode; //!< global selection mode
214 Standard_Integer mycurrent; //!< [deprecated] iterator value
215 Standard_Boolean myAutoHilight; //!< auto-highlighting flag defining
905b0e31 216
42cf5bc1 217};
218
b5cce1ab 219DEFINE_STANDARD_HANDLE(SelectMgr_SelectableObject, PrsMgr_PresentableObject)
220
42cf5bc1 221#endif // _SelectMgr_SelectableObject_HeaderFile