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