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