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 <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <Graphic3d_CStructure.hxx>
24 #include <Graphic3d_IndexedMapOfAddress.hxx>
25 #include <Quantity_Color.hxx>
26 #include <Aspect_TypeOfHighlightMethod.hxx>
27 #include <Standard_Address.hxx>
28 #include <Graphic3d_TypeOfStructure.hxx>
29 #include <MMgt_TShared.hxx>
30 #include <Standard_Boolean.hxx>
31 #include <Standard_Integer.hxx>
32 #include <Graphic3d_ZLayerId.hxx>
33 #include <Graphic3d_SequenceOfHClipPlane.hxx>
34 #include <Standard_Real.hxx>
35 #include <Graphic3d_SequenceOfGroup.hxx>
36 #include <Graphic3d_TypeOfConnection.hxx>
37 #include <Graphic3d_MapOfStructure.hxx>
38 #include <Graphic3d_TypeOfComposition.hxx>
39 #include <Graphic3d_TransformPers.hxx>
40 #include <Graphic3d_TransModeFlags.hxx>
41 #include <Graphic3d_BndBox4f.hxx>
42 #include <Graphic3d_BndBox4d.hxx>
43 #include <Graphic3d_Vertex.hxx>
44 class Graphic3d_PriorityDefinitionError;
45 class Graphic3d_StructureDefinitionError;
46 class Graphic3d_TransformError;
47 class Graphic3d_Group;
48 class Graphic3d_StructureManager;
50 class Graphic3d_DataStructureManager;
53 class Graphic3d_Vector;
56 class Graphic3d_Structure;
57 DEFINE_STANDARD_HANDLE(Graphic3d_Structure, MMgt_TShared)
59 //! This class allows the definition a graphic object.
60 //! This graphic structure can be displayed,
61 //! erased, or highlighted.
62 //! This graphic structure can be connected with
63 //! another graphic structure.
64 //! Keywords: Structure, StructureManager, Display, Erase, Highlight,
65 //! UnHighlight, Visible, Priority, Selectable, Visible,
66 //! Visual, Connection, Ancestors, Descendants, Transformation
67 class Graphic3d_Structure : public MMgt_TShared
73 //! Creates a graphic object in the manager theManager.
74 //! It will appear in all the views of the visualiser.
75 //! The structure is not displayed when it is created.
76 Standard_EXPORT Graphic3d_Structure(const Handle(Graphic3d_StructureManager)& theManager);
78 //! Creates a shadow link to existing graphic object.
79 Standard_EXPORT Graphic3d_Structure(const Handle(Graphic3d_StructureManager)& theManager, const Handle(Graphic3d_Structure)& thePrs);
81 //! if WithDestruction == Standard_True then
82 //! suppress all the groups of primitives in the structure.
83 //! and it is mandatory to create a new group in <me>.
84 //! if WithDestruction == Standard_False then
85 //! clears all the groups of primitives in the structure.
86 //! and all the groups are conserved and empty.
87 //! They will be erased at the next screen update.
88 //! The structure itself is conserved.
89 //! The transformation and the attributes of <me> are conserved.
90 //! The childs of <me> are conserved.
91 Standard_EXPORT virtual void Clear (const Standard_Boolean WithDestruction = Standard_True);
93 //! Suppresses the structure <me>.
94 //! It will be erased at the next screen update.
95 Standard_EXPORT ~Graphic3d_Structure();
97 //! Displays the structure <me> in all the views of the visualiser.
98 Standard_EXPORT virtual void Display();
100 //! Returns the current display priority for the
102 Standard_EXPORT Standard_Integer DisplayPriority() const;
104 //! Erases the structure <me> in all the views
105 //! of the visualiser.
106 Standard_EXPORT virtual void Erase();
108 //! Highlights the structure <me> in all the views of the visualiser, using the following methods:
109 //! TOHM_COLOR = drawn in the highlight color
110 //! TOHM_BOUNDBOX = enclosed by the boundary box
111 Standard_EXPORT void Highlight (const Aspect_TypeOfHighlightMethod theMethod, const Quantity_Color& theColor, const Standard_Boolean theToUpdateMgr = Standard_True);
113 //! Suppress the structure <me>.
114 //! It will be erased at the next screen update.
115 //! Warning: No more graphic operations in <me> after this call.
116 //! Category: Methods to modify the class definition
117 Standard_EXPORT void Remove();
119 //! Computes axis-aligned bounding box of a structure.
120 Standard_EXPORT virtual void CalculateBoundBox();
122 //! If <theToSet> is Standard_True then <me> is infinite and
123 //! the MinMaxValues method method return :
124 //! theXMin = theYMin = theZMin = RealFirst().
125 //! theXMax = theYMax = theZMax = RealLast().
126 //! By default, <me> is not infinite but empty.
127 Standard_EXPORT void SetInfiniteState (const Standard_Boolean theToSet);
129 //! Modifies the order of displaying the structure.
130 //! Values are between 0 and 10.
131 //! Structures are drawn according to their display priorities
132 //! in ascending order.
133 //! A structure of priority 10 is displayed the last and appears over the others.
134 //! The default value is 5.
135 //! Category: Methods to modify the class definition
136 //! Warning: If <me> is displayed then the SetDisplayPriority
137 //! method erase <me> and display <me> with the
139 //! Raises PriorityDefinitionError if <Priority> is
140 //! greater than 10 or a negative value.
141 Standard_EXPORT void SetDisplayPriority (const Standard_Integer Priority);
143 //! Reset the current priority of the structure to the
144 //! previous priority.
145 //! Category: Methods to modify the class definition
146 //! Warning: If <me> is displayed then the SetDisplayPriority
147 //! method erase <me> and display <me> with the
148 //! previous priority.
149 Standard_EXPORT void ResetDisplayPriority();
151 //! Set Z layer ID for the structure. The Z layer mechanism
152 //! allows to display structures presented in higher layers in overlay
153 //! of structures in lower layers by switching off z buffer depth
154 //! test between layers
155 Standard_EXPORT void SetZLayer (const Graphic3d_ZLayerId theLayerId);
157 //! Get Z layer ID of displayed structure. The method
158 //! returns -1 if the structure has no ID (deleted from graphic driver).
159 Standard_EXPORT Graphic3d_ZLayerId GetZLayer() const;
161 //! Changes a sequence of clip planes slicing the structure on rendering.
162 //! @param thePlanes [in] the set of clip planes.
163 Standard_EXPORT void SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes);
165 //! Get clip planes slicing the structure on rendering.
166 //! @return set of clip planes.
167 Standard_EXPORT const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const;
169 //! Modifies the visibility indicator to Standard_True or
170 //! Standard_False for the structure <me>.
171 //! The default value at the definition of <me> is
173 Standard_EXPORT void SetVisible (const Standard_Boolean AValue);
175 //! Modifies the visualisation mode for the structure <me>.
176 Standard_EXPORT virtual void SetVisual (const Graphic3d_TypeOfStructure AVisual);
178 //! Modifies the minimum and maximum zoom coefficients
179 //! for the structure <me>.
180 //! The default value at the definition of <me> is unlimited.
181 //! Category: Methods to modify the class definition
182 //! Warning: Raises StructureDefinitionError if <LimitInf> is
183 //! greater than <LimitSup> or if <LimitInf> or
184 //! <LimitSup> is a negative value.
185 Standard_EXPORT void SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup);
187 //! marks the structure <me> representing wired structure needed for
188 //! highlight only so it won't be added to BVH tree.
189 //! Category: Methods to modify the class definition
190 Standard_EXPORT void SetIsForHighlight (const Standard_Boolean isForHighlight);
192 //! Suppresses the highlight for the structure <me>
193 //! in all the views of the visualiser.
194 Standard_EXPORT void UnHighlight();
196 Standard_EXPORT virtual void Compute();
198 //! Returns the new Structure defined for the new visualization
199 Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& aProjector);
201 //! Returns the new Structure defined for the new visualization
202 Standard_EXPORT virtual Handle(Graphic3d_Structure) Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
203 const Handle(Geom_Transformation)& theTrsf);
205 //! Returns the new Structure defined for the new visualization
206 Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& aProjector, Handle(Graphic3d_Structure)& aStructure);
208 //! Returns the new Structure defined for the new visualization
209 Standard_EXPORT virtual void Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
210 const Handle(Geom_Transformation)& theTrsf,
211 Handle(Graphic3d_Structure)& theStructure);
213 //! Forces a new construction of the structure <me>
214 //! if <me> is displayed and TOS_COMPUTED.
215 Standard_EXPORT void ReCompute();
217 //! Forces a new construction of the structure <me>
218 //! if <me> is displayed in <aProjetor> and TOS_COMPUTED.
219 Standard_EXPORT void ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector);
221 //! Returns Standard_True if the structure <me> contains
222 //! Polygons, Triangles or Quadrangles.
223 Standard_EXPORT Standard_Boolean ContainsFacet() const;
225 //! Returns the groups sequence included in the structure <me> (internal storage).
226 Standard_EXPORT const Graphic3d_SequenceOfGroup& Groups() const;
228 //! Returns the current number of groups in the
230 Standard_EXPORT Standard_Integer NumberOfGroups() const;
232 //! Append new group to this structure.
233 Standard_EXPORT Handle(Graphic3d_Group) NewGroup();
235 //! Returns the highlight color for the Highlight method
236 //! with the highlight method TOHM_COLOR or TOHM_BOUNDBOX.
237 Standard_EXPORT const Quantity_Color& HighlightColor() const;
239 //! Returns Standard_True if the structure <me> is deleted.
240 //! <me> is deleted after the call Remove (me).
241 Standard_EXPORT Standard_Boolean IsDeleted() const;
243 //! Returns the display indicator for the structure <me>.
244 Standard_EXPORT virtual Standard_Boolean IsDisplayed() const;
246 //! Returns Standard_True if the structure <me> is empty.
247 //! Warning: A structure is empty if :
248 //! it do not have group or all the groups are empties
249 //! and it do not have descendant or all the descendants
251 Standard_EXPORT Standard_Boolean IsEmpty() const;
253 //! Returns Standard_True if the structure <me> is infinite.
254 Standard_EXPORT Standard_Boolean IsInfinite() const;
256 //! Returns the highlight indicator for the structure <me>.
257 Standard_EXPORT virtual Standard_Boolean IsHighlighted() const;
259 //! Returns Standard_True if the structure <me> is transformed.
260 //! <=> The transformation != Identity.
261 Standard_EXPORT Standard_Boolean IsTransformed() const;
263 //! Returns the visibility indicator for the structure <me>.
264 Standard_EXPORT Standard_Boolean IsVisible() const;
266 //! Returns the coordinates of the boundary box of the structure <me>.
267 //! If <theToIgnoreInfiniteFlag> is TRUE, the method returns actual graphical
268 //! boundaries of the Graphic3d_Group components. Otherwise, the
269 //! method returns boundaries taking into account infinite state
270 //! of the structure. This approach generally used for application
271 //! specific fit operation (e.g. fitting the model into screen,
272 //! not taking into accout infinite helper elements).
273 //! Warning: If the structure <me> is empty then the empty box is returned,
274 //! If the structure <me> is infinite then the whole box is returned.
275 Standard_EXPORT Bnd_Box MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
277 //! Returns the visualisation mode for the structure <me>.
278 Standard_EXPORT Graphic3d_TypeOfStructure Visual() const;
280 //! Returns Standard_True if the connection is possible between
281 //! <AStructure1> and <AStructure2> without a creation
284 //! It's not possible to call the method
285 //! AStructure1->Connect (AStructure2, TypeOfConnection)
287 //! - the set of all ancestors of <AStructure1> contains
288 //! <AStructure1> and if the
289 //! TypeOfConnection == TOC_DESCENDANT
290 //! - the set of all descendants of <AStructure1> contains
291 //! <AStructure2> and if the
292 //! TypeOfConnection == TOC_ANCESTOR
293 Standard_EXPORT static Standard_Boolean AcceptConnection (const Handle(Graphic3d_Structure)& AStructure1, const Handle(Graphic3d_Structure)& AStructure2, const Graphic3d_TypeOfConnection AType);
295 //! Returns the group of structures to which <me> is connected.
296 Standard_EXPORT void Ancestors (Graphic3d_MapOfStructure& SG) const;
298 //! If Atype is TOC_DESCENDANT then add <AStructure>
299 //! as a child structure of <me>.
300 //! If Atype is TOC_ANCESTOR then add <AStructure>
301 //! as a parent structure of <me>.
302 //! The connection propagates Display, Highlight, Erase,
303 //! Remove, and stacks the transformations.
304 //! No connection if the graph of the structures
305 //! contains a cycle and <WithCheck> is Standard_True;
306 Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, const Standard_Boolean WithCheck = Standard_False);
308 //! Returns the group of structures connected to <me>.
309 Standard_EXPORT void Descendants (Graphic3d_MapOfStructure& SG) const;
311 //! Suppress the connection between <AStructure> and <me>.
312 Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& AStructure);
314 //! If Atype is TOC_DESCENDANT then suppress all
315 //! the connections with the child structures of <me>.
316 //! If Atype is TOC_ANCESTOR then suppress all
317 //! the connections with the parent structures of <me>.
318 Standard_EXPORT void DisconnectAll (const Graphic3d_TypeOfConnection AType);
320 //! Returns <ASet> the group of structures :
321 //! - directly or indirectly connected to <AStructure> if the
322 //! TypeOfConnection == TOC_DESCENDANT
323 //! - to which <AStructure> is directly or indirectly connected
324 //! if the TypeOfConnection == TOC_ANCESTOR
325 Standard_EXPORT static void Network (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, Graphic3d_MapOfStructure& ASet);
327 Standard_EXPORT void SetOwner (const Standard_Address Owner);
329 Standard_EXPORT Standard_Address Owner() const;
331 Standard_EXPORT void SetHLRValidation (const Standard_Boolean AFlag);
333 Standard_EXPORT Standard_Boolean HLRValidation() const;
335 //! Return local transformation.
336 const Handle(Geom_Transformation)& Transformation() const { return myCStructure->Transformation(); }
338 //! Modifies the current local transformation
339 Standard_EXPORT void SetTransformation (const Handle(Geom_Transformation)& theTrsf);
341 Standard_DEPRECATED("This method is deprecated - SetTransformation() should be called instead")
342 void Transform (const Handle(Geom_Transformation)& theTrsf) { SetTransformation (theTrsf); }
344 //! Modifies the current transform persistence (pan, zoom or rotate)
345 Standard_EXPORT void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers);
347 //! @return transform persistence of the presentable object.
348 const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myCStructure->TransformPersistence(); }
350 //! Sets if the structure location has mutable nature (content or location will be changed regularly).
351 Standard_EXPORT void SetMutable (const Standard_Boolean theIsMutable);
353 //! Returns true if structure has mutable nature (content or location are be changed regularly).
354 //! Mutable structure will be managed in different way than static onces.
355 Standard_EXPORT Standard_Boolean IsMutable() const;
357 Standard_EXPORT Graphic3d_TypeOfStructure ComputeVisual() const;
359 //! Clears the structure <me>.
360 Standard_EXPORT void GraphicClear (const Standard_Boolean WithDestruction);
362 Standard_EXPORT void GraphicConnect (const Handle(Graphic3d_Structure)& ADaughter);
364 Standard_EXPORT void GraphicDisconnect (const Handle(Graphic3d_Structure)& ADaughter);
366 //! Highlights the structure <me>.
367 Standard_EXPORT void GraphicHighlight (const Aspect_TypeOfHighlightMethod Method);
369 //! Internal method which sets new transformation without calling graphic manager callbacks.
370 Standard_EXPORT void GraphicTransform (const Handle(Geom_Transformation)& theTrsf);
372 //! Suppress the highlight for the structure <me>.
373 Standard_EXPORT void GraphicUnHighlight();
375 //! Returns the identification number of the structure <me>.
376 Standard_EXPORT Standard_Integer Identification() const;
378 //! Prints informations about the network associated
379 //! with the structure <AStructure>.
380 Standard_EXPORT static void PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType);
382 //! Suppress the adress <APtr> in the list
383 //! of descendants or in the list of ancestors.
384 Standard_EXPORT void Remove (const Standard_Address APtr, const Graphic3d_TypeOfConnection AType);
386 Standard_EXPORT void SetComputeVisual (const Graphic3d_TypeOfStructure AVisual);
388 //! Transforms theX, theY, theZ with the transformation theTrsf.
389 Standard_EXPORT static void Transforms (const gp_Trsf& theTrsf,
390 const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
391 Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ);
393 //! Returns the low-level structure
394 const Handle(Graphic3d_CStructure)& CStructure() const { return myCStructure; }
396 friend class Graphic3d_Group;
399 DEFINE_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared)
403 //! Transforms boundaries with <theTrsf> transformation.
404 Standard_EXPORT static void TransformBoundaries (const gp_Trsf& theTrsf,
405 Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
406 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax);
408 //! Appends new descendant structure.
409 Standard_EXPORT Standard_Boolean AppendDescendant (const Standard_Address theDescendant);
411 //! Removes the given descendant structure.
412 Standard_EXPORT Standard_Boolean RemoveDescendant (const Standard_Address theDescendant);
414 //! Appends new ancestor structure.
415 Standard_EXPORT Standard_Boolean AppendAncestor (const Standard_Address theAncestor);
417 //! Removes the given ancestor structure.
418 Standard_EXPORT Standard_Boolean RemoveAncestor (const Standard_Address theAncestor);
422 //! Suppress in the structure <me>, the group theGroup.
423 //! It will be erased at the next screen update.
424 Standard_EXPORT void Remove (const Handle(Graphic3d_Group)& theGroup);
426 //! Manages the number of groups in the structure <me>
427 //! which contains facet.
428 //! Polygons, Triangles or Quadrangles.
429 //! <ADelta> = +1 or -1
430 Standard_EXPORT void GroupsWithFacet (const Standard_Integer ADelta);
432 //! Returns the extreme coordinates found in the structure <me> without transformation applied.
433 Standard_EXPORT Graphic3d_BndBox4f minMaxCoord() const;
435 //! Gets untransformed bounding box from structure.
436 Standard_EXPORT void getBox (Graphic3d_BndBox4d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
438 //! Adds transformed (with myCStructure->Transformation) bounding box of structure to theBox.
439 Standard_EXPORT void addTransformed (Graphic3d_BndBox4d& theBox, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const;
441 //! Returns the manager to which <me> is associated.
442 Standard_EXPORT Handle(Graphic3d_StructureManager) StructureManager() const;
444 //! Calls the Update method of the StructureManager which contains the Structure <me>.
445 //! If theUpdateLayer is true then invalidates bounding box of ZLayer.
446 Standard_EXPORT void Update (const bool theUpdateLayer = false) const;
450 Graphic3d_StructureManager* myStructureManager;
451 Graphic3d_StructureManager* myFirstStructureManager;
452 Graphic3d_TypeOfStructure myComputeVisual;
454 Handle(Graphic3d_CStructure) myCStructure;
455 Graphic3d_IndexedMapOfAddress myAncestors;
456 Graphic3d_IndexedMapOfAddress myDescendants;
457 Quantity_Color myHighlightColor;
458 Aspect_TypeOfHighlightMethod myHighlightMethod;
459 Standard_Address myOwner;
460 Graphic3d_TypeOfStructure myVisual;
464 #endif // _Graphic3d_Structure_HeaderFile