Back to index

salome-geom  6.5.0
GEOMImpl_ICurvesOperations.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifdef WNT
00024 // E.A. : On windows with python 2.6, there is a conflict
00025 // E.A. : between pymath.h and Standard_math.h which define
00026 // E.A. : some same symbols : acosh, asinh, ...
00027 #include <Standard_math.hxx>
00028 #include <pymath.h>
00029 #endif
00030 
00031 #include <Python.h>
00032 #include <structmember.h>
00033 
00034 #ifdef HAVE_FINITE
00035 #undef HAVE_FINITE
00036 #endif
00037 #include <Standard_Stream.hxx>
00038 
00039 #include <GEOMImpl_ICurvesOperations.hxx>
00040 #include <GEOMImpl_Types.hxx>
00041 
00042 #include <GEOM_Function.hxx>
00043 #include <GEOM_PythonDump.hxx>
00044 
00045 #include <GEOMImpl_PolylineDriver.hxx>
00046 #include <GEOMImpl_CircleDriver.hxx>
00047 #include <GEOMImpl_SplineDriver.hxx>
00048 #include <GEOMImpl_EllipseDriver.hxx>
00049 #include <GEOMImpl_ArcDriver.hxx>
00050 #include <GEOMImpl_SketcherDriver.hxx>
00051 #include <GEOMImpl_3DSketcherDriver.hxx>
00052 
00053 #include <GEOMImpl_IPolyline.hxx>
00054 #include <GEOMImpl_ICircle.hxx>
00055 #include <GEOMImpl_ISpline.hxx>
00056 #include <GEOMImpl_IEllipse.hxx>
00057 #include <GEOMImpl_IArc.hxx>
00058 #include <GEOMImpl_ISketcher.hxx>
00059 #include <GEOMImpl_I3DSketcher.hxx>
00060 
00061 #include <Basics_OCCTVersion.hxx>
00062 
00063 #include "utilities.h"
00064 
00065 #include <TDF_Tool.hxx>
00066 #include <TColStd_HArray1OfReal.hxx>
00067 
00068 #include <Standard_Failure.hxx>
00069 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
00070 
00071 
00072 /* ==================================
00073  * ===========  PYTHON ==============
00074  * ==================================*/
00075 
00076 typedef struct {
00077   PyObject_HEAD
00078   int softspace;
00079   std::string *out;
00080   } PyStdOut;
00081 
00082 static void
00083 PyStdOut_dealloc(PyStdOut *self)
00084 {
00085   PyObject_Del(self);
00086 }
00087 
00088 static PyObject *
00089 PyStdOut_write(PyStdOut *self, PyObject *args)
00090 {
00091   char *c;
00092   int l;
00093   if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
00094     return NULL;
00095 
00096   //std::cerr << c ;
00097   *(self->out)=*(self->out)+c;
00098 
00099   Py_INCREF(Py_None);
00100   return Py_None;
00101 }
00102 
00103 static PyMethodDef PyStdOut_methods[] = {
00104   {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
00105     PyDoc_STR("write(string) -> None")},
00106   {NULL,    NULL}   /* sentinel */
00107 };
00108 
00109 static PyMemberDef PyStdOut_memberlist[] = {
00110   {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
00111    (char*)"flag indicating that a space needs to be printed; used by print"},
00112   {NULL} /* Sentinel */
00113 };
00114 
00115 static PyTypeObject PyStdOut_Type = {
00116   /* The ob_type field must be initialized in the module init function
00117    * to be portable to Windows without using C++. */
00118   PyObject_HEAD_INIT(NULL)
00119   0,                            /*ob_size*/
00120   "PyOut",                      /*tp_name*/
00121   sizeof(PyStdOut),             /*tp_basicsize*/
00122   0,                            /*tp_itemsize*/
00123   /* methods */
00124   (destructor)PyStdOut_dealloc, /*tp_dealloc*/
00125   0,                            /*tp_print*/
00126   0,                            /*tp_getattr*/
00127   0,                            /*tp_setattr*/
00128   0,                            /*tp_compare*/
00129   0,                            /*tp_repr*/
00130   0,                            /*tp_as_number*/
00131   0,                            /*tp_as_sequence*/
00132   0,                            /*tp_as_mapping*/
00133   0,                            /*tp_hash*/
00134   0,                            /*tp_call*/
00135   0,                            /*tp_str*/
00136   PyObject_GenericGetAttr,      /*tp_getattro*/
00137   /* softspace is writable:  we must supply tp_setattro */
00138   PyObject_GenericSetAttr,      /* tp_setattro */
00139   0,                            /*tp_as_buffer*/
00140   Py_TPFLAGS_DEFAULT,           /*tp_flags*/
00141   0,                            /*tp_doc*/
00142   0,                            /*tp_traverse*/
00143   0,                            /*tp_clear*/
00144   0,                            /*tp_richcompare*/
00145   0,                            /*tp_weaklistoffset*/
00146   0,                            /*tp_iter*/
00147   0,                            /*tp_iternext*/
00148   PyStdOut_methods,             /*tp_methods*/
00149   PyStdOut_memberlist,          /*tp_members*/
00150   0,                            /*tp_getset*/
00151   0,                            /*tp_base*/
00152   0,                            /*tp_dict*/
00153   0,                            /*tp_descr_get*/
00154   0,                            /*tp_descr_set*/
00155   0,                            /*tp_dictoffset*/
00156   0,                            /*tp_init*/
00157   0,                            /*tp_alloc*/
00158   0,                            /*tp_new*/
00159   0,                            /*tp_free*/
00160   0,                            /*tp_is_gc*/
00161 };
00162 
00163 PyObject * newPyStdOut( std::string& out )
00164 {
00165   PyStdOut *self;
00166   self = PyObject_New(PyStdOut, &PyStdOut_Type);
00167   if (self == NULL)
00168     return NULL;
00169   self->softspace = 0;
00170   self->out=&out;
00171   return (PyObject*)self;
00172 }
00173 
00174 
00176 //=============================================================================
00180 //=============================================================================
00181 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
00182 : GEOM_IOperations(theEngine, theDocID)
00183 {
00184   MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
00185 }
00186 
00187 //=============================================================================
00191 //=============================================================================
00192 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
00193 {
00194   MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
00195 }
00196 
00197 
00198 //=============================================================================
00202 //=============================================================================
00203 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
00204                                                                     Handle(GEOM_Object) thePnt2,
00205                                                                     Handle(GEOM_Object) thePnt3)
00206 {
00207   SetErrorCode(KO);
00208 
00209   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
00210 
00211   //Add a new Circle object
00212   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
00213 
00214   //Add a new Circle function for creation a circle relatively to three points
00215   Handle(GEOM_Function) aFunction =
00216     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
00217   if (aFunction.IsNull()) return NULL;
00218 
00219   //Check if the function is set correctly
00220   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
00221 
00222   GEOMImpl_ICircle aCI (aFunction);
00223 
00224   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
00225   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
00226   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
00227 
00228   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
00229 
00230   aCI.SetPoint1(aRefPnt1);
00231   aCI.SetPoint2(aRefPnt2);
00232   aCI.SetPoint3(aRefPnt3);
00233 
00234   //Compute the Circle value
00235   try {
00236 #if OCC_VERSION_LARGE > 0x06010000
00237     OCC_CATCH_SIGNALS;
00238 #endif
00239     if (!GetSolver()->ComputeFunction(aFunction)) {
00240       SetErrorCode("Circle driver failed");
00241       return NULL;
00242     }
00243   }
00244   catch (Standard_Failure) {
00245     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00246     SetErrorCode(aFail->GetMessageString());
00247     return NULL;
00248   }
00249 
00250   //Make a Python command
00251   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
00252     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
00253 
00254   SetErrorCode(OK);
00255   return aCircle;
00256 }
00257 
00258 //=============================================================================
00262 //=============================================================================
00263 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
00264                                                                       Handle(GEOM_Object) thePnt2,
00265                                                                       Handle(GEOM_Object) thePnt3)
00266 {
00267   SetErrorCode(KO);
00268 
00269   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
00270 
00271   //Add a new Circle object
00272   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
00273 
00274   //Add a new Circle function for creation a circle relatively to center and 2 points
00275   Handle(GEOM_Function) aFunction =
00276     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
00277   if (aFunction.IsNull()) return NULL;
00278 
00279   //Check if the function is set correctly
00280   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
00281 
00282   GEOMImpl_ICircle aCI (aFunction);
00283 
00284   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
00285   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
00286   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
00287 
00288   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
00289 
00290   aCI.SetPoint1(aRefPnt1);
00291   aCI.SetPoint2(aRefPnt2);
00292   aCI.SetPoint3(aRefPnt3);
00293 
00294   //Compute the Circle value
00295   try {
00296 #if OCC_VERSION_LARGE > 0x06010000
00297     OCC_CATCH_SIGNALS;
00298 #endif
00299     if (!GetSolver()->ComputeFunction(aFunction)) {
00300       SetErrorCode("Circle driver failed");
00301       return NULL;
00302     }
00303   }
00304   catch (Standard_Failure) {
00305     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00306     SetErrorCode(aFail->GetMessageString());
00307     return NULL;
00308   }
00309 
00310   //Make a Python command
00311   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
00312     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
00313 
00314   SetErrorCode(OK);
00315   return aCircle;
00316 }
00317 
00318 //=============================================================================
00322 //=============================================================================
00323 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
00324        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
00325 {
00326   SetErrorCode(KO);
00327 
00328   // Not set thePnt means origin of global CS,
00329   // Not set theVec means Z axis of global CS
00330   //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
00331 
00332   //Add a new Circle object
00333   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
00334 
00335   //Add a new Circle function for creation a circle relatively to point and vector
00336   Handle(GEOM_Function) aFunction =
00337     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
00338   if (aFunction.IsNull()) return NULL;
00339 
00340   //Check if the function is set correctly
00341   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
00342 
00343   GEOMImpl_ICircle aCI (aFunction);
00344 
00345   if (!thePnt.IsNull()) {
00346     Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
00347     if (aRefPnt.IsNull()) return NULL;
00348     aCI.SetCenter(aRefPnt);
00349   }
00350 
00351   if (!theVec.IsNull()) {
00352     Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
00353     if (aRefVec.IsNull()) return NULL;
00354     aCI.SetVector(aRefVec);
00355   }
00356 
00357   aCI.SetRadius(theR);
00358 
00359   //Compute the Circle value
00360   try {
00361 #if OCC_VERSION_LARGE > 0x06010000
00362     OCC_CATCH_SIGNALS;
00363 #endif
00364     if (!GetSolver()->ComputeFunction(aFunction)) {
00365       SetErrorCode("Circle driver failed");
00366       return NULL;
00367     }
00368   }
00369   catch (Standard_Failure) {
00370     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00371     SetErrorCode(aFail->GetMessageString());
00372     return NULL;
00373   }
00374 
00375   //Make a Python command
00376   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
00377     << thePnt << ", " << theVec << ", " << theR << ")";
00378 
00379   SetErrorCode(OK);
00380   return aCircle;
00381 }
00382 
00383 //=============================================================================
00387 //=============================================================================
00388 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
00389                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
00390                         double theRMajor, double theRMinor,
00391                         Handle(GEOM_Object) theVecMaj)
00392 {
00393   SetErrorCode(KO);
00394 
00395   // Not set thePnt means origin of global CS,
00396   // Not set theVec means Z axis of global CS
00397   // Not set theVecMaj means X axis of global CS
00398   //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
00399 
00400   //Add a new Ellipse object
00401   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
00402 
00403   //Add a new Ellipse function
00404   Handle(GEOM_Function) aFunction =
00405     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
00406   if (aFunction.IsNull()) return NULL;
00407 
00408   //Check if the function is set correctly
00409   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
00410 
00411   GEOMImpl_IEllipse aCI (aFunction);
00412 
00413   if (!thePnt.IsNull()) {
00414     Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
00415     if (aRefPnt.IsNull()) return NULL;
00416     aCI.SetCenter(aRefPnt);
00417   }
00418 
00419   if (!theVec.IsNull()) {
00420     Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
00421     if (aRefVec.IsNull()) return NULL;
00422     aCI.SetVector(aRefVec);
00423   }
00424 
00425   aCI.SetRMajor(theRMajor);
00426   aCI.SetRMinor(theRMinor);
00427 
00428   if (!theVecMaj.IsNull()) {
00429     Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
00430     if (aRefVecMaj.IsNull()) return NULL;
00431     aCI.SetVectorMajor(aRefVecMaj);
00432   }
00433 
00434   //Compute the Ellipse value
00435   try {
00436 #if OCC_VERSION_LARGE > 0x06010000
00437     OCC_CATCH_SIGNALS;
00438 #endif
00439     if (!GetSolver()->ComputeFunction(aFunction)) {
00440       SetErrorCode("Ellipse driver failed");
00441       return NULL;
00442     }
00443   }
00444   catch (Standard_Failure) {
00445     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00446     SetErrorCode(aFail->GetMessageString());
00447     return NULL;
00448   }
00449 
00450   //Make a Python command
00451   if (!theVecMaj.IsNull()) {
00452     GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
00453                                  << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
00454                                  << ", " << theVecMaj << ")";
00455   }
00456   else {
00457     GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
00458                                  << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
00459   }
00460 
00461   SetErrorCode(OK);
00462   return anEll;
00463 }
00464 
00465 //=============================================================================
00469 //=============================================================================
00470 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
00471                                                          Handle(GEOM_Object) thePnt2,
00472                                                          Handle(GEOM_Object) thePnt3)
00473 {
00474   SetErrorCode(KO);
00475 
00476   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
00477 
00478   //Add a new Circle Arc object
00479   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
00480 
00481   //Add a new Circle Arc function
00482   Handle(GEOM_Function) aFunction =
00483       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);
00484 
00485   if (aFunction.IsNull()) return NULL;
00486 
00487   //Check if the function is set correctly
00488   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
00489   GEOMImpl_IArc aCI (aFunction);
00490 
00491   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
00492   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
00493   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
00494 
00495   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
00496 
00497   aCI.SetPoint1(aRefPnt1);
00498   aCI.SetPoint2(aRefPnt2);
00499   aCI.SetPoint3(aRefPnt3);
00500 
00501   //Compute the Arc value
00502   try {
00503 #if OCC_VERSION_LARGE > 0x06010000
00504     OCC_CATCH_SIGNALS;
00505 #endif
00506     if (!GetSolver()->ComputeFunction(aFunction)) {
00507       SetErrorCode("Arc driver failed");
00508       return NULL;
00509     }
00510   }
00511   catch (Standard_Failure) {
00512     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00513     SetErrorCode(aFail->GetMessageString());
00514     return NULL;
00515   }
00516 
00517   //Make a Python command
00518   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
00519     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
00520 
00521   SetErrorCode(OK);
00522   return anArc;
00523 }
00524 
00525 //=============================================================================
00529 //=============================================================================
00530 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
00531                                                                Handle(GEOM_Object) thePnt2,
00532                                                                Handle(GEOM_Object) thePnt3,
00533                                                                bool                theSense)
00534 {
00535   SetErrorCode(KO);
00536   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
00537 
00538   //Add a new Circle Arc object
00539   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
00540 
00541   //Add a new Circle Arc function
00542   Handle(GEOM_Function) aFunction =
00543       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
00544   if (aFunction.IsNull()) return NULL;
00545 
00546   //Check if the function is set correctly
00547   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
00548 
00549   GEOMImpl_IArc aCI (aFunction);
00550 
00551   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
00552   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
00553   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
00554 
00555   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
00556 
00557   aCI.SetPoint1(aRefPnt1);
00558   aCI.SetPoint2(aRefPnt2);
00559   aCI.SetPoint3(aRefPnt3);
00560   aCI.SetSense(theSense);
00561 
00562   //Compute the Arc value
00563   try {
00564 #if OCC_VERSION_LARGE > 0x06010000
00565     OCC_CATCH_SIGNALS;
00566 #endif
00567     if (!GetSolver()->ComputeFunction(aFunction)) {
00568   SetErrorCode("Arc driver failed");
00569   return NULL;
00570     }
00571   }
00572   catch (Standard_Failure) {
00573     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00574     SetErrorCode(aFail->GetMessageString());
00575     return NULL;
00576   }
00577   //Make a Python command
00578   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
00579       << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
00580 
00581   SetErrorCode(OK);
00582   return anArc;
00583 }
00584 
00585 //=============================================================================
00589 //=============================================================================
00590 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
00591                                                                   Handle(GEOM_Object) thePnt2,
00592                                                                   Handle(GEOM_Object) thePnt3)
00593 {
00594   SetErrorCode(KO);
00595 
00596   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
00597 
00598   //Add a new Circle Arc object
00599   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
00600 
00601   //Add a new Circle Arc function
00602   Handle(GEOM_Function) aFunction =
00603       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
00604 
00605   if (aFunction.IsNull()) return NULL;
00606 
00607   //Check if the function is set correctly
00608   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
00609   GEOMImpl_IArc aCI (aFunction);
00610 
00611   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
00612   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
00613   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
00614 
00615   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
00616 
00617   aCI.SetPoint1(aRefPnt1);
00618   aCI.SetPoint2(aRefPnt2);
00619   aCI.SetPoint3(aRefPnt3);
00620 
00621   //Compute the Arc value
00622   try {
00623 #if OCC_VERSION_LARGE > 0x06010000
00624     OCC_CATCH_SIGNALS;
00625 #endif
00626     if (!GetSolver()->ComputeFunction(aFunction)) {
00627       SetErrorCode("Arc driver failed");
00628       return NULL;
00629     }
00630   }
00631   catch (Standard_Failure) {
00632     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00633     SetErrorCode(aFail->GetMessageString());
00634     return NULL;
00635   }
00636 
00637   //Make a Python command
00638   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
00639     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
00640 
00641   SetErrorCode(OK);
00642   return anArc;
00643 }
00644 
00645 //=============================================================================
00649 //=============================================================================
00650 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
00651                                                               bool theIsClosed)
00652 {
00653   SetErrorCode(KO);
00654 
00655   //Add a new Polyline object
00656   Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
00657 
00658   //Add a new Polyline function for creation a polyline relatively to points set
00659   Handle(GEOM_Function) aFunction =
00660     aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
00661   if (aFunction.IsNull()) return NULL;
00662 
00663   //Check if the function is set correctly
00664   if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
00665 
00666   GEOMImpl_IPolyline aCI (aFunction);
00667 
00668   int aLen = thePoints.size();
00669   aCI.SetLength(aLen);
00670   aCI.SetConstructorType(POINT_CONSTRUCTOR);
00671 
00672   int ind = 1;
00673   std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
00674   for (; it != thePoints.end(); it++, ind++) {
00675     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
00676     if (aRefPnt.IsNull()) {
00677       SetErrorCode("NULL point for Polyline");
00678       return NULL;
00679     }
00680     aCI.SetPoint(ind, aRefPnt);
00681   }
00682 
00683   aCI.SetIsClosed(theIsClosed);
00684 
00685   //Compute the Polyline value
00686   try {
00687 #if OCC_VERSION_LARGE > 0x06010000
00688     OCC_CATCH_SIGNALS;
00689 #endif
00690     if (!GetSolver()->ComputeFunction(aFunction)) {
00691       SetErrorCode("Polyline driver failed");
00692       return NULL;
00693     }
00694   }
00695   catch (Standard_Failure) {
00696     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00697     SetErrorCode(aFail->GetMessageString());
00698     return NULL;
00699   }
00700 
00701   //Make a Python command
00702   GEOM::TPythonDump pd (aFunction);
00703   pd << aPolyline << " = geompy.MakePolyline([";
00704 
00705   it = thePoints.begin();
00706   pd << (*it++);
00707   while (it != thePoints.end()) {
00708     pd << ", " << (*it++);
00709   }
00710   pd << "], " << theIsClosed << ")";
00711 
00712   SetErrorCode(OK);
00713   return aPolyline;
00714 }
00715 
00716 //=============================================================================
00720 //=============================================================================
00721 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
00722                                           (std::list<Handle(GEOM_Object)> thePoints,
00723                                            bool theIsClosed)
00724 {
00725   SetErrorCode(KO);
00726 
00727   //Add a new Spline object
00728   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
00729 
00730   //Add a new Spline function for creation a bezier curve relatively to points set
00731   Handle(GEOM_Function) aFunction =
00732     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
00733   if (aFunction.IsNull()) return NULL;
00734 
00735   //Check if the function is set correctly
00736   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
00737 
00738   GEOMImpl_ISpline aCI (aFunction);
00739 
00740   int aLen = thePoints.size();
00741   aCI.SetLength(aLen);
00742   aCI.SetConstructorType(POINT_CONSTRUCTOR);
00743 
00744   int ind = 1;
00745   std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
00746   for (; it != thePoints.end(); it++, ind++) {
00747     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
00748 
00749     if (aRefPnt.IsNull()) return NULL;
00750 
00751     aCI.SetPoint(ind, aRefPnt);
00752   }
00753 
00754   aCI.SetIsClosed(theIsClosed);
00755 
00756   //Compute the Spline value
00757   try {
00758 #if OCC_VERSION_LARGE > 0x06010000
00759     OCC_CATCH_SIGNALS;
00760 #endif
00761     if (!GetSolver()->ComputeFunction(aFunction)) {
00762       SetErrorCode("Spline driver failed");
00763       return NULL;
00764     }
00765   }
00766   catch (Standard_Failure) {
00767     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00768     SetErrorCode(aFail->GetMessageString());
00769     return NULL;
00770   }
00771 
00772   //Make a Python command
00773   GEOM::TPythonDump pd (aFunction);
00774   pd << aSpline << " = geompy.MakeBezier([";
00775 
00776   it = thePoints.begin();
00777   pd << (*it++);
00778   while (it != thePoints.end()) {
00779     pd << ", " << (*it++);
00780   }
00781   pd << "], " << theIsClosed << ")";
00782 
00783   SetErrorCode(OK);
00784   return aSpline;
00785 }
00786 
00787 //=============================================================================
00791 //=============================================================================
00792 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
00793                                           (std::list<Handle(GEOM_Object)> thePoints,
00794                                            bool theIsClosed,
00795                                            bool theDoReordering)
00796 {
00797   SetErrorCode(KO);
00798 
00799   //Add a new Spline object
00800   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
00801 
00802   //Add a new Spline function for creation a bezier curve relatively to points set
00803   Handle(GEOM_Function) aFunction =
00804     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
00805   if (aFunction.IsNull()) return NULL;
00806 
00807   //Check if the function is set correctly
00808   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
00809 
00810   GEOMImpl_ISpline aCI (aFunction);
00811 
00812   int aLen = thePoints.size();
00813   aCI.SetConstructorType(POINT_CONSTRUCTOR);
00814   aCI.SetLength(aLen);
00815 
00816   int ind = 1;
00817   std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
00818   for (; it != thePoints.end(); it++, ind++) {
00819     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
00820 
00821     if (aRefPnt.IsNull()) return NULL;
00822 
00823     aCI.SetPoint(ind, aRefPnt);
00824   }
00825 
00826   aCI.SetIsClosed(theIsClosed);
00827   aCI.SetDoReordering(theDoReordering);
00828 
00829   //Compute the Spline value
00830   try {
00831 #if OCC_VERSION_LARGE > 0x06010000
00832     OCC_CATCH_SIGNALS;
00833 #endif
00834     if (!GetSolver()->ComputeFunction(aFunction)) {
00835       SetErrorCode("Spline driver failed");
00836       return NULL;
00837     }
00838   }
00839   catch (Standard_Failure) {
00840     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00841     SetErrorCode(aFail->GetMessageString());
00842     return NULL;
00843   }
00844 
00845   //Make a Python command
00846   GEOM::TPythonDump pd (aFunction);
00847   pd << aSpline << " = geompy.MakeInterpol([";
00848 
00849   it = thePoints.begin();
00850   pd << (*it++);
00851   while (it != thePoints.end()) {
00852     pd << ", " << (*it++);
00853   }
00854   pd << "], " << theIsClosed << ", " << theDoReordering << ")";
00855 
00856   SetErrorCode(OK);
00857   return aSpline;
00858 }
00859 
00860 //=============================================================================
00864 //=============================================================================
00865 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric
00866              (const char* thexExpr, const char* theyExpr, const char* thezExpr,
00867               double theParamMin, double theParamMax, double theParamStep,
00868               CurveType theCurveType, 
00869               int theParamNbStep, bool theNewMethod)
00870 {
00871   TCollection_AsciiString aPyScript;
00872   aPyScript +="from math import *                                          \n";
00873   aPyScript +="def X(t):                                                   \n";
00874   aPyScript +="    return ";
00875   aPyScript += thexExpr;
00876   aPyScript += "\n";
00877   aPyScript +="def Y(t):                                                   \n";
00878   aPyScript +="    return ";
00879   aPyScript += theyExpr;
00880   aPyScript += "\n";
00881 
00882   aPyScript +="def Z(t):                                                   \n";
00883   aPyScript +="    return ";
00884   aPyScript += thezExpr;
00885   aPyScript += "\n";
00886 
00887   if (theNewMethod)
00888   {
00889     aPyScript +="def coordCalculator(tmin, tmax, nstep):                     \n";
00890     aPyScript +="   coords = []                                              \n";
00891     aPyScript +="   tstep  = (tmax - tmin) / nstep                           \n";
00892     aPyScript +="   n = 0                                                    \n";
00893     aPyScript +="   while n <= nstep :                                       \n";
00894     aPyScript +="      t = tmin + n*tstep                                    \n";
00895     aPyScript +="      coords.append([X(t), Y(t), Z(t)])                     \n";
00896     aPyScript +="      n = n+1                                               \n";
00897     aPyScript +="   return coords                                            \n";
00898   }
00899   else
00900   {
00901     aPyScript +="def coordCalculator(tmin, tmax, tstep):                      \n";
00902     aPyScript +="   coords = []                                              \n";
00903     aPyScript +="   while tmin <= tmax :                                     \n";
00904     aPyScript +="      coords.append([X(tmin), Y(tmin), Z(tmin)])            \n";
00905     aPyScript +="      tmin = tmin + tstep                                   \n";
00906     aPyScript +="   return coords                                            \n";
00907   }
00908 
00909   SetErrorCode(KO);
00910 
00911   if(theParamMin >= theParamMax) {
00912     SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
00913     return NULL;
00914   }
00915 
00916   if(!theNewMethod && theParamStep <= 0.0) {
00917     SetErrorCode("Value of the step must be positive !!!");
00918     return NULL;
00919   }
00920   else if(theNewMethod && theParamNbStep < 0) {
00921     SetErrorCode("The number of steps must be positive !!!");
00922     return NULL;
00923   }
00924 
00925   /* Initialize the Python interpreter */
00926   if (! Py_IsInitialized()) {
00927     SetErrorCode("Python interpreter is not initialized !!! ");
00928     return NULL;
00929   }
00930 
00931   PyGILState_STATE gstate;
00932   gstate = PyGILState_Ensure();
00933 
00934   PyObject* main_mod = PyImport_AddModule("__main__");
00935   PyObject* main_dict = PyModule_GetDict(main_mod);
00936 
00937   PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
00938 
00939   if (obj == NULL) {
00940     SetErrorCode("Error during executing of python script !!!");
00941     PyErr_Print();
00942     PyGILState_Release(gstate);
00943     return NULL;
00944   } else {
00945     Py_DECREF(obj);
00946   }
00947 
00948   PyObject * func = NULL;
00949   func = PyObject_GetAttrString(main_mod, "coordCalculator");
00950 
00951   if (func == NULL){
00952     SetErrorCode("Can't get function from python module !!!");
00953     PyGILState_Release(gstate);
00954     return NULL;
00955   }
00956 
00957   PyObject* coords;
00958   if (theNewMethod)
00959     coords = PyObject_CallFunction(func,(char*)"(d, d, i)", theParamMin, theParamMax, theParamNbStep );
00960   else
00961     coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
00962   
00963   PyObject* new_stderr = NULL;
00964 
00965   if (coords == NULL){
00966     fflush(stderr);
00967     std::string err_description="";
00968     new_stderr = newPyStdOut(err_description);
00969     PySys_SetObject((char*)"stderr", new_stderr);
00970     PyErr_Print();
00971     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
00972     Py_DECREF(new_stderr);
00973     MESSAGE("Can't evaluate coordCalculator()" << " error is " << err_description);
00974     SetErrorCode("Can't evaluate the expressions, please check them !!!");
00975     PyGILState_Release(gstate);
00976     return NULL;
00977   }
00978 
00979   Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3);
00980 
00981   if(PyList_Size( coords ) <= 0) {
00982     SetErrorCode("Empty list of the points, please check input parameters !!!");
00983     return NULL;
00984   }
00985 
00986   int k=1;
00987   for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
00988     PyObject* coord = PyList_GetItem( coords, i );
00989     if (coord != NULL) {
00990       for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
00991         PyObject* item = PyList_GetItem(coord, j);
00992         aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
00993         k++;
00994       }
00995     }
00996   }
00997 
00998   Py_DECREF(coords);
00999 
01000   PyGILState_Release(gstate);
01001 
01002   Handle(GEOM_Object) aCurve;
01003   Handle(GEOM_Function) aFunction;
01004   TCollection_AsciiString aCurveType;
01005 
01006   switch(theCurveType) {
01007   case Polyline: {
01008     //Add a new Polyline object
01009     aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
01010 
01011     //Add a new Polyline function for creation a polyline relatively to points set
01012     aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
01013     if (aFunction.IsNull()) return NULL;
01014 
01015     //Check if the function is set correctly
01016     if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
01017 
01018     GEOMImpl_IPolyline aCI (aFunction);
01019 
01020     aCI.SetLength(PyList_Size( coords ));
01021     aCI.SetConstructorType(COORD_CONSTRUCTOR);
01022     aCI.SetIsClosed(false);
01023     aCI.SetCoordinates(aCoordsArray);
01024     aCurveType = "geompy.GEOM.Polyline";
01025     break;
01026   }
01027   case Bezier: {
01028     //Add a new Spline object
01029     aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
01030     //Add a new Spline function for creation a bezier curve relatively to points set
01031     aFunction =
01032       aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
01033     if (aFunction.IsNull()) return NULL;
01034 
01035     //Check if the function is set correctly
01036     if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
01037 
01038     GEOMImpl_ISpline aCI (aFunction);
01039 
01040     aCI.SetLength(PyList_Size( coords ));
01041     aCI.SetConstructorType(COORD_CONSTRUCTOR);
01042     aCI.SetIsClosed(false);
01043     aCI.SetCoordinates(aCoordsArray);
01044     aCurveType = "geompy.GEOM.Bezier";
01045     break;
01046   }
01047   case Interpolation: {
01048     //Add a new Spline object
01049     aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
01050 
01051     //Add a new Spline function for creation a bezier curve relatively to points set
01052     aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
01053     if (aFunction.IsNull()) return NULL;
01054 
01055     //Check if the function is set correctly
01056     if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
01057 
01058     GEOMImpl_ISpline aCI (aFunction);
01059     aCI.SetConstructorType(COORD_CONSTRUCTOR);
01060     aCI.SetLength(PyList_Size( coords ));
01061     aCI.SetIsClosed(false);
01062     aCI.SetDoReordering(false);
01063     aCI.SetCoordinates(aCoordsArray);
01064     aCurveType = "geompy.GEOM.Interpolation";
01065     break;
01066   }
01067   }
01068 
01069   //Compute the Curve value
01070   try {
01071 #if OCC_VERSION_LARGE > 0x06010000
01072     OCC_CATCH_SIGNALS;
01073 #endif
01074     if (!GetSolver()->ComputeFunction(aFunction)) {
01075       SetErrorCode("Curve driver failed !!!");
01076       return NULL;
01077     }
01078   }
01079   catch (Standard_Failure) {
01080     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
01081     SetErrorCode(aFail->GetMessageString());
01082     return NULL;
01083   }
01084 
01085   //Make a Python command
01086   GEOM::TPythonDump pd (aFunction);
01087   pd << aCurve << " = geompy.MakeCurveParametric(";
01088   pd << "\"" << thexExpr << "\", ";
01089   pd << "\"" << theyExpr << "\", ";
01090   pd << "\"" << thezExpr << "\", ";
01091 
01092   pd << theParamMin <<", ";
01093   pd << theParamMax <<", ";
01094   if (theNewMethod)
01095     pd << theParamNbStep <<", ";
01096   else
01097     pd << theParamStep <<", ";
01098   pd << aCurveType.ToCString() <<", ";
01099   pd << theNewMethod <<")";
01100 
01101   SetErrorCode(OK);
01102   return aCurve;
01103 }
01104 
01105 //=============================================================================
01109 //=============================================================================
01110 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
01111                                                               std::list<double> theWorkingPlane)
01112 {
01113   SetErrorCode(KO);
01114 
01115   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
01116 
01117   //Add a new Sketcher object
01118   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
01119 
01120   //Add a new Sketcher function
01121   Handle(GEOM_Function) aFunction =
01122     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
01123   if (aFunction.IsNull()) return NULL;
01124 
01125   //Check if the function is set correctly
01126   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
01127 
01128   GEOMImpl_ISketcher aCI (aFunction);
01129 
01130   TCollection_AsciiString aCommand((char*) theCommand);
01131   aCI.SetCommand(aCommand);
01132 
01133   int ind = 1;
01134   std::list<double>::iterator it = theWorkingPlane.begin();
01135   for (; it != theWorkingPlane.end(); it++, ind++)
01136     aCI.SetWorkingPlane(ind, *it);
01137 
01138   //Compute the Sketcher value
01139   try {
01140 #if OCC_VERSION_LARGE > 0x06010000
01141     OCC_CATCH_SIGNALS;
01142 #endif
01143     if (!GetSolver()->ComputeFunction(aFunction)) {
01144       SetErrorCode("Sketcher driver failed");
01145       return NULL;
01146     }
01147   }
01148   catch (Standard_Failure) {
01149     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
01150     SetErrorCode(aFail->GetMessageString());
01151     return NULL;
01152   }
01153 
01154   //Make a Python command
01155   GEOM::TPythonDump pd (aFunction);
01156   pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
01157 
01158   it = theWorkingPlane.begin();
01159   pd << (*it++);
01160   while (it != theWorkingPlane.end()) {
01161     pd << ", " << (*it++);
01162   }
01163   pd << "])";
01164 
01165   SetErrorCode(OK);
01166   return aSketcher;
01167 }
01168 
01169 //=============================================================================
01173 //=============================================================================
01174 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
01175 {
01176   SetErrorCode(KO);
01177 
01178   //Add a new Sketcher object
01179   Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
01180 
01181   //Add a new Sketcher function
01182   Handle(GEOM_Function) aFunction =
01183     a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
01184   if (aFunction.IsNull()) return NULL;
01185 
01186   //Check if the function is set correctly
01187   if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
01188 
01189   GEOMImpl_I3DSketcher aCI (aFunction);
01190 
01191   int nbOfCoords = 0;
01192   std::list<double>::iterator it = theCoordinates.begin();
01193   for (; it != theCoordinates.end(); it++)
01194     nbOfCoords++;
01195 
01196   Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
01197 
01198   it = theCoordinates.begin();
01199   int ind = 1;
01200   for (; it != theCoordinates.end(); it++, ind++)
01201     aCoordsArray->SetValue(ind, *it);
01202 
01203   aCI.SetCoordinates(aCoordsArray);
01204 
01205   //Compute the Sketcher value
01206   try {
01207 #if OCC_VERSION_LARGE > 0x06010000
01208     OCC_CATCH_SIGNALS;
01209 #endif
01210     if (!GetSolver()->ComputeFunction(aFunction)) {
01211       SetErrorCode("3D Sketcher driver failed");
01212       return NULL;
01213     }
01214   }
01215   catch (Standard_Failure) {
01216     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
01217     SetErrorCode(aFail->GetMessageString());
01218     return NULL;
01219   }
01220 
01221   //Make a Python command
01222   GEOM::TPythonDump pd (aFunction);
01223   pd << a3DSketcher << " = geompy.Make3DSketcher([";
01224 
01225   it = theCoordinates.begin();
01226   pd << (*it++);
01227   while (it != theCoordinates.end()) {
01228     pd << ", " << (*it++);
01229   }
01230   pd << "])";
01231 
01232   SetErrorCode(OK);
01233   return a3DSketcher;
01234 }
01235 
01236 //=============================================================================
01240 //=============================================================================
01241 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
01242                                (const char* theCommand,
01243                                 Handle(GEOM_Object)            theWorkingPlane)
01244 {
01245   SetErrorCode(KO);
01246 
01247   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
01248 
01249   //Add a new Sketcher object
01250   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
01251 
01252   //Add a new Sketcher function
01253   Handle(GEOM_Function) aFunction =
01254     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
01255   if (aFunction.IsNull()) return NULL;
01256 
01257   //Check if the function is set correctly
01258   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
01259 
01260   GEOMImpl_ISketcher aCI (aFunction);
01261 
01262   TCollection_AsciiString aCommand((char*) theCommand);
01263   aCI.SetCommand(aCommand);
01264 
01265   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
01266   if (aRefPlane.IsNull()) return NULL;
01267   aCI.SetWorkingPlane( aRefPlane );
01268 
01269   //Compute the Sketcher value
01270   try {
01271 #if OCC_VERSION_LARGE > 0x06010000
01272     OCC_CATCH_SIGNALS;
01273 #endif
01274     if (!GetSolver()->ComputeFunction(aFunction)) {
01275       SetErrorCode("Sketcher driver failed");
01276       return NULL;
01277     }
01278   }
01279   catch (Standard_Failure) {
01280     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
01281     SetErrorCode(aFail->GetMessageString());
01282     return NULL;
01283   }
01284 
01285   //Make a Python command
01286   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
01287     << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
01288 
01289   SetErrorCode(OK);
01290   return aSketcher;
01291 }