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
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.
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.
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.
23 #include <TNaming.ixx>
25 #include <BRep_Builder.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRepBuilderAPI_Transform.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>
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>
55 #include <IntTools_FClass2d.hxx>
56 #include <BRepClass3d_SolidClassifier.hxx>
59 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
60 #include <TNaming_TranslateTool.hxx>
61 #include <TopLoc_Datum3D.hxx>
66 //#define MDTV_DEB_FSET
69 #include <BRepTools.hxx>
70 #include <TCollection_AsciiString.hxx>
71 #include <TopTools_DataMapIteratorOfDataMapOfOrientedShapeShape.hxx>
72 static void WriteS(const TopoDS_Shape& shape,
73 const Standard_CString filename)
76 if(strlen(filename) > 256) return;
78 strcpy_s (buf, filename);
80 strcpy (buf, filename);
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);
96 //=======================================================================
97 //function : MapShapes
99 //=======================================================================
101 static void MapShapes(const TopoDS_Shape& SCible, const TopoDS_Shape& SSource, TopTools_DataMapOfShapeShape& M)
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);
113 //=======================================================================
114 //function : MapShapes
116 //=======================================================================
118 static void MapShapes(const TDF_Label& LCible, const TDF_Label& LSource, TopTools_DataMapOfShapeShape& M)
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);
126 if (!icible.NewShape().IsNull()) {
127 if (!M.IsBound(icible.NewShape())) MapShapes(icible.NewShape(),isource.NewShape(),M);
133 TDF_ChildIterator iccible(LCible);
134 TDF_ChildIterator icsource(LSource);
135 while (iccible.More()) {
136 MapShapes(iccible.Value(),icsource.Value(),M);
142 //=======================================================================
143 //function : SubstituteShape
145 //=======================================================================
147 void static SubstituteShape(const TopoDS_Shape& oldShape,
148 const TopoDS_Shape& newShape,
149 TNaming_DataMapOfShapePtrRefShape& amap)
151 if (oldShape.IsSame(newShape)) {
152 cout <<"import_tool::Substitute : oldShape IsSame newShape"<<endl;
155 if (!amap.IsBound(oldShape)) {
158 TNaming_RefShape* pos;
159 pos = amap.ChangeFind(oldShape);
160 pos->Shape(newShape);
161 amap.UnBind(oldShape);
162 amap.Bind(newShape,pos);
165 //=======================================================================
166 //function : MakeShape
168 //=======================================================================
170 TopoDS_Shape TNaming::MakeShape (const TopTools_MapOfShape& MS)
172 if (!MS.IsEmpty ()) {
173 TopTools_MapIteratorOfMapOfShape it(MS);
174 if (MS.Extent() == 1) {
181 for (; it.More(); it.Next()){
187 return TopoDS_Shape();
190 //=======================================================================
191 //function : Substitute
193 //=======================================================================
195 void TNaming::Substitute(const TDF_Label& LSource,
196 const TDF_Label& LCible ,
197 TopTools_DataMapOfShapeShape& M)
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);
209 //=======================================================================
210 //function : SubstituteSShape
212 //=======================================================================
213 Standard_Boolean TNaming::SubstituteSShape(const TDF_Label& Lab, const TopoDS_Shape& From, TopoDS_Shape& To)
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;
224 To.Orientation(From.Orientation());
226 return amap.Bind(To, pos);
229 //=======================================================================
232 //=======================================================================
234 static Standard_Boolean Rebuild (const TopoDS_Shape& S,
235 TopTools_DataMapOfShapeShape& M)
237 Standard_Boolean IsModified = Standard_False;
238 if (M.IsBound(S)) return IsModified;
241 TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
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;
250 return Standard_True;
253 // Reconstruction de S
254 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
256 if (NewS.ShapeType() == TopAbs_EDGE) {
258 BRep_Tool::Range(TopoDS::Edge(S),f,l);
259 B.Range(TopoDS::Edge(NewS),f,l);
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()));
267 M.Bind (S,NewS.Oriented(S.Orientation()));
272 //=======================================================================
275 //=======================================================================
277 void TNaming::Update(const TDF_Label& L,
278 TopTools_DataMapOfShapeShape& M)
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();
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();
293 if (Rebuild (S,M)) Change = Standard_True;
294 SubstituteShape(S,M(S),amap);
296 if (!it.NewShape().IsNull()) {
297 const TopoDS_Shape& S = it.NewShape();
299 if (Rebuild (S,M)) Change = Standard_True;
300 SubstituteShape(S,M(S),amap);
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);
312 //=======================================================================
313 //function : BuilCompound
315 //=======================================================================
317 static void BuildCompound(TopoDS_Compound& C,
321 for (TNaming_Iterator it(L); it.More(); it.Next()) {
322 if (!it.OldShape().IsNull()) {
323 B.Add(C,it.OldShape());
325 if (!it.NewShape().IsNull()) {
326 B.Add(C,it.NewShape());
329 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
330 BuildCompound (C,ciL.Value());
334 //=======================================================================
337 //=======================================================================
339 static void BuildMap(const TDF_Label& L,
340 BRepBuilderAPI_Transform& Transformer,
341 TopTools_DataMapOfShapeShape& M)
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));
350 if (!it.NewShape().IsNull()) {
351 const TopoDS_Shape& S = it.NewShape();
352 M.Bind(S,Transformer.ModifiedShape(S));
355 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
356 BuildMap (ciL.Value(),Transformer,M);
360 //=======================================================================
361 //function : LoadNamedShape
363 //=======================================================================
365 static void LoadNamedShape (TNaming_Builder& B,
366 TNaming_Evolution Evol,
367 const TopoDS_Shape& OS,
368 const TopoDS_Shape& NS)
371 case TNaming_PRIMITIVE :
376 case TNaming_GENERATED :
381 case TNaming_MODIFY :
386 case TNaming_DELETE :
391 case TNaming_SELECTED :
401 //=======================================================================
402 //function : Displace
404 //=======================================================================
406 void TNaming::Displace (const TDF_Label& L,
407 const TopLoc_Location& Loc,
408 const Standard_Boolean WithOld)
412 TopTools_ListOfShape Olds;
413 TopTools_ListOfShape News;
414 TNaming_Evolution Evol;
415 TNaming_Iterator it(L);
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());
425 TopTools_ListIteratorOfListOfShape itOlds(Olds);
426 TopTools_ListIteratorOfListOfShape itNews(News);
427 TNaming_Builder B(L);
429 for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) {
431 const TopoDS_Shape& SO = itOlds.Value();
432 const TopoDS_Shape& SN = itNews.Value();
434 if (WithOld && !SO.IsNull()) OS = SO.Moved(Loc);
435 if (!SN.IsNull()) NS = SN.Moved(Loc);
437 LoadNamedShape ( B, Evol, OS, NS);
440 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
441 Displace (ciL.Value(),Loc);
445 //=======================================================================
448 //=======================================================================
450 static void Replace (const TDF_Label& L,
451 const TopTools_DataMapOfShapeShape& M)
454 TNaming_Evolution Evol;
455 TNaming_Iterator it(L);
457 if (!it.More()) return;
458 Evol = it.Evolution();
460 TNaming_Builder B(L);
464 for ( ; it.More(); it.Next()) {
465 if (!it.OldShape().IsNull()) {
467 if (M.IsBound(OS)) OS = M(OS);
469 if (!it.NewShape().IsNull()) {
471 if (M.IsBound(NS)) NS = M(NS);
473 LoadNamedShape ( B, Evol, OS, NS);
475 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
476 Replace (ciL.Value(),M);
480 //=======================================================================
483 //=======================================================================
485 void TNaming::Transform(const TDF_Label& L,
489 //--------------------------------------------------------------------
490 // Construction du compound qui contient tous les shapes sous le label
492 //--------------------------------------------------------------------
493 TopoDS_Compound CompShape;
495 B.MakeCompound(CompShape);
497 BuildCompound (CompShape,L);
499 //----------------------------
500 // Transformation du compound.
501 //-----------------------------
502 BRepBuilderAPI_Transform Transformer(CompShape, T);
504 //-----------------------------------------------------------
505 //Remplacement des shapes initiaux par les shapes transformes.
506 //-----------------------------------------------------------
507 TopTools_DataMapOfShapeShape M;
508 BuildMap (L,Transformer,M);
512 //=======================================================================
515 //=======================================================================
517 void TNaming::IDList(TDF_IDList& anIDList)
518 { anIDList.Append(TNaming_NamedShape::GetID()); }
521 //=======================================================================
522 //function : Replicate
524 //=======================================================================
526 void TNaming::Replicate(const Handle(TNaming_NamedShape)& NS,
530 TopoDS_Shape SH = TNaming_Tool::CurrentShape(NS);
531 TNaming::Replicate(SH, T, L);
534 //=======================================================================
535 //function : Replicate
537 //=======================================================================
539 void TNaming::Replicate (const TopoDS_Shape& SH,
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
549 opeTrsf.Perform(SH, Standard_False);
551 const TopoDS_Shape& newSH = opeTrsf.Shape();
552 //BRepLib::UpdateTolerances(newSH, Standard_True);
556 TNaming_Builder Builder(L);
557 Builder.Generated(SH, newSH);
560 TopAbs_ShapeEnum SST = TopAbs_FACE;
561 if (SH.ShapeType() == TopAbs_FACE || SH.ShapeType() == TopAbs_WIRE )
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);
573 //=======================================================================
574 //function : ShapeCopy
576 //=======================================================================
578 static TopoDS_Shape ShapeCopy(const TopoDS_Shape& S,
579 TopTools_DataMapOfShapeShape& M)
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 //----------------------------
589 TopoDS_Iterator it (S.Oriented(TopAbs_FORWARD));
591 for ( ; it.More(); it.Next()) {
592 const TopoDS_Shape& SS = it.Value();
593 TopoDS_Shape NewSS = ShapeCopy(SS,M);
595 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
597 if (NewS.ShapeType() == TopAbs_EDGE) {
599 BRep_Tool::Range(TopoDS::Edge(S),f,l);
600 B.Range(TopoDS::Edge(NewS),f,l);
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()));
607 NewS.Orientation(S.Orientation());
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());
617 //=======================================================================
618 //function : ChangeShapes
620 //=======================================================================
622 void TNaming::ChangeShapes(const TDF_Label& L,
623 TopTools_DataMapOfShapeShape& M)
625 TopTools_ListOfShape Olds;
626 TopTools_ListOfShape News;
628 Handle(TNaming_NamedShape) NS;
629 L.FindAttribute(TNaming_NamedShape::GetID(),NS);
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));
639 TopTools_ListIteratorOfListOfShape itOlds(Olds);
640 TopTools_ListIteratorOfListOfShape itNews(News);
642 TNaming_Builder B(L);
644 for ( ;itOlds.More() ; itOlds.Next(),itNews.Next()) {
645 LoadNamedShape ( B, Evol, itOlds.Value(), itNews.Value());
649 for (TDF_ChildIterator ciL(L); ciL.More(); ciL.Next()) {
650 ChangeShapes (ciL.Value(),M);
655 //=======================================================================
658 //=======================================================================
660 Standard_OStream& TNaming::Print (const TNaming_Evolution EVOL, Standard_OStream& s)
663 case TNaming_PRIMITIVE :
665 s <<"PRIMITIVE"; break;
667 case TNaming_GENERATED :
669 s <<"GENERATED"; break;
671 case TNaming_MODIFY :
675 case TNaming_DELETE :
679 case TNaming_SELECTED :
681 s <<"SELECTED"; break;
684 s << "UNKNOWN_Evolution"; break;
691 //=======================================================================
694 //=======================================================================
696 Standard_OStream& TNaming::Print (const TNaming_NameType NAME, Standard_OStream& s)
700 case TNaming_UNKNOWN :
702 s <<"UNKNOWN"; break;
704 case TNaming_IDENTITY :
706 s <<"IDENTITY"; break;
708 case TNaming_MODIFUNTIL :
710 s <<"MODIFUNTIL"; break;
712 case TNaming_GENERATION :
714 s <<"GENERATION"; break;
716 case TNaming_INTERSECTION :
718 s <<"INTERSECTION"; break;
724 case TNaming_SUBSTRACTION :
726 s <<"SUBSTRACTION"; break;
728 case TNaming_CONSTSHAPE :
730 s <<"CONSTSHAPE"; break;
732 case TNaming_FILTERBYNEIGHBOURGS:
734 s <<"FILTERBYNEIGHBOURGS"; break;
736 case TNaming_ORIENTATION:
738 s <<"ORIENTATION"; break;
744 case TNaming_SHELLIN:
746 s <<"SHELLIN"; break;
750 s <<"UNKNOWN_NameType"; break;
758 //=======================================================================
760 //purpose : Prints UsedShapes.
761 //=======================================================================
763 Standard_OStream& TNaming::Print (const TDF_Label& ACCESS, Standard_OStream& s) {
764 Handle(TNaming_UsedShapes) US;
765 if (!ACCESS.Root().FindAttribute(TNaming_UsedShapes::GetID(), US)) {
767 cout<<"TNaming::Print(US): Bad access"<<endl;
776 //=======================================================================
777 //function : BuildMapIn
779 //=======================================================================
780 static void BuildMapIn(const TopoDS_Shape& Context, const TopAbs_ShapeEnum StopType,
781 TopTools_DataMapOfOrientedShapeShape& Map)
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);
787 aType = (TopAbs_ShapeEnum)(Context.ShapeType()+1);
788 for (TopExp_Explorer exp(Context,aType); exp.More(); exp.Next()) {
790 if(!Map.Bind(exp.Current(), Context))
791 cout << "Not bind = " <<exp.Current().ShapeType() <<endl;
793 cout <<"Bind = " <<exp.Current().ShapeType() << " to Context = " <<Context.ShapeType()<<endl;
795 Map.Bind(exp.Current(), Context);
797 if(exp.Current().ShapeType() < StopType ) {
798 BuildMapIn(exp.Current(), StopType, Map);
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;
812 //=======================================================================
813 //function : BuildMapC0
814 //purpose : builds data map: key - context, C0 - top context
815 //=======================================================================
816 static void BuildMapC0(const TopoDS_Shape& Context, const TopoDS_Shape& C0, const TopAbs_ShapeEnum StopType,
817 TopTools_DataMapOfOrientedShapeShape& Map)
819 TopoDS_Iterator anIt(Context);
821 const TopoDS_Shape& aKey = anIt.Value();
823 if(!Map.Bind(aKey, C0))
824 cout << "Not bind = " <<aKey.ShapeType() <<endl;
828 if(aKey.ShapeType() < StopType ) {
829 if(aKey.ShapeType() < TopAbs_SOLID) {
830 BuildMapC0(aKey, Context, StopType, Map);
833 BuildMapIn(aKey, StopType, Map);
839 //=======================================================================
840 //function : BuildMap
841 //purpose : builds data map: key - context
842 //=======================================================================
843 static void BuildMap(const TopoDS_Shape& Context, const TopAbs_ShapeEnum StopType,
844 TopTools_DataMapOfOrientedShapeShape& Map)
847 TCollection_AsciiString Nam("Cnt_");
848 Standard_Integer i = 0;
850 TopoDS_Iterator anIt(Context);
852 const TopoDS_Shape& aKey = anIt.Value();
854 if(!Map.Bind(aKey, Context))
855 cout << "Not bind = " <<aKey.ShapeType() <<endl;
857 Map.Bind(aKey, Context);
859 if(aKey.ShapeType() < StopType ) {
860 if(aKey.ShapeType() < TopAbs_SOLID)
861 BuildMapC0(aKey, Context, StopType, Map);
863 BuildMapIn(aKey, StopType, Map);
868 //=======================================================================
869 //function : FindUniqueContext
870 //purpose : Find unique context of selection
871 //=======================================================================
872 TopoDS_Shape TNaming::FindUniqueContext(const TopoDS_Shape& Selection, const TopoDS_Shape& Context)
874 TopTools_DataMapOfOrientedShapeShape aMap;
875 BuildMap(Context, Selection.ShapeType(), aMap);
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;
883 if(aMap.IsBound(Selection))
884 return aMap.Find(Selection);
885 return TopoDS_Shape();
888 //=======================================================================
889 //function : FindUniqueContexts
890 //purpose : Find unique context of selection which is pure concatenation
891 // : of atomic shapes (Compound)
892 //=======================================================================
893 TopoDS_Shape TNaming::FindUniqueContextSet(const TopoDS_Shape& Selection, const TopoDS_Shape& Context,
894 Handle(TopTools_HArray1OfShape)& Arr)
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();
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;
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()));
927 Arr->SetValue(num1+1, aMap.Find(it.Value()));
929 if(aMap.Find(it.Value()) == Context)
933 if(num1 == num2 && num2)
936 TopoDS_Iterator it(CompShape);
937 Standard_Integer n(0);
939 for(;it.More();it.Next()) {
945 cout << "FindUniqueContextSet: n = " << n <<endl;
953 return TopoDS_Shape();
956 //=======================================================================
957 //function : OuterWire
958 //purpose : Returns True & <theWire> if Outer wire is found.
959 //=======================================================================
960 Standard_Boolean TNaming::OuterWire(const TopoDS_Face& theFace, TopoDS_Wire& theWire)
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());
975 bFlag = aFC.IsHole();
980 return !bFlag;// if bFlag == True - not found
982 //=======================================================================
983 //function : IsInternal
985 //=======================================================================
986 static Standard_Boolean IsInternal(const TopoDS_Shape& aSx)
988 TopAbs_Orientation aOr;
989 Standard_Boolean bInternal(Standard_False);
990 TopoDS_Iterator aIt(aSx);
992 const TopoDS_Shape& aSy = aIt.Value();
993 aOr = aSy.Orientation();
994 bInternal = (aOr == TopAbs_INTERNAL || aOr == TopAbs_EXTERNAL);
998 //=======================================================================
999 //function : OuterShell
1000 //purpose : returns True & <theShell>, if Outer shell is found
1001 //=======================================================================
1002 Standard_Boolean TNaming::OuterShell(const TopoDS_Solid& theSolid,
1003 TopoDS_Shell& theShell)
1007 TopAbs_State aState;
1008 Standard_Boolean bFound(Standard_False);
1009 Standard_Real aTol(1.e-7);
1012 BRepClass3d_SolidClassifier aSC;
1013 TopoDS_Iterator aIt(theSolid);
1014 for (; aIt.More(); aIt.Next()) {
1015 const TopoDS_Shape& aSx = aIt.Value();
1017 if (aSx.ShapeType() != TopAbs_SHELL)
1019 if (IsInternal(aSx))
1022 aSHx = *((TopoDS_Shell*)&aSx);
1027 aBB.Add(aSDx, aSHx);
1030 //BRepClass3d_SolidClassifier& aSC=aCtx.SolidClassifier(aSDx);
1031 aSC.PerformInfinitePoint(aTol);
1032 aState = aSC.State();
1033 if(aState == TopAbs_OUT) {
1034 bFound = Standard_True;