0027860: Visualization - clean up Transformation Persistence API
[occt.git] / src / Graphic3d / Graphic3d_ClipPlane.hxx
1 // Created on: 2013-07-12
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Graphic3d_ClipPlane_HeaderFile
17 #define _Graphic3d_ClipPlane_HeaderFile
18
19 #include <Standard_Macro.hxx>
20 #include <Standard_TypeDef.hxx>
21 #include <Standard_Transient.hxx>
22 #include <NCollection_Vec4.hxx>
23 #include <Graphic3d_AspectFillArea3d.hxx>
24 #include <Graphic3d_CappingFlags.hxx>
25 #include <Graphic3d_TextureMap.hxx>
26 #include <Aspect_HatchStyle.hxx>
27
28 class gp_Pln;
29
30 //! Container for properties describing graphic driver clipping planes.
31 //! It is up to application to create instances of this class and specify its
32 //! properties. The instances are passed into graphic driver or other facilities
33 //! that implement clipping features (e.g. selection).
34 //! Depending on usage context the class can be used to specify:
35 //! - Global clipping applied over the whole scene.
36 //! - Object-level clipping applied for each particular object.
37 //! The plane equation is specified in "world" coordinate system.
38 //! Please note that the set of planes can define convex clipping volume.
39 //! Be aware that number of clip planes supported by OpenGl is implementation
40 //! dependent: at least 6 planes are available. Thus, take into account
41 //! number of clipping planes passed for rendering: the object planes plus
42 //! the view defined ones.
43 class Graphic3d_ClipPlane : public Standard_Transient
44 {
45 public:
46
47   typedef NCollection_Vec4<Standard_Real> Equation;
48
49   //! Default constructor.
50   //! Initializes clip plane container with the following properties:
51   //! - Equation (0.0, 0.0, 1.0, 0)
52   //! - IsOn (True),
53   //! - IsCapping (False),
54   //! - Material (Graphic3d_NOM_DEFAULT),
55   //! - Texture (NULL),
56   //! - HatchStyle (Aspect_HS_HORIZONTAL),
57   //! - IsHatchOn (False)
58   Standard_EXPORT Graphic3d_ClipPlane();
59
60   //! Copy constructor.
61   //! @param theOther [in] the copied plane.
62   Standard_EXPORT Graphic3d_ClipPlane(const Graphic3d_ClipPlane& theOther);
63
64   //! Construct clip plane for the passed equation.
65   //! By default the plane is on, capping is turned off.
66   //! @param theEquation [in] the plane equation.
67   Standard_EXPORT Graphic3d_ClipPlane (const Equation& theEquation);
68
69   //! Construct clip plane from the passed geometrical definition.
70   //! By default the plane is on, capping is turned off.
71   //! @param thePlane [in] the plane.
72   Standard_EXPORT Graphic3d_ClipPlane (const gp_Pln& thePlane);
73
74   //! Set plane equation by its geometrical definition.
75   //! The equation is specified in "world" coordinate system.
76   //! @param thePlane [in] the plane.
77   Standard_EXPORT void SetEquation (const gp_Pln& thePlane);
78
79   //! Set 4-component equation vector for clipping plane.
80   //! The equation is specified in "world" coordinate system.
81   //! @param theEquation [in] the XYZW (or "ABCD") equation vector.
82   Standard_EXPORT void SetEquation (const Equation& theEquation);
83
84   //! Get 4-component equation vector for clipping plane.
85   //! @return clipping plane equation vector.
86   const Equation& GetEquation() const
87   {
88     return myEquation;
89   }
90
91   //! Check that the clipping plane is turned on.
92   //! @return boolean flag indicating whether the plane is in on or off state.
93   Standard_Boolean IsOn() const
94   {
95     return myIsOn;
96   }
97
98   //! Change state of the clipping plane.
99   //! @param theIsOn [in] the flag specifying whether the graphic driver
100   //! clipping by this plane should be turned on or off.
101   Standard_EXPORT void SetOn(const Standard_Boolean theIsOn);
102
103   //! Change state of capping surface rendering.
104   //! @param theIsOn [in] the flag specifying whether the graphic driver should
105   //! perform rendering of capping surface produced by this plane. The graphic
106   //! driver produces this surface for convex graphics by means of stencil-test
107   //! and multi-pass rendering.
108   Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
109
110   //! Check state of capping surface rendering.
111   //! @return true (turned on) or false depending on the state.
112   Standard_Boolean IsCapping() const
113   {
114     return myIsCapping;
115   }
116
117   //! Get geometrical definition. The plane is built up
118   //! from the equation clipping plane equation vector.
119   //! @return geometrical definition of clipping plane.
120   Standard_EXPORT gp_Pln ToPlane() const;
121
122   //! Clone plane. Virtual method to simplify copying procedure if plane
123   //! class is redefined at application level to add specific fields to it
124   //! e.g. id, name, etc.
125   //! @return new instance of clipping plane with same properties and attributes.
126   Standard_EXPORT virtual Handle(Graphic3d_ClipPlane) Clone() const;
127
128 public: // @name user-defined graphical attributes
129
130   //! Set material for rendering capping surface.
131   //! @param theMat [in] the material.
132   Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
133
134   //! @return capping material.
135   const Graphic3d_MaterialAspect& CappingMaterial() const { return myAspect->FrontMaterial(); }
136
137   //! Set texture to be applied on capping surface.
138   //! @param theTexture [in] the texture.
139   Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
140
141   //! @return capping texture map.
142   const Handle(Graphic3d_TextureMap)& CappingTexture() const { return myAspect->TextureMap(); }
143
144   //! Set hatch style (stipple) and turn hatching on.
145   //! @param theStyle [in] the hatch style.
146   Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
147
148   //! @return hatching style.
149   Aspect_HatchStyle CappingHatch() const { return myAspect->HatchStyle(); }
150
151   //! Turn on hatching.
152   Standard_EXPORT void SetCappingHatchOn();
153
154   //! Turn off hatching.
155   Standard_EXPORT void SetCappingHatchOff();
156
157   //! @return True if hatching mask is turned on.
158   Standard_Boolean IsHatchOn() const { return myAspect->InteriorStyle() == Aspect_IS_HATCH; }
159
160   //! This ID is used for managing associated resources in graphical driver.
161   //! The clip plane can be assigned within a range of IO which can be
162   //! displayed in separate OpenGl contexts. For each of the context an associated
163   //! OpenGl resource for graphical aspects should be created and kept.
164   //! The resources are stored in graphical driver for each of individual groups
165   //! of shared context under the clip plane identifier.
166   //! @return clip plane resource identifier string.
167   const TCollection_AsciiString& GetId() const
168   {
169     return myId;
170   }
171
172 public:
173
174   //! Return capping aspect.
175   //! @return capping surface rendering aspect.
176   const Handle(Graphic3d_AspectFillArea3d)& CappingAspect() const { return myAspect; }
177
178   //! Assign capping aspect.
179   Standard_EXPORT void SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
180
181   //! Flag indicating whether material for capping plane should be taken from object.
182   //! Default value: FALSE (use dedicated capping plane material).
183   bool ToUseObjectMaterial() const { return (myFlags & Graphic3d_CappingFlags_ObjectMaterial) != 0; }
184
185   //! Set flag for controlling the source of capping plane material.
186   void SetUseObjectMaterial (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectMaterial); }
187
188   //! Flag indicating whether texture for capping plane should be taken from object.
189   //! Default value: FALSE.
190   bool ToUseObjectTexture() const { return (myFlags & Graphic3d_CappingFlags_ObjectTexture) != 0; }
191
192   //! Set flag for controlling the source of capping plane texture.
193   void SetUseObjectTexture (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectTexture); }
194
195   //! Flag indicating whether shader program for capping plane should be taken from object.
196   //! Default value: FALSE.
197   bool ToUseObjectShader() const { return (myFlags & Graphic3d_CappingFlags_ObjectShader) != 0; }
198
199   //! Set flag for controlling the source of capping plane shader program.
200   void SetUseObjectShader(bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectShader); }
201
202   //! Return true if some fill area aspect properties should be taken from object.
203   bool ToUseObjectProperties() const { return myFlags != Graphic3d_CappingFlags_None; }
204
205 public: // @name modification counters
206
207   //! @return modification counter for equation.
208   unsigned int MCountEquation() const
209   {
210     return myEquationMod;
211   }
212
213   //! @return modification counter for aspect.
214   unsigned int MCountAspect() const
215   {
216     return myAspectMod;
217   }
218
219 private:
220
221   //! Generate unique object id for OpenGL graphic resource manager.
222   void makeId();
223
224   //! Set capping flag.
225   Standard_EXPORT void setCappingFlag (bool theToUse, int theFlag);
226
227 private:
228
229   Handle(Graphic3d_AspectFillArea3d) myAspect;    //!< fill area aspect
230   TCollection_AsciiString myId;                   //!< resource id
231   Equation                myEquation;             //!< plane equation vector
232   unsigned int            myFlags;                //!< capping flags
233   Standard_Boolean        myIsOn;                 //!< state of the clipping plane
234   Standard_Boolean        myIsCapping;            //!< state of graphic driver capping
235   unsigned int            myEquationMod;          //!< modification counter for equation
236   unsigned int            myAspectMod;            //!< modification counter of aspect
237
238 public:
239
240   DEFINE_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
241 };
242
243 DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)
244
245 #endif