Salome HOME
Porting to OCCT development version: Standard_PI -> M_PI
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WESCorrector.cxx
index 26280fd0d58d417284663bc24b2bd961de4edbe4..93cfc6e60147d8975980e7a7293e8b89883a8ddc 100755 (executable)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 // File:        NMTAlgo_WESCorrector.cxx
 // Created:     
 //
 #include <GEOMAlgo_WESCorrector.ixx>
 
+#include <Geom_Surface.hxx>
+
+#include <TopLoc_Location.hxx>
 #include <TopoDS.hxx>
+
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
@@ -34,6 +38,7 @@
 
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
+#include <BRepAdaptor_Surface.hxx>
 
 #include <TopTools_IndexedMapOfOrientedShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopTools_MapIteratorOfMapOfShape.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <GEOMAlgo_WireSplitter.hxx>
-
+#include <GEOMAlgo_WESScaler.hxx>
 
 static
   void MakeWire(const TopTools_ListOfShape& aLE, 
                 TopoDS_Wire& newWire);
 
+
+static
+  Standard_Boolean IsToScale(const TopoDS_Face& aF, 
+                            Standard_Real& aScale);
+
 //=======================================================================
 // function: 
 // purpose: 
@@ -214,19 +224,21 @@ static
         aER.Orientation(TopAbs_REVERSED);
         aLEC.Append(aER);
         //
-        //modified by NIZNHY-PKV Tue Nov 28 12:02:29 2006f
-        //bClosed=BRep_Tool::IsClosed(TopoDS::Edge(aER), myWES->Face());
-        //if (!bClosed) {
-          bRegular=Standard_False;
-        //}
-        //modified by NIZNHY-PKV Tue Nov 28 12:02:33 2006t
+       bRegular=Standard_False;
       }
       else {
         aLEC.Append(aER);
       }
       //
       if (bRegular) {
-        TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
+       //modified by NIZNHY-PKV Wed Oct 20 14:45:52 2010f
+       const  TopoDS_Edge& aEx=*((TopoDS_Edge*)&aER);
+       if (!BRep_Tool::Degenerated(aEx)) {
+         TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
+       }
+       //
+        //TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
+       //modified by NIZNHY-PKV Wed Oct 20 14:46:48 2010t
       }
     }//for (j=1; j<=aNbC; ++j) {
     //
@@ -265,21 +277,24 @@ static
 //=======================================================================
   void GEOMAlgo_WESCorrector::DoCorrections()
 {
-  Standard_Boolean bIsRegular, bIsNothingToDo;
+  Standard_Boolean bIsRegular, bIsNothingToDo, bToScale;
   Standard_Integer iErr;
+  Standard_Real aScale;
   TopoDS_Wire aW;
   BOP_ListIteratorOfListOfConnexityBlock aCBIt;
+  GEOMAlgo_WESScaler aWSC;
   //
   const TopoDS_Face& aF=myWES->Face();
   //
+  bToScale=IsToScale(aF, aScale);
+  //
   myNewWES.SetFace(aF);
   aCBIt.Initialize(myConnexityBlocks);
   for (; aCBIt.More(); aCBIt.Next()) {
     const BOP_ConnexityBlock& aCB=aCBIt.Value();
     const TopTools_ListOfShape& aLE=aCB.Shapes();
-
+    //
     bIsRegular=aCB.IsRegular();
-
     if (bIsRegular) {
       MakeWire(aLE, aW);
       myNewWES.AddShape (aW);
@@ -288,30 +303,84 @@ static
     //
     GEOMAlgo_WireSplitter aWS;
     //
-    aWS.SetFace(aF);
-    aWS.SetEdges(aLE);
-    //
-    aWS.Perform();
-    iErr=aWS.ErrorStatus();
-    if (iErr) {
-      continue;
-    }
-    bIsNothingToDo=aWS.IsNothingToDo();
-    if (bIsNothingToDo) {
-      MakeWire(aLE, aW);
-      myNewWES.AddShape (aW);
-      continue;
-    }
+    if(bToScale) {
+      TopoDS_Shape aE;
+      TopTools_ListIteratorOfListOfShape aIt;
+      BOPTColStd_ListIteratorOfListOfListOfShape aItLLSS;
+      //
+      aWSC.SetScale(aScale);
+      aWSC.SetFace(aF);
+      aWSC.SetEdges(aLE);
+      //
+      aWSC.Perform();
+      iErr=aWSC.ErrorStatus();
+      if (iErr) {
+       return;
+      }
+      //
+      const TopoDS_Face& aFS=aWSC.FaceScaled();
+      const TopTools_ListOfShape& aLES=aWSC.EdgesScaled();
+      //
+      aWS.SetFace(aFS);
+      aWS.SetEdges(aLES);
+      //
+      aWS.Perform();
+      iErr=aWS.ErrorStatus();
+      if (iErr) {
+       continue;
+      }
+      //
+      bIsNothingToDo=aWS.IsNothingToDo();
+      if (bIsNothingToDo) {
+       MakeWire(aLE, aW);
+       myNewWES.AddShape (aW);
+       continue;
+      }
+      //
+      const BOPTColStd_ListOfListOfShape& aLLSS=aWS.Shapes();
+      aItLLSS.Initialize(aLLSS);
+      for (; aItLLSS.More(); aItLLSS.Next()) {
+       TopTools_ListOfShape aLS;
+       //
+       const TopTools_ListOfShape& aLSS=aItLLSS.Value();
+       aIt.Initialize(aLSS);
+       for (; aIt.More(); aIt.Next()) {
+         const TopoDS_Shape& aES=aIt.Value();
+         aE=aWSC.Origin(aES);
+         aLS.Append(aE);
+       }
+       //
+       MakeWire(aLS, aW);
+       myNewWES.AddShape (aW);
+      }
+    }//if(bToScale)
     //
-    const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
-    
-    BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
-    for (; aWireIt.More(); aWireIt.Next()) {
-      const TopTools_ListOfShape& aLEx=aWireIt.Value();
+    else {
+      aWS.SetFace(aF);
+      aWS.SetEdges(aLE);
       //
-      MakeWire(aLEx, aW);
-      myNewWES.AddShape (aW);
-    }
+      aWS.Perform();
+      iErr=aWS.ErrorStatus();
+      if (iErr) {
+       continue;
+      }
+      bIsNothingToDo=aWS.IsNothingToDo();
+      if (bIsNothingToDo) {
+       MakeWire(aLE, aW);
+       myNewWES.AddShape (aW);
+       continue;
+      }
+      //
+      const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
+    
+      BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
+      for (; aWireIt.More(); aWireIt.Next()) {
+       const TopTools_ListOfShape& aLEx=aWireIt.Value();
+       //
+       MakeWire(aLEx, aW);
+       myNewWES.AddShape (aW);
+      }
+    }// else
   }
 }
 //=======================================================================
@@ -330,3 +399,36 @@ static
     aBB.Add(newWire, aE);
   }
 }
+//
+
+//=======================================================================
+//function : IsToScale
+//purpose  : 
+//=======================================================================
+Standard_Boolean IsToScale(const TopoDS_Face& aF, 
+                          Standard_Real& aScale)
+{
+  Standard_Boolean bRet;
+  Standard_Real aV1, aV2, dV, aTr;
+  GeomAbs_SurfaceType aType;
+  BRepAdaptor_Surface aBAS;
+  //
+  bRet=Standard_False;
+  aScale=1.;
+  //
+  aBAS.Initialize(aF);
+  aType=aBAS.GetType();
+  if (aType==GeomAbs_Cylinder) {
+    aTr=1.e5;
+    aV1=aBAS.FirstVParameter();
+    aV2=aBAS.LastVParameter();
+    dV=aV2-aV1;
+    if (dV>aTr) {
+      bRet=!bRet;
+      aScale=1./aTr;
+    }
+  }
+  return bRet;
+}
+