0027750: Visualization, V3d_View - remove unused functionality ZClipping and ZCueing
[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
79f4f036 27class OpenGl_Context;
c04c30b3 28class OpenGl_Workspace;
29
4269bd1b 30//! This class contains logics related to tracking and modification of clipping plane
31//! state for particular OpenGl context. It contains information about enabled
32//! clipping planes and provides method to change clippings in context. The methods
33//! should be executed within OpenGl context associated with instance of this
34//! class.
30f0ad28 35class OpenGl_Clipping
4269bd1b 36{
b859a34d 37public: //! @name general methods
38
4269bd1b 39 //! Default constructor.
30f0ad28 40 Standard_EXPORT OpenGl_Clipping();
4269bd1b 41
42 //! Initialize.
43 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
44 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
45
b859a34d 46public: //! @name non-modifying getters
4269bd1b 47
b859a34d 48 //! Check whether the clipping plane has been added to the current context state.
4269bd1b 49 //! @param thePlane [in] the plane to check.
50 //! @return True if plane is set.
b859a34d 51 inline Standard_Boolean Contains (const Handle(Graphic3d_ClipPlane)& thePlane) const
52 {
53 return myPlaneStates.IsBound (thePlane);
54 }
55
56 //! Get clip planes defined for context.
57 //! @return sequence of set clipping planes.
51b10cd4 58 inline const Graphic3d_SequenceOfHClipPlane& Planes() const
b859a34d 59 {
60 return myPlanes;
61 }
62
4269bd1b 63 //! Check whether the clipping plane has been set and enabled for the current context state.
64 //! @param thePlane [in] the plane to check.
65 //! @return True if plane is enabled.
b859a34d 66 inline Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const
67 {
68 return myPlaneStates.Find (thePlane).IsEnabled;
69 }
70
3b1817a9 71 //! @return true if there are enabled clipping planes (NOT capping)
72 inline Standard_Boolean IsClippingOn() const
73 {
74 return myNbClipping > 0;
75 }
76
77 //! @return true if there are enabled capping planes
78 inline Standard_Boolean IsCappingOn() const
79 {
80 return myNbCapping > 0;
81 }
82
83 //! @return true if there are enabled clipping or capping planes
84 inline Standard_Boolean IsClippingOrCappingOn() const
85 {
86 return (myNbClipping + myNbCapping) > 0;
87 }
88
b859a34d 89public: //! @name clipping state modification commands
90
91 //! Add planes to the context clipping at the specified system of coordinates.
92 //! This methods loads appropriate transformation matrix from workspace to
93 //! to transform equation coordinates. The planes become enabled in the context.
94 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
95 //! are simply ignored.
79f4f036 96 //!
97 //! Within FFP, method also temporarily resets ModelView matrix before calling glClipPlane().
98 //! Otherwise the method just redirects to addLazy().
99 //!
100 //! @param theGlCtx [in] context to access the matrices
79f4f036 101 //! @param thePlanes [in/out] the list of planes to be added
b859a34d 102 //! The list then provides information on which planes were really added to clipping state.
103 //! This list then can be used to fall back to previous state.
79f4f036 104 Standard_EXPORT void add (const Handle(OpenGl_Context)& theGlCtx,
79f4f036 105 Graphic3d_SequenceOfHClipPlane& thePlanes);
b859a34d 106
107 //! Add planes to the context clipping at the specified system of coordinates.
108 //! This method assumes that appropriate matrix is already set in context state.
109 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
110 //! are simply ignored.
111 //! @param thePlanes [in/out] the list of planes to be added.
112 //! The list then provides information on which planes were really added to clipping state.
113 //! This list then can be used to fall back to previous state.
79f4f036 114 Standard_EXPORT void addLazy (const Handle(OpenGl_Context)& theGlCtx,
79f4f036 115 Graphic3d_SequenceOfHClipPlane& thePlanes);
b859a34d 116
117 //! Remove the passed set of clipping planes from the context state.
118 //! @param thePlanes [in] the planes to remove from list.
79f4f036 119 Standard_EXPORT void Remove (const Handle(OpenGl_Context)& theGlCtx,
120 const Graphic3d_SequenceOfHClipPlane& thePlanes);
b859a34d 121
122 //! Enable or disable clipping plane in the OpenGl context.
123 //! @param thePlane [in] the plane to affect.
124 //! @param theIsEnabled [in] the state of the plane.
79f4f036 125 Standard_EXPORT void SetEnabled (const Handle(OpenGl_Context)& theGlCtx,
126 const Handle(Graphic3d_ClipPlane)& thePlane,
127 const Standard_Boolean theIsEnabled);
b859a34d 128
129public: //! @name Short-cuts
130
b859a34d 131 //! Add planes to the context clipping at the world system of coordinates.
132 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
133 //! are simply ignored.
79f4f036 134 //! @param theGlCtx [in] context to access the matrices
135 //! @param thePlanes [in/out] the list of planes to be added
b859a34d 136 //! The list then provides information on which planes were really added to clipping state.
137 //! This list then can be used to fall back to previous state.
79f4f036 138 inline void AddWorld (const Handle(OpenGl_Context)& theGlCtx,
139 Graphic3d_SequenceOfHClipPlane& thePlanes)
b859a34d 140 {
89a929ea 141 add (theGlCtx, thePlanes);
b859a34d 142 }
143
b859a34d 144 //! Remove all of the planes from context state.
79f4f036 145 inline void RemoveAll (const Handle(OpenGl_Context)& theGlCtx)
b859a34d 146 {
79f4f036 147 Remove (theGlCtx, Planes());
b859a34d 148 }
149
150private:
4269bd1b 151
b859a34d 152 struct PlaneProps
153 {
154 // declare default constructor
155 // to allow compilation of template collections
156 PlaneProps() {}
89a929ea 157 PlaneProps (const Standard_Integer theID,
b859a34d 158 const Standard_Boolean theIsEnabled)
159 {
b859a34d 160 ContextID = theID;
161 IsEnabled = theIsEnabled;
162 }
163
b859a34d 164 Standard_Integer ContextID;
165 Standard_Boolean IsEnabled;
166 };
4269bd1b 167
168private:
169
b859a34d 170 typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), PlaneProps> OpenGl_MapOfPlaneStates;
4269bd1b 171 typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds;
172
3b1817a9 173 Graphic3d_SequenceOfHClipPlane myPlanes; //!< defined clipping planes
174 OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes bound for the props
175 OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids
176 Standard_Boolean myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
177 Standard_Boolean myNbCapping; //!< number of enabled capping planes
4269bd1b 178
179private:
180
181 //! Copying allowed only within Handles
30f0ad28 182 OpenGl_Clipping (const OpenGl_Clipping& );
183 OpenGl_Clipping& operator= (const OpenGl_Clipping& );
4269bd1b 184};
185
186#endif