Back to index

salome-geom  6.5.0
GEOMAlgo_GetInPlace.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 // File:     GEOMAlgo_GetInPlace.cxx
00023 // Created:
00024 // Author:   Peter KURNEV
00025 
00026 #include <GEOMAlgo_GetInPlace.hxx>
00027 
00028 #include <NMTDS_BoxBndTree.hxx>
00029 #include <NCollection_UBTreeFiller.hxx>
00030 
00031 #include <Bnd_Box.hxx>
00032 #include <gp_Pnt.hxx>
00033 
00034 #include <TColStd_ListOfInteger.hxx>
00035 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00036 
00037 #include <TopAbs_ShapeEnum.hxx>
00038 
00039 #include <TopoDS_Iterator.hxx>
00040 #include <TopoDS_Shape.hxx>
00041 #include <TopoDS_Vertex.hxx>
00042 #include <TopoDS_Edge.hxx>
00043 #include <TopoDS_Face.hxx>
00044 #include <TopoDS_Compound.hxx>
00045 
00046 #include <BRep_Tool.hxx>
00047 #include <BRep_Builder.hxx>
00048 
00049 #include <BRepBndLib.hxx>
00050 
00051 #include <TopExp.hxx>
00052 
00053 #include <TopTools_IndexedMapOfShape.hxx>
00054 #include <TopTools_ListOfShape.hxx>
00055 #include <TopTools_DataMapOfShapeListOfShape.hxx>
00056 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
00057 #include <TopTools_ListIteratorOfListOfShape.hxx>
00058 #include <TopTools_MapOfShape.hxx>
00059 #include <TopTools_MapIteratorOfMapOfShape.hxx>
00060 
00061 
00062 #include <NMTTools_CoupleOfShape.hxx>
00063 #include <GEOMAlgo_Tools.hxx>
00064 
00065 
00066 static
00067   void MapBRepShapes(const TopoDS_Shape& aS,
00068                      TopTools_IndexedMapOfShape& aM);
00069 
00070 
00071 //=======================================================================
00072 //function : GEOMAlgo_GetInPlace
00073 //purpose  :
00074 //=======================================================================
00075 GEOMAlgo_GetInPlace::GEOMAlgo_GetInPlace()
00076 :
00077   GEOMAlgo_GluerAlgo(),
00078   GEOMAlgo_Algo()
00079 {
00080   myTolerance=0.0001;
00081   myTolMass=0.0001;
00082   myTolCG=0.0001;
00083   myFound=Standard_False;
00084   myCheckGeometry=Standard_True;
00085 }
00086 //=======================================================================
00087 //function : ~
00088 //purpose  :
00089 //=======================================================================
00090 GEOMAlgo_GetInPlace::~GEOMAlgo_GetInPlace()
00091 {
00092 }
00093 //=======================================================================
00094 //function : SetTolMass
00095 //purpose  :
00096 //=======================================================================
00097 void GEOMAlgo_GetInPlace::SetTolMass(const Standard_Real theTol)
00098 {
00099   myTolMass=theTol;
00100 }
00101 //=======================================================================
00102 //function : TolMass
00103 //purpose  :
00104 //=======================================================================
00105 Standard_Real GEOMAlgo_GetInPlace::TolMass()const
00106 {
00107   return myTolMass;
00108 }
00109 //=======================================================================
00110 //function : SetTolCG
00111 //purpose  :
00112 //=======================================================================
00113 void GEOMAlgo_GetInPlace::SetTolCG(const Standard_Real theTol)
00114 {
00115   myTolCG=theTol;
00116 }
00117 //=======================================================================
00118 //function : TolCG
00119 //purpose  :
00120 //=======================================================================
00121 Standard_Real GEOMAlgo_GetInPlace::TolCG()const
00122 {
00123   return myTolCG;
00124 }
00125 //=======================================================================
00126 //function : IsFound
00127 //purpose  :
00128 //=======================================================================
00129 Standard_Boolean GEOMAlgo_GetInPlace::IsFound()const
00130 {
00131   return myFound;
00132 }
00133 //=======================================================================
00134 //function : SetShapeWhere
00135 //purpose  :
00136 //=======================================================================
00137 void GEOMAlgo_GetInPlace::SetShapeWhere(const TopoDS_Shape& theShape)
00138 {
00139   myShapeWhere=theShape;
00140 }
00141 //=======================================================================
00142 //function : ShapeWhere
00143 //purpose  :
00144 //=======================================================================
00145 const TopoDS_Shape& GEOMAlgo_GetInPlace::ShapeWhere()const
00146 {
00147   return myShapeWhere;
00148 }
00149 //=======================================================================
00150 //function : ShapesIn
00151 //purpose  :
00152 //=======================================================================
00153 const GEOMAlgo_DataMapOfShapeMapOfShape& GEOMAlgo_GetInPlace::ShapesIn()const
00154 {
00155   return myShapesIn;
00156 }
00157 //=======================================================================
00158 //function : ShapesOn
00159 //purpose  :
00160 //=======================================================================
00161 const GEOMAlgo_DataMapOfShapeMapOfShape& GEOMAlgo_GetInPlace::ShapesOn()const
00162 {
00163   return myShapesOn;
00164 }
00165 //=======================================================================
00166 //function : Clear
00167 //purpose  :
00168 //=======================================================================
00169 void GEOMAlgo_GetInPlace::Clear()
00170 {
00171   myErrorStatus=0;
00172   myWarningStatus=0;
00173   //
00174   GEOMAlgo_GluerAlgo::Clear();
00175   myIterator.Clear();
00176   myShapesIn.Clear();
00177   myShapesOn.Clear();
00178   myMapShapePnt.Clear();
00179 }
00180 //=======================================================================
00181 //function : Perform
00182 //purpose  :
00183 //=======================================================================
00184 void GEOMAlgo_GetInPlace::Perform()
00185 {
00186   myFound=Standard_False;
00187   myErrorStatus=0;
00188   myWarningStatus=0;
00189   //
00190   Clear();
00191   if (myErrorStatus) {
00192     return;
00193   }
00194   //
00195   CheckData();
00196   if (myErrorStatus) {
00197     return;
00198   }
00199   //
00200   // Initialize the context
00201   GEOMAlgo_GluerAlgo::Perform();
00202   //
00203   Intersect();
00204   if (myErrorStatus) {
00205     return;
00206   }
00207   //
00208   PerformVV();
00209   if (myErrorStatus) {
00210     return;
00211   }
00212   //
00213   FillEdgesOn();
00214   if (myErrorStatus) {
00215     return;
00216   }
00217   //
00218   PerformVE();
00219   if (myErrorStatus) {
00220     return;
00221   }
00222   //
00223   PerformEE();
00224   if (myErrorStatus) {
00225     return;
00226   }
00227   //
00228   PerformVF();
00229   if (myErrorStatus) {
00230     return;
00231   }
00232   //
00233   FillFacesOn();
00234   if (myErrorStatus) {
00235     return;
00236   }
00237   //
00238   PerformEF();
00239   if (myErrorStatus) {
00240     return;
00241   }
00242   //
00243   PerformFF();
00244   if (myErrorStatus) {
00245     return;
00246   }
00247   //
00248   FillSolidsOn();
00249   if (myErrorStatus) {
00250     return;
00251   }
00252   //
00253   PerformZF();
00254   if (myErrorStatus) {
00255     return;
00256   }
00257   //
00258   PerformZZ();
00259   if (myErrorStatus) {
00260     return;
00261   }
00262   //
00263   FillImages();
00264   if (myErrorStatus) {
00265     return;
00266   }
00267   //
00268   CheckGProps();
00269   if (myErrorStatus) {
00270     return;
00271   }
00272 }
00273 //=======================================================================
00274 //function : CheckData
00275 //purpose  :
00276 //=======================================================================
00277 void GEOMAlgo_GetInPlace::CheckData()
00278 {
00279   myErrorStatus=0;
00280   myWarningStatus=0;
00281   //
00282   if (myArgument.IsNull()) {
00283     myErrorStatus=2;
00284     return;
00285   }
00286   //
00287   if (myShapeWhere.IsNull()) {
00288     myErrorStatus=3;
00289     return;
00290   }
00291 }
00292 //=======================================================================
00293 //function : Intersect
00294 //purpose  :
00295 //=======================================================================
00296 void GEOMAlgo_GetInPlace::Intersect()
00297 {
00298   Standard_Integer i, j, aNbS1, aNbS2, aNbSD;
00299   TColStd_ListIteratorOfListOfInteger aItLI;
00300   TopTools_IndexedMapOfShape aMS1, aMS2;
00301   TopTools_DataMapOfShapeListOfShape aDMSLS;
00302   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
00303   TopTools_ListIteratorOfListOfShape aItLS;
00304   NMTTools_CoupleOfShape aCS;
00305   //
00306   NMTDS_BoxBndTreeSelector aSelector;
00307   NMTDS_BoxBndTree aBBTree;
00308   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
00309   //
00310   myErrorStatus=0;
00311   myWarningStatus=0;
00312   //
00313   myIterator.Clear();
00314   //
00315   MapBRepShapes(myArgument, aMS1);
00316   aNbS1=aMS1.Extent();
00317   for (i=1; i<=aNbS1; ++i) {
00318     Bnd_Box aBox1;
00319     //
00320     const TopoDS_Shape& aS1=aMS1(i);
00321     BRepBndLib::Add(aS1, aBox1);
00322     //modified by NIZNHY-PKV Fri Jun 10 08:20:03 2011f
00323     //aBox1.SetGap(myTolerance);
00324     aBox1.Enlarge(myTolerance);
00325     //modified by NIZNHY-PKV Fri Jun 10 08:20:06 2011t
00326     //
00327     aTreeFiller.Add(i, aBox1);
00328   }
00329   //
00330   aTreeFiller.Fill();
00331   //
00332   MapBRepShapes(myShapeWhere, aMS2);
00333   aNbS2=aMS2.Extent();
00334   for (j=1; j<=aNbS2; ++j) {
00335     Bnd_Box aBox2;
00336     //
00337     const TopoDS_Shape& aS2=aMS2(j);
00338     BRepBndLib::Add(aS2, aBox2);
00339     //modified by NIZNHY-PKV Fri Jun 10 08:20:23 2011f
00340     //aBox2.SetGap(myTolerance);
00341     aBox2.Enlarge(myTolerance);
00342     //modified by NIZNHY-PKV Fri Jun 10 08:20:25 2011t
00343     //
00344     aSelector.Clear();
00345     aSelector.SetBox(aBox2);
00346     aNbSD=aBBTree.Select(aSelector);
00347     if (!aNbSD) {
00348       continue;  // it should not be
00349     }
00350     //
00351     const TColStd_ListOfInteger& aLI=aSelector.Indices();
00352     aItLI.Initialize(aLI);
00353     for (; aItLI.More(); aItLI.Next()) {
00354       i=aItLI.Value();
00355       const TopoDS_Shape& aS1=aMS1(i);
00356       //
00357       if (aDMSLS.IsBound(aS1)) {
00358         TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aS1);
00359         aLS.Append(aS2);
00360       }
00361       else {
00362         TopTools_ListOfShape aLS;
00363         //
00364         aLS.Append(aS2);
00365         aDMSLS.Bind(aS1, aLS);
00366       }
00367     }
00368   }// for (j=1; j<=aNbS2; ++j) {
00369   //
00370   aItDMSLS.Initialize(aDMSLS);
00371   for (; aItDMSLS.More(); aItDMSLS.Next()) {
00372     const TopoDS_Shape& aS1=aItDMSLS.Key();
00373     const TopTools_ListOfShape& aLS2=aItDMSLS.Value();
00374     aCS.SetShape1(aS1);
00375     aItLS.Initialize(aLS2);
00376     for (; aItLS.More(); aItLS.Next()) {
00377       const TopoDS_Shape& aS2=aItLS.Value();
00378       aCS.SetShape2(aS2);
00379       myIterator.AppendPair(aCS);
00380     }
00381   }
00382 }
00383 //=======================================================================
00384 //function : PerformVV
00385 //purpose  :
00386 //=======================================================================
00387 void GEOMAlgo_GetInPlace::PerformVV()
00388 {
00389   myErrorStatus=0;
00390   myWarningStatus=0;
00391   //
00392   myIterator.Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
00393   for (; myIterator.More(); myIterator.Next()) {
00394     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00395     const TopoDS_Shape& aV1=aCS.Shape1();
00396     const TopoDS_Shape& aV2=aCS.Shape2();
00397     //
00398     FillShapesOn(aV1, aV2);
00399   }
00400 }
00401 //=======================================================================
00402 //function : FillEdgesOn
00403 //purpose  :
00404 //=======================================================================
00405 void GEOMAlgo_GetInPlace::FillEdgesOn()
00406 {
00407   Standard_Integer i, aNbE;
00408   TopoDS_Iterator aIt;
00409   TopTools_IndexedMapOfShape aME;
00410   TopTools_MapIteratorOfMapOfShape aItMS;
00411   //
00412   TopExp::MapShapes(myArgument, TopAbs_EDGE, aME);
00413   aNbE=aME.Extent();
00414   for (i=1; i<=aNbE; ++i) {
00415     const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(i));
00416     if (BRep_Tool::Degenerated(aE1)) {
00417       continue;
00418     }
00419     //
00420     aIt.Initialize(aE1);
00421     for (; aIt.More(); aIt.Next()) {
00422       const TopoDS_Shape& aV1=aIt.Value();
00423       if (myShapesOn.IsBound(aV1)) {
00424         const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aV1);
00425         //aNbSOn=aMSOn.Extent();
00426         aItMS.Initialize(aMSOn);
00427         for (; aItMS.More(); aItMS.Next()) {
00428           const TopoDS_Shape& aV2=aItMS.Key();
00429           FillShapesOn(aE1, aV2);
00430         }
00431       }
00432     }
00433   }
00434 }
00435 //=======================================================================
00436 //function : PerformVE
00437 //purpose  :
00438 //=======================================================================
00439 void GEOMAlgo_GetInPlace::PerformVE()
00440 {
00441   Standard_Boolean bFound;
00442   //
00443   myErrorStatus=0;
00444   myWarningStatus=0;
00445   //
00446   // 2. Fill Shapes In
00447   myIterator.Initialize(TopAbs_EDGE, TopAbs_VERTEX);
00448   for (; myIterator.More(); myIterator.Next()) {
00449     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00450     const TopoDS_Shape& aE1=aCS.Shape1();
00451     const TopoDS_Shape& aV2=aCS.Shape2();
00452     //
00453     if (myShapesOn.IsBound(aE1)) {
00454       const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aE1);
00455       if (aMSOn.Contains(aV2)) {
00456         continue;
00457       }
00458     }
00459     //
00460     bFound=CheckCoincidence(aE1, aV2);
00461     if (myErrorStatus) {
00462       return;
00463     }
00464     if (bFound) {
00465       FillShapesIn(aE1, aV2);
00466     }
00467   }
00468 }
00469 //=======================================================================
00470 //function : PerformEE
00471 //purpose  :
00472 //=======================================================================
00473 void GEOMAlgo_GetInPlace::PerformEE()
00474 {
00475   Standard_Boolean bHasOn, bHasIn, bFound;
00476   TopoDS_Iterator aIt;
00477   TopTools_MapOfShape aMSX;
00478   //
00479   myErrorStatus=0;
00480   myWarningStatus=0;
00481   //
00482   myIterator.Initialize(TopAbs_EDGE, TopAbs_EDGE);
00483   for (; myIterator.More(); myIterator.Next()) {
00484     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00485     const TopoDS_Shape& aE1=aCS.Shape1();
00486     const TopoDS_Shape& aE2=aCS.Shape2();
00487     //
00488     bHasOn=myShapesOn.IsBound(aE1);
00489     bHasIn=myShapesIn.IsBound(aE1);
00490     const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aE1) : aMSX;
00491     const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aE1) : aMSX;
00492     //
00493     bFound=Standard_True;
00494     aIt.Initialize(aE2);
00495     for (; aIt.More(); aIt.Next()) {
00496       const TopoDS_Shape& aV2=aIt.Value();
00497       if (!(aMSOn.Contains(aV2) || aMSIn.Contains(aV2))) {
00498         bFound=!bFound;
00499         break;
00500       }
00501     }
00502     if (!bFound) {
00503       continue;
00504     }
00505     //
00506     bFound=CheckCoincidence(aE1, aE2);
00507     if (myErrorStatus) {
00508       return;
00509     }
00510     if (bFound) {
00511       FillShapesIn(aE1, aE2);
00512     }
00513   }
00514 }
00515 //=======================================================================
00516 //function : PerformVF
00517 //purpose  :
00518 //=======================================================================
00519 void GEOMAlgo_GetInPlace::PerformVF()
00520 {
00521   Standard_Boolean bHasOn, bHasIn, bFound;
00522   Standard_Integer i, aNbE;
00523   TopTools_MapOfShape aMSX;
00524   TopTools_IndexedMapOfShape aME;
00525   //
00526   myErrorStatus=0;
00527   myWarningStatus=0;
00528   //
00529   myIterator.Initialize(TopAbs_FACE, TopAbs_VERTEX);
00530   for (; myIterator.More(); myIterator.Next()) {
00531     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00532     const TopoDS_Shape& aF1=aCS.Shape1();
00533     const TopoDS_Shape& aV2=aCS.Shape2();
00534     //
00535     aME.Clear();
00536     TopExp::MapShapes(aF1, TopAbs_EDGE, aME);
00537     //
00538     bFound=Standard_False;
00539     aNbE=aME.Extent();
00540     for (i=1; i<=aNbE; ++i) {
00541       const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(i));
00542       if (BRep_Tool::Degenerated(aE1)) {
00543         continue;
00544       }
00545       //
00546       bHasOn=myShapesOn.IsBound(aE1);
00547       bHasIn=myShapesIn.IsBound(aE1);
00548       const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aE1) : aMSX;
00549       const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aE1) : aMSX;
00550       bFound= (aMSOn.Contains(aV2) || aMSIn.Contains(aV2));
00551       if (bFound) {
00552         break;
00553       }
00554     }
00555     //
00556     if (bFound) {
00557       continue;
00558     }
00559     //
00560     bFound=CheckCoincidence(aF1, aV2);
00561     if (myErrorStatus) {
00562       return;
00563     }
00564     if (bFound) {
00565       FillShapesIn(aF1, aV2);
00566     }
00567   }
00568 }
00569 //=======================================================================
00570 //function : FillFacesOn
00571 //purpose  :
00572 //=======================================================================
00573 void GEOMAlgo_GetInPlace::FillFacesOn()
00574 {
00575   Standard_Integer i, j, aNbF, aNbE;
00576   TopoDS_Iterator aIt;
00577   TopTools_IndexedMapOfShape aMF, aME;
00578   TopTools_MapIteratorOfMapOfShape aItMS;
00579   //
00580   TopExp::MapShapes(myArgument, TopAbs_FACE, aMF);
00581   aNbF=aMF.Extent();
00582   for (i=1; i<=aNbF; ++i) {
00583     const TopoDS_Face& aF1=*((TopoDS_Face*)&aMF(i));
00584     //
00585     aME.Clear();
00586     TopExp::MapShapes(aF1, TopAbs_EDGE, aME);
00587     aNbE=aME.Extent();
00588     for (j=1; j<=aNbE; ++j) {
00589       const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(j));
00590       if (BRep_Tool::Degenerated(aE1)) {
00591         continue;
00592       }
00593       //
00594       if (myShapesOn.IsBound(aE1)) {
00595         const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aE1);
00596         aItMS.Initialize(aMSOn);
00597         for (; aItMS.More(); aItMS.Next()) {
00598           const TopoDS_Shape& aS2=aItMS.Key();
00599           FillShapesOn(aF1, aS2);
00600         }
00601       }
00602       //
00603       if (myShapesIn.IsBound(aE1)) {
00604         const TopTools_MapOfShape& aMSIn=myShapesIn.Find(aE1);
00605         aItMS.Initialize(aMSIn);
00606         for (; aItMS.More(); aItMS.Next()) {
00607           const TopoDS_Shape& aS2=aItMS.Key();
00608           FillShapesOn(aF1, aS2);
00609         }
00610       }
00611     }//for (j=1; j<=aNbE; ++j) {
00612   }//for (i=1; i<=aNbF; ++i) {
00613 }
00614 //=======================================================================
00615 //function : PerformEF
00616 //purpose  :
00617 //=======================================================================
00618 void GEOMAlgo_GetInPlace::PerformEF()
00619 {
00620   Standard_Boolean  bFound, bHasOnF, bHasInF;
00621   TopoDS_Iterator aIt;
00622   TopTools_MapOfShape aMSX;
00623   //
00624   myErrorStatus=0;
00625   myWarningStatus=0;
00626   //
00627   myIterator.Initialize(TopAbs_FACE, TopAbs_EDGE);
00628   for (; myIterator.More(); myIterator.Next()) {
00629     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00630     const TopoDS_Shape& aF1=aCS.Shape1();
00631     const TopoDS_Shape& aE2=aCS.Shape2();
00632     //
00633     // 1.
00634     bHasOnF=myShapesOn.IsBound(aF1);
00635     const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aF1) : aMSX;
00636     bFound=aMSOnF.Contains(aE2);
00637     if (bFound) {
00638       continue;
00639     }
00640     //
00641     // 2.
00642     bHasInF=myShapesIn.IsBound(aF1);
00643     const TopTools_MapOfShape& aMSInF=(bHasInF) ? myShapesIn.Find(aF1) : aMSX;
00644     //
00645     aIt.Initialize(aE2);
00646     for (; aIt.More(); aIt.Next()) {
00647       const TopoDS_Shape& aV2=aIt.Value();
00648       bFound=(aMSOnF.Contains(aV2) || aMSInF.Contains(aV2));
00649       if (!bFound) {
00650         break;
00651       }
00652     }
00653     if (!bFound) {
00654       continue;
00655     }
00656     //------------------------------
00657     bFound=CheckCoincidence(aF1, aE2);
00658     if (myErrorStatus) {
00659       return;
00660     }
00661     if (bFound) {
00662       FillShapesIn(aF1, aE2);
00663     }
00664   }
00665 }
00666 //=======================================================================
00667 //function : PerformFF
00668 //purpose  :
00669 //=======================================================================
00670 void GEOMAlgo_GetInPlace::PerformFF()
00671 {
00672   Standard_Boolean  bFound, bHasOnF, bHasInF;
00673   Standard_Integer i, aNbS2;
00674   TopTools_MapOfShape aMSX;
00675   TopTools_IndexedMapOfShape aMS2;
00676   //
00677   myErrorStatus=0;
00678   myWarningStatus=0;
00679   //
00680   myIterator.Initialize(TopAbs_FACE, TopAbs_FACE);
00681   for (; myIterator.More(); myIterator.Next()) {
00682     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00683     const TopoDS_Shape& aF1=aCS.Shape1();
00684     const TopoDS_Shape& aF2=aCS.Shape2();
00685     //
00686     bHasOnF=myShapesOn.IsBound(aF1);
00687     const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aF1) : aMSX;
00688     //
00689     bHasInF=myShapesIn.IsBound(aF1);
00690     const TopTools_MapOfShape& aMSInF=(bHasInF) ? myShapesIn.Find(aF1) : aMSX;
00691     //
00692     aMS2.Clear();
00693     MapBRepShapes(aF2, aMS2);
00694     //
00695     bFound=Standard_False;
00696     aNbS2=aMS2.Extent();
00697     for (i=1; i<=aNbS2; ++i) {
00698       const TopoDS_Shape& aS2=aMS2(i);
00699       if (aS2.IsSame(aF2)) {
00700         continue;
00701       }
00702       bFound=(aMSOnF.Contains(aS2) || aMSInF.Contains(aS2));
00703       if (!bFound) {
00704         break;
00705       }
00706     }
00707     if (!bFound) {
00708       continue;
00709     }
00710     //
00711     bFound=CheckCoincidence(aF1, aF2);
00712     if (myErrorStatus) {
00713       return;
00714     }
00715     if (bFound) {
00716       FillShapesIn(aF1, aF2);
00717     }
00718   }
00719 }
00720 //=======================================================================
00721 //function : FillSolidsOn
00722 //purpose  :
00723 //=======================================================================
00724 void GEOMAlgo_GetInPlace::FillSolidsOn()
00725 {
00726   Standard_Integer i, j, aNbS, aNbF;
00727   TopTools_IndexedMapOfShape aMS, aMF;
00728   TopTools_MapIteratorOfMapOfShape aItMS;
00729   //
00730   TopExp::MapShapes(myArgument, TopAbs_SOLID, aMS);
00731   //
00732   aNbS=aMS.Extent();
00733   for (i=1; i<=aNbS; ++i) {
00734     const TopoDS_Shape& aSD1=aMS(i);
00735     //
00736     aMF.Clear();
00737     TopExp::MapShapes(aSD1, TopAbs_FACE, aMF);
00738     aNbF=aMF.Extent();
00739     for (j=1; j<=aNbF; ++j) {
00740       const TopoDS_Shape& aF1=aMF(j);
00741       //
00742       if (myShapesOn.IsBound(aF1)) {
00743         const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aF1);
00744         aItMS.Initialize(aMSOn);
00745         for (; aItMS.More(); aItMS.Next()) {
00746           const TopoDS_Shape& aS2=aItMS.Key();
00747           FillShapesOn(aSD1, aS2);
00748         }
00749       }
00750       //
00751       if (myShapesIn.IsBound(aF1)) {
00752         const TopTools_MapOfShape& aMSIn=myShapesIn.Find(aF1);
00753         aItMS.Initialize(aMSIn);
00754         for (; aItMS.More(); aItMS.Next()) {
00755           const TopoDS_Shape& aS2=aItMS.Key();
00756           FillShapesOn(aSD1, aS2);
00757         }
00758       }
00759     }//for (j=1; j<=aNbF; ++j) {
00760   }//for (i=1; i<=aNbS; ++i) {
00761 }
00762 //=======================================================================
00763 //function : PerformZF
00764 //purpose  :
00765 //=======================================================================
00766 void GEOMAlgo_GetInPlace::PerformZF()
00767 {
00768   Standard_Boolean  bFound, bHasOnF;
00769   TopTools_MapOfShape aMSX;
00770   //
00771   myErrorStatus=0;
00772   myWarningStatus=0;
00773   //
00774   myIterator.Initialize(TopAbs_SOLID, TopAbs_FACE);
00775   for (; myIterator.More(); myIterator.Next()) {
00776     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00777     const TopoDS_Shape& aSo1=aCS.Shape1();
00778     const TopoDS_Shape& aF2=aCS.Shape2();
00779     //
00780     bHasOnF=myShapesOn.IsBound(aSo1);
00781     const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aSo1) : aMSX;
00782     bFound=aMSOnF.Contains(aF2);
00783     if (bFound) {
00784       continue;
00785     }
00786     //------------------------------
00787     bFound=CheckCoincidence(aSo1, aF2);
00788     if (myErrorStatus) {
00789       return;
00790     }
00791     if (bFound) {
00792       FillShapesIn(aSo1, aF2);
00793     }
00794   }
00795 }
00796 //=======================================================================
00797 //function : PerformZZ
00798 //purpose  :
00799 //=======================================================================
00800 void GEOMAlgo_GetInPlace::PerformZZ()
00801 {
00802   Standard_Boolean bFound, bHasOn, bHasIn;
00803   Standard_Integer i, aNbS2, iCntOn, iCntIn, iCntOut;
00804   TopTools_MapOfShape aMSX;
00805   TopTools_IndexedMapOfShape aMS2;
00806   //
00807   myErrorStatus=0;
00808   myWarningStatus=0;
00809   //
00810   myIterator.Initialize(TopAbs_SOLID, TopAbs_SOLID);
00811   for (; myIterator.More(); myIterator.Next()) {
00812     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
00813     const TopoDS_Shape& aSo1=aCS.Shape1();
00814     const TopoDS_Shape& aSo2=aCS.Shape2();
00815     //
00816     bHasOn=myShapesOn.IsBound(aSo1);
00817     const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aSo1) : aMSX;
00818     //
00819     bHasIn=myShapesIn.IsBound(aSo1);
00820     const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aSo1) : aMSX;
00821     //
00822     aMS2.Clear();
00823     TopExp::MapShapes(aSo2, TopAbs_FACE, aMS2);
00824     //
00825     iCntIn=0;
00826     iCntOn=0;
00827     iCntOut=0;
00828     bFound=Standard_False;
00829     aNbS2=aMS2.Extent();
00830     for (i=1; i<=aNbS2; ++i) {
00831       const TopoDS_Shape& aF2=aMS2(i);
00832       //
00833       if (aMSIn.Contains(aF2)) {
00834         ++iCntIn;
00835         bFound=Standard_True;
00836         break;
00837       }
00838       else if (!aMSOn.Contains(aF2)) {
00839         ++iCntOut;
00840         bFound=Standard_False;// out
00841         break;
00842       }
00843       else {
00844         ++iCntOn; //on
00845       }
00846     }
00847     //
00848     if (!bFound && iCntOut) {
00849       continue;
00850     }
00851     //
00852     if (!iCntIn) {
00853       bFound=CheckCoincidence(aSo1, aSo2);
00854       if (myErrorStatus) {
00855         return;
00856       }
00857     }
00858     if (bFound) {
00859       FillShapesIn(aSo1, aSo2);
00860     }
00861   }// for (; myIterator.More(); myIterator.Next()) {
00862 }
00863 //=======================================================================
00864 //function : FillImages
00865 //purpose  :
00866 //=======================================================================
00867 void GEOMAlgo_GetInPlace::FillImages()
00868 {
00869   Standard_Integer i, aNbS, aNbSx, aNbSi;
00870   TopAbs_ShapeEnum aType;
00871   TopoDS_Iterator aIt;
00872   TopTools_ListOfShape aLSx;
00873   TopTools_ListIteratorOfListOfShape aItLS;
00874   TopTools_IndexedMapOfShape aMS;
00875   TopTools_MapIteratorOfMapOfShape aItMS;
00876   //
00877   myErrorStatus=0;
00878   myWarningStatus=0;
00879   //
00880   myImages.Clear();
00881   //
00882   // 1. Vertices
00883   aMS.Clear();
00884   TopExp::MapShapes(myArgument, TopAbs_VERTEX, aMS);
00885   aNbS=aMS.Extent();
00886   for (i=1; i<=aNbS; ++i) {
00887     const TopoDS_Shape& aV=aMS(i);
00888     if (myShapesOn.IsBound(aV)) {
00889       const TopTools_MapOfShape& aMSx=myShapesOn.Find(aV);
00890       aNbSx=aMSx.Extent();
00891       //
00892       aLSx.Clear();
00893       aItMS.Initialize(aMSx);
00894       for (; aItMS.More(); aItMS.Next()) {
00895         const TopoDS_Shape& aVx=aItMS.Key();
00896         aLSx.Append(aVx);
00897       }
00898       //
00899       myImages.Bind(aV, aLSx);
00900     }
00901   }
00902   //
00903   // 2. Edges
00904   aMS.Clear();
00905   TopExp::MapShapes(myArgument, TopAbs_EDGE, aMS);
00906   aNbS=aMS.Extent();
00907   for (i=1; i<=aNbS; ++i) {
00908     const TopoDS_Shape& aE=aMS(i);
00909     if (myShapesIn.IsBound(aE)) {
00910       const TopTools_MapOfShape& aMSx=myShapesIn.Find(aE);
00911       aNbSx=aMSx.Extent();
00912       //
00913       aLSx.Clear();
00914       aItMS.Initialize(aMSx);
00915       for (; aItMS.More(); aItMS.Next()) {
00916         const TopoDS_Shape& aEx=aItMS.Key();
00917         aType=aEx.ShapeType();
00918         if (aType==TopAbs_EDGE){
00919           aLSx.Append(aEx);
00920         }
00921       }
00922       //
00923       myImages.Bind(aE, aLSx);
00924     }
00925   }
00926   //
00927   // 3. Wires
00928   aMS.Clear();
00929   TopExp::MapShapes(myArgument, TopAbs_WIRE, aMS);
00930   aNbS=aMS.Extent();
00931   for (i=1; i<=aNbS; ++i) {
00932     const TopoDS_Shape& aW=aMS(i);
00933     aLSx.Clear();
00934     aIt.Initialize(aW);
00935     for(; aIt.More(); aIt.Next()) {
00936       const TopoDS_Shape& aE=aIt.Value();
00937       if (myImages.IsBound(aE)) {
00938         const TopTools_ListOfShape& aLSi=myImages.Find(aE);
00939         aNbSi=aLSi.Extent();
00940         //
00941         aItLS.Initialize(aLSi);
00942         for (; aItLS.More(); aItLS.Next()) {
00943           const TopoDS_Shape& aEi=aItLS.Value();
00944           aLSx.Append(aEi);
00945         }
00946       }
00947     }
00948     myImages.Bind(aW, aLSx);
00949   }
00950   //
00951   // 4. Faces
00952   aMS.Clear();
00953   TopExp::MapShapes(myArgument, TopAbs_FACE, aMS);
00954   aNbS=aMS.Extent();
00955   for (i=1; i<=aNbS; ++i) {
00956     const TopoDS_Shape& aF=aMS(i);
00957     if (myShapesIn.IsBound(aF)) {
00958       const TopTools_MapOfShape& aMSx=myShapesIn.Find(aF);
00959       aNbSx=aMSx.Extent();
00960       //
00961       aLSx.Clear();
00962       aItMS.Initialize(aMSx);
00963       for (; aItMS.More(); aItMS.Next()) {
00964         const TopoDS_Shape& aFx=aItMS.Key();
00965         aType=aFx.ShapeType();
00966         if (aType==TopAbs_FACE){
00967           aLSx.Append(aFx);
00968         }
00969       }
00970       //
00971       myImages.Bind(aF, aLSx);
00972     }
00973   }
00974   //
00975   // 5. Shells
00976   aMS.Clear();
00977   TopExp::MapShapes(myArgument, TopAbs_SHELL, aMS);
00978   aNbS=aMS.Extent();
00979   for (i=1; i<=aNbS; ++i) {
00980     const TopoDS_Shape& aSh=aMS(i);
00981     aLSx.Clear();
00982     aIt.Initialize(aSh);
00983     for(; aIt.More(); aIt.Next()) {
00984       const TopoDS_Shape& aF=aIt.Value();
00985       if (myImages.IsBound(aF)) {
00986         const TopTools_ListOfShape& aLSi=myImages.Find(aF);
00987         aNbSi=aLSi.Extent();
00988         //
00989         aItLS.Initialize(aLSi);
00990         for (; aItLS.More(); aItLS.Next()) {
00991           const TopoDS_Shape& aFi=aItLS.Value();
00992           aLSx.Append(aFi);
00993         }
00994       }
00995     }
00996     myImages.Bind(aSh, aLSx);
00997   }
00998   //
00999   // 6. Solids
01000   aMS.Clear();
01001   TopExp::MapShapes(myArgument, TopAbs_SOLID, aMS);
01002   aNbS=aMS.Extent();
01003   for (i=1; i<=aNbS; ++i) {
01004     const TopoDS_Shape& aZ=aMS(i);
01005     if (myShapesIn.IsBound(aZ)) {
01006       const TopTools_MapOfShape& aMSx=myShapesIn.Find(aZ);
01007       aNbSx=aMSx.Extent();
01008       //
01009       aLSx.Clear();
01010       aItMS.Initialize(aMSx);
01011       for (; aItMS.More(); aItMS.Next()) {
01012         const TopoDS_Shape& aZx=aItMS.Key();
01013         aType=aZx.ShapeType();
01014         if (aType==TopAbs_SOLID){
01015           aLSx.Append(aZx);
01016         }
01017       }
01018       //
01019       myImages.Bind(aZ, aLSx);
01020     }
01021   }
01022   //
01023   // 7. CompSolids
01024   aMS.Clear();
01025   TopExp::MapShapes(myArgument, TopAbs_COMPSOLID, aMS);
01026   aNbS=aMS.Extent();
01027   for (i=1; i<=aNbS; ++i) {
01028     const TopoDS_Shape& aCs=aMS(i);
01029     aLSx.Clear();
01030     aIt.Initialize(aCs);
01031     for(; aIt.More(); aIt.Next()) {
01032       const TopoDS_Shape& aZ=aIt.Value();
01033       if (myImages.IsBound(aZ)) {
01034         const TopTools_ListOfShape& aLSi=myImages.Find(aZ);
01035         aNbSi=aLSi.Extent();
01036         //
01037         aItLS.Initialize(aLSi);
01038         for (; aItLS.More(); aItLS.Next()) {
01039           const TopoDS_Shape& aZi=aItLS.Value();
01040           aLSx.Append(aZi);
01041         }
01042       }
01043     }
01044     myImages.Bind(aCs, aLSx);
01045   }
01046   //
01047   // 8. Compounds
01048   aType=myArgument.ShapeType();
01049   if (aType==TopAbs_COMPOUND) {
01050     FillImagesCompound(myArgument);
01051   }
01052 }
01053 //=======================================================================
01054 //function : FillImagesCompound
01055 //purpose  :
01056 //=======================================================================
01057 void GEOMAlgo_GetInPlace::FillImagesCompound(const TopoDS_Shape& aS)
01058 {
01059   TopAbs_ShapeEnum aType;
01060   TopoDS_Iterator aIt;
01061   TopTools_ListOfShape aLSx;
01062   TopTools_ListIteratorOfListOfShape aItLS;
01063   //
01064   aIt.Initialize(aS);
01065   for(; aIt.More(); aIt.Next()) {
01066     const TopoDS_Shape& aSx=aIt.Value();
01067     aType=aSx.ShapeType();
01068     //
01069     if (aType==TopAbs_COMPOUND) {
01070       FillImagesCompound(aSx);
01071     }
01072     //
01073     if (myImages.IsBound(aSx)) {
01074       const TopTools_ListOfShape& aLSi=myImages.Find(aSx);
01075       aItLS.Initialize(aLSi);
01076       for (; aItLS.More(); aItLS.Next()) {
01077         const TopoDS_Shape& aSi=aItLS.Value();
01078         aLSx.Append(aSi);
01079       }
01080     }
01081   }
01082   myImages.Bind(aS, aLSx);
01083 }
01084 
01085 //=======================================================================
01086 //function : FillShapesIn
01087 //purpose  :
01088 //=======================================================================
01089 void GEOMAlgo_GetInPlace::FillShapesIn(const TopoDS_Shape& aS1,
01090                                        const TopoDS_Shape& aS2)
01091 {
01092   if (myShapesIn.IsBound(aS1)) {
01093     TopTools_MapOfShape& aMS=myShapesIn.ChangeFind(aS1);
01094     aMS.Add(aS2);
01095   }
01096   else {
01097     TopTools_MapOfShape aMS;
01098     //
01099     aMS.Add(aS2);
01100     myShapesIn.Bind(aS1, aMS);
01101   }
01102 }
01103 //=======================================================================
01104 //function : FillShapesOn
01105 //purpose  :
01106 //=======================================================================
01107 void GEOMAlgo_GetInPlace::FillShapesOn(const TopoDS_Shape& aS1,
01108                                        const TopoDS_Shape& aS2)
01109 {
01110   if (myShapesOn.IsBound(aS1)) {
01111     TopTools_MapOfShape& aMS=myShapesOn.ChangeFind(aS1);
01112     aMS.Add(aS2);
01113   }
01114   else {
01115     TopTools_MapOfShape aMS;
01116     //
01117     aMS.Add(aS2);
01118     myShapesOn.Bind(aS1, aMS);
01119   }
01120 }
01121 //=======================================================================
01122 //function : MapBRepShapes
01123 //purpose  :
01124 //=======================================================================
01125 void MapBRepShapes(const TopoDS_Shape& aS,
01126                    TopTools_IndexedMapOfShape& aM)
01127 {
01128   Standard_Boolean bDegenerated;
01129   TopAbs_ShapeEnum aType;
01130   TopoDS_Iterator aIt;
01131   //
01132   aType=aS.ShapeType();
01133   if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||
01134       aType==TopAbs_FACE   || aType==TopAbs_SOLID) {
01135     bDegenerated=Standard_False;
01136     if (aType==TopAbs_EDGE) {
01137       TopoDS_Edge *pE=(TopoDS_Edge*)&aS;
01138       bDegenerated=BRep_Tool::Degenerated(*pE);
01139     }
01140     if (!bDegenerated) {
01141       aM.Add(aS);
01142     }
01143   }
01144   //
01145   aIt.Initialize(aS);
01146   for(; aIt.More(); aIt.Next()) {
01147     const TopoDS_Shape& aSx=aIt.Value();
01148     aType=aSx.ShapeType();
01149     MapBRepShapes(aSx, aM);
01150   }
01151 }