0023047: Behaviour of XDE sample is non-stable
[occt.git] / src / XCAFDoc / XCAFDoc_ShapeTool.cdl
CommitLineData
b311480e 1-- Created on: 2000-06-15
2-- Created by: Edward AGAPOV
3-- Copyright (c) 2000-2012 OPEN CASCADE SAS
4--
5-- The content of this file is subject to the Open CASCADE Technology Public
6-- License Version 6.5 (the "License"). You may not use the content of this file
7-- except in compliance with the License. Please obtain a copy of the License
8-- at http://www.opencascade.org and read it completely before using this file.
9--
10-- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11-- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12--
13-- The Original Code and all software distributed under the License is
14-- distributed on an "AS IS" basis, without warranty of any kind, and the
15-- Initial Developer hereby disclaims all such warranties, including without
16-- limitation, any warranties of merchantability, fitness for a particular
17-- purpose or non-infringement. Please see the License for the specific terms
18-- and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22class ShapeTool from XCAFDoc inherits Attribute from TDF
23
24 ---Purpose: A tool to store shapes in an XDE
25-- document in the form of assembly structure, and to maintain this structure.
26-- The API provided by this class allows to work with this
27-- structure regardless of its low-level implementation.
28-- All the shapes are stored on child labels of a main label which is
29-- XCAFDoc_DocumentTool::LabelShapes(). The label for assembly also has
30-- sub-labels, each of which represents the instance of
31-- another shape in that assembly (component). Such sub-label
32-- stores reference to the label of the original shape in the form
33-- of TDataStd_TreeNode with GUID XCAFDoc::ShapeRefGUID(), and its
34-- location encapsulated into the NamedShape.
35-- For correct work with an XDE document, it is necessary to use
36-- methods for analysis and methods for working with shapes.
37-- For example:
38-- if ( STool->IsAssembly(aLabel) )
39-- { Standard_Boolean subchilds = Standard_False; (default)
40-- Standard_Integer nbc = STool->NbComponents
41-- (aLabel[,subchilds]);
42-- }
43-- If subchilds is True, commands also consider sub-levels. By
44-- default, only level one is checked.
45-- In this example, number of children from the first level of
46-- assembly will be returned. Methods for creation and initialization:
47-- Constructor:
48-- XCAFDoc_ShapeTool::XCAFDoc_ShapeTool()
49-- Getting a guid:
50-- Standard_GUID GetID ();
51-- Creation (if does not exist) of ShapeTool on label L:
52-- Handle(XCAFDoc_ShapeTool) XCAFDoc_ShapeTool::Set(const TDF_Label& L)
53-- Analyze whether shape is a simple shape or an instance or a
54-- component of an assembly or it is an assembly ( methods of analysis).
55-- For example:
56-- STool->IsShape(aLabel) ;
57-- Analyze that the label represents a shape (simple
58-- shape, assembly or reference) or
59-- STool->IsTopLevel(aLabel);
60-- Analyze that the label is a label of a top-level shape.
61-- Work with simple shapes, assemblies and instances (
62-- methods for work with shapes).
63-- For example:
64-- Add shape:
65-- Standard_Boolean makeAssembly;
66-- // True to interpret a Compound as an Assembly, False to take it
67-- as a whole
68-- aLabel = STool->AddShape(aShape, makeAssembly);
69-- Get shape:
70-- TDF_Label aLabel...
71-- // A label must be present if
72-- (aLabel.IsNull()) { ... no such label : abandon .. }
73-- TopoDS_Shape aShape;
74-- aShape = STool->GetShape(aLabel);
75-- if (aShape.IsNull())
76-- { ... this label is not for a Shape ... }
77-- To get a label from shape.
78-- Standard_Boolean findInstance = Standard_False;
79-- (this is default value)
80-- aLabel = STool->FindShape(aShape [,findInstance]);
81-- if (aLabel.IsNull())
82-- { ... no label found for this shape ... }
83
84uses
85 Document from TDocStd,
86 TreeNode from TDataStd,
87 Location from TopLoc,
88 Label from TDF,
89 LabelSequence from TDF,
90 LabelMap from TDF,
91 Shape from TopoDS,
92 SequenceOfShape from TopTools,
93 HAsciiString from TCollection,
94 RelocationTable from TDF,
95 SequenceOfHAsciiString from TColStd,
96 GraphNode from XCAFDoc,
97 AttributeSequence from TDF,
98 DataMapOfShapeLabel from XCAFDoc
99
100is
101 GetID (myclass)
102 ---C++: return const &
103 returns GUID from Standard;
104
105
106 Set (myclass; L : Label from TDF) returns ShapeTool from XCAFDoc;
107 ---Purpose: Create (if not exist) ShapeTool from XCAFDoc on <L>.
108
109
110
111
112 Create returns ShapeTool from XCAFDoc;
113 ---Purpose: Creates an empty tool
114
115 --Create (Doc: Document from TDocStd) returns ShapeTool from XCAFDoc;
116 ---Purpose: Creates a tool to work with a document <Doc>
117 -- Attaches to label XCAFDoc::LabelShapes()
118
119
120
121 ---API: Analysis
122
123 IsTopLevel (me; L: Label from TDF) returns Boolean;
124 ---Purpose: Returns True if the label is a label of top-level shape,
125 -- as opposed to component of assembly or subshape
126
127 IsFree (myclass; L: Label from TDF) returns Boolean;
128 ---Purpose: Returns True if the label is not used by any assembly, i.e.
129 -- contains sublabels which are assembly components
130 -- This is relevant only if IsShape() is True
131 -- (There is no Father TreeNode on this <L>)
132
133 IsShape (myclass; L: Label from TDF) returns Boolean;
134 ---Purpose: Returns True if the label represents a shape (simple shape,
135 -- assembly or reference)
136
137 IsSimpleShape (myclass; L: Label from TDF) returns Boolean;
138 ---Purpose: Returns True if the label is a label of simple shape
139
140 IsReference (myclass; L: Label from TDF) returns Boolean;
141 ---Purpose: Return true if <L> is a located instance of other shape
142 -- i.e. reference
143
144 IsAssembly (myclass; L: Label from TDF) returns Boolean;
145 ---Purpose: Returns True if the label is a label of assembly, i.e.
146 -- contains sublabels which are assembly components
147 -- This is relevant only if IsShape() is True
148
149 IsComponent (myclass; L: Label from TDF) returns Boolean;
150 ---Purpose: Return true if <L> is reference serving as component
151 -- of assembly
152
153 IsCompound (myclass; L: Label from TDF) returns Boolean;
154 ---Purpose: Returns True if the label is a label of compound, i.e.
155 -- contains some sublabels
156 -- This is relevant only if IsShape() is True
157
158 IsSubShape (myclass; L: Label from TDF) returns Boolean;
159 ---Purpose: Return true if <L> is subshape of the top-level shape
160
161 IsSubShape (me; shapeL: Label from TDF;
162 sub: Shape from TopoDS)
163 returns Boolean;
164 ---Purpose: Checks whether shape <sub> is subshape of shape stored on
165 -- label shapeL
166
167 ---API: Work with top-level structure of shapes
168
169 SearchUsingMap (me; S: Shape from TopoDS; L: out Label from TDF;
170 findWithoutLoc: Boolean; findSubshape: Boolean)
171 returns Boolean from Standard;
172
173 Search (me; S: Shape from TopoDS; L: out Label from TDF;
174 findInstance: Boolean = Standard_True;
175 findComponent: Boolean = Standard_True;
176 findSubshape: Boolean = Standard_True)
177 returns Boolean from Standard;
178 ---Purpose: General tool to find a (sub) shape in the document
179 -- * If findInstance is True, and S has a non-null location,
180 -- first tries to find the shape among the top-level shapes
181 -- with this location
182 -- * If not found, and findComponent is True, tries to find the shape
183 -- among the components of assemblies
184 -- * If not found, tries to find the shape without location
185 -- among top-level shapes
186 -- * If not found and findSubshape is True, tries to find a
187 -- shape as a subshape of top-level simple shapes
188 -- Returns False if nothing is found
189
190 FindShape (me; S: Shape from TopoDS; L: out Label from TDF;
191 findInstance: Boolean = Standard_False)
192 returns Boolean from Standard;
193 ---Purpose: Returns the label corresponding to shape S
194 -- (searches among top-level shapes, not including subcomponents
195 -- of assemblies)
196 -- If findInstance is False (default), searches for the
197 -- non-located shape (i.e. among original shapes)
198 -- If findInstance is True, searches for the shape with the same
199 -- location, including shape instances
200 -- Return True if <S> is found.
201
202 FindShape (me; S: Shape from TopoDS;
203 findInstance: Boolean = Standard_False)
204 returns Label from TDF;
205 ---Purpose: Does the same as previous method
206 -- Returns Null label if not found
207
208 GetShape (myclass; L: Label from TDF;
209 S: out Shape from TopoDS) returns Boolean from Standard;
210 ---Purpose: To get TopoDS_Shape from shape's label
211 -- For component, returns new shape with correct location
212 -- Returns False if label does not contain shape
213
214 GetShape (myclass; L: Label from TDF) returns Shape from TopoDS;
215 ---Purpose: To get TopoDS_Shape from shape's label
216 -- For component, returns new shape with correct location
217 -- Returns Null shape if label does not contain shape
218
219 NewShape (me) returns Label from TDF;
220 ---Purpose: Creates new (empty) top-level shape.
221 -- Initially it holds empty TopoDS_Compound
222
223 SetShape (me:mutable; L: Label from TDF; S: Shape from TopoDS);
224 ---Purpose: Sets representation (TopoDS_Shape) for top-level shape
225
226 AddShape (me:mutable; S: Shape from TopoDS;
227 makeAssembly: Boolean = Standard_True;
228 makePrepare : Boolean = Standard_True)
229 returns Label from TDF;
230 ---Purpose: Adds a new top-level (creates and returns a new label)
231 -- If makeAssembly is True, treats TopAbs_COMPOUND shapes
232 -- as assemblies (creates assembly structure).
233 -- NOTE: <makePrepare> replace components without location
234 -- in assmebly by located components to avoid some problems.
235
236 addShape (me:mutable; S: Shape from TopoDS;
237 makeAssembly: Boolean = Standard_True)
238 returns Label from TDF is private;
239 ---Purpose: Adds a new top-level (creates and returns a new label)
240 -- For internal use. Used by public method AddShape.
241
a7aa1465 242 RemoveShape (me; L: Label from TDF;
243 removeCompletely: Boolean = Standard_True)
244 returns Boolean;
7fd59977 245 ---Purpose: Removes shape (whole label and all its sublabels)
a7aa1465 246 -- If removeCompletely is true, removes complete shape
247 -- If removeCompletely is false, removes instance(location) only
7fd59977 248 -- Returns False (and does nothing) if shape is not free
249 -- or is not top-level shape
250
251 Init (me: mutable);
252 ---Purpose: set hasComponents into false
253
254 ComputeShapes (me: mutable; L: Label from TDF);
255 ---Purpose: recursive
256
257 ComputeSimpleShapes (me: mutable);
258 ---Purpose: Compute a sequence of simple shapes
259
260 GetShapes (me; Labels: out LabelSequence from TDF);
261 ---Purpose: Returns a sequence of all top-level shapes
262
263 GetFreeShapes (me; FreeLabels : out LabelSequence from TDF);
264 ---Purpose: Returns a sequence of all top-level shapes
265 -- which are free (i.e. not referred by any other)
266
267 GetUsers (myclass; L: Label from TDF;
268 Labels : out LabelSequence from TDF;
269 getsubchilds: Boolean from Standard = Standard_False)
270 returns Integer;
271 ---Purpose: Returns list of labels which refer shape L as component
272 -- Returns number of users (0 if shape is free)
273
274 GetLocation (myclass; L: Label from TDF)
275 returns Location from TopLoc;
276 ---Purpose: Returns location of instance
277
278 GetReferredShape (myclass; L: Label from TDF;
279 Label: out Label from TDF)
280 returns Boolean;
281 ---Purpose: Returns label which corresponds to a shape referred by L
282 -- Returns False if label is not reference
283
284 ---API: Work with assembly structure
285
286 NbComponents (myclass; L: Label from TDF;
287 getsubchilds: Boolean from Standard = Standard_False)
288 returns Integer;
289 ---Purpose: Returns number of Assembles components
290
291 GetComponents (myclass; L: Label from TDF;
292 Labels : out LabelSequence from TDF;
293 getsubchilds: Boolean from Standard = Standard_False)
294 returns Boolean;
295 ---Purpose: Returns list of components of assembly
296 -- Returns False if label is not assembly
297
298 AddComponent (me; assembly, comp: Label from TDF;
299 Loc: Location from TopLoc)
300 returns Label from TDF;
301 ---Purpose: Adds a component given by its label and location to the assembly
302 -- Note: assembly must be IsAssembly() or IsSimpleShape()
303
304 AddComponent (me:mutable; assembly: Label from TDF;
305 comp: Shape from TopoDS; expand: Boolean = Standard_False)
306 returns Label from TDF;
307 ---Purpose: Adds a shape (located) as a component to the assembly
308 -- If necessary, creates an additional top-level shape for
309 -- component and return the Label of component.
310 -- If expand is True and component is Compound, it will
311 -- be created as assembly also
312 -- Note: assembly must be IsAssembly() or IsSimpleShape()
313
314 RemoveComponent (me; comp: Label from TDF);
315 ---Purpose: Removes a component from its assembly
316
317 UpdateAssembly (me; L: Label from TDF);
318 ---Purpose: Update an assembly at label <L>
319
320 ---API: work with sub-shapes of shape
321
322 FindSubShape (me; shapeL: Label from TDF;
323 sub: Shape from TopoDS;
324 L: out Label from TDF)
325 returns Boolean;
326 ---Purpose: Finds a label for subshape <sub> of shape stored on
327 -- label shapeL
328 -- Returns Null label if it is not found
329
330 AddSubShape (me; shapeL: Label from TDF;
331 sub: Shape from TopoDS)
332 returns Label from TDF;
333 ---Purpose: Adds a label for subshape <sub> of shape stored on
334 -- label shapeL
335 -- Returns Null label if it is not subshape
336
337 FindMainShapeUsingMap (me; sub: Shape from TopoDS)
338 returns Label from TDF;
339
340 FindMainShape (me; sub: Shape from TopoDS)
341 returns Label from TDF;
342 ---Purpose: Performs a search among top-level shapes to find
343 -- the shape containing <sub> as subshape
344 -- Checks only simple shapes, and returns the first found
345 -- label (which should be the only one for valid model)
346
347 GetSubShapes (myclass; L: Label from TDF;
348 Labels : out LabelSequence from TDF)
349 returns Boolean;
350 ---Purpose: Returns list of labels identifying subshapes of the given shape
351 -- Returns False if no subshapes are placed on that label
352
353 ---API: Auxiliary
354
355 BaseLabel(me) returns Label from TDF;
356 ---Purpose: returns the label under which shapes are stored
357
358 Dump(me; deep : Boolean from Standard = Standard_False);
359
360 DumpShape(myclass; L: Label from TDF;
361 level :Integer from Standard = 0;
362 deep : Boolean from Standard = Standard_False);
363 ---Purpose: Print in cout type of shape found on <L> label
364 -- and the entry of <L>, with <level> tabs before.
365 -- If <deep>, print also TShape and Location addresses
366
367 --- Private
368
369 MakeReference (myclass; L, refL: Label from TDF; loc: Location from TopLoc)
370 is private;
371 ---Purpose: Makes a shape on label L to be a reference to shape refL
372 -- with location loc
373
374
375 ---Category: TDF_Attribute methods
376 -- =====================
377
378 ID (me)
379 ---C++: return const &
380 returns GUID from Standard;
381
382 Restore (me: mutable; with : Attribute from TDF);
383
384 NewEmpty (me)
385 returns mutable Attribute from TDF;
386
387 Paste (me; into : mutable Attribute from TDF;
388 RT : mutable RelocationTable from TDF);
389
390 IsExternRef (myclass; L: Label from TDF) returns Boolean;
391 ---Purpose: Returns True if the label is a label of external references, i.e.
392 -- there are some reference on the no-step files, which are
393 -- described in document only their names
394
395 SetExternRefs (me; SHAS: SequenceOfHAsciiString from TColStd) returns Label from TDF;
396 ---Purpose: Sets the names of references on the no-step files
397
398 SetExternRefs (me; L: Label from TDF; SHAS: SequenceOfHAsciiString from TColStd);
399 ---Purpose: Sets the names of references on the no-step files
400
401 GetExternRefs (myclass; L: Label from TDF; SHAS: in out SequenceOfHAsciiString from TColStd);
402 ---Purpose: Gets the names of references on the no-step files
403
404 ---API: Work with SHUO (Specified Higher Usage Occurrance) structure
405
406 SetSHUO (me; Labels : LabelSequence from TDF;
407 MainSHUOAttr : in out GraphNode from XCAFDoc)
408 returns Boolean;
409 ---Purpose: Sets the SHUO structure between upper_usage and next_usage
410 -- create multy-level (if number of labels > 2) SHUO from first to last
411 -- Initialise out <MainSHUOAttr> by main upper_usage SHUO attribute.
412 -- Returns FALSE if some of labels in not component label
413
414 GetSHUO (myclass; SHUOLabel : Label from TDF;
415 aSHUOAttr : in out GraphNode from XCAFDoc)
416 returns Boolean;
417 ---Purpose: Returns founded SHUO GraphNode attribute <aSHUOAttr>
418 -- Returns false in other case
419
420 GetAllComponentSHUO (myclass; CompLabel : Label from TDF;
421 SHUOAttrs : in out AttributeSequence from TDF)
422 returns Boolean;
423 ---Purpose: Returns founded SHUO GraphNodes of indicated component
424 -- Returns false in other case
425
426 GetSHUOUpperUsage (myclass; NextUsageL: Label from TDF;
427 Labels : out LabelSequence from TDF)
428 returns Boolean;
429 ---Purpose: Returns the sequence of labels of SHUO attributes,
430 -- which is upper_usage for this next_usage SHUO attribute
431 -- (that indicated by label)
432 -- NOTE: returns upper_usages only on one level (not recurse)
433 -- NOTE: do not clear the sequence before filling
434
435 GetSHUONextUsage (myclass; UpperUsageL: Label from TDF;
436 Labels : out LabelSequence from TDF)
437 returns Boolean;
438 ---Purpose: Returns the sequence of labels of SHUO attributes,
439 -- which is next_usage for this upper_usage SHUO attribute
440 -- (that indicated by label)
441 -- NOTE: returns next_usages only on one level (not recurse)
442 -- NOTE: do not clear the sequence before filling
443
444 RemoveSHUO (me; SHUOLabel : Label from TDF)
445 returns Boolean;
446 ---Purpose: Remove SHUO from component sublabel,
447 -- remove all dependencies on other SHUO.
448 -- Returns FALSE if cannot remove SHUO dependencies.
449 -- NOTE: remove any styles that associated with this SHUO.
450
451 FindComponent (me; theShape : Shape from TopoDS;
452 Labels : out LabelSequence from TDF)
453 returns Boolean;
454 ---Purpose: Serach the path of labels in the document,
455 -- that corresponds the component from any assembly
456 -- Try to search the sequence of labels with location that
457 -- produce this shape as component of any assembly
458 -- NOTE: Clear sequence of labels before filling
459
460 GetSHUOInstance (me; theSHUO : GraphNode from XCAFDoc)
461 returns Shape from TopoDS;
462 ---Purpose: Search for the component shape that styled by shuo
463 -- Returns null shape if no any shape is found.
464
465 SetInstanceSHUO (me; theShape : Shape from TopoDS)
466 returns GraphNode from XCAFDoc;
467 ---Purpose: Search for the component shape by labelks path
468 -- and set SHUO structure for founded label structure
469 -- Returns null attribute if no component in any assembly found.
470
471 GetAllSHUOInstances (me; theSHUO : GraphNode from XCAFDoc;
472 theSHUOShapeSeq : in out SequenceOfShape from TopTools)
473 returns Boolean from Standard;
474 ---Purpose: Seaching for component shapes that styled by shuo
475 -- Returns empty sequence of shape if no any shape is found.
476
477 FindSHUO (myclass; Labels : LabelSequence from TDF;
478 theSHUOAttr : in out GraphNode from XCAFDoc)
479 returns Boolean from Standard;
480 ---Purpose: Searchs the SHUO by labels of components
481 -- from upper_usage componet to next_usage
482 -- Returns null attribute if no SHUO found
483
484fields
485 myShapeLabels : DataMapOfShapeLabel from XCAFDoc; --skl 15.10.2003
486 mySubShapes : DataMapOfShapeLabel from XCAFDoc;
487 mySimpleShapes : DataMapOfShapeLabel from XCAFDoc;
488 hasSimpleShapes : Boolean from Standard;
489
490end ShapeTool;