Back to index

salome-geom  6.5.0
GEOMAlgo_Builder_3.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_Builder_3.cxx
00023 //  Created :
00024 //  Author  : Peter KURNEV
00025 
00026 #include <GEOMAlgo_Builder.hxx>
00027 
00028 #include <TopAbs_State.hxx>
00029 
00030 #include <TopoDS.hxx>
00031 #include <TopoDS_Iterator.hxx>
00032 #include <TopoDS_Solid.hxx>
00033 #include <TopoDS_Shape.hxx>
00034 #include <TopoDS_Face.hxx>
00035 #include <TopoDS_Solid.hxx>
00036 #include <TopoDS_Iterator.hxx>
00037 #include <TopoDS_Shell.hxx>
00038 #include <TopoDS_Compound.hxx>
00039 
00040 #include <TopExp.hxx>
00041 #include <TopExp_Explorer.hxx>
00042 
00043 #include <BRep_Builder.hxx>
00044 #include <BRepTools.hxx>
00045 #include <BRepClass3d_SolidClassifier.hxx>
00046 
00047 #include <TopTools_ListOfShape.hxx>
00048 #include <TopTools_IndexedMapOfShape.hxx>
00049 #include <TopTools_ListIteratorOfListOfShape.hxx>
00050 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00051 #include <TopTools_IndexedMapOfShape.hxx>
00052 #include <TopTools_MapIteratorOfMapOfShape.hxx>
00053 #include <TopTools_DataMapOfShapeShape.hxx>
00054 #include <TopTools_DataMapOfShapeInteger.hxx>
00055 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
00056 #include <TopTools_MapOfShape.hxx>
00057 
00058 #include <IntTools_Context.hxx>
00059 
00060 #include <NMTDS_ShapesDataStructure.hxx>
00061 #include <NMTTools_PaveFiller.hxx>
00062 
00063 #include <GEOMAlgo_Tools3D.hxx>
00064 #include <GEOMAlgo_BuilderSolid.hxx>
00065 #include <GEOMAlgo_ShapeSet.hxx>
00066 #include <GEOMAlgo_DataMapOfShapeShapeSet.hxx>
00067 #include <GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet.hxx>
00068 
00069 
00070 
00071 static
00072   void OwnInternalShapes(const TopoDS_Shape& ,
00073                          TopTools_IndexedMapOfShape& );
00074 
00075 //=======================================================================
00076 //function : FillImagesSolids
00077 //purpose  :
00078 //=======================================================================
00079   void GEOMAlgo_Builder::FillImagesSolids()
00080 {
00081   myErrorStatus=0;
00082   //
00083   FillIn3DParts();
00084   BuildSplitSolids();
00085   FillInternalShapes();
00086 }
00087 //=======================================================================
00088 //function : BuildDraftSolid
00089 //purpose  :
00090 //=======================================================================
00091 void GEOMAlgo_Builder::BuildDraftSolid (const TopoDS_Shape& theSolid,
00092                                         TopoDS_Shape& theDraftSolid,
00093                                         TopTools_ListOfShape& theLIF)
00094 {
00095   myErrorStatus=0;
00096   //
00097   NMTTools_PaveFiller* pPF=myPaveFiller;
00098   const Handle(IntTools_Context)& aCtx= pPF->Context();
00099   //
00100   Standard_Boolean bToReverse;
00101   Standard_Integer  iFlag;
00102   TopAbs_Orientation aOrF, aOrSh, aOrSd;
00103   TopoDS_Iterator aIt1, aIt2;
00104   TopTools_ListIteratorOfListOfShape aItS;
00105   BRep_Builder aBB;
00106   TopoDS_Shell aShD;
00107   TopoDS_Shape aFSDx, aFx;
00108   //
00109   aOrSd=theSolid.Orientation();
00110   theDraftSolid.Orientation(aOrSd);
00111   //
00112   aIt1.Initialize(theSolid);
00113   for (; aIt1.More(); aIt1.Next()) {
00114     const TopoDS_Shape& aSh=aIt1.Value();
00115     if(aSh.ShapeType()!=TopAbs_SHELL) {
00116       continue; // mb internal edges,vertices
00117     }
00118     //
00119     aOrSh=aSh.Orientation();
00120     aBB.MakeShell(aShD);
00121     aShD.Orientation(aOrSh);
00122     iFlag=0;
00123     //
00124     aIt2.Initialize(aSh);
00125     for (; aIt2.More(); aIt2.Next()) {
00126       const TopoDS_Shape& aF=aIt2.Value();
00127       aOrF=aF.Orientation();
00128       //
00129       if (myImages.HasImage(aF)) {
00130         const TopTools_ListOfShape& aLSp=myImages.Image(aF);
00131         aItS.Initialize(aLSp);
00132         for (; aItS.More(); aItS.Next()) {
00133           aFx=aItS.Value();
00134           //
00135           if (mySameDomainShapes.Contains(aFx)) {
00136             aFSDx=mySameDomainShapes.FindFromKey(aFx);
00137             //
00138             if (aOrF==TopAbs_INTERNAL) {
00139               aFSDx.Orientation(aOrF);
00140               theLIF.Append(aFSDx);
00141             }
00142             else {
00143               bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFSDx, aF, aCtx);
00144               if (bToReverse) {
00145                 aFSDx.Reverse();
00146               }
00147               //
00148               iFlag=1;
00149               aBB.Add(aShD, aFSDx);
00150             }
00151           }// if (mySameDomainShapes.Contains(aFx)) {
00152           else {
00153             aFx.Orientation(aOrF);
00154             if (aOrF==TopAbs_INTERNAL) {
00155               theLIF.Append(aFx);
00156             }
00157             else{
00158               iFlag=1;
00159               aBB.Add(aShD, aFx);
00160             }
00161           }
00162         }
00163       } //if (myImages.HasImage(aF)) {
00164       //
00165       else {
00166         if (aOrF==TopAbs_INTERNAL) {
00167           theLIF.Append(aF);
00168         }
00169         else{
00170           iFlag=1;
00171           aBB.Add(aShD, aF);
00172         }
00173       }
00174     } //for (; aIt2.More(); aIt2.Next()) {
00175     //
00176     if (iFlag) {
00177       aBB.Add(theDraftSolid, aShD);
00178     }
00179   } //for (; aIt1.More(); aIt1.Next()) {
00180 }
00181 //=======================================================================
00182 //function : FillIn3DParts
00183 //purpose  :
00184 //=======================================================================
00185   void GEOMAlgo_Builder::FillIn3DParts()
00186 {
00187   myErrorStatus=0;
00188   //
00189   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00190   NMTTools_PaveFiller* pPF=myPaveFiller;
00191   const Handle(IntTools_Context)& aCtx= pPF->Context();
00192   //
00193   Standard_Boolean bIsIN, bHasImage;
00194   Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF;
00195   TopAbs_ShapeEnum aType;
00196   TopAbs_State aState;
00197   TopTools_IndexedMapOfShape aMSolids, aMS, aMFaces, aMFIN;
00198   TopTools_MapOfShape aMFDone;
00199   TopTools_IndexedDataMapOfShapeListOfShape aMEF;
00200   TopTools_ListIteratorOfListOfShape aItS;
00201   TopoDS_Iterator aIt, aItF;
00202   BRep_Builder aBB;
00203   TopoDS_Solid aSolidSp;
00204   TopoDS_Face aFP;
00205   //
00206   myDraftSolids.Clear();
00207   //
00208   aNbS=aDS.NumberOfShapesOfTheObject();
00209   for (i=1; i<=aNbS; ++i) {
00210     const TopoDS_Shape& aS=aDS.Shape(i);
00211     //
00212     aType=aS.ShapeType();
00213     if (aType==TopAbs_SOLID) {
00214       // all solids from DS
00215       aMSolids.Add(aS);
00216     }
00217     else if (aType==TopAbs_FACE) {
00218       // all faces (originals from DS or theirs images)
00219       if (myImages.HasImage(aS)) {
00220         const TopTools_ListOfShape& aLS=myImages.Image(aS);
00221         aItS.Initialize(aLS);
00222         for (; aItS.More(); aItS.Next()) {
00223           const TopoDS_Shape& aFx=aItS.Value();
00224           //
00225           if (mySameDomainShapes.Contains(aFx)) {
00226             const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aFx);
00227             aMFaces.Add(aFSDx);
00228           }
00229           else {
00230             aMFaces.Add(aFx);
00231           }
00232         }
00233       }
00234       else {
00235         if (mySameDomainShapes.Contains(aS)) {
00236           const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aS);
00237           aMFaces.Add(aFSDx);
00238         }
00239         else {
00240           aMFaces.Add(aS);
00241         }
00242       }
00243     }
00244   }
00245   //
00246   aNbFaces=aMFaces.Extent();
00247   aNbSolids=aMSolids.Extent();
00248   //
00249   for (i=1; i<=aNbSolids; ++i) {
00250     const TopoDS_Solid& aSolid=TopoDS::Solid(aMSolids(i));
00251     aMFDone.Clear();
00252     aMFIN.Clear();
00253     aMEF.Clear();
00254     //
00255     aBB.MakeSolid(aSolidSp);
00256     //
00257     TopTools_ListOfShape aLIF;
00258     //
00259     BuildDraftSolid(aSolid, aSolidSp, aLIF);
00260     aNbLIF=aLIF.Extent();
00261     //
00262     // 1 all faces/edges from aSolid [ aMS ]
00263     bHasImage=Standard_False;
00264     aMS.Clear();
00265     aIt.Initialize(aSolid);
00266     for (; aIt.More(); aIt.Next()) {
00267       const TopoDS_Shape& aShell=aIt.Value();
00268       //
00269       if (myImages.HasImage(aShell)) {
00270         bHasImage=Standard_True;
00271         //
00272         const TopTools_ListOfShape& aLS=myImages.Image(aShell);
00273         aItS.Initialize(aLS);
00274         for (; aItS.More(); aItS.Next()) {
00275           const TopoDS_Shape& aSx=aItS.Value();
00276           aMS.Add(aSx);
00277           TopExp::MapShapes(aSx, TopAbs_FACE, aMS);
00278           TopExp::MapShapes(aSx, TopAbs_EDGE, aMS);
00279           TopExp::MapShapesAndAncestors(aSx, TopAbs_EDGE, TopAbs_FACE, aMEF);
00280         }
00281       }
00282       else {
00283         //aMS.Add(aShell);
00284         TopExp::MapShapes(aShell, TopAbs_FACE, aMS);
00285         //modified by NIZNHY-PKV Fri Dec 03 11:18:45 2010f
00286         TopExp::MapShapes(aShell, TopAbs_EDGE, aMS);
00287         //modified by NIZNHY-PKV Fri Dec 03 11:18:51 2010t
00288         TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF);
00289       }
00290     }
00291     //
00292     // 2 all faces that are not from aSolid [ aLFP1 ]
00293     Standard_Integer aNbEFP;
00294     TopTools_IndexedDataMapOfShapeListOfShape aMEFP;
00295     TopTools_ListIteratorOfListOfShape aItFP, aItEx;
00296     TopTools_MapOfShape aMFence;
00297     TopTools_ListOfShape aLFP1, aLFP2, aLFP, aLCBF, aLFIN, aLEx;//*pLFP,
00298     //
00299     // for all non-solid faces build EF map [ aMEFP ]
00300     for (j=1; j<=aNbFaces; ++j) {
00301       const TopoDS_Shape& aFace=aMFaces(j);
00302       if (!aMS.Contains(aFace)) {
00303         TopExp::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP);
00304       }
00305     }
00306     //
00307     // among all faces from aMEFP select these that have same edges
00308     // with the solid (i.e aMEF). These faces will be treated first
00309     // to prevent the usage of 3D classifier.
00310     // The full list of faces to process is aLFP1.
00311     aNbEFP=aMEFP.Extent();
00312     for (j=1; j<=aNbEFP; ++j) {
00313       const TopoDS_Shape& aE=aMEFP.FindKey(j);
00314       //
00315       if (aMEF.Contains(aE)) { // !!
00316         const TopTools_ListOfShape& aLF=aMEFP(j);
00317         aItFP.Initialize(aLF);
00318         for (; aItFP.More(); aItFP.Next()) {
00319           const TopoDS_Shape& aF=aItFP.Value();
00320           if (aMFence.Add(aF)) {
00321             aLFP1.Append(aF);
00322           }
00323         }
00324       }
00325       else {
00326         aLEx.Append(aE);
00327       }
00328     }
00329     //
00330     aItEx.Initialize(aLEx);
00331     for (; aItEx.More(); aItEx.Next()) {
00332       const TopoDS_Shape& aE=aItEx.Value();
00333       const TopTools_ListOfShape& aLF=aMEFP.FindFromKey(aE);
00334       aItFP.Initialize(aLF);
00335       for (; aItFP.More(); aItFP.Next()) {
00336         const TopoDS_Shape& aF=aItFP.Value();
00337         if (aMFence.Add(aF)) {
00338           aLFP2.Append(aF);
00339         }
00340       }
00341     }
00342     aLFP1.Append(aLFP2);
00343     //==========
00344     //
00345     // 3 Process faces aLFP1
00346     aNbFP=aLFP1.Extent();
00347     aItFP.Initialize(aLFP1);
00348     for (; aItFP.More(); aItFP.Next()) {
00349       const TopoDS_Shape& aSP=aItFP.Value();
00350       if (!aMFDone.Add(aSP)) {
00351         continue;
00352       }
00353 
00354       //
00355       // first face to process
00356       aFP=TopoDS::Face(aSP);
00357       bIsIN= GEOMAlgo_Tools3D::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, aCtx);
00358       aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT;
00359       //
00360       // collect faces to process [ aFP is the first ]
00361       aLFP.Clear();
00362       aLFP.Append(aFP);
00363       aItS.Initialize(aLFP1);
00364       for (; aItS.More(); aItS.Next()) {
00365         const TopoDS_Shape& aSk=aItS.Value();
00366         if (!aMFDone.Contains(aSk)) {
00367           aLFP.Append(aSk);
00368         }
00369       }
00370       //
00371       // Connexity Block that spreads from aFP the Bound
00372       // or till the end of the block itself
00373       aLCBF.Clear();
00374       GEOMAlgo_Tools3D::MakeConnexityBlock(aLFP, aMS, aLCBF);
00375       //
00376       // fill states for the Connexity Block
00377       aItS.Initialize(aLCBF);
00378       for (; aItS.More(); aItS.Next()) {
00379         const TopoDS_Shape& aSx=aItS.Value();
00380         aMFDone.Add(aSx);
00381         if (aState==TopAbs_IN) {
00382           aMFIN.Add(aSx);
00383         }
00384       }
00385       //
00386       aNbFPx=aMFDone.Extent();
00387       if (aNbFPx==aNbFP) {
00388         break;
00389       }
00390     }//for (; aItFP.More(); aItFP.Next())
00391     //
00392     // faces Inside aSolid
00393     aLFIN.Clear();
00394     aNbFIN=aMFIN.Extent();
00395     if (aNbFIN || aNbLIF) {
00396       for (j=1; j<=aNbFIN; ++j) {
00397         const TopoDS_Shape& aFIN=aMFIN(j);
00398         aLFIN.Append(aFIN);
00399       }
00400       //
00401       aItS.Initialize(aLIF);
00402       for (; aItS.More(); aItS.Next()) {
00403         const TopoDS_Shape& aFIN=aItS.Value();
00404         aLFIN.Append(aFIN);
00405       }
00406       //
00407       myInParts.Add(aSolid, aLFIN);
00408     }
00409     if (aNbFIN || bHasImage) {
00410       myDraftSolids.Add(aSolid, aSolidSp);
00411     }
00412   }//for (i=1; i<=aNbSolids; ++i) { // next solid
00413 }
00414 //=======================================================================
00415 //function : BuildSplitSolids
00416 //purpose  :
00417 //=======================================================================
00418   void GEOMAlgo_Builder::BuildSplitSolids()
00419 {
00420   myErrorStatus=0;
00421   //
00422   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00423   NMTTools_PaveFiller* pPF=myPaveFiller;
00424   const Handle(IntTools_Context)& aCtx= pPF->Context();
00425   //
00426   Standard_Integer i, aNbS, iErr;
00427   TopExp_Explorer aExp;
00428   TopTools_ListOfShape aSFS, aLSEmpty;
00429   TopTools_MapOfShape aMFence;
00430   TopTools_ListIteratorOfListOfShape aIt;
00431   GEOMAlgo_BuilderSolid aSB;
00432   GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet aItSS;
00433   GEOMAlgo_DataMapOfShapeShapeSet aMSS;
00434   GEOMAlgo_ShapeSet aSSi;
00435   //
00436   // 0. Find same domain solids for non-interferred solids
00437   aNbS=aDS.NumberOfShapesOfTheObject();
00438   for (i=1; i<=aNbS; ++i) {
00439     const TopoDS_Shape& aS=aDS.Shape(i);
00440     if (aS.ShapeType()!=TopAbs_SOLID) {
00441       continue;
00442     }
00443     if (!aMFence.Add(aS)) {
00444       continue;
00445     }
00446     if(myDraftSolids.Contains(aS)) {
00447       continue;
00448     }
00449     //
00450     aSSi.Clear();
00451     aSSi.Add(aS, TopAbs_FACE);
00452     //
00453     aMSS.Bind(aS, aSSi);
00454   } //for (i=1; i<=aNbS; ++i)
00455   //
00456   // 1. Build solids for interferred source solids
00457   aSB.SetContext(aCtx);
00458   aSB.ComputeInternalShapes(myComputeInternalShapes);
00459   aNbS=myDraftSolids.Extent();
00460   for (i=1; i<=aNbS; ++i) {
00461     const TopoDS_Shape& aS =myDraftSolids.FindKey(i);
00462     const TopoDS_Shape& aSD=myDraftSolids.FindFromIndex(i);
00463     const TopTools_ListOfShape& aLFIN=
00464       (myInParts.Contains(aS)) ? myInParts.FindFromKey(aS) : aLSEmpty;
00465     //
00466     // 1.1 Fill Shell Faces Set
00467     aSFS.Clear();
00468 
00469     aExp.Init(aSD, TopAbs_FACE);
00470     for (; aExp.More(); aExp.Next()) {
00471       const TopoDS_Shape& aF=aExp.Current();
00472       aSFS.Append(aF);
00473     }
00474     //
00475     aIt.Initialize(aLFIN);
00476     for (; aIt.More(); aIt.Next()) {
00477       TopoDS_Shape aF=aIt.Value();
00478       //
00479       aF.Orientation(TopAbs_FORWARD);
00480       aSFS.Append(aF);
00481       aF.Orientation(TopAbs_REVERSED);
00482       aSFS.Append(aF);
00483     }
00484     //
00485     Standard_Integer aNbSFS;
00486     aNbSFS=aSFS.Extent();
00487     //
00488     // 1.2
00489     // Check whether aSFS contains a subsets of faces
00490     // of solids that have been already built.
00491     // If yes, shrink aSFS by these subsets.
00492     aSSi.Clear();
00493     aSSi.Add(aSFS);
00494     //
00495     aItSS.Initialize(aMSS);
00496     for (; aItSS.More(); aItSS.Next()) {
00497       const TopoDS_Shape& aSR=aItSS.Key();
00498       const GEOMAlgo_ShapeSet& aSSR=aItSS.Value();
00499       if (aSSi.Contains(aSSR)) {
00500         // the aSR is SD solid for aS
00501         aSSi.Subtract(aSSR);
00502         // update images
00503         if(myImages.HasImage(aS)) {
00504           myImages.Add(aS, aSR);
00505         }
00506         else {
00507           myImages.Bind(aS, aSR);
00508         }
00509         //
00510         // update SD Shapes
00511         mySameDomainShapes.Add(aSR, aSR);
00512       }
00513     }
00514     const TopTools_ListOfShape& aSFS1=aSSi.GetSet();
00515     aNbSFS=aSFS1.Extent();
00516     //modified by NIZNHY-PKV Wed Oct 27 09:53:15 2010f
00517     if (!aNbSFS) {
00518       continue;
00519     }
00520     //modified by NIZNHY-PKV Wed Oct 27 09:53:18 2010t
00521     //
00522     // 1.3 Build new solids
00523     aSB.SetContext(aCtx);
00524     aSB.SetShapes(aSFS1);
00525     aSB.Perform();
00526     iErr=aSB.ErrorStatus();
00527     if (iErr) {
00528       myErrorStatus=30; // SolidBuilder failed
00529       return;
00530     }
00531     //
00532     const TopTools_ListOfShape& aLSR=aSB.Areas();
00533     //
00534       // 1.4 Collect resulting solids and theirs set of faces
00535     aIt.Initialize(aLSR);
00536     for (; aIt.More(); aIt.Next()) {
00537       const TopoDS_Shape& aSR=aIt.Value();
00538       //
00539       aSSi.Clear();
00540       aExp.Init(aSR, TopAbs_FACE);
00541       for (; aExp.More(); aExp.Next()) {
00542         const TopoDS_Shape& aF=aExp.Current();
00543         aSSi.Add(aF);
00544       }
00545       aMSS.Bind(aSR, aSSi);
00546     }
00547     //
00548     // Update images
00549     if (myImages.HasImage(aS)) {
00550       myImages.Add(aS, aLSR);
00551     }
00552     else {
00553       myImages.Bind(aS, aLSR);
00554     }
00555   } // for (i=1; i<=aNbS; ++i) {
00556 }
00557 //=======================================================================
00558 //function :FillInternalShapes
00559 //purpose  :
00560 //=======================================================================
00561   void GEOMAlgo_Builder::FillInternalShapes()
00562 {
00563   myErrorStatus=0;
00564   //
00565   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00566   NMTTools_PaveFiller* pPF=myPaveFiller;
00567   const Handle(IntTools_Context)& aCtx= pPF->Context();
00568   //
00569   //Standard_Boolean bHasImage;
00570   Standard_Integer i, j, jT, aNbS, aNbSI, aNbSx, aNbSd;
00571   TopAbs_ShapeEnum aType, aT[]={ TopAbs_VERTEX, TopAbs_EDGE };
00572   TopAbs_State aState;
00573   TopTools_ListIteratorOfListOfShape aIt, aIt1;
00574   TopTools_IndexedDataMapOfShapeListOfShape aMSx;
00575   TopTools_IndexedMapOfShape aMx;
00576   TopTools_MapOfShape aMSI, aMFence, aMSOr;
00577   TopTools_MapIteratorOfMapOfShape aItM;
00578   TopTools_ListOfShape aLSI, aLSd;
00579   TopoDS_Iterator aItS;
00580   BRep_Builder aBB;
00581   //
00582   // 1. Shapes to process
00583   //
00584   // 1.1 Shapes from pure arguments aMSI
00585   // 1.1.1 vertex, edge
00586   for (i=0; i<2; ++i) {
00587     jT=(Standard_Integer)aT[i];
00588     const TopTools_ListOfShape &aLS=myShapes1[jT];
00589     aIt.Initialize(aLS);
00590     for (; aIt.More(); aIt.Next()) {
00591       const TopoDS_Shape& aS=aIt.Value();
00592       if (aMFence.Add(aS)) {
00593         aLSI.Append(aS);
00594       }
00595     }
00596   }
00597   // 1.1.2 wire
00598   {
00599     jT=(Standard_Integer)TopAbs_WIRE;
00600     const TopTools_ListOfShape &aLW=myShapes1[jT];
00601     aIt.Initialize(aLW);
00602     for (; aIt.More(); aIt.Next()) {
00603       const TopoDS_Shape& aW=aIt.Value();
00604       aItS.Initialize(aW);
00605       for (; aItS.More(); aItS.Next()) {
00606         const TopoDS_Shape& aE=aItS.Value();
00607         if (aMFence.Add(aE)) {
00608           aLSI.Append(aE);
00609         }
00610       }
00611     }
00612   }
00613   // 1.1.3 theirs images/sources
00614   aIt1.Initialize(aLSI);
00615   for (; aIt1.More(); aIt1.Next()) {
00616     const TopoDS_Shape& aS=aIt1.Value();
00617     if (myImages.HasImage(aS)) {
00618       const TopTools_ListOfShape &aLSp=myImages.Image(aS);
00619       aIt.Initialize(aLSp);
00620       for (; aIt.More(); aIt.Next()) {
00621         const TopoDS_Shape& aSI=aIt.Value();
00622         aMSI.Add(aSI);
00623       }
00624     }
00625     else {
00626       aMSI.Add(aS);
00627     }
00628   }
00629   aLSI.Clear();
00630   aNbSI=aMSI.Extent();
00631   //
00632   // 2. Internal vertices, edges from source solids
00633   aMFence.Clear();
00634   aLSd.Clear();
00635   //
00636   aNbS=aDS.NumberOfShapesOfTheObject();
00637   for (i=1; i<=aNbS; ++i) {
00638     const TopoDS_Shape& aS=aDS.Shape(i);
00639     aType=aS.ShapeType();
00640     if (aType==TopAbs_SOLID) {
00641       //
00642       aMx.Clear();
00643       OwnInternalShapes(aS, aMx);
00644       //
00645       aNbSx=aMx.Extent();
00646       for (j=1; j<=aNbSx; ++j) {
00647         const TopoDS_Shape& aSI=aMx(j);
00648         if (myImages.HasImage(aSI)) {
00649           const TopTools_ListOfShape &aLSp=myImages.Image(aSI);
00650           aIt.Initialize(aLSp);
00651           for (; aIt.More(); aIt.Next()) {
00652             const TopoDS_Shape& aSp=aIt.Value();
00653             aMSI.Add(aSp);
00654           }
00655         }
00656         else {
00657           aMSI.Add(aSI);
00658         }
00659       }
00660       //
00661       // build aux map from splits of solids
00662       if (myImages.HasImage(aS)) {
00663         const TopTools_ListOfShape &aLSp=myImages.Image(aS);
00664         aIt.Initialize(aLSp);
00665         for (; aIt.More(); aIt.Next()) {
00666           const TopoDS_Shape& aSp=aIt.Value();
00667           if (aMFence.Add(aSp)) {
00668             TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
00669             TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx);
00670             TopExp::MapShapesAndAncestors(aSp, TopAbs_EDGE  , TopAbs_FACE, aMSx);
00671             aLSd.Append(aSp);
00672           }
00673         }
00674       }
00675       else {
00676         if (aMFence.Add(aS)) {
00677           TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
00678           TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx);
00679           TopExp::MapShapesAndAncestors(aS, TopAbs_EDGE  , TopAbs_FACE, aMSx);
00680           aLSd.Append(aS);
00681           aMSOr.Add(aS);
00682         }
00683       }
00684     }//if (aType==TopAbs_SOLID)
00685   }
00686   //
00687   aNbSd=aLSd.Extent();
00688   //
00689   // 3. Some shapes of aMSI can be already tied with faces of
00690   //    split solids
00691   aItM.Initialize(aMSI);
00692   for (; aItM.More(); aItM.Next()) {
00693     const TopoDS_Shape& aSI=aItM.Key();
00694     if (aMSx.Contains(aSI)) {
00695       const TopTools_ListOfShape &aLSx=aMSx.FindFromKey(aSI);
00696       aNbSx=aLSx.Extent();
00697       if (aNbSx) {
00698         aMSI.Remove(aSI);
00699       }
00700     }
00701   }
00702   //
00703   // 4. Just check it
00704   aNbSI=aMSI.Extent();
00705   if (!aNbSI) {
00706     return;
00707   }
00708   //
00709   // 5 Settle internal vertices and edges into solids
00710   aMx.Clear();
00711   aIt.Initialize(aLSd);
00712   for (; aIt.More(); aIt.Next()) {
00713     TopoDS_Solid aSd=TopoDS::Solid(aIt.Value());
00714     //
00715     aItM.Initialize(aMSI);
00716     for (; aItM.More(); aItM.Next()) {
00717       TopoDS_Shape aSI=aItM.Key();
00718       aSI.Orientation(TopAbs_INTERNAL);
00719       //
00720       aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
00721       if (aState==TopAbs_IN) {
00722         //
00723         if(aMSOr.Contains(aSd)) {
00724           //
00725           TopoDS_Solid aSdx;
00726           //
00727           aBB.MakeSolid(aSdx);
00728           aItS.Initialize(aSd);
00729           for (; aItS.More(); aItS.Next()) {
00730             const TopoDS_Shape& aSh=aItS.Value();
00731             aBB.Add(aSdx, aSh);
00732           }
00733           //
00734           aBB.Add(aSdx, aSI);
00735           //
00736           myImages.Bind(aSd, aSdx);
00737           aMSOr.Remove(aSd);
00738           aSd=aSdx;
00739         }
00740         else {
00741           aBB.Add(aSd, aSI);
00742         }
00743         //
00744         aMSI.Remove(aSI);
00745       } //if (aState==TopAbs_IN) {
00746     }// for (; aItM.More(); aItM.Next()) {
00747   }//for (; aIt1.More(); aIt1.Next()) {
00748 }
00749 //=======================================================================
00750 //function : OwnInternalShapes
00751 //purpose  :
00752 //=======================================================================
00753   void OwnInternalShapes(const TopoDS_Shape& theS,
00754                          TopTools_IndexedMapOfShape& theMx)
00755 {
00756   TopoDS_Iterator aIt;
00757   //
00758   aIt.Initialize(theS);
00759   for (; aIt.More(); aIt.Next()) {
00760     const TopoDS_Shape& aSx=aIt.Value();
00761     if (aSx.ShapeType()!=TopAbs_SHELL) {
00762       theMx.Add(aSx);
00763     }
00764   }
00765 }
00766 //
00767 // ErrorStatus
00768 // 30 - SolidBuilder failed