Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ShapeDriver.cxx
index 349b59f09a25e0e321d5c60e29051a1d16c275a2..17854800a356768ce482dd2b8274d18bca240afc 100644 (file)
@@ -1,22 +1,23 @@
-// Copyright (C) 2005  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.
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  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
 
 #include <GEOMImpl_ShapeDriver.hxx>
 
@@ -28,6 +29,7 @@
 
 // OCCT Includes
 #include <ShapeFix_Wire.hxx>
+#include <ShapeFix_Edge.hxx>
 
 #include <BRep_Tool.hxx>
 #include <BRep_Builder.hxx>
@@ -151,16 +153,38 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
         Standard_ConstructionError::Raise("Wire construction failed: several loops detected");
       } else if (aFW->StatusReorder(ShapeExtend_FAIL)) {
         Standard_ConstructionError::Raise("Wire construction failed");
-      } else if (aFW->StatusReorder(ShapeExtend_DONE2)) {
-        Standard_ConstructionError::Raise("Wire construction failed: some gaps detected");
+      //} else if (aFW->StatusReorder(ShapeExtend_DONE2)) {
+      //  Standard_ConstructionError::Raise("Wire construction failed: some gaps detected");
       } else {
       }
 
+      // IMP 0019766: Building a Wire from unconnected edges by introducing a tolerance
+      Standard_Real aTolerance = aCI.GetTolerance();
+      if (aTolerance < Precision::Confusion())
+        aTolerance = Precision::Confusion();
+
       aFW->ClosedWireMode() = Standard_False;
-      aFW->FixConnected();
+      aFW->FixConnected(aTolerance);
       if (aFW->StatusConnected(ShapeExtend_FAIL)) {
         Standard_ConstructionError::Raise("Wire construction failed: cannot build connected wire");
       }
+      // IMP 0019766
+      if (aFW->StatusConnected(ShapeExtend_DONE3)) {
+        // Confused with <prec> but not Analyzer.Precision(), set the same
+        aFW->FixGapsByRangesMode() = Standard_True;
+        if (aFW->FixGaps3d()) {
+          Handle(ShapeExtend_WireData) sbwd = aFW->WireData();
+          Handle(ShapeFix_Edge) aFe = new ShapeFix_Edge;
+          for (Standard_Integer iedge = 1; iedge <= sbwd->NbEdges(); iedge++) {
+            TopoDS_Edge aEdge = TopoDS::Edge(sbwd->Edge(iedge));
+            aFe->FixVertexTolerance(aEdge);
+            aFe->FixSameParameter(aEdge);
+          }
+        }
+        else if (aFW->StatusGaps3d(ShapeExtend_FAIL)) {
+          Standard_ConstructionError::Raise("Wire construction failed: cannot fix 3d gaps");
+        }
+      }
 
       aShape = aFW->WireAPIMake();
     }
@@ -388,15 +412,10 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
     if ( ish == 0 ) return 0;
     BRepClass3d_SolidClassifier SC (Sol);
     SC.PerformInfinitePoint(Precision::Confusion());
-    switch (SC.State()) {
-    case TopAbs_IN:
-      aShape = Sol.Reversed(); break;
-    case TopAbs_OUT:
-      aShape = Sol; break;
-    default: // not closed shell?
-      return 0;
-    }
-
+    if (SC.State() == TopAbs_IN)
+      aShape = Sol.Reversed();
+    else
+      aShape = Sol;
   }
   else if (aType == COMPOUND_SHAPES) {
     Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
@@ -445,7 +464,7 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const
   // Check shape validity
   BRepCheck_Analyzer ana (aShape, false);
   if (!ana.IsValid()) {
-    Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
+    //Standard_ConstructionError::Raise("Algorithm have produced an invalid shape result");
   }
 
   aFunction->SetValue(aShape);