1 // Created on: 2013-09-05
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_Clipping_H__
17 #define _OpenGl_Clipping_H__
19 #include <Aspect_GenId.hxx>
20 #include <Graphic3d_ClipPlane.hxx>
21 #include <Graphic3d_SequenceOfHClipPlane.hxx>
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_Handle.hxx>
24 #include <Standard_TypeDef.hxx>
25 #include <OpenGl_Matrix.hxx>
27 class OpenGl_Workspace;
29 //! This class contains logics related to tracking and modification of clipping plane
30 //! state for particular OpenGl context. It contains information about enabled
31 //! clipping planes and provides method to change clippings in context. The methods
32 //! should be executed within OpenGl context associated with instance of this
38 //! Enumerates supported equation coordinate spaces.
45 public: //! @name general methods
47 //! Default constructor.
48 Standard_EXPORT OpenGl_Clipping();
51 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
52 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
54 public: //! @name non-modifying getters
56 //! Check whether the clipping plane has been added to the current context state.
57 //! @param thePlane [in] the plane to check.
58 //! @return True if plane is set.
59 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
61 return myPlaneStates.IsBound (thePlane);
64 //! Get clip planes defined for context.
65 //! @return sequence of set clipping planes.
66 inline const Graphic3d_SequenceOfHClipPlane& Planes() const
71 //! @return kind of equation coordinate space used for the clip plane.
72 inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
74 return myPlaneStates.Find (thePlane).CoordSpace;
77 //! Check whether the clipping plane has been set and enabled for the current context state.
78 //! @param thePlane [in] the plane to check.
79 //! @return True if plane is enabled.
80 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
82 return myPlaneStates.Find (thePlane).IsEnabled;
85 //! @return true if there are enabled clipping planes (NOT capping)
86 inline Standard_Boolean IsClippingOn() const
88 return myNbClipping > 0;
91 //! @return true if there are enabled capping planes
92 inline Standard_Boolean IsCappingOn() const
94 return myNbCapping > 0;
97 //! @return true if there are enabled clipping or capping planes
98 inline Standard_Boolean IsClippingOrCappingOn() const
100 return (myNbClipping + myNbCapping) > 0;
103 public: //! @name clipping state modification commands
105 //! Add planes to the context clipping at the specified system of coordinates.
106 //! This methods loads appropriate transformation matrix from workspace to
107 //! to transform equation coordinates. The planes become enabled in the context.
108 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
109 //! are simply ignored.
110 //! @param thePlanes [in/out] the list of planes to be added.
111 //! The list then provides information on which planes were really added to clipping state.
112 //! This list then can be used to fall back to previous state.
113 //! @param theCoordSpace [in] the equation definition space.
114 //! @param theWS [in] the workspace to access the matrices.
115 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
116 const EquationCoords& theCoordSpace,
117 const Handle(OpenGl_Workspace)& theWS);
119 //! Add planes to the context clipping at the specified system of coordinates.
120 //! This method assumes that appropriate matrix is already set in context state.
121 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
122 //! are simply ignored.
123 //! @param thePlanes [in/out] the list of planes to be added.
124 //! The list then provides information on which planes were really added to clipping state.
125 //! This list then can be used to fall back to previous state.
126 //! @param theCoordSpace [in] the equation definition space.
127 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
128 const EquationCoords& theCoordSpace);
130 //! Remove the passed set of clipping planes from the context state.
131 //! @param thePlanes [in] the planes to remove from list.
132 Standard_EXPORT void Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes);
134 //! Enable or disable clipping plane in the OpenGl context.
135 //! @param thePlane [in] the plane to affect.
136 //! @param theIsEnabled [in] the state of the plane.
137 Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
138 const Standard_Boolean theIsEnabled);
140 public: //! @name Short-cuts
142 //! Add planes to the context clipping at the view system of coordinates.
143 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
144 //! are simply ignored.
145 //! @param thePlanes [in/out] the list of planes to be added.
146 //! The list then provides information on which planes were really added to clipping state.
147 //! This list then can be used to fall back to previous state.
148 //! @param theWS [in] the workspace to access the matrices.
149 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
151 Add (thePlanes, EquationCoords_View, theWS);
154 //! Add planes to the context clipping at the view system of coordinates.
155 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
156 //! are simply ignored.
157 //! @param thePlanes [in/out] the list of planes to be added.
158 //! The list then provides information on which planes were really added to clipping state.
159 //! This list then can be used to fall back to previous state.
160 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes)
162 Add (thePlanes, EquationCoords_View);
165 //! Add planes to the context clipping at the world system of coordinates.
166 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
167 //! are simply ignored.
168 //! @param thePlanes [in/out] the list of planes to be added.
169 //! The list then provides information on which planes were really added to clipping state.
170 //! This list then can be used to fall back to previous state.
171 //! @param theWS [in] the workspace to access the matrices.
172 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
174 Add (thePlanes, EquationCoords_World, theWS);
177 //! Add planes to the context clipping at the world system of coordinates.
178 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
179 //! are simply ignored.
180 //! @param thePlanes [in/out] the list of planes to be added.
181 //! The list then provides information on which planes were really added to clipping state.
182 //! This list then can be used to fall back to previous state.
183 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes)
185 Add (thePlanes, EquationCoords_World);
188 //! Remove all of the planes from context state.
189 inline void RemoveAll()
198 // declare default constructor
199 // to allow compilation of template collections
201 PlaneProps (const EquationCoords theCoords,
202 const Standard_Integer theID,
203 const Standard_Boolean theIsEnabled)
205 CoordSpace = theCoords;
207 IsEnabled = theIsEnabled;
210 EquationCoords CoordSpace;
211 Standard_Integer ContextID;
212 Standard_Boolean IsEnabled;
217 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
218 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
220 Graphic3d_SequenceOfHClipPlane myPlanes; //!< defined clipping planes
221 OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props
222 OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids
223 Standard_Boolean myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
224 Standard_Boolean myNbCapping; //!< number of enabled capping planes
228 //! Copying allowed only within Handles
229 OpenGl_Clipping (const OpenGl_Clipping& );
230 OpenGl_Clipping& operator= (const OpenGl_Clipping& );