1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_GetInPlace.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_GetInPlace.hxx>
29 #include <NCollection_UBTreeFiller.hxx>
31 #include <Bnd_Box.hxx>
34 #include <TColStd_ListOfInteger.hxx>
35 #include <TColStd_ListIteratorOfListOfInteger.hxx>
37 #include <TopAbs_ShapeEnum.hxx>
39 #include <TopoDS_Iterator.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopoDS_Compound.hxx>
46 #include <BRep_Tool.hxx>
47 #include <BRep_Builder.hxx>
49 #include <BRepBndLib.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
54 #include <TopTools_ListOfShape.hxx>
55 #include <TopTools_DataMapOfShapeListOfShape.hxx>
56 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <TopTools_MapIteratorOfMapOfShape.hxx>
61 #include <GEOMAlgo_BoxBndTree.hxx>
62 #include <GEOMAlgo_CoupleOfShapes.hxx>
66 void MapBRepShapes(const TopoDS_Shape& aS,
67 TopTools_IndexedMapOfShape& aM);
70 //=======================================================================
71 //function : GEOMAlgo_GetInPlace
73 //=======================================================================
74 GEOMAlgo_GetInPlace::GEOMAlgo_GetInPlace()
82 myFound=Standard_False;
83 myCheckGeometry=Standard_True;
85 //=======================================================================
88 //=======================================================================
89 GEOMAlgo_GetInPlace::~GEOMAlgo_GetInPlace()
92 //=======================================================================
93 //function : SetTolMass
95 //=======================================================================
96 void GEOMAlgo_GetInPlace::SetTolMass(const Standard_Real theTol)
100 //=======================================================================
103 //=======================================================================
104 Standard_Real GEOMAlgo_GetInPlace::TolMass()const
108 //=======================================================================
109 //function : SetTolCG
111 //=======================================================================
112 void GEOMAlgo_GetInPlace::SetTolCG(const Standard_Real theTol)
116 //=======================================================================
119 //=======================================================================
120 Standard_Real GEOMAlgo_GetInPlace::TolCG()const
124 //=======================================================================
127 //=======================================================================
128 Standard_Boolean GEOMAlgo_GetInPlace::IsFound()const
132 //=======================================================================
133 //function : SetShapeWhere
135 //=======================================================================
136 void GEOMAlgo_GetInPlace::SetShapeWhere(const TopoDS_Shape& theShape)
138 myShapeWhere=theShape;
140 //=======================================================================
141 //function : ShapeWhere
143 //=======================================================================
144 const TopoDS_Shape& GEOMAlgo_GetInPlace::ShapeWhere()const
148 //=======================================================================
149 //function : ShapesIn
151 //=======================================================================
152 const GEOMAlgo_DataMapOfShapeMapOfShape& GEOMAlgo_GetInPlace::ShapesIn()const
156 //=======================================================================
157 //function : ShapesOn
159 //=======================================================================
160 const GEOMAlgo_DataMapOfShapeMapOfShape& GEOMAlgo_GetInPlace::ShapesOn()const
164 //=======================================================================
167 //=======================================================================
168 void GEOMAlgo_GetInPlace::Clear()
175 GEOMAlgo_GluerAlgo::Clear();
179 myShapesInclusive.Clear();
180 myMapShapePnt.Clear();
184 //=======================================================================
187 //=======================================================================
188 void GEOMAlgo_GetInPlace::Perform()
190 myFound=Standard_False;
204 // Initialize the context
205 GEOMAlgo_GluerAlgo::Perform();
217 FillEdgesOn(myArgument);
218 FillEdgesOn(myShapeWhere);
238 FillFacesOn(myArgument);
239 FillFacesOn(myShapeWhere);
254 FillSolidsOn(myArgument);
255 FillSolidsOn(myShapeWhere);
271 FillImages(myShapeWhere, Standard_True);
272 FillImages(myArgument, Standard_False);
283 //=======================================================================
284 //function : CheckData
286 //=======================================================================
287 void GEOMAlgo_GetInPlace::CheckData()
292 if (myArgument.IsNull()) {
297 if (myShapeWhere.IsNull()) {
302 //=======================================================================
303 //function : Intersect
305 //=======================================================================
306 void GEOMAlgo_GetInPlace::Intersect()
308 Standard_Integer i, j, aNbS1, aNbS2, aNbSD;
309 TColStd_ListIteratorOfListOfInteger aItLI;
310 TopTools_IndexedMapOfShape aMS1, aMS2;
311 TopTools_DataMapOfShapeListOfShape aDMSLS;
312 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
313 TopTools_ListIteratorOfListOfShape aItLS;
314 GEOMAlgo_CoupleOfShapes aCS;
316 GEOMAlgo_BoxBndTreeSelector aSelector;
317 GEOMAlgo_BoxBndTree aBBTree;
318 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
325 MapBRepShapes(myArgument, aMS1);
327 for (i=1; i<=aNbS1; ++i) {
330 const TopoDS_Shape& aS1=aMS1(i);
331 BRepBndLib::Add(aS1, aBox1);
332 aBox1.Enlarge(myTolerance);
334 aTreeFiller.Add(i, aBox1);
339 MapBRepShapes(myShapeWhere, aMS2);
341 for (j=1; j<=aNbS2; ++j) {
344 const TopoDS_Shape& aS2=aMS2(j);
345 BRepBndLib::Add(aS2, aBox2);
346 aBox2.Enlarge(myTolerance);
349 aSelector.SetBox(aBox2);
350 aNbSD=aBBTree.Select(aSelector);
352 continue; // it should not be
355 const TColStd_ListOfInteger& aLI=aSelector.Indices();
356 aItLI.Initialize(aLI);
357 for (; aItLI.More(); aItLI.Next()) {
359 const TopoDS_Shape& aS1=aMS1(i);
361 if (aDMSLS.IsBound(aS1)) {
362 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aS1);
366 TopTools_ListOfShape aLS;
369 aDMSLS.Bind(aS1, aLS);
372 }// for (j=1; j<=aNbS2; ++j) {
374 aItDMSLS.Initialize(aDMSLS);
375 for (; aItDMSLS.More(); aItDMSLS.Next()) {
376 const TopoDS_Shape& aS1=aItDMSLS.Key();
377 const TopTools_ListOfShape& aLS2=aItDMSLS.Value();
379 aItLS.Initialize(aLS2);
380 for (; aItLS.More(); aItLS.Next()) {
381 const TopoDS_Shape& aS2=aItLS.Value();
383 myIterator.AppendPair(aCS);
387 //=======================================================================
388 //function : PerformVV
390 //=======================================================================
391 void GEOMAlgo_GetInPlace::PerformVV()
396 myIterator.Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
397 for (; myIterator.More(); myIterator.Next()) {
398 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
399 const TopoDS_Shape& aV1=aCS.Shape1();
400 const TopoDS_Shape& aV2=aCS.Shape2();
402 FillShapesOn(aV1, aV2);
403 FillShapesOn(aV2, aV1);
406 //=======================================================================
407 //function : FillEdgesOn
409 //=======================================================================
410 void GEOMAlgo_GetInPlace::FillEdgesOn(const TopoDS_Shape &theShape)
412 Standard_Integer i, aNbE;
414 TopTools_IndexedMapOfShape aME;
415 TopTools_MapIteratorOfMapOfShape aItMS;
417 TopExp::MapShapes(theShape, TopAbs_EDGE, aME);
419 for (i=1; i<=aNbE; ++i) {
420 const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(i));
421 if (BRep_Tool::Degenerated(aE1)) {
426 for (; aIt.More(); aIt.Next()) {
427 const TopoDS_Shape& aV1=aIt.Value();
428 if (myShapesOn.IsBound(aV1)) {
429 const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aV1);
430 //aNbSOn=aMSOn.Extent();
431 aItMS.Initialize(aMSOn);
432 for (; aItMS.More(); aItMS.Next()) {
433 const TopoDS_Shape& aV2=aItMS.Key();
434 FillShapesOn(aE1, aV2);
440 //=======================================================================
441 //function : PerformVE
443 //=======================================================================
444 void GEOMAlgo_GetInPlace::PerformVE()
446 Standard_Boolean bFound;
452 myIterator.Initialize(TopAbs_EDGE, TopAbs_VERTEX);
453 for (; myIterator.More(); myIterator.Next()) {
454 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
455 const TopoDS_Shape& aE1=aCS.Shape1();
456 const TopoDS_Shape& aV2=aCS.Shape2();
458 if (myShapesOn.IsBound(aE1)) {
459 const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aE1);
460 if (aMSOn.Contains(aV2)) {
465 bFound=CheckCoincidence(aE1, aV2);
470 FillShapesIn(aE1, aV2);
474 //=======================================================================
475 //function : PerformEE
477 //=======================================================================
478 void GEOMAlgo_GetInPlace::PerformEE()
483 myIterator.Initialize(TopAbs_EDGE, TopAbs_EDGE);
484 for (; myIterator.More(); myIterator.Next()) {
485 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
486 const TopoDS_Shape& aE1=aCS.Shape1();
487 const TopoDS_Shape& aE2=aCS.Shape2();
502 //=======================================================================
503 //function : PerformEE
505 //=======================================================================
506 void GEOMAlgo_GetInPlace::PerformEE(const TopoDS_Shape &theE1,
507 const TopoDS_Shape &theE2)
509 Standard_Boolean bHasOn, bHasIn, bFound;
511 TopTools_MapOfShape aMSX;
513 bHasOn=myShapesOn.IsBound(theE1);
514 bHasIn=myShapesIn.IsBound(theE1);
515 const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(theE1) : aMSX;
516 const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(theE1) : aMSX;
518 bFound=Standard_True;
519 aIt.Initialize(theE2);
520 for (; aIt.More(); aIt.Next()) {
521 const TopoDS_Shape& aV2=aIt.Value();
522 if (!(aMSOn.Contains(aV2) || aMSIn.Contains(aV2))) {
531 bFound=CheckCoincidence(theE1, theE2);
536 FillShapesIn(theE1, theE2);
539 //=======================================================================
540 //function : PerformVF
542 //=======================================================================
543 void GEOMAlgo_GetInPlace::PerformVF()
545 Standard_Boolean bHasOn, bHasIn, bFound;
546 Standard_Integer i, aNbE;
547 TopTools_MapOfShape aMSX;
548 TopTools_IndexedMapOfShape aME;
553 myIterator.Initialize(TopAbs_FACE, TopAbs_VERTEX);
554 for (; myIterator.More(); myIterator.Next()) {
555 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
556 const TopoDS_Shape& aF1=aCS.Shape1();
557 const TopoDS_Shape& aV2=aCS.Shape2();
560 TopExp::MapShapes(aF1, TopAbs_EDGE, aME);
562 bFound=Standard_False;
564 for (i=1; i<=aNbE; ++i) {
565 const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(i));
566 if (BRep_Tool::Degenerated(aE1)) {
570 bHasOn=myShapesOn.IsBound(aE1);
571 bHasIn=myShapesIn.IsBound(aE1);
572 const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aE1) : aMSX;
573 const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aE1) : aMSX;
574 bFound= (aMSOn.Contains(aV2) || aMSIn.Contains(aV2));
584 bFound=CheckCoincidence(aF1, aV2);
589 FillShapesIn(aF1, aV2);
593 //=======================================================================
594 //function : FillFacesOn
596 //=======================================================================
597 void GEOMAlgo_GetInPlace::FillFacesOn(const TopoDS_Shape &theShape)
599 Standard_Integer i, j, aNbF, aNbE;
601 TopTools_IndexedMapOfShape aMF, aME;
602 TopTools_MapIteratorOfMapOfShape aItMS;
604 TopExp::MapShapes(theShape, TopAbs_FACE, aMF);
606 for (i=1; i<=aNbF; ++i) {
607 const TopoDS_Face& aF1=*((TopoDS_Face*)&aMF(i));
610 TopExp::MapShapes(aF1, TopAbs_EDGE, aME);
612 for (j=1; j<=aNbE; ++j) {
613 const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(j));
614 if (BRep_Tool::Degenerated(aE1)) {
618 if (myShapesOn.IsBound(aE1)) {
619 const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aE1);
620 aItMS.Initialize(aMSOn);
621 for (; aItMS.More(); aItMS.Next()) {
622 const TopoDS_Shape& aS2=aItMS.Key();
623 FillShapesOn(aF1, aS2);
627 if (myShapesIn.IsBound(aE1)) {
628 const TopTools_MapOfShape& aMSIn=myShapesIn.Find(aE1);
629 aItMS.Initialize(aMSIn);
630 for (; aItMS.More(); aItMS.Next()) {
631 const TopoDS_Shape& aS2=aItMS.Key();
632 FillShapesOn(aF1, aS2);
635 }//for (j=1; j<=aNbE; ++j) {
636 }//for (i=1; i<=aNbF; ++i) {
638 //=======================================================================
639 //function : PerformEF
641 //=======================================================================
642 void GEOMAlgo_GetInPlace::PerformEF()
644 Standard_Boolean bFound, bHasOnF, bHasInF;
646 TopTools_MapOfShape aMSX;
651 myIterator.Initialize(TopAbs_FACE, TopAbs_EDGE);
652 for (; myIterator.More(); myIterator.Next()) {
653 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
654 const TopoDS_Shape& aF1=aCS.Shape1();
655 const TopoDS_Shape& aE2=aCS.Shape2();
658 bHasOnF=myShapesOn.IsBound(aF1);
659 const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aF1) : aMSX;
660 bFound=aMSOnF.Contains(aE2);
666 bHasInF=myShapesIn.IsBound(aF1);
667 const TopTools_MapOfShape& aMSInF=(bHasInF) ? myShapesIn.Find(aF1) : aMSX;
670 for (; aIt.More(); aIt.Next()) {
671 const TopoDS_Shape& aV2=aIt.Value();
672 bFound=(aMSOnF.Contains(aV2) || aMSInF.Contains(aV2));
680 //------------------------------
681 bFound=CheckCoincidence(aF1, aE2);
686 FillShapesIn(aF1, aE2);
690 //=======================================================================
691 //function : PerformFF
693 //=======================================================================
694 void GEOMAlgo_GetInPlace::PerformFF()
699 myIterator.Initialize(TopAbs_FACE, TopAbs_FACE);
700 for (; myIterator.More(); myIterator.Next()) {
701 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
702 const TopoDS_Shape& aF1=aCS.Shape1();
703 const TopoDS_Shape& aF2=aCS.Shape2();
718 //=======================================================================
719 //function : PerformFF
721 //=======================================================================
722 void GEOMAlgo_GetInPlace::PerformFF(const TopoDS_Shape &theF1,
723 const TopoDS_Shape &theF2)
725 Standard_Boolean bFound, bHasOnF, bHasInF;
726 Standard_Integer i, aNbS2;
727 TopTools_MapOfShape aMSX;
728 TopTools_IndexedMapOfShape aMS2;
730 bHasOnF=myShapesOn.IsBound(theF1);
731 const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(theF1) : aMSX;
733 bHasInF=myShapesIn.IsBound(theF1);
734 const TopTools_MapOfShape& aMSInF=(bHasInF) ? myShapesIn.Find(theF1) : aMSX;
736 MapBRepShapes(theF2, aMS2);
738 bFound=Standard_False;
740 for (i=1; i<=aNbS2; ++i) {
741 const TopoDS_Shape& aS2=aMS2(i);
742 if (aS2.IsSame(theF2)) {
745 bFound=(aMSOnF.Contains(aS2) || aMSInF.Contains(aS2));
754 bFound=CheckCoincidence(theF1, theF2);
759 FillShapesIn(theF1, theF2);
762 //=======================================================================
763 //function : FillSolidsOn
765 //=======================================================================
766 void GEOMAlgo_GetInPlace::FillSolidsOn(const TopoDS_Shape &theShape)
768 Standard_Integer i, j, aNbS, aNbF;
769 TopTools_IndexedMapOfShape aMS, aMF;
770 TopTools_MapIteratorOfMapOfShape aItMS;
772 TopExp::MapShapes(theShape, TopAbs_SOLID, aMS);
775 for (i=1; i<=aNbS; ++i) {
776 const TopoDS_Shape& aSD1=aMS(i);
779 TopExp::MapShapes(aSD1, TopAbs_FACE, aMF);
781 for (j=1; j<=aNbF; ++j) {
782 const TopoDS_Shape& aF1=aMF(j);
784 if (myShapesOn.IsBound(aF1)) {
785 const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aF1);
786 aItMS.Initialize(aMSOn);
787 for (; aItMS.More(); aItMS.Next()) {
788 const TopoDS_Shape& aS2=aItMS.Key();
789 FillShapesOn(aSD1, aS2);
793 if (myShapesIn.IsBound(aF1)) {
794 const TopTools_MapOfShape& aMSIn=myShapesIn.Find(aF1);
795 aItMS.Initialize(aMSIn);
796 for (; aItMS.More(); aItMS.Next()) {
797 const TopoDS_Shape& aS2=aItMS.Key();
798 FillShapesOn(aSD1, aS2);
801 }//for (j=1; j<=aNbF; ++j) {
802 }//for (i=1; i<=aNbS; ++i) {
804 //=======================================================================
805 //function : PerformZF
807 //=======================================================================
808 void GEOMAlgo_GetInPlace::PerformZF()
810 Standard_Boolean bFound, bHasOnF;
811 TopTools_MapOfShape aMSX;
816 myIterator.Initialize(TopAbs_SOLID, TopAbs_FACE);
817 for (; myIterator.More(); myIterator.Next()) {
818 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
819 const TopoDS_Shape& aSo1=aCS.Shape1();
820 const TopoDS_Shape& aF2=aCS.Shape2();
822 bHasOnF=myShapesOn.IsBound(aSo1);
823 const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aSo1) : aMSX;
824 bFound=aMSOnF.Contains(aF2);
828 //------------------------------
829 bFound=CheckCoincidence(aSo1, aF2);
834 FillShapesIn(aSo1, aF2);
838 //=======================================================================
839 //function : PerformZZ
841 //=======================================================================
842 void GEOMAlgo_GetInPlace::PerformZZ()
847 myIterator.Initialize(TopAbs_SOLID, TopAbs_SOLID);
848 for (; myIterator.More(); myIterator.Next()) {
849 const GEOMAlgo_CoupleOfShapes& aCS=myIterator.Value();
850 const TopoDS_Shape& aSo1=aCS.Shape1();
851 const TopoDS_Shape& aSo2=aCS.Shape2();
853 PerformZZ(aSo1, aSo2);
859 PerformZZ(aSo2, aSo1);
864 }// for (; myIterator.More(); myIterator.Next()) {
866 //=======================================================================
867 //function : PerformZZ
869 //=======================================================================
870 void GEOMAlgo_GetInPlace::PerformZZ(const TopoDS_Shape &theSo1,
871 const TopoDS_Shape &theSo2)
873 Standard_Boolean bFound, bHasOn, bHasIn;
874 Standard_Integer i, aNbS2, iCntOn, iCntIn, iCntOut;
875 TopTools_MapOfShape aMSX;
876 TopTools_IndexedMapOfShape aMS2;
878 bHasOn=myShapesOn.IsBound(theSo1);
879 const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(theSo1) : aMSX;
881 bHasIn=myShapesIn.IsBound(theSo1);
882 const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(theSo1) : aMSX;
884 TopExp::MapShapes(theSo2, TopAbs_FACE, aMS2);
889 bFound=Standard_False;
891 for (i=1; i<=aNbS2; ++i) {
892 const TopoDS_Shape& aF2=aMS2(i);
894 if (aMSIn.Contains(aF2)) {
896 bFound=Standard_True;
899 else if (!aMSOn.Contains(aF2)) {
901 bFound=Standard_False;// out
909 if (!bFound && iCntOut) {
914 bFound=CheckCoincidence(theSo1, theSo2);
920 FillShapesIn(theSo1, theSo2);
923 //=======================================================================
924 //function : FillImages
926 //=======================================================================
927 void GEOMAlgo_GetInPlace::FillImages(const TopoDS_Shape &theShape,
928 const Standard_Boolean IsWhere)
935 FillImgSimple(theShape, TopAbs_VERTEX, IsWhere);
938 FillImgSimple(theShape, TopAbs_EDGE, IsWhere);
941 FillImgComplex(theShape, TopAbs_WIRE, IsWhere);
944 FillImgSimple(theShape, TopAbs_FACE, IsWhere);
947 FillImgComplex(theShape, TopAbs_SHELL, IsWhere);
950 FillImgSimple(theShape, TopAbs_SOLID, IsWhere);
953 FillImgComplex(theShape, TopAbs_COMPSOLID, IsWhere);
956 const TopAbs_ShapeEnum aType = theShape.ShapeType();
958 if (aType == TopAbs_COMPOUND) {
959 FillImgComplex(theShape, IsWhere);
963 //=======================================================================
964 //function : FillImgSimple
966 //=======================================================================
967 void GEOMAlgo_GetInPlace::FillImgSimple
968 (const TopoDS_Shape &theShape,
969 const TopAbs_ShapeEnum theSubShapeType,
970 const Standard_Boolean IsWhere)
972 TopTools_IndexedMapOfShape aMS;
974 TopExp::MapShapes(theShape, theSubShapeType, aMS);
977 const Standard_Integer aNbS = aMS.Extent();
978 const GEOMAlgo_DataMapOfShapeMapOfShape &aShapesInOn =
979 (theSubShapeType == TopAbs_VERTEX ? myShapesOn : myShapesIn);
981 for (i = 1; i <= aNbS; i++) {
982 const TopoDS_Shape& aS = aMS(i);
984 if (aShapesInOn.IsBound(aS)) {
985 const TopTools_MapOfShape& aMSx = aShapesInOn.Find(aS);
986 TopTools_ListOfShape aLSx;
987 TopTools_MapIteratorOfMapOfShape aItMS(aMSx);
989 for (; aItMS.More(); aItMS.Next()) {
990 const TopoDS_Shape& aSx = aItMS.Key();
991 TopAbs_ShapeEnum aType = aSx.ShapeType();
993 if (aType == theSubShapeType){
997 myShapesInclusive.Bind(aSx, aS);
1002 myImages.Bind(aS, aLSx);
1007 //=======================================================================
1008 //function : FillImgComplex
1010 //=======================================================================
1011 void GEOMAlgo_GetInPlace::FillImgComplex(const TopoDS_Shape &theShape,
1012 const Standard_Boolean IsWhere)
1014 TopTools_MapOfShape aMapRemaining;
1015 TopoDS_Iterator aIt(theShape);
1016 TopTools_ListOfShape aLSx;
1017 TopTools_MapOfShape aMSx;
1019 for(; aIt.More(); aIt.Next()) {
1020 const TopoDS_Shape &aSubS = aIt.Value();
1021 TopAbs_ShapeEnum aType = aSubS.ShapeType();
1023 if (aType == TopAbs_COMPOUND) {
1024 // Recursively treat compounds.
1025 FillImgComplex(aSubS, IsWhere);
1028 if (myImages.IsBound(aSubS)) {
1029 const TopTools_ListOfShape& aLSi = myImages.Find(aSubS);
1030 TopTools_ListIteratorOfListOfShape aItLS(aLSi);
1032 for (; aItLS.More(); aItLS.Next()) {
1033 const TopoDS_Shape &aSubSi = aItLS.Value();
1035 if (aMSx.Add(aSubSi)) {
1036 aLSx.Append(aSubSi);
1039 } else if (!IsWhere) {
1040 aMapRemaining.Add(aSubS);
1044 if (!(IsWhere || aMapRemaining.IsEmpty())) {
1045 // Find the whole from parts.
1046 while (!aMapRemaining.IsEmpty()) {
1047 TopTools_MapIteratorOfMapOfShape anIter(aMapRemaining);
1048 const TopoDS_Shape &aShape = anIter.Key();
1050 if (myShapesInclusive.IsBound(aShape)) {
1051 // This "what" shape is inclusive to the "where" shape.
1052 // Get the other inclusive shapes.
1053 const TopoDS_Shape &aSWhere = myShapesInclusive.Find(aShape);
1055 if (myImages.IsBound(aSWhere)) {
1056 // Remove inclusive shapes from aMapRemaining.
1057 const TopTools_ListOfShape& aLWhat = myImages.Find(aSWhere);
1058 TopTools_ListIteratorOfListOfShape aItLS(aLWhat);
1060 for (; aItLS.More(); aItLS.Next()) {
1061 const TopoDS_Shape &aSWhat = aItLS.Value();
1063 aMapRemaining.Remove(aSWhat);
1066 // Add "whole" shape to the list of images.
1067 if (aMSx.Add(aSWhere)) {
1068 aLSx.Append(aSWhere);
1072 // This "what" shape is not inclusive to the "where" shape. Skip it.
1073 aMapRemaining.Remove(aShape);
1078 myImages.Bind(theShape, aLSx);
1081 //=======================================================================
1082 //function : FillImgComplex
1084 //=======================================================================
1085 void GEOMAlgo_GetInPlace::FillImgComplex
1086 (const TopoDS_Shape &theShape,
1087 const TopAbs_ShapeEnum theSubShapeType,
1088 const Standard_Boolean IsWhere)
1090 TopTools_IndexedMapOfShape aMS;
1092 TopExp::MapShapes(theShape, theSubShapeType, aMS);
1095 const Standard_Integer aNbS = aMS.Extent();
1097 for (i=1; i<=aNbS; ++i) {
1098 const TopoDS_Shape &aS = aMS(i);
1100 FillImgComplex(aS, IsWhere);
1104 //=======================================================================
1105 //function : FillShapesIn
1107 //=======================================================================
1108 void GEOMAlgo_GetInPlace::FillShapesIn(const TopoDS_Shape& aS1,
1109 const TopoDS_Shape& aS2)
1111 if (myShapesIn.IsBound(aS1)) {
1112 TopTools_MapOfShape& aMS=myShapesIn.ChangeFind(aS1);
1116 TopTools_MapOfShape aMS;
1119 myShapesIn.Bind(aS1, aMS);
1122 //=======================================================================
1123 //function : FillShapesOn
1125 //=======================================================================
1126 void GEOMAlgo_GetInPlace::FillShapesOn(const TopoDS_Shape& aS1,
1127 const TopoDS_Shape& aS2)
1129 if (myShapesOn.IsBound(aS1)) {
1130 TopTools_MapOfShape& aMS=myShapesOn.ChangeFind(aS1);
1134 TopTools_MapOfShape aMS;
1137 myShapesOn.Bind(aS1, aMS);
1141 //=======================================================================
1142 //function : MapBRepShapes
1144 //=======================================================================
1145 void MapBRepShapes(const TopoDS_Shape& aS,
1146 TopTools_IndexedMapOfShape& aM)
1148 Standard_Boolean bDegenerated;
1149 TopAbs_ShapeEnum aType;
1150 TopoDS_Iterator aIt;
1152 aType=aS.ShapeType();
1153 if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||
1154 aType==TopAbs_FACE || aType==TopAbs_SOLID) {
1155 bDegenerated=Standard_False;
1156 if (aType==TopAbs_EDGE) {
1157 TopoDS_Edge *pE=(TopoDS_Edge*)&aS;
1158 bDegenerated=BRep_Tool::Degenerated(*pE);
1160 if (!bDegenerated) {
1166 for(; aIt.More(); aIt.Next()) {
1167 const TopoDS_Shape& aSx=aIt.Value();
1168 aType=aSx.ShapeType();
1169 MapBRepShapes(aSx, aM);
1172 //=======================================================================
1175 //=======================================================================
1176 const TopoDS_Shape &GEOMAlgo_GetInPlace::Result()
1178 TopoDS_Shape aDummy;
1182 Standard_Boolean bFound;
1185 TopTools_ListIteratorOfListOfShape aItLS;
1187 bFound=myImages.IsBound(myArgument);
1192 aBB.MakeCompound(aC);
1194 const TopTools_ListOfShape& aLS=myImages.Find(myArgument);
1195 aItLS.Initialize(aLS);
1196 for (; aItLS.More(); aItLS.Next()) {
1197 const TopoDS_Shape& aSD=aItLS.Value();