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