1 // Created on: 2011-08-01
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef OpenGl_Structure_Header
17 #define OpenGl_Structure_Header
19 #include <Graphic3d_CStructure.hxx>
20 #include <Graphic3d_SequenceOfHClipPlane.hxx>
22 #include <OpenGl_AspectLine.hxx>
23 #include <OpenGl_AspectFace.hxx>
24 #include <OpenGl_AspectMarker.hxx>
25 #include <OpenGl_AspectText.hxx>
27 #include <OpenGl_Group.hxx>
28 #include <OpenGl_Matrix.hxx>
29 #include <OpenGl_NamedStatus.hxx>
30 #include <OpenGl_Vec.hxx>
31 #include <OpenGl_Workspace.hxx>
33 #include <NCollection_List.hxx>
34 #include <InterfaceGraphic_Graphic3d.hxx>
36 class OpenGl_Structure;
37 class OpenGl_GraphicDriver;
39 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
41 //! Implementation of low-level graphic structure.
42 class OpenGl_Structure : public Graphic3d_CStructure
44 friend class OpenGl_Group;
48 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
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->()); }
60 Graphic3d_SequenceOfGroup::Iterator myIter;
66 //! Create empty structure
67 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
69 //! Setup structure graphic state
70 Standard_EXPORT virtual void UpdateNamedStatus();
72 //! Clear graphic data
73 Standard_EXPORT virtual void Clear();
75 //! Connect other structure to this one
76 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure);
78 //! Disconnect other structure to this one
79 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure);
81 //! Synchronize structure aspects
82 Standard_EXPORT virtual void UpdateAspects();
84 //! Synchronize structure transformation
85 Standard_EXPORT virtual void UpdateTransformation();
87 //! Highlight entire structure with color
88 Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
89 const Standard_Boolean theToCreate);
91 //! Highlight structure using boundary box
92 Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
93 const Standard_Boolean theToCreate);
95 //! Create shadow link to this structure
96 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
98 //! Create new group within this structure
99 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
101 //! Remove group from this structure
102 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
106 //! @return graphic groups
107 virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
112 //! Access graphic driver
113 OpenGl_GraphicDriver* GlDriver() const
115 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
118 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
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);
125 void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
127 void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
128 const Graphic3d_Vec3& theColor);
130 void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
132 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
134 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
136 //! Set z layer ID to display the structure in specified layer
137 Standard_EXPORT void SetZLayer (const Standard_Integer theLayerIndex);
140 Standard_EXPORT Standard_Integer GetZLayer() const;
142 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
143 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
145 //! Marks structure as not overlapping view volume (as it is by default).
146 void ResetCullingStatus() const
148 if (!IsAlwaysRendered())
150 myIsCulled = Standard_True;
154 //! Marks structure as overlapping the current view volume one.
155 //! The method is called during traverse of BVH tree.
156 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
158 //! Returns Standard_False if the structure hits the current view volume, otherwise
159 //! returns Standard_True. The default value for all structures before each traverse
160 //! of BVH tree is Standard_True.
161 Standard_Boolean IsCulled() const { return myIsCulled; }
163 //! Checks if the structure should be included into BVH tree or not.
164 const Standard_Boolean IsAlwaysRendered() const
170 || TransformPersistence.Flag != 0;
173 //! This method releases GL resources without actual elements destruction.
174 //! As result structure could be correctly destroyed layer without GL context
175 //! (after last window was closed for example).
177 //! Notice however that reusage of this structure after calling this method is incorrect
178 //! and will lead to broken visualization due to loosed data.
179 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
181 //! Returns list of connected OpenGL structures.
182 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
184 //! Returns OpenGL face aspect.
185 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
187 //! Returns OpenGL transformation matrix.
188 const OpenGl_Matrix* Transformation() const { return myTransformation; }
190 //! Returns OpenGL persistent translation.
191 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
193 //! Returns structure modification state (for ray-tracing).
194 Standard_Size ModificationState() const { return myModificationState; }
196 //! Resets structure modification state (for ray-tracing)
197 void ResetModificationState() const { myModificationState = 0; }
199 //! Is the structure ray-tracable (contains ray-tracable elements)?
200 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
204 Standard_EXPORT virtual ~OpenGl_Structure();
206 //! Registers ancestor connected structure (for updating ray-tracing state).
207 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
209 //! Unregisters ancestor connected structure (for updating ray-tracing state).
210 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
212 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
213 void UnregisterFromAncestorStructure() const;
215 //! Updates modification state for structure and its parents.
216 void UpdateStateWithAncestorStructures() const;
218 //! Updates ray-tracable status for structure and its parents.
219 void UpdateRaytracableWithAncestorStructures() const;
221 //! Sets ray-tracable status for structure and its parents.
222 void SetRaytracableWithAncestorStructures() const;
226 OpenGl_Matrix* myTransformation;
227 TEL_TRANSFORM_PERSISTENCE* myTransPers;
228 OpenGl_AspectLine* myAspectLine;
229 OpenGl_AspectFace* myAspectFace;
230 OpenGl_AspectMarker* myAspectMarker;
231 OpenGl_AspectText* myAspectText;
233 Handle(OpenGl_Group) myHighlightBox;
234 TEL_COLOUR* myHighlightColor;
239 OpenGl_ListOfStructure myConnected;
241 mutable OpenGl_ListOfStructure myAncestorStructures;
242 mutable Standard_Boolean myIsRaytracable;
243 mutable Standard_Size myModificationState;
245 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
249 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
253 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
255 #endif // OpenGl_Structure_Header