4269bd1b |
1 | // Created on: 2013-09-05 |
2 | // Created by: Anton POLETAEV |
3 | // Copyright (c) 2013 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
20 | #ifndef _OpenGl_ClippingState_H__ |
21 | #define _OpenGl_ClippingState_H__ |
22 | |
23 | #include <Aspect_GenId.hxx> |
24 | #include <Graphic3d_ClipPlane.hxx> |
25 | #include <Graphic3d_SetOfHClipPlane.hxx> |
26 | #include <NCollection_DataMap.hxx> |
27 | #include <NCollection_Handle.hxx> |
28 | #include <Standard_TypeDef.hxx> |
29 | #include <OpenGl_Matrix.hxx> |
30 | |
31 | //! This class contains logics related to tracking and modification of clipping plane |
32 | //! state for particular OpenGl context. It contains information about enabled |
33 | //! clipping planes and provides method to change clippings in context. The methods |
34 | //! should be executed within OpenGl context associated with instance of this |
35 | //! class. |
36 | class OpenGl_ClippingState |
37 | { |
38 | public: |
39 | |
40 | //! Default constructor. |
41 | Standard_EXPORT OpenGl_ClippingState (); |
42 | |
43 | //! Initialize. |
44 | //! @param theMaxPlanes [in] number of clipping planes supported by OpenGl context. |
45 | Standard_EXPORT void Init (const Standard_Integer theMaxPlanes); |
46 | |
47 | //! @return sequence of set clipping planes. |
48 | Standard_EXPORT Graphic3d_SetOfHClipPlane Planes() const; |
49 | |
50 | //! Check whether the clipping plane has been set for the current context state. |
51 | //! @param thePlane [in] the plane to check. |
52 | //! @return True if plane is set. |
53 | Standard_EXPORT Standard_Boolean IsSet (const Handle(Graphic3d_ClipPlane)& thePlane) const; |
54 | |
55 | //! Set collection of clipping planes for available plane ids. Current model view matrix is used. |
56 | //! @param thePlanes [in] collection of planes. |
57 | //! @param theToEnable [in] the boolean flag notifying whether the planes should be enabled. |
58 | Standard_EXPORT void Set (const Graphic3d_SetOfHClipPlane& thePlanes, |
59 | const Standard_Boolean theToEnable = Standard_True); |
60 | |
61 | //! Set collection of clipping planes for available plane ids. Identity matrix in case |
62 | //! if passed matrix pointer is NULL. |
63 | //! @param thePlanes [in] collection of planes. |
64 | //! @param theViewMatrix [in] view matrix to be used to define plane equation. |
65 | //! @param theToEnable [in] the boolean flag notifying whether the planes should be enabled. |
66 | Standard_EXPORT void Set (const Graphic3d_SetOfHClipPlane& thePlanes, |
67 | const OpenGl_Matrix* theViewMatrix, |
68 | const Standard_Boolean theToEnable = Standard_True); |
69 | |
70 | //! Unset and disable collection of clipping planes. |
71 | //! @param thePlanes [in] the plane to deactivate. |
72 | Standard_EXPORT void Unset (const Graphic3d_SetOfHClipPlane& thePlanes); |
73 | |
74 | //! Check whether the clipping plane has been set and enabled for the current context state. |
75 | //! @param thePlane [in] the plane to check. |
76 | //! @return True if plane is enabled. |
77 | Standard_EXPORT Standard_Boolean IsEnabled (const Handle(Graphic3d_ClipPlane)& thePlane) const; |
78 | |
79 | //! Change enabled / disabled state of the clipping plane. |
80 | //! @param thePlane [in] the plane to change the state. |
81 | //! @param theIsEnabled [in] the flag indicating whether the plane should be enabled or not. |
82 | //! @return False if plane is not set for the context. |
83 | Standard_EXPORT void SetEnabled (const Handle(Graphic3d_ClipPlane)& thePlane, const Standard_Boolean theIsEnabled); |
84 | |
85 | private: |
86 | |
87 | typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), Standard_Integer> OpenGl_MapOfContextPlanes; |
88 | typedef NCollection_DataMap<Handle(Graphic3d_ClipPlane), Standard_Boolean> OpenGl_MapOfPlaneStates; |
89 | typedef NCollection_Handle<Aspect_GenId> OpenGl_EmptyPlaneIds; |
90 | |
91 | OpenGl_MapOfContextPlanes myPlanes; //!< map of clip planes bound for the ids |
92 | OpenGl_MapOfPlaneStates myPlaneStates; //!< map of clip planes state (enabled/disabled). |
93 | OpenGl_EmptyPlaneIds myEmptyPlaneIds; //!< generator of empty ids |
94 | |
95 | private: |
96 | |
97 | //! Copying allowed only within Handles |
98 | OpenGl_ClippingState (const OpenGl_ClippingState& ); |
99 | OpenGl_ClippingState& operator= (const OpenGl_ClippingState& ); |
100 | |
101 | }; |
102 | |
103 | #endif |