X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FOpenGl%2FOpenGl_ClippingState.hxx;h=5b087c158228b4a74f48d20486ac8473b1f556ca;hb=b859a34d22aee97e9e67852ba18574939daab9f6;hpb=cbf1862449aa61edb80301953695bf22641a6914 diff --git a/src/OpenGl/OpenGl_ClippingState.hxx b/src/OpenGl/OpenGl_ClippingState.hxx index c52df31782..5b087c1582 100644 --- a/src/OpenGl/OpenGl_ClippingState.hxx +++ b/src/OpenGl/OpenGl_ClippingState.hxx @@ -27,6 +27,7 @@ #include #include #include +#include //! This class contains logics related to tracking and modification of clipping plane //! state for particular OpenGl context. It contains information about enabled @@ -37,67 +38,179 @@ class OpenGl_ClippingState { public: + //! Enumerates supported equation coordinate spaces. + enum EquationCoords + { + EquationCoords_View, + EquationCoords_World + }; + +public: //! @name general methods + //! Default constructor. - Standard_EXPORT OpenGl_ClippingState (); + Standard_EXPORT OpenGl_ClippingState(); //! Initialize. //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context. Standard_EXPORT void Init (const Standard_Integer theMaxPlanes); - //! @return sequence of set clipping planes. - Standard_EXPORT Graphic3d_SetOfHClipPlane Planes() const; +public: //! @name non-modifying getters - //! Check whether the clipping plane has been set for the current context state. + //! Check whether the clipping plane has been added to the current context state. //! @param thePlane [in] the plane to check. //! @return True if plane is set. - Standard_EXPORT Standard_Boolean IsSet (const Handle(Graphic3d_ClipPlane)& thePlane) const; - - //! Set collection of clipping planes for available plane ids. Current model view matrix is used. - //! @param thePlanes [in] collection of planes. - //! @param theToEnable [in] the boolean flag notifying whether the planes should be enabled. - Standard_EXPORT void Set (const Graphic3d_SetOfHClipPlane& thePlanes, - const Standard_Boolean theToEnable = Standard_True); - - //! Set collection of clipping planes for available plane ids. Identity matrix in case - //! if passed matrix pointer is NULL. - //! @param thePlanes [in] collection of planes. - //! @param theViewMatrix [in] view matrix to be used to define plane equation. - //! @param theToEnable [in] the boolean flag notifying whether the planes should be enabled. - Standard_EXPORT void Set (const Graphic3d_SetOfHClipPlane& thePlanes, - const OpenGl_Matrix* theViewMatrix, - const Standard_Boolean theToEnable = Standard_True); - - //! Unset and disable collection of clipping planes. - //! @param thePlanes [in] the plane to deactivate. - Standard_EXPORT void Unset (const Graphic3d_SetOfHClipPlane& thePlanes); + inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const + { + return myPlaneStates.IsBound (thePlane); + } + + //! Get clip planes defined for context. + //! @return sequence of set clipping planes. + inline const Graphic3d_SetOfHClipPlane& Planes() const + { + return myPlanes; + } + + //! @return kind of equation coordinate space used for the clip plane. + inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const + { + return myPlaneStates.Find (thePlane).CoordSpace; + } //! Check whether the clipping plane has been set and enabled for the current context state. //! @param thePlane [in] the plane to check. //! @return True if plane is enabled. - Standard_EXPORT Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const; + inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const + { + return myPlaneStates.Find (thePlane).IsEnabled; + } + +public: //! @name clipping state modification commands + + //! Add planes to the context clipping at the specified system of coordinates. + //! This methods loads appropriate transformation matrix from workspace to + //! to transform equation coordinates. The planes become enabled in the context. + //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes + //! are simply ignored. + //! @param thePlanes [in/out] the list of planes to be added. + //! The list then provides information on which planes were really added to clipping state. + //! This list then can be used to fall back to previous state. + //! @param theCoordSpace [in] the equation definition space. + //! @param theWS [in] the workspace to access the matrices. + Standard_EXPORT void Add (Graphic3d_SetOfHClipPlane& thePlanes, + const EquationCoords& theCoordSpace, + const Handle(OpenGl_Workspace)& theWS); + + //! Add planes to the context clipping at the specified system of coordinates. + //! This method assumes that appropriate matrix is already set in context state. + //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes + //! are simply ignored. + //! @param thePlanes [in/out] the list of planes to be added. + //! The list then provides information on which planes were really added to clipping state. + //! This list then can be used to fall back to previous state. + //! @param theCoordSpace [in] the equation definition space. + Standard_EXPORT void Add (Graphic3d_SetOfHClipPlane& thePlanes, + const EquationCoords& theCoordSpace); + + //! Remove the passed set of clipping planes from the context state. + //! @param thePlanes [in] the planes to remove from list. + Standard_EXPORT void Remove (const Graphic3d_SetOfHClipPlane& thePlanes); + + //! Enable or disable clipping plane in the OpenGl context. + //! @param thePlane [in] the plane to affect. + //! @param theIsEnabled [in] the state of the plane. + Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane, + const Standard_Boolean theIsEnabled); + +public: //! @name Short-cuts + + //! Add planes to the context clipping at the view system of coordinates. + //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes + //! are simply ignored. + //! @param thePlanes [in/out] the list of planes to be added. + //! The list then provides information on which planes were really added to clipping state. + //! This list then can be used to fall back to previous state. + //! @param theWS [in] the workspace to access the matrices. + inline void AddView (Graphic3d_SetOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS) + { + Add (thePlanes, EquationCoords_View, theWS); + } + + //! Add planes to the context clipping at the view system of coordinates. + //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes + //! are simply ignored. + //! @param thePlanes [in/out] the list of planes to be added. + //! The list then provides information on which planes were really added to clipping state. + //! This list then can be used to fall back to previous state. + inline void AddView (Graphic3d_SetOfHClipPlane& thePlanes) + { + Add (thePlanes, EquationCoords_View); + } + + //! Add planes to the context clipping at the world system of coordinates. + //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes + //! are simply ignored. + //! @param thePlanes [in/out] the list of planes to be added. + //! The list then provides information on which planes were really added to clipping state. + //! This list then can be used to fall back to previous state. + //! @param theWS [in] the workspace to access the matrices. + inline void AddWorld (Graphic3d_SetOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS) + { + Add (thePlanes, EquationCoords_World, theWS); + } + + //! Add planes to the context clipping at the world system of coordinates. + //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes + //! are simply ignored. + //! @param thePlanes [in/out] the list of planes to be added. + //! The list then provides information on which planes were really added to clipping state. + //! This list then can be used to fall back to previous state. + inline void AddWorld (Graphic3d_SetOfHClipPlane& thePlanes) + { + Add (thePlanes, EquationCoords_World); + } + + //! Remove all of the planes from context state. + inline void RemoveAll() + { + Remove (Planes()); + } + +private: - //! Change enabled / disabled state of the clipping plane. - //! @param thePlane [in] the plane to change the state. - //! @param theIsEnabled [in] the flag indicating whether the plane should be enabled or not. - //! @return False if plane is not set for the context. - Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane, const Standard_Boolean theIsEnabled); + struct PlaneProps + { + // declare default constructor + // to allow compilation of template collections + PlaneProps() {} + PlaneProps (const EquationCoords theCoords, + const Standard_Integer theID, + const Standard_Boolean theIsEnabled) + { + CoordSpace = theCoords; + ContextID = theID; + IsEnabled = theIsEnabled; + } + + EquationCoords CoordSpace; + Standard_Integer ContextID; + Standard_Boolean IsEnabled; + }; private: - typedef NCollection_DataMap OpenGl_MapOfContextPlanes; - typedef NCollection_DataMap OpenGl_MapOfPlaneStates; + typedef NCollection_DataMap OpenGl_MapOfPlaneStates; typedef NCollection_Handle OpenGl_EmptyPlaneIds; - OpenGl_MapOfContextPlanes myPlanes; //!< map of clip planes bound for the ids - OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes state (enabled/disabled). - OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids + Graphic3d_SetOfHClipPlane myPlanes; //!< defined clipping planes. + OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props. + OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids. private: //! Copying allowed only within Handles OpenGl_ClippingState (const OpenGl_ClippingState& ); OpenGl_ClippingState& operator= (const OpenGl_ClippingState& ); - }; #endif