Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IHealingOperations.cxx
index 15852e3130df4ce3d5f4f863d780a8570e646ba0..d0892338137abdad97fd06d38e8d6630a05554d7 100644 (file)
@@ -1,17 +1,44 @@
-using namespace std;
-
-#include "GEOMImpl_IHealingOperations.hxx"
-
-#include "GEOMImpl_HealingDriver.hxx"
-#include "GEOMImpl_Types.hxx"
-#include "GEOMImpl_IHealing.hxx"
-#include "GEOMImpl_CopyDriver.hxx"
-
-#include "ShHealOper_ShapeProcess.hxx"
+//  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
+//
+#ifdef WNT
+#pragma warning( disable:4786 )
+#endif
+
+#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>
 
@@ -22,6 +49,9 @@ using namespace std;
 #include <TColStd_HSequenceOfTransient.hxx>
 #include <TCollection_AsciiString.hxx>
 
+#include <TDF_Tool.hxx>
+
+#include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 
@@ -107,8 +137,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");
@@ -123,8 +155,30 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Objec
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump pd (aFunction);
+  pd << aNewObject << " = geompy.ProcessShape(" << theObject << ", [";
+
+  // list of operators
+  int i = theOperators->Lower(), nb = theOperators->Upper();
+  for ( ; i <= nb; i++) {
+    pd << "\"" << TCollection_AsciiString(theOperators->Value( i )).ToCString()
+      << (( i < nb ) ? "\", " : "\"");
+  }
+  pd << "], [";
+  // list of parameters
+  i = theParams->Lower(); nb = theParams->Upper();
+  for ( ; i <= nb; i++) {
+    pd << "\"" << TCollection_AsciiString(theParams->Value( i )).ToCString()
+      << (( i < nb ) ? "\", " : "\"");
+  }
+  pd << "], [";
+  // list of values
+  i = theValues->Lower(); nb = theValues->Upper();
+  for ( ; i <= nb; i++) {
+    pd << "\"" << TCollection_AsciiString(theValues->Value( i )).ToCString()
+      << (( i < nb ) ? "\", " : "\"");
+  }
+  pd << "])";
 
   SetErrorCode(OK);
   return aNewObject;
@@ -135,35 +189,20 @@ 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;
-  int nbOperatorErrors( 0 ), nbParamValueErrors( 0 );
+  int nbOperatorErrors( 0 );
   if ( aHealer.GetOperators( anOperators ) )
   {
     for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
     {
-      string anOperation = anOperators.Value( i ).ToCString();
-      theOperations.push_back( anOperation );
-      list<string> aParams, aValues;
-      if ( GetParameters( anOperation, aParams ) )
-      {
-        for ( list<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() );
-          }
-         else
-            nbParamValueErrors++;
-        }
-      }
+      std::string anOperation = anOperators.Value( i ).ToCString();
+      if ( GetOperatorParameters( anOperation, theParams, theValues ) )
+       theOperations.push_back( anOperation );
       else
         nbOperatorErrors++;
     }
@@ -173,22 +212,56 @@ void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list<string>& theOp
     SetErrorCode("ERROR retrieving operators (GEOMImpl_IHealingOperations)");
   }
 
-  if (nbOperatorErrors || nbParamValueErrors) {
+  if ( nbOperatorErrors ) {
     TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameters (GEOMImpl_IHealingOperations): nbOperatorErrors = ");
-    aMsg += TCollection_AsciiString(nbOperatorErrors);
-    aMsg += " ,nbParamValueErrors = ";
-    aMsg += TCollection_AsciiString(nbParamValueErrors);
+    aMsg += TCollection_AsciiString( nbOperatorErrors );
     MESSAGE(aMsg.ToCString());
   }
 }
 
+//=============================================================================
+/*!
+ *  GetOperatorParameters
+ */
+//=============================================================================
+bool GEOMImpl_IHealingOperations::GetOperatorParameters( const std::string theOperation, 
+                                                        std::list<std::string>& theParams,
+                                                        std::list<std::string>& theValues )
+{
+  ShHealOper_ShapeProcess aHealer;
+  int nbParamValueErrors( 0 );
+  std::list<std::string> aParams;
+  if ( GetParameters( theOperation, aParams ) ) {
+    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() );
+      }
+      else
+       nbParamValueErrors++;
+    }
+  }
+  else
+    return false;
+
+  if ( nbParamValueErrors ) {
+    TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameter values (GEOMImpl_IHealingOperations): nbParamValueErrors = ");
+    aMsg += TCollection_AsciiString( nbParamValueErrors );
+    MESSAGE(aMsg.ToCString());
+  }
+
+  return true;
+}
+
 //=============================================================================
 /*!
  *  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" );
@@ -244,8 +317,8 @@ bool GEOMImpl_IHealingOperations::GetParameters (const string theOperation,
  *  SuppressFaces
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Object) theObject,
-                                                                const Handle(TColStd_HArray1OfInteger)& theFaces)
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
+       (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theFaces)
 {
   // set error code, check parameters
   SetErrorCode(KO);
@@ -273,8 +346,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Obje
   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");
@@ -289,8 +364,13 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Obje
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump pd (aFunction);
+  pd << aNewObject << " = geompy.SuppressFaces(" << theObject << ", [";
+
+  // list of face ids
+  int i = theFaces->Lower(), nb = theFaces->Upper();
+  for ( ; i <= nb; i++)
+    pd << theFaces->Value( i ) << (( i < nb ) ? ", " : "])");
 
   SetErrorCode(OK);
   return aNewObject;
@@ -302,15 +382,19 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Obje
  *  CloseContour
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Object) theObject,
-                                                              const Handle(TColStd_HArray1OfInteger)& theWires,
-                                                               bool isCommonVertex)
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
+                    (Handle(GEOM_Object) theObject,
+                     const Handle(TColStd_HArray1OfInteger)& theWires,
+                     bool isCommonVertex)
 {
   // set error code, check parameters
   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
@@ -333,8 +417,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Objec
   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");
@@ -349,8 +435,18 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Objec
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump pd (aFunction);
+  pd << aNewObject << " = geompy.CloseContour(" << theObject << ", [";
+
+  // list of wire ids
+  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;
@@ -361,8 +457,8 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Objec
  *  RemoveIntWires
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires (Handle(GEOM_Object) theObject,
-                                                                 const Handle(TColStd_HArray1OfInteger)& theWires)
+Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires
+       (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theWires)
 {
   // set error code, check parameters
   SetErrorCode(KO);
@@ -390,8 +486,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires (Handle(GEOM_Obj
   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");
@@ -406,8 +504,17 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires (Handle(GEOM_Obj
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump pd (aFunction);
+  pd << aNewObject << " = geompy.SuppressInternalWires(" << theObject << ", [";
+
+  // list of wire ids
+  if (!theWires.IsNull()) {
+    int i = theWires->Lower(), nb = theWires->Upper();
+    for ( ; i <= nb; i++)
+      pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
+  } else {
+    pd << "])";
+  }
 
   SetErrorCode(OK);
   return aNewObject;
@@ -447,8 +554,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");
@@ -463,8 +572,17 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object)
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump pd (aFunction);
+  pd << aNewObject << " = geompy.SuppressHoles(" << theObject << ", [";
+
+  // list of wire ids
+  if ( theWires.IsNull() )
+    pd << "])";
+  else {
+    int i = theWires->Lower(), nb = theWires->Upper();
+    for ( ; i <= nb; i++)
+      pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
+  }
 
   SetErrorCode(OK);
   return aNewObject;
@@ -504,8 +622,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");
@@ -520,8 +640,8 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObj
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.Sew("
+                               << theObject << ", " << theTolerance << ")";
 
   SetErrorCode(OK);
   return aNewObject;
@@ -565,8 +685,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");
@@ -581,8 +703,8 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object)
   }
 
   //Make a Python command
-  // ...
-  // ... missing ...
+  GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.DivideEdge(" << theObject
+    << ", " << theIndex << ", " << theValue << ", " << (int)isByParameter << ")";
 
   SetErrorCode(OK);
   return aNewObject;
@@ -633,6 +755,157 @@ 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(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);
+
+  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;
+    }
+  }
+  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;
+}
+