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)
109 if (!myCStructure.IsNull()) { myCStructure->IsInfinite = theToSet ? 1 : 0; }
112 //! Modifies the order of displaying the structure.
113 //! Values are between 0 and 10.
114 //! Structures are drawn according to their display priorities
115 //! in ascending order.
116 //! A structure of priority 10 is displayed the last and appears over the others.
117 //! The default value is 5.
118 //! Category: Methods to modify the class definition
119 //! Warning: If <me> is displayed then the SetDisplayPriority
120 //! method erase <me> and display <me> with the
122 //! Raises PriorityDefinitionError if <Priority> is
123 //! greater than 10 or a negative value.
124 Standard_EXPORT void SetDisplayPriority (const Standard_Integer Priority);
126 //! Reset the current priority of the structure to the
127 //! previous priority.
128 //! Category: Methods to modify the class definition
129 //! Warning: If <me> is displayed then the SetDisplayPriority
130 //! method erase <me> and display <me> with the
131 //! previous priority.
132 Standard_EXPORT void ResetDisplayPriority();
134 //! Set Z layer ID for the structure. The Z layer mechanism
135 //! allows to display structures presented in higher layers in overlay
136 //! of structures in lower layers by switching off z buffer depth
137 //! test between layers
138 Standard_EXPORT void SetZLayer (const Graphic3d_ZLayerId theLayerId);
140 //! Get Z layer ID of displayed structure.
141 //! The method returns -1 if the structure has no ID (deleted from graphic driver).
142 Graphic3d_ZLayerId GetZLayer() const { return myCStructure->ZLayer(); }
144 //! Changes a sequence of clip planes slicing the structure on rendering.
145 //! @param thePlanes [in] the set of clip planes.
146 void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes)
148 if (!myCStructure.IsNull()) { myCStructure->SetClipPlanes (thePlanes); }
151 //! Get clip planes slicing the structure on rendering.
152 //! @return set of clip planes.
153 const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const { return myCStructure->ClipPlanes(); }
155 //! Modifies the visibility indicator to Standard_True or
156 //! Standard_False for the structure <me>.
157 //! The default value at the definition of <me> is
159 Standard_EXPORT void SetVisible (const Standard_Boolean AValue);
161 //! Modifies the visualisation mode for the structure <me>.
162 Standard_EXPORT virtual void SetVisual (const Graphic3d_TypeOfStructure AVisual);
164 //! Modifies the minimum and maximum zoom coefficients
165 //! for the structure <me>.
166 //! The default value at the definition of <me> is unlimited.
167 //! Category: Methods to modify the class definition
168 //! Warning: Raises StructureDefinitionError if <LimitInf> is
169 //! greater than <LimitSup> or if <LimitInf> or
170 //! <LimitSup> is a negative value.
171 Standard_EXPORT void SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup);
173 //! Marks the structure <me> representing wired structure needed for highlight only so it won't be added to BVH tree.
174 void SetIsForHighlight (const Standard_Boolean isForHighlight)
176 if (!myCStructure.IsNull()) { myCStructure->IsForHighlight = isForHighlight; }
179 //! Suppresses the highlight for the structure <me>
180 //! in all the views of the visualiser.
181 Standard_EXPORT void UnHighlight();
183 virtual void Compute()
188 //! Returns the new Structure defined for the new visualization
189 virtual void computeHLR (const Handle(Graphic3d_Camera)& theProjector,
190 Handle(Graphic3d_Structure)& theStructure)
196 //! Forces a new construction of the structure <me>
197 //! if <me> is displayed and TOS_COMPUTED.
198 Standard_EXPORT void ReCompute();
200 //! Forces a new construction of the structure <me>
201 //! if <me> is displayed in <aProjetor> and TOS_COMPUTED.
202 Standard_EXPORT void ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector);
204 //! Returns Standard_True if the structure <me> contains
205 //! Polygons, Triangles or Quadrangles.
206 Standard_EXPORT Standard_Boolean ContainsFacet() const;
208 //! Returns the groups sequence included in this structure.
209 const Graphic3d_SequenceOfGroup& Groups() const { return myCStructure->Groups(); }
211 //! Returns the current number of groups in this structure.
212 Standard_Integer NumberOfGroups() const { return myCStructure->Groups().Length(); }
214 //! Append new group to this structure.
215 Standard_EXPORT Handle(Graphic3d_Group) NewGroup();
217 //! Returns the last created group or creates new one if list is empty.
218 Handle(Graphic3d_Group) CurrentGroup()
220 if (Groups().IsEmpty())
224 return Groups().Last();
227 //! Returns the highlight attributes.
228 const Handle(Graphic3d_PresentationAttributes)& HighlightStyle() const { return myCStructure->HighlightStyle(); }
230 //! Returns TRUE if this structure is deleted (after Remove() call).
231 Standard_Boolean IsDeleted() const { return myCStructure.IsNull(); }
233 //! Returns the display indicator for this structure.
234 virtual Standard_Boolean IsDisplayed() const
236 return !myCStructure.IsNull()
237 && myCStructure->stick != 0;
240 //! Returns Standard_True if the structure <me> is empty.
241 //! Warning: A structure is empty if :
242 //! it do not have group or all the groups are empties
243 //! and it do not have descendant or all the descendants
245 Standard_EXPORT Standard_Boolean IsEmpty() const;
247 //! Returns Standard_True if the structure <me> is infinite.
248 Standard_Boolean IsInfinite() const
251 || myCStructure->IsInfinite;
254 //! Returns the highlight indicator for this structure.
255 virtual Standard_Boolean IsHighlighted() const
257 return !myCStructure.IsNull()
258 && myCStructure->highlight != 0;
261 //! Returns TRUE if the structure is transformed.
262 Standard_Boolean IsTransformed() const
264 return !myCStructure.IsNull()
265 && !myCStructure->Transformation().IsNull()
266 && myCStructure->Transformation()->Form() != gp_Identity;
269 //! Returns the visibility indicator for this structure.
270 Standard_Boolean IsVisible() const
272 return !myCStructure.IsNull()
273 && myCStructure->visible != 0;
276 //! Returns the coordinates of the boundary box of the structure <me>.
277 //! If <theToIgnoreInfiniteFlag> is TRUE, the method returns actual graphical
278 //! boundaries of the Graphic3d_Group components. Otherwise, the
279 //! method returns boundaries taking into account infinite state
280 //! of the structure. This approach generally used for application
281 //! specific fit operation (e.g. fitting the model into screen,
282 //! not taking into accout infinite helper elements).
283 //! Warning: If the structure <me> is empty then the empty box is returned,
284 //! If the structure <me> is infinite then the whole box is returned.
285 Standard_EXPORT Bnd_Box MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
287 //! Returns the visualisation mode for the structure <me>.
288 Graphic3d_TypeOfStructure Visual() const { return myVisual; }
290 //! Returns Standard_True if the connection is possible between
291 //! <AStructure1> and <AStructure2> without a creation
294 //! It's not possible to call the method
295 //! AStructure1->Connect (AStructure2, TypeOfConnection)
297 //! - the set of all ancestors of <AStructure1> contains
298 //! <AStructure1> and if the
299 //! TypeOfConnection == TOC_DESCENDANT
300 //! - the set of all descendants of <AStructure1> contains
301 //! <AStructure2> and if the
302 //! TypeOfConnection == TOC_ANCESTOR
303 Standard_EXPORT static Standard_Boolean AcceptConnection (Graphic3d_Structure* theStructure1,
304 Graphic3d_Structure* theStructure2,
305 Graphic3d_TypeOfConnection theType);
307 //! Returns the group of structures to which <me> is connected.
308 Standard_EXPORT void Ancestors (Graphic3d_MapOfStructure& SG) const;
310 //! If Atype is TOC_DESCENDANT then add <AStructure>
311 //! as a child structure of <me>.
312 //! If Atype is TOC_ANCESTOR then add <AStructure>
313 //! as a parent structure of <me>.
314 //! The connection propagates Display, Highlight, Erase,
315 //! Remove, and stacks the transformations.
316 //! No connection if the graph of the structures
317 //! contains a cycle and <WithCheck> is Standard_True;
318 Standard_EXPORT void Connect (Graphic3d_Structure* theStructure,
319 Graphic3d_TypeOfConnection theType,
320 Standard_Boolean theWithCheck = Standard_False);
322 Standard_DEPRECATED("Deprecated short-cut")
323 void Connect (const Handle(Graphic3d_Structure)& thePrs)
325 Connect (thePrs.get(), Graphic3d_TOC_DESCENDANT);
328 //! Returns the group of structures connected to <me>.
329 Standard_EXPORT void Descendants (Graphic3d_MapOfStructure& SG) const;
331 //! Suppress the connection between <AStructure> and <me>.
332 Standard_EXPORT void Disconnect (Graphic3d_Structure* theStructure);
334 Standard_DEPRECATED("Deprecated alias for Disconnect()")
335 void Remove (const Handle(Graphic3d_Structure)& thePrs) { Disconnect (thePrs.get()); }
337 //! If Atype is TOC_DESCENDANT then suppress all
338 //! the connections with the child structures of <me>.
339 //! If Atype is TOC_ANCESTOR then suppress all
340 //! the connections with the parent structures of <me>.
341 Standard_EXPORT void DisconnectAll (const Graphic3d_TypeOfConnection AType);
343 Standard_DEPRECATED("Deprecated alias for DisconnectAll()")
344 void RemoveAll() { DisconnectAll (Graphic3d_TOC_DESCENDANT); }
346 //! Returns <ASet> the group of structures :
347 //! - directly or indirectly connected to <AStructure> if the
348 //! TypeOfConnection == TOC_DESCENDANT
349 //! - to which <AStructure> is directly or indirectly connected
350 //! if the TypeOfConnection == TOC_ANCESTOR
351 Standard_EXPORT static void Network (Graphic3d_Structure* theStructure,
352 const Graphic3d_TypeOfConnection theType,
353 NCollection_Map<Graphic3d_Structure*>& theSet);
355 void SetOwner (const Standard_Address theOwner) { myOwner = theOwner; }
357 Standard_Address Owner() const { return myOwner; }
359 void SetHLRValidation (const Standard_Boolean theFlag)
361 if (!myCStructure.IsNull()) { myCStructure->HLRValidation = theFlag ? 1 : 0; }
364 //! Hidden parts stored in this structure are valid if:
365 //! 1) the owner is defined.
366 //! 2) they are not invalid.
367 Standard_Boolean HLRValidation() const
369 return myOwner != NULL
370 && myCStructure->HLRValidation != 0;
373 //! Return local transformation.
374 const Handle(TopLoc_Datum3D)& Transformation() const { return myCStructure->Transformation(); }
376 //! Modifies the current local transformation
377 Standard_EXPORT void SetTransformation (const Handle(TopLoc_Datum3D)& theTrsf);
379 Standard_DEPRECATED("This method is deprecated - SetTransformation() should be called instead")
380 void Transform (const Handle(TopLoc_Datum3D)& theTrsf) { SetTransformation (theTrsf); }
382 //! Modifies the current transform persistence (pan, zoom or rotate)
383 Standard_EXPORT void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers);
385 //! @return transform persistence of the presentable object.
386 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myCStructure->TransformPersistence(); }
388 //! Sets if the structure location has mutable nature (content or location will be changed regularly).
389 void SetMutable (const Standard_Boolean theIsMutable)
391 if (!myCStructure.IsNull()) { myCStructure->IsMutable = theIsMutable; }
394 //! Returns true if structure has mutable nature (content or location are be changed regularly).
395 //! Mutable structure will be managed in different way than static onces.
396 Standard_Boolean IsMutable() const
398 return !myCStructure.IsNull()
399 && myCStructure->IsMutable;
402 Graphic3d_TypeOfStructure ComputeVisual() const { return myComputeVisual; }
404 //! Clears the structure <me>.
405 Standard_EXPORT void GraphicClear (const Standard_Boolean WithDestruction);
407 void GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter)
409 if (!myCStructure.IsNull()) { myCStructure->Connect (*theDaughter->myCStructure); }
412 void GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter)
414 if (!myCStructure.IsNull()) { myCStructure->Disconnect (*theDaughter->myCStructure); }
417 //! Internal method which sets new transformation without calling graphic manager callbacks.
418 void GraphicTransform (const Handle(TopLoc_Datum3D)& theTrsf)
420 if (!myCStructure.IsNull()) { myCStructure->SetTransformation (theTrsf); }
423 //! Returns the identification number of this structure.
424 Standard_Integer Identification() const { return myCStructure->Id; }
426 //! Prints informations about the network associated
427 //! with the structure <AStructure>.
428 Standard_EXPORT static void PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType);
430 //! Suppress the structure in the list of descendants or in the list of ancestors.
431 Standard_EXPORT void Remove (Graphic3d_Structure* thePtr,
432 const Graphic3d_TypeOfConnection theType);
434 void SetComputeVisual (const Graphic3d_TypeOfStructure theVisual)
436 // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING.
437 // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED.
438 if (theVisual != Graphic3d_TOS_COMPUTED)
440 myComputeVisual = theVisual;
444 //! Transforms theX, theY, theZ with the transformation theTrsf.
445 Standard_EXPORT static void Transforms (const gp_Trsf& theTrsf,
446 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
447 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ);
449 //! Returns the low-level structure
450 const Handle(Graphic3d_CStructure)& CStructure() const { return myCStructure; }
452 //! Dumps the content of me into the stream
453 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
457 //! Transforms boundaries with <theTrsf> transformation.
458 Standard_EXPORT static void TransformBoundaries (const gp_Trsf& theTrsf,
459 Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
460 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax);
462 //! Appends new descendant structure.
463 Standard_EXPORT Standard_Boolean AppendDescendant (Graphic3d_Structure* theDescendant);
465 //! Removes the given descendant structure.
466 Standard_EXPORT Standard_Boolean RemoveDescendant (Graphic3d_Structure* theDescendant);
468 //! Appends new ancestor structure.
469 Standard_EXPORT Standard_Boolean AppendAncestor (Graphic3d_Structure* theAncestor);
471 //! Removes the given ancestor structure.
472 Standard_EXPORT Standard_Boolean RemoveAncestor (Graphic3d_Structure* theAncestor);
474 //! Clears all the groups of primitives in the structure.
475 Standard_EXPORT void clear (const Standard_Boolean WithDestruction);
477 //! Erases this structure in all the views of the visualiser.
478 Standard_EXPORT void erase();
482 //! Suppress in the structure <me>, the group theGroup.
483 //! It will be erased at the next screen update.
484 Standard_EXPORT void Remove (const Handle(Graphic3d_Group)& theGroup);
486 //! Manages the number of groups in the structure <me>
487 //! which contains facet.
488 //! Polygons, Triangles or Quadrangles.
489 //! <ADelta> = +1 or -1
490 Standard_EXPORT void GroupsWithFacet (const Standard_Integer ADelta);
492 //! Returns the extreme coordinates found in the structure <me> without transformation applied.
493 Standard_EXPORT Graphic3d_BndBox4f minMaxCoord() const;
495 //! Gets untransformed bounding box from structure.
496 Standard_EXPORT void getBox (Graphic3d_BndBox3d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
498 //! Adds transformed (with myCStructure->Transformation) bounding box of structure to theBox.
499 Standard_EXPORT void addTransformed (Graphic3d_BndBox3d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
501 //! Returns the manager to which <me> is associated.
502 Standard_EXPORT Handle(Graphic3d_StructureManager) StructureManager() const;
504 //! Calls the Update method of the StructureManager which contains the Structure <me>.
505 //! If theUpdateLayer is true then invalidates bounding box of ZLayer.
506 Standard_EXPORT void Update (const bool theUpdateLayer = false) const;
510 Graphic3d_StructureManager* myStructureManager;
511 Handle(Graphic3d_CStructure) myCStructure;
512 NCollection_IndexedMap<Graphic3d_Structure*> myAncestors;
513 NCollection_IndexedMap<Graphic3d_Structure*> myDescendants;
514 Standard_Address myOwner;
515 Graphic3d_TypeOfStructure myVisual;
516 Graphic3d_TypeOfStructure myComputeVisual;
520 #endif // _Graphic3d_Structure_HeaderFile