0027860: Visualization - clean up Transformation Persistence API
[occt.git] / src / Graphic3d / Graphic3d_ClipPlane.hxx
old mode 100644 (file)
new mode 100755 (executable)
index 16e48d0..d4141a0
@@ -1,21 +1,17 @@
 // Created on: 2013-07-12
 // Created by: Anton POLETAEV
-// Copyright (c) 2013 OPEN CASCADE SAS
+// Copyright (c) 2013-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 65 (the "License") You may not use the content of this file
-// except in compliance with the License Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE SAS, having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #ifndef _Graphic3d_ClipPlane_HeaderFile
 #define _Graphic3d_ClipPlane_HeaderFile
 #include <Standard_TypeDef.hxx>
 #include <Standard_Transient.hxx>
 #include <NCollection_Vec4.hxx>
-#include <Graphic3d_MaterialAspect.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_CappingFlags.hxx>
 #include <Graphic3d_TextureMap.hxx>
 #include <Aspect_HatchStyle.hxx>
 
-DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)
-
 class gp_Pln;
-class Graphic3d_AspectFillArea3d;
-class Handle(Graphic3d_AspectFillArea3d);
 
 //! Container for properties describing graphic driver clipping planes.
 //! It is up to application to create instances of this class and specify its
@@ -41,9 +34,10 @@ class Handle(Graphic3d_AspectFillArea3d);
 //! Depending on usage context the class can be used to specify:
 //! - Global clipping applied over the whole scene.
 //! - Object-level clipping applied for each particular object.
+//! The plane equation is specified in "world" coordinate system.
 //! Please note that the set of planes can define convex clipping volume.
 //! Be aware that number of clip planes supported by OpenGl is implementation
-//! dependant: at least 6 planes are available. Thus, take into account
+//! dependent: at least 6 planes are available. Thus, take into account
 //! number of clipping planes passed for rendering: the object planes plus
 //! the view defined ones.
 class Graphic3d_ClipPlane : public Standard_Transient
@@ -72,16 +66,18 @@ public:
   //! @param theEquation [in] the plane equation.
   Standard_EXPORT Graphic3d_ClipPlane (const Equation& theEquation);
 
-  //! Construct clip plane from the passed geomertical definition.
+  //! Construct clip plane from the passed geometrical definition.
   //! By default the plane is on, capping is turned off.
   //! @param thePlane [in] the plane.
   Standard_EXPORT Graphic3d_ClipPlane (const gp_Pln& thePlane);
 
   //! Set plane equation by its geometrical definition.
+  //! The equation is specified in "world" coordinate system.
   //! @param thePlane [in] the plane.
   Standard_EXPORT void SetEquation (const gp_Pln& thePlane);
 
   //! Set 4-component equation vector for clipping plane.
+  //! The equation is specified in "world" coordinate system.
   //! @param theEquation [in] the XYZW (or "ABCD") equation vector.
   Standard_EXPORT void SetEquation (const Equation& theEquation);
 
@@ -108,7 +104,7 @@ public:
   //! @param theIsOn [in] the flag specifying whether the graphic driver should
   //! perform rendering of capping surface produced by this plane. The graphic
   //! driver produces this surface for convex graphics by means of stencil-test
-  //! and multipass rendering.
+  //! and multi-pass rendering.
   Standard_EXPORT void SetCapping(const Standard_Boolean theIsOn);
 
   //! Check state of capping surface rendering.
@@ -118,7 +114,7 @@ public:
     return myIsCapping;
   }
 
-  //! Get geomertical definition. The plane is built up
+  //! Get geometrical definition. The plane is built up
   //! from the equation clipping plane equation vector.
   //! @return geometrical definition of clipping plane.
   Standard_EXPORT gp_Pln ToPlane() const;
@@ -136,30 +132,21 @@ public: // @name user-defined graphical attributes
   Standard_EXPORT void SetCappingMaterial (const Graphic3d_MaterialAspect& theMat);
 
   //! @return capping material.
-  const Graphic3d_MaterialAspect& CappingMaterial() const
-  {
-    return myMaterial;
-  }
+  const Graphic3d_MaterialAspect& CappingMaterial() const { return myAspect->FrontMaterial(); }
 
   //! Set texture to be applied on capping surface.
   //! @param theTexture [in] the texture.
   Standard_EXPORT void SetCappingTexture (const Handle(Graphic3d_TextureMap)& theTexture);
 
   //! @return capping texture map.
-  const Handle(Graphic3d_TextureMap)& CappingTexture() const
-  {
-    return myTexture;
-  }
+  const Handle(Graphic3d_TextureMap)& CappingTexture() const { return myAspect->TextureMap(); }
 
   //! Set hatch style (stipple) and turn hatching on.
   //! @param theStyle [in] the hatch style.
   Standard_EXPORT void SetCappingHatch (const Aspect_HatchStyle theStyle);
 
   //! @return hatching style.
-  Aspect_HatchStyle CappingHatch() const
-  {
-    return myHatch;
-  }
+  Aspect_HatchStyle CappingHatch() const { return myAspect->HatchStyle(); }
 
   //! Turn on hatching.
   Standard_EXPORT void SetCappingHatchOn();
@@ -168,10 +155,7 @@ public: // @name user-defined graphical attributes
   Standard_EXPORT void SetCappingHatchOff();
 
   //! @return True if hatching mask is turned on.
-  Standard_Boolean IsHatchOn() const
-  {
-    return myHatchOn;
-  }
+  Standard_Boolean IsHatchOn() const { return myAspect->InteriorStyle() == Aspect_IS_HATCH; }
 
   //! This ID is used for managing associated resources in graphical driver.
   //! The clip plane can be assigned within a range of IO which can be
@@ -185,11 +169,40 @@ public: // @name user-defined graphical attributes
     return myId;
   }
 
-  //! Compute and return capping apsect from the graphical attributes.
+public:
+
+  //! Return capping aspect.
   //! @return capping surface rendering aspect.
-  Standard_EXPORT Handle(Graphic3d_AspectFillArea3d) CappingAspect() const;
+  const Handle(Graphic3d_AspectFillArea3d)& CappingAspect() const { return myAspect; }
 
-public: // @name modificaton counters
+  //! Assign capping aspect.
+  Standard_EXPORT void SetCappingAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspect);
+
+  //! Flag indicating whether material for capping plane should be taken from object.
+  //! Default value: FALSE (use dedicated capping plane material).
+  bool ToUseObjectMaterial() const { return (myFlags & Graphic3d_CappingFlags_ObjectMaterial) != 0; }
+
+  //! Set flag for controlling the source of capping plane material.
+  void SetUseObjectMaterial (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectMaterial); }
+
+  //! Flag indicating whether texture for capping plane should be taken from object.
+  //! Default value: FALSE.
+  bool ToUseObjectTexture() const { return (myFlags & Graphic3d_CappingFlags_ObjectTexture) != 0; }
+
+  //! Set flag for controlling the source of capping plane texture.
+  void SetUseObjectTexture (bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectTexture); }
+
+  //! Flag indicating whether shader program for capping plane should be taken from object.
+  //! Default value: FALSE.
+  bool ToUseObjectShader() const { return (myFlags & Graphic3d_CappingFlags_ObjectShader) != 0; }
+
+  //! Set flag for controlling the source of capping plane shader program.
+  void SetUseObjectShader(bool theToUse) { setCappingFlag (theToUse, Graphic3d_CappingFlags_ObjectShader); }
+
+  //! Return true if some fill area aspect properties should be taken from object.
+  bool ToUseObjectProperties() const { return myFlags != Graphic3d_CappingFlags_None; }
+
+public: // @name modification counters
 
   //! @return modification counter for equation.
   unsigned int MCountEquation() const
@@ -205,24 +218,28 @@ public: // @name modificaton counters
 
 private:
 
-  void MakeId();
+  //! Generate unique object id for OpenGL graphic resource manager.
+  void makeId();
+
+  //! Set capping flag.
+  Standard_EXPORT void setCappingFlag (bool theToUse, int theFlag);
 
 private:
 
-  Equation                     myEquation;    //!< Plane equation vector.
-  Standard_Boolean             myIsOn;        //!< State of the clipping plane.
-  Standard_Boolean             myIsCapping;   //!< State of graphic driver capping.
-  Graphic3d_MaterialAspect     myMaterial;    //!< Capping surface material.
-  Handle(Graphic3d_TextureMap) myTexture;     //!< Capping surface texture.
-  Aspect_HatchStyle            myHatch;       //!< Capping surface hatch mask.
-  Standard_Boolean             myHatchOn;     //!< Capping surface hatching flag.
-  TCollection_AsciiString      myId;          //!< Resource id.
-  unsigned int                 myEquationMod; //!< Modification counter for equation.
-  unsigned int                 myAspectMod;   //!< Modification counter of aspect.
+  Handle(Graphic3d_AspectFillArea3d) myAspect;    //!< fill area aspect
+  TCollection_AsciiString myId;                   //!< resource id
+  Equation                myEquation;             //!< plane equation vector
+  unsigned int            myFlags;                //!< capping flags
+  Standard_Boolean        myIsOn;                 //!< state of the clipping plane
+  Standard_Boolean        myIsCapping;            //!< state of graphic driver capping
+  unsigned int            myEquationMod;          //!< modification counter for equation
+  unsigned int            myAspectMod;            //!< modification counter of aspect
 
 public:
 
-  DEFINE_STANDARD_RTTI(Graphic3d_ClipPlane);
+  DEFINE_STANDARD_RTTIEXT(Graphic3d_ClipPlane,Standard_Transient)
 };
 
+DEFINE_STANDARD_HANDLE (Graphic3d_ClipPlane, Standard_Transient)
+
 #endif