Back to index

salome-geom  6.5.0
GEOMAlgo_Builder_1.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 
00023 // File:        GEOMAlgo_Builder_1.cxx
00024 // Created:
00025 // Author:      Peter KURNEV
00026 //
00027 #include <GEOMAlgo_Builder.hxx>
00028 //
00029 #include <TColStd_ListOfInteger.hxx>
00030 
00031 #include <TopoDS.hxx>
00032 #include <TopoDS_Shape.hxx>
00033 #include <TopoDS_Wire.hxx>
00034 #include <TopoDS_Edge.hxx>
00035 #include <TopoDS_Shell.hxx>
00036 #include <TopoDS_Iterator.hxx>
00037 //
00038 #include <TopTools_MapOfShape.hxx>
00039 #include <TopTools_ListOfShape.hxx>
00040 #include <TopTools_ListIteratorOfListOfShape.hxx>
00041 #include <TopTools_MapIteratorOfMapOfShape.hxx>
00042 //
00043 #include <BRep_Tool.hxx>
00044 #include <BRep_Builder.hxx>
00045 //
00046 #include <IntTools_Context.hxx>
00047 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
00048 #include <BOPTools_ListOfPaveBlock.hxx>
00049 #include <BOPTools_PaveBlock.hxx>
00050 //
00051 #include <NMTDS_ShapesDataStructure.hxx>
00052 //
00053 #include <NMTTools_PaveFiller.hxx>
00054 #include <NMTTools_CommonBlockPool.hxx>
00055 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
00056 #include <NMTTools_CommonBlock.hxx>
00057 #include <NMTTools_CommonBlockPool.hxx>
00058 #include <NMTTools_ListOfCommonBlock.hxx>
00059 #include <NMTTools_CommonBlockAPI.hxx>
00060 //
00061 #include <GEOMAlgo_Tools3D.hxx>
00062 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00063 
00064 
00065 
00066 static
00067   void FillImagesCompounds(const TopTools_MapOfShape& ,
00068                            BRepAlgo_Image& );
00069 
00070 static
00071   void FillImagesCompound(const TopoDS_Shape& ,
00072                         BRepAlgo_Image& ,
00073                         TopTools_MapOfShape& );
00074 
00075 //=======================================================================
00076 //function : FillImagesVertices
00077 //purpose  :
00078 //=======================================================================
00079   void GEOMAlgo_Builder::FillImagesVertices()
00080 {
00081   myErrorStatus=0;
00082   //
00083   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00084   NMTTools_PaveFiller* pPF=myPaveFiller;
00085   //
00086   Standard_Integer i, aNb, iV;
00087   //
00088   aNb=aDS.NumberOfShapesOfTheObject();
00089   for (i=1; i<=aNb; ++i) {
00090     const TopoDS_Shape& aV=aDS.Shape(i);
00091     if (aV.ShapeType()==TopAbs_VERTEX) {
00092       iV=pPF->FindSDVertex(i);
00093       if (iV) {
00094         const TopoDS_Shape& aVSD=aDS.Shape(iV);
00095         if (!myImages.HasImage(aV)) {
00096           myImages.Bind(aV, aVSD);
00097           //
00098           mySameDomainShapes.Add(aV, aVSD);
00099         }
00100       }
00101     }
00102   }
00103 }
00104 //=======================================================================
00105 // function: FillImagesEdges
00106 // purpose:
00107 //=======================================================================
00108   void GEOMAlgo_Builder::FillImagesEdges()
00109 {
00110   myErrorStatus=0;
00111   //
00112   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00113   NMTTools_PaveFiller* pPF=myPaveFiller;
00114   const BOPTools_SplitShapesPool& aSSP=pPF->SplitShapesPool();
00115   const Handle(IntTools_Context)& aCtx=pPF->Context();
00116   //
00117   Standard_Boolean bToReverse;
00118   Standard_Integer i, aNb, aNbSp, nSp, nSpR, nSpx, aIsCB, aNbLB;
00119   TColStd_ListIteratorOfListOfInteger aItLB;
00120   TColStd_ListOfInteger aLB;
00121   TopoDS_Edge aEE, aESpR;
00122   TopTools_MapOfShape aMFence;
00123   TopTools_ListOfShape aLSp;
00124   TopTools_ListIteratorOfListOfShape aIt1;
00125   BOPTools_ListIteratorOfListOfPaveBlock aIt;
00126   //
00127   aNb=aDS.NumberOfShapesOfTheObject();
00128   for (i=1; i<=aNb; ++i) {
00129     const TopoDS_Shape& aE=aDS.Shape(i);
00130     if (aE.ShapeType()!=TopAbs_EDGE) {
00131       continue;
00132     }
00133     //
00134     if (!aMFence.Add(aE)) {
00135       continue;
00136     }
00137     //
00138     const BOPTools_ListOfPaveBlock& aLPB=aSSP(aDS.RefEdge(i));
00139     aNbSp=aLPB.Extent();
00140     if (!aNbSp) {
00141       continue;
00142     }
00143     //
00144     aEE=TopoDS::Edge(aE);
00145     aLSp.Clear();
00146     //
00147     if (aNbSp==1) {
00148       const BOPTools_PaveBlock& aPB=aLPB.First();
00149       nSp=aPB.Edge();
00150       const TopoDS_Shape& aSp=aDS.Shape(nSp);
00151       //
00152       const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
00153       //modified by NIZNHY-PKV Wed Oct 27 11:19:30 2010f
00154       aNbLB=aLB.Extent();
00155       if (aIsCB && aNbLB<2) {
00156        aIsCB=0;
00157       }
00158       //modified by NIZNHY-PKV Wed Oct 27 11:19:34 2010t
00159       //
00160       nSpR=aPBR.Edge();
00161       const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
00162       if (aSpR.IsSame(aSp) && aSpR.IsSame(aE) && !aIsCB) {
00163         continue;
00164       }
00165       //
00166       aESpR=TopoDS::Edge(aSpR);
00167       bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
00168       if (bToReverse) {
00169         aESpR.Reverse();
00170       }
00171       aLSp.Append(aESpR);
00172       //
00173       aItLB.Initialize(aLB);
00174       for (; aItLB.More(); aItLB.Next()) {
00175         nSpx=aItLB.Value();
00176         const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
00177         mySameDomainShapes.Add(aSpx ,aSpR);
00178       }
00179       //
00180       //
00181     }// if (aNbSp==1) {
00182     else {
00183       aIt.Initialize(aLPB);
00184       for (; aIt.More(); aIt.Next()) {
00185         const BOPTools_PaveBlock& aPB=aIt.Value();
00186         const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB, aLB, aIsCB);
00187         nSpR=aPBR.Edge();
00188         const TopoDS_Shape& aSpR=aDS.Shape(nSpR);
00189         //
00190         aESpR=TopoDS::Edge(aSpR);
00191         bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aESpR, aEE, aCtx);
00192         if (bToReverse) {
00193           aESpR.Reverse();
00194         }
00195         aLSp.Append(aESpR);
00196         //
00197         aItLB.Initialize(aLB);
00198         for (; aItLB.More(); aItLB.Next()) {
00199           nSpx=aItLB.Value();
00200           const TopoDS_Shape& aSpx=aDS.Shape(nSpx);
00201           mySameDomainShapes.Add(aSpx ,aSpR);
00202         }
00203       }
00204     }
00205     //
00206     myImages.Bind(aE, aLSp);
00207 
00208   }//for (i=1; i<=aNb; ++i)
00209 }
00210 //=======================================================================
00211 // function: FillImagesContainers
00212 // purpose:
00213 //=======================================================================
00214   void GEOMAlgo_Builder::FillImagesContainers(const TopAbs_ShapeEnum theType)
00215 {
00216   myErrorStatus=0;
00217   //
00218   Standard_Boolean bInterferred, bToReverse;
00219   Standard_Integer i, aNbS;
00220   TopAbs_ShapeEnum aType;
00221   BRep_Builder aBB;
00222   TopoDS_Iterator aIt;
00223   TopTools_ListIteratorOfListOfShape aItIm;
00224   TopTools_MapOfShape aMS;
00225   TopTools_MapIteratorOfMapOfShape aItS;
00226   //
00227   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
00228   NMTTools_PaveFiller* pPF=myPaveFiller;
00229   const Handle(IntTools_Context)& aCtx= pPF->Context();
00230   //
00231   aNbS=aDS.NumberOfShapesOfTheObject();
00232   for (i=1; i<=aNbS; ++i) {
00233     const TopoDS_Shape& aC=aDS.Shape(i);
00234     aType=aC.ShapeType();
00235     if (aType==theType) {
00236       aMS.Add(aC);
00237     }
00238   }
00239   //
00240   if (theType==TopAbs_COMPOUND) {
00241     FillImagesCompounds(aMS, myImages);
00242     return;
00243   }
00244   //
00245   aItS.Initialize(aMS);
00246   for (; aItS.More(); aItS.Next()) {
00247     const TopoDS_Shape& aC=aItS.Key();
00248     // whether the shape has image
00249     bInterferred=Standard_False;
00250     aIt.Initialize(aC);
00251     for (; aIt.More(); aIt.Next()) {
00252       const TopoDS_Shape& aF=aIt.Value();
00253       if (myImages.HasImage(aF)) {
00254         bInterferred=!bInterferred;
00255         break;
00256       }
00257     }
00258     if (!bInterferred){
00259       continue;
00260     }
00261     //
00262     TopoDS_Shape aCIm;
00263     GEOMAlgo_Tools3D::MakeContainer(theType, aCIm);
00264     //
00265     aIt.Initialize(aC);
00266     for (; aIt.More(); aIt.Next()) {
00267       const TopoDS_Shape& aF=aIt.Value();
00268       if (myImages.HasImage(aF)) {
00269         const TopTools_ListOfShape& aLFIm=myImages.Image(aF);
00270         aItIm.Initialize(aLFIm);
00271         for (; aItIm.More(); aItIm.Next()) {
00272           TopoDS_Shape aFIm=aItIm.Value();
00273           //
00274           bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFIm, aF, aCtx);
00275           if (bToReverse) {
00276             aFIm.Reverse();
00277           }
00278           aBB.Add(aCIm, aFIm);
00279         }
00280       }
00281       else {
00282         aBB.Add(aCIm, aF);
00283       }
00284     }
00285     myImages.Bind(aC, aCIm);
00286   }// for (; aItS.More(); aItS.Next()) {
00287 }
00288 //=======================================================================
00289 // function: FillImagesCompounds
00290 // purpose:
00291 //=======================================================================
00292 void FillImagesCompounds(const TopTools_MapOfShape& theMS,
00293                          BRepAlgo_Image& theImages)
00294 {
00295   TopTools_MapOfShape aMFP;
00296   TopTools_MapIteratorOfMapOfShape aItS;
00297   //
00298   aItS.Initialize(theMS);
00299   for (; aItS.More(); aItS.Next()) {
00300     const TopoDS_Shape& aC=aItS.Key();
00301     FillImagesCompound(aC, theImages, aMFP);
00302   }
00303 }
00304 //=======================================================================
00305 //function : FillImagesCompound
00306 //purpose  :
00307 //=======================================================================
00308 void FillImagesCompound(const TopoDS_Shape& theS,
00309                         BRepAlgo_Image& theImages,
00310                         TopTools_MapOfShape& theMFP)
00311 {
00312   Standard_Boolean bInterferred;
00313   TopAbs_ShapeEnum aTypeX;
00314   TopAbs_Orientation aOrX;
00315   TopoDS_Iterator aIt;
00316   BRep_Builder aBB;
00317   TopTools_ListIteratorOfListOfShape aItIm;
00318   //
00319   if (!theMFP.Add(theS)) {
00320     return;
00321   }
00322   //
00323   bInterferred=Standard_False;
00324   aIt.Initialize(theS);
00325   for (; aIt.More(); aIt.Next()) {
00326     const TopoDS_Shape& aSX=aIt.Value();
00327     aTypeX=aSX.ShapeType();
00328     if (aTypeX==TopAbs_COMPOUND) {
00329       FillImagesCompound(aSX, theImages, theMFP);
00330     }
00331     if (theImages.HasImage(aSX)) {
00332       bInterferred=Standard_True;
00333     }
00334   }
00335   if (!bInterferred){
00336     return;
00337   }
00338   //
00339   TopoDS_Shape aCIm;
00340   GEOMAlgo_Tools3D::MakeContainer(TopAbs_COMPOUND, aCIm);
00341   //
00342   aIt.Initialize(theS);
00343   for (; aIt.More(); aIt.Next()) {
00344     const TopoDS_Shape& aSX=aIt.Value();
00345     aOrX=aSX.Orientation();
00346     if (theImages.HasImage(aSX)) {
00347       const TopTools_ListOfShape& aLFIm=theImages.Image(aSX);
00348       aItIm.Initialize(aLFIm);
00349       for (; aItIm.More(); aItIm.Next()) {
00350         TopoDS_Shape aSXIm=aItIm.Value();
00351         aSXIm.Orientation(aOrX);
00352         aBB.Add(aCIm, aSXIm);
00353       }
00354     }
00355     else {
00356       aBB.Add(aCIm, aSX);
00357     }
00358   }
00359   theImages.Bind(theS, aCIm);
00360 }