0030748: Visualization - Marker displayed in immediate layer ruins QT Quick view...
[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
51b10cd4 19#include <Graphic3d_SequenceOfHClipPlane.hxx>
3202bf1e 20#include <NCollection_Vector.hxx>
4269bd1b 21#include <Standard_TypeDef.hxx>
4269bd1b 22
3202bf1e 23class OpenGl_ClippingIterator;
c04c30b3 24
4269bd1b 25//! This class contains logics related to tracking and modification of clipping plane
26//! state for particular OpenGl context. It contains information about enabled
27//! clipping planes and provides method to change clippings in context. The methods
28//! should be executed within OpenGl context associated with instance of this
29//! class.
30f0ad28 30class OpenGl_Clipping
4269bd1b 31{
25c35042 32 friend class OpenGl_ClippingIterator;
b859a34d 33public: //! @name general methods
34
4269bd1b 35 //! Default constructor.
30f0ad28 36 Standard_EXPORT OpenGl_Clipping();
4269bd1b 37
38 //! Initialize.
25c35042 39 Standard_EXPORT void Init();
4269bd1b 40
3202bf1e 41 //! Setup list of global (for entire view) clipping planes
42 //! and clears local plane list if it was not released before.
25c35042 43 Standard_EXPORT void Reset (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
4269bd1b 44
3202bf1e 45 //! Setup list of local (for current object) clipping planes.
25c35042 46 Standard_EXPORT void SetLocalPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
3b1817a9 47
48 //! @return true if there are enabled capping planes
3202bf1e 49 Standard_Boolean IsCappingOn() const { return myNbCapping > 0; }
3b1817a9 50
51 //! @return true if there are enabled clipping or capping planes
25c35042 52 Standard_Boolean IsClippingOrCappingOn() const { return NbClippingOrCappingOn() > 0; }
3b1817a9 53
1a7ece8f 54 //! @return number of enabled clipping + capping planes
25c35042 55 Standard_Integer NbClippingOrCappingOn() const
56 {
57 if (IsCappingDisableAllExcept())
58 {
59 return 1; // all Chains are disabled - only single (sub) plane is active
60 }
61 return myNbClipping + myNbCapping
62 + (IsCappingEnableAllExcept() ? -1 : 0); // exclude 1 plane with Capping filter turned ON
63 }
64
65 //! Return TRUE if there are clipping chains in the list (defining more than 1 sub-plane)
66 Standard_Boolean HasClippingChains() const
67 {
68 if (IsCappingDisableAllExcept() // all chains are disabled - only single (sub) plane is active;
69 || myNbChains == (myNbClipping + myNbCapping)) // no sub-planes
70 {
71 return Standard_False;
72 }
73 return !IsCappingEnableAllExcept()
74 || myCappedChain->NbChainNextPlanes() == 1
75 || myNbChains > 1; // if capping filter ON - chains counter should be decremented
76 }
3202bf1e 77
78public: //! @name advanced method for disabling defined planes
79
80 //! Return true if some clipping planes have been temporarily disabled.
81 Standard_Boolean HasDisabled() const { return myNbDisabled > 0; }
82
83 //! Disable plane temporarily.
25c35042 84 Standard_EXPORT Standard_Boolean SetEnabled (const OpenGl_ClippingIterator& thePlane,
3202bf1e 85 const Standard_Boolean theIsEnabled);
86
87 //! Temporarily disable all planes from the global (view) list, keep only local (object) list.
25c35042 88 Standard_EXPORT void DisableGlobal();
3202bf1e 89
90 //! Restore all temporarily disabled planes.
91 //! Does NOT affect constantly disabled planes Graphic3d_ClipPlane::IsOn().
25c35042 92 Standard_EXPORT void RestoreDisabled();
93
94//! @name capping algorithm filter
95public:
96
97 //! Chain which is either temporary disabled or the only one enabled for Capping algorithm.
98 const Handle(Graphic3d_ClipPlane)& CappedChain() const { return myCappedChain; }
99
100 //! Sub-plane index within filtered Chain; positive number for DisableAllExcept and negative for EnableAllExcept.
101 Standard_Integer CappedSubPlane() const { return myCappedSubPlane; }
102
103 //! Return TRUE if capping algorithm is in state, when all clipping planes are temporarily disabled except currently processed one.
104 bool IsCappingFilterOn() const { return !myCappedChain.IsNull(); }
105
106 //! Return TRUE if capping algorithm is in state, when all clipping planes are temporarily disabled except currently processed one.
107 bool IsCappingDisableAllExcept() const { return myCappedSubPlane > 0; }
108
109 //! Return TRUE if capping algorithm is in state, when all clipping planes are enabled except currently rendered one.
110 bool IsCappingEnableAllExcept() const { return myCappedSubPlane < 0; }
3202bf1e 111
25c35042 112 //! Temporarily disable all planes except specified one for Capping algorithm.
3202bf1e 113 //! Does not affect already disabled planes.
25c35042 114 Standard_EXPORT void DisableAllExcept (const Handle(Graphic3d_ClipPlane)& theChain,
115 const Standard_Integer theSubPlaneIndex);
3202bf1e 116
25c35042 117 //! Enable back planes disabled by ::DisableAllExcept() for Capping algorithm.
3202bf1e 118 //! Keeps only specified plane enabled.
25c35042 119 Standard_EXPORT void EnableAllExcept (const Handle(Graphic3d_ClipPlane)& theChain,
120 const Standard_Integer theSubPlaneIndex);
121
122 //! Resets chain filter for Capping algorithm.
123 Standard_EXPORT void ResetCappingFilter();
1a7ece8f 124
3202bf1e 125protected: //! @name clipping state modification commands
b859a34d 126
127 //! Add planes to the context clipping at the specified system of coordinates.
128 //! This methods loads appropriate transformation matrix from workspace to
129 //! to transform equation coordinates. The planes become enabled in the context.
130 //! If the number of the passed planes exceeds capabilities of OpenGl, the last planes
131 //! are simply ignored.
79f4f036 132 //!
133 //! Within FFP, method also temporarily resets ModelView matrix before calling glClipPlane().
134 //! Otherwise the method just redirects to addLazy().
135 //!
79f4f036 136 //! @param thePlanes [in/out] the list of planes to be added
b859a34d 137 //! The list then provides information on which planes were really added to clipping state.
138 //! This list then can be used to fall back to previous state.
25c35042 139 Standard_EXPORT void add (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
3202bf1e 140 const Standard_Integer theStartIndex);
b859a34d 141
142 //! Remove the passed set of clipping planes from the context state.
143 //! @param thePlanes [in] the planes to remove from list.
25c35042 144 Standard_EXPORT void remove (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes,
3202bf1e 145 const Standard_Integer theStartIndex);
146
147private:
b859a34d 148
3202bf1e 149 Handle(Graphic3d_SequenceOfHClipPlane) myPlanesGlobal; //!< global clipping planes
150 Handle(Graphic3d_SequenceOfHClipPlane) myPlanesLocal; //!< object clipping planes
151 NCollection_Vector<Standard_Boolean> myDisabledPlanes; //!< ids of disabled planes
25c35042 152
153 Handle(Graphic3d_ClipPlane) myCappedChain; //!< chain which is either temporary disabled or the only one enabled for Capping algorithm
154 Standard_Integer myCappedSubPlane; //!< sub-plane index within filtered chain; positive number for DisableAllExcept and negative for EnableAllExcept
155
3202bf1e 156 Standard_Integer myNbClipping; //!< number of enabled clipping-only planes (NOT capping)
157 Standard_Integer myNbCapping; //!< number of enabled capping planes
25c35042 158 Standard_Integer myNbChains; //!< number of enabled chains
3202bf1e 159 Standard_Integer myNbDisabled; //!< number of defined but disabled planes
b859a34d 160
3202bf1e 161private:
3202bf1e 162 //! Copying allowed only within Handles
163 OpenGl_Clipping (const OpenGl_Clipping& );
164 OpenGl_Clipping& operator= (const OpenGl_Clipping& );
4269bd1b 165};
166
167#endif