0024023: Revamp the OCCT Handle -- automatic
[occt.git] / src / OpenGl / OpenGl_Clipping.hxx
CommitLineData
4269bd1b 1// Created on: 2013-09-05
2// Created by: Anton POLETAEV
d5f74e42 3// Copyright (c) 2013-2014 OPEN CASCADE SAS
4269bd1b 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
4269bd1b 6//
d5f74e42 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
973c2be1 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.
4269bd1b 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
4269bd1b 15
30f0ad28 16#ifndef _OpenGl_Clipping_H__
17#define _OpenGl_Clipping_H__
4269bd1b 18
19#include <Aspect_GenId.hxx>
20#include <Graphic3d_ClipPlane.hxx>
51b10cd4 21#include <Graphic3d_SequenceOfHClipPlane.hxx>
4269bd1b 22#include <NCollection_DataMap.hxx>
23#include <NCollection_Handle.hxx>
24#include <Standard_TypeDef.hxx>
25#include <OpenGl_Matrix.hxx>
26
27//! This class contains logics related to tracking and modification of clipping plane
28//! state for particular OpenGl context. It contains information about enabled
29//! clipping planes and provides method to change clippings in context. The methods
30//! should be executed within OpenGl context associated with instance of this
31//! class.
30f0ad28 32class OpenGl_Clipping
4269bd1b 33{
34public:
35
b859a34d 36 //! Enumerates supported equation coordinate spaces.
37 enum EquationCoords
38 {
39 EquationCoords_View,
40 EquationCoords_World
41 };
42
43public: //! @name general methods
44
4269bd1b 45 //! Default constructor.
30f0ad28 46 Standard_EXPORT OpenGl_Clipping();
4269bd1b 47
48 //! Initialize.
49 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
50 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
51
b859a34d 52public: //! @name non-modifying getters
4269bd1b 53
b859a34d 54 //! Check whether the clipping plane has been added to the current context state.
4269bd1b 55 //! @param thePlane [in] the plane to check.
56 //! @return True if plane is set.
b859a34d 57 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
58 {
59 return myPlaneStates.IsBound (thePlane);
60 }
61
62 //! Get clip planes defined for context.
63 //! @return sequence of set clipping planes.
51b10cd4 64 inline const Graphic3d_SequenceOfHClipPlane& Planes() const
b859a34d 65 {
66 return myPlanes;
67 }
68
69 //! @return kind of equation coordinate space used for the clip plane.
70 inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
71 {
72 return myPlaneStates.Find (thePlane).CoordSpace;
73 }
4269bd1b 74
75 //! Check whether the clipping plane has been set and enabled for the current context state.
76 //! @param thePlane [in] the plane to check.
77 //! @return True if plane is enabled.
b859a34d 78 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
79 {
80 return myPlaneStates.Find (thePlane).IsEnabled;
81 }
82
3b1817a9 83 //! @return true if there are enabled clipping planes (NOT capping)
84 inline Standard_Boolean IsClippingOn() const
85 {
86 return myNbClipping > 0;
87 }
88
89 //! @return true if there are enabled capping planes
90 inline Standard_Boolean IsCappingOn() const
91 {
92 return myNbCapping > 0;
93 }
94
95 //! @return true if there are enabled clipping or capping planes
96 inline Standard_Boolean IsClippingOrCappingOn() const
97 {
98 return (myNbClipping + myNbCapping) > 0;
99 }
100
b859a34d 101public: //! @name clipping state modification commands
102
103 //! Add planes to the context clipping at the specified system of coordinates.
104 //! This methods loads appropriate transformation matrix from workspace to
105 //! to transform equation coordinates. The planes become enabled in the context.
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 //! @param theWS [in] the workspace to access the matrices.
51b10cd4 113 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
b859a34d 114 const EquationCoords& theCoordSpace,
115 const Handle(OpenGl_Workspace)& theWS);
116
117 //! Add planes to the context clipping at the specified system of coordinates.
118 //! This method assumes that appropriate matrix is already set in context state.
119 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
120 //! are simply ignored.
121 //! @param thePlanes [in/out] the list of planes to be added.
122 //! The list then provides information on which planes were really added to clipping state.
123 //! This list then can be used to fall back to previous state.
124 //! @param theCoordSpace [in] the equation definition space.
51b10cd4 125 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
b859a34d 126 const EquationCoords& theCoordSpace);
127
128 //! Remove the passed set of clipping planes from the context state.
129 //! @param thePlanes [in] the planes to remove from list.
51b10cd4 130 Standard_EXPORT void Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes);
b859a34d 131
132 //! Enable or disable clipping plane in the OpenGl context.
133 //! @param thePlane [in] the plane to affect.
134 //! @param theIsEnabled [in] the state of the plane.
135 Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane,
136 const Standard_Boolean theIsEnabled);
137
138public: //! @name Short-cuts
139
140 //! Add planes to the context clipping at the view system of coordinates.
141 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
142 //! are simply ignored.
143 //! @param thePlanes [in/out] the list of planes to be added.
144 //! The list then provides information on which planes were really added to clipping state.
145 //! This list then can be used to fall back to previous state.
146 //! @param theWS [in] the workspace to access the matrices.
51b10cd4 147 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
b859a34d 148 {
149 Add (thePlanes, EquationCoords_View, theWS);
150 }
151
152 //! Add planes to the context clipping at the view system of coordinates.
153 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
154 //! are simply ignored.
155 //! @param thePlanes [in/out] the list of planes to be added.
156 //! The list then provides information on which planes were really added to clipping state.
157 //! This list then can be used to fall back to previous state.
51b10cd4 158 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 159 {
160 Add (thePlanes, EquationCoords_View);
161 }
162
163 //! Add planes to the context clipping at the world system of coordinates.
164 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
165 //! are simply ignored.
166 //! @param thePlanes [in/out] the list of planes to be added.
167 //! The list then provides information on which planes were really added to clipping state.
168 //! This list then can be used to fall back to previous state.
169 //! @param theWS [in] the workspace to access the matrices.
51b10cd4 170 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
b859a34d 171 {
172 Add (thePlanes, EquationCoords_World, theWS);
173 }
174
175 //! Add planes to the context clipping at the world system of coordinates.
176 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
177 //! are simply ignored.
178 //! @param thePlanes [in/out] the list of planes to be added.
179 //! The list then provides information on which planes were really added to clipping state.
180 //! This list then can be used to fall back to previous state.
51b10cd4 181 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 182 {
183 Add (thePlanes, EquationCoords_World);
184 }
185
186 //! Remove all of the planes from context state.
187 inline void RemoveAll()
188 {
189 Remove (Planes());
190 }
191
192private:
4269bd1b 193
b859a34d 194 struct PlaneProps
195 {
196 // declare default constructor
197 // to allow compilation of template collections
198 PlaneProps() {}
199 PlaneProps (const EquationCoords theCoords,
200 const Standard_Integer theID,
201 const Standard_Boolean theIsEnabled)
202 {
203 CoordSpace = theCoords;
204 ContextID = theID;
205 IsEnabled = theIsEnabled;
206 }
207
208 EquationCoords CoordSpace;
209 Standard_Integer ContextID;
210 Standard_Boolean IsEnabled;
211 };
4269bd1b 212
213private:
214
b859a34d 215 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
4269bd1b 216 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
217
3b1817a9 218 Graphic3d_SequenceOfHClipPlane myPlanes; //!< defined clipping planes
219 OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props
220 OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids
221 Standard_Boolean myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
222 Standard_Boolean myNbCapping; //!< number of enabled capping planes
4269bd1b 223
224private:
225
226 //! Copying allowed only within Handles
30f0ad28 227 OpenGl_Clipping (const OpenGl_Clipping& );
228 OpenGl_Clipping& operator= (const OpenGl_Clipping& );
4269bd1b 229};
230
231#endif