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 | |
79f4f036 |
23 | class OpenGl_Context; |
3202bf1e |
24 | class OpenGl_ClippingIterator; |
c04c30b3 |
25 | |
4269bd1b |
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 |
30 | //! class. |
30f0ad28 |
31 | class OpenGl_Clipping |
4269bd1b |
32 | { |
b859a34d |
33 | public: //! @name general methods |
34 | |
4269bd1b |
35 | //! Default constructor. |
30f0ad28 |
36 | Standard_EXPORT OpenGl_Clipping(); |
4269bd1b |
37 | |
38 | //! Initialize. |
39 | //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context. |
40 | Standard_EXPORT void Init (const Standard_Integer theMaxPlanes); |
41 | |
3202bf1e |
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); |
4269bd1b |
46 | |
3202bf1e |
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); |
b859a34d |
50 | |
3b1817a9 |
51 | //! @return true if there are enabled clipping planes (NOT capping) |
3202bf1e |
52 | Standard_Boolean IsClippingOn() const { return myNbClipping > 0; } |
3b1817a9 |
53 | |
54 | //! @return true if there are enabled capping planes |
3202bf1e |
55 | Standard_Boolean IsCappingOn() const { return myNbCapping > 0; } |
3b1817a9 |
56 | |
57 | //! @return true if there are enabled clipping or capping planes |
3202bf1e |
58 | Standard_Boolean IsClippingOrCappingOn() const { return (myNbClipping + myNbCapping) > 0; } |
3b1817a9 |
59 | |
1a7ece8f |
60 | //! @return number of enabled clipping + capping planes |
3202bf1e |
61 | Standard_Integer NbClippingOrCappingOn() const { return myNbClipping + myNbCapping; } |
62 | |
63 | public: //! @name advanced method for disabling defined planes |
64 | |
65 | //! Return true if some clipping planes have been temporarily disabled. |
66 | Standard_Boolean HasDisabled() const { return myNbDisabled > 0; } |
67 | |
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); |
72 | |
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); |
75 | |
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); |
79 | |
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); |
84 | |
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); |
1a7ece8f |
89 | |
3202bf1e |
90 | protected: //! @name clipping state modification commands |
b859a34d |
91 | |
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. |
79f4f036 |
97 | //! |
98 | //! Within FFP, method also temporarily resets ModelView matrix before calling glClipPlane(). |
99 | //! Otherwise the method just redirects to addLazy(). |
100 | //! |
101 | //! @param theGlCtx [in] context to access the matrices |
79f4f036 |
102 | //! @param thePlanes [in/out] the list of planes to be added |
b859a34d |
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. |
3202bf1e |
105 | Standard_EXPORT void add (const Handle(OpenGl_Context)& theGlCtx, |
106 | const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes, |
107 | const Standard_Integer theStartIndex); |
b859a34d |
108 | |
109 | //! Remove the passed set of clipping planes from the context state. |
110 | //! @param thePlanes [in] the planes to remove from list. |
3202bf1e |
111 | Standard_EXPORT void remove (const Handle(OpenGl_Context)& theGlCtx, |
112 | const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes, |
113 | const Standard_Integer theStartIndex); |
114 | |
115 | private: |
b859a34d |
116 | |
3202bf1e |
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() |
3202bf1e |
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 |
b859a34d |
124 | |
3202bf1e |
125 | private: |
b859a34d |
126 | |
3202bf1e |
127 | //! Copying allowed only within Handles |
128 | OpenGl_Clipping (const OpenGl_Clipping& ); |
129 | OpenGl_Clipping& operator= (const OpenGl_Clipping& ); |
b859a34d |
130 | |
3202bf1e |
131 | friend class OpenGl_ClippingIterator; |
132 | }; |
b859a34d |
133 | |
3202bf1e |
134 | //! The iterator through clipping planes. |
135 | class OpenGl_ClippingIterator |
136 | { |
137 | public: |
138 | |
139 | //! Main constructor. |
140 | Standard_EXPORT OpenGl_ClippingIterator(const OpenGl_Clipping& theClipping); |
4269bd1b |
141 | |
3202bf1e |
142 | //! Return true if iterator points to the valid clipping plane. |
143 | bool More() const { return myIter1.More() || myIter2.More(); } |
144 | |
145 | //! Go to the next clipping plane. |
146 | void Next() |
b859a34d |
147 | { |
3202bf1e |
148 | ++myCurrIndex; |
149 | if (myIter1.More()) |
150 | { |
151 | myIter1.Next(); |
152 | } |
153 | else |
b859a34d |
154 | { |
3202bf1e |
155 | myIter2.Next(); |
b859a34d |
156 | } |
3202bf1e |
157 | } |
b859a34d |
158 | |
3202bf1e |
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(); } |
4269bd1b |
162 | |
3202bf1e |
163 | //! Return the plane at current iterator position. |
164 | const Handle(Graphic3d_ClipPlane)& Value() const |
165 | { |
166 | return myIter1.More() |
167 | ? myIter1.Value() |
168 | : myIter2.Value(); |
169 | } |
4269bd1b |
170 | |
3202bf1e |
171 | //! Return true if plane from the global (view) list. |
172 | bool IsGlobal() const { return myIter1.More(); } |
4269bd1b |
173 | |
3202bf1e |
174 | //! Return the plane index. |
175 | Standard_Integer PlaneIndex() const { return myCurrIndex; } |
4269bd1b |
176 | |
177 | private: |
178 | |
3202bf1e |
179 | Graphic3d_SequenceOfHClipPlane::Iterator myIter1; |
180 | Graphic3d_SequenceOfHClipPlane::Iterator myIter2; |
181 | const NCollection_Vector<Standard_Boolean>* myDisabled; |
182 | Standard_Integer myCurrIndex; |
183 | |
4269bd1b |
184 | }; |
185 | |
186 | #endif |