Back to index

salome-geom  6.5.0
GEOMAlgo_Gluer2_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_Gluer2_1.cxx
00024 // Author:   Peter KURNEV
00025 
00026 #include <GEOMAlgo_Gluer2.hxx>
00027 
00028 #include <gp_XYZ.hxx>
00029 #include <gp_Pnt.hxx>
00030 
00031 #include <TopLoc_Location.hxx>
00032 
00033 #include <Geom_Surface.hxx>
00034 
00035 #include <TopAbs_ShapeEnum.hxx>
00036 
00037 #include <TopoDS_Shape.hxx>
00038 #include <TopoDS_Vertex.hxx>
00039 #include <TopoDS_Edge.hxx>
00040 #include <TopoDS_Wire.hxx>
00041 #include <TopoDS_Face.hxx>
00042 #include <TopoDS_Iterator.hxx>
00043 
00044 #include <BRep_Tool.hxx>
00045 #include <BRep_Builder.hxx>
00046 
00047 #include <BRepTools.hxx>
00048 #include <TopExp.hxx>
00049 
00050 #include <TopTools_MapOfShape.hxx>
00051 #include <TopTools_ListIteratorOfListOfShape.hxx>
00052 #include <TopTools_ListOfShape.hxx>
00053 
00054 #include <BOPTools_Tools.hxx>
00055 #include <BOPTools_Tools2D.hxx>
00056 #include <BOPTools_Tools3D.hxx>
00057 
00058 #include <GEOMAlgo_Tools.hxx>
00059 
00060 //=======================================================================
00061 //function : MakeBRepShapes
00062 //purpose  :
00063 //=======================================================================
00064 void GEOMAlgo_Gluer2::MakeBRepShapes(const TopoDS_Shape& theS,
00065                                      TopoDS_Shape& theSnew)
00066 {
00067   TopAbs_ShapeEnum aType;
00068   //
00069   aType=theS.ShapeType();
00070   if (aType==TopAbs_EDGE) {
00071     TopoDS_Edge aEE, aEEnew;
00072     //
00073     aEE=*((TopoDS_Edge*)&theS);
00074     MakeEdge(aEE, aEEnew);
00075     if (myErrorStatus) {
00076       return;
00077     }
00078     //
00079     theSnew=aEEnew;
00080   }
00081   else if (aType==TopAbs_FACE) {
00082     TopoDS_Face aFF, aFFnew;
00083     //
00084     aFF=*((TopoDS_Face*)&theS);
00085     MakeFace(aFF, aFFnew);
00086     if (myErrorStatus) {
00087       return;
00088     }
00089     //
00090     theSnew=aFFnew;
00091   }
00092 }
00093 //=======================================================================
00094 //function : MakeFace
00095 //purpose  :
00096 //=======================================================================
00097 void GEOMAlgo_Gluer2::MakeFace(const TopoDS_Face& theF,
00098                                TopoDS_Face& theFnew)
00099 {
00100   Standard_Boolean bIsToReverse, bIsUPeriodic;
00101   Standard_Integer iRet;
00102   Standard_Real aTol, aUMin, aUMax, aVMin, aVMax;
00103   TopAbs_Orientation aOrE;
00104   Handle(Geom_Surface) aS;
00105   TopLoc_Location aLoc;
00106   TopoDS_Shape aW, aWr;
00107   TopoDS_Edge aEx;
00108   TopoDS_Face aFF, aFnew;
00109   TopoDS_Iterator aItW, aItE;
00110   BRep_Builder aBB;
00111   TopTools_ListOfShape aLEr;
00112   TopTools_ListIteratorOfListOfShape aItLE;
00113   //
00114   myErrorStatus=0;
00115   //
00116   aFF=theF;
00117   aFF.Orientation(TopAbs_FORWARD);
00118   //
00119   aTol=BRep_Tool::Tolerance(aFF);
00120   aS=BRep_Tool::Surface(aFF, aLoc);
00121   bIsUPeriodic=GEOMAlgo_Tools::IsUPeriodic(aS);
00122   BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
00123   //
00124   aBB.MakeFace (aFnew, aS, aLoc, aTol);
00125   //
00126   aItW.Initialize(aFF);
00127   for (; aItW.More(); aItW.Next()) {
00128     const TopoDS_Shape& aW=aItW.Value();
00129     //
00130     if (!myOrigins.IsBound(aW)) {
00131       aBB.Add(aFnew, aW);
00132       continue;
00133     }
00134     //
00135     aWr=myOrigins.Find(aW);
00136     //
00137     // clear contents of Wr
00138     aLEr.Clear();
00139     aItE.Initialize(aWr);
00140     for (; aItE.More(); aItE.Next()) {
00141       const TopoDS_Shape& aEr=aItE.Value();
00142       aLEr.Append(aEr);
00143     }
00144     //
00145     aItLE.Initialize(aLEr);
00146     for (; aItLE.More(); aItLE.Next()) {
00147       const TopoDS_Shape& aEr=aItLE.Value();
00148       aBB.Remove(aWr, aEr);
00149     }
00150     //
00151     // refill contents of Wr
00152     aItE.Initialize(aW);
00153     for (; aItE.More(); aItE.Next()) {
00154       const TopoDS_Edge& aE=*((TopoDS_Edge*)(&aItE.Value()));
00155       //
00156       aEx=aE;
00157       if (myOrigins.IsBound(aE)) {
00158         aEx=*((TopoDS_Edge*)(&myOrigins.Find(aE)));
00159       }
00160       //
00161       if (!BRep_Tool::Degenerated(aEx)) {
00162         aEx.Orientation(TopAbs_FORWARD);
00163         if (bIsUPeriodic) {
00164           GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(aEx, aFF, aUMin, aUMax);
00165         }
00166         //
00167         //modified by NIZNHY-PKV Fri Feb 03 11:18:17 2012f
00168         iRet=GEOMAlgo_Tools::BuildPCurveForEdgeOnFace(aE, aEx, aFF, myContext);
00169         if (iRet) {
00170           continue;
00171         }
00172         //BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aEx, aFF);
00173         //modified by NIZNHY-PKV Fri Feb 03 11:18:20 2012t
00174         //
00175         bIsToReverse=BOPTools_Tools3D::IsSplitToReverse1(aEx, aE, myContext);
00176         if (bIsToReverse) {
00177           aEx.Reverse();
00178         }
00179       }
00180       else {
00181         aEx.Orientation(aE.Orientation());
00182       }
00183       aBB.Add(aWr, aEx);
00184     }// for (; aItE.More(); aItE.Next()) {
00185     //
00186     aBB.Add(aFnew, aWr);
00187   }// for (; aItW.More(); aItW.Next()) {
00188   theFnew=aFnew;
00189 }
00190 //=======================================================================
00191 //function : MakeEdge
00192 //purpose  :
00193 //=======================================================================
00194 void GEOMAlgo_Gluer2::MakeEdge(const TopoDS_Edge& aE,
00195                                TopoDS_Edge& aNewEdge)
00196 {
00197   myErrorStatus=0;
00198   //
00199   Standard_Boolean bIsDE;
00200   Standard_Real aT1, aT2;
00201   TopoDS_Vertex aV1, aV2, aVR1, aVR2;
00202   TopoDS_Edge aEx;
00203   //
00204   bIsDE=BRep_Tool::Degenerated(aE);
00205   //
00206   aEx=aE;
00207   aEx.Orientation(TopAbs_FORWARD);
00208   //
00209   TopExp::Vertices(aEx, aV1, aV2);
00210   //
00211   aT1=BRep_Tool::Parameter(aV1, aEx);
00212   aT2=BRep_Tool::Parameter(aV2, aEx);
00213   //
00214   aVR1=aV1;
00215   if (myOrigins.IsBound(aV1)) {
00216     aVR1=*((TopoDS_Vertex*)&myOrigins.Find(aV1));
00217   }
00218   aVR1.Orientation(TopAbs_FORWARD);
00219   //
00220   aVR2=aV2;
00221   if (myOrigins.IsBound(aV2)) {
00222     aVR2=*((TopoDS_Vertex*)&myOrigins.Find(aV2));
00223   }
00224   aVR2.Orientation(TopAbs_REVERSED);
00225   //
00226   if (!bIsDE) {
00227     BOPTools_Tools::MakeSplitEdge(aEx, aVR1, aT1, aVR2, aT2, aNewEdge);
00228   }
00229   else {
00230     Standard_Real aTol;
00231     BRep_Builder aBB;
00232     TopoDS_Edge E;
00233     //
00234     aTol=BRep_Tool::Tolerance(aE);
00235     //
00236     E=aEx;
00237     E.EmptyCopy();
00238     //
00239     aBB.Add  (E, aVR1);
00240     aBB.Add  (E, aVR2);
00241     aBB.Range(E, aT1, aT2);
00242     aBB.Degenerated(E, Standard_True);
00243     aBB.UpdateEdge(E, aTol);
00244     //
00245     aNewEdge=E;
00246   }
00247 }
00248 //=======================================================================
00249 //function : MakeVertex
00250 //purpose  :
00251 //=======================================================================
00252 void GEOMAlgo_Gluer2::MakeVertex(const TopTools_ListOfShape& aLV,
00253                                  TopoDS_Vertex& aNewVertex)
00254 {
00255   Standard_Integer aNbV;
00256   Standard_Real aTolV, aD, aDmax;
00257   gp_XYZ aGC;
00258   gp_Pnt aP3D, aPGC;
00259   TopoDS_Vertex aVx;
00260   BRep_Builder aBB;
00261   TopTools_ListIteratorOfListOfShape aIt;
00262   //
00263   aNbV=aLV.Extent();
00264   if (!aNbV) {
00265     return;
00266   }
00267   //
00268   // center of gravity
00269   aGC.SetCoord(0.,0.,0.);
00270   aIt.Initialize(aLV);
00271   for (; aIt.More(); aIt.Next()) {
00272     aVx=*((TopoDS_Vertex*)(&aIt.Value()));
00273     aP3D=BRep_Tool::Pnt(aVx);
00274     aGC+=aP3D.XYZ();
00275   }
00276   aGC/=(Standard_Real)aNbV;
00277   aPGC.SetXYZ(aGC);
00278   //
00279   // tolerance value
00280   aDmax=-1.;
00281   aIt.Initialize(aLV);
00282   for (; aIt.More(); aIt.Next()) {
00283     aVx=*((TopoDS_Vertex*)(&aIt.Value()));
00284     aP3D=BRep_Tool::Pnt(aVx);
00285     aTolV=BRep_Tool::Tolerance(aVx);
00286     aD=aPGC.Distance(aP3D)+aTolV;
00287     if (aD>aDmax) {
00288       aDmax=aD;
00289     }
00290   }
00291   //
00292   aBB.MakeVertex (aNewVertex, aPGC, aDmax);
00293 }
00294 //=======================================================================
00295 //function : MapBRepShapes
00296 //purpose  :
00297 //=======================================================================
00298 void GEOMAlgo_Gluer2::MapBRepShapes(const TopoDS_Shape& aS,
00299                                     TopTools_MapOfShape& aM)
00300 {
00301   //Standard_Boolean bHasBRep;
00302   TopAbs_ShapeEnum aType;
00303   TopoDS_Iterator aIt;
00304   //
00305   aType=aS.ShapeType();
00306   if (aType==TopAbs_VERTEX ||
00307       aType==TopAbs_EDGE ||
00308       aType==TopAbs_FACE) {
00309     aM.Add(aS);
00310   }
00311   //
00312   aIt.Initialize(aS);
00313   for(; aIt.More(); aIt.Next()) {
00314     const TopoDS_Shape& aSx=aIt.Value();
00315     aType=aSx.ShapeType();
00316     GEOMAlgo_Gluer2::MapBRepShapes(aSx, aM);
00317   }
00318 }
00319 
00320 //
00321 // ErrorStatus
00322 //
00323 // 40   - GEOMAlgo_GlueDetector is failed