Salome HOME
Heal invalid shape after scaling, because different scaling along axes can produce...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ICurvesOperations.cxx
index e6162262b33d77a24b12b8702cc3b8dd8fb4a809..3bd246817d1fa83ce43cf6d7581f97ecf7938cfa 100644 (file)
@@ -15,7 +15,7 @@
 // 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/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include <Standard_Stream.hxx>
 
@@ -44,6 +44,7 @@
 
 #include <TDF_Tool.hxx>
 
+#include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 //=============================================================================
@@ -106,6 +107,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_O
 
   //Compute the Polyline value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Polyline driver failed");
       return NULL;
@@ -170,6 +174,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_
 
   //Compute the Circle value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Circle driver failed");
       return NULL;
@@ -189,6 +196,66 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_
   return aCircle;
 }
 
+//=============================================================================
+/*!
+ *  MakeCircleCenter2Pnt
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
+                                                                      Handle(GEOM_Object) thePnt2,
+                                                                      Handle(GEOM_Object) thePnt3)
+{
+  SetErrorCode(KO);
+
+  if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
+
+  //Add a new Circle object
+  Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
+
+  //Add a new Circle function for creation a circle relatively to center and 2 points
+  Handle(GEOM_Function) aFunction =
+    aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
+
+  GEOMImpl_ICircle aCI (aFunction);
+
+  Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
+  Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
+  Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
+
+  if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
+
+  aCI.SetPoint1(aRefPnt1);
+  aCI.SetPoint2(aRefPnt2);
+  aCI.SetPoint3(aRefPnt3);
+
+  //Compute the Circle value
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Circle 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) << aCircle << " = geompy.MakeCircleCenter2Pnt("
+    << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
+
+  SetErrorCode(OK);
+  return aCircle;
+}
+
 //=============================================================================
 /*!
  *  MakeCirclePntVecR
@@ -199,7 +266,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
 {
   SetErrorCode(KO);
 
-  if (thePnt.IsNull() || theVec.IsNull()) return NULL;
+  // Not set thePnt means origin of global CS,
+  // Not set theVec means Z axis of global CS
+  //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
 
   //Add a new Circle object
   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
@@ -214,17 +283,25 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
 
   GEOMImpl_ICircle aCI (aFunction);
 
-  Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
-  Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
+  if (!thePnt.IsNull()) {
+    Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
+    if (aRefPnt.IsNull()) return NULL;
+    aCI.SetCenter(aRefPnt);
+  }
 
-  if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
+  if (!theVec.IsNull()) {
+    Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
+    if (aRefVec.IsNull()) return NULL;
+    aCI.SetVector(aRefVec);
+  }
 
-  aCI.SetCenter(aRefPnt);
-  aCI.SetVector(aRefVec);
   aCI.SetRadius(theR);
 
   //Compute the Circle value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Circle driver failed");
       return NULL;
@@ -255,7 +332,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
 {
   SetErrorCode(KO);
 
-  if (thePnt.IsNull() || theVec.IsNull()) return NULL;
+  // Not set thePnt means origin of global CS,
+  // Not set theVec means Z axis of global CS
+  //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
 
   //Add a new Ellipse object
   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
@@ -270,18 +349,26 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
 
   GEOMImpl_IEllipse aCI (aFunction);
 
-  Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
-  Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
+  if (!thePnt.IsNull()) {
+    Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
+    if (aRefPnt.IsNull()) return NULL;
+    aCI.SetCenter(aRefPnt);
+  }
 
-  if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
+  if (!theVec.IsNull()) {
+    Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
+    if (aRefVec.IsNull()) return NULL;
+    aCI.SetVector(aRefVec);
+  }
 
-  aCI.SetCenter(aRefPnt);
-  aCI.SetVector(aRefVec);
   aCI.SetRMajor(theRMajor);
   aCI.SetRMinor(theRMinor);
 
   //Compute the Ellipse value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Ellipse driver failed");
       return NULL;
@@ -319,26 +406,30 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) the
 
   //Add a new Circle Arc function
   Handle(GEOM_Function) aFunction =
-    anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
-  if (aFunction.IsNull()) return NULL;
+      anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);  
 
+  if (aFunction.IsNull()) return NULL;
+  
   //Check if the function is set correctly
   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
-
   GEOMImpl_IArc aCI (aFunction);
 
   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
+  
 
   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
 
   aCI.SetPoint1(aRefPnt1);
   aCI.SetPoint2(aRefPnt2);
   aCI.SetPoint3(aRefPnt3);
-
+  
   //Compute the Arc value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Arc driver failed");
       return NULL;
@@ -358,6 +449,66 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) the
   return anArc;
 }
 
+//=============================================================================
+/*!
+ *  MakeArcCenter
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
+                                                               Handle(GEOM_Object) thePnt2,
+                                                               Handle(GEOM_Object) thePnt3,
+                                                               bool                theSense)
+{
+  SetErrorCode(KO);
+  if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
+
+  //Add a new Circle Arc object
+  Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
+
+  //Add a new Circle Arc function
+  Handle(GEOM_Function) aFunction =
+      anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
+
+  GEOMImpl_IArc aCI (aFunction);
+
+  Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
+  Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
+  Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
+
+  if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
+
+  aCI.SetPoint1(aRefPnt1);
+  aCI.SetPoint2(aRefPnt2);
+  aCI.SetPoint3(aRefPnt3);
+  aCI.SetSense(theSense);
+
+  //Compute the Arc value
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+  SetErrorCode("Arc 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) << anArc << " = geompy.MakeArcCenter("
+      << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
+
+  SetErrorCode(OK);
+  return anArc;
+}
+
 //=============================================================================
 /*!
  *  MakeSplineBezier
@@ -396,6 +547,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
 
   //Compute the Spline value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Spline driver failed");
       return NULL;
@@ -460,6 +614,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
 
   //Compute the Spline value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Spline driver failed");
       return NULL;
@@ -491,13 +648,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
  *  MakeSketcher
  */
 //=============================================================================
-Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
-                               (const TCollection_AsciiString& theCommand,
-                                list<double>                   theWorkingPlane)
+Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
+                                                             list<double> theWorkingPlane)
 {
   SetErrorCode(KO);
 
-  if (theCommand.IsEmpty()) return NULL;
+  if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
 
   //Add a new Sketcher object
   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
@@ -512,7 +668,8 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
 
   GEOMImpl_ISketcher aCI (aFunction);
 
-  aCI.SetCommand(theCommand);
+  TCollection_AsciiString aCommand((char*) theCommand);
+  aCI.SetCommand(aCommand);
 
   int ind = 1;
   list<double>::iterator it = theWorkingPlane.begin();
@@ -521,6 +678,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
 
   //Compute the Sketcher value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Sketcher driver failed");
       return NULL;
@@ -534,7 +694,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
 
   //Make a Python command
   GEOM::TPythonDump pd (aFunction);
-  pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
+  pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
 
   it = theWorkingPlane.begin();
   pd << (*it++);
@@ -553,12 +713,12 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
  */
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
-                               (const TCollection_AsciiString& theCommand,
+                               (const char* theCommand,
                                 Handle(GEOM_Object)            theWorkingPlane)
 {
   SetErrorCode(KO);
 
-  if (theCommand.IsEmpty()) return NULL;
+  if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
 
   //Add a new Sketcher object
   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
@@ -572,7 +732,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
 
   GEOMImpl_ISketcher aCI (aFunction);
-  aCI.SetCommand(theCommand);
+
+  TCollection_AsciiString aCommand((char*) theCommand);
+  aCI.SetCommand(aCommand);
 
   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
   if (aRefPlane.IsNull()) return NULL;
@@ -580,6 +742,9 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
 
   //Compute the Sketcher value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Sketcher driver failed");
       return NULL;
@@ -593,7 +758,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
 
   //Make a Python command
   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
-    << theCommand.ToCString() << "\", " << theWorkingPlane << " )";
+    << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
 
   SetErrorCode(OK);
   return aSketcher;