Salome HOME
Merge from V6_main (04/10/2012)
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ICurvesOperations.cxx
index ca1ac5db0be258c1e2515282f1cc11a7c712f6d2..f4508d35b089d5c9028a7db2c698e1747438dc29 100644 (file)
@@ -18,7 +18,6 @@
 // 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
 // E.A. : On windows with python 2.6, there is a conflict
@@ -1168,39 +1167,36 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCom
 
 //=============================================================================
 /*!
- *  Make3DSketcher
+ *  MakeSketcherOnPlane
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
+                               (const char* theCommand,
+                                Handle(GEOM_Object)            theWorkingPlane)
 {
   SetErrorCode(KO);
 
+  if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
+
   //Add a new Sketcher object
-  Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
+  Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
 
   //Add a new Sketcher function
   Handle(GEOM_Function) aFunction =
-    a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
+    aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
   if (aFunction.IsNull()) return NULL;
 
   //Check if the function is set correctly
-  if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
-
-  GEOMImpl_I3DSketcher aCI (aFunction);
-
-  int nbOfCoords = 0;
-  std::list<double>::iterator it = theCoordinates.begin();
-  for (; it != theCoordinates.end(); it++)
-    nbOfCoords++;
+  if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
 
-  Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
+  GEOMImpl_ISketcher aCI (aFunction);
 
-  it = theCoordinates.begin();
-  int ind = 1;
-  for (; it != theCoordinates.end(); it++, ind++)
-    aCoordsArray->SetValue(ind, *it);
+  TCollection_AsciiString aCommand((char*) theCommand);
+  aCI.SetCommand(aCommand);
 
-  aCI.SetCoordinates(aCoordsArray);
+  Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
+  if (aRefPlane.IsNull()) return NULL;
+  aCI.SetWorkingPlane( aRefPlane );
 
   //Compute the Sketcher value
   try {
@@ -1208,7 +1204,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
-      SetErrorCode("3D Sketcher driver failed");
+      SetErrorCode("Sketcher driver failed");
       return NULL;
     }
   }
@@ -1219,52 +1215,99 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double
   }
 
   //Make a Python command
-  GEOM::TPythonDump pd (aFunction);
-  pd << a3DSketcher << " = geompy.Make3DSketcher([";
-
-  it = theCoordinates.begin();
-  pd << (*it++);
-  while (it != theCoordinates.end()) {
-    pd << ", " << (*it++);
-  }
-  pd << "])";
+  GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
+    << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
 
   SetErrorCode(OK);
-  return a3DSketcher;
+  return aSketcher;
 }
 
 //=============================================================================
 /*!
- *  MakeSketcherOnPlane
+ *  Make3DSketcherCommand
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
-                               (const char* theCommand,
-                                Handle(GEOM_Object)            theWorkingPlane)
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcherCommand (const char* theCommand)
 {
   SetErrorCode(KO);
 
   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
 
   //Add a new Sketcher object
-  Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
+  Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
 
   //Add a new Sketcher function
   Handle(GEOM_Function) aFunction =
-    aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
+    aSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COMMAND);
   if (aFunction.IsNull()) return NULL;
 
   //Check if the function is set correctly
-  if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
+  if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
 
-  GEOMImpl_ISketcher aCI (aFunction);
+  GEOMImpl_I3DSketcher aCI (aFunction);
 
-  TCollection_AsciiString aCommand((char*) theCommand);
+  TCollection_AsciiString aCommand ((char*) theCommand);
   aCI.SetCommand(aCommand);
 
-  Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
-  if (aRefPlane.IsNull()) return NULL;
-  aCI.SetWorkingPlane( aRefPlane );
+  //Compute the 3D Sketcher value
+  try {
+#if OCC_VERSION_LARGE > 0x06010000
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("3D Sketcher 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);
+  pd << aSketcher << " = geompy.Make3DSketcherCommand(\"" << aCommand.ToCString() << "\")";
+
+  SetErrorCode(OK);
+  return aSketcher;
+}
+
+//=============================================================================
+/*!
+ *  Make3DSketcher
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
+{
+  SetErrorCode(KO);
+
+  //Add a new Sketcher object
+  Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
+
+  //Add a new Sketcher function
+  Handle(GEOM_Function) aFunction =
+    a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), SKETCHER3D_COORDS);
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
+
+  GEOMImpl_I3DSketcher aCI (aFunction);
+
+  int nbOfCoords = 0;
+  std::list<double>::iterator it = theCoordinates.begin();
+  for (; it != theCoordinates.end(); it++)
+    nbOfCoords++;
+
+  Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
+
+  it = theCoordinates.begin();
+  int ind = 1;
+  for (; it != theCoordinates.end(); it++, ind++)
+    aCoordsArray->SetValue(ind, *it);
+
+  aCI.SetCoordinates(aCoordsArray);
 
   //Compute the Sketcher value
   try {
@@ -1272,7 +1315,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
     OCC_CATCH_SIGNALS;
 #endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
-      SetErrorCode("Sketcher driver failed");
+      SetErrorCode("3D Sketcher driver failed");
       return NULL;
     }
   }
@@ -1283,9 +1326,16 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
   }
 
   //Make a Python command
-  GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
-    << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
+  GEOM::TPythonDump pd (aFunction);
+  pd << a3DSketcher << " = geompy.Make3DSketcher([";
+
+  it = theCoordinates.begin();
+  pd << (*it++);
+  while (it != theCoordinates.end()) {
+    pd << ", " << (*it++);
+  }
+  pd << "])";
 
   SetErrorCode(OK);
-  return aSketcher;
+  return a3DSketcher;
 }