b311480e |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // ------------ |
7fd59977 |
17 | // Version: 0.0 |
b311480e |
18 | //Version Date Purpose |
7fd59977 |
19 | // 0.0 Mar 13 1997 Creation |
20 | |
42cf5bc1 |
21 | #include <TCollection_AsciiString.hxx> |
22 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
23 | #include <TColStd_ListOfInteger.hxx> |
7fd59977 |
24 | #include <TDF_AttributeIndexedMap.hxx> |
42cf5bc1 |
25 | #include <TDF_AttributeIterator.hxx> |
7fd59977 |
26 | #include <TDF_ChildIterator.hxx> |
42cf5bc1 |
27 | #include <TDF_Data.hxx> |
7fd59977 |
28 | #include <TDF_DataSet.hxx> |
42cf5bc1 |
29 | #include <TDF_IDFilter.hxx> |
30 | #include <TDF_Label.hxx> |
7fd59977 |
31 | #include <TDF_ListIteratorOfLabelList.hxx> |
42cf5bc1 |
32 | #include <TDF_MapIteratorOfAttributeMap.hxx> |
33 | #include <TDF_MapIteratorOfLabelMap.hxx> |
34 | #include <TDF_Tool.hxx> |
7fd59977 |
35 | |
36 | #define TDF_TagSeparator ':' |
37 | |
38 | static void TDF_Tool_ExtendedDeepDump(Standard_OStream& anOS, |
39 | const TDF_Label& aLabel, |
40 | const TDF_IDFilter& aFilter, |
41 | TDF_AttributeIndexedMap& aMap); |
42 | |
43 | static Standard_Boolean TDF_Tool_DescendantRef(const TDF_Label& aRefLabel, |
44 | const TDF_Label& aLabel, |
45 | const TDF_IDFilter& aFilter, |
46 | const Handle(TDF_DataSet)& ds); |
47 | |
48 | static void TDF_Tool_OutReferers(const TDF_Label& aRefLabel, |
49 | const TDF_Label& aLabel, |
50 | TDF_AttributeMap& atts, |
51 | const TDF_IDFilter& aFilterForReferers, |
52 | const TDF_IDFilter& aFilterForReferences, |
53 | const Handle(TDF_DataSet)& ds); |
54 | |
55 | static void TDF_Tool_OutReferences(const TDF_Label& aRefLabel, |
56 | const TDF_Label& aLabel, |
57 | TDF_AttributeMap& atts, |
58 | const TDF_IDFilter& aFilterForReferers, |
59 | const TDF_IDFilter& aFilterForReferences, |
60 | const Handle(TDF_DataSet)& ds); |
61 | |
62 | //======================================================================= |
63 | //function : NbLabels |
64 | //purpose : Returns the numbers of labels of the tree. |
65 | //======================================================================= |
66 | |
67 | Standard_Integer TDF_Tool::NbLabels(const TDF_Label& aLabel) |
68 | { |
69 | Standard_Integer n = 1; |
70 | for (TDF_ChildIterator itr(aLabel,Standard_True); itr.More(); itr.Next()) |
71 | ++n; |
72 | return n; |
73 | } |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : NbAttributes |
78 | //purpose : Returns the number of attributes of the tree. |
79 | //======================================================================= |
80 | |
81 | Standard_Integer TDF_Tool::NbAttributes(const TDF_Label& aLabel) |
82 | { |
83 | Standard_Integer n = aLabel.NbAttributes(); |
84 | for (TDF_ChildIterator itr(aLabel,Standard_True); itr.More(); itr.Next()) |
85 | n += itr.Value().NbAttributes(); |
86 | return n; |
87 | } |
88 | |
89 | |
90 | //======================================================================= |
91 | //function : NbAttributes |
92 | //purpose : Returns the number of attributes of the tree, |
93 | // selected by an IDFilter. |
94 | //======================================================================= |
95 | |
96 | Standard_Integer TDF_Tool::NbAttributes |
97 | (const TDF_Label& aLabel, |
98 | const TDF_IDFilter& aFilter) |
99 | { |
100 | Standard_Integer n = 0; |
101 | TDF_AttributeIterator it2; |
102 | for (it2.Initialize(aLabel,Standard_True);it2.More();it2.Next()) |
103 | if (aFilter.IsKept(it2.Value())) ++n; |
104 | for (TDF_ChildIterator it1(aLabel,Standard_True); it1.More(); it1.Next()) |
105 | for (it2.Initialize(it1.Value(),Standard_True);it2.More();it2.Next()) |
106 | if (aFilter.IsKept(it2.Value())) ++n; |
107 | return n; |
108 | } |
109 | |
110 | |
111 | //======================================================================= |
112 | //function : IsSelfContained |
113 | //purpose : |
114 | //======================================================================= |
115 | |
116 | Standard_Boolean TDF_Tool::IsSelfContained(const TDF_Label& aLabel) |
117 | { |
118 | TDF_IDFilter filter(Standard_False); // Keep all. |
119 | return IsSelfContained(aLabel,filter); |
120 | } |
121 | |
122 | //======================================================================= |
123 | //function : IsSelfContained |
124 | //purpose : |
125 | //======================================================================= |
126 | |
127 | Standard_Boolean TDF_Tool::IsSelfContained |
128 | (const TDF_Label& aLabel, |
129 | const TDF_IDFilter& aFilter) |
130 | { |
131 | Handle(TDF_DataSet) ds = new TDF_DataSet(); |
132 | |
133 | if (!TDF_Tool_DescendantRef(aLabel,aLabel,aFilter,ds)) |
134 | return Standard_False; |
135 | |
136 | for (TDF_ChildIterator itr(aLabel,Standard_True); |
137 | itr.More(); |
138 | itr.Next()) { |
139 | if (!TDF_Tool_DescendantRef(aLabel,itr.Value(),aFilter,ds)) |
140 | return Standard_False; |
141 | } |
142 | return Standard_True; |
143 | } |
144 | |
145 | |
146 | //======================================================================= |
147 | //function : TDF_Tool_DescendantRef |
148 | //purpose : |
149 | //======================================================================= |
150 | |
151 | static Standard_Boolean TDF_Tool_DescendantRef |
152 | (const TDF_Label& aRefLabel, |
153 | const TDF_Label& aLabel, |
154 | const TDF_IDFilter& aFilter, |
155 | const Handle(TDF_DataSet)& ds) |
156 | { |
157 | for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) { |
158 | // CLE |
159 | // const Handle(TDF_Attribute)& labAtt = itr.Value(); |
160 | Handle(TDF_Attribute) labAtt = itr.Value(); |
161 | // ENDCLE |
162 | if (aFilter.IsKept(labAtt)) { |
163 | labAtt->References(ds); |
164 | // First of all, the referenced labels. |
165 | const TDF_LabelMap& labMap = ds->Labels(); |
166 | |
167 | for (TDF_MapIteratorOfLabelMap labMItr(labMap); |
168 | labMItr.More(); labMItr.Next()) { |
169 | if (!labMItr.Key().IsDescendant(aRefLabel)) |
170 | return Standard_False; |
171 | } |
172 | // Then the referenced attributes. |
173 | const TDF_AttributeMap& attMap = ds->Attributes(); |
174 | for (TDF_MapIteratorOfAttributeMap attMItr(attMap); |
175 | attMItr.More(); attMItr.Next()) { |
176 | // CLE |
177 | // const Handle(TDF_Attribute)& att = attMItr.Key(); |
178 | Handle(TDF_Attribute) att = attMItr.Key(); |
643cc6aa |
179 | if (!att.IsNull() && !att->Label().IsNull()) |
180 | { |
181 | // ENDCLE |
182 | if (aFilter.IsKept(att) && !att->Label().IsDescendant(aRefLabel)) |
183 | return Standard_False; |
184 | } |
7fd59977 |
185 | } |
186 | ds->Clear(); |
187 | } |
188 | } |
189 | return Standard_True; |
190 | } |
191 | |
192 | |
193 | //======================================================================= |
194 | //function : OutReferers |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | void TDF_Tool::OutReferers(const TDF_Label& aLabel, |
199 | TDF_AttributeMap& atts) |
200 | { |
201 | TDF_IDFilter filter(Standard_False); // Keep all. |
202 | OutReferers(aLabel,filter,filter,atts); |
203 | } |
204 | |
205 | |
206 | //======================================================================= |
207 | //function : OutReferers |
208 | //purpose : |
209 | //======================================================================= |
210 | |
211 | void TDF_Tool::OutReferers(const TDF_Label& aLabel, |
212 | const TDF_IDFilter& aFilterForReferers, |
213 | const TDF_IDFilter& aFilterForReferences, |
214 | TDF_AttributeMap& atts) |
215 | { |
216 | Handle(TDF_DataSet) ds = new TDF_DataSet(); |
217 | TDF_Tool_OutReferers(aLabel,aLabel,atts,aFilterForReferers,aFilterForReferences,ds); |
218 | for (TDF_ChildIterator itr(aLabel,Standard_True);itr.More();itr.Next()) { |
219 | TDF_Tool_OutReferers(aLabel,itr.Value(),atts,aFilterForReferers,aFilterForReferences,ds); |
220 | } |
221 | } |
222 | |
223 | |
224 | //======================================================================= |
225 | //function : TDF_Tool_OutReferers |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | static void TDF_Tool_OutReferers(const TDF_Label& aRefLabel, |
230 | const TDF_Label& aLabel, |
231 | TDF_AttributeMap& atts, |
232 | const TDF_IDFilter& aFilterForReferers, |
233 | const TDF_IDFilter& aFilterForReferences, |
234 | const Handle(TDF_DataSet)& ds) |
235 | { |
236 | Standard_Boolean outRefFound = Standard_False; |
237 | |
238 | for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) { |
239 | |
240 | if (!aFilterForReferers.IsKept(itr.Value())) continue; |
241 | itr.Value()->References(ds); |
242 | |
243 | const TDF_AttributeMap& attMap = ds->Attributes(); |
244 | for (TDF_MapIteratorOfAttributeMap attMItr(attMap); |
245 | attMItr.More(); attMItr.Next()) { |
246 | // CLE |
247 | // const Handle(TDF_Attribute)& att = attMItr.Key(); |
248 | Handle(TDF_Attribute) att = attMItr.Key(); |
249 | // ENDCLE |
d91b3986 |
250 | if (aFilterForReferences.IsKept(att) && |
251 | !att->Label().IsNull() && |
252 | !att->Label().IsDescendant(aRefLabel)) |
253 | { |
254 | atts.Add(itr.Value()); |
255 | outRefFound = Standard_True; |
256 | break; |
7fd59977 |
257 | } |
258 | } |
259 | |
260 | if (!outRefFound) { |
261 | const TDF_LabelMap& labMap = ds->Labels(); |
262 | for (TDF_MapIteratorOfLabelMap labMItr(labMap); |
263 | labMItr.More(); labMItr.Next()) { |
264 | if (!labMItr.Key().IsDescendant(aRefLabel)) { |
265 | atts.Add(itr.Value()); |
266 | break; |
267 | } |
268 | } |
269 | } |
270 | |
271 | outRefFound = Standard_False; |
272 | ds->Clear(); |
273 | } |
274 | } |
275 | |
276 | //======================================================================= |
277 | //function : OutReferences |
278 | //purpose : |
279 | //======================================================================= |
280 | |
281 | void TDF_Tool::OutReferences(const TDF_Label& aLabel, |
282 | TDF_AttributeMap& atts) |
283 | { |
284 | TDF_IDFilter filter(Standard_False); // Keep all. |
285 | OutReferences(aLabel,filter,filter,atts); |
286 | } |
287 | |
288 | //======================================================================= |
289 | //function : OutReferences |
290 | //purpose : |
291 | //======================================================================= |
292 | |
293 | void TDF_Tool::OutReferences(const TDF_Label& aLabel, |
294 | const TDF_IDFilter& aFilterForReferers, |
295 | const TDF_IDFilter& aFilterForReferences, |
296 | TDF_AttributeMap& atts) |
297 | { |
298 | Handle(TDF_DataSet) ds = new TDF_DataSet(); |
299 | TDF_Tool_OutReferences(aLabel,aLabel,atts,aFilterForReferers,aFilterForReferences,ds); |
300 | for (TDF_ChildIterator itr(aLabel,Standard_True);itr.More();itr.Next()) { |
301 | TDF_Tool_OutReferences(aLabel,itr.Value(),atts,aFilterForReferers,aFilterForReferences,ds); |
302 | } |
303 | } |
304 | |
305 | //======================================================================= |
306 | //function : TDF_Tool_OutReferences |
307 | //purpose : |
308 | //======================================================================= |
309 | |
310 | static void TDF_Tool_OutReferences(const TDF_Label& aRefLabel, |
311 | const TDF_Label& aLabel, |
312 | TDF_AttributeMap& atts, |
313 | const TDF_IDFilter& aFilterForReferers, |
314 | const TDF_IDFilter& aFilterForReferences, |
315 | const Handle(TDF_DataSet)& ds) |
316 | { |
317 | for (TDF_AttributeIterator itr(aLabel); itr.More(); itr.Next()) { |
318 | if (!aFilterForReferers.IsKept(itr.Value())) continue; |
319 | itr.Value()->References(ds); |
320 | const TDF_AttributeMap& attMap = ds->Attributes(); |
321 | for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More();attMItr.Next()) { |
322 | Handle(TDF_Attribute) att = attMItr.Key(); |
d91b3986 |
323 | if (aFilterForReferences.IsKept(att) && |
324 | !att->Label().IsNull() && |
325 | !att->Label().IsDescendant(aRefLabel)) |
326 | { |
327 | atts.Add(att); |
7fd59977 |
328 | } |
329 | } |
330 | const TDF_LabelMap& labMap = ds->Labels(); |
331 | for (TDF_MapIteratorOfLabelMap labMItr(labMap);labMItr.More();labMItr.Next()) { |
332 | if (!labMItr.Key().IsDescendant(aRefLabel)) { |
333 | TDF_AttributeIterator itra(labMItr.Key()); |
334 | for (; itra.More(); itra.Next()) { |
335 | if (aFilterForReferences.IsKept(itra.Value())) { |
336 | atts.Add(itra.Value()); |
337 | } |
338 | } |
339 | } |
340 | } |
341 | } |
342 | ds->Clear(); |
343 | } |
344 | |
345 | //======================================================================= |
346 | //function : RelocateLabel |
347 | //purpose : |
348 | //======================================================================= |
349 | |
350 | void TDF_Tool::RelocateLabel |
351 | (const TDF_Label& aSourceLabel, |
352 | const TDF_Label& fromRoot, |
353 | const TDF_Label& toRoot, |
354 | TDF_Label& aTargetLabel, |
355 | const Standard_Boolean create) |
356 | { |
357 | if (!aSourceLabel.IsDescendant(fromRoot)) return; |
358 | aTargetLabel.Nullify(); |
359 | TColStd_ListOfInteger labelTags; |
360 | TDF_Tool::TagList(aSourceLabel,labelTags); |
361 | TColStd_ListOfInteger toTags; |
362 | TDF_Tool::TagList(toRoot,toTags); |
363 | for (Standard_Integer i = fromRoot.Depth(); i >= 0; --i) |
364 | labelTags.RemoveFirst(); |
365 | labelTags.Prepend(toTags); |
366 | TDF_Tool::Label(toRoot.Data(),labelTags,aTargetLabel,create); |
367 | } |
368 | |
369 | |
370 | //======================================================================= |
371 | //function : Entry |
372 | //purpose : Returns the entry as an ascii string. |
373 | //======================================================================= |
374 | |
375 | void TDF_Tool::Entry |
376 | (const TDF_Label& aLabel, |
377 | TCollection_AsciiString& anEntry) |
378 | { |
379 | anEntry.Clear(); |
380 | if (!aLabel.IsNull()) { |
381 | TColStd_ListOfInteger Tags; |
382 | TDF_Tool::TagList(aLabel, Tags); |
383 | anEntry += TCollection_AsciiString(Tags.First()); |
384 | Tags.RemoveFirst(); |
385 | if (Tags.IsEmpty()) { |
386 | anEntry += TDF_TagSeparator; // It must be the root label case. |
387 | } |
388 | else { |
389 | while (!Tags.IsEmpty()) { |
390 | anEntry += TDF_TagSeparator; |
391 | anEntry += TCollection_AsciiString(Tags.First()); |
392 | Tags.RemoveFirst(); |
393 | } |
394 | } |
395 | } |
396 | } |
397 | |
398 | |
399 | //======================================================================= |
400 | //function : TagList |
401 | //purpose : Returns the entry of a label as a list of integers. |
402 | //======================================================================= |
403 | |
404 | void TDF_Tool::TagList |
405 | (const TDF_Label& aLabel, |
406 | TColStd_ListOfInteger& aTagList) |
407 | { |
408 | aTagList.Clear(); |
409 | if (!aLabel.IsNull()) { |
410 | TDF_Label Label = aLabel; |
411 | for (;;) { |
412 | aTagList.Prepend(Label.Tag()); |
413 | if (Label.IsRoot()) break; |
414 | Label = Label.Father(); |
415 | } |
416 | } |
417 | } |
418 | |
419 | |
420 | //======================================================================= |
421 | //function : TagList |
422 | //purpose : Returns the entry expressed as a string as a list of integers. |
423 | //======================================================================= |
424 | |
425 | void TDF_Tool::TagList |
426 | (const TCollection_AsciiString& anEntry, |
427 | TColStd_ListOfInteger& aTagList) |
428 | { |
429 | char* cc = (char *)anEntry.ToCString(); |
430 | Standard_Integer n = 0; |
431 | aTagList.Clear(); |
432 | while (*cc != '\0') { |
433 | while ( *cc >= '0' && *cc <= '9') { |
434 | n = 10*n + (*cc - '0'); |
435 | ++cc; |
436 | } |
437 | if (*cc == TDF_TagSeparator || *cc == '\0') { |
438 | aTagList.Append(n); |
439 | n = 0; |
440 | if (*cc != '\0') ++cc; |
441 | } |
442 | else { // Not an entry! |
443 | aTagList.Clear(); |
444 | break; |
445 | } |
446 | } |
447 | } |
448 | |
449 | |
450 | //======================================================================= |
451 | //function : Label |
452 | //purpose : Returns the label expressed by <anEntry>. |
453 | //======================================================================= |
454 | |
455 | void TDF_Tool::Label |
456 | (const Handle(TDF_Data)& aDF, |
457 | const TCollection_AsciiString& anEntry, |
458 | TDF_Label& aLabel, |
459 | const Standard_Boolean create) |
460 | { TDF_Tool::Label(aDF,anEntry.ToCString(),aLabel,create); } |
461 | |
462 | |
463 | //======================================================================= |
464 | //function : Label |
465 | //purpose : Returns the label expressed by <anEntry>, |
466 | // and creates it if <create> is true. |
467 | //======================================================================= |
468 | |
469 | void TDF_Tool::Label |
470 | (const Handle(TDF_Data)& aDF, |
471 | const Standard_CString anEntry, |
472 | TDF_Label& aLabel, |
473 | const Standard_Boolean create) |
474 | { |
475 | TColStd_ListOfInteger tagList; |
476 | TDF_Tool::TagList(anEntry,tagList); |
477 | TDF_Tool::Label(aDF,tagList,aLabel,create); |
478 | } |
479 | |
480 | |
481 | //======================================================================= |
482 | //function : Label |
483 | //purpose : Returns the label expressed by <anEntry>, |
484 | // and creates it if <create> is true. |
485 | //======================================================================= |
486 | |
487 | void TDF_Tool::Label |
488 | (const Handle(TDF_Data)& aDF, |
489 | const TColStd_ListOfInteger& aTagList, |
490 | TDF_Label& aLabel, |
491 | const Standard_Boolean create) |
492 | { |
493 | if (aTagList.Extent() == 0) { |
494 | aLabel.Nullify(); |
495 | } |
496 | else { |
497 | aLabel = aDF->Root(); |
498 | if (aTagList.Extent() == 1 && aTagList.First() == 0) return; |
499 | else { |
500 | TColStd_ListIteratorOfListOfInteger tagItr (aTagList); |
501 | tagItr.Next(); // Suppresses root tag. |
502 | for (; !aLabel.IsNull() && tagItr.More(); tagItr.Next()) { |
503 | aLabel = aLabel.FindChild(tagItr.Value(),create); |
504 | } |
505 | } |
506 | } |
507 | } |
508 | |
509 | |
510 | //======================================================================= |
511 | //function : CountLabels |
512 | //purpose : |
513 | //======================================================================= |
514 | |
515 | void TDF_Tool::CountLabels |
516 | (TDF_LabelList& aLabelList, |
517 | TDF_LabelIntegerMap& aLabelMap) |
518 | { |
519 | if (aLabelList.IsEmpty()) return; |
520 | Standard_Boolean next = Standard_True; |
521 | TDF_ListIteratorOfLabelList itr(aLabelList); |
522 | while (itr.More()) { |
523 | const TDF_Label& lab = itr.Value(); |
524 | if (aLabelMap.IsBound(lab)) { |
525 | aLabelMap(lab) += 1; |
526 | aLabelList.Remove(itr); |
527 | next = Standard_False; |
528 | } |
529 | else { |
530 | aLabelMap.Bind(lab,1); |
531 | next = itr.More(); |
532 | } |
533 | if (next && !aLabelList.IsEmpty()) itr.Next(); |
534 | } |
535 | } |
536 | |
537 | |
538 | //======================================================================= |
539 | //function : DeductLabels |
540 | //purpose : |
541 | //======================================================================= |
542 | |
543 | void TDF_Tool::DeductLabels |
544 | (TDF_LabelList& aLabelList, |
545 | TDF_LabelIntegerMap& aLabelMap) |
546 | { |
547 | if (aLabelList.IsEmpty()) return; |
548 | Standard_Boolean next = Standard_True; |
549 | TDF_ListIteratorOfLabelList itr(aLabelList); |
550 | while (itr.More()) { |
551 | const TDF_Label& lab = itr.Value(); |
552 | if (aLabelMap.IsBound(lab)) { |
553 | aLabelMap(lab) -= 1; |
554 | if (aLabelMap(lab) == 0) { |
555 | aLabelMap.UnBind(lab); |
556 | aLabelList.Remove(itr); |
557 | next = Standard_False; |
558 | } |
559 | } |
560 | else next = itr.More(); |
561 | if (next && !aLabelList.IsEmpty()) itr.Next(); |
562 | } |
563 | } |
564 | |
565 | |
566 | //======================================================================= |
567 | //function : DeepDump |
568 | //purpose : Deep dump of a DF. |
569 | //======================================================================= |
570 | |
571 | void TDF_Tool::DeepDump |
572 | (Standard_OStream& anOS, |
573 | const Handle(TDF_Data)& aDF) |
574 | { |
575 | anOS<<aDF; |
576 | TDF_Tool::DeepDump(anOS,aDF->Root()); |
577 | } |
578 | |
579 | |
580 | //======================================================================= |
581 | //function : ExtendedDeepDump |
582 | //purpose : Extended deep dump of a DF. |
583 | //======================================================================= |
584 | |
585 | void TDF_Tool::ExtendedDeepDump |
586 | (Standard_OStream& anOS, |
587 | const Handle(TDF_Data)& aDF, |
588 | const TDF_IDFilter& aFilter) |
589 | { |
590 | anOS<<aDF; |
591 | TDF_Tool::ExtendedDeepDump(anOS,aDF->Root(),aFilter); |
592 | } |
593 | |
594 | |
595 | //======================================================================= |
596 | //function : DeepDump |
597 | //purpose : Deep dump of a label. |
598 | //======================================================================= |
599 | |
600 | void TDF_Tool::DeepDump |
601 | (Standard_OStream& anOS, |
602 | const TDF_Label& aLabel) |
603 | { |
604 | // Dumps the label. |
605 | anOS<<aLabel; |
606 | // Its children |
607 | for (TDF_ChildIterator ChildIt(aLabel); ChildIt.More (); ChildIt.Next ()) { |
608 | TDF_Tool::DeepDump(anOS,ChildIt.Value()); |
609 | } |
610 | } |
611 | |
612 | |
613 | //======================================================================= |
614 | //function : ExtendedDeepDump |
615 | //purpose : Extended deep dump of a label. |
616 | //======================================================================= |
617 | |
618 | void TDF_Tool::ExtendedDeepDump |
619 | (Standard_OStream& anOS, |
620 | const TDF_Label& aLabel, |
621 | const TDF_IDFilter& aFilter) |
622 | { |
623 | TDF_AttributeIndexedMap map; |
624 | TDF_Tool_ExtendedDeepDump(anOS,aLabel,aFilter,map); |
625 | |
626 | anOS<<map.Extent()<<" attribute"; if (map.Extent()>1) anOS<<"s"; |
04232180 |
627 | anOS<<" referenced by the label structure."<<std::endl; |
7fd59977 |
628 | |
04232180 |
629 | anOS<<std::endl<<"Extended dump of filtered attribute(s):"<<std::endl; |
7fd59977 |
630 | Standard_Integer nba = 0; |
631 | TCollection_AsciiString entry; |
632 | Standard_Integer i ; |
633 | for ( i = 1; i<= map.Extent(); ++i) { |
634 | const Handle(TDF_Attribute)& att = map.FindKey(i); |
635 | if (aFilter.IsKept(att)) { |
636 | ++nba; |
637 | anOS<<"# "<<i; |
638 | if (att->Label().IsNull()) { |
04232180 |
639 | anOS<<" (no label)"<<std::endl; |
7fd59977 |
640 | } |
641 | else { |
642 | TDF_Tool::Entry(att->Label(),entry); |
04232180 |
643 | anOS<<" (label: "<<entry<<")"<<std::endl; |
7fd59977 |
644 | } |
04232180 |
645 | att->ExtendedDump(anOS,aFilter,map); anOS<<std::endl; |
7fd59977 |
646 | } |
647 | } |
04232180 |
648 | anOS<<std::endl<<nba<<" attribute"; |
7fd59977 |
649 | if (nba>1) anOS<<"s"; |
04232180 |
650 | anOS<<" dumped between "<<--i<<std::endl; |
7fd59977 |
651 | } |
652 | |
653 | |
654 | //======================================================================= |
655 | //function : ExtendedDeepDump |
656 | //purpose : Internal method. |
657 | //======================================================================= |
658 | |
659 | static void TDF_Tool_ExtendedDeepDump |
660 | (Standard_OStream& anOS, |
661 | const TDF_Label& aLabel, |
662 | const TDF_IDFilter& aFilter, |
663 | TDF_AttributeIndexedMap& aMap) |
664 | { |
665 | // Dumps the label. |
666 | aLabel.ExtendedDump(anOS,aFilter,aMap); |
667 | // Its children |
668 | for (TDF_ChildIterator ChildIt(aLabel); ChildIt.More (); ChildIt.Next ()) { |
669 | TDF_Tool_ExtendedDeepDump(anOS,ChildIt.Value(),aFilter,aMap); |
670 | } |
671 | } |