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 <Graphic3d_SequenceOfHClipPlane.hxx>
20 #include <NCollection_Vector.hxx>
21 #include <Standard_TypeDef.hxx>
24 class OpenGl_ClippingIterator;
26 //! This class contains logics related to tracking and modification of clipping plane
27 //! state for particular OpenGl context. It contains information about enabled
28 //! clipping planes and provides method to change clippings in context. The methods
29 //! should be executed within OpenGl context associated with instance of this
33 public: //! @name general methods
35 //! Default constructor.
36 Standard_EXPORT OpenGl_Clipping();
39 //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context.
40 Standard_EXPORT void Init (const Standard_Integer theMaxPlanes);
42 //! Setup list of global (for entire view) clipping planes
43 //! and clears local plane list if it was not released before.
44 Standard_EXPORT void Reset (const Handle(OpenGl_Context)& theGlCtx,
45 const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
47 //! Setup list of local (for current object) clipping planes.
48 Standard_EXPORT void SetLocalPlanes (const Handle(OpenGl_Context)& theGlCtx,
49 const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
51 //! @return true if there are enabled clipping planes (NOT capping)
52 Standard_Boolean IsClippingOn() const { return myNbClipping > 0; }
54 //! @return true if there are enabled capping planes
55 Standard_Boolean IsCappingOn() const { return myNbCapping > 0; }
57 //! @return true if there are enabled clipping or capping planes
58 Standard_Boolean IsClippingOrCappingOn() const { return (myNbClipping + myNbCapping) > 0; }
60 //! @return number of enabled clipping + capping planes
61 Standard_Integer NbClippingOrCappingOn() const { return myNbClipping + myNbCapping; }
63 public: //! @name advanced method for disabling defined planes
65 //! Return true if some clipping planes have been temporarily disabled.
66 Standard_Boolean HasDisabled() const { return myNbDisabled > 0; }
68 //! Disable plane temporarily.
69 Standard_EXPORT Standard_Boolean SetEnabled (const Handle(OpenGl_Context)& theGlCtx,
70 const OpenGl_ClippingIterator& thePlane,
71 const Standard_Boolean theIsEnabled);
73 //! Temporarily disable all planes from the global (view) list, keep only local (object) list.
74 Standard_EXPORT void DisableGlobal (const Handle(OpenGl_Context)& theGlCtx);
76 //! Restore all temporarily disabled planes.
77 //! Does NOT affect constantly disabled planes Graphic3d_ClipPlane::IsOn().
78 Standard_EXPORT void RestoreDisabled (const Handle(OpenGl_Context)& theGlCtx);
80 //! Temporarily disable all planes except specified one.
81 //! Does not affect already disabled planes.
82 Standard_EXPORT void DisableAllExcept (const Handle(OpenGl_Context)& theGlCtx,
83 const OpenGl_ClippingIterator& thePlane);
85 //! Enable back planes disabled by ::DisableAllExcept().
86 //! Keeps only specified plane enabled.
87 Standard_EXPORT void EnableAllExcept (const Handle(OpenGl_Context)& theGlCtx,
88 const OpenGl_ClippingIterator& thePlane);
90 protected: //! @name clipping state modification commands
92 //! Add planes to the context clipping at the specified system of coordinates.
93 //! This methods loads appropriate transformation matrix from workspace to
94 //! to transform equation coordinates. The planes become enabled in the context.
95 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
96 //! are simply ignored.
98 //! Within FFP, method also temporarily resets ModelView matrix before calling glClipPlane().
99 //! Otherwise the method just redirects to addLazy().
101 //! @param theGlCtx [in] context to access the matrices
102 //! @param thePlanes [in/out] the list of planes to be added
103 //! The list then provides information on which planes were really added to clipping state.
104 //! This list then can be used to fall back to previous state.
105 Standard_EXPORT void add (const Handle(OpenGl_Context)& theGlCtx,
106 const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
107 const Standard_Integer theStartIndex);
109 //! Remove the passed set of clipping planes from the context state.
110 //! @param thePlanes [in] the planes to remove from list.
111 Standard_EXPORT void remove (const Handle(OpenGl_Context)& theGlCtx,
112 const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
113 const Standard_Integer theStartIndex);
117 Handle(Graphic3d_SequenceOfHClipPlane) myPlanesGlobal; //!< global clipping planes
118 Handle(Graphic3d_SequenceOfHClipPlane) myPlanesLocal; //!< object clipping planes
119 NCollection_Vector<Standard_Boolean> myDisabledPlanes; //!< ids of disabled planes
120 NCollection_Vector<Standard_Boolean> mySkipFilter; //!< ids of planes that were disabled before calling ::DisableAllExcept()
121 Standard_Integer myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
122 Standard_Integer myNbCapping; //!< number of enabled capping planes
123 Standard_Integer myNbDisabled; //!< number of defined but disabled planes
127 //! Copying allowed only within Handles
128 OpenGl_Clipping (const OpenGl_Clipping& );
129 OpenGl_Clipping& operator= (const OpenGl_Clipping& );
131 friend class OpenGl_ClippingIterator;
134 //! The iterator through clipping planes.
135 class OpenGl_ClippingIterator
139 //! Main constructor.
140 Standard_EXPORT OpenGl_ClippingIterator(const OpenGl_Clipping& theClipping);
142 //! Return true if iterator points to the valid clipping plane.
143 bool More() const { return myIter1.More() || myIter2.More(); }
145 //! Go to the next clipping plane.
159 //! Return true if plane has been temporarily disabled
160 //! either by Graphic3d_ClipPlane->IsOn() property or by temporary filter.
161 bool IsDisabled() const { return myDisabled->Value (myCurrIndex) || !Value()->IsOn(); }
163 //! Return the plane at current iterator position.
164 const Handle(Graphic3d_ClipPlane)& Value() const
166 return myIter1.More()
171 //! Return true if plane from the global (view) list.
172 bool IsGlobal() const { return myIter1.More(); }
174 //! Return the plane index.
175 Standard_Integer PlaneIndex() const { return myCurrIndex; }
179 Graphic3d_SequenceOfHClipPlane::Iterator myIter1;
180 Graphic3d_SequenceOfHClipPlane::Iterator myIter2;
181 const NCollection_Vector<Standard_Boolean>* myDisabled;
182 Standard_Integer myCurrIndex;