1 // Created on: 2013-09-05
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2013 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #ifndef _OpenGl_Clipping_H__
21 #define _OpenGl_Clipping_H__
23 #include <Aspect_GenId.hxx>
24 #include <Graphic3d_ClipPlane.hxx>
25 #include <Graphic3d_SetOfHClipPlane.hxx>
26 #include <NCollection_DataMap.hxx>
27 #include <NCollection_Handle.hxx>
28 #include <Standard_TypeDef.hxx>
29 #include <OpenGl_Matrix.hxx>
30 #include <Handle_OpenGl_Workspace.hxx>
32 //! This class contains logics related to tracking and modification of clipping plane
33 //! state for particular OpenGl context. It contains information about enabled
34 //! clipping planes and provides method to change clippings in context. The methods
35 //! should be executed within OpenGl context associated with instance of this
41 //! Enumerates supported equation coordinate spaces.
48 public: //! @name general methods
50 //! Default constructor.
51 Standard_EXPORT OpenGl_Clipping();
54 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
55 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
57 public: //! @name non-modifying getters
59 //! Check whether the clipping plane has been added to the current context state.
60 //! @param thePlane [in] the plane to check.
61 //! @return True if plane is set.
62 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
64 return myPlaneStates.IsBound (thePlane);
67 //! Get clip planes defined for context.
68 //! @return sequence of set clipping planes.
69 inline const Graphic3d_SetOfHClipPlane& Planes() const
74 //! @return kind of equation coordinate space used for the clip plane.
75 inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
77 return myPlaneStates.Find (thePlane).CoordSpace;
80 //! Check whether the clipping plane has been set and enabled for the current context state.
81 //! @param thePlane [in] the plane to check.
82 //! @return True if plane is enabled.
83 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
85 return myPlaneStates.Find (thePlane).IsEnabled;
88 public: //! @name clipping state modification commands
90 //! Add planes to the context clipping at the specified system of coordinates.
91 //! This methods loads appropriate transformation matrix from workspace to
92 //! to transform equation coordinates. The planes become enabled in the context.
93 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
94 //! are simply ignored.
95 //! @param thePlanes [in/out] the list of planes to be added.
96 //! The list then provides information on which planes were really added to clipping state.
97 //! This list then can be used to fall back to previous state.
98 //! @param theCoordSpace [in] the equation definition space.
99 //! @param theWS [in] the workspace to access the matrices.
100 Standard_EXPORT void Add (Graphic3d_SetOfHClipPlane& thePlanes,
101 const EquationCoords& theCoordSpace,
102 const Handle(OpenGl_Workspace)& theWS);
104 //! Add planes to the context clipping at the specified system of coordinates.
105 //! This method assumes that appropriate matrix is already set in context state.
106 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
107 //! are simply ignored.
108 //! @param thePlanes [in/out] the list of planes to be added.
109 //! The list then provides information on which planes were really added to clipping state.
110 //! This list then can be used to fall back to previous state.
111 //! @param theCoordSpace [in] the equation definition space.
112 Standard_EXPORT void Add (Graphic3d_SetOfHClipPlane& thePlanes,
113 const EquationCoords& theCoordSpace);
115 //! Remove the passed set of clipping planes from the context state.
116 //! @param thePlanes [in] the planes to remove from list.
117 Standard_EXPORT void Remove (const Graphic3d_SetOfHClipPlane& thePlanes);
119 //! Enable or disable clipping plane in the OpenGl context.
120 //! @param thePlane [in] the plane to affect.
121 //! @param theIsEnabled [in] the state of the plane.
122 Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
123 const Standard_Boolean theIsEnabled);
125 public: //! @name Short-cuts
127 //! Add planes to the context clipping at the view system of coordinates.
128 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
129 //! are simply ignored.
130 //! @param thePlanes [in/out] the list of planes to be added.
131 //! The list then provides information on which planes were really added to clipping state.
132 //! This list then can be used to fall back to previous state.
133 //! @param theWS [in] the workspace to access the matrices.
134 inline void AddView (Graphic3d_SetOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
136 Add (thePlanes, EquationCoords_View, theWS);
139 //! Add planes to the context clipping at the view system of coordinates.
140 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
141 //! are simply ignored.
142 //! @param thePlanes [in/out] the list of planes to be added.
143 //! The list then provides information on which planes were really added to clipping state.
144 //! This list then can be used to fall back to previous state.
145 inline void AddView (Graphic3d_SetOfHClipPlane& thePlanes)
147 Add (thePlanes, EquationCoords_View);
150 //! Add planes to the context clipping at the world system of coordinates.
151 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
152 //! are simply ignored.
153 //! @param thePlanes [in/out] the list of planes to be added.
154 //! The list then provides information on which planes were really added to clipping state.
155 //! This list then can be used to fall back to previous state.
156 //! @param theWS [in] the workspace to access the matrices.
157 inline void AddWorld (Graphic3d_SetOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
159 Add (thePlanes, EquationCoords_World, theWS);
162 //! Add planes to the context clipping at the world system of coordinates.
163 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
164 //! are simply ignored.
165 //! @param thePlanes [in/out] the list of planes to be added.
166 //! The list then provides information on which planes were really added to clipping state.
167 //! This list then can be used to fall back to previous state.
168 inline void AddWorld (Graphic3d_SetOfHClipPlane& thePlanes)
170 Add (thePlanes, EquationCoords_World);
173 //! Remove all of the planes from context state.
174 inline void RemoveAll()
183 // declare default constructor
184 // to allow compilation of template collections
186 PlaneProps (const EquationCoords theCoords,
187 const Standard_Integer theID,
188 const Standard_Boolean theIsEnabled)
190 CoordSpace = theCoords;
192 IsEnabled = theIsEnabled;
195 EquationCoords CoordSpace;
196 Standard_Integer ContextID;
197 Standard_Boolean IsEnabled;
202 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
203 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
205 Graphic3d_SetOfHClipPlane myPlanes; //!< defined clipping planes.
206 OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props.
207 OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids.
211 //! Copying allowed only within Handles
212 OpenGl_Clipping (const OpenGl_Clipping& );
213 OpenGl_Clipping& operator= (const OpenGl_Clipping& );