0029365: Visualization, TKOpenGl - do not include hidden structures to Rendered withi...
[occt.git] / src / PrsMgr / PrsMgr_PresentableObject.hxx
CommitLineData
42cf5bc1 1// Created on: 1995-01-25
2// Created by: Jean-Louis Frenkel
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 _PrsMgr_PresentableObject_HeaderFile
18#define _PrsMgr_PresentableObject_HeaderFile
19
1f7f5a90 20#include <gp_GTrsf.hxx>
21#include <Graphic3d_ClipPlane.hxx>
42cf5bc1 22#include <Graphic3d_SequenceOfHClipPlane.hxx>
1f7f5a90 23#include <Graphic3d_TransformPers.hxx>
24#include <Graphic3d_TransModeFlags.hxx>
42cf5bc1 25#include <Graphic3d_ZLayerId.hxx>
b5cce1ab 26#include <Prs3d_Drawer.hxx>
42cf5bc1 27#include <PrsMgr_ListOfPresentableObjects.hxx>
42cf5bc1 28#include <PrsMgr_Presentation.hxx>
1f7f5a90 29#include <PrsMgr_Presentations.hxx>
42cf5bc1 30#include <PrsMgr_PresentationManager3d.hxx>
1f7f5a90 31#include <PrsMgr_PresentableObjectPointer.hxx>
32#include <PrsMgr_TypeOfPresentation3d.hxx>
42cf5bc1 33#include <TColStd_ListOfInteger.hxx>
42cf5bc1 34
35//! A framework to supply the Graphic3d
36//! structure of the object to be presented. On the first
37//! display request, this structure is created by calling the
38//! appropriate algorithm and retaining this frameworkfor
39//! further display.
40//! This abstract framework is inherited in Application
41//! Interactive Services (AIS), notably in:
42//! - AIS_InteractiveObject
43//! - AIS_ConnectedInteractive
44//! - AIS_MultipleConnectedInteractive
45//! - AIS_Shape
46//! Consequently, 3D presentation should be handled by
47//! the relevant daughter classes and their member
48//! functions in AIS. This is particularly true in the
49//! creation of new interactive objects.
f838dac4 50class PrsMgr_PresentableObject : public Standard_Transient
42cf5bc1 51{
f838dac4 52 DEFINE_STANDARD_RTTIEXT(PrsMgr_PresentableObject, Standard_Transient)
53 friend class PrsMgr_Presentation;
54 friend class PrsMgr_PresentationManager;
42cf5bc1 55public:
56
1f7f5a90 57 PrsMgr_Presentations& Presentations() { return myPresentations; }
be5c3602 58
42cf5bc1 59 //! Returns information on whether the object accepts display in HLR mode or not.
3202bf1e 60 PrsMgr_TypeOfPresentation3d TypeOfPresentation3d() const { return myTypeOfPresentation3d; }
be5c3602 61
778cd667 62 //! @return transform persistence of the presentable object.
63 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTransformPersistence; }
64
65 //! Sets up Transform Persistence for this object.
66 Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers);
67
42cf5bc1 68 //! Sets up Transform Persistence Mode for this object.
69 //! This function used to lock in object position, rotation and / or zooming relative to camera position.
778cd667 70 //! Object will be drawn in the origin setted by thePoint parameter (except Graphic3d_TMF_TriedronPers flag
71 //! - see description later). theMode should be:
42cf5bc1 72 //! - Graphic3d_TMF_None - no persistence attributes (reset);
42cf5bc1 73 //! - Graphic3d_TMF_ZoomPers - object doesn't resize;
74 //! - Graphic3d_TMF_RotatePers - object doesn't rotate;
778cd667 75 //! - Graphic3d_TMF_ZoomRotatePers - object doesn't resize and rotate;
76 //! - Graphic3d_TMF_RotatePers - object doesn't rotate;
77 //! - Graphic3d_TMF_TriedronPers - object behaves like trihedron.
78 //! If Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d persistence mode selected thePoint coordinates X and Y means:
42cf5bc1 79 //! - X = 0.0, Y = 0.0 - center of view window;
80 //! - X > 0.0, Y > 0.0 - right upper corner of view window;
81 //! - X > 0.0, Y < 0.0 - right lower corner of view window;
82 //! - X < 0.0, Y > 0.0 - left upper corner of view window;
83 //! - X < 0.0, Y < 0.0 - left lower corner of view window.
84 //! And Z coordinate defines the gap from border of view window (except center position).
778cd667 85 Standard_DEPRECATED("This method is deprecated - SetTransformPersistence() taking Graphic3d_TransformPers should be called instead")
86 void SetTransformPersistence (const Graphic3d_TransModeFlags theMode, const gp_Pnt& thePoint = gp_Pnt (0.0, 0.0, 0.0))
87 {
88 SetTransformPersistence (Graphic3d_TransformPers::FromDeprecatedParams (theMode, thePoint));
89 }
1d92133e 90
42cf5bc1 91 //! Gets Transform Persistence Mode for this object
778cd667 92 Standard_DEPRECATED("This method is deprecated - TransformPersistence() should be called instead")
93 Graphic3d_TransModeFlags GetTransformPersistenceMode() const
94 {
95 return myTransformPersistence.IsNull()
96 ? Graphic3d_TMF_None
97 : myTransformPersistence->Mode();
98 }
99
42cf5bc1 100 //! Gets point of transform persistence for this object
778cd667 101 Standard_DEPRECATED("This method is deprecated - TransformPersistence() should be called instead")
42cf5bc1 102 Standard_EXPORT gp_Pnt GetTransformPersistencePoint() const;
825aa485 103
42cf5bc1 104 Standard_EXPORT void SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d aType);
105
106 //! flags the Prs of mode <AMode> to be Updated.
107 //! the Update will be done when needed.
108 Standard_EXPORT void SetToUpdate (const Standard_Integer aMode);
109
110 //! flags all the Presentations to be Updated.
111 Standard_EXPORT void SetToUpdate();
112
113 //! gives the list of modes which are flagged "to be updated".
114 Standard_EXPORT void ToBeUpdated (TColStd_ListOfInteger& ListOfMode) const;
115
1f7f5a90 116 //! Return the local transformation.
117 const Handle(Geom_Transformation)& LocalTransformationGeom() const { return myLocalTransformation; }
118
42cf5bc1 119 //! Sets local transformation to theTransformation.
1f7f5a90 120 void SetLocalTransformation (const gp_Trsf& theTrsf) { setLocalTransformation (new Geom_Transformation (theTrsf)); }
121
122 //! Sets local transformation to theTransformation.
123 void SetLocalTransformation (const Handle(Geom_Transformation)& theTrsf) { setLocalTransformation (theTrsf); }
124
42cf5bc1 125 //! Returns true if object has a transformation that is different from the identity.
1f7f5a90 126 Standard_Boolean HasTransformation() const { return !myTransformation.IsNull() && myTransformation->Form() != gp_Identity; }
3202bf1e 127
1f7f5a90 128 //! Return the transformation taking into account transformation of parent object(s).
129 const Handle(Geom_Transformation)& TransformationGeom() const { return myTransformation; }
3202bf1e 130
1f7f5a90 131 //! Return the local transformation.
132 const gp_Trsf& LocalTransformation() const { return !myLocalTransformation.IsNull()
133 ? myLocalTransformation->Trsf()
134 : getIdentityTrsf(); }
135
136 //! Return the transformation taking into account transformation of parent object(s).
137 const gp_Trsf& Transformation() const { return !myTransformation.IsNull()
138 ? myTransformation->Trsf()
139 : getIdentityTrsf(); }
3202bf1e 140
141 const gp_GTrsf& InversedTransformation() const { return myInvTransformation; }
42cf5bc1 142
143 //! resets local transformation to identity.
144 Standard_EXPORT virtual void ResetTransformation();
145
146 Standard_EXPORT virtual void UpdateTransformation();
147
148 Standard_EXPORT virtual void UpdateTransformation (const Handle(Prs3d_Presentation)& P);
149
150 //! Set Z layer ID and update all presentations of the presentable object.
151 //! The layers mechanism allows drawing objects in higher layers in overlay of objects in lower layers.
152 Standard_EXPORT virtual void SetZLayer (const Graphic3d_ZLayerId theLayerId);
153
154 //! Get ID of Z layer.
155 Standard_EXPORT Graphic3d_ZLayerId ZLayer() const;
156
157 //! Adds clip plane for graphical clipping for all display mode
158 //! presentations. The composition of clip planes truncates the rendering
159 //! space to convex volume. Please be aware that number of supported
160 //! clip plane is limited. The planes which exceed the limit are ignored.
161 //! Besides of this, some planes can be already set in view where the object
162 //! is shown: the number of these planes should be substracted from limit
163 //! to predict the maximum possible number of object clipping planes.
164 //! @param thePlane [in] the clip plane to be appended to map of clip planes.
165 Standard_EXPORT virtual void AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane);
166
167 //! Removes previously added clip plane.
168 //! @param thePlane [in] the clip plane to be removed from map of clip planes.
169 Standard_EXPORT virtual void RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane);
170
171 //! Set clip planes for graphical clipping for all display mode presentations.
3202bf1e 172 //! The composition of clip planes truncates the rendering space to convex volume.
173 //! Please be aware that number of supported clip plane is limited.
174 //! The planes which exceed the limit are ignored.
175 //! Besides of this, some planes can be already set in view where the object is shown:
176 //! the number of these planes should be subtracted from limit to predict the maximum
42cf5bc1 177 //! possible number of object clipping planes.
3202bf1e 178 Standard_EXPORT virtual void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
179
180 Standard_DEPRECATED("This method is deprecated - overload taking Handle should be used instead")
181 void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
182 {
183 Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = new Graphic3d_SequenceOfHClipPlane (thePlanes);
184 SetClipPlanes (aPlanes);
185 }
186
42cf5bc1 187 //! Get clip planes.
188 //! @return set of previously added clip planes for all display mode presentations.
3202bf1e 189 const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const { return myClipPlanes; }
190
42cf5bc1 191 //! Sets if the object has mutable nature (content or location will be changed regularly).
192 //! This method should be called before object displaying to take effect.
193 Standard_EXPORT virtual void SetMutable (const Standard_Boolean theIsMutable);
194
195 //! Returns true if object has mutable nature (content or location are be changed regularly).
196 //! Mutable object will be managed in different way than static onces (another optimizations).
3202bf1e 197 Standard_Boolean IsMutable() const { return myIsMutable; }
42cf5bc1 198
199 //! Makes theObject child of current object in scene hierarchy.
200 Standard_EXPORT virtual void AddChild (const Handle(PrsMgr_PresentableObject)& theObject);
201
202 //! Removes theObject from children of current object in scene hierarchy.
203 Standard_EXPORT virtual void RemoveChild (const Handle(PrsMgr_PresentableObject)& theObject);
204
205 //! Returns children of the current object.
3202bf1e 206 const PrsMgr_ListOfPresentableObjects& Children() const { return myChildren; }
be5c3602 207
42cf5bc1 208 //! Returns true if object should have own presentations.
3202bf1e 209 Standard_Boolean HasOwnPresentations() const { return myHasOwnPresentations; }
be5c3602 210
42cf5bc1 211 //! Returns parent of current object in scene hierarchy.
3202bf1e 212 PrsMgr_PresentableObjectPointer Parent() const { return myParent; }
42cf5bc1 213
f838dac4 214 //! Initializes the drawing tool theDrawer.
215 Standard_EXPORT virtual void SetAttributes(const Handle(Prs3d_Drawer)& theDrawer);
42cf5bc1 216
f838dac4 217 //! Returns the attributes settings.
218 const Handle(Prs3d_Drawer)& Attributes() const
219 {
220 return myDrawer;
221 }
222
223 //! Clears settings provided by the drawing tool theDrawer.
224 Standard_EXPORT virtual void UnsetAttributes();
225
226 //! Returns the hilight attributes settings.
cee2b556 227 //! When not NULL, overrides both Prs3d_TypeOfHighlight_LocalSelected and Prs3d_TypeOfHighlight_Selected defined within AIS_InteractiveContext.
f838dac4 228 const Handle(Prs3d_Drawer)& HilightAttributes() const { return myHilightDrawer; }
229
230 //! Initializes the hilight drawing tool theDrawer.
231 virtual void SetHilightAttributes(const Handle(Prs3d_Drawer)& theDrawer) { myHilightDrawer = theDrawer; }
232
233 //! Returns the hilight attributes settings.
cee2b556 234 //! When not NULL, overrides both Prs3d_TypeOfHighlight_LocalDynamic and Prs3d_TypeOfHighlight_Dynamic defined within AIS_InteractiveContext.
f838dac4 235 const Handle(Prs3d_Drawer)& DynamicHilightAttributes() const { return myDynHilightDrawer; }
236
237 //! Initializes the dynamic hilight drawing tool.
238 virtual void SetDynamicHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer) { myDynHilightDrawer = theDrawer; }
239
240 //! Clears settings provided by the hilight drawing tool theDrawer.
241 virtual void UnsetHilightAttributes() { myHilightDrawer.Nullify(); }
42cf5bc1 242
42cf5bc1 243protected:
244
245
246 Standard_EXPORT PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
247Standard_EXPORT virtual ~PrsMgr_PresentableObject();
248
249 //! Calculates the 3D view aPresentation and its
250 //! updates. The latter are managed by aPresentationManager.
251 //! aPresentableObject has the display mode aMode;
252 //! this has the default value of 0, that is, the wireframe display mode.
8b9a309b 253 Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPresentation, const Standard_Integer aMode);
42cf5bc1 254
255 //! Calculates the 3D view aPresentation and its
256 //! updates. The latter are managed by
257 //! aPresentationManager. Each of the views in the
258 //! viewer and every modification such as rotation, for
259 //! example, entails recalculation.
260 //! It must be redefined to implement hidden line removal
261 //! for the object. The user never calls this method
262 //! himself. This is done via the InteractiveContext object
263 //! and is dependent on the point of view from which the
264 //! object is displayed.
265 Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation);
266
267 //! Calculates the 3D view aPresentation and its
268 //! updates. The latter are managed by
269 //! aPresentationManager. A point of view is provided
270 //! by the projector aProjector, and the geometric
271 //! transformation which has transformed associated
272 //! presentable objects is specified by aTrsf.
273 //! This function is to be used in case where a hidden
274 //! line removal display cannot be calculated
275 //! automatically. This occurs when associated
276 //! presentable objects have been transformed
277 //! geometrically, but not translated.
278 //! Warning
279 //! The transformation aTrsf must be applied to the
280 //! object before computation.
281 Standard_EXPORT virtual void Compute (const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTrsf, const Handle(Prs3d_Presentation)& aPresentation);
282
283 //! recomputes all presentations of the object.
284 Standard_EXPORT void Update (const Standard_Boolean AllModes = Standard_False);
285
286 //! Recomputes the presentation in the given mode.
287 //! If ClearOther is true, other presentation will be cleared.
288 Standard_EXPORT void Update (const Standard_Integer aMode, const Standard_Boolean ClearOther);
289
290 //! High-level interface for controlling polygon offsets
8b9a309b 291 Standard_EXPORT virtual void Fill (const Handle(PrsMgr_PresentationManager)& aPresentationManager, const Handle(PrsMgr_Presentation)& aPresentation, const Standard_Integer aMode);
42cf5bc1 292
293 //! Sets myCombinedParentTransform to theTransformation. Thus object receives transformation
294 //! from parent node and able to derive its own.
1f7f5a90 295 Standard_EXPORT virtual void SetCombinedParentTransform (const Handle(Geom_Transformation)& theTrsf);
42cf5bc1 296
297 //! General virtual method for internal update of presentation state
298 //! when some modifications on list of clip planes occurs. Base
299 //! implementation propagate clip planes to every presentation.
300 Standard_EXPORT virtual void UpdateClipping();
301
1f7f5a90 302 //! Sets local transformation to theTransformation.
303 Standard_EXPORT virtual void setLocalTransformation (const Handle(Geom_Transformation)& theTransformation);
304
305private:
306
307 //! Return the identity transformation.
308 Standard_EXPORT static const gp_Trsf& getIdentityTrsf();
309
3202bf1e 310protected:
311
42cf5bc1 312 PrsMgr_Presentations myPresentations;
3202bf1e 313 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
f838dac4 314 Handle(Prs3d_Drawer) myDrawer;
315 Handle(Prs3d_Drawer) myHilightDrawer;
316 Handle(Prs3d_Drawer) myDynHilightDrawer;
317 PrsMgr_TypeOfPresentation3d myTypeOfPresentation3d;
42cf5bc1 318 Standard_Boolean myIsMutable;
42cf5bc1 319 Standard_Boolean myHasOwnPresentations;
320
42cf5bc1 321private:
322
778cd667 323 Handle(Graphic3d_TransformPers) myTransformPersistence;
42cf5bc1 324 PrsMgr_PresentableObjectPointer myParent;
1f7f5a90 325 Handle(Geom_Transformation) myLocalTransformation;
326 Handle(Geom_Transformation) myTransformation;
327 Handle(Geom_Transformation) myCombinedParentTransform;
91d96372 328 gp_GTrsf myInvTransformation;
42cf5bc1 329 PrsMgr_ListOfPresentableObjects myChildren;
330
42cf5bc1 331};
332
f838dac4 333DEFINE_STANDARD_HANDLE(PrsMgr_PresentableObject, Standard_Transient)
1f7f5a90 334
42cf5bc1 335#endif // _PrsMgr_PresentableObject_HeaderFile