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