Commit | Line | Data |
---|---|---|
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 | 21 | |
bf5f0ca2 | 22 | #include <OpenGl_Aspects.hxx> |
2166f0fa | 23 | |
5b111128 | 24 | #include <OpenGl_GraphicDriver.hxx> |
2166f0fa | 25 | #include <OpenGl_Group.hxx> |
b7cd4ba7 | 26 | #include <OpenGl_Vec.hxx> |
27 | #include <OpenGl_Workspace.hxx> | |
2166f0fa | 28 | |
63bcc448 | 29 | #include <NCollection_List.hxx> |
4269bd1b | 30 | |
63bcc448 | 31 | class OpenGl_GraphicDriver; |
bf75be98 | 32 | |
d325cb7f | 33 | DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure) |
bf75be98 | 34 | typedef NCollection_List<const OpenGl_Structure* > OpenGl_ListOfStructure; |
2166f0fa | 35 | |
b64d84be | 36 | //! Implementation of low-level graphic structure. |
63bcc448 | 37 | class OpenGl_Structure : public Graphic3d_CStructure |
2166f0fa | 38 | { |
e276548b | 39 | friend class OpenGl_Group; |
d325cb7f | 40 | DEFINE_STANDARD_RTTIEXT(OpenGl_Structure, Graphic3d_CStructure) |
b64d84be | 41 | public: |
42 | ||
d325cb7f | 43 | //! Auxiliary wrapper to iterate OpenGl_Structure sequence. |
44 | typedef SubclassStructIterator<OpenGl_Structure> StructIterator; | |
b64d84be | 45 | |
d325cb7f | 46 | //! Auxiliary wrapper to iterate OpenGl_Group sequence. |
47 | typedef SubclassGroupIterator<OpenGl_Group> GroupIterator; | |
b64d84be | 48 | |
5e27df78 | 49 | public: |
50 | ||
63bcc448 | 51 | //! Create empty structure |
b64d84be | 52 | Standard_EXPORT OpenGl_Structure (const Handle(Graphic3d_StructureManager)& theManager); |
63bcc448 | 53 | |
54 | //! Setup structure graphic state | |
a1954302 | 55 | Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE; |
63bcc448 | 56 | |
57 | //! Clear graphic data | |
79104795 | 58 | Standard_EXPORT virtual void Clear() Standard_OVERRIDE; |
63bcc448 | 59 | |
60 | //! Connect other structure to this one | |
79104795 | 61 | Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE; |
63bcc448 | 62 | |
63 | //! Disconnect other structure to this one | |
79104795 | 64 | Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE; |
63bcc448 | 65 | |
63bcc448 | 66 | //! Synchronize structure transformation |
7f24b768 | 67 | Standard_EXPORT virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) Standard_OVERRIDE; |
63bcc448 | 68 | |
7c3ef2f7 | 69 | //! Set transformation persistence. |
70 | Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE; | |
71 | ||
72 | //! Set z layer ID to display the structure in specified layer | |
73 | Standard_EXPORT virtual void SetZLayer(const Graphic3d_ZLayerId theLayerIndex) Standard_OVERRIDE; | |
74 | ||
8e5fb5ea | 75 | //! Highlights structure according to the given style and updates corresponding class fields |
76 | //! (highlight status and style) | |
98b15dbf | 77 | Standard_EXPORT virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) Standard_OVERRIDE; |
63bcc448 | 78 | |
8e5fb5ea | 79 | //! Unighlights structure and updates corresponding class fields (highlight status and style) |
80 | Standard_EXPORT virtual void GraphicUnhighlight() Standard_OVERRIDE; | |
63bcc448 | 81 | |
679ecdee | 82 | //! Create shadow link to this structure |
79104795 | 83 | Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE; |
b64d84be | 84 | |
85 | //! Create new group within this structure | |
79104795 | 86 | Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE; |
b64d84be | 87 | |
88 | //! Remove group from this structure | |
79104795 | 89 | Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE; |
679ecdee | 90 | |
63bcc448 | 91 | public: |
92 | ||
93 | //! Access graphic driver | |
94 | OpenGl_GraphicDriver* GlDriver() const | |
95 | { | |
96 | return (OpenGl_GraphicDriver* )myGraphicDriver.operator->(); | |
97 | } | |
2166f0fa | 98 | |
b64d84be | 99 | Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx); |
2166f0fa | 100 | |
0717ddc1 | 101 | //! Renders the structure. |
b31fbc83 | 102 | Standard_EXPORT virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; |
0717ddc1 | 103 | |
104 | //! Releases structure resources. | |
b31fbc83 | 105 | Standard_EXPORT virtual void Release (const Handle(OpenGl_Context)& theGlCtx); |
5e27df78 | 106 | |
dd8a4ce9 | 107 | //! This method releases GL resources without actual elements destruction. |
e276548b | 108 | //! As result structure could be correctly destroyed layer without GL context |
dd8a4ce9 | 109 | //! (after last window was closed for example). |
110 | //! | |
111 | //! Notice however that reusage of this structure after calling this method is incorrect | |
112 | //! and will lead to broken visualization due to loosed data. | |
b64d84be | 113 | Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx); |
e276548b | 114 | |
d4aaad5b | 115 | //! Returns instanced OpenGL structure. |
116 | const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; } | |
e276548b | 117 | |
e276548b | 118 | //! Returns structure modification state (for ray-tracing). |
119 | Standard_Size ModificationState() const { return myModificationState; } | |
120 | ||
189f85a3 | 121 | //! Resets structure modification state (for ray-tracing). |
e276548b | 122 | void ResetModificationState() const { myModificationState = 0; } |
123 | ||
124 | //! Is the structure ray-tracable (contains ray-tracable elements)? | |
d4aaad5b | 125 | Standard_Boolean IsRaytracable() const; |
e276548b | 126 | |
7c3ef2f7 | 127 | //! Update render transformation matrix. |
d325cb7f | 128 | Standard_EXPORT virtual void updateLayerTransformation() Standard_OVERRIDE; |
7c3ef2f7 | 129 | |
bc73b006 | 130 | //! Dumps the content of me into the stream |
131 | Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; | |
132 | ||
5e27df78 | 133 | protected: |
134 | ||
b64d84be | 135 | Standard_EXPORT virtual ~OpenGl_Structure(); |
5e27df78 | 136 | |
e276548b | 137 | //! Updates ray-tracable status for structure and its parents. |
d4aaad5b | 138 | void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const; |
e276548b | 139 | |
3e05329c | 140 | //! Renders groups of structure without applying any attributes (i.e. transform, material etc). |
141 | //! @param theWorkspace current workspace | |
142 | //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives | |
143 | Standard_EXPORT void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace, | |
144 | bool& theHasClosed) const; | |
145 | ||
98b15dbf | 146 | //! Render the bounding box. |
147 | Standard_EXPORT void renderBoundingBox(const Handle(OpenGl_Workspace)& theWorkspace) const; | |
8e5fb5ea | 148 | |
5e27df78 | 149 | protected: |
2166f0fa | 150 | |
d4aaad5b | 151 | OpenGl_Structure* myInstancedStructure; |
7c3ef2f7 | 152 | Graphic3d_Mat4 myRenderTrsf; //!< transformation, actually used for rendering (includes Local Origin shift) |
2166f0fa | 153 | |
d4aaad5b | 154 | mutable Standard_Boolean myIsRaytracable; |
155 | mutable Standard_Size myModificationState; | |
e276548b | 156 | |
d4aaad5b | 157 | Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order. |
7d9e854b | 158 | |
2166f0fa SK |
159 | }; |
160 | ||
63bcc448 | 161 | #endif // OpenGl_Structure_Header |