1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Graphic3d_CStructure_HeaderFile
16 #define _Graphic3d_CStructure_HeaderFile
18 #include <Graphic3d_BndBox3d.hxx>
19 #include <Graphic3d_Group.hxx>
20 #include <Graphic3d_PresentationAttributes.hxx>
21 #include <Graphic3d_SequenceOfGroup.hxx>
22 #include <Graphic3d_SequenceOfHClipPlane.hxx>
23 #include <Graphic3d_TypeOfComposition.hxx>
24 #include <Graphic3d_ViewAffinity.hxx>
25 #include <Graphic3d_TransformPers.hxx>
26 #include <Graphic3d_Vec3.hxx>
27 #include <Graphic3d_ZLayerId.hxx>
28 #include <TopLoc_Datum3D.hxx>
29 #include <NCollection_IndexedMap.hxx>
31 class Graphic3d_GraphicDriver;
32 class Graphic3d_StructureManager;
34 //! Low-level graphic structure interface
35 class Graphic3d_CStructure : public Standard_Transient
39 //! Auxiliary wrapper to iterate through structure list.
40 template<class Struct_t>
41 class SubclassStructIterator
44 SubclassStructIterator (const NCollection_IndexedMap<const Graphic3d_CStructure*>& theStructs) : myIter (theStructs) {}
45 Standard_Boolean More() const { return myIter.More(); }
46 void Next() { myIter.Next(); }
47 const Struct_t* Value() const { return (const Struct_t* )(myIter.Value()); }
48 Struct_t* ChangeValue() { return (Struct_t* )(myIter.Value()); }
50 NCollection_IndexedMap<const Graphic3d_CStructure*>::Iterator myIter;
53 //! Auxiliary wrapper to iterate through group sequence.
54 template<class Group_t>
55 class SubclassGroupIterator
58 SubclassGroupIterator (const Graphic3d_SequenceOfGroup& theGroups) : myIter (theGroups) {}
59 Standard_Boolean More() const { return myIter.More(); }
60 void Next() { myIter.Next(); }
61 const Group_t* Value() const { return (const Group_t* )(myIter.Value().get()); }
62 Group_t* ChangeValue() { return (Group_t* )(myIter.ChangeValue().get()); }
64 Graphic3d_SequenceOfGroup::Iterator myIter;
69 //! @return graphic driver created this structure
70 const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const
72 return myGraphicDriver;
75 //! @return graphic groups
76 const Graphic3d_SequenceOfGroup& Groups() const
81 //! Return transformation.
82 const Handle(TopLoc_Datum3D)& Transformation() const { return myTrsf; }
84 //! Assign transformation.
85 virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) { myTrsf = theTrsf; }
87 //! Return transformation persistence.
88 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; }
90 //! Set transformation persistence.
91 virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; }
93 //! @return associated clip planes
94 const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const
99 //! Pass clip planes to the associated graphic driver structure
100 void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) { myClipPlanes = thePlanes; }
102 //! @return bounding box of this presentation
103 const Graphic3d_BndBox3d& BoundingBox() const
108 //! @return bounding box of this presentation
109 //! without transformation matrix applied
110 Graphic3d_BndBox3d& ChangeBoundingBox()
115 //! Return structure visibility flag
116 bool IsVisible() const { return visible != 0; }
118 //! Return structure visibility considering both View Affinity and global visibility state.
119 bool IsVisible (const Standard_Integer theViewId) const
122 && (ViewAffinity.IsNull()
123 || ViewAffinity->IsVisible (theViewId));
126 //! Set z layer ID to display the structure in specified layer
127 virtual void SetZLayer (const Graphic3d_ZLayerId theLayerIndex) { myZLayer = theLayerIndex; }
130 Graphic3d_ZLayerId ZLayer() const { return myZLayer; }
132 //! Returns valid handle to highlight style of the structure in case if
133 //! highlight flag is set to true
134 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
138 //! Returns FALSE if the structure hits the current view volume, otherwise returns TRUE.
139 Standard_Boolean IsCulled() const { return myIsCulled; }
141 //! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here!
142 void SetCulled (Standard_Boolean theIsCulled) const { myIsCulled = theIsCulled; }
144 //! Marks structure as overlapping the current view volume one.
145 //! The method is called during traverse of BVH tree.
146 void MarkAsNotCulled() const { myIsCulled = Standard_False; }
148 //! Returns whether check of object's bounding box clipping is enabled before drawing of object; TRUE by default.
149 Standard_Boolean BndBoxClipCheck() const { return myBndBoxClipCheck; }
151 //! Enable/disable check of object's bounding box clipping before drawing of object.
152 void SetBndBoxClipCheck(Standard_Boolean theBndBoxClipCheck) { myBndBoxClipCheck = theBndBoxClipCheck; }
154 //! Checks if the structure should be included into BVH tree or not.
155 Standard_Boolean IsAlwaysRendered() const
161 || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
166 //! Update structure visibility state
167 virtual void OnVisibilityChanged() = 0;
169 //! Clear graphic data
170 virtual void Clear() = 0;
172 //! Connect other structure to this one
173 virtual void Connect (Graphic3d_CStructure& theStructure) = 0;
175 //! Disconnect other structure to this one
176 virtual void Disconnect (Graphic3d_CStructure& theStructure) = 0;
178 //! Highlights structure with the given style
179 virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) = 0;
181 //! Unhighlights the structure and invalidates pointer to structure's highlight
183 virtual void GraphicUnhighlight() = 0;
185 //! Create shadow link to this structure
186 virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const = 0;
188 //! Create new group within this structure
189 virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) = 0;
191 //! Remove group from this structure
192 virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) = 0;
194 //! Update render transformation matrix.
195 virtual void updateLayerTransformation() {}
197 //! Dumps the content of me into the stream
198 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
203 Graphic3d_ZLayerId myZLayer;
205 int PreviousPriority;
209 Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask
211 unsigned IsInfinite : 1;
212 unsigned stick : 1; //!< displaying state - should be set when structure has been added to scene graph (but can be in hidden state)
213 unsigned highlight : 1;
214 unsigned visible : 1; //!< visibility flag - can be used to suppress structure while leaving it in the scene graph
215 unsigned HLRValidation : 1;
216 unsigned IsForHighlight : 1;
217 unsigned IsMutable : 1;
218 unsigned Is2dText : 1;
222 //! Create empty structure.
223 Standard_EXPORT Graphic3d_CStructure (const Handle(Graphic3d_StructureManager)& theManager);
227 Handle(Graphic3d_GraphicDriver) myGraphicDriver;
228 Graphic3d_SequenceOfGroup myGroups;
229 Graphic3d_BndBox3d myBndBox;
230 Handle(TopLoc_Datum3D) myTrsf;
231 Handle(Graphic3d_TransformPers) myTrsfPers;
232 Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
233 Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //! Current highlight style; is set only if highlight flag is true
235 mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse
236 Standard_Boolean myBndBoxClipCheck; //!< Flag responsible for checking of bounding box clipping before drawing of object
240 DEFINE_STANDARD_RTTIEXT(Graphic3d_CStructure,Standard_Transient) // Type definition
244 DEFINE_STANDARD_HANDLE (Graphic3d_CStructure, Standard_Transient)
246 #endif // _Graphic3d_CStructure_HeaderFile