0026885: Visualization - drop redundant aspects from structure level
[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
5b111128 27#include <OpenGl_GraphicDriver.hxx>
2166f0fa
SK
28#include <OpenGl_Group.hxx>
29#include <OpenGl_Matrix.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
a1954302 70 Standard_EXPORT virtual void OnVisibilityChanged() Standard_OVERRIDE;
63bcc448 71
72 //! Clear graphic data
79104795 73 Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
63bcc448 74
75 //! Connect other structure to this one
79104795 76 Standard_EXPORT virtual void Connect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
63bcc448 77
78 //! Disconnect other structure to this one
79104795 79 Standard_EXPORT virtual void Disconnect (Graphic3d_CStructure& theStructure) Standard_OVERRIDE;
63bcc448 80
63bcc448 81 //! Synchronize structure transformation
79104795 82 Standard_EXPORT virtual void UpdateTransformation() Standard_OVERRIDE;
63bcc448 83
84 //! Highlight entire structure with color
b64d84be 85 Standard_EXPORT virtual void HighlightWithColor (const Graphic3d_Vec3& theColor,
79104795 86 const Standard_Boolean theToCreate) Standard_OVERRIDE;
63bcc448 87
88 //! Highlight structure using boundary box
b64d84be 89 Standard_EXPORT virtual void HighlightWithBndBox (const Handle(Graphic3d_Structure)& theStruct,
79104795 90 const Standard_Boolean theToCreate) Standard_OVERRIDE;
63bcc448 91
679ecdee 92 //! Create shadow link to this structure
79104795 93 Standard_EXPORT virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const Standard_OVERRIDE;
b64d84be 94
95 //! Create new group within this structure
79104795 96 Standard_EXPORT virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) Standard_OVERRIDE;
b64d84be 97
98 //! Remove group from this structure
79104795 99 Standard_EXPORT virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) Standard_OVERRIDE;
679ecdee 100
63bcc448 101public:
102
b64d84be 103 //! @return graphic groups
104 virtual const Graphic3d_SequenceOfGroup& DrawGroups() const
105 {
106 return myGroups;
107 }
108
63bcc448 109 //! Access graphic driver
110 OpenGl_GraphicDriver* GlDriver() const
111 {
112 return (OpenGl_GraphicDriver* )myGraphicDriver.operator->();
113 }
2166f0fa 114
b64d84be 115 void clearHighlightBox (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 116
b64d84be 117 void setHighlightColor (const Handle(OpenGl_Context)& theGlCtx,
63bcc448 118 const Graphic3d_Vec3& theColor);
2166f0fa 119
b64d84be 120 void clearHighlightColor (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 121
b64d84be 122 Standard_EXPORT void Clear (const Handle(OpenGl_Context)& theGlCtx);
2166f0fa 123
0717ddc1 124 //! Renders groups of structure without applying any attributes (i.e. transform, material etc).
cc6852f3 125 //! @param theWorkspace current workspace
126 //! @param theHasClosed flag will be set to TRUE if structure contains at least one group of closed primitives
127 virtual void renderGeometry (const Handle(OpenGl_Workspace)& theWorkspace,
128 bool& theHasClosed) const;
129
130 //! Renders groups of closed primitives without applying any attributes (i.e. transform, material etc).
131 virtual void renderClosedGeometry (const Handle(OpenGl_Workspace)& theWorkspace) const;
0717ddc1 132
133 //! Renders the structure.
5e27df78 134 virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const;
0717ddc1 135
136 //! Releases structure resources.
137 virtual void Release (const Handle(OpenGl_Context)& theGlCtx);
5e27df78 138
b7cd4ba7 139 //! Marks structure as not overlapping view volume (as it is by default).
140 void ResetCullingStatus() const
141 {
142 if (!IsAlwaysRendered())
143 {
144 myIsCulled = Standard_True;
145 }
146 }
147
148 //! Marks structure as overlapping the current view volume one.
149 //! The method is called during traverse of BVH tree.
150 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
151
152 //! Returns Standard_False if the structure hits the current view volume, otherwise
153 //! returns Standard_True. The default value for all structures before each traverse
154 //! of BVH tree is Standard_True.
155 Standard_Boolean IsCulled() const { return myIsCulled; }
156
157 //! Checks if the structure should be included into BVH tree or not.
487bf1ce 158 Standard_Boolean IsAlwaysRendered() const
b7cd4ba7 159 {
160 return IsInfinite
161 || IsForHighlight
162 || IsMutable
163 || Is2dText
97f937cc 164 || (TransformPersistence.Flags & Graphic3d_TMF_2d) != 0
165 || (TransformPersistence.Flags & Graphic3d_TMF_PanPers) != 0
166 || (TransformPersistence.Flags & Graphic3d_TMF_TriedronPers) != 0;
b7cd4ba7 167 }
168
dd8a4ce9 169 //! This method releases GL resources without actual elements destruction.
e276548b 170 //! As result structure could be correctly destroyed layer without GL context
dd8a4ce9 171 //! (after last window was closed for example).
172 //!
173 //! Notice however that reusage of this structure after calling this method is incorrect
174 //! and will lead to broken visualization due to loosed data.
b64d84be 175 Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theGlCtx);
e276548b 176
d4aaad5b 177 //! Returns instanced OpenGL structure.
178 const OpenGl_Structure* InstancedStructure() const { return myInstancedStructure; }
e276548b 179
e276548b 180 //! Returns structure modification state (for ray-tracing).
181 Standard_Size ModificationState() const { return myModificationState; }
182
189f85a3 183 //! Resets structure modification state (for ray-tracing).
e276548b 184 void ResetModificationState() const { myModificationState = 0; }
185
186 //! Is the structure ray-tracable (contains ray-tracable elements)?
d4aaad5b 187 Standard_Boolean IsRaytracable() const;
e276548b 188
5e27df78 189protected:
190
b64d84be 191 Standard_EXPORT virtual ~OpenGl_Structure();
5e27df78 192
e276548b 193 //! Updates ray-tracable status for structure and its parents.
d4aaad5b 194 void UpdateStateIfRaytracable (const Standard_Boolean toCheck = Standard_True) const;
e276548b 195
5e27df78 196protected:
2166f0fa 197
b64d84be 198 Handle(OpenGl_Group) myHighlightBox;
5e27df78 199 TEL_COLOUR* myHighlightColor;
63bcc448 200
d4aaad5b 201 OpenGl_Structure* myInstancedStructure;
2166f0fa 202
d4aaad5b 203 mutable Standard_Boolean myIsRaytracable;
204 mutable Standard_Size myModificationState;
e276548b 205
d4aaad5b 206 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse.
b7cd4ba7 207
d4aaad5b 208 Standard_Boolean myIsMirrored; //!< Used to tell OpenGl to interpret polygons in clockwise order.
7d9e854b 209
5e27df78 210public:
2166f0fa 211
92efcf78 212 DEFINE_STANDARD_RTTIEXT(OpenGl_Structure,Graphic3d_CStructure) // Type definition
5e27df78 213
2166f0fa
SK
214};
215
63bcc448 216DEFINE_STANDARD_HANDLE(OpenGl_Structure, Graphic3d_CStructure)
217
218#endif // OpenGl_Structure_Header