Integration of adjusted testing cases.
[occt.git] / src / TNaming / TNaming.cxx
CommitLineData
b311480e 1// Created on: 1998-01-20
2// Created by: Yves FRICAUD
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <TNaming.ixx>
24
25#include <BRep_Builder.hxx>
26#include <BRep_Tool.hxx>
27#include <BRepBuilderAPI_Transform.hxx>
28#include <TopoDS.hxx>
29#include <TopoDS_Shape.hxx>
30#include <TopoDS_Compound.hxx>
31#include <TopExp_Explorer.hxx>
32#include <TopoDS_Iterator.hxx>
33#include <TopTools_MapOfShape.hxx>
34#include <TopTools_MapIteratorOfMapOfShape.hxx>
35#include <TopTools_ListOfShape.hxx>
36#include <TopTools_ListIteratorOfListOfShape.hxx>
37#include <TopTools_DataMapOfShapeShape.hxx>
38#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
39#include <TopTools_DataMapOfOrientedShapeShape.hxx>
40#include <TopTools_DataMapIteratorOfDataMapOfOrientedShapeShape.hxx>
7fd59977 41#include <TDF_Label.hxx>
42#include <TDF_ChildIterator.hxx>
43#include <TNaming_Builder.hxx>
44#include <TNaming_NamedShape.hxx>
45#include <TNaming_UsedShapes.hxx>
46#include <TNaming_ShapesSet.hxx>
47#include <TNaming_Iterator.hxx>
48#include <TNaming_NewShapeIterator.hxx>
49#include <TNaming_ListOfNamedShape.hxx>
50#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
51#include <TNaming_RefShape.hxx>
52#include <TNaming_DataMapOfShapePtrRefShape.hxx>
53#include <TNaming_Tool.hxx>
54
55// CopyShape
56#include <TColStd_IndexedDataMapOfTransientTransient.hxx>
57#include <TNaming_TranslateTool.hxx>
58#include <TopLoc_Datum3D.hxx>
59
60#define BUC60862
61#ifdef DEB
62//#define MDTV_DEB
63//#define MDTV_DEB_FSET
64#endif
65#ifdef MDTV_DEB
66#include <BRepTools.hxx>
67#include <TCollection_AsciiString.hxx>
68#include <TopTools_DataMapIteratorOfDataMapOfOrientedShapeShape.hxx>
69static void WriteS(const TopoDS_Shape& shape,
70 const Standard_CString filename)
71{
72 char buf[256];
73 if(strlen(filename) > 256) return;
74#if defined WNT
75 strcpy_s (buf, filename);
76#else
77 strcpy (buf, filename);
78#endif
79 char* p = buf;
80 while (*p) {
81 if(*p == ':')
82 *p = '-';
83 p++;
84 }
85 ofstream save (buf);
86 if(!save)
87 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
88 save << "DBRep_DrawableShape" << endl << endl;
89 if(!shape.IsNull()) BRepTools::Write(shape, save);
90 save.close();
91}
92#endif
93//=======================================================================
94//function : MapShapes
95//purpose : TNaming
96//=======================================================================
97
98static void MapShapes(const TopoDS_Shape& SCible, const TopoDS_Shape& SSource, TopTools_DataMapOfShapeShape& M)
99{
100 M.Bind(SCible,SSource);
101 TopoDS_Iterator icible(SCible);
102 TopoDS_Iterator isource(SSource);
103 while (icible.More()) {
104 if (!M.IsBound(icible.Value())) MapShapes(icible.Value(),isource.Value(),M);
105 icible.Next();
106 isource.Next();
107 }
108}
109
110//=======================================================================
111//function : MapShapes
112//purpose : TNaming
113//=======================================================================
114
115static void MapShapes(const TDF_Label& LCible, const TDF_Label& LSource, TopTools_DataMapOfShapeShape& M)
116{
117 TNaming_Iterator icible(LCible);
118 TNaming_Iterator isource(LSource);
119 while (icible.More()) {
120 if (!icible.OldShape().IsNull()) {
121 if (!M.IsBound(icible.OldShape())) MapShapes(icible.OldShape(),isource.OldShape(),M);
122 }
123 if (!icible.NewShape().IsNull()) {
124 if (!M.IsBound(icible.NewShape())) MapShapes(icible.NewShape(),isource.NewShape(),M);
125 }
126 icible.Next();
127 isource.Next();
128 }
129
130 TDF_ChildIterator iccible(LCible);
131 TDF_ChildIterator icsource(LSource);
132 while (iccible.More()) {
133 MapShapes(iccible.Value(),icsource.Value(),M);
134 iccible.Next();
135 icsource.Next();
136 }
137}
138
139//=======================================================================
140//function : SubstituteShape
141//purpose : TNaming
142//=======================================================================
143
144void static SubstituteShape(const TopoDS_Shape& oldShape,
145 const TopoDS_Shape& newShape,
146 TNaming_DataMapOfShapePtrRefShape& amap)
147{
148 if (oldShape.IsSame(newShape)) {
149 cout <<"import_tool::Substitute : oldShape IsSame newShape"<<endl;
150 }
151
152 if (!amap.IsBound(oldShape)) {
153 return;
154 }
155 TNaming_RefShape* pos;
156 pos = amap.ChangeFind(oldShape);
157 pos->Shape(newShape);
158 amap.UnBind(oldShape);
159 amap.Bind(newShape,pos);
160}
161
162//=======================================================================
163//function : MakeShape
164//purpose : ANaming
165//=======================================================================
166
167TopoDS_Shape TNaming::MakeShape (const TopTools_MapOfShape& MS)
168{
169 if (!MS.IsEmpty ()) {
170 TopTools_MapIteratorOfMapOfShape it(MS);
171 if (MS.Extent() == 1) {
172 return it.Key();
173 }
174 else {
175 TopoDS_Compound C;
176 BRep_Builder B;
177 B.MakeCompound(C);
178 for (; it.More(); it.Next()){
179 B.Add(C,it.Key());
180 }
181 return C;
182 }
183 }
184 return TopoDS_Shape();
185}
186
187//=======================================================================
188//function : Substitute
189//purpose : TNaming
190//=======================================================================
191
192void TNaming::Substitute(const TDF_Label& LSource,
193 const TDF_Label& LCible ,
194 TopTools_DataMapOfShapeShape& M)
195{
196//attention pour etre en parallele au niveau structure il faut que Lciblble corresponde au premier fils recopie
197 MapShapes(LCible,LSource,M);
198 Handle(TNaming_UsedShapes) US;
199 LCible.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
200 TNaming_DataMapOfShapePtrRefShape& amap = US->Map();
201 for (TopTools_DataMapIteratorOfDataMapOfShapeShape It(M);It.More();It.Next()) {
202 SubstituteShape(It.Key(),It.Value(),amap);
203 }
204}
205
206//=======================================================================
207//function : SubstituteSShape
208//purpose :
209//=======================================================================
210Standard_Boolean TNaming::SubstituteSShape(const TDF_Label& Lab, const TopoDS_Shape& From, TopoDS_Shape& To)
211{
212 Handle(TNaming_UsedShapes) US;
213 Lab.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
214 TNaming_DataMapOfShapePtrRefShape& amap = US->Map();
215 if (!amap.IsBound(To))
216 return Standard_False;
217 TNaming_RefShape* pos;
218 pos = amap.ChangeFind(To);
219 if(!amap.UnBind(To)) return Standard_False;
220 //update shape
221 To.Orientation(From.Orientation());
222 pos->Shape(To);
223 return amap.Bind(To, pos);
224}
225
226//=======================================================================
227//function : Rebuild
228//purpose : TNaming
229//=======================================================================
230
231static Standard_Boolean Rebuild (const TopoDS_Shape& S,
232 TopTools_DataMapOfShapeShape& M)
233{
234 Standard_Boolean IsModified = Standard_False;
235 if (M.IsBound(S)) return IsModified;
236
237 BRep_Builder B;
238 TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
239
240 // Reconstruction des sous shapes si necessaire.
241 for (; iteS.More(); iteS.Next()) {
242 const TopoDS_Shape& SS = iteS.Value();
243 if (Rebuild (SS,M)) IsModified = Standard_True;
244 }
245 if (!IsModified) {
246 M.Bind(S,S);
247 return Standard_True;
248 }
249
250 // Reconstruction de S
251 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
252 NewS.EmptyCopy();
253 if (NewS.ShapeType() == TopAbs_EDGE) {
254 Standard_Real f,l;
255 BRep_Tool::Range(TopoDS::Edge(S),f,l);
256 B.Range(TopoDS::Edge(NewS),f,l);
257 }
258 iteS.Initialize(S.Oriented(TopAbs_FORWARD));
259 for (iteS.Initialize(S.Oriented(TopAbs_FORWARD)) ;iteS.More(); iteS.Next()) {
260 const TopoDS_Shape& OS = iteS.Value();
261 const TopoDS_Shape& NS = M(OS);
262 B.Add(NewS,NS.Oriented(OS.Orientation()));
263 }
264 M.Bind (S,NewS.Oriented(S.Orientation()));
265 return IsModified;
266}
267
268
269//=======================================================================
270//function : Update
271//purpose : TNaming
272//=======================================================================
273
274void TNaming::Update(const TDF_Label& L,
275 TopTools_DataMapOfShapeShape& M)
276
277{
278 //Reconstruction des shapes de L suite aux substitutions decrites dans la map M.
279 // ex : si une face est remplacee par une autre il faut reconstruire les shapes
280 // qui contiennent cette face.
281 Handle(TNaming_UsedShapes) US;
282 L.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
283 TNaming_DataMapOfShapePtrRefShape& amap = US->Map();
284
285 Standard_Boolean Change = Standard_False;
286 for (TNaming_Iterator it(L); it.More(); it.Next()) {
287 if (!it.OldShape().IsNull()) {
288 const TopoDS_Shape& S = it.OldShape();
289 if (!M.IsBound(S))
290 if (Rebuild (S,M)) Change = Standard_True;
291 SubstituteShape(S,M(S),amap);
292 }
293 if (!it.NewShape().IsNull()) {
294 const TopoDS_Shape& S = it.NewShape();
295 if (!M.IsBound(S))
296 if (Rebuild (S,M)) Change = Standard_True;
297 SubstituteShape(S,M(S),amap);
298 }
299 }
300
301 // SI Les shapes dans les sous-labels sont des sous shapes des shapes de L
302 // si les shapes de L n ont pas changes les shapes des sous-labels ne seront
303 // pas changes non plus.
304 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
305 TNaming::Update (ciL.Value(),M);
306 }
307}
308
309//=======================================================================
310//function : BuilCompound
311//purpose : TNaming
312//=======================================================================
313
314static void BuildCompound(TopoDS_Compound& C,
315 const TDF_Label& L)
316{
317 BRep_Builder B;
318 for (TNaming_Iterator it(L); it.More(); it.Next()) {
319 if (!it.OldShape().IsNull()) {
320 B.Add(C,it.OldShape());
321 }
322 if (!it.NewShape().IsNull()) {
323 B.Add(C,it.NewShape());
324 }
325 }
326 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
327 BuildCompound (C,ciL.Value());
328 }
329}
330
331//=======================================================================
332//function : Update
333//purpose : TNaming
334//=======================================================================
335
336static void BuildMap(const TDF_Label& L,
337 BRepBuilderAPI_Transform& Transformer,
338 TopTools_DataMapOfShapeShape& M)
339{
340 Handle(TNaming_UsedShapes) US;
341 L.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
342 for (TNaming_Iterator it(L); it.More(); it.Next()) {
343 if (!it.OldShape().IsNull()) {
344 const TopoDS_Shape& S = it.OldShape();
345 M.Bind(S,Transformer.ModifiedShape(S));
346 }
347 if (!it.NewShape().IsNull()) {
348 const TopoDS_Shape& S = it.NewShape();
349 M.Bind(S,Transformer.ModifiedShape(S));
350 }
351 }
352 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
353 BuildMap (ciL.Value(),Transformer,M);
354 }
355}
356
357//=======================================================================
358//function : LoadNamedShape
359//purpose : TNaming
360//=======================================================================
361
362static void LoadNamedShape (TNaming_Builder& B,
363 TNaming_Evolution Evol,
364 const TopoDS_Shape& OS,
365 const TopoDS_Shape& NS)
366{
367 switch (Evol) {
368 case TNaming_PRIMITIVE :
369 {
370 B.Generated(NS);
371 break;
372 }
373 case TNaming_GENERATED :
374 {
375 B.Generated(OS,NS);
376 break;
377 }
378 case TNaming_MODIFY :
379 {
380 B.Modify(OS,NS);
381 break;
382 }
383 case TNaming_DELETE :
384 {
385 B.Delete (OS);
386 break;
387 }
388 case TNaming_SELECTED :
389 {
390 B.Select(NS,OS);
391 }
392 default:
393 break;
394 }
395}
396
397//=======================================================================
398//function : Displace
399//purpose : TNaming
400//=======================================================================
401
402void TNaming::Displace (const TDF_Label& L,
403 const TopLoc_Location& Loc,
404 const Standard_Boolean WithOld)
405{
406
407
408 TopTools_ListOfShape Olds;
409 TopTools_ListOfShape News;
410 TNaming_Evolution Evol;
411 TNaming_Iterator it(L);
412
413 if (it.More()) { // dp on continue de visiter les fils meme s'il y a pas de shape
414 Evol = it.Evolution();
415 for ( ; it.More(); it.Next()) {
416 Olds.Append(it.OldShape());
417 News.Append(it.NewShape());
418
419 }
420
421 TopTools_ListIteratorOfListOfShape itOlds(Olds);
422 TopTools_ListIteratorOfListOfShape itNews(News);
423 TNaming_Builder B(L);
424
425 for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) {
426 TopoDS_Shape OS,NS;
427 const TopoDS_Shape& SO = itOlds.Value();
428 const TopoDS_Shape& SN = itNews.Value();
429 OS = SO;
430 if (WithOld && !SO.IsNull()) OS = SO.Moved(Loc);
431 if (!SN.IsNull()) NS = SN.Moved(Loc);
432
433 LoadNamedShape ( B, Evol, OS, NS);
434 }
435 }
436 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
437 Displace (ciL.Value(),Loc);
438 }
439}
440
441//=======================================================================
442//function : Replace
443//purpose : TNaming
444//=======================================================================
445
446static void Replace (const TDF_Label& L,
447 const TopTools_DataMapOfShapeShape& M)
448{
449
450 TNaming_Evolution Evol;
451 TNaming_Iterator it(L);
452
453 if (!it.More()) return;
454 Evol = it.Evolution();
455
456 TNaming_Builder B(L);
457
458 TopoDS_Shape OS,NS;
459
460 for ( ; it.More(); it.Next()) {
461 if (!it.OldShape().IsNull()) {
462 OS = it.OldShape();
463 if (M.IsBound(OS)) OS = M(OS);
464 }
465 if (!it.NewShape().IsNull()) {
466 NS = it.NewShape();
467 if (M.IsBound(NS)) NS = M(NS);
468 }
469 LoadNamedShape ( B, Evol, OS, NS);
470 }
471 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
472 Replace (ciL.Value(),M);
473 }
474}
475
476//=======================================================================
477//function : Update
478//purpose : TNaming
479//=======================================================================
480
481void TNaming::Transform(const TDF_Label& L,
482 const gp_Trsf& T)
483{
484
485 //--------------------------------------------------------------------
486 // Construction du compound qui contient tous les shapes sous le label
487 // et ses fils.
488 //--------------------------------------------------------------------
489 TopoDS_Compound CompShape;
490 BRep_Builder B;
491 B.MakeCompound(CompShape);
492
493 BuildCompound (CompShape,L);
494
495 //----------------------------
496 // Transformation du compound.
497 //-----------------------------
498 BRepBuilderAPI_Transform Transformer(CompShape, T);
499
500 //-----------------------------------------------------------
501 //Remplacement des shapes initiaux par les shapes transformes.
502 //-----------------------------------------------------------
503 TopTools_DataMapOfShapeShape M;
504 BuildMap (L,Transformer,M);
505 Replace (L,M);
506}
507
508//=======================================================================
509//function : IDList
510//purpose : TNaming
511//=======================================================================
512
513void TNaming::IDList(TDF_IDList& anIDList)
514{ anIDList.Append(TNaming_NamedShape::GetID()); }
515
516
517//=======================================================================
518//function : Replicate
519//purpose :
520//=======================================================================
521
522void TNaming::Replicate(const Handle(TNaming_NamedShape)& NS,
523 const gp_Trsf& T,
524 const TDF_Label& L)
525{
526 TopoDS_Shape SH = TNaming_Tool::CurrentShape(NS);
527 TNaming::Replicate(SH, T, L);
528}
529
530//=======================================================================
531//function : Replicate
532//purpose : TNaming
533//=======================================================================
534
535void TNaming::Replicate (const TopoDS_Shape& SH,
536 const gp_Trsf& T,
537 const TDF_Label& L)
538{
539 // transform
540 BRepBuilderAPI_Transform opeTrsf(T);
541 if (SH.ShapeType() == TopAbs_FACE || SH.ShapeType() == TopAbs_WIRE ) {
542 opeTrsf.Perform(SH, Standard_True); // pour le pattern de prism
543 }
544 else {
545 opeTrsf.Perform(SH, Standard_False);
546 }
547 const TopoDS_Shape& newSH = opeTrsf.Shape();
548 //BRepLib::UpdateTolerances(newSH, Standard_True);
549
550 // principal shape
551
552 TNaming_Builder Builder(L);
553 Builder.Generated(SH, newSH);
554
555 // sub shape
556 TopAbs_ShapeEnum SST = TopAbs_FACE;
557 if (SH.ShapeType() == TopAbs_FACE || SH.ShapeType() == TopAbs_WIRE )
558 SST = TopAbs_EDGE;
559
560 TNaming_Builder Builder2 (L.FindChild(1,Standard_True));
561 for (TopExp_Explorer exp(SH, SST); exp.More(); exp.Next()) {
562 const TopoDS_Shape& oldSubShape = exp.Current();
563 const TopoDS_Shape& newSubShape = opeTrsf.ModifiedShape(oldSubShape);
564 Builder2.Generated(oldSubShape, newSubShape);
565 }
566}
567
568
569//=======================================================================
570//function : ShapeCopy
571//purpose : TNaming
572//=======================================================================
573
574static TopoDS_Shape ShapeCopy(const TopoDS_Shape& S,
575 TopTools_DataMapOfShapeShape& M)
576{
577 if (S.IsNull()) return S;
578 if (M.IsBound(S)) return M(S);
579 //----------------------------
580 //construction de la copie.
581 // 1- copie des sous shapes.
582 // 2- reconstruction du TShape
583 //----------------------------
584 BRep_Builder B;
585 TopoDS_Iterator it (S.Oriented(TopAbs_FORWARD));
586
587 for ( ; it.More(); it.Next()) {
588 const TopoDS_Shape& SS = it.Value();
589 TopoDS_Shape NewSS = ShapeCopy(SS,M);
590 }
591 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
592 NewS.EmptyCopy();
593 if (NewS.ShapeType() == TopAbs_EDGE) {
594 Standard_Real f,l;
595 BRep_Tool::Range(TopoDS::Edge(S),f,l);
596 B.Range(TopoDS::Edge(NewS),f,l);
597 }
598 for (it.Initialize(S.Oriented(TopAbs_FORWARD)) ;it.More(); it.Next()) {
599 const TopoDS_Shape& OS = it.Value();
600 const TopoDS_Shape& NS = M(OS);
601 B.Add(NewS,NS.Oriented(OS.Orientation()));
602 }
603 NewS.Orientation(S.Orientation());
604
605 NewS.Free (S.Free()) ;NewS.Modified(S.Modified());NewS.Checked (S.Checked());
606 NewS.Orientable(S.Orientable());NewS.Closed (S.Closed()) ;NewS.Infinite(S.Infinite());
607 NewS.Convex (S.Convex());
608
609 M.Bind (S,NewS);
610 return NewS;
611}
612
613//=======================================================================
614//function : ChangeShapes
615//purpose : TNaming
616//=======================================================================
617
618void TNaming::ChangeShapes(const TDF_Label& L,
619 TopTools_DataMapOfShapeShape& M)
620{
621 TopTools_ListOfShape Olds;
622 TopTools_ListOfShape News;
623
624 Handle(TNaming_NamedShape) NS;
625 L.FindAttribute(TNaming_NamedShape::GetID(),NS);
626
627 if (!NS.IsNull()) {
628 TNaming_Evolution Evol = NS->Evolution();
629 for (TNaming_Iterator it(L); it.More(); it.Next()) {
630 const TopoDS_Shape& S1 = it.OldShape();
631 const TopoDS_Shape& S2 = it.NewShape();
632 Olds.Append(ShapeCopy(S1,M));News.Append(ShapeCopy(S2,M));
633 }
634
635 TopTools_ListIteratorOfListOfShape itOlds(Olds);
636 TopTools_ListIteratorOfListOfShape itNews(News);
637
638 TNaming_Builder B(L);
639
640 for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) {
641 LoadNamedShape ( B, Evol, itOlds.Value(), itNews.Value());
642 }
643 }
644
645 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
646 ChangeShapes (ciL.Value(),M);
647 }
648}
649
650
651//=======================================================================
652//function :
653//purpose :
654//=======================================================================
655
656Standard_OStream& TNaming::Print (const TNaming_Evolution EVOL, Standard_OStream& s)
657{
658 switch(EVOL){
659 case TNaming_PRIMITIVE :
660 {
661 s <<"PRIMITIVE"; break;
662 }
663 case TNaming_GENERATED :
664 {
665 s <<"GENERATED"; break;
666 }
667 case TNaming_MODIFY :
668 {
669 s <<"MODIFY"; break;
670 }
671 case TNaming_DELETE :
672 {
673 s <<"DELETE"; break;
674 }
675 case TNaming_SELECTED :
676 {
677 s <<"SELECTED"; break;
678 }
679 default :
680 s << "UNKNOWN_Evolution"; break;
681 }
682 return s;
683}
684
685
686
687//=======================================================================
688//function :
689//purpose :
690//=======================================================================
691
692Standard_OStream& TNaming::Print (const TNaming_NameType NAME, Standard_OStream& s)
693{
694
695 switch (NAME) {
696 case TNaming_UNKNOWN :
697 {
698 s <<"UNKNOWN"; break;
699 }
700 case TNaming_IDENTITY :
701 {
702 s <<"IDENTITY"; break;
703 }
704 case TNaming_MODIFUNTIL :
705 {
706 s <<"MODIFUNTIL"; break;
707 }
708 case TNaming_GENERATION :
709 {
710 s <<"GENERATION"; break;
711 }
712 case TNaming_INTERSECTION :
713 {
714 s <<"INTERSECTION"; break;
715 }
716 case TNaming_UNION:
717 {
718 s <<"UNION"; break;
719 }
720 case TNaming_SUBSTRACTION :
721 {
722 s <<"SUBSTRACTION"; break;
723 }
724 case TNaming_CONSTSHAPE :
725 {
726 s <<"CONSTSHAPE"; break;
727 }
728 case TNaming_FILTERBYNEIGHBOURGS:
729 {
730 s <<"FILTERBYNEIGHBOURGS"; break;
731 }
732 case TNaming_ORIENTATION:
733 {
734 s <<"ORIENTATION"; break;
735 }
736 case TNaming_WIREIN:
737 {
738 s <<"WIREIN"; break;
739 }
740 default :
741 {
742 s <<"UNKNOWN_NameType"; break;
743 }
744 }
745 return s;
746}
747
748#ifdef BUC60862
749
750//=======================================================================
751//function : Print
752//purpose : Prints UsedShapes.
753//=======================================================================
754
755Standard_OStream& TNaming::Print (const TDF_Label& ACCESS, Standard_OStream& s) {
756 Handle(TNaming_UsedShapes) US;
757 if (!ACCESS.Root().FindAttribute(TNaming_UsedShapes::GetID(), US)) {
758#ifdef DEB
759 cout<<"TNaming::Print(US): Bad access"<<endl;
760#endif
761 return s;
762 }
763 return US->Dump(s);
764}
765
766#endif
767
768//=======================================================================
769//function : BuildMapIn
770//purpose :
771//=======================================================================
772static void BuildMapIn(const TopoDS_Shape& Context, const TopAbs_ShapeEnum StopType,
773 TopTools_DataMapOfOrientedShapeShape& Map)
774{
775 TopAbs_ShapeEnum aType;
776 if((Context.ShapeType() == TopAbs_SOLID || Context.ShapeType() == TopAbs_FACE) && (StopType - Context.ShapeType()) != 1)
777 aType = (TopAbs_ShapeEnum)(Context.ShapeType() +2);
778 else
779 aType = (TopAbs_ShapeEnum)(Context.ShapeType()+1);
780 for (TopExp_Explorer exp(Context,aType); exp.More(); exp.Next()) {
781#ifdef MDTV_DEB
782 if(!Map.Bind(exp.Current(), Context))
783 cout << "Not bind = " <<exp.Current().ShapeType() <<endl;
784 else
785 cout <<"Bind = " <<exp.Current().ShapeType() << " to Context = " <<Context.ShapeType()<<endl;
786#else
787 Map.Bind(exp.Current(), Context);
788#endif
789 if(exp.Current().ShapeType() < StopType ) {
790 BuildMapIn(exp.Current(), StopType, Map);
791 }
792 }
793 // fix for NMT case
794 if(Context.ShapeType() < StopType) {
795 TopoDS_Iterator it(Context);
796 for(;it.More();it.Next()) {
797 if(it.Value().Orientation() != TopAbs_FORWARD && it.Value().Orientation() != TopAbs_REVERSED) {
798 Map.Bind(it.Value(), Context);
799 //cout << "INTERNAL || EXTERNAL Orientation found" <<endl;
800 }
801 }
802 }
803}
804//=======================================================================
805//function : BuildMapC0
806//purpose : builds data map: key - context, C0 - top context
807//=======================================================================
808static void BuildMapC0(const TopoDS_Shape& Context, const TopoDS_Shape& C0, const TopAbs_ShapeEnum StopType,
809 TopTools_DataMapOfOrientedShapeShape& Map)
810{
811 TopoDS_Iterator anIt(Context);
812 while(anIt.More()) {
813 const TopoDS_Shape& aKey = anIt.Value();
814#ifdef MDTV_DEB
815 if(!Map.Bind(aKey, C0))
816 cout << "Not bind = " <<aKey.ShapeType() <<endl;
817#else
818 Map.Bind(aKey, C0);
819#endif
820 if(aKey.ShapeType() < StopType ) {
821 if(aKey.ShapeType() < TopAbs_SOLID) {
822 BuildMapC0(aKey, Context, StopType, Map);
823 }
824 else
825 BuildMapIn(aKey, StopType, Map);
826 }
827 anIt.Next();
828 }
829}
830
831//=======================================================================
832//function : BuildMap
833//purpose : builds data map: key - context
834//=======================================================================
835static void BuildMap(const TopoDS_Shape& Context, const TopAbs_ShapeEnum StopType,
836 TopTools_DataMapOfOrientedShapeShape& Map)
837{
838#ifdef MDTV_DEB
839 TCollection_AsciiString Nam("Cnt_");
840 Standard_Integer i = 0;
841#endif
842 TopoDS_Iterator anIt(Context);
843 while(anIt.More()) {
844 const TopoDS_Shape& aKey = anIt.Value();
845#ifdef MDTV_DEB
846 if(!Map.Bind(aKey, Context))
847 cout << "Not bind = " <<aKey.ShapeType() <<endl;
848#else
849 Map.Bind(aKey, Context);
850#endif
851 if(aKey.ShapeType() < StopType ) {
852 if(aKey.ShapeType() < TopAbs_SOLID)
853 BuildMapC0(aKey, Context, StopType, Map);
854 else
855 BuildMapIn(aKey, StopType, Map);
856 }
857 anIt.Next();
858 }
859}
860//=======================================================================
861//function : FindUniqueContext
862//purpose : Find unique context of selection
863//=======================================================================
864TopoDS_Shape TNaming::FindUniqueContext(const TopoDS_Shape& Selection, const TopoDS_Shape& Context)
865{
866 TopTools_DataMapOfOrientedShapeShape aMap;
867 BuildMap(Context, Selection.ShapeType(), aMap);
868#ifdef MDTV_DEB
869 TopTools_DataMapIteratorOfDataMapOfOrientedShapeShape it (aMap);
870 for (;it.More();it.Next()) {
871 cout <<"FindUniqueContext: Key - " <<it.Key().ShapeType()<< " " << it.Key().TShape() <<" OR = " <<it.Key().Orientation() <<
872 " Context - " << it.Value().ShapeType() << " " << it.Value().TShape() << " OR = " <<it.Value().Orientation() <<endl;
873 }
874#endif
875 if(aMap.IsBound(Selection))
876 return aMap.Find(Selection);
877 return TopoDS_Shape();
878}
879
880//=======================================================================
881//function : FindUniqueContexts
882//purpose : Find unique context of selection which is pure concatenation
883// : of atomic shapes (Compound)
884//=======================================================================
885TopoDS_Shape TNaming::FindUniqueContextSet(const TopoDS_Shape& Selection, const TopoDS_Shape& Context,
886 Handle(TopTools_HArray1OfShape)& Arr)
887{
888 if(Selection.ShapeType() == TopAbs_COMPOUND) {
889 TopTools_DataMapOfOrientedShapeShape aMap;
890 Standard_Integer Up(0);
891 TopAbs_ShapeEnum aStopType(TopAbs_COMPOUND);
892 TopoDS_Iterator it(Selection);
893 for(;it.More(); it.Next()) {
894 const TopoDS_Shape& aS = it.Value();
895 if(aS.ShapeType() > aStopType)
896 aStopType = aS.ShapeType();
897 Up++;
898 }
899 if(Up > 0)
900 Arr = new TopTools_HArray1OfShape(1, Up);
901 if(aStopType == TopAbs_SHAPE)
902 aStopType = Selection.ShapeType();
903 BuildMap(Context, aStopType, aMap);
904 if(aMap.IsBound(Selection))
905 return aMap.Find(Selection);
906 else if(Selection.ShapeType() == TopAbs_COMPOUND) {
907 Standard_Integer num1(0),num2(0);
908 TopoDS_Compound CompShape;
909 BRep_Builder B;
910 B.MakeCompound(CompShape);
911 TopoDS_Iterator it(Selection);
912 TopTools_MapOfShape aView;
913 for(;it.More(); it.Next(),num1++) {
914 if(aMap.IsBound(it.Value())) {
915 if(aView.Add(aMap.Find(it.Value()))) {
916 B.Add(CompShape, aMap.Find(it.Value()));
917 }
918 if(!Arr.IsNull())
919 Arr->SetValue(num1+1, aMap.Find(it.Value()));
920
921 if(aMap.Find(it.Value()) == Context)
922 num2++;
923 }
924 }
925 if(num1 == num2 && num2)
926 return Context;
927 else {
928 TopoDS_Iterator it(CompShape);
929 Standard_Integer n(0);
930 TopoDS_Shape aCmp;
931 for(;it.More();it.Next()) {
932 n++;
933 aCmp = it.Value();
934 }
935 if(n == 1) {
936#ifdef MDTV_DEB_FSET
937 cout << "FindUniqueContextSet: n = " << n <<endl;
938#endif
939 return aCmp;
940 }
941 return CompShape;
942 }
943 }
944 }
945 return TopoDS_Shape();
946}
947
948
949
950