0027919: Visualization - support multiple transformation persistence groups within...
[occt.git] / src / Graphic3d / Graphic3d_CStructure.hxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _Graphic3d_CStructure_HeaderFile
16 #define _Graphic3d_CStructure_HeaderFile
17
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_ViewAffinity.hxx>
24 #include <Graphic3d_TransformPers.hxx>
25 #include <Graphic3d_Vec3.hxx>
26 #include <Graphic3d_ZLayerId.hxx>
27 #include <TopLoc_Datum3D.hxx>
28 #include <NCollection_IndexedMap.hxx>
29
30 class Graphic3d_GraphicDriver;
31 class Graphic3d_StructureManager;
32
33 //! Low-level graphic structure interface
34 class Graphic3d_CStructure : public Standard_Transient
35 {
36   DEFINE_STANDARD_RTTIEXT(Graphic3d_CStructure, Standard_Transient)
37 protected:
38
39   //! Auxiliary wrapper to iterate through structure list.
40   template<class Struct_t>
41   class SubclassStructIterator
42   {
43   public:
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()); }
49   private:
50     NCollection_IndexedMap<const Graphic3d_CStructure*>::Iterator myIter;
51   };
52
53   //! Auxiliary wrapper to iterate through group sequence.
54   template<class Group_t>
55   class SubclassGroupIterator
56   {
57   public:
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()); }
63   private:
64     Graphic3d_SequenceOfGroup::Iterator myIter;
65   };
66
67 public:
68
69   //! @return graphic driver created this structure
70   const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const
71   {
72     return myGraphicDriver;
73   }
74
75   //! @return graphic groups
76   const Graphic3d_SequenceOfGroup& Groups() const
77   {
78     return myGroups;
79   }
80
81   //! Return transformation.
82   const Handle(TopLoc_Datum3D)& Transformation() const { return myTrsf; }
83
84   //! Assign transformation.
85   virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) { myTrsf = theTrsf; }
86
87   //! Return transformation persistence.
88   const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; }
89
90   //! Set transformation persistence.
91   virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; }
92
93   //! Return TRUE if some groups might have transform persistence; FALSE by default.
94   bool HasGroupTransformPersistence() const { return myHasGroupTrsf; }
95
96   //! Set if some groups might have transform persistence.
97   void SetGroupTransformPersistence (bool theValue) { myHasGroupTrsf = theValue; }
98
99   //! @return associated clip planes
100   const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const
101   {
102     return myClipPlanes;
103   }
104
105   //! Pass clip planes to the associated graphic driver structure
106   void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) { myClipPlanes = thePlanes; }
107
108   //! @return bounding box of this presentation
109   const Graphic3d_BndBox3d& BoundingBox() const
110   {
111     return myBndBox;
112   }
113
114   //! @return bounding box of this presentation
115   //! without transformation matrix applied
116   Graphic3d_BndBox3d& ChangeBoundingBox()
117   {
118     return myBndBox;
119   }
120
121   //! Return structure visibility flag
122   bool IsVisible() const { return visible != 0; }
123
124   //! Return structure visibility considering both View Affinity and global visibility state.
125   bool IsVisible (const Standard_Integer theViewId) const
126   {
127     return visible != 0
128         && (ViewAffinity.IsNull()
129          || ViewAffinity->IsVisible (theViewId));
130   }
131
132   //! Set z layer ID to display the structure in specified layer
133   virtual void SetZLayer (const Graphic3d_ZLayerId theLayerIndex) { myZLayer = theLayerIndex; }
134
135   //! Get z layer ID
136   Graphic3d_ZLayerId ZLayer() const { return myZLayer; }
137
138   //! Returns valid handle to highlight style of the structure in case if
139   //! highlight flag is set to true
140   const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; }
141
142 public:
143
144   //! Returns FALSE if the structure hits the current view volume, otherwise returns TRUE.
145   Standard_Boolean IsCulled() const { return myIsCulled; }
146
147   //! Marks structure as culled/not culled - note that IsAlwaysRendered() is ignored here!
148   void SetCulled (Standard_Boolean theIsCulled) const { myIsCulled = theIsCulled; }
149
150   //! Marks structure as overlapping the current view volume one.
151   //! The method is called during traverse of BVH tree.
152   void MarkAsNotCulled() const { myIsCulled = Standard_False; }
153
154   //! Returns whether check of object's bounding box clipping is enabled before drawing of object; TRUE by default.
155   Standard_Boolean BndBoxClipCheck() const { return myBndBoxClipCheck; }
156
157   //! Enable/disable check of object's bounding box clipping before drawing of object.
158   void SetBndBoxClipCheck(Standard_Boolean theBndBoxClipCheck) { myBndBoxClipCheck = theBndBoxClipCheck; }
159
160   //! Checks if the structure should be included into BVH tree or not.
161   Standard_Boolean IsAlwaysRendered() const
162   {
163     return IsInfinite
164         || IsForHighlight
165         || IsMutable
166         || Is2dText
167         || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d());
168   }
169
170 public:
171
172   //! Update structure visibility state
173   virtual void OnVisibilityChanged() = 0;
174
175   //! Clear graphic data
176   virtual void Clear() = 0;
177
178   //! Connect other structure to this one
179   virtual void Connect    (Graphic3d_CStructure& theStructure) = 0;
180
181   //! Disconnect other structure to this one
182   virtual void Disconnect (Graphic3d_CStructure& theStructure) = 0;
183
184   //! Highlights structure with the given style
185   virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) = 0;
186
187   //! Unhighlights the structure and invalidates pointer to structure's highlight
188   //! style
189   virtual void GraphicUnhighlight() = 0;
190
191   //! Create shadow link to this structure
192   virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const = 0;
193
194   //! Create new group within this structure
195   virtual Handle(Graphic3d_Group) NewGroup (const Handle(Graphic3d_Structure)& theStruct) = 0;
196
197   //! Remove group from this structure
198   virtual void RemoveGroup (const Handle(Graphic3d_Group)& theGroup) = 0;
199
200   //! Update render transformation matrix.
201   virtual void updateLayerTransformation() {}
202
203   //! Dumps the content of me into the stream
204   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
205
206 public:
207
208   Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask
209
210   Standard_Integer Id;
211   Standard_Integer Priority;
212   Standard_Integer PreviousPriority;
213
214   Standard_Integer ContainsFacet;
215
216 protected:
217
218   //! Create empty structure.
219   Standard_EXPORT Graphic3d_CStructure (const Handle(Graphic3d_StructureManager)& theManager);
220
221 protected:
222
223   Handle(Graphic3d_GraphicDriver) myGraphicDriver;
224   Graphic3d_SequenceOfGroup       myGroups;
225   Graphic3d_BndBox3d              myBndBox;
226   Handle(TopLoc_Datum3D)          myTrsf;
227   Handle(Graphic3d_TransformPers) myTrsfPers;
228   Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes;
229   Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //! Current highlight style; is set only if highlight flag is true
230
231   Graphic3d_ZLayerId myZLayer;
232
233   mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse
234   Standard_Boolean myBndBoxClipCheck;  //!< Flag responsible for checking of bounding box clipping before drawing of object
235
236   Standard_Boolean myHasGroupTrsf;     //!< flag specifying that some groups might have transform persistence
237
238 public:
239
240   unsigned IsInfinite     : 1;
241   unsigned stick          : 1; //!< displaying state - should be set when structure has been added to scene graph (but can be in hidden state)
242   unsigned highlight      : 1;
243   unsigned visible        : 1; //!< visibility flag - can be used to suppress structure while leaving it in the scene graph
244   unsigned HLRValidation  : 1;
245   unsigned IsForHighlight : 1;
246   unsigned IsMutable      : 1;
247   unsigned Is2dText       : 1;
248
249 };
250
251 DEFINE_STANDARD_HANDLE (Graphic3d_CStructure, Standard_Transient)
252
253 #endif // _Graphic3d_CStructure_HeaderFile