Back to index

salome-geom  6.5.0
GEOMAlgo_Builder_4.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_4.cxx
00024 // Created:
00025 // Author:      Peter KURNEV
00026 //
00027 #include <GEOMAlgo_Builder.hxx>
00028 
00029 #include <TopoDS_Iterator.hxx>
00030 
00031 #include <TopTools_ListOfShape.hxx>
00032 #include <TopTools_ListIteratorOfListOfShape.hxx>
00033 #include <TopTools_MapOfShape.hxx>
00034 #include <TopTools_MapIteratorOfMapOfShape.hxx>
00035 
00036 #include <IntTools_Context.hxx>
00037 
00038 #include <NMTDS_ShapesDataStructure.hxx>
00039 
00040 #include <NMTTools_PaveFiller.hxx>
00041 
00042 #include <GEOMAlgo_Tools3D.hxx>
00043 
00044 static
00045   void MapShapes(const TopoDS_Shape& aS,
00046                  TopTools_MapOfShape& aM);
00047 
00048 //=======================================================================
00049 //function : Generated
00050 //purpose  :
00051 //=======================================================================
00052   const TopTools_ListOfShape& GEOMAlgo_Builder::Generated(const TopoDS_Shape& theS)
00053 {
00054   NMTTools_PaveFiller* pPF=myPaveFiller;
00055   const Handle(IntTools_Context)& aCtx=pPF->Context();
00056   //
00057   Standard_Boolean bHasImage, bToReverse;
00058   TopAbs_ShapeEnum aType;
00059   TopTools_ListIteratorOfListOfShape aIt;
00060   //
00061   myHistShapes.Clear();
00062   //
00063   if (theS.IsNull()) {
00064     return myHistShapes;
00065   }
00066   //
00067   bHasImage=myImages.HasImage(theS);
00068   if (!bHasImage) {
00069     return myHistShapes;
00070   }
00071   //
00072   aType=theS.ShapeType();
00073   //
00074   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
00075       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
00076     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
00077     aIt.Initialize(aLSp);
00078     for (; aIt.More(); aIt.Next()) {
00079       const TopoDS_Shape& aSp=aIt.Value();
00080       if (mySameDomainShapes.Contains(aSp)) {
00081         if (myMapShape.Contains(aSp)) {
00082           TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
00083           //
00084           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
00085             aSpR.Orientation(theS.Orientation());
00086           }
00087           else {
00088             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSpR, theS, aCtx);
00089             if (bToReverse) {
00090               aSpR.Reverse();
00091             }
00092           }
00093           //
00094           myHistShapes.Append(aSpR);
00095         }
00096       }
00097     }
00098   }
00099   //
00100   return myHistShapes;
00101 }
00102 //=======================================================================
00103 //function : Modified
00104 //purpose  :
00105 //=======================================================================
00106   const TopTools_ListOfShape& GEOMAlgo_Builder::Modified(const TopoDS_Shape& theS)
00107 {
00108   NMTTools_PaveFiller* pPF=myPaveFiller;
00109   const Handle(IntTools_Context)& aCtx=pPF->Context();
00110   //
00111   Standard_Boolean bHasImage, bToReverse;
00112   TopAbs_ShapeEnum aType;
00113   TopTools_ListIteratorOfListOfShape aIt;
00114   //
00115   myHistShapes.Clear();
00116   //
00117   if (theS.IsNull()) {
00118     return myHistShapes;
00119   }
00120   //
00121   bHasImage=myImages.HasImage(theS);
00122   if (!bHasImage) {
00123     return myHistShapes;
00124   }
00125   //
00126   aType=theS.ShapeType();
00127   //
00128   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
00129       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
00130     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
00131     aIt.Initialize(aLSp);
00132     for (; aIt.More(); aIt.Next()) {
00133       TopoDS_Shape aSp=aIt.Value();
00134       if (!mySameDomainShapes.Contains(aSp)) {
00135         if (myMapShape.Contains(aSp)) {
00136           //
00137           if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
00138             aSp.Orientation(theS.Orientation());
00139           }
00140           else {
00141             bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSp, theS, aCtx);
00142             if (bToReverse) {
00143               aSp.Reverse();
00144             }
00145           }
00146           //
00147           myHistShapes.Append(aSp);
00148         }
00149       }
00150     }
00151   }
00152   //
00153   return myHistShapes;
00154 }
00155 //=======================================================================
00156 //function : IsDeleted
00157 //purpose  :
00158 //=======================================================================
00159   Standard_Boolean GEOMAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
00160 {
00161   Standard_Boolean bRet, bHasImage, bContains;
00162   TopAbs_ShapeEnum aType;
00163   TopTools_ListIteratorOfListOfShape aIt;
00164   //
00165   bRet=Standard_False;
00166   //
00167   if (theS.IsNull()) {
00168     return !bRet; //true
00169   }
00170   //
00171   bContains=myMapShape.Contains(theS);
00172   if (bContains) {
00173     return bRet; //false
00174   }
00175   //
00176   bHasImage=myImages.HasImage(theS);
00177   if (!bHasImage) {
00178     return !bRet; //true
00179   }
00180   //
00181   aType=theS.ShapeType();
00182   if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
00183       aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
00184     const TopTools_ListOfShape& aLSp=myImages.Image(theS);
00185     aIt.Initialize(aLSp);
00186     for (; aIt.More(); aIt.Next()) {
00187       TopoDS_Shape aSp=aIt.Value();
00188       //
00189       if (!mySameDomainShapes.Contains(aSp)) {
00190         if (myMapShape.Contains(aSp)) {
00191           return bRet; //false
00192         }
00193       }
00194       else {
00195         TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
00196         if (myMapShape.Contains(aSpR)) {
00197           return bRet; //false
00198         }
00199       }
00200     }
00201   }
00202   return !bRet; // true
00203 }
00204 //=======================================================================
00205 //function : PrepareHistory
00206 //purpose  :
00207 //=======================================================================
00208   void GEOMAlgo_Builder::PrepareHistory()
00209 {
00210   if(myShape.IsNull()) {
00211     return;
00212   }
00213   //
00214   Standard_Boolean bHasImage, bContainsSD;
00215   TopAbs_ShapeEnum aType;
00216   TopTools_MapOfShape aMS;
00217   TopTools_ListIteratorOfListOfShape aIt;
00218   TopTools_MapIteratorOfMapOfShape aItM;
00219   //
00220   // 1. Clearing
00221   GEOMAlgo_BuilderShape::PrepareHistory();
00222   //
00223   // 2. myMapShape - all shapes of result with theirs sub-shapes
00224   MapShapes(myShape, myMapShape);
00225   //
00226   // 3. MS - all argument shapes with theirs sub-shapes
00227   aIt.Initialize(myShapes);
00228   for (; aIt.More(); aIt.Next()) {
00229     const TopoDS_Shape& aSx=aIt.Value();
00230     MapShapes(aSx, aMS);
00231   }
00232   //
00233   // 4. Treatment
00234   aItM.Initialize(aMS);
00235   for (; aItM.More(); aItM.Next()) {
00236     const TopoDS_Shape& aSx=aItM.Key();
00237     aType=aSx.ShapeType();
00238     //modified by NIZNHY-PKV Thu Dec  7 11:34:05 2006f
00239     //
00240     // 4.1 .myImagesResult
00241     TopTools_ListOfShape aLSx;
00242     //
00243     bHasImage=myImages.HasImage(aSx);
00244     if (!bHasImage) {
00245       if (myMapShape.Contains(aSx)) {
00246         aLSx.Append(aSx);
00247         myImagesResult.Add(aSx, aLSx);
00248       }
00249     }
00250     else {
00251       const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
00252       aIt.Initialize(aLSp);
00253       for (; aIt.More(); aIt.Next()) {
00254         const TopoDS_Shape& aSp=aIt.Value();
00255         if (myMapShape.Contains(aSp)) {
00256           aLSx.Append(aSp);
00257         }
00258       }
00259       myImagesResult.Add(aSx, aLSx);
00260     }
00261     //
00262     //modified by NIZNHY-PKV Thu Dec  7 11:34:10 2006t
00263     //
00264     // 4.2 As it was
00265     if (!myHasDeleted) {
00266       myHasDeleted=IsDeleted(aSx);//xx
00267     }
00268     //
00269     if (!myHasGenerated || !myHasModified) {
00270       if (aType==TopAbs_EDGE   || aType==TopAbs_FACE ||
00271           aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
00272         //modified by NIZNHY-PKV Thu Dec  7 11:53:01 2006f
00273         //bHasImage=myImages.HasImage(aSx);
00274         //modified by NIZNHY-PKV Thu Dec  7 11:53:04 2006t
00275         if (bHasImage) {
00276           const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
00277           aIt.Initialize(aLSp);
00278           for (; aIt.More(); aIt.Next()) {
00279             const TopoDS_Shape& aSp=aIt.Value();
00280             //
00281             if (myMapShape.Contains(aSp)) {
00282               bContainsSD=mySameDomainShapes.Contains(aSp);
00283               //
00284               if (!myHasGenerated) {
00285                 if (bContainsSD) {
00286                   myHasGenerated=Standard_True;
00287                 }
00288               }
00289               if (!myHasModified) {
00290                 if (!bContainsSD) {
00291                   myHasModified=Standard_True;
00292                 }
00293               }
00294             } // if (myMapShape.Contains(aSp))
00295           }
00296         }
00297       }
00298     }
00299   }
00300 
00301 }
00302 //=======================================================================
00303 //function : MapShapes
00304 //purpose  :
00305 //=======================================================================
00306   void MapShapes(const TopoDS_Shape& theS,
00307                  TopTools_MapOfShape& theM)
00308 {
00309   theM.Add(theS);
00310   TopoDS_Iterator anIt;
00311   anIt.Initialize(theS);
00312   for (; anIt.More(); anIt.Next()) {
00313     const TopoDS_Shape& aSx=anIt.Value();
00314     MapShapes(aSx, theM);
00315   }
00316 }