Salome HOME
Merge from V6_2_BR 23/12/2010
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IHealingOperations.cxx
index 3fc9299b783d485a00c8e1ccc411815259b8efe9..e19acd19ad31bbda170483c3548876f657cfa6be 100644 (file)
@@ -1,19 +1,45 @@
-using namespace std;
-
-#include "GEOMImpl_IHealingOperations.hxx"
-
-#include "GEOM_PythonDump.hxx"
-
-#include "GEOMImpl_HealingDriver.hxx"
-#include "GEOMImpl_Types.hxx"
-#include "GEOMImpl_IHealing.hxx"
-#include "GEOMImpl_CopyDriver.hxx"
-
-#include "ShHealOper_ShapeProcess.hxx"
+//  Copyright (C) 2007-2010  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
+
+#ifdef WNT
+#pragma warning( disable:4786 )
+#endif
+
+#include <Standard_Version.hxx>
+#include <Standard_Stream.hxx>
+
+#include <GEOMImpl_IHealingOperations.hxx>
+
+#include <GEOM_PythonDump.hxx>
+
+#include <GEOMImpl_HealingDriver.hxx>
+#include <GEOMImpl_Types.hxx>
+#include <GEOMImpl_IHealing.hxx>
+#include <GEOMImpl_CopyDriver.hxx>
+
+#include <ShHealOper_ShapeProcess.hxx>
 
 #include "utilities.h"
-#include "OpUtil.hxx"
-#include "Utils_ExceptHandlers.hxx"
+#include <OpUtil.hxx>
+#include <Utils_ExceptHandlers.hxx>
 
 #include <ShapeAnalysis_FreeBounds.hxx>
 
@@ -26,8 +52,15 @@ using namespace std;
 
 #include <TDF_Tool.hxx>
 
+#include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
+#ifdef OCC_VERSION_SERVICEPACK
+#define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8 | OCC_VERSION_SERVICEPACK)
+#else
+#define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8)
+#endif
+
 
 //=============================================================================
 /*!
@@ -111,8 +144,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Objec
   }
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Shape Healing algorithm failed");
@@ -161,9 +196,9 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Objec
  *  ShapeProcess
  */
 //=============================================================================
-void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list<string>& theOperations,
-                                                             list<string>& theParams,
-                                                             list<string>& theValues)
+void GEOMImpl_IHealingOperations::GetShapeProcessParameters (std::list<std::string>& theOperations,
+                                                             std::list<std::string>& theParams,
+                                                             std::list<std::string>& theValues)
 {
   ShHealOper_ShapeProcess aHealer;
   TColStd_SequenceOfAsciiString anOperators;
@@ -172,9 +207,9 @@ void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list<string>& theOp
   {
     for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
     {
-      string anOperation = anOperators.Value( i ).ToCString();
+      std::string anOperation = anOperators.Value( i ).ToCString();
       if ( GetOperatorParameters( anOperation, theParams, theValues ) )
-       theOperations.push_back( anOperation );
+        theOperations.push_back( anOperation );
       else
         nbOperatorErrors++;
     }
@@ -196,23 +231,23 @@ void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list<string>& theOp
  *  GetOperatorParameters
  */
 //=============================================================================
-bool GEOMImpl_IHealingOperations::GetOperatorParameters( const string theOperation, 
-                                                        list<string>& theParams,
-                                                        list<string>& theValues )
+bool GEOMImpl_IHealingOperations::GetOperatorParameters( const std::string theOperation,
+                                                         std::list<std::string>& theParams,
+                                                         std::list<std::string>& theValues )
 {
   ShHealOper_ShapeProcess aHealer;
   int nbParamValueErrors( 0 );
-  list<string> aParams;
+  std::list<std::string> aParams;
   if ( GetParameters( theOperation, aParams ) ) {
-    for ( list<string>::iterator it = aParams.begin(); it != aParams.end(); ++it ) {
+    for ( std::list<std::string>::iterator it = aParams.begin(); it != aParams.end(); ++it ) {
       TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() );
       TCollection_AsciiString aValue;
       if ( aHealer.GetParameter( aParam, aValue ) ) {
-       theParams.push_back( aParam.ToCString() );
-       theValues.push_back( aValue.ToCString() );
+        theParams.push_back( aParam.ToCString() );
+        theValues.push_back( aValue.ToCString() );
       }
       else
-       nbParamValueErrors++;
+        nbParamValueErrors++;
     }
   }
   else
@@ -232,8 +267,8 @@ bool GEOMImpl_IHealingOperations::GetOperatorParameters( const string theOperati
  *  GetParameters
  */
 //=============================================================================
-bool GEOMImpl_IHealingOperations::GetParameters (const string theOperation,
-                                                 list<string>& theParams)
+bool GEOMImpl_IHealingOperations::GetParameters (const std::string theOperation,
+                                                 std::list<std::string>& theParams)
 {
   if ( theOperation == "SplitAngle" ) {
     theParams.push_back( "SplitAngle.Angle" );
@@ -295,31 +330,33 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
   // set error code, check parameters
   SetErrorCode(KO);
 
-  if ( theObject.IsNull() ) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
+  if (theObject.IsNull()) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
     return NULL;
 
   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
-  if(aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
+  if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
 
   // Add a new object
-  Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
+  Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
 
   //Add the function
   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
 
-  if(aFunction.IsNull()) return NULL;
+  if (aFunction.IsNull()) return NULL;
 
   //Check if the function is set correctly
-  if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
+  if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
 
   // prepare "data container" class IHealing
-  GEOMImpl_IHealing HI(aFunction);
-  HI.SetFaces( theFaces );
-  HI.SetOriginal( aLastFunction );
+  GEOMImpl_IHealing HI (aFunction);
+  HI.SetFaces(theFaces);
+  HI.SetOriginal(aLastFunction);
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Healing driver failed");
@@ -328,7 +365,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
   }
   catch (Standard_Failure)
   {
-       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     SetErrorCode(aFail->GetMessageString());
     return NULL;
   }
@@ -346,7 +383,6 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
   return aNewObject;
 }
 
-
 //=============================================================================
 /*!
  *  CloseContour
@@ -361,7 +397,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
   SetErrorCode(KO);
 
   if (theObject.IsNull())
+  {
+    SetErrorCode("NULL object given");
     return NULL;
+  }
 
   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
@@ -384,8 +423,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
   HI.SetOriginal( aLastFunction );
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Healing driver failed");
@@ -394,7 +435,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
   }
   catch (Standard_Failure)
   {
-       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+        Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     SetErrorCode(aFail->GetMessageString());
     return NULL;
   }
@@ -404,11 +445,14 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
   pd << aNewObject << " = geompy.CloseContour(" << theObject << ", [";
 
   // list of wire ids
-  int i = theWires->Lower(), nb = theWires->Upper();
-  for ( ; i <= nb; i++)
-    pd << theWires->Value( i ) << (( i < nb ) ? ", " : "], ");
-
-  pd << (int)isCommonVertex << ")";
+  if (!theWires.IsNull())
+  {
+    int i = theWires->Lower(), nb = theWires->Upper();
+    pd << theWires->Value(i++);
+    while (i <= nb)
+      pd << ", " << theWires->Value(i++);
+  }
+  pd << "], " << (int)isCommonVertex << ")";
 
   SetErrorCode(OK);
   return aNewObject;
@@ -448,8 +492,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires
   HI.SetOriginal( aLastFunction );
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Healing driver failed");
@@ -514,8 +560,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object)
   HI.SetOriginal( aLastFunction );
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Healing driver failed");
@@ -524,7 +572,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object)
   }
   catch (Standard_Failure)
   {
-       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+        Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     SetErrorCode(aFail->GetMessageString());
     return NULL;
   }
@@ -580,8 +628,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObj
   HI.SetOriginal( aLastFunction );
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Healing driver failed");
@@ -590,7 +640,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObj
   }
   catch (Standard_Failure)
   {
-       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+        Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     SetErrorCode(aFail->GetMessageString());
     return NULL;
   }
@@ -641,8 +691,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object)
   HI.SetOriginal( aLastFunction );
 
   //Compute the translation
-  try
-  {
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction))
     {
       SetErrorCode("Healing driver failed");
@@ -651,7 +703,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object)
   }
   catch (Standard_Failure)
   {
-       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+        Handle(Standard_Failure) aFail = Standard_Failure::Caught();
     SetErrorCode(aFail->GetMessageString());
     return NULL;
   }
@@ -670,8 +722,8 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object)
  */
 //=============================================================================
 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject,
-                                                  Handle(TColStd_HSequenceOfTransient)& theClosed,
-                                                  Handle(TColStd_HSequenceOfTransient)& theOpen )
+                                                   Handle(TColStd_HSequenceOfTransient)& theClosed,
+                                                   Handle(TColStd_HSequenceOfTransient)& theOpen )
 {
   // set error code, check parameters
   SetErrorCode(KO);
@@ -684,7 +736,13 @@ bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject
     return false;
 
   // get free boundary shapes
-  ShapeAnalysis_FreeBounds anAnalizer( aShape );
+
+#if OCC_VERSION_LARGE > 0x06030008
+  ShapeAnalysis_FreeBounds anAnalizer(aShape, Standard_False,
+                                      Standard_True, Standard_True);
+#else
+  ShapeAnalysis_FreeBounds anAnalizer(aShape);
+#endif
   TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
   TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
 
@@ -709,35 +767,214 @@ bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject
     theOpen->Append(anObj);
   }
 
+  if(!aFunction.IsNull()) {
+
+    //Make a Python command
+    GEOM::TPythonDump pd (aFunction);
+
+    Standard_Integer i, aLen = theClosed->Length();
+    if (aLen > 0) {
+      pd << "(isDone, [";
+      for (i = 1; i <= aLen; i++) {
+        Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i));
+        pd << anObj_i << ((i < aLen) ? ", " : "");
+      }
+      pd << "], ";
+    } else {
+      pd << "(isDone, empty_list, ";
+    }
+
+    aLen = theOpen->Length();
+    if (aLen > 0) {
+      pd << "[";
+      for (i = 1; i <= aLen; i++) {
+        Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i));
+        pd << anObj_i << ((i < aLen) ? ", " : "");
+      }
+      pd << "]";
+    } else {
+      pd << "empty_list";
+    }
+
+    pd << ") = geompy.GetFreeBoundary(" << theObject << ")";
+  }
+
+  SetErrorCode(OK);
+  return true;
+}
+
+
+//=============================================================================
+/*!
+ *  ChangeOrientation
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_Object) theObject)
+{
+  // set error code, check parameters
+  SetErrorCode(KO);
+
+  if (theObject.IsNull())
+    return NULL;
+
+  if (!theObject->IsMainShape()) {
+    SetErrorCode("Sub shape cannot be transformed - need to create a copy");
+    return NULL;
+  }
+
+  Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+  if (aLastFunction.IsNull())
+    return NULL; //There is no function which creates an object to be processed
+
+  //Add the function
+  aFunction = theObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
+
+  if (aFunction.IsNull())
+    return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
+
+  // prepare "data container" class IHealing
+  GEOMImpl_IHealing HI(aFunction);
+  HI.SetOriginal( aLastFunction );
+
+  //Compute the translation
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Healing driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
   //Make a Python command
-  GEOM::TPythonDump pd (aFunction);
+  GEOM::TPythonDump(aFunction) << "geompy.ChangeOrientationShell("
+                               << theObject << ")";
+
+  SetErrorCode(OK);
+  return theObject;
+}
+
+//=============================================================================
+/*!
+ *  ChangeOrientationCopy
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(GEOM_Object) theObject)
+{
+  // set error code, check parameters
+  SetErrorCode(KO);
 
-  Standard_Integer i, aLen = theClosed->Length();
-  if (aLen > 0) {
-    pd << "(isDone, [";
-    for (i = 1; i <= aLen; i++) {
-      Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i));
-      pd << anObj_i << ((i < aLen) ? ", " : "");
+  if (theObject.IsNull())
+    return NULL;
+
+  Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+  if (aLastFunction.IsNull())
+    return NULL; //There is no function which creates an object to be processed
+
+  // Add a new object
+  Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), theObject->GetType() );
+
+  //Add the function
+  aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
+
+  if (aFunction.IsNull())
+    return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
+
+  // prepare "data container" class IHealing
+  GEOMImpl_IHealing HI(aFunction);
+  HI.SetOriginal( aLastFunction );
+
+  //Compute the translation
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Healing driver failed");
+      return NULL;
     }
-    pd << "], ";
-  } else {
-    pd << "(isDone, empty_list, ";
   }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.ChangeOrientationShellCopy("
+                               << theObject << ")";
+
+  SetErrorCode(OK);
+  return aNewObject;
+}
+
+//=============================================================================
+/*!
+ *  LimitTolerance
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject,
+                                                                 double theTolerance)
+{
+  // Set error code, check parameters
+  SetErrorCode(KO);
 
-  aLen = theOpen->Length();
-  if (aLen > 0) {
-    pd << "[";
-    for (i = 1; i <= aLen; i++) {
-      Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i));
-      pd << anObj_i << ((i < aLen) ? ", " : "");
+  if (theObject.IsNull())
+    return NULL;
+
+  Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+  if (aLastFunction.IsNull())
+    return NULL; // There is no function which creates an object to be processed
+
+  // Add a new object
+  Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+
+  // Add the function
+  aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), LIMIT_TOLERANCE);
+
+  if (aFunction.IsNull())
+    return NULL;
+
+  // Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
+
+  // Prepare "data container" class IHealing
+  GEOMImpl_IHealing HI (aFunction);
+  HI.SetOriginal(aLastFunction);
+  HI.SetTolerance(theTolerance);
+
+  // Compute
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Healing driver failed");
+      return NULL;
     }
-    pd << "]";
-  } else {
-    pd << "empty_list";
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
   }
 
-  pd << ") = geompy.GetFreeBoundary(" << theObject << ")";
+  // Make a Python command
+  GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance("
+                               << theObject << ", " << theTolerance << ")";
 
   SetErrorCode(OK);
-  return true;
+  return aNewObject;
 }