0024704: Visualization - inherit OpenGl_Structure from Graphic3d_CStructure
[occt.git] / src / OpenGl / OpenGl_Structure.hxx
CommitLineData
b311480e 1// Created on: 2011-08-01
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
2166f0fa
SK
16#ifndef OpenGl_Structure_Header
17#define OpenGl_Structure_Header
18
63bcc448 19#include <Graphic3d_CStructure.hxx>
20#include <Graphic3d_SequenceOfHClipPlane.hxx>
2166f0fa
SK
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>
e276548b 29#include <OpenGl_NamedStatus.hxx>
2166f0fa 30
63bcc448 31#include <NCollection_List.hxx>
32#include <InterfaceGraphic_Graphic3d.hxx>
4269bd1b 33
bf75be98 34class OpenGl_Structure;
63bcc448 35class OpenGl_GraphicDriver;
bf75be98 36
37typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
2166f0fa 38
63bcc448 39class OpenGl_Structure : public Graphic3d_CStructure
2166f0fa 40{
e276548b 41 friend class OpenGl_Group;
5e27df78 42
43public:
44
63bcc448 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();
2166f0fa 62
63bcc448 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
73public:
74
75 //! Access graphic driver
76 OpenGl_GraphicDriver* GlDriver() const
77 {
78 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
79 }
2166f0fa
SK
80
81 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
82
fd4a6963 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);
2166f0fa 87
5e27df78 88 void SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
30f0ad28 89 const CALL_DEF_BOUNDBOX& theBoundBox);
5e27df78 90
91 void ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
92
93 void SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 94 const Graphic3d_Vec3& theColor);
2166f0fa 95
5e27df78 96 void ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 97
e276548b 98 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
2166f0fa 99
5e27df78 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);
2166f0fa 104
59f45b7c 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;
2166f0fa 110
5e27df78 111 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
112 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
113
dd8a4ce9 114 //! This method releases GL resources without actual elements destruction.
e276548b 115 //! As result structure could be correctly destroyed layer without GL context
dd8a4ce9 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
e276548b 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
5e27df78 150protected:
151
152 virtual ~OpenGl_Structure();
153
e276548b 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
d5af8626 162 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
163 void UnregisterFromAncestorStructure() const;
164
e276548b 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
5e27df78 176protected:
2166f0fa 177
5e27df78 178 OpenGl_Matrix* myTransformation;
179 TEL_TRANSFORM_PERSISTENCE* myTransPers;
5e27df78 180 OpenGl_AspectLine* myAspectLine;
181 OpenGl_AspectFace* myAspectFace;
182 OpenGl_AspectMarker* myAspectMarker;
183 OpenGl_AspectText* myAspectText;
63bcc448 184
5e27df78 185 OpenGl_Group* myHighlightBox;
186 TEL_COLOUR* myHighlightColor;
63bcc448 187
188 int myNamedStatus;
5e27df78 189 int myZLayer;
2166f0fa 190
51b10cd4 191 OpenGl_ListOfStructure myConnected;
192 OpenGl_ListOfGroup myGroups;
2166f0fa 193
e276548b 194#ifdef HAVE_OPENCL
195 mutable OpenGl_ListOfStructure myAncestorStructures;
196 mutable Standard_Boolean myIsRaytracable;
197 mutable Standard_Size myModificationState;
198#endif
199
5e27df78 200public:
2166f0fa 201
63bcc448 202 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
5e27df78 203
2166f0fa
SK
204};
205
63bcc448 206DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
207
208#endif // OpenGl_Structure_Header