0024778: Convertation of the generic classes to the non-generic. Part 9
[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>
b859a34d 26#include <Handle_OpenGl_Workspace.hxx>
4269bd1b 27
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
32//! class.
30f0ad28 33class OpenGl_Clipping
4269bd1b 34{
35public:
36
b859a34d 37 //! Enumerates supported equation coordinate spaces.
38 enum EquationCoords
39 {
40 EquationCoords_View,
41 EquationCoords_World
42 };
43
44public: //! @name general methods
45
4269bd1b 46 //! Default constructor.
30f0ad28 47 Standard_EXPORT OpenGl_Clipping();
4269bd1b 48
49 //! Initialize.
50 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
51 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
52
b859a34d 53public: //! @name non-modifying getters
4269bd1b 54
b859a34d 55 //! Check whether the clipping plane has been added to the current context state.
4269bd1b 56 //! @param thePlane [in] the plane to check.
57 //! @return True if plane is set.
b859a34d 58 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
59 {
60 return myPlaneStates.IsBound (thePlane);
61 }
62
63 //! Get clip planes defined for context.
64 //! @return sequence of set clipping planes.
51b10cd4 65 inline const Graphic3d_SequenceOfHClipPlane& Planes() const
b859a34d 66 {
67 return myPlanes;
68 }
69
70 //! @return kind of equation coordinate space used for the clip plane.
71 inline EquationCoords GetEquationSpace (const Handle(Graphic3d_ClipPlane)& thePlane) const
72 {
73 return myPlaneStates.Find (thePlane).CoordSpace;
74 }
4269bd1b 75
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.
b859a34d 79 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
80 {
81 return myPlaneStates.Find (thePlane).IsEnabled;
82 }
83
3b1817a9 84 //! @return true if there are enabled clipping planes (NOT capping)
85 inline Standard_Boolean IsClippingOn() const
86 {
87 return myNbClipping > 0;
88 }
89
90 //! @return true if there are enabled capping planes
91 inline Standard_Boolean IsCappingOn() const
92 {
93 return myNbCapping > 0;
94 }
95
96 //! @return true if there are enabled clipping or capping planes
97 inline Standard_Boolean IsClippingOrCappingOn() const
98 {
99 return (myNbClipping + myNbCapping) > 0;
100 }
101
b859a34d 102public: //! @name clipping state modification commands
103
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.
51b10cd4 114 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
b859a34d 115 const EquationCoords& theCoordSpace,
116 const Handle(OpenGl_Workspace)& theWS);
117
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.
51b10cd4 126 Standard_EXPORT void Add (Graphic3d_SequenceOfHClipPlane& thePlanes,
b859a34d 127 const EquationCoords& theCoordSpace);
128
129 //! Remove the passed set of clipping planes from the context state.
130 //! @param thePlanes [in] the planes to remove from list.
51b10cd4 131 Standard_EXPORT void Remove (const Graphic3d_SequenceOfHClipPlane& thePlanes);
b859a34d 132
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);
138
139public: //! @name Short-cuts
140
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.
51b10cd4 148 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
b859a34d 149 {
150 Add (thePlanes, EquationCoords_View, theWS);
151 }
152
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.
51b10cd4 159 inline void AddView (Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 160 {
161 Add (thePlanes, EquationCoords_View);
162 }
163
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.
51b10cd4 171 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes, const Handle(OpenGl_Workspace)& theWS)
b859a34d 172 {
173 Add (thePlanes, EquationCoords_World, theWS);
174 }
175
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.
51b10cd4 182 inline void AddWorld (Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 183 {
184 Add (thePlanes, EquationCoords_World);
185 }
186
187 //! Remove all of the planes from context state.
188 inline void RemoveAll()
189 {
190 Remove (Planes());
191 }
192
193private:
4269bd1b 194
b859a34d 195 struct PlaneProps
196 {
197 // declare default constructor
198 // to allow compilation of template collections
199 PlaneProps() {}
200 PlaneProps (const EquationCoords theCoords,
201 const Standard_Integer theID,
202 const Standard_Boolean theIsEnabled)
203 {
204 CoordSpace = theCoords;
205 ContextID = theID;
206 IsEnabled = theIsEnabled;
207 }
208
209 EquationCoords CoordSpace;
210 Standard_Integer ContextID;
211 Standard_Boolean IsEnabled;
212 };
4269bd1b 213
214private:
215
b859a34d 216 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
4269bd1b 217 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
218
3b1817a9 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
4269bd1b 224
225private:
226
227 //! Copying allowed only within Handles
30f0ad28 228 OpenGl_Clipping (const OpenGl_Clipping& );
229 OpenGl_Clipping& operator= (const OpenGl_Clipping& );
4269bd1b 230};
231
232#endif