0024837: Visualization - revise design and implementation of connected Interactive...
[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>
b7cd4ba7 30#include <OpenGl_Vec.hxx>
31#include <OpenGl_Workspace.hxx>
2166f0fa 32
63bcc448 33#include <NCollection_List.hxx>
34#include <InterfaceGraphic_Graphic3d.hxx>
4269bd1b 35
bf75be98 36class OpenGl_Structure;
63bcc448 37class OpenGl_GraphicDriver;
bf75be98 38
39typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
2166f0fa 40
b64d84be 41//! Implementation of low-level graphic structure.
63bcc448 42class OpenGl_Structure : public Graphic3d_CStructure
2166f0fa 43{
e276548b 44 friend class OpenGl_Group;
5e27df78 45
46public:
47
b64d84be 48 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
49 class GroupIterator
50 {
51
52 public:
53 GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
54 Standard_Boolean More() const { return myIter.More(); }
55 void Next() { myIter.Next(); }
56 const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
57 OpenGl_Group* ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
58
59 private:
60 Graphic3d_SequenceOfGroup::Iterator myIter;
61
62 };
63
64public:
65
63bcc448 66 //! Create empty structure
b64d84be 67 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
63bcc448 68
69 //! Setup structure graphic state
b64d84be 70 Standard_EXPORT virtual void UpdateNamedStatus();
63bcc448 71
72 //! Clear graphic data
b64d84be 73 Standard_EXPORT virtual void Clear();
63bcc448 74
75 //! Connect other structure to this one
b64d84be 76 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure);
63bcc448 77
78 //! Disconnect other structure to this one
b64d84be 79 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure);
63bcc448 80
81 //! Synchronize structure aspects
b64d84be 82 Standard_EXPORT virtual void UpdateAspects();
2166f0fa 83
63bcc448 84 //! Synchronize structure transformation
b64d84be 85 Standard_EXPORT virtual void UpdateTransformation();
63bcc448 86
87 //! Highlight entire structure with color
b64d84be 88 Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
89 const Standard_Boolean theToCreate);
63bcc448 90
91 //! Highlight structure using boundary box
b64d84be 92 Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
93 const Standard_Boolean theToCreate);
63bcc448 94
679ecdee 95 //! Create shadow link to this structure
b64d84be 96 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
97
98 //! Create new group within this structure
99 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
100
101 //! Remove group from this structure
102 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
679ecdee 103
63bcc448 104public:
105
b64d84be 106 //! @return graphic groups
107 virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
108 {
109 return myGroups;
110 }
111
63bcc448 112 //! Access graphic driver
113 OpenGl_GraphicDriver* GlDriver() const
114 {
115 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
116 }
2166f0fa
SK
117
118 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
119
fd4a6963 120 void SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect);
121 void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect);
122 void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
123 void SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect);
2166f0fa 124
b64d84be 125 void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 126
b64d84be 127 void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 128 const Graphic3d_Vec3& theColor);
2166f0fa 129
b64d84be 130 void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 131
e276548b 132 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
2166f0fa 133
b64d84be 134 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 135
59f45b7c 136 //! Set z layer ID to display the structure in specified layer
b64d84be 137 Standard_EXPORT void SetZLayer (const Standard_Integer theLayerIndex);
59f45b7c 138
139 //! Get z layer ID
b64d84be 140 Standard_EXPORT Standard_Integer GetZLayer() const;
2166f0fa 141
0717ddc1 142 //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
143 virtual void RenderGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const;
144
145 //! Renders the structure.
5e27df78 146 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
0717ddc1 147
148 //! Releases structure resources.
149 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 150
b7cd4ba7 151 //! Marks structure as not overlapping view volume (as it is by default).
152 void ResetCullingStatus() const
153 {
154 if (!IsAlwaysRendered())
155 {
156 myIsCulled = Standard_True;
157 }
158 }
159
160 //! Marks structure as overlapping the current view volume one.
161 //! The method is called during traverse of BVH tree.
162 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
163
164 //! Returns Standard_False if the structure hits the current view volume, otherwise
165 //! returns Standard_True. The default value for all structures before each traverse
166 //! of BVH tree is Standard_True.
167 Standard_Boolean IsCulled() const { return myIsCulled; }
168
169 //! Checks if the structure should be included into BVH tree or not.
170 const Standard_Boolean IsAlwaysRendered() const
171 {
172 return IsInfinite
173 || IsForHighlight
174 || IsMutable
175 || Is2dText
176 || TransformPersistence.Flag != 0;
177 }
178
dd8a4ce9 179 //! This method releases GL resources without actual elements destruction.
e276548b 180 //! As result structure could be correctly destroyed layer without GL context
dd8a4ce9 181 //! (after last window was closed for example).
182 //!
183 //! Notice however that reusage of this structure after calling this method is incorrect
184 //! and will lead to broken visualization due to loosed data.
b64d84be 185 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
e276548b 186
187 //! Returns list of connected OpenGL structures.
188 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
189
190 //! Returns OpenGL face aspect.
191 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
192
193 //! Returns OpenGL transformation matrix.
194 const OpenGl_Matrix* Transformation() const { return myTransformation; }
195
196 //! Returns OpenGL persistent translation.
197 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
198
e276548b 199 //! Returns structure modification state (for ray-tracing).
200 Standard_Size ModificationState() const { return myModificationState; }
201
202 //! Resets structure modification state (for ray-tracing)
203 void ResetModificationState() const { myModificationState = 0; }
204
205 //! Is the structure ray-tracable (contains ray-tracable elements)?
206 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
207
5e27df78 208protected:
209
b64d84be 210 Standard_EXPORT virtual ~OpenGl_Structure();
5e27df78 211
e276548b 212 //! Registers ancestor connected structure (for updating ray-tracing state).
213 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
214
215 //! Unregisters ancestor connected structure (for updating ray-tracing state).
216 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
217
d5af8626 218 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
219 void UnregisterFromAncestorStructure() const;
220
e276548b 221 //! Updates modification state for structure and its parents.
222 void UpdateStateWithAncestorStructures() const;
223
224 //! Updates ray-tracable status for structure and its parents.
225 void UpdateRaytracableWithAncestorStructures() const;
226
227 //! Sets ray-tracable status for structure and its parents.
228 void SetRaytracableWithAncestorStructures() const;
229
5e27df78 230protected:
2166f0fa 231
5e27df78 232 OpenGl_Matrix* myTransformation;
233 TEL_TRANSFORM_PERSISTENCE* myTransPers;
5e27df78 234 OpenGl_AspectLine* myAspectLine;
235 OpenGl_AspectFace* myAspectFace;
236 OpenGl_AspectMarker* myAspectMarker;
237 OpenGl_AspectText* myAspectText;
63bcc448 238
b64d84be 239 Handle(OpenGl_Group) myHighlightBox;
5e27df78 240 TEL_COLOUR* myHighlightColor;
63bcc448 241
242 int myNamedStatus;
5e27df78 243 int myZLayer;
2166f0fa 244
51b10cd4 245 OpenGl_ListOfStructure myConnected;
2166f0fa 246
e276548b 247 mutable OpenGl_ListOfStructure myAncestorStructures;
248 mutable Standard_Boolean myIsRaytracable;
249 mutable Standard_Size myModificationState;
e276548b 250
b7cd4ba7 251 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
252
5e27df78 253public:
2166f0fa 254
63bcc448 255 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
5e27df78 256
2166f0fa
SK
257};
258
63bcc448 259DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
260
261#endif // OpenGl_Structure_Header