1 -- Created on: 2000-06-15
2 -- Created by: Edward AGAPOV
3 -- Copyright (c) 2000-2014 OPEN CASCADE SAS
5 -- This file is part of Open CASCADE Technology software library.
7 -- This library is free software; you can redistribute it and/or modify it under
8 -- the terms of the GNU Lesser General Public License version 2.1 as published
9 -- by the Free Software Foundation, with special exception defined in the file
10 -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 -- distribution for complete text of the license and disclaimer of any warranty.
13 -- Alternatively, this file may be used under the terms of Open CASCADE
14 -- commercial license or contractual agreement.
16 class ShapeTool from XCAFDoc inherits Attribute from TDF
18 ---Purpose: A tool to store shapes in an XDE
19 -- document in the form of assembly structure, and to maintain this structure.
20 -- Attribute containing Shapes section of DECAF document.
21 -- Provide tools for management of Shapes section.
22 -- The API provided by this class allows to work with this
23 -- structure regardless of its low-level implementation.
24 -- All the shapes are stored on child labels of a main label which is
25 -- XCAFDoc_DocumentTool::LabelShapes(). The label for assembly also has
26 -- sub-labels, each of which represents the instance of
27 -- another shape in that assembly (component). Such sub-label
28 -- stores reference to the label of the original shape in the form
29 -- of TDataStd_TreeNode with GUID XCAFDoc::ShapeRefGUID(), and its
30 -- location encapsulated into the NamedShape.
31 -- For correct work with an XDE document, it is necessary to use
32 -- methods for analysis and methods for working with shapes.
34 -- if ( STool->IsAssembly(aLabel) )
35 -- { Standard_Boolean subchilds = Standard_False; (default)
36 -- Standard_Integer nbc = STool->NbComponents
37 -- (aLabel[,subchilds]);
39 -- If subchilds is True, commands also consider sub-levels. By
40 -- default, only level one is checked.
41 -- In this example, number of children from the first level of
42 -- assembly will be returned. Methods for creation and initialization:
44 -- XCAFDoc_ShapeTool::XCAFDoc_ShapeTool()
46 -- Standard_GUID GetID ();
47 -- Creation (if does not exist) of ShapeTool on label L:
48 -- Handle(XCAFDoc_ShapeTool) XCAFDoc_ShapeTool::Set(const TDF_Label& L)
49 -- Analyze whether shape is a simple shape or an instance or a
50 -- component of an assembly or it is an assembly ( methods of analysis).
52 -- STool->IsShape(aLabel) ;
53 -- Analyze that the label represents a shape (simple
54 -- shape, assembly or reference) or
55 -- STool->IsTopLevel(aLabel);
56 -- Analyze that the label is a label of a top-level shape.
57 -- Work with simple shapes, assemblies and instances (
58 -- methods for work with shapes).
61 -- Standard_Boolean makeAssembly;
62 -- // True to interpret a Compound as an Assembly, False to take it
64 -- aLabel = STool->AddShape(aShape, makeAssembly);
66 -- TDF_Label aLabel...
67 -- // A label must be present if
68 -- (aLabel.IsNull()) { ... no such label : abandon .. }
69 -- TopoDS_Shape aShape;
70 -- aShape = STool->GetShape(aLabel);
71 -- if (aShape.IsNull())
72 -- { ... this label is not for a Shape ... }
73 -- To get a label from shape.
74 -- Standard_Boolean findInstance = Standard_False;
75 -- (this is default value)
76 -- aLabel = STool->FindShape(aShape [,findInstance]);
77 -- if (aLabel.IsNull())
78 -- { ... no label found for this shape ... }
81 Document from TDocStd,
82 TreeNode from TDataStd,
85 LabelSequence from TDF,
88 SequenceOfShape from TopTools,
89 HAsciiString from TCollection,
90 RelocationTable from TDF,
91 SequenceOfHAsciiString from TColStd,
92 GraphNode from XCAFDoc,
93 AttributeSequence from TDF,
94 DataMapOfShapeLabel from XCAFDoc
98 ---C++: return const &
99 returns GUID from Standard;
102 Set (myclass; L : Label from TDF) returns ShapeTool from XCAFDoc;
103 ---Purpose: Create (if not exist) ShapeTool from XCAFDoc on <L>.
108 Create returns ShapeTool from XCAFDoc;
109 ---Purpose: Creates an empty tool
111 --Create (Doc: Document from TDocStd) returns ShapeTool from XCAFDoc;
112 ---Purpose: Creates a tool to work with a document <Doc>
113 -- Attaches to label XCAFDoc::LabelShapes()
119 IsTopLevel (me; L: Label from TDF) returns Boolean;
120 ---Purpose: Returns True if the label is a label of top-level shape,
121 -- as opposed to component of assembly or subshape
123 IsFree (myclass; L: Label from TDF) returns Boolean;
124 ---Purpose: Returns True if the label is not used by any assembly, i.e.
125 -- contains sublabels which are assembly components
126 -- This is relevant only if IsShape() is True
127 -- (There is no Father TreeNode on this <L>)
129 IsShape (myclass; L: Label from TDF) returns Boolean;
130 ---Purpose: Returns True if the label represents a shape (simple shape,
131 -- assembly or reference)
133 IsSimpleShape (myclass; L: Label from TDF) returns Boolean;
134 ---Purpose: Returns True if the label is a label of simple shape
136 IsReference (myclass; L: Label from TDF) returns Boolean;
137 ---Purpose: Return true if <L> is a located instance of other shape
140 IsAssembly (myclass; L: Label from TDF) returns Boolean;
141 ---Purpose: Returns True if the label is a label of assembly, i.e.
142 -- contains sublabels which are assembly components
143 -- This is relevant only if IsShape() is True
145 IsComponent (myclass; L: Label from TDF) returns Boolean;
146 ---Purpose: Return true if <L> is reference serving as component
149 IsCompound (myclass; L: Label from TDF) returns Boolean;
150 ---Purpose: Returns True if the label is a label of compound, i.e.
151 -- contains some sublabels
152 -- This is relevant only if IsShape() is True
154 IsSubShape (myclass; L: Label from TDF) returns Boolean;
155 ---Purpose: Return true if <L> is subshape of the top-level shape
157 IsSubShape (me; shapeL: Label from TDF;
158 sub: Shape from TopoDS)
160 ---Purpose: Checks whether shape <sub> is subshape of shape stored on
163 ---API: Work with top-level structure of shapes
165 SearchUsingMap (me; S: Shape from TopoDS; L: out Label from TDF;
166 findWithoutLoc: Boolean; findSubshape: Boolean)
167 returns Boolean from Standard;
169 Search (me; S: Shape from TopoDS; L: out Label from TDF;
170 findInstance: Boolean = Standard_True;
171 findComponent: Boolean = Standard_True;
172 findSubshape: Boolean = Standard_True)
173 returns Boolean from Standard;
174 ---Purpose: General tool to find a (sub) shape in the document
175 -- * If findInstance is True, and S has a non-null location,
176 -- first tries to find the shape among the top-level shapes
177 -- with this location
178 -- * If not found, and findComponent is True, tries to find the shape
179 -- among the components of assemblies
180 -- * If not found, tries to find the shape without location
181 -- among top-level shapes
182 -- * If not found and findSubshape is True, tries to find a
183 -- shape as a subshape of top-level simple shapes
184 -- Returns False if nothing is found
186 FindShape (me; S: Shape from TopoDS; L: out Label from TDF;
187 findInstance: Boolean = Standard_False)
188 returns Boolean from Standard;
189 ---Purpose: Returns the label corresponding to shape S
190 -- (searches among top-level shapes, not including subcomponents
192 -- If findInstance is False (default), searches for the
193 -- non-located shape (i.e. among original shapes)
194 -- If findInstance is True, searches for the shape with the same
195 -- location, including shape instances
196 -- Return True if <S> is found.
198 FindShape (me; S: Shape from TopoDS;
199 findInstance: Boolean = Standard_False)
200 returns Label from TDF;
201 ---Purpose: Does the same as previous method
202 -- Returns Null label if not found
204 GetShape (myclass; L: Label from TDF;
205 S: out Shape from TopoDS) returns Boolean from Standard;
206 ---Purpose: To get TopoDS_Shape from shape's label
207 -- For component, returns new shape with correct location
208 -- Returns False if label does not contain shape
210 GetShape (myclass; L: Label from TDF) returns Shape from TopoDS;
211 ---Purpose: To get TopoDS_Shape from shape's label
212 -- For component, returns new shape with correct location
213 -- Returns Null shape if label does not contain shape
215 NewShape (me) returns Label from TDF;
216 ---Purpose: Creates new (empty) top-level shape.
217 -- Initially it holds empty TopoDS_Compound
219 SetShape (me:mutable; L: Label from TDF; S: Shape from TopoDS);
220 ---Purpose: Sets representation (TopoDS_Shape) for top-level shape
222 AddShape (me:mutable; S: Shape from TopoDS;
223 makeAssembly: Boolean = Standard_True;
224 makePrepare : Boolean = Standard_True)
225 returns Label from TDF;
226 ---Purpose: Adds a new top-level (creates and returns a new label)
227 -- If makeAssembly is True, treats TopAbs_COMPOUND shapes
228 -- as assemblies (creates assembly structure).
229 -- NOTE: <makePrepare> replace components without location
230 -- in assmebly by located components to avoid some problems.
231 -- If AutoNaming() is True then automatically attaches names.
233 addShape (me:mutable; S: Shape from TopoDS;
234 makeAssembly: Boolean = Standard_True)
235 returns Label from TDF is private;
236 ---Purpose: Adds a new top-level (creates and returns a new label)
237 -- For internal use. Used by public method AddShape.
239 RemoveShape (me; L: Label from TDF;
240 removeCompletely: Boolean = Standard_True)
242 ---Purpose: Removes shape (whole label and all its sublabels)
243 -- If removeCompletely is true, removes complete shape
244 -- If removeCompletely is false, removes instance(location) only
245 -- Returns False (and does nothing) if shape is not free
246 -- or is not top-level shape
249 ---Purpose: set hasComponents into false
251 SetAutoNaming (myclass; V: Boolean);
252 ---Purpose: Sets auto-naming mode to <V>. If True then for added
253 -- shapes, links, assemblies and SHUO's, the TDataStd_Name attribute
254 -- is automatically added. For shapes it contains a shape type
255 -- (e.g. "SOLID", "SHELL", etc); for links it has a form
256 -- "=>[0:1:1:2]" (where a tag is a label containing a shape
257 -- without a location); for assemblies it is "ASSEMBLY", and
258 -- "SHUO" for SHUO's.
259 -- This setting is global; it cannot be made a member function
260 -- as it is used by static methods as well.
261 -- By default, auto-naming is enabled.
262 -- See also AutoNaming().
264 AutoNaming (myclass) returns Boolean;
265 ---Purpose: Returns current auto-naming mode. See SetAutoNaming() for
268 ComputeShapes (me: mutable; L: Label from TDF);
269 ---Purpose: recursive
271 ComputeSimpleShapes (me: mutable);
272 ---Purpose: Compute a sequence of simple shapes
274 GetShapes (me; Labels: out LabelSequence from TDF);
275 ---Purpose: Returns a sequence of all top-level shapes
277 GetFreeShapes (me; FreeLabels : out LabelSequence from TDF);
278 ---Purpose: Returns a sequence of all top-level shapes
279 -- which are free (i.e. not referred by any other)
281 GetUsers (myclass; L: Label from TDF;
282 Labels : out LabelSequence from TDF;
283 getsubchilds: Boolean from Standard = Standard_False)
285 ---Purpose: Returns list of labels which refer shape L as component
286 -- Returns number of users (0 if shape is free)
288 GetLocation (myclass; L: Label from TDF)
289 returns Location from TopLoc;
290 ---Purpose: Returns location of instance
292 GetReferredShape (myclass; L: Label from TDF;
293 Label: out Label from TDF)
295 ---Purpose: Returns label which corresponds to a shape referred by L
296 -- Returns False if label is not reference
298 ---API: Work with assembly structure
300 NbComponents (myclass; L: Label from TDF;
301 getsubchilds: Boolean from Standard = Standard_False)
303 ---Purpose: Returns number of Assembles components
305 GetComponents (myclass; L: Label from TDF;
306 Labels : out LabelSequence from TDF;
307 getsubchilds: Boolean from Standard = Standard_False)
309 ---Purpose: Returns list of components of assembly
310 -- Returns False if label is not assembly
312 AddComponent (me; assembly, comp: Label from TDF;
313 Loc: Location from TopLoc)
314 returns Label from TDF;
315 ---Purpose: Adds a component given by its label and location to the assembly
316 -- Note: assembly must be IsAssembly() or IsSimpleShape()
318 AddComponent (me:mutable; assembly: Label from TDF;
319 comp: Shape from TopoDS; expand: Boolean = Standard_False)
320 returns Label from TDF;
321 ---Purpose: Adds a shape (located) as a component to the assembly
322 -- If necessary, creates an additional top-level shape for
323 -- component and return the Label of component.
324 -- If expand is True and component is Compound, it will
325 -- be created as assembly also
326 -- Note: assembly must be IsAssembly() or IsSimpleShape()
328 RemoveComponent (me; comp: Label from TDF);
329 ---Purpose: Removes a component from its assembly
331 UpdateAssembly (me; L: Label from TDF);
332 ---Purpose: Update an assembly at label <L>
334 ---API: work with sub-shapes of shape
336 FindSubShape (me; shapeL: Label from TDF;
337 sub: Shape from TopoDS;
338 L: out Label from TDF)
340 ---Purpose: Finds a label for subshape <sub> of shape stored on
342 -- Returns Null label if it is not found
344 AddSubShape (me; shapeL: Label from TDF;
345 sub: Shape from TopoDS)
346 returns Label from TDF;
347 ---Purpose: Adds a label for subshape <sub> of shape stored on
349 -- Returns Null label if it is not subshape
351 FindMainShapeUsingMap (me; sub: Shape from TopoDS)
352 returns Label from TDF;
354 FindMainShape (me; sub: Shape from TopoDS)
355 returns Label from TDF;
356 ---Purpose: Performs a search among top-level shapes to find
357 -- the shape containing <sub> as subshape
358 -- Checks only simple shapes, and returns the first found
359 -- label (which should be the only one for valid model)
361 GetSubShapes (myclass; L: Label from TDF;
362 Labels : out LabelSequence from TDF)
364 ---Purpose: Returns list of labels identifying subshapes of the given shape
365 -- Returns False if no subshapes are placed on that label
369 BaseLabel(me) returns Label from TDF;
370 ---Purpose: returns the label under which shapes are stored
372 Dump(me; deep : Boolean from Standard = Standard_False);
374 DumpShape(myclass; L: Label from TDF;
375 level :Integer from Standard = 0;
376 deep : Boolean from Standard = Standard_False);
377 ---Purpose: Print in cout type of shape found on <L> label
378 -- and the entry of <L>, with <level> tabs before.
379 -- If <deep>, print also TShape and Location addresses
383 MakeReference (myclass; L, refL: Label from TDF; loc: Location from TopLoc)
385 ---Purpose: Makes a shape on label L to be a reference to shape refL
389 ---Category: TDF_Attribute methods
390 -- =====================
393 ---C++: return const &
394 returns GUID from Standard;
396 Restore (me: mutable; with : Attribute from TDF);
399 returns Attribute from TDF;
401 Paste (me; into : Attribute from TDF;
402 RT : RelocationTable from TDF);
404 IsExternRef (myclass; L: Label from TDF) returns Boolean;
405 ---Purpose: Returns True if the label is a label of external references, i.e.
406 -- there are some reference on the no-step files, which are
407 -- described in document only their names
409 SetExternRefs (me; SHAS: SequenceOfHAsciiString from TColStd) returns Label from TDF;
410 ---Purpose: Sets the names of references on the no-step files
412 SetExternRefs (me; L: Label from TDF; SHAS: SequenceOfHAsciiString from TColStd);
413 ---Purpose: Sets the names of references on the no-step files
415 GetExternRefs (myclass; L: Label from TDF; SHAS: in out SequenceOfHAsciiString from TColStd);
416 ---Purpose: Gets the names of references on the no-step files
418 ---API: Work with SHUO (Specified Higher Usage Occurrance) structure
420 SetSHUO (me; Labels : LabelSequence from TDF;
421 MainSHUOAttr : in out GraphNode from XCAFDoc)
423 ---Purpose: Sets the SHUO structure between upper_usage and next_usage
424 -- create multy-level (if number of labels > 2) SHUO from first to last
425 -- Initialise out <MainSHUOAttr> by main upper_usage SHUO attribute.
426 -- Returns FALSE if some of labels in not component label
428 GetSHUO (myclass; SHUOLabel : Label from TDF;
429 aSHUOAttr : in out GraphNode from XCAFDoc)
431 ---Purpose: Returns founded SHUO GraphNode attribute <aSHUOAttr>
432 -- Returns false in other case
434 GetAllComponentSHUO (myclass; CompLabel : Label from TDF;
435 SHUOAttrs : in out AttributeSequence from TDF)
437 ---Purpose: Returns founded SHUO GraphNodes of indicated component
438 -- Returns false in other case
440 GetSHUOUpperUsage (myclass; NextUsageL: Label from TDF;
441 Labels : out LabelSequence from TDF)
443 ---Purpose: Returns the sequence of labels of SHUO attributes,
444 -- which is upper_usage for this next_usage SHUO attribute
445 -- (that indicated by label)
446 -- NOTE: returns upper_usages only on one level (not recurse)
447 -- NOTE: do not clear the sequence before filling
449 GetSHUONextUsage (myclass; UpperUsageL: Label from TDF;
450 Labels : out LabelSequence from TDF)
452 ---Purpose: Returns the sequence of labels of SHUO attributes,
453 -- which is next_usage for this upper_usage SHUO attribute
454 -- (that indicated by label)
455 -- NOTE: returns next_usages only on one level (not recurse)
456 -- NOTE: do not clear the sequence before filling
458 RemoveSHUO (me; SHUOLabel : Label from TDF)
460 ---Purpose: Remove SHUO from component sublabel,
461 -- remove all dependencies on other SHUO.
462 -- Returns FALSE if cannot remove SHUO dependencies.
463 -- NOTE: remove any styles that associated with this SHUO.
465 FindComponent (me; theShape : Shape from TopoDS;
466 Labels : out LabelSequence from TDF)
468 ---Purpose: Serach the path of labels in the document,
469 -- that corresponds the component from any assembly
470 -- Try to search the sequence of labels with location that
471 -- produce this shape as component of any assembly
472 -- NOTE: Clear sequence of labels before filling
474 GetSHUOInstance (me; theSHUO : GraphNode from XCAFDoc)
475 returns Shape from TopoDS;
476 ---Purpose: Search for the component shape that styled by shuo
477 -- Returns null shape if no any shape is found.
479 SetInstanceSHUO (me; theShape : Shape from TopoDS)
480 returns GraphNode from XCAFDoc;
481 ---Purpose: Search for the component shape by labelks path
482 -- and set SHUO structure for founded label structure
483 -- Returns null attribute if no component in any assembly found.
485 GetAllSHUOInstances (me; theSHUO : GraphNode from XCAFDoc;
486 theSHUOShapeSeq : in out SequenceOfShape from TopTools)
487 returns Boolean from Standard;
488 ---Purpose: Seaching for component shapes that styled by shuo
489 -- Returns empty sequence of shape if no any shape is found.
491 FindSHUO (myclass; Labels : LabelSequence from TDF;
492 theSHUOAttr : in out GraphNode from XCAFDoc)
493 returns Boolean from Standard;
494 ---Purpose: Searchs the SHUO by labels of components
495 -- from upper_usage componet to next_usage
496 -- Returns null attribute if no SHUO found
499 myShapeLabels : DataMapOfShapeLabel from XCAFDoc; --skl 15.10.2003
500 mySubShapes : DataMapOfShapeLabel from XCAFDoc;
501 mySimpleShapes : DataMapOfShapeLabel from XCAFDoc;
502 hasSimpleShapes : Boolean from Standard;