1 // Created on: 1998-01-20
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TNaming.ixx>
19 #include <BRep_Builder.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepBuilderAPI_Transform.hxx>
23 #include <TopoDS_Shape.hxx>
24 #include <TopoDS_Compound.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopTools_MapOfShape.hxx>
28 #include <TopTools_MapIteratorOfMapOfShape.hxx>
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <TopTools_DataMapOfShapeShape.hxx>
32 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
33 #include <TopTools_DataMapOfOrientedShapeShape.hxx>
34 #include <TopTools_DataMapIteratorOfDataMapOfOrientedShapeShape.hxx>
35 #include <TDF_Label.hxx>
36 #include <TDF_ChildIterator.hxx>
37 #include <TNaming_Builder.hxx>
38 #include <TNaming_NamedShape.hxx>
39 #include <TNaming_UsedShapes.hxx>
40 #include <TNaming_ShapesSet.hxx>
41 #include <TNaming_Iterator.hxx>
42 #include <TNaming_NewShapeIterator.hxx>
43 #include <TNaming_ListOfNamedShape.hxx>
44 #include <TNaming_ListIteratorOfListOfNamedShape.hxx>
45 #include <TNaming_RefShape.hxx>
46 #include <TNaming_DataMapOfShapePtrRefShape.hxx>
47 #include <TNaming_Tool.hxx>
49 #include <IntTools_FClass2d.hxx>
50 #include <BRepClass3d_SolidClassifier.hxx>
53 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
54 #include <TNaming_TranslateTool.hxx>
55 #include <TopLoc_Datum3D.hxx>
57 //=======================================================================
58 //function : MapShapes
60 //=======================================================================
62 static void MapShapes(const TopoDS_Shape& SCible, const TopoDS_Shape& SSource, TopTools_DataMapOfShapeShape& M)
64 M.Bind(SCible,SSource);
65 TopoDS_Iterator icible(SCible);
66 TopoDS_Iterator isource(SSource);
67 while (icible.More()) {
68 if (!M.IsBound(icible.Value())) MapShapes(icible.Value(),isource.Value(),M);
74 //=======================================================================
75 //function : MapShapes
77 //=======================================================================
79 static void MapShapes(const TDF_Label& LCible, const TDF_Label& LSource, TopTools_DataMapOfShapeShape& M)
81 TNaming_Iterator icible(LCible);
82 TNaming_Iterator isource(LSource);
83 while (icible.More()) {
84 if (!icible.OldShape().IsNull()) {
85 if (!M.IsBound(icible.OldShape())) MapShapes(icible.OldShape(),isource.OldShape(),M);
87 if (!icible.NewShape().IsNull()) {
88 if (!M.IsBound(icible.NewShape())) MapShapes(icible.NewShape(),isource.NewShape(),M);
94 TDF_ChildIterator iccible(LCible);
95 TDF_ChildIterator icsource(LSource);
96 while (iccible.More()) {
97 MapShapes(iccible.Value(),icsource.Value(),M);
103 //=======================================================================
104 //function : SubstituteShape
106 //=======================================================================
108 static void SubstituteShape(const TopoDS_Shape& oldShape,
109 const TopoDS_Shape& newShape,
110 TNaming_DataMapOfShapePtrRefShape& amap)
112 if (oldShape.IsSame(newShape)) {
113 cout <<"import_tool::Substitute : oldShape IsSame newShape"<<endl;
116 if (!amap.IsBound(oldShape)) {
119 TNaming_RefShape* pos;
120 pos = amap.ChangeFind(oldShape);
121 pos->Shape(newShape);
122 amap.UnBind(oldShape);
123 amap.Bind(newShape,pos);
126 //=======================================================================
127 //function : MakeShape
129 //=======================================================================
131 TopoDS_Shape TNaming::MakeShape (const TopTools_MapOfShape& MS)
133 if (!MS.IsEmpty ()) {
134 TopTools_MapIteratorOfMapOfShape it(MS);
135 if (MS.Extent() == 1) {
142 for (; it.More(); it.Next()){
148 return TopoDS_Shape();
151 //=======================================================================
152 //function : Substitute
154 //=======================================================================
156 void TNaming::Substitute(const TDF_Label& LSource,
157 const TDF_Label& LCible ,
158 TopTools_DataMapOfShapeShape& M)
160 //attention pour etre en parallele au niveau structure il faut que Lciblble corresponde au premier fils recopie
161 MapShapes(LCible,LSource,M);
162 Handle(TNaming_UsedShapes) US;
163 LCible.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
164 TNaming_DataMapOfShapePtrRefShape& amap = US->Map();
165 for (TopTools_DataMapIteratorOfDataMapOfShapeShape It(M);It.More();It.Next()) {
166 SubstituteShape(It.Key(),It.Value(),amap);
170 //=======================================================================
171 //function : SubstituteSShape
173 //=======================================================================
174 Standard_Boolean TNaming::SubstituteSShape(const TDF_Label& Lab, const TopoDS_Shape& From, TopoDS_Shape& To)
176 Handle(TNaming_UsedShapes) US;
177 Lab.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
178 TNaming_DataMapOfShapePtrRefShape& amap = US->Map();
179 if (!amap.IsBound(To))
180 return Standard_False;
181 TNaming_RefShape* pos;
182 pos = amap.ChangeFind(To);
183 if(!amap.UnBind(To)) return Standard_False;
185 To.Orientation(From.Orientation());
187 return amap.Bind(To, pos);
190 //=======================================================================
193 //=======================================================================
195 static Standard_Boolean Rebuild (const TopoDS_Shape& S,
196 TopTools_DataMapOfShapeShape& M)
198 Standard_Boolean IsModified = Standard_False;
199 if (M.IsBound(S)) return IsModified;
202 TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
204 // Reconstruction des sous shapes si necessaire.
205 for (; iteS.More(); iteS.Next()) {
206 const TopoDS_Shape& SS = iteS.Value();
207 if (Rebuild (SS,M)) IsModified = Standard_True;
211 return Standard_True;
214 // Reconstruction de S
215 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
217 if (NewS.ShapeType() == TopAbs_EDGE) {
219 BRep_Tool::Range(TopoDS::Edge(S),f,l);
220 B.Range(TopoDS::Edge(NewS),f,l);
222 iteS.Initialize(S.Oriented(TopAbs_FORWARD));
223 for (iteS.Initialize(S.Oriented(TopAbs_FORWARD)) ;iteS.More(); iteS.Next()) {
224 const TopoDS_Shape& OS = iteS.Value();
225 const TopoDS_Shape& NS = M(OS);
226 B.Add(NewS,NS.Oriented(OS.Orientation()));
228 M.Bind (S,NewS.Oriented(S.Orientation()));
233 //=======================================================================
236 //=======================================================================
238 void TNaming::Update(const TDF_Label& L,
239 TopTools_DataMapOfShapeShape& M)
242 //Reconstruction des shapes de L suite aux substitutions decrites dans la map M.
243 // ex : si une face est remplacee par une autre il faut reconstruire les shapes
244 // qui contiennent cette face.
245 Handle(TNaming_UsedShapes) US;
246 L.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
247 TNaming_DataMapOfShapePtrRefShape& amap = US->Map();
249 for (TNaming_Iterator it(L); it.More(); it.Next()) {
250 if (!it.OldShape().IsNull()) {
251 const TopoDS_Shape& S = it.OldShape();
254 SubstituteShape(S,M(S),amap);
256 if (!it.NewShape().IsNull()) {
257 const TopoDS_Shape& S = it.NewShape();
260 SubstituteShape(S,M(S),amap);
264 // SI Les shapes dans les sous-labels sont des sous shapes des shapes de L
265 // si les shapes de L n ont pas changes les shapes des sous-labels ne seront
266 // pas changes non plus.
267 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
268 TNaming::Update (ciL.Value(),M);
272 //=======================================================================
273 //function : BuilCompound
275 //=======================================================================
277 static void BuildCompound(TopoDS_Compound& C,
281 for (TNaming_Iterator it(L); it.More(); it.Next()) {
282 if (!it.OldShape().IsNull()) {
283 B.Add(C,it.OldShape());
285 if (!it.NewShape().IsNull()) {
286 B.Add(C,it.NewShape());
289 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
290 BuildCompound (C,ciL.Value());
294 //=======================================================================
297 //=======================================================================
299 static void BuildMap(const TDF_Label& L,
300 BRepBuilderAPI_Transform& Transformer,
301 TopTools_DataMapOfShapeShape& M)
303 Handle(TNaming_UsedShapes) US;
304 L.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
305 for (TNaming_Iterator it(L); it.More(); it.Next()) {
306 if (!it.OldShape().IsNull()) {
307 const TopoDS_Shape& S = it.OldShape();
308 M.Bind(S,Transformer.ModifiedShape(S));
310 if (!it.NewShape().IsNull()) {
311 const TopoDS_Shape& S = it.NewShape();
312 M.Bind(S,Transformer.ModifiedShape(S));
315 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
316 BuildMap (ciL.Value(),Transformer,M);
320 //=======================================================================
321 //function : LoadNamedShape
323 //=======================================================================
325 static void LoadNamedShape (TNaming_Builder& B,
326 TNaming_Evolution Evol,
327 const TopoDS_Shape& OS,
328 const TopoDS_Shape& NS)
331 case TNaming_PRIMITIVE :
336 case TNaming_GENERATED :
341 case TNaming_MODIFY :
346 case TNaming_DELETE :
351 case TNaming_SELECTED :
361 //=======================================================================
362 //function : Displace
364 //=======================================================================
366 void TNaming::Displace (const TDF_Label& L,
367 const TopLoc_Location& Loc,
368 const Standard_Boolean WithOld)
372 TopTools_ListOfShape Olds;
373 TopTools_ListOfShape News;
374 TNaming_Evolution Evol;
375 TNaming_Iterator it(L);
377 if (it.More()) { // dp on continue de visiter les fils meme s'il y a pas de shape
378 Evol = it.Evolution();
379 for ( ; it.More(); it.Next()) {
380 Olds.Append(it.OldShape());
381 News.Append(it.NewShape());
385 TopTools_ListIteratorOfListOfShape itOlds(Olds);
386 TopTools_ListIteratorOfListOfShape itNews(News);
387 TNaming_Builder B(L);
389 for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) {
391 const TopoDS_Shape& SO = itOlds.Value();
392 const TopoDS_Shape& SN = itNews.Value();
394 if (WithOld && !SO.IsNull()) OS = SO.Moved(Loc);
395 if (!SN.IsNull()) NS = SN.Moved(Loc);
397 LoadNamedShape ( B, Evol, OS, NS);
400 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
401 Displace (ciL.Value(),Loc);
405 //=======================================================================
408 //=======================================================================
410 static void Replace (const TDF_Label& L,
411 const TopTools_DataMapOfShapeShape& M)
414 TNaming_Evolution Evol;
415 TNaming_Iterator it(L);
417 if (!it.More()) return;
418 Evol = it.Evolution();
420 TNaming_Builder B(L);
424 for ( ; it.More(); it.Next()) {
425 if (!it.OldShape().IsNull()) {
427 if (M.IsBound(OS)) OS = M(OS);
429 if (!it.NewShape().IsNull()) {
431 if (M.IsBound(NS)) NS = M(NS);
433 LoadNamedShape ( B, Evol, OS, NS);
435 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
436 Replace (ciL.Value(),M);
440 //=======================================================================
443 //=======================================================================
445 void TNaming::Transform(const TDF_Label& L,
449 //--------------------------------------------------------------------
450 // Construction du compound qui contient tous les shapes sous le label
452 //--------------------------------------------------------------------
453 TopoDS_Compound CompShape;
455 B.MakeCompound(CompShape);
457 BuildCompound (CompShape,L);
459 //----------------------------
460 // Transformation du compound.
461 //-----------------------------
462 BRepBuilderAPI_Transform Transformer(CompShape, T);
464 //-----------------------------------------------------------
465 //Remplacement des shapes initiaux par les shapes transformes.
466 //-----------------------------------------------------------
467 TopTools_DataMapOfShapeShape M;
468 BuildMap (L,Transformer,M);
472 //=======================================================================
475 //=======================================================================
477 void TNaming::IDList(TDF_IDList& anIDList)
478 { anIDList.Append(TNaming_NamedShape::GetID()); }
481 //=======================================================================
482 //function : Replicate
484 //=======================================================================
486 void TNaming::Replicate(const Handle(TNaming_NamedShape)& NS,
490 TopoDS_Shape SH = TNaming_Tool::CurrentShape(NS);
491 TNaming::Replicate(SH, T, L);
494 //=======================================================================
495 //function : Replicate
497 //=======================================================================
499 void TNaming::Replicate (const TopoDS_Shape& SH,
504 BRepBuilderAPI_Transform opeTrsf(T);
505 if (SH.ShapeType() == TopAbs_FACE || SH.ShapeType() == TopAbs_WIRE ) {
506 opeTrsf.Perform(SH, Standard_True); // pour le pattern de prism
509 opeTrsf.Perform(SH, Standard_False);
511 const TopoDS_Shape& newSH = opeTrsf.Shape();
512 //BRepLib::UpdateTolerances(newSH, Standard_True);
516 TNaming_Builder Builder(L);
517 Builder.Generated(SH, newSH);
520 TopAbs_ShapeEnum SST = TopAbs_FACE;
521 if (SH.ShapeType() == TopAbs_FACE || SH.ShapeType() == TopAbs_WIRE )
524 TNaming_Builder Builder2 (L.FindChild(1,Standard_True));
525 for (TopExp_Explorer exp(SH, SST); exp.More(); exp.Next()) {
526 const TopoDS_Shape& oldSubShape = exp.Current();
527 const TopoDS_Shape& newSubShape = opeTrsf.ModifiedShape(oldSubShape);
528 Builder2.Generated(oldSubShape, newSubShape);
533 //=======================================================================
534 //function : ShapeCopy
536 //=======================================================================
538 static TopoDS_Shape ShapeCopy(const TopoDS_Shape& S,
539 TopTools_DataMapOfShapeShape& M)
541 if (S.IsNull()) return S;
542 if (M.IsBound(S)) return M(S);
543 //----------------------------
544 //construction de la copie.
545 // 1- copie des sous shapes.
546 // 2- reconstruction du TShape
547 //----------------------------
549 TopoDS_Iterator it (S.Oriented(TopAbs_FORWARD));
551 for ( ; it.More(); it.Next()) {
552 const TopoDS_Shape& SS = it.Value();
553 TopoDS_Shape NewSS = ShapeCopy(SS,M);
555 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
557 if (NewS.ShapeType() == TopAbs_EDGE) {
559 BRep_Tool::Range(TopoDS::Edge(S),f,l);
560 B.Range(TopoDS::Edge(NewS),f,l);
562 for (it.Initialize(S.Oriented(TopAbs_FORWARD)) ;it.More(); it.Next()) {
563 const TopoDS_Shape& OS = it.Value();
564 const TopoDS_Shape& NS = M(OS);
565 B.Add(NewS,NS.Oriented(OS.Orientation()));
567 NewS.Orientation(S.Orientation());
569 NewS.Free (S.Free()) ;NewS.Modified(S.Modified());NewS.Checked (S.Checked());
570 NewS.Orientable(S.Orientable());NewS.Closed (S.Closed()) ;NewS.Infinite(S.Infinite());
571 NewS.Convex (S.Convex());
577 //=======================================================================
578 //function : ChangeShapes
580 //=======================================================================
582 void TNaming::ChangeShapes(const TDF_Label& L,
583 TopTools_DataMapOfShapeShape& M)
585 TopTools_ListOfShape Olds;
586 TopTools_ListOfShape News;
588 Handle(TNaming_NamedShape) NS;
589 L.FindAttribute(TNaming_NamedShape::GetID(),NS);
592 TNaming_Evolution Evol = NS->Evolution();
593 for (TNaming_Iterator it(L); it.More(); it.Next()) {
594 const TopoDS_Shape& S1 = it.OldShape();
595 const TopoDS_Shape& S2 = it.NewShape();
596 Olds.Append(ShapeCopy(S1,M));News.Append(ShapeCopy(S2,M));
599 TopTools_ListIteratorOfListOfShape itOlds(Olds);
600 TopTools_ListIteratorOfListOfShape itNews(News);
602 TNaming_Builder B(L);
604 for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) {
605 LoadNamedShape ( B, Evol, itOlds.Value(), itNews.Value());
609 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
610 ChangeShapes (ciL.Value(),M);
615 //=======================================================================
618 //=======================================================================
620 Standard_OStream& TNaming::Print (const TNaming_Evolution EVOL, Standard_OStream& s)
623 case TNaming_PRIMITIVE :
625 s <<"PRIMITIVE"; break;
627 case TNaming_GENERATED :
629 s <<"GENERATED"; break;
631 case TNaming_MODIFY :
635 case TNaming_DELETE :
639 case TNaming_SELECTED :
641 s <<"SELECTED"; break;
644 s << "UNKNOWN_Evolution"; break;
651 //=======================================================================
654 //=======================================================================
656 Standard_OStream& TNaming::Print (const TNaming_NameType NAME, Standard_OStream& s)
660 case TNaming_UNKNOWN :
662 s <<"UNKNOWN"; break;
664 case TNaming_IDENTITY :
666 s <<"IDENTITY"; break;
668 case TNaming_MODIFUNTIL :
670 s <<"MODIFUNTIL"; break;
672 case TNaming_GENERATION :
674 s <<"GENERATION"; break;
676 case TNaming_INTERSECTION :
678 s <<"INTERSECTION"; break;
684 case TNaming_SUBSTRACTION :
686 s <<"SUBSTRACTION"; break;
688 case TNaming_CONSTSHAPE :
690 s <<"CONSTSHAPE"; break;
692 case TNaming_FILTERBYNEIGHBOURGS:
694 s <<"FILTERBYNEIGHBOURGS"; break;
696 case TNaming_ORIENTATION:
698 s <<"ORIENTATION"; break;
704 case TNaming_SHELLIN:
706 s <<"SHELLIN"; break;
710 s <<"UNKNOWN_NameType"; break;
716 //=======================================================================
718 //purpose : Prints UsedShapes.
719 //=======================================================================
721 Standard_OStream& TNaming::Print (const TDF_Label& ACCESS, Standard_OStream& s) {
722 Handle(TNaming_UsedShapes) US;
723 if (!ACCESS.Root().FindAttribute(TNaming_UsedShapes::GetID(), US)) {
725 cout<<"TNaming::Print(US): Bad access"<<endl;
732 //=======================================================================
733 //function : BuildMapIn
735 //=======================================================================
736 static void BuildMapIn(const TopoDS_Shape& Context, const TopAbs_ShapeEnum StopType,
737 TopTools_DataMapOfOrientedShapeShape& Map)
739 TopAbs_ShapeEnum aType;
740 if((Context.ShapeType() == TopAbs_SOLID || Context.ShapeType() == TopAbs_FACE) && (StopType - Context.ShapeType()) != 1)
741 aType = (TopAbs_ShapeEnum)(Context.ShapeType() +2);
743 aType = (TopAbs_ShapeEnum)(Context.ShapeType()+1);
744 for (TopExp_Explorer exp(Context,aType); exp.More(); exp.Next()) {
746 if(!Map.Bind(exp.Current(), Context))
747 cout << "Not bind = " <<exp.Current().ShapeType() <<endl;
749 cout <<"Bind = " <<exp.Current().ShapeType() << " to Context = " <<Context.ShapeType()<<endl;
751 Map.Bind(exp.Current(), Context);
753 if(exp.Current().ShapeType() < StopType ) {
754 BuildMapIn(exp.Current(), StopType, Map);
758 if(Context.ShapeType() < StopType) {
759 TopoDS_Iterator it(Context);
760 for(;it.More();it.Next()) {
761 if(it.Value().Orientation() != TopAbs_FORWARD && it.Value().Orientation() != TopAbs_REVERSED) {
762 Map.Bind(it.Value(), Context);
763 //cout << "INTERNAL || EXTERNAL Orientation found" <<endl;
768 //=======================================================================
769 //function : BuildMapC0
770 //purpose : builds data map: key - context, C0 - top context
771 //=======================================================================
772 static void BuildMapC0(const TopoDS_Shape& Context, const TopoDS_Shape& C0, const TopAbs_ShapeEnum StopType,
773 TopTools_DataMapOfOrientedShapeShape& Map)
775 TopoDS_Iterator anIt(Context);
777 const TopoDS_Shape& aKey = anIt.Value();
779 if(!Map.Bind(aKey, C0))
780 cout << "Not bind = " <<aKey.ShapeType() <<endl;
784 if(aKey.ShapeType() < StopType ) {
785 if(aKey.ShapeType() < TopAbs_SOLID) {
786 BuildMapC0(aKey, Context, StopType, Map);
789 BuildMapIn(aKey, StopType, Map);
795 //=======================================================================
796 //function : BuildMap
797 //purpose : builds data map: key - context
798 //=======================================================================
799 static void BuildMap(const TopoDS_Shape& Context, const TopAbs_ShapeEnum StopType,
800 TopTools_DataMapOfOrientedShapeShape& Map)
802 TopoDS_Iterator anIt(Context);
804 const TopoDS_Shape& aKey = anIt.Value();
806 if(!Map.Bind(aKey, Context))
807 cout << "Not bind = " <<aKey.ShapeType() <<endl;
809 Map.Bind(aKey, Context);
811 if(aKey.ShapeType() < StopType ) {
812 if(aKey.ShapeType() < TopAbs_SOLID)
813 BuildMapC0(aKey, Context, StopType, Map);
815 BuildMapIn(aKey, StopType, Map);
820 //=======================================================================
821 //function : FindUniqueContext
822 //purpose : Find unique context of selection
823 //=======================================================================
824 TopoDS_Shape TNaming::FindUniqueContext(const TopoDS_Shape& Selection, const TopoDS_Shape& Context)
826 TopTools_DataMapOfOrientedShapeShape aMap;
827 BuildMap(Context, Selection.ShapeType(), aMap);
829 TopTools_DataMapIteratorOfDataMapOfOrientedShapeShape it (aMap);
830 for (;it.More();it.Next()) {
831 cout <<"FindUniqueContext: Key - " <<it.Key().ShapeType()<< " " << it.Key().TShape() <<" OR = " <<it.Key().Orientation() <<
832 " Context - " << it.Value().ShapeType() << " " << it.Value().TShape() << " OR = " <<it.Value().Orientation() <<endl;
835 if(aMap.IsBound(Selection))
836 return aMap.Find(Selection);
837 return TopoDS_Shape();
840 //=======================================================================
841 //function : FindUniqueContexts
842 //purpose : Find unique context of selection which is pure concatenation
843 // : of atomic shapes (Compound)
844 //=======================================================================
845 TopoDS_Shape TNaming::FindUniqueContextSet(const TopoDS_Shape& Selection, const TopoDS_Shape& Context,
846 Handle(TopTools_HArray1OfShape)& Arr)
848 if(Selection.ShapeType() == TopAbs_COMPOUND) {
849 TopTools_DataMapOfOrientedShapeShape aMap;
850 Standard_Integer Up(0);
851 TopAbs_ShapeEnum aStopType(TopAbs_COMPOUND);
852 TopoDS_Iterator it(Selection);
853 for(;it.More(); it.Next()) {
854 const TopoDS_Shape& aS = it.Value();
855 if(aS.ShapeType() > aStopType)
856 aStopType = aS.ShapeType();
860 Arr = new TopTools_HArray1OfShape(1, Up);
861 if(aStopType == TopAbs_SHAPE)
862 aStopType = Selection.ShapeType();
863 BuildMap(Context, aStopType, aMap);
864 if(aMap.IsBound(Selection))
865 return aMap.Find(Selection);
866 else if(Selection.ShapeType() == TopAbs_COMPOUND) {
867 Standard_Integer num1(0),num2(0);
868 TopoDS_Compound CompShape;
870 B.MakeCompound(CompShape);
871 TopoDS_Iterator it(Selection);
872 TopTools_MapOfShape aView;
873 for(;it.More(); it.Next(),num1++) {
874 if(aMap.IsBound(it.Value())) {
875 if(aView.Add(aMap.Find(it.Value()))) {
876 B.Add(CompShape, aMap.Find(it.Value()));
879 Arr->SetValue(num1+1, aMap.Find(it.Value()));
881 if(aMap.Find(it.Value()) == Context)
885 if(num1 == num2 && num2)
888 TopoDS_Iterator it(CompShape);
889 Standard_Integer n(0);
891 for(;it.More();it.Next()) {
896 #ifdef OCCT_DEBUG_FSET
897 cout << "FindUniqueContextSet: n = " << n <<endl;
905 return TopoDS_Shape();
908 //=======================================================================
909 //function : OuterWire
910 //purpose : Returns True & <theWire> if Outer wire is found.
911 //=======================================================================
912 Standard_Boolean TNaming::OuterWire(const TopoDS_Face& theFace, TopoDS_Wire& theWire)
917 IntTools_FClass2d aFC;
918 Standard_Boolean bFlag(Standard_False);
919 Standard_Real aTol = BRep_Tool::Tolerance(theFace);
920 TopoDS_Iterator aIt(theFace);
921 for (; aIt.More(); aIt.Next()) {
922 aWx=*((TopoDS_Wire*)&aIt.Value());
927 bFlag = aFC.IsHole();
932 return !bFlag;// if bFlag == True - not found
934 //=======================================================================
935 //function : IsInternal
937 //=======================================================================
938 static Standard_Boolean IsInternal(const TopoDS_Shape& aSx)
940 TopAbs_Orientation aOr;
941 Standard_Boolean bInternal(Standard_False);
942 TopoDS_Iterator aIt(aSx);
944 const TopoDS_Shape& aSy = aIt.Value();
945 aOr = aSy.Orientation();
946 bInternal = (aOr == TopAbs_INTERNAL || aOr == TopAbs_EXTERNAL);
950 //=======================================================================
951 //function : OuterShell
952 //purpose : returns True & <theShell>, if Outer shell is found
953 //=======================================================================
954 Standard_Boolean TNaming::OuterShell(const TopoDS_Solid& theSolid,
955 TopoDS_Shell& theShell)
960 Standard_Boolean bFound(Standard_False);
961 Standard_Real aTol(1.e-7);
964 BRepClass3d_SolidClassifier aSC;
965 TopoDS_Iterator aIt(theSolid);
966 for (; aIt.More(); aIt.Next()) {
967 const TopoDS_Shape& aSx = aIt.Value();
969 if (aSx.ShapeType() != TopAbs_SHELL)
974 aSHx = *((TopoDS_Shell*)&aSx);
982 //BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aSDx);
983 aSC.PerformInfinitePoint(aTol);
984 aState = aSC.State();
985 if(aState == TopAbs_OUT) {
986 bFound = Standard_True;