Salome HOME
Fix for the bug IPAL22851: Sub-shapes spelling
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Tools.cxx
index f19581253252f64d543831b8f18ecc81fde3ec79..e71ab85db31c980d05cbe35fb163b04d553f51b2 100644 (file)
@@ -1,29 +1,28 @@
-//  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
-//
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-// File:       GEOMAlgo_Tools.cxx
-// Created:    Mon Dec  6 11:35:29 2004
-// Author:     Peter KURNEV
-//             <pkv@irinox>
+// 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
+
+// File:        GEOMAlgo_Tools.cxx
+// Created:     Mon Dec  6 11:35:29 2004
+// Author:      Peter KURNEV
+
 #include <GEOMAlgo_Tools.ixx>
 
 #include <gp_Pnt.hxx>
@@ -59,7 +58,7 @@
 
 static 
   void GetCount(const TopoDS_Shape& aS,
-               Standard_Integer& iCnt);
+                Standard_Integer& iCnt);
 
 //=======================================================================
 //function : IsCompositeShape
@@ -83,7 +82,7 @@ Standard_Boolean GEOMAlgo_Tools::IsCompositeShape(const TopoDS_Shape& aS)
 //purpose  : 
 //=======================================================================
 void GetCount(const TopoDS_Shape& aS,
-             Standard_Integer& iCnt)
+              Standard_Integer& iCnt)
 {
   TopoDS_Iterator aIt;
   TopAbs_ShapeEnum aTS;
@@ -110,8 +109,8 @@ void GetCount(const TopoDS_Shape& aS,
 //purpose  : 
 //=======================================================================
   Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape& aMPKLE,
-                                                 const Standard_Real aTol,
-                                                 IntTools_Context& aCtx)
+                                                  const Standard_Real aTol,
+                                                  IntTools_Context& aCtx)
 {
   Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
   TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
@@ -137,12 +136,12 @@ void GetCount(const TopoDS_Shape& aS,
       TopTools_ListOfShape& aLEE=aMEE.ChangeFromIndex(j);
       //
       if (j==1) {
-       aLSDE.Clear();
-       aLSDE.Append(aLEE);
+        aLSDE.Clear();
+        aLSDE.Append(aLEE);
       }
       else {
-       const TopoDS_Shape& aE1=aLEE.First();
-       aMEToAdd.Add(aE1, aLEE);
+        const TopoDS_Shape& aE1=aLEE.First();
+        aMEToAdd.Add(aE1, aLEE);
       }
     }
   }
@@ -172,9 +171,9 @@ void GetCount(const TopoDS_Shape& aS,
 //purpose  : 
 //=======================================================================
 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
-                                             const Standard_Real aTol,
-                                             TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
-                                             IntTools_Context& aCtx)
+                                              const Standard_Real aTol,
+                                              TopTools_IndexedDataMapOfShapeListOfShape& aMEE,
+                                              IntTools_Context& aCtx)
 {
   Standard_Integer aNbE, aNbEProcessed, aNbESD, iErr;
   TopTools_ListOfShape aLESD;
@@ -203,37 +202,37 @@ Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
       const TopoDS_Shape& aS=aIt.Value();
       //
       if (aMProcessed.Contains(aS)) {
-       continue;
+        continue;
       }
       //
       //modified by NIZNHY-PKV Thu Dec 30 10:57:01 2004 f
       aType=aS.ShapeType();
       if (aType==TopAbs_EDGE) {
-       const TopoDS_Edge& aE=TopoDS::Edge(aS);
-       if (BRep_Tool::Degenerated(aE)) {
-         aMProcessed.Add(aE);
-         continue;
-       }
+        const TopoDS_Edge& aE=TopoDS::Edge(aS);
+        if (BRep_Tool::Degenerated(aE)) {
+          aMProcessed.Add(aE);
+          continue;
+        }
       }
       //modified by NIZNHY-PKV Thu Dec 30 10:57:03 2004 t
       //
       aLESD.Clear();
       iErr=GEOMAlgo_Tools::FindSDShapes(aS, aLE, aTol, aLESD, aCtx);
       if (iErr) {
-       return 2; // Err
+        return 2; // Err
       }
       //
       aNbESD=aLESD.Extent();
       if (!aNbESD) {
-       return 1; // Err
+        return 1; // Err
       }
       //
       aMEE.Add(aS, aLESD);
       //
       aIt1.Initialize(aLESD);
       for (; aIt1.More(); aIt1.Next()) {
-       const TopoDS_Shape& aE1=aIt1.Value();
-       aMProcessed.Add(aE1);
+        const TopoDS_Shape& aE1=aIt1.Value();
+        aMProcessed.Add(aE1);
       }
     }
   }
@@ -244,10 +243,10 @@ Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopTools_ListOfShape& aLE,
 //purpose  : 
 //=======================================================================
 Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
-                                             const TopTools_ListOfShape& aLE,
-                                             const Standard_Real aTol,
-                                             TopTools_ListOfShape& aLESD,
-                                             IntTools_Context& aCtx)
+                                              const TopTools_ListOfShape& aLE,
+                                              const Standard_Real aTol,
+                                              TopTools_ListOfShape& aLESD,
+                                              IntTools_Context& aCtx)
 {
   Standard_Boolean bIsDone;
   Standard_Real aTol2, aD2;
@@ -266,11 +265,12 @@ Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
     else {
       bIsDone=GEOMAlgo_Tools::ProjectPointOnShape(aP1, aE2, aP2, aCtx);
       if (!bIsDone) {
-       return 1; 
+        //return 1; 
+        continue; // jfa BUG 20361
       }
       aD2=aP1.SquareDistance(aP2);
       if(aD2<aTol2) {
-       aLESD.Append(aE2);
+        aLESD.Append(aE2);
       }
     }
   }
@@ -282,9 +282,9 @@ Standard_Integer GEOMAlgo_Tools::FindSDShapes(const TopoDS_Shape& aE1,
 //purpose  : 
 //=======================================================================
 Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
-                                                    const TopoDS_Shape& aS,
-                                                    gp_Pnt& aP2,
-                                                    IntTools_Context& aCtx)
+                                                     const TopoDS_Shape& aS,
+                                                     gp_Pnt& aP2,
+                                                     IntTools_Context& aCtx)
 {
   Standard_Boolean bIsDone = Standard_False;
   Standard_Real aT2;
@@ -295,24 +295,20 @@ Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
     {
     case TopAbs_EDGE:
       {
-        // cout << "$$$ case TopAbs_EDGE" << endl;
         const TopoDS_Edge& aE2 = TopoDS::Edge(aS);
         //
         if (BRep_Tool::Degenerated(aE2)) { // jfa
-          // cout << "$$$ Degenerated" << endl;
           return Standard_True;
         }
         else {
           Standard_Real f, l;
           Handle(Geom_Curve) aC3D = BRep_Tool::Curve (aE2, f, l);
           if (aC3D.IsNull()) {
-            // cout << "$$$ aC3D.IsNull()" << endl;
             return Standard_True;
           }
           bIsDone = aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
         }
         if (!bIsDone) {
-          // cout << "$$$ !bIsDone" << endl;
           return bIsDone;
         }
         //
@@ -345,7 +341,7 @@ Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
-                                 gp_Pnt& aP3D)
+                                  gp_Pnt& aP3D)
 {
   TopAbs_ShapeEnum aType;
   //
@@ -373,7 +369,7 @@ void GEOMAlgo_Tools::PointOnShape(const TopoDS_Shape& aS,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
-                                gp_Pnt& aP3D)
+                                 gp_Pnt& aP3D)
 {
   Standard_Real aU, aV, aUMin, aUMax, aVMin, aVMax;
   //
@@ -389,9 +385,9 @@ void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
-                                const Standard_Real aU,
-                                const Standard_Real aV,
-                                gp_Pnt& aP3D)
+                                 const Standard_Real aU,
+                                 const Standard_Real aV,
+                                 gp_Pnt& aP3D)
 {
   Handle(Geom_Surface) aS;
   //
@@ -403,7 +399,7 @@ void GEOMAlgo_Tools::PointOnFace(const TopoDS_Face& aF,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
-                                gp_Pnt& aP3D)
+                                 gp_Pnt& aP3D)
 {
   Standard_Real aTx, aT1, aT2;
   //
@@ -416,8 +412,8 @@ void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
-                                const Standard_Real aT,
-                                gp_Pnt& aP3D)
+                                 const Standard_Real aT,
+                                 gp_Pnt& aP3D)
 {
   Standard_Real aT1, aT2;
   Handle(Geom_Curve) aC3D;
@@ -430,18 +426,16 @@ void GEOMAlgo_Tools::PointOnEdge(const TopoDS_Edge& aE,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_Tools::RefinePCurveForEdgeOnFace(const TopoDS_Edge& aE,
-                                              const TopoDS_Face& aF,
-                                              const Standard_Real aUMin, 
-                                              const Standard_Real aUMax) 
+                                               const TopoDS_Face& aF,
+                                               const Standard_Real aUMin, 
+                                               const Standard_Real aUMax) 
 {
-  Standard_Real aT1, aT2, aTx, aUx, aTol, aTwoPI;
+  Standard_Real aT1, aT2, aTx, aUx, aTol;
   gp_Pnt2d aP2D;
   Handle(Geom_Surface) aS;
   Handle(Geom2d_Curve) aC2D;
   BRep_Builder aBB;
   //
-  aTwoPI=PI+PI;
-  //
   aC2D=BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
   if (!aC2D.IsNull()) {
     if (BRep_Tool::IsClosed(aE, aF)) {
@@ -472,8 +466,8 @@ Standard_Boolean GEOMAlgo_Tools::IsUPeriodic(const  Handle(Geom_Surface) &aS)
   aGAS.Load(aS);
   aType=aGAS.GetType();
   bRet=(aType==GeomAbs_Cylinder||
-       aType==GeomAbs_Cone ||
-       aType==GeomAbs_Sphere);
+        aType==GeomAbs_Cone ||
+        aType==GeomAbs_Sphere);
   //
   return bRet;
 }