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>
26 #include <Handle_OpenGl_Workspace.hxx>
28 //! This class contains logics related to tracking and modification of clipping plane
29 //! state for particular OpenGl context. It contains information about enabled
30 //! clipping planes and provides method to change clippings in context. The methods
31 //! should be executed within OpenGl context associated with instance of this
37 //! Enumerates supported equation coordinate spaces.
44 public: //! @name general methods
46 //! Default constructor.
47 Standard_EXPORT OpenGl_Clipping();
50 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
51 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
53 public: //! @name non-modifying getters
55 //! Check whether the clipping plane has been added to the current context state.
56 //! @param thePlane [in] the plane to check.
57 //! @return True if plane is set.
58 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
60 return myPlaneStates.IsBound (thePlane);
63 //! Get clip planes defined for context.
64 //! @return sequence of set clipping planes.
65 inline const Graphic3d_SequenceOfHClipPlane& Planes() const
70 //! @return kind of equation coordinate space used for the clip plane.
71 inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
73 return myPlaneStates.Find (thePlane).CoordSpace;
76 //! Check whether the clipping plane has been set and enabled for the current context state.
77 //! @param thePlane [in] the plane to check.
78 //! @return True if plane is enabled.
79 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
81 return myPlaneStates.Find (thePlane).IsEnabled;
84 //! @return true if there are enabled clipping planes (NOT capping)
85 inline Standard_Boolean IsClippingOn() const
87 return myNbClipping > 0;
90 //! @return true if there are enabled capping planes
91 inline Standard_Boolean IsCappingOn() const
93 return myNbCapping > 0;
96 //! @return true if there are enabled clipping or capping planes
97 inline Standard_Boolean IsClippingOrCappingOn() const
99 return (myNbClipping + myNbCapping) > 0;
102 public: //! @name clipping state modification commands
104 //! Add planes to the context clipping at the specified system of coordinates.
105 //! This methods loads appropriate transformation matrix from workspace to
106 //! to transform equation coordinates. The planes become enabled in the context.
107 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
108 //! are simply ignored.
109 //! @param thePlanes [in/out] the list of planes to be added.
110 //! The list then provides information on which planes were really added to clipping state.
111 //! This list then can be used to fall back to previous state.
112 //! @param theCoordSpace [in] the equation definition space.
113 //! @param theWS [in] the workspace to access the matrices.
114 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
115 const EquationCoords& theCoordSpace,
116 const Handle(OpenGl_Workspace)& theWS);
118 //! Add planes to the context clipping at the specified system of coordinates.
119 //! This method assumes that appropriate matrix is already set in context state.
120 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
121 //! are simply ignored.
122 //! @param thePlanes [in/out] the list of planes to be added.
123 //! The list then provides information on which planes were really added to clipping state.
124 //! This list then can be used to fall back to previous state.
125 //! @param theCoordSpace [in] the equation definition space.
126 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
127 const EquationCoords& theCoordSpace);
129 //! Remove the passed set of clipping planes from the context state.
130 //! @param thePlanes [in] the planes to remove from list.
131 Standard_EXPORT void Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes);
133 //! Enable or disable clipping plane in the OpenGl context.
134 //! @param thePlane [in] the plane to affect.
135 //! @param theIsEnabled [in] the state of the plane.
136 Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
137 const Standard_Boolean theIsEnabled);
139 public: //! @name Short-cuts
141 //! Add planes to the context clipping at the view system of coordinates.
142 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
143 //! are simply ignored.
144 //! @param thePlanes [in/out] the list of planes to be added.
145 //! The list then provides information on which planes were really added to clipping state.
146 //! This list then can be used to fall back to previous state.
147 //! @param theWS [in] the workspace to access the matrices.
148 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
150 Add (thePlanes, EquationCoords_View, theWS);
153 //! Add planes to the context clipping at the view system of coordinates.
154 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
155 //! are simply ignored.
156 //! @param thePlanes [in/out] the list of planes to be added.
157 //! The list then provides information on which planes were really added to clipping state.
158 //! This list then can be used to fall back to previous state.
159 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes)
161 Add (thePlanes, EquationCoords_View);
164 //! Add planes to the context clipping at the world system of coordinates.
165 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
166 //! are simply ignored.
167 //! @param thePlanes [in/out] the list of planes to be added.
168 //! The list then provides information on which planes were really added to clipping state.
169 //! This list then can be used to fall back to previous state.
170 //! @param theWS [in] the workspace to access the matrices.
171 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
173 Add (thePlanes, EquationCoords_World, theWS);
176 //! Add planes to the context clipping at the world system of coordinates.
177 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
178 //! are simply ignored.
179 //! @param thePlanes [in/out] the list of planes to be added.
180 //! The list then provides information on which planes were really added to clipping state.
181 //! This list then can be used to fall back to previous state.
182 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes)
184 Add (thePlanes, EquationCoords_World);
187 //! Remove all of the planes from context state.
188 inline void RemoveAll()
197 // declare default constructor
198 // to allow compilation of template collections
200 PlaneProps (const EquationCoords theCoords,
201 const Standard_Integer theID,
202 const Standard_Boolean theIsEnabled)
204 CoordSpace = theCoords;
206 IsEnabled = theIsEnabled;
209 EquationCoords CoordSpace;
210 Standard_Integer ContextID;
211 Standard_Boolean IsEnabled;
216 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
217 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
219 Graphic3d_SequenceOfHClipPlane myPlanes; //!< defined clipping planes
220 OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props
221 OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids
222 Standard_Boolean myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
223 Standard_Boolean myNbCapping; //!< number of enabled capping planes
227 //! Copying allowed only within Handles
228 OpenGl_Clipping (const OpenGl_Clipping& );
229 OpenGl_Clipping& operator= (const OpenGl_Clipping& );