Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Tools.cxx
index 1a4437b7fd3a264412d23b85b86295b49ef2c8f5..a265c785f28788af96f951437ef5f7060e5605fa 100644 (file)
@@ -1,8 +1,29 @@
+//  Copyright (C) 2007-2008  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
+//
+//  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.
+//
+//  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>
-
+//
 #include <GEOMAlgo_Tools.ixx>
 
 #include <gp_Pnt.hxx>
@@ -33,8 +54,8 @@
 #include <BOPTools_Tools2D.hxx>
 #include <IntTools_Context.hxx>
 
-#include <GEOMAlgo_PassKeyShape.hxx>
-#include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>
+#include <GEOMAlgo_PassKeyShape.hxx>//qft
+#include <GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape.hxx>//qft
 
 static 
   void GetCount(const TopoDS_Shape& aS,
@@ -88,9 +109,9 @@ void GetCount(const TopoDS_Shape& aS,
 //function : RefineSDShapes
 //purpose  : 
 //=======================================================================
-Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape &aMPKLE,
-                                               const Standard_Real aTol,
-                                               IntTools_Context& aCtx)
+  Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKeyShapeListOfShape& aMPKLE,
+                                                 const Standard_Real aTol,
+                                                 IntTools_Context& aCtx)
 {
   Standard_Integer i, aNbE, iErr, j, aNbEE, aNbToAdd;
   TopTools_IndexedDataMapOfShapeListOfShape aMEE, aMSDE, aMEToAdd;
@@ -137,7 +158,10 @@ Standard_Integer GEOMAlgo_Tools::RefineSDShapes(GEOMAlgo_IndexedDataMapOfPassKey
     const TopoDS_Shape& aE1=aMEToAdd.FindKey(i);
     const TopTools_ListOfShape& aLE=aMEToAdd(i);
     //
-    aPKE1.SetIds(aE1);
+    //qf
+    //aPKE1.SetIds(aE1);
+    aPKE1.SetShapes(aE1);
+    //qt
     aMPKLE.Add(aPKE1, aLE);
   }
   //
@@ -242,7 +266,8 @@ 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) {
@@ -262,41 +287,54 @@ Standard_Boolean GEOMAlgo_Tools::ProjectPointOnShape(const gp_Pnt& aP1,
                                                     gp_Pnt& aP2,
                                                     IntTools_Context& aCtx)
 {
-  Standard_Boolean bIsDone=Standard_False;
+  Standard_Boolean bIsDone = Standard_False;
   Standard_Real aT2;
   TopAbs_ShapeEnum aType;
   //
-  aType=aS.ShapeType();
-  switch(aType) {
-    case TopAbs_EDGE: {
-      const TopoDS_Edge& aE2=TopoDS::Edge(aS);
-      //
-      bIsDone=aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
-      if (!bIsDone) {
-       return bIsDone;
+  aType = aS.ShapeType();
+  switch (aType)
+    {
+    case TopAbs_EDGE:
+      {
+        const TopoDS_Edge& aE2 = TopoDS::Edge(aS);
+        //
+        if (BRep_Tool::Degenerated(aE2)) { // jfa
+          return Standard_True;
+        }
+        else {
+          Standard_Real f, l;
+          Handle(Geom_Curve) aC3D = BRep_Tool::Curve (aE2, f, l);
+          if (aC3D.IsNull()) {
+            return Standard_True;
+          }
+          bIsDone = aCtx.ProjectPointOnEdge(aP1, aE2, aT2);
+        }
+        if (!bIsDone) {
+          return bIsDone;
+        }
+        //
+        GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
       }
-      //
-      GEOMAlgo_Tools::PointOnEdge(aE2, aT2, aP2);
-    }
       break;
       //
-    case TopAbs_FACE: {
-      const TopoDS_Face& aF2=TopoDS::Face(aS);
-      GeomAPI_ProjectPointOnSurf& aProj=aCtx.ProjPS(aF2);
-      //
-      aProj.Perform(aP1);
-      bIsDone=aProj.IsDone();
-      if (!bIsDone) {
-       return bIsDone;
+    case TopAbs_FACE:
+      {
+        const TopoDS_Face& aF2 = TopoDS::Face(aS);
+        GeomAPI_ProjectPointOnSurf& aProj = aCtx.ProjPS(aF2);
+        //
+        aProj.Perform(aP1);
+        bIsDone = aProj.IsDone();
+        if (!bIsDone) {
+          return bIsDone;
+        }
+        //
+        aP2 = aProj.NearestPoint(); 
       }
-      //
-      aP2=aProj.NearestPoint(); 
-    }
       break;
       //  
     default:
       break; // Err
-  }
+    }
   return bIsDone;
 }
 //=======================================================================