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>
31 #include <NCollection_List.hxx>
32 #include <InterfaceGraphic_Graphic3d.hxx>
34 class OpenGl_Structure;
35 class OpenGl_GraphicDriver;
37 typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure;
39 //! Implementation of low-level graphic structure.
40 class OpenGl_Structure : public Graphic3d_CStructure
42 friend class OpenGl_Group;
46 //! Auxiliary wrapper to iterate OpenGl_Group sequence.
51 GroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
52 Standard_Boolean More() const { return myIter.More(); }
53 void Next() { myIter.Next(); }
54 const OpenGl_Group* Value() const { return (const OpenGl_Group* )(myIter.Value().operator->()); }
55 OpenGl_Group* ChangeValue() { return (OpenGl_Group* )(myIter.ChangeValue().operator->()); }
58 Graphic3d_SequenceOfGroup::Iterator myIter;
64 //! Create empty structure
65 Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
67 //! Setup structure graphic state
68 Standard_EXPORT virtual void UpdateNamedStatus();
70 //! Clear graphic data
71 Standard_EXPORT virtual void Clear();
73 //! Connect other structure to this one
74 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure);
76 //! Disconnect other structure to this one
77 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure);
79 //! Synchronize structure aspects
80 Standard_EXPORT virtual void UpdateAspects();
82 //! Synchronize structure transformation
83 Standard_EXPORT virtual void UpdateTransformation();
85 //! Highlight entire structure with color
86 Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
87 const Standard_Boolean theToCreate);
89 //! Highlight structure using boundary box
90 Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
91 const Standard_Boolean theToCreate);
93 //! Create shadow link to this structure
94 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const;
96 //! Create new group within this structure
97 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct);
99 //! Remove group from this structure
100 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup);
104 //! @return graphic groups
105 virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
110 //! Access graphic driver
111 OpenGl_GraphicDriver* GlDriver() const
113 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
116 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
118 void SetAspectLine (const CALL_DEF_CONTEXTLINE &theAspect);
119 void SetAspectFace (const CALL_DEF_CONTEXTFILLAREA& theAspect);
120 void SetAspectMarker (const CALL_DEF_CONTEXTMARKER& theAspect);
121 void SetAspectText (const CALL_DEF_CONTEXTTEXT &theAspect);
123 void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
125 void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
126 const Graphic3d_Vec3& theColor);
128 void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
130 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
132 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
134 //! Set z layer ID to display the structure in specified layer
135 Standard_EXPORT void SetZLayer (const Standard_Integer theLayerIndex);
138 Standard_EXPORT Standard_Integer GetZLayer() const;
140 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
141 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
143 //! This method releases GL resources without actual elements destruction.
144 //! As result structure could be correctly destroyed layer without GL context
145 //! (after last window was closed for example).
147 //! Notice however that reusage of this structure after calling this method is incorrect
148 //! and will lead to broken visualization due to loosed data.
149 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
151 //! Returns list of connected OpenGL structures.
152 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
154 //! Returns OpenGL face aspect.
155 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
157 //! Returns OpenGL transformation matrix.
158 const OpenGl_Matrix* Transformation() const { return myTransformation; }
160 //! Returns OpenGL persistent translation.
161 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
165 //! Returns structure modification state (for ray-tracing).
166 Standard_Size ModificationState() const { return myModificationState; }
168 //! Resets structure modification state (for ray-tracing)
169 void ResetModificationState() const { myModificationState = 0; }
171 //! Is the structure ray-tracable (contains ray-tracable elements)?
172 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
178 Standard_EXPORT virtual ~OpenGl_Structure();
182 //! Registers ancestor connected structure (for updating ray-tracing state).
183 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
185 //! Unregisters ancestor connected structure (for updating ray-tracing state).
186 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
188 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
189 void UnregisterFromAncestorStructure() const;
191 //! Updates modification state for structure and its parents.
192 void UpdateStateWithAncestorStructures() const;
194 //! Updates ray-tracable status for structure and its parents.
195 void UpdateRaytracableWithAncestorStructures() const;
197 //! Sets ray-tracable status for structure and its parents.
198 void SetRaytracableWithAncestorStructures() const;
204 OpenGl_Matrix* myTransformation;
205 TEL_TRANSFORM_PERSISTENCE* myTransPers;
206 OpenGl_AspectLine* myAspectLine;
207 OpenGl_AspectFace* myAspectFace;
208 OpenGl_AspectMarker* myAspectMarker;
209 OpenGl_AspectText* myAspectText;
211 Handle(OpenGl_Group) myHighlightBox;
212 TEL_COLOUR* myHighlightColor;
217 OpenGl_ListOfStructure myConnected;
220 mutable OpenGl_ListOfStructure myAncestorStructures;
221 mutable Standard_Boolean myIsRaytracable;
222 mutable Standard_Size myModificationState;
227 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
231 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
233 #endif // OpenGl_Structure_Header