b311480e |
1 | // Created on: 1997-01-06 |
2 | // Created by: Yves FRICAUD |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <BRep_Builder.hxx> |
19 | #include <Standard_NoSuchObject.hxx> |
20 | #include <TDF_AttributeMap.hxx> |
21 | #include <TDF_ChildIterator.hxx> |
22 | #include <TDF_Label.hxx> |
7fd59977 |
23 | #include <TDF_LabelList.hxx> |
42cf5bc1 |
24 | #include <TDF_MapIteratorOfAttributeMap.hxx> |
25 | #include <TDF_Tool.hxx> |
26 | #include <TNaming_Iterator.hxx> |
27 | #include <TNaming_ListIteratorOfListOfNamedShape.hxx> |
28 | #include <TNaming_ListOfNamedShape.hxx> |
29 | #include <TNaming_Localizer.hxx> |
7fd59977 |
30 | #include <TNaming_NamedShape.hxx> |
42cf5bc1 |
31 | #include <TNaming_Naming.hxx> |
7fd59977 |
32 | #include <TNaming_NewShapeIterator.hxx> |
33 | #include <TNaming_OldShapeIterator.hxx> |
7fd59977 |
34 | #include <TNaming_RefShape.hxx> |
42cf5bc1 |
35 | #include <TNaming_Tool.hxx> |
36 | #include <TNaming_UsedShapes.hxx> |
37 | #include <TopExp_Explorer.hxx> |
7fd59977 |
38 | #include <TopoDS_Compound.hxx> |
42cf5bc1 |
39 | #include <TopoDS_Shape.hxx> |
0df87563 |
40 | #include <TopTools_IndexedMapOfShape.hxx> |
7fd59977 |
41 | #include <TopTools_MapIteratorOfMapOfShape.hxx> |
42cf5bc1 |
42 | #include <TopTools_MapOfShape.hxx> |
7fd59977 |
43 | |
44 | //======================================================================= |
45 | //function : LastModif |
46 | //purpose : |
47 | //======================================================================= |
7fd59977 |
48 | static void LastModif( TNaming_NewShapeIterator& it, |
49 | const TopoDS_Shape& S, |
0df87563 |
50 | TopTools_IndexedMapOfShape& MS, |
7fd59977 |
51 | const TDF_LabelMap& Updated, |
52 | TDF_LabelList& Deleted) |
53 | { |
54 | Standard_Boolean YaModif = Standard_False; |
55 | for (; it.More(); it.Next()) { |
56 | const TDF_Label& Lab = it.Label(); |
57 | if (!Updated.Contains(Lab)) continue; |
58 | |
59 | if (it.IsModification()) { |
60 | YaModif = Standard_True; |
61 | TNaming_NewShapeIterator it2(it); |
62 | if (!it2.More()) { |
63 | const TopoDS_Shape& S1 = it.Shape(); |
64 | if (S1.IsNull()) { |
65 | Deleted.Append(Lab); |
66 | } |
67 | else { |
68 | MS.Add (S1); // Modified |
69 | } |
70 | } |
71 | else |
72 | LastModif(it2,it.Shape(),MS,Updated,Deleted); |
73 | } |
74 | } |
75 | if (!YaModif) |
76 | MS.Add(S); |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : LastModif |
81 | //purpose : |
82 | //======================================================================= |
83 | |
84 | static void LastModif(TNaming_NewShapeIterator& it, |
0df87563 |
85 | TopTools_IndexedMapOfShape& MS, |
7fd59977 |
86 | const TopoDS_Shape& S, |
87 | TDF_LabelList& Deleted) |
88 | { |
89 | Standard_Boolean YaModif = Standard_False; |
90 | for (; it.More(); it.Next()) { |
91 | const TDF_Label& Lab = it.Label(); |
92 | if (it.IsModification()) { |
93 | YaModif = Standard_True; |
94 | TNaming_NewShapeIterator it2(it); |
95 | if (!it2.More()) { |
96 | const TopoDS_Shape& S1 = it.Shape(); |
97 | if (S1.IsNull()) { |
98 | Deleted.Append(Lab); |
99 | } |
100 | else { |
101 | MS.Add (S1); // Modified |
102 | } |
103 | } |
104 | else |
105 | LastModif(it2,MS,it.Shape(), Deleted); |
106 | } |
107 | } |
108 | if (!YaModif) |
109 | MS.Add(S); |
110 | } |
111 | |
112 | //======================================================================= |
113 | //function : MakeShape |
114 | //purpose : |
115 | //======================================================================= |
116 | |
0df87563 |
117 | static TopoDS_Shape MakeShape (const TopTools_IndexedMapOfShape& MS) |
7fd59977 |
118 | { |
119 | if (!MS.IsEmpty ()) { |
7fd59977 |
120 | if (MS.Extent() == 1) { |
0df87563 |
121 | return MS (1); |
7fd59977 |
122 | } |
123 | else { |
124 | TopoDS_Compound C; |
125 | BRep_Builder B; |
126 | B.MakeCompound(C); |
0df87563 |
127 | for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) { |
128 | B.Add (C, MS (anItMS)); |
7fd59977 |
129 | } |
130 | return C; |
131 | } |
132 | } |
133 | return TopoDS_Shape(); |
134 | } |
135 | |
136 | //======================================================================= |
137 | //function : GetShape |
138 | //purpose : |
139 | //======================================================================= |
7fd59977 |
140 | TopoDS_Shape TNaming_Tool::GetShape(const Handle(TNaming_NamedShape)& NS) |
141 | { |
142 | TNaming_Iterator itL (NS); |
0df87563 |
143 | TopTools_IndexedMapOfShape MS; |
7fd59977 |
144 | if(NS->Evolution() == TNaming_SELECTED) { |
145 | for (; itL.More(); itL.Next()) { |
146 | if(!itL.NewShape().IsNull()) { |
7dcac1df |
147 | if(itL.NewShape().ShapeType() != TopAbs_VERTEX ) { //OR-N |
148 | Handle (TNaming_Naming) aNaming; |
149 | NS->Label().FindAttribute(TNaming_Naming::GetID(), aNaming); |
150 | if(!aNaming.IsNull()) { |
151 | if(aNaming->GetName().Orientation() == TopAbs_FORWARD || |
152 | aNaming->GetName().Orientation() == TopAbs_REVERSED) { |
153 | TopoDS_Shape aS = itL.NewShape(); |
154 | if(aNaming->GetName().Type() == TNaming_ORIENTATION) { |
155 | aS.Orientation(aNaming->GetName().Orientation()); |
156 | } else { |
157 | Handle (TNaming_Naming) aNaming2; |
158 | TDF_ChildIterator it(aNaming->Label()); |
159 | for(;it.More();it.Next()) { |
160 | const TDF_Label& aLabel = it.Value(); |
161 | aLabel.FindAttribute(TNaming_Naming::GetID(), aNaming2); |
162 | if(!aNaming2.IsNull()) { |
163 | if(aNaming2->GetName().Type() == TNaming_ORIENTATION) { |
164 | aS.Orientation(aNaming2->GetName().Orientation()); |
165 | break; |
166 | } |
167 | } |
168 | } |
169 | } |
170 | MS.Add(aS); |
171 | } else |
172 | MS.Add(itL.NewShape()); |
173 | } else |
174 | MS.Add(itL.NewShape()); |
175 | } // |
176 | else |
177 | MS.Add(itL.NewShape()); |
178 | } |
179 | } |
7fd59977 |
180 | } else |
181 | for (; itL.More(); itL.Next()) { |
182 | if (!itL.NewShape().IsNull()) MS.Add(itL.NewShape()); |
183 | } |
184 | return MakeShape(MS); |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : InitialShape |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | TopoDS_Shape TNaming_Tool::OriginalShape (const Handle(TNaming_NamedShape)& NS) |
193 | { |
194 | TNaming_Iterator itL (NS); |
0df87563 |
195 | TopTools_IndexedMapOfShape MS; |
7fd59977 |
196 | for (; itL.More(); itL.Next()) { |
197 | MS.Add(itL.OldShape()); |
198 | } |
199 | return MakeShape(MS); |
200 | } |
201 | |
202 | //======================================================================= |
0df87563 |
203 | static void ApplyOrientation (TopTools_IndexedMapOfShape& MS, |
7fd59977 |
204 | const TopAbs_Orientation OrientationToApply) |
205 | { |
0df87563 |
206 | for (Standard_Integer anItMS = 1; anItMS <= MS.Extent(); ++anItMS) |
207 | { |
208 | MS.Substitute (anItMS, MS (anItMS).Oriented (OrientationToApply)); |
209 | } |
7fd59977 |
210 | } |
211 | |
212 | //======================================================================= |
213 | //function : CurrentShape |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | TopoDS_Shape TNaming_Tool::CurrentShape(const Handle(TNaming_NamedShape)& Att) |
218 | { |
0df87563 |
219 | TopTools_IndexedMapOfShape MS; |
7fd59977 |
220 | TDF_LabelList Deleted; |
221 | |
222 | TNaming_Iterator itL (Att); |
223 | for (; itL.More(); itL.Next()) { |
224 | const TopoDS_Shape& S = itL.NewShape(); |
225 | if (S.IsNull()) continue; |
7dcac1df |
226 | //OR-N |
7fd59977 |
227 | Standard_Boolean YaOrientationToApply(Standard_False); |
228 | TopAbs_Orientation OrientationToApply(TopAbs_FORWARD); |
229 | if(Att->Evolution() == TNaming_SELECTED) { |
7dcac1df |
230 | if (itL.More() && itL.NewShape().ShapeType() != TopAbs_VERTEX) { |
231 | Handle (TNaming_Naming) aNaming; |
232 | Att->Label().FindAttribute(TNaming_Naming::GetID(), aNaming); |
233 | if(!aNaming.IsNull()) { |
234 | if(aNaming->GetName().Type() == TNaming_ORIENTATION) { |
235 | OrientationToApply = aNaming->GetName().Orientation(); |
236 | } else { |
237 | Handle (TNaming_Naming) aNaming2; |
238 | TDF_ChildIterator it(aNaming->Label()); |
239 | for(;it.More();it.Next()) { |
240 | const TDF_Label& aLabel = it.Value(); |
241 | aLabel.FindAttribute(TNaming_Naming::GetID(), aNaming2); |
242 | if(!aNaming2.IsNull()) { |
243 | if(aNaming2->GetName().Type() == TNaming_ORIENTATION) { |
244 | OrientationToApply = aNaming2->GetName().Orientation(); |
245 | break; |
246 | } |
247 | } |
248 | } |
249 | } |
250 | if(OrientationToApply == TopAbs_FORWARD || OrientationToApply == TopAbs_REVERSED) |
251 | YaOrientationToApply = Standard_True; |
252 | } |
253 | } |
254 | } // |
7fd59977 |
255 | TNaming_NewShapeIterator it(itL); |
256 | if (!it.More()) { |
257 | MS.Add(S); |
258 | } |
259 | else { |
260 | // LastModif(it, MS, S, Deleted); |
0df87563 |
261 | TopTools_IndexedMapOfShape MS2; // to be optimized later |
7fd59977 |
262 | LastModif(it, MS2, S, Deleted); |
263 | if (YaOrientationToApply) ApplyOrientation (MS2, OrientationToApply); |
0df87563 |
264 | for (Standard_Integer anItMS2 = 1; anItMS2 <= MS2.Extent(); ++anItMS2) |
265 | MS.Add (MS2 (anItMS2)); |
7fd59977 |
266 | } |
267 | } |
268 | return MakeShape (MS); |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : CurrentShape |
273 | //purpose : |
274 | //======================================================================= |
275 | TopoDS_Shape TNaming_Tool::CurrentShape(const Handle(TNaming_NamedShape)& Att, |
276 | const TDF_LabelMap& Updated) |
277 | { |
278 | TDF_Label Lab = Att->Label(); |
279 | |
0df87563 |
280 | TopTools_IndexedMapOfShape MS; |
7fd59977 |
281 | TDF_LabelList Deleted; |
282 | |
283 | if (!Updated.Contains(Lab)) { |
284 | return TopoDS_Shape(); |
285 | } |
286 | |
287 | TNaming_Iterator itL (Att); |
288 | for (; itL.More(); itL.Next()) { |
289 | const TopoDS_Shape& S = itL.NewShape(); |
290 | if (S.IsNull()) continue; |
7dcac1df |
291 | //OR-N |
7fd59977 |
292 | Standard_Boolean YaOrientationToApply(Standard_False); |
293 | TopAbs_Orientation OrientationToApply(TopAbs_FORWARD); |
294 | if(Att->Evolution() == TNaming_SELECTED) { |
7dcac1df |
295 | if (itL.More() && itL.NewShape().ShapeType() != TopAbs_VERTEX) { |
296 | Handle (TNaming_Naming) aNaming; |
297 | Att->Label().FindAttribute(TNaming_Naming::GetID(), aNaming); |
298 | if(!aNaming.IsNull()) { |
299 | if(aNaming->GetName().Type() == TNaming_ORIENTATION) { |
300 | OrientationToApply = aNaming->GetName().Orientation(); |
301 | } else { |
302 | Handle (TNaming_Naming) aNaming2; |
303 | TDF_ChildIterator it(aNaming->Label()); |
304 | for(;it.More();it.Next()) { |
305 | const TDF_Label& aLabel = it.Value(); |
306 | aLabel.FindAttribute(TNaming_Naming::GetID(), aNaming2); |
307 | if(!aNaming2.IsNull()) { |
308 | if(aNaming2->GetName().Type() == TNaming_ORIENTATION) { |
309 | OrientationToApply = aNaming2->GetName().Orientation(); |
310 | break; |
311 | } |
312 | } |
313 | } |
314 | } |
315 | if(OrientationToApply == TopAbs_FORWARD || OrientationToApply == TopAbs_REVERSED) |
316 | YaOrientationToApply = Standard_True; |
317 | } |
7fd59977 |
318 | } |
7dcac1df |
319 | } // |
7fd59977 |
320 | TNaming_NewShapeIterator it(itL); |
321 | if (!it.More()) { |
322 | MS.Add(S); |
323 | } |
324 | else { |
325 | // LastModif(it, S, MS, Updated, Deleted); |
0df87563 |
326 | TopTools_IndexedMapOfShape MS2; // to be optimized later |
7fd59977 |
327 | LastModif(it, S, MS2, Updated, Deleted); |
328 | if (YaOrientationToApply) ApplyOrientation (MS2, OrientationToApply); |
0df87563 |
329 | for (Standard_Integer anItMS2 = 1; anItMS2 <= MS2.Extent(); ++anItMS2) |
330 | MS.Add(MS2 (anItMS2)); |
7fd59977 |
331 | } |
332 | } |
333 | return MakeShape (MS); |
334 | } |
335 | |
336 | //======================================================================= |
337 | //function : CurrentNamedShape |
338 | //purpose : |
339 | //======================================================================= |
340 | Handle(TNaming_NamedShape) TNaming_Tool::CurrentNamedShape(const Handle(TNaming_NamedShape)& Att, |
341 | const TDF_LabelMap& Updated) |
342 | { |
343 | TopoDS_Shape CS = CurrentShape(Att,Updated); |
344 | if (CS.IsNull()) { |
345 | Handle(TNaming_NamedShape) NS; |
346 | return NS; |
347 | } |
348 | return NamedShape(CS,Att->Label()); |
349 | } |
350 | |
351 | //======================================================================= |
352 | //function : CurrentNamedShape |
353 | //purpose : |
354 | //======================================================================= |
355 | Handle(TNaming_NamedShape) TNaming_Tool::CurrentNamedShape(const Handle(TNaming_NamedShape)& Att) |
356 | |
357 | { |
358 | TopoDS_Shape CS = CurrentShape(Att); |
359 | if (CS.IsNull()) { |
360 | Handle(TNaming_NamedShape) NS; |
361 | return NS; |
362 | } |
363 | return NamedShape(CS,Att->Label()); |
364 | } |
365 | |
366 | //======================================================================= |
367 | //function : FindModifUntil |
368 | //purpose : |
369 | //======================================================================= |
370 | |
371 | static void FindModifUntil (TNaming_NewShapeIterator& it, |
0df87563 |
372 | TopTools_IndexedMapOfShape& MS, |
7fd59977 |
373 | const Handle(TNaming_NamedShape)& Context) |
374 | { |
375 | for (; it.More(); it.Next()) { |
376 | if (!it.Shape().IsNull()) { |
377 | if (it.NamedShape() == Context) { |
378 | MS.Add(it.Shape()); |
379 | } |
380 | else { |
381 | TNaming_NewShapeIterator it2(it); |
382 | FindModifUntil (it2,MS,Context); |
383 | } |
384 | } |
385 | } |
386 | } |
387 | |
388 | //======================================================================= |
389 | //function : GeneratedShape |
390 | //purpose : |
391 | //======================================================================= |
392 | TopoDS_Shape TNaming_Tool::GeneratedShape(const TopoDS_Shape& S, |
393 | const Handle(TNaming_NamedShape)& Generation) |
394 | |
395 | { |
0df87563 |
396 | TopTools_IndexedMapOfShape MS; |
7fd59977 |
397 | Handle(TNaming_UsedShapes) US; |
398 | Generation->Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
399 | |
400 | for (TNaming_NewShapeIterator it(S,US); it.More(); it.Next()) { |
401 | if (!it.Shape().IsNull() && it.NamedShape() == Generation) { |
402 | MS.Add(it.Shape()); |
403 | } |
404 | } |
405 | if (MS.IsEmpty()) { |
406 | TNaming_NewShapeIterator it2(S,US); |
407 | FindModifUntil (it2,MS,Generation); |
408 | } |
409 | return MakeShape (MS); |
410 | } |
411 | |
412 | //======================================================================= |
413 | //function : FirstOlds |
414 | //purpose : |
415 | //======================================================================= |
416 | void TNaming_Tool::FirstOlds (const Handle(TNaming_UsedShapes)& US, |
417 | const TopoDS_Shape& S, |
418 | TNaming_OldShapeIterator& it, |
0df87563 |
419 | TopTools_IndexedMapOfShape& MS, |
7fd59977 |
420 | TDF_LabelList& Labels) |
421 | { |
422 | Standard_Integer TransDef; |
423 | Standard_Boolean YaModif = 0; |
424 | |
425 | for (; it.More(); it.Next()) { |
426 | if (it.IsModification()) { |
427 | YaModif = 1; |
428 | TNaming_OldShapeIterator it2(it); |
429 | if (!it2.More()) { |
430 | Labels.Append(TNaming_Tool::Label(US,it.Shape(),TransDef)); |
431 | MS.Add (it.Shape()); |
432 | } |
433 | else { |
434 | FirstOlds(US,it.Shape(),it2,MS,Labels); |
435 | } |
436 | } |
437 | } |
438 | if (!YaModif) MS.Add(S); |
439 | } |
440 | |
441 | //======================================================================= |
442 | //function : InitialShape |
443 | //purpose : |
444 | //======================================================================= |
445 | |
446 | TopoDS_Shape TNaming_Tool::InitialShape(const TopoDS_Shape& S, |
447 | const TDF_Label& Acces, |
448 | TDF_LabelList& Labels) |
449 | { |
450 | Handle(TNaming_UsedShapes) US; |
451 | Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
452 | TopoDS_Shape Res; |
453 | |
454 | if (!TNaming_Tool::HasLabel(US,S)) return Res; |
455 | |
456 | Standard_Integer Transdef; |
457 | Label(US,S,Transdef); |
0df87563 |
458 | TopTools_IndexedMapOfShape MS; |
7fd59977 |
459 | TNaming_OldShapeIterator it(S,Transdef,US); |
460 | if (!it.More()) { |
461 | return S; |
462 | } |
463 | else { |
464 | FirstOlds(US,S,it,MS,Labels); |
465 | } |
466 | return MakeShape(MS); |
467 | } |
468 | |
469 | |
470 | |
471 | //======================================================================= |
472 | //function : Back |
473 | //purpose : |
474 | //======================================================================= |
475 | |
476 | static void Back (const Handle(TNaming_NamedShape)& NS, |
477 | TNaming_MapOfNamedShape& MNS) |
478 | { |
479 | for (TNaming_Iterator it(NS); it.More(); it.Next()) { |
480 | if (it.NewShape().IsNull()) continue; |
481 | for (TNaming_OldShapeIterator Oldit(it); Oldit.More(); Oldit.Next()) { |
482 | const TopoDS_Shape& OS = Oldit.Shape(); |
483 | if (!OS.IsNull()) { |
484 | Handle(TNaming_NamedShape) NOS = TNaming_Tool::NamedShape(OS,NS->Label()); |
485 | // Continue de remonter |
486 | if (!NOS.IsNull()) { |
487 | if (MNS.Add(NOS)) Back (NOS,MNS); |
488 | } |
489 | } |
490 | } |
491 | } |
492 | } |
493 | |
494 | //======================================================================= |
495 | //function : Collect |
496 | //purpose : |
497 | //======================================================================= |
498 | |
499 | void TNaming_Tool::Collect(const Handle(TNaming_NamedShape)& NS, |
500 | TNaming_MapOfNamedShape& MNS, |
501 | const Standard_Boolean OnlyModif) |
502 | { |
503 | MNS.Add(NS); |
504 | Back (NS,MNS); |
505 | |
506 | for (TNaming_Iterator it(NS); it.More(); it.Next()) { |
507 | if (it.NewShape().IsNull()) continue; |
508 | for (TNaming_NewShapeIterator NewIt(it); NewIt.More(); NewIt.Next()) { |
509 | if (!OnlyModif || NewIt.IsModification()) { |
510 | // Continue la descente |
511 | Collect(NewIt.NamedShape(),MNS,OnlyModif); |
512 | } |
513 | } |
514 | } |
515 | } |
516 | |
517 | |
518 | // Pour DEBUGGER |
0797d9d3 |
519 | #ifdef OCCT_DEBUG |
7fd59977 |
520 | |
521 | //======================================================================= |
522 | //function : TNamingTool_Label |
523 | //purpose : |
524 | //======================================================================= |
525 | void TNamingTool_DumpLabel (const TopoDS_Shape& S, |
526 | const TDF_Label& Acces) |
527 | { |
528 | Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(S,Acces); |
529 | NS->Label().EntryDump(cout); |
530 | cout<<endl; |
531 | } |
532 | |
533 | #include <BRepTools.hxx> |
534 | //======================================================================= |
535 | //function : |
536 | //purpose : |
537 | //======================================================================= |
538 | void TNamingTool_Write (const TopoDS_Shape& S, |
539 | const Standard_CString File) |
540 | { |
541 | BRepTools::Write (S,File); |
542 | } |
543 | |
544 | #endif |
545 | |
546 | |
7fd59977 |
547 | //======================================================================= |
548 | //function : FindShape |
549 | //purpose : ANaming |
550 | //======================================================================= |
551 | |
552 | void TNaming_Tool::FindShape(const TDF_LabelMap& Valid, |
553 | const TDF_LabelMap& /*Forbiden*/, |
554 | const Handle(TNaming_NamedShape)& Arg, |
555 | TopoDS_Shape& S) |
556 | { |
557 | if (!Valid.IsEmpty() && !Valid.Contains(Arg->Label())) return; |
558 | if (Arg.IsNull() || Arg->IsEmpty()) return; |
559 | |
560 | // Which type of shape is being expected? |
561 | Handle(TNaming_Naming) aNaming; |
562 | if (!Arg->FindAttribute(TNaming_Naming::GetID(), aNaming)) { |
0797d9d3 |
563 | #ifdef OCCT_DEBUG |
7fd59977 |
564 | // cout<<"TNaming_Tool::FindShape(): Naming attribute hasn't been found attached at the Argument label"<<endl; |
565 | #endif |
566 | return; |
567 | } |
568 | |
569 | // Looking for sub shapes of the result shape |
570 | TopTools_MapOfShape subShapes; |
571 | TopExp_Explorer anExpl(Arg->Get(), (TopAbs_ShapeEnum)((int)(aNaming->GetName().ShapeType()) + 1)); |
572 | for (; anExpl.More(); anExpl.Next()) subShapes.Add(anExpl.Current()); |
0797d9d3 |
573 | #ifdef OCCT_DEBUG |
7fd59977 |
574 | // cout<<"TNaming_Tool::FindShape(): Nb of sub shapes = "<<subShapes.Extent()<<endl; |
575 | #endif |
576 | |
577 | // Looking for external arguments: |
578 | TNaming_ListOfNamedShape extArgs; |
579 | TDF_AttributeMap outRefs; |
580 | TDF_Tool::OutReferences(Arg->Label(), outRefs); |
581 | if (outRefs.IsEmpty()) { |
0797d9d3 |
582 | #ifdef OCCT_DEBUG |
7fd59977 |
583 | // cout<<"TNaming_Tool::FindShape(): No out references have been found"<<endl; |
584 | #endif |
585 | return; |
586 | } |
587 | for (TDF_MapIteratorOfAttributeMap itr(outRefs); itr.More(); itr.Next()) { |
588 | if (itr.Key()->DynamicType() == STANDARD_TYPE(TNaming_NamedShape)) { |
0797d9d3 |
589 | #ifdef OCCT_DEBUG |
7fd59977 |
590 | // Standard_Integer nbExtArgs = extArgs.Extent(); |
591 | #endif |
c5f3a425 |
592 | Handle(TNaming_NamedShape) anExtArg (Handle(TNaming_NamedShape)::DownCast(itr.Key())); |
7fd59977 |
593 | const Handle(TNaming_NamedShape)& aCurrentExtArg = TNaming_Tool::CurrentNamedShape(anExtArg); |
594 | if (!aCurrentExtArg.IsNull() && !aCurrentExtArg->IsEmpty()) |
595 | extArgs.Append(aCurrentExtArg); |
0797d9d3 |
596 | #ifdef OCCT_DEBUG |
7fd59977 |
597 | // if (extArgs.Extent() - 1 == nbExtArgs) { |
598 | // cout<<"TNaming_Tool::FindShape(): An external reference has been found at "; |
599 | // itr.Key()->Label().EntryDump(cout); cout<<endl; |
600 | // } |
601 | #endif |
602 | } |
603 | } |
604 | |
605 | // The iterator on external arguments: |
606 | TNaming_ListIteratorOfListOfNamedShape extArgsIterator (extArgs); |
607 | for(; extArgsIterator.More(); extArgsIterator.Next()) { |
608 | Handle(TNaming_NamedShape) anExtArg = extArgsIterator.Value(); |
609 | |
610 | // Looking for context: |
611 | Handle(TNaming_NamedShape) aContextNS; |
612 | if (anExtArg->Label().Father().IsNull() || |
613 | !anExtArg->Label().Father().FindAttribute(TNaming_NamedShape::GetID(), aContextNS)) { |
614 | aContextNS = anExtArg; |
0797d9d3 |
615 | // #ifdef OCCT_DEBUG |
7fd59977 |
616 | // cout<<"TNaming_Tool::FindShape(): A context shape hasn't been found at the father label of the external argument"<<endl; |
617 | // #endif |
618 | // continue; |
619 | } |
620 | |
0797d9d3 |
621 | #ifdef OCCT_DEBUG |
7fd59977 |
622 | // cout<<"TNaming_Tool::FindShape(): Searching in the external reference "; |
623 | // aContextNS->Label().EntryDump(cout); cout<<" "; |
624 | #endif |
625 | |
626 | // Lets find the sub shape of the context which coincides with our sub shapes (subShapes map): |
627 | TopExp_Explorer explC(aContextNS->Get(), aNaming->GetName().ShapeType()), explSubC; |
628 | for (; explC.More(); explC.Next()) { |
629 | Standard_Integer DoesCoincide = 0; |
630 | const TopoDS_Shape& possibleResult = explC.Current(); |
631 | TopTools_MapOfShape subShapesOfResult; |
632 | for (explSubC.Init(possibleResult, (TopAbs_ShapeEnum)((int)(aNaming->GetName().ShapeType()) + 1)); |
633 | explSubC.More(); explSubC.Next()) { |
634 | subShapesOfResult.Add(explSubC.Current()); |
635 | } |
636 | if (subShapesOfResult.Extent() != subShapes.Extent()) continue; |
637 | for (TopTools_MapIteratorOfMapOfShape itrR(subShapesOfResult); itrR.More(); itrR.Next()) { |
638 | for (TopTools_MapIteratorOfMapOfShape itr1(subShapes); itr1.More(); itr1.Next()) { |
639 | if (itrR.Key().IsSame(itr1.Key())) { |
640 | DoesCoincide++; //cout<<"."; |
641 | break; |
642 | } |
643 | } |
644 | } |
645 | if (DoesCoincide == subShapes.Extent()) { |
0797d9d3 |
646 | #ifdef OCCT_DEBUG |
7fd59977 |
647 | // cout<<"TNaming_Tool::FindShape(): Found! "; |
648 | #endif |
649 | S = possibleResult; |
650 | break; |
651 | } |
652 | } |
653 | |
654 | if (!S.IsNull()) break; |
0797d9d3 |
655 | #ifdef OCCT_DEBUG |
7fd59977 |
656 | // cout<<endl; |
657 | #endif |
658 | |
659 | } |
660 | |
0797d9d3 |
661 | #ifdef OCCT_DEBUG |
7fd59977 |
662 | if (S.IsNull()) { |
663 | cout<<"TNaming_Tool::FindShape(): There hasn't been found a sub shape of the context shape coinciding with the sub shapes of naming"<<endl; |
664 | } |
665 | #endif |
666 | |
667 | } |