b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #ifndef _Graphic3d_CStructure_HeaderFile |
16 | #define _Graphic3d_CStructure_HeaderFile |
17 | |
7c3ef2f7 |
18 | #include <Graphic3d_BndBox3d.hxx> |
b64d84be |
19 | #include <Graphic3d_Group.hxx> |
f838dac4 |
20 | #include <Graphic3d_PresentationAttributes.hxx> |
b64d84be |
21 | #include <Graphic3d_SequenceOfGroup.hxx> |
51b10cd4 |
22 | #include <Graphic3d_SequenceOfHClipPlane.hxx> |
a272ed94 |
23 | #include <Graphic3d_ViewAffinity.hxx> |
825aa485 |
24 | #include <Graphic3d_TransformPers.hxx> |
63bcc448 |
25 | #include <Graphic3d_Vec3.hxx> |
a1954302 |
26 | #include <Graphic3d_ZLayerId.hxx> |
7f24b768 |
27 | #include <TopLoc_Datum3D.hxx> |
d325cb7f |
28 | #include <NCollection_IndexedMap.hxx> |
bf75be98 |
29 | |
c04c30b3 |
30 | class Graphic3d_GraphicDriver; |
31 | class Graphic3d_StructureManager; |
63bcc448 |
32 | |
33 | //! Low-level graphic structure interface |
34 | class Graphic3d_CStructure : public Standard_Transient |
bf75be98 |
35 | { |
4e993e4d |
36 | DEFINE_STANDARD_RTTIEXT(Graphic3d_CStructure, Standard_Transient) |
d325cb7f |
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 | }; |
bf75be98 |
66 | |
67 | public: |
68 | |
63bcc448 |
69 | //! @return graphic driver created this structure |
70 | const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const |
71 | { |
72 | return myGraphicDriver; |
73 | } |
74 | |
b64d84be |
75 | //! @return graphic groups |
76 | const Graphic3d_SequenceOfGroup& Groups() const |
77 | { |
78 | return myGroups; |
79 | } |
80 | |
1f7f5a90 |
81 | //! Return transformation. |
7f24b768 |
82 | const Handle(TopLoc_Datum3D)& Transformation() const { return myTrsf; } |
1f7f5a90 |
83 | |
84 | //! Assign transformation. |
7f24b768 |
85 | virtual void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf) { myTrsf = theTrsf; } |
1f7f5a90 |
86 | |
778cd667 |
87 | //! Return transformation persistence. |
88 | const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; } |
89 | |
90 | //! Set transformation persistence. |
7c3ef2f7 |
91 | virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; } |
778cd667 |
92 | |
4e993e4d |
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 | |
63bcc448 |
99 | //! @return associated clip planes |
3202bf1e |
100 | const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const |
63bcc448 |
101 | { |
102 | return myClipPlanes; |
103 | } |
104 | |
105 | //! Pass clip planes to the associated graphic driver structure |
3202bf1e |
106 | void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) { myClipPlanes = thePlanes; } |
63bcc448 |
107 | |
b7cd4ba7 |
108 | //! @return bounding box of this presentation |
7c3ef2f7 |
109 | const Graphic3d_BndBox3d& BoundingBox() const |
b7cd4ba7 |
110 | { |
111 | return myBndBox; |
112 | } |
113 | |
114 | //! @return bounding box of this presentation |
115 | //! without transformation matrix applied |
7c3ef2f7 |
116 | Graphic3d_BndBox3d& ChangeBoundingBox() |
b7cd4ba7 |
117 | { |
118 | return myBndBox; |
119 | } |
120 | |
a1954302 |
121 | //! Return structure visibility flag |
122 | bool IsVisible() const { return visible != 0; } |
123 | |
3fe9ce0e |
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 | |
a1954302 |
132 | //! Set z layer ID to display the structure in specified layer |
7c3ef2f7 |
133 | virtual void SetZLayer (const Graphic3d_ZLayerId theLayerIndex) { myZLayer = theLayerIndex; } |
a1954302 |
134 | |
135 | //! Get z layer ID |
136 | Graphic3d_ZLayerId ZLayer() const { return myZLayer; } |
137 | |
8e5fb5ea |
138 | //! Returns valid handle to highlight style of the structure in case if |
139 | //! highlight flag is set to true |
f838dac4 |
140 | const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myHighlightStyle; } |
8e5fb5ea |
141 | |
d325cb7f |
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 | |
8e6ce38c |
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 | |
d325cb7f |
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 | |
63bcc448 |
170 | public: |
171 | |
172 | //! Update structure visibility state |
a1954302 |
173 | virtual void OnVisibilityChanged() = 0; |
63bcc448 |
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 | |
8e5fb5ea |
184 | //! Highlights structure with the given style |
98b15dbf |
185 | virtual void GraphicHighlight (const Handle(Graphic3d_PresentationAttributes)& theStyle) = 0; |
63bcc448 |
186 | |
8e5fb5ea |
187 | //! Unhighlights the structure and invalidates pointer to structure's highlight |
188 | //! style |
189 | virtual void GraphicUnhighlight() = 0; |
63bcc448 |
190 | |
679ecdee |
191 | //! Create shadow link to this structure |
192 | virtual Handle(Graphic3d_CStructure) ShadowLink (const Handle(Graphic3d_StructureManager)& theManager) const = 0; |
193 | |
b64d84be |
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 | |
d325cb7f |
200 | //! Update render transformation matrix. |
201 | virtual void updateLayerTransformation() {} |
202 | |
bc73b006 |
203 | //! Dumps the content of me into the stream |
204 | Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; |
205 | |
63bcc448 |
206 | public: |
207 | |
a272ed94 |
208 | Handle(Graphic3d_ViewAffinity) ViewAffinity; //!< view affinity mask |
209 | |
4e993e4d |
210 | Standard_Integer Id; |
211 | Standard_Integer Priority; |
212 | Standard_Integer PreviousPriority; |
213 | |
214 | Standard_Integer ContainsFacet; |
bf75be98 |
215 | |
63bcc448 |
216 | protected: |
7fd59977 |
217 | |
63bcc448 |
218 | //! Create empty structure. |
219 | Standard_EXPORT Graphic3d_CStructure (const Handle(Graphic3d_StructureManager)& theManager); |
7fd59977 |
220 | |
63bcc448 |
221 | protected: |
222 | |
223 | Handle(Graphic3d_GraphicDriver) myGraphicDriver; |
b64d84be |
224 | Graphic3d_SequenceOfGroup myGroups; |
7c3ef2f7 |
225 | Graphic3d_BndBox3d myBndBox; |
7f24b768 |
226 | Handle(TopLoc_Datum3D) myTrsf; |
778cd667 |
227 | Handle(Graphic3d_TransformPers) myTrsfPers; |
3202bf1e |
228 | Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes; |
f838dac4 |
229 | Handle(Graphic3d_PresentationAttributes) myHighlightStyle; //! Current highlight style; is set only if highlight flag is true |
63bcc448 |
230 | |
4e993e4d |
231 | Graphic3d_ZLayerId myZLayer; |
232 | |
d325cb7f |
233 | mutable Standard_Boolean myIsCulled; //!< A status specifying is structure needs to be rendered after BVH tree traverse |
8e6ce38c |
234 | Standard_Boolean myBndBoxClipCheck; //!< Flag responsible for checking of bounding box clipping before drawing of object |
d325cb7f |
235 | |
4e993e4d |
236 | Standard_Boolean myHasGroupTrsf; //!< flag specifying that some groups might have transform persistence |
237 | |
63bcc448 |
238 | public: |
239 | |
4e993e4d |
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; |
63bcc448 |
248 | |
249 | }; |
7fd59977 |
250 | |
494782f6 |
251 | DEFINE_STANDARD_HANDLE (Graphic3d_CStructure, Standard_Transient) |
252 | |
63bcc448 |
253 | #endif // _Graphic3d_CStructure_HeaderFile |