0024704: Visualization - inherit OpenGl_Structure from Graphic3d_CStructure
[occt.git] / src / OpenGl / OpenGl_Structure.hxx
1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef OpenGl_Structure_Header
17 #define OpenGl_Structure_Header
18
19 #include <Graphic3d_CStructure.hxx>
20 #include <Graphic3d_SequenceOfHClipPlane.hxx>
21
22 #include <OpenGl_AspectLine.hxx>
23 #include <OpenGl_AspectFace.hxx>
24 #include <OpenGl_AspectMarker.hxx>
25 #include <OpenGl_AspectText.hxx>
26
27 #include <OpenGl_Group.hxx>
28 #include <OpenGl_Matrix.hxx>
29 #include <OpenGl_NamedStatus.hxx>
30
31 #include <NCollection_List.hxx>
32 #include <InterfaceGraphic_Graphic3d.hxx>
33
34 class OpenGl_Structure;
35 class OpenGl_GraphicDriver;
36
37 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
38
39 class OpenGl_Structure : public Graphic3d_CStructure
40 {
41   friend class OpenGl_Group;
42
43 public:
44
45   //! Create empty structure
46   OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
47
48   //! Setup structure graphic state
49   virtual void UpdateNamedStatus();
50
51   //! Clear graphic data
52   virtual void Clear();
53
54   //! Connect other structure to this one
55   virtual void Connect    (Graphic3d_CStructure& theStructure);
56
57   //! Disconnect other structure to this one
58   virtual void Disconnect (Graphic3d_CStructure& theStructure);
59
60   //! Synchronize structure aspects
61   virtual void UpdateAspects();
62
63   //! Synchronize structure transformation
64   virtual void UpdateTransformation();
65
66   //! Highlight entire structure with color
67   virtual void HighlightWithColor  (const Graphic3d_Vec3&  theColor,
68                                     const Standard_Boolean theToCreate);
69
70   //! Highlight structure using boundary box
71   virtual void HighlightWithBndBox (const Standard_Boolean theToCreate);
72
73 public:
74
75   //! Access graphic driver
76   OpenGl_GraphicDriver* GlDriver() const
77   {
78     return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
79   }
80
81   void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
82
83   void SetAspectLine   (const CALL_DEF_CONTEXTLINE &theAspect);
84   void SetAspectFace   (const CALL_DEF_CONTEXTFILLAREA& theAspect);
85   void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
86   void SetAspectText   (const CALL_DEF_CONTEXTTEXT &theAspect);
87
88   void SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
89                         const CALL_DEF_BOUNDBOX& theBoundBox);
90
91   void ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
92
93   void SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
94                           const Graphic3d_Vec3&         theColor);
95
96   void ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
97
98   Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
99
100   OpenGl_Group* AddGroup();
101   void RemoveGroup (const Handle(OpenGl_Context)& theGlCtx,
102                     const OpenGl_Group*           theGroup);
103   void Clear (const Handle(OpenGl_Context)& theGlCtx);
104
105   //! Set z layer ID to display the structure in specified layer
106   void SetZLayer (const Standard_Integer theLayerIndex);
107
108   //! Get z layer ID
109   Standard_Integer GetZLayer () const;
110
111   virtual void Render  (const Handle(OpenGl_Workspace)& theWorkspace) const;
112   virtual void Release (const Handle(OpenGl_Context)&   theGlCtx);
113
114   //! This method releases GL resources without actual elements destruction.
115   //! As result structure could be correctly destroyed layer without GL context
116   //! (after last window was closed for example).
117   //!
118   //! Notice however that reusage of this structure after calling this method is incorrect
119   //! and will lead to broken visualization due to loosed data.
120   void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
121
122   //! Returns list of OpenGL groups.
123   const OpenGl_ListOfGroup& Groups() const { return myGroups; }
124
125   //! Returns list of connected OpenGL structures.
126   const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
127
128   //! Returns OpenGL face aspect.
129   const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
130
131   //! Returns OpenGL transformation matrix.
132   const OpenGl_Matrix* Transformation() const { return myTransformation; }
133   
134   //! Returns OpenGL persistent translation.
135   const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
136
137 #ifdef HAVE_OPENCL
138
139   //! Returns structure modification state (for ray-tracing).
140   Standard_Size ModificationState() const { return myModificationState; }
141
142   //! Resets structure modification state (for ray-tracing)
143   void ResetModificationState() const { myModificationState = 0; }
144
145   //! Is the structure ray-tracable (contains ray-tracable elements)?
146   Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
147
148 #endif
149
150 protected:
151
152   virtual ~OpenGl_Structure();
153
154 #ifdef HAVE_OPENCL
155
156   //! Registers ancestor connected structure (for updating ray-tracing state).
157   void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
158
159   //! Unregisters ancestor connected structure (for updating ray-tracing state).
160   void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
161
162   //! Unregisters structure from ancestor structure (for updating ray-tracing state).
163   void UnregisterFromAncestorStructure() const;
164
165   //! Updates modification state for structure and its parents.
166   void UpdateStateWithAncestorStructures() const;
167
168   //! Updates ray-tracable status for structure and its parents.
169   void UpdateRaytracableWithAncestorStructures() const;
170
171   //! Sets ray-tracable status for structure and its parents.
172   void SetRaytracableWithAncestorStructures() const;
173
174 #endif
175
176 protected:
177
178   OpenGl_Matrix*             myTransformation;
179   TEL_TRANSFORM_PERSISTENCE* myTransPers;
180   OpenGl_AspectLine*         myAspectLine;
181   OpenGl_AspectFace*         myAspectFace;
182   OpenGl_AspectMarker*       myAspectMarker;
183   OpenGl_AspectText*         myAspectText;
184
185   OpenGl_Group*              myHighlightBox;
186   TEL_COLOUR*                myHighlightColor;
187
188   int                        myNamedStatus;
189   int                        myZLayer;
190
191   OpenGl_ListOfStructure           myConnected;
192   OpenGl_ListOfGroup               myGroups;
193
194 #ifdef HAVE_OPENCL
195   mutable OpenGl_ListOfStructure   myAncestorStructures;
196   mutable Standard_Boolean         myIsRaytracable;
197   mutable Standard_Size            myModificationState;
198 #endif
199
200 public:
201
202   DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
203
204 };
205
206 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
207
208 #endif // OpenGl_Structure_Header