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 class OpenGl_Structure : public Graphic3d_CStructure
41 friend class OpenGl_Group;
45 //! Create empty structure
46 OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager);
48 //! Setup structure graphic state
49 virtual void UpdateNamedStatus();
51 //! Clear graphic data
54 //! Connect other structure to this one
55 virtual void Connect (Graphic3d_CStructure& theStructure);
57 //! Disconnect other structure to this one
58 virtual void Disconnect (Graphic3d_CStructure& theStructure);
60 //! Synchronize structure aspects
61 virtual void UpdateAspects();
63 //! Synchronize structure transformation
64 virtual void UpdateTransformation();
66 //! Highlight entire structure with color
67 virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
68 const Standard_Boolean theToCreate);
70 //! Highlight structure using boundary box
71 virtual void HighlightWithBndBox (const Standard_Boolean theToCreate);
75 //! Access graphic driver
76 OpenGl_GraphicDriver* GlDriver() const
78 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
81 void SetTransformPersistence (const CALL_DEF_TRANSFORM_PERSISTENCE &ATransPers);
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);
88 void SetHighlightBox (const Handle(OpenGl_Context)& theGlCtx,
89 const CALL_DEF_BOUNDBOX& theBoundBox);
91 void ClearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
93 void SetHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
94 const Graphic3d_Vec3& theColor);
96 void ClearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
98 Standard_Boolean IsVisible() const { return !(myNamedStatus & OPENGL_NS_HIDE); }
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);
105 //! Set z layer ID to display the structure in specified layer
106 void SetZLayer (const Standard_Integer theLayerIndex);
109 Standard_Integer GetZLayer () const;
111 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
112 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
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).
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);
122 //! Returns list of OpenGL groups.
123 const OpenGl_ListOfGroup& Groups() const { return myGroups; }
125 //! Returns list of connected OpenGL structures.
126 const OpenGl_ListOfStructure& ConnectedStructures() const { return myConnected; }
128 //! Returns OpenGL face aspect.
129 const OpenGl_AspectFace* AspectFace() const { return myAspectFace; }
131 //! Returns OpenGL transformation matrix.
132 const OpenGl_Matrix* Transformation() const { return myTransformation; }
134 //! Returns OpenGL persistent translation.
135 const TEL_TRANSFORM_PERSISTENCE* PersistentTranslation() const { return myTransPers; }
139 //! Returns structure modification state (for ray-tracing).
140 Standard_Size ModificationState() const { return myModificationState; }
142 //! Resets structure modification state (for ray-tracing)
143 void ResetModificationState() const { myModificationState = 0; }
145 //! Is the structure ray-tracable (contains ray-tracable elements)?
146 Standard_Boolean IsRaytracable() const { return myIsRaytracable; }
152 virtual ~OpenGl_Structure();
156 //! Registers ancestor connected structure (for updating ray-tracing state).
157 void RegisterAncestorStructure (const OpenGl_Structure* theStructure) const;
159 //! Unregisters ancestor connected structure (for updating ray-tracing state).
160 void UnregisterAncestorStructure (const OpenGl_Structure* theStructure) const;
162 //! Unregisters structure from ancestor structure (for updating ray-tracing state).
163 void UnregisterFromAncestorStructure() const;
165 //! Updates modification state for structure and its parents.
166 void UpdateStateWithAncestorStructures() const;
168 //! Updates ray-tracable status for structure and its parents.
169 void UpdateRaytracableWithAncestorStructures() const;
171 //! Sets ray-tracable status for structure and its parents.
172 void SetRaytracableWithAncestorStructures() const;
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;
185 OpenGl_Group* myHighlightBox;
186 TEL_COLOUR* myHighlightColor;
191 OpenGl_ListOfStructure myConnected;
192 OpenGl_ListOfGroup myGroups;
195 mutable OpenGl_ListOfStructure myAncestorStructures;
196 mutable Standard_Boolean myIsRaytracable;
197 mutable Standard_Size myModificationState;
202 DEFINE_STANDARD_RTTI(OpenGl_Structure) // Type definition
206 DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
208 #endif // OpenGl_Structure_Header