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