1 // Created on: 1991-06-12
2 // Created by: NW,JPB,CAL
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Graphic3d_Structure_HeaderFile
18 #define _Graphic3d_Structure_HeaderFile
20 #include <Graphic3d_BndBox4f.hxx>
21 #include <Graphic3d_BndBox4d.hxx>
22 #include <Graphic3d_CStructure.hxx>
23 #include <Graphic3d_MapOfStructure.hxx>
24 #include <Graphic3d_SequenceOfGroup.hxx>
25 #include <Graphic3d_SequenceOfHClipPlane.hxx>
26 #include <Graphic3d_TypeOfComposition.hxx>
27 #include <Graphic3d_TypeOfConnection.hxx>
28 #include <Graphic3d_TypeOfStructure.hxx>
29 #include <Graphic3d_TransformPers.hxx>
30 #include <Graphic3d_TransModeFlags.hxx>
31 #include <Graphic3d_Vertex.hxx>
32 #include <Graphic3d_ZLayerId.hxx>
33 #include <NCollection_IndexedMap.hxx>
35 class Graphic3d_StructureManager;
36 class Graphic3d_DataStructureManager;
40 DEFINE_STANDARD_HANDLE(Graphic3d_Structure, Standard_Transient)
42 //! This class allows the definition a graphic object.
43 //! This graphic structure can be displayed, erased, or highlighted.
44 //! This graphic structure can be connected with another graphic structure.
45 class Graphic3d_Structure : public Standard_Transient
47 DEFINE_STANDARD_RTTIEXT(Graphic3d_Structure, Standard_Transient)
48 friend class Graphic3d_Group;
51 //! Creates a graphic object in the manager theManager.
52 //! It will appear in all the views of the visualiser.
53 //! The structure is not displayed when it is created.
54 //! @param theManager structure manager holding this structure
55 //! @param theLinkPrs another structure for creating a shadow (linked) structure
56 Standard_EXPORT Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager,
57 const Handle(Graphic3d_Structure)& theLinkPrs = Handle(Graphic3d_Structure)());
59 //! if WithDestruction == Standard_True then
60 //! suppress all the groups of primitives in the structure.
61 //! and it is mandatory to create a new group in <me>.
62 //! if WithDestruction == Standard_False then
63 //! clears all the groups of primitives in the structure.
64 //! and all the groups are conserved and empty.
65 //! They will be erased at the next screen update.
66 //! The structure itself is conserved.
67 //! The transformation and the attributes of <me> are conserved.
68 //! The childs of <me> are conserved.
69 virtual void Clear (const Standard_Boolean WithDestruction = Standard_True)
71 clear (WithDestruction);
74 //! Suppresses the structure <me>.
75 //! It will be erased at the next screen update.
76 Standard_EXPORT virtual ~Graphic3d_Structure();
78 //! Displays the structure <me> in all the views of the visualiser.
79 Standard_EXPORT virtual void Display();
81 //! Returns the current display priority for this structure.
82 Standard_Integer DisplayPriority() const { return myCStructure->Priority; }
84 //! Erases this structure in all the views of the visualiser.
85 virtual void Erase() { erase(); }
87 //! Highlights the structure in all the views with the given style
88 //! @param theStyle [in] the style (type of highlighting: box/color, color and opacity)
89 //! @param theToUpdateMgr [in] defines whether related computed structures will be
90 //! highlighted via structure manager or not
91 Standard_EXPORT void Highlight (const Handle(Graphic3d_PresentationAttributes)& theStyle, const Standard_Boolean theToUpdateMgr = Standard_True);
93 //! Suppress the structure <me>.
94 //! It will be erased at the next screen update.
95 //! Warning: No more graphic operations in <me> after this call.
96 //! Category: Methods to modify the class definition
97 Standard_EXPORT void Remove();
99 //! Computes axis-aligned bounding box of a structure.
100 Standard_EXPORT virtual void CalculateBoundBox();
102 //! Sets infinite flag.
103 //! When TRUE, the MinMaxValues method returns:
104 //! theXMin = theYMin = theZMin = RealFirst().
105 //! theXMax = theYMax = theZMax = RealLast().
106 //! By default, structure is created not infinite but empty.
107 void SetInfiniteState (const Standard_Boolean theToSet) { myCStructure->IsInfinite = theToSet ? 1 : 0; }
109 //! Modifies the order of displaying the structure.
110 //! Values are between 0 and 10.
111 //! Structures are drawn according to their display priorities
112 //! in ascending order.
113 //! A structure of priority 10 is displayed the last and appears over the others.
114 //! The default value is 5.
115 //! Category: Methods to modify the class definition
116 //! Warning: If <me> is displayed then the SetDisplayPriority
117 //! method erase <me> and display <me> with the
119 //! Raises PriorityDefinitionError if <Priority> is
120 //! greater than 10 or a negative value.
121 Standard_EXPORT void SetDisplayPriority (const Standard_Integer Priority);
123 //! Reset the current priority of the structure to the
124 //! previous priority.
125 //! Category: Methods to modify the class definition
126 //! Warning: If <me> is displayed then the SetDisplayPriority
127 //! method erase <me> and display <me> with the
128 //! previous priority.
129 Standard_EXPORT void ResetDisplayPriority();
131 //! Set Z layer ID for the structure. The Z layer mechanism
132 //! allows to display structures presented in higher layers in overlay
133 //! of structures in lower layers by switching off z buffer depth
134 //! test between layers
135 Standard_EXPORT void SetZLayer (const Graphic3d_ZLayerId theLayerId);
137 //! Get Z layer ID of displayed structure.
138 //! The method returns -1 if the structure has no ID (deleted from graphic driver).
139 Graphic3d_ZLayerId GetZLayer() const { return myCStructure->ZLayer(); }
141 //! Changes a sequence of clip planes slicing the structure on rendering.
142 //! @param thePlanes [in] the set of clip planes.
143 void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) { myCStructure->SetClipPlanes (thePlanes); }
145 //! Get clip planes slicing the structure on rendering.
146 //! @return set of clip planes.
147 const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const { return myCStructure->ClipPlanes(); }
149 //! Modifies the visibility indicator to Standard_True or
150 //! Standard_False for the structure <me>.
151 //! The default value at the definition of <me> is
153 Standard_EXPORT void SetVisible (const Standard_Boolean AValue);
155 //! Modifies the visualisation mode for the structure <me>.
156 Standard_EXPORT virtual void SetVisual (const Graphic3d_TypeOfStructure AVisual);
158 //! Modifies the minimum and maximum zoom coefficients
159 //! for the structure <me>.
160 //! The default value at the definition of <me> is unlimited.
161 //! Category: Methods to modify the class definition
162 //! Warning: Raises StructureDefinitionError if <LimitInf> is
163 //! greater than <LimitSup> or if <LimitInf> or
164 //! <LimitSup> is a negative value.
165 Standard_EXPORT void SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup);
167 //! Marks the structure <me> representing wired structure needed for highlight only so it won't be added to BVH tree.
168 void SetIsForHighlight (const Standard_Boolean isForHighlight) { myCStructure->IsForHighlight = isForHighlight; }
170 //! Suppresses the highlight for the structure <me>
171 //! in all the views of the visualiser.
172 Standard_EXPORT void UnHighlight();
174 virtual void Compute()
179 //! Returns the new Structure defined for the new visualization
180 virtual void computeHLR (const Handle(Graphic3d_Camera)& theProjector,
181 Handle(Graphic3d_Structure)& theStructure)
187 //! Forces a new construction of the structure <me>
188 //! if <me> is displayed and TOS_COMPUTED.
189 Standard_EXPORT void ReCompute();
191 //! Forces a new construction of the structure <me>
192 //! if <me> is displayed in <aProjetor> and TOS_COMPUTED.
193 Standard_EXPORT void ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector);
195 //! Returns Standard_True if the structure <me> contains
196 //! Polygons, Triangles or Quadrangles.
197 Standard_EXPORT Standard_Boolean ContainsFacet() const;
199 //! Returns the groups sequence included in this structure.
200 const Graphic3d_SequenceOfGroup& Groups() const { return myCStructure->Groups(); }
202 //! Returns the current number of groups in this structure.
203 Standard_Integer NumberOfGroups() const { return myCStructure->Groups().Length(); }
205 //! Append new group to this structure.
206 Standard_EXPORT Handle(Graphic3d_Group) NewGroup();
208 //! Returns the last created group or creates new one if list is empty.
209 Handle(Graphic3d_Group) CurrentGroup()
211 if (Groups().IsEmpty())
215 return Groups().Last();
218 //! Returns the highlight attributes.
219 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myCStructure->HighlightStyle(); }
221 //! Returns TRUE if this structure is deleted (after Remove() call).
222 Standard_Boolean IsDeleted() const { return myCStructure.IsNull(); }
224 //! Returns the display indicator for this structure.
225 virtual Standard_Boolean IsDisplayed() const { return myCStructure->stick != 0; }
227 //! Returns Standard_True if the structure <me> is empty.
228 //! Warning: A structure is empty if :
229 //! it do not have group or all the groups are empties
230 //! and it do not have descendant or all the descendants
232 Standard_EXPORT Standard_Boolean IsEmpty() const;
234 //! Returns Standard_True if the structure <me> is infinite.
235 Standard_Boolean IsInfinite() const
238 || myCStructure->IsInfinite;
241 //! Returns the highlight indicator for this structure.
242 virtual Standard_Boolean IsHighlighted() const { return myCStructure->highlight != 0; }
244 //! Returns TRUE if the structure is transformed.
245 Standard_Boolean IsTransformed() const
247 return !myCStructure->Transformation().IsNull()
248 && myCStructure->Transformation()->Form() != gp_Identity;
251 //! Returns the visibility indicator for this structure.
252 Standard_Boolean IsVisible() const { return myCStructure->visible != 0; }
254 //! Returns the coordinates of the boundary box of the structure <me>.
255 //! If <theToIgnoreInfiniteFlag> is TRUE, the method returns actual graphical
256 //! boundaries of the Graphic3d_Group components. Otherwise, the
257 //! method returns boundaries taking into account infinite state
258 //! of the structure. This approach generally used for application
259 //! specific fit operation (e.g. fitting the model into screen,
260 //! not taking into accout infinite helper elements).
261 //! Warning: If the structure <me> is empty then the empty box is returned,
262 //! If the structure <me> is infinite then the whole box is returned.
263 Standard_EXPORT Bnd_Box MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
265 //! Returns the visualisation mode for the structure <me>.
266 Graphic3d_TypeOfStructure Visual() const { return myVisual; }
268 //! Returns Standard_True if the connection is possible between
269 //! <AStructure1> and <AStructure2> without a creation
272 //! It's not possible to call the method
273 //! AStructure1->Connect (AStructure2, TypeOfConnection)
275 //! - the set of all ancestors of <AStructure1> contains
276 //! <AStructure1> and if the
277 //! TypeOfConnection == TOC_DESCENDANT
278 //! - the set of all descendants of <AStructure1> contains
279 //! <AStructure2> and if the
280 //! TypeOfConnection == TOC_ANCESTOR
281 Standard_EXPORT static Standard_Boolean AcceptConnection (Graphic3d_Structure* theStructure1,
282 Graphic3d_Structure* theStructure2,
283 Graphic3d_TypeOfConnection theType);
285 //! Returns the group of structures to which <me> is connected.
286 Standard_EXPORT void Ancestors (Graphic3d_MapOfStructure& SG) const;
288 //! If Atype is TOC_DESCENDANT then add <AStructure>
289 //! as a child structure of <me>.
290 //! If Atype is TOC_ANCESTOR then add <AStructure>
291 //! as a parent structure of <me>.
292 //! The connection propagates Display, Highlight, Erase,
293 //! Remove, and stacks the transformations.
294 //! No connection if the graph of the structures
295 //! contains a cycle and <WithCheck> is Standard_True;
296 Standard_EXPORT void Connect (Graphic3d_Structure* theStructure,
297 Graphic3d_TypeOfConnection theType,
298 Standard_Boolean theWithCheck = Standard_False);
300 Standard_DEPRECATED("Deprecated short-cut")
301 void Connect (const Handle(Graphic3d_Structure)& thePrs)
303 Connect (thePrs.get(), Graphic3d_TOC_DESCENDANT);
306 //! Returns the group of structures connected to <me>.
307 Standard_EXPORT void Descendants (Graphic3d_MapOfStructure& SG) const;
309 //! Suppress the connection between <AStructure> and <me>.
310 Standard_EXPORT void Disconnect (Graphic3d_Structure* theStructure);
312 Standard_DEPRECATED("Deprecated alias for Disconnect()")
313 void Remove (const Handle(Graphic3d_Structure)& thePrs) { Disconnect (thePrs.get()); }
315 //! If Atype is TOC_DESCENDANT then suppress all
316 //! the connections with the child structures of <me>.
317 //! If Atype is TOC_ANCESTOR then suppress all
318 //! the connections with the parent structures of <me>.
319 Standard_EXPORT void DisconnectAll (const Graphic3d_TypeOfConnection AType);
321 Standard_DEPRECATED("Deprecated alias for DisconnectAll()")
322 void RemoveAll() { DisconnectAll (Graphic3d_TOC_DESCENDANT); }
324 //! Returns <ASet> the group of structures :
325 //! - directly or indirectly connected to <AStructure> if the
326 //! TypeOfConnection == TOC_DESCENDANT
327 //! - to which <AStructure> is directly or indirectly connected
328 //! if the TypeOfConnection == TOC_ANCESTOR
329 Standard_EXPORT static void Network (Graphic3d_Structure* theStructure,
330 const Graphic3d_TypeOfConnection theType,
331 NCollection_Map<Graphic3d_Structure*>& theSet);
333 void SetOwner (const Standard_Address theOwner) { myOwner = theOwner; }
335 Standard_Address Owner() const { return myOwner; }
337 void SetHLRValidation (const Standard_Boolean theFlag) { myCStructure->HLRValidation = theFlag ? 1 : 0; }
339 //! Hidden parts stored in this structure are valid if:
340 //! 1) the owner is defined.
341 //! 2) they are not invalid.
342 Standard_Boolean HLRValidation() const
344 return myOwner != NULL
345 && myCStructure->HLRValidation != 0;
348 //! Return local transformation.
349 const Handle(TopLoc_Datum3D)& Transformation() const { return myCStructure->Transformation(); }
351 //! Modifies the current local transformation
352 Standard_EXPORT void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf);
354 Standard_DEPRECATED("This method is deprecated - SetTransformation() should be called instead")
355 void Transform (const Handle(TopLoc_Datum3D)& theTrsf) { SetTransformation (theTrsf); }
357 //! Modifies the current transform persistence (pan, zoom or rotate)
358 Standard_EXPORT void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers);
360 //! @return transform persistence of the presentable object.
361 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myCStructure->TransformPersistence(); }
363 //! Sets if the structure location has mutable nature (content or location will be changed regularly).
364 void SetMutable (const Standard_Boolean theIsMutable) { myCStructure->IsMutable = theIsMutable; }
366 //! Returns true if structure has mutable nature (content or location are be changed regularly).
367 //! Mutable structure will be managed in different way than static onces.
368 Standard_Boolean IsMutable() const { return myCStructure->IsMutable; }
370 Graphic3d_TypeOfStructure ComputeVisual() const { return myComputeVisual; }
372 //! Clears the structure <me>.
373 Standard_EXPORT void GraphicClear (const Standard_Boolean WithDestruction);
375 void GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter) { myCStructure->Connect (*theDaughter->myCStructure); }
377 void GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter) { myCStructure->Disconnect (*theDaughter->myCStructure); }
379 //! Internal method which sets new transformation without calling graphic manager callbacks.
380 void GraphicTransform (const Handle(TopLoc_Datum3D)& theTrsf) { myCStructure->SetTransformation (theTrsf); }
382 //! Returns the identification number of this structure.
383 Standard_Integer Identification() const { return myCStructure->Id; }
385 //! Prints informations about the network associated
386 //! with the structure <AStructure>.
387 Standard_EXPORT static void PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType);
389 //! Suppress the structure in the list of descendants or in the list of ancestors.
390 Standard_EXPORT void Remove (Graphic3d_Structure* thePtr,
391 const Graphic3d_TypeOfConnection theType);
393 void SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
395 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
396 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
397 if (theVisual != Graphic3d_TOS_COMPUTED)
399 myComputeVisual = theVisual;
403 //! Transforms theX, theY, theZ with the transformation theTrsf.
404 Standard_EXPORT static void Transforms (const gp_Trsf& theTrsf,
405 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
406 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ);
408 //! Returns the low-level structure
409 const Handle(Graphic3d_CStructure)& CStructure() const { return myCStructure; }
411 //! Dumps the content of me into the stream
412 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
416 //! Transforms boundaries with <theTrsf> transformation.
417 Standard_EXPORT static void TransformBoundaries (const gp_Trsf& theTrsf,
418 Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
419 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax);
421 //! Appends new descendant structure.
422 Standard_EXPORT Standard_Boolean AppendDescendant (Graphic3d_Structure* theDescendant);
424 //! Removes the given descendant structure.
425 Standard_EXPORT Standard_Boolean RemoveDescendant (Graphic3d_Structure* theDescendant);
427 //! Appends new ancestor structure.
428 Standard_EXPORT Standard_Boolean AppendAncestor (Graphic3d_Structure* theAncestor);
430 //! Removes the given ancestor structure.
431 Standard_EXPORT Standard_Boolean RemoveAncestor (Graphic3d_Structure* theAncestor);
433 //! Clears all the groups of primitives in the structure.
434 Standard_EXPORT void clear (const Standard_Boolean WithDestruction);
436 //! Erases this structure in all the views of the visualiser.
437 Standard_EXPORT void erase();
441 //! Suppress in the structure <me>, the group theGroup.
442 //! It will be erased at the next screen update.
443 Standard_EXPORT void Remove (const Handle(Graphic3d_Group)& theGroup);
445 //! Manages the number of groups in the structure <me>
446 //! which contains facet.
447 //! Polygons, Triangles or Quadrangles.
448 //! <ADelta> = +1 or -1
449 Standard_EXPORT void GroupsWithFacet (const Standard_Integer ADelta);
451 //! Returns the extreme coordinates found in the structure <me> without transformation applied.
452 Standard_EXPORT Graphic3d_BndBox4f minMaxCoord() const;
454 //! Gets untransformed bounding box from structure.
455 Standard_EXPORT void getBox (Graphic3d_BndBox3d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
457 //! Adds transformed (with myCStructure->Transformation) bounding box of structure to theBox.
458 Standard_EXPORT void addTransformed (Graphic3d_BndBox3d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
460 //! Returns the manager to which <me> is associated.
461 Standard_EXPORT Handle(Graphic3d_StructureManager) StructureManager() const;
463 //! Calls the Update method of the StructureManager which contains the Structure <me>.
464 //! If theUpdateLayer is true then invalidates bounding box of ZLayer.
465 Standard_EXPORT void Update (const bool theUpdateLayer = false) const;
469 Graphic3d_StructureManager* myStructureManager;
470 Handle(Graphic3d_CStructure) myCStructure;
471 NCollection_IndexedMap<Graphic3d_Structure*> myAncestors;
472 NCollection_IndexedMap<Graphic3d_Structure*> myDescendants;
473 Standard_Address myOwner;
474 Graphic3d_TypeOfStructure myVisual;
475 Graphic3d_TypeOfStructure myComputeVisual;
479 #endif // _Graphic3d_Structure_HeaderFile