Salome HOME
Merge from V6_2_BR 23/12/2010
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IHealingOperations.cxx
index 7c90d1e2cf589b2718b498a937fd396974a4756e..e19acd19ad31bbda170483c3548876f657cfa6be 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  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
@@ -23,6 +23,7 @@
 #pragma warning( disable:4786 )
 #endif
 
+#include <Standard_Version.hxx>
 #include <Standard_Stream.hxx>
 
 #include <GEOMImpl_IHealingOperations.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
+
 
 //=============================================================================
 /*!
@@ -729,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();
 
@@ -850,7 +863,6 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_
   return theObject;
 }
 
-
 //=============================================================================
 /*!
  *  ChangeOrientationCopy
@@ -907,3 +919,62 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(G
   SetErrorCode(OK);
   return aNewObject;
 }
+
+//=============================================================================
+/*!
+ *  LimitTolerance
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject,
+                                                                 double theTolerance)
+{
+  // Set error code, check parameters
+  SetErrorCode(KO);
+
+  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;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  // Make a Python command
+  GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance("
+                               << theObject << ", " << theTolerance << ")";
+
+  SetErrorCode(OK);
+  return aNewObject;
+}