]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx
Salome HOME
54ac51a06dc5b8494fdb5f88b02710a93ff7fe18
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ICurvesOperations.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include <Python.h>
23 #include <structmember.h>
24
25 #include <Standard_Stream.hxx>
26
27 #include <GEOMImpl_ICurvesOperations.hxx>
28
29 #include <TColStd_HArray1OfReal.hxx>
30
31 #include <GEOM_Function.hxx>
32 #include <GEOM_PythonDump.hxx>
33
34 #include <GEOMImpl_Types.hxx>
35
36 #include <GEOMImpl_PolylineDriver.hxx>
37 #include <GEOMImpl_CircleDriver.hxx>
38 #include <GEOMImpl_SplineDriver.hxx>
39 #include <GEOMImpl_EllipseDriver.hxx>
40 #include <GEOMImpl_ArcDriver.hxx>
41 #include <GEOMImpl_SketcherDriver.hxx>
42 #include <GEOMImpl_3DSketcherDriver.hxx>
43
44 #include <GEOMImpl_IPolyline.hxx>
45 #include <GEOMImpl_ICircle.hxx>
46 #include <GEOMImpl_ISpline.hxx>
47 #include <GEOMImpl_IEllipse.hxx>
48 #include <GEOMImpl_IArc.hxx>
49 #include <GEOMImpl_ISketcher.hxx>
50 #include <GEOMImpl_I3DSketcher.hxx>
51
52 #include "utilities.h"
53
54 #include <TDF_Tool.hxx>
55
56 #include <Standard_Failure.hxx>
57 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
58
59
60 /* ==================================
61  * ===========  PYTHON ==============
62  * ==================================*/
63
64 typedef struct {
65   PyObject_HEAD
66   int softspace;
67   std::string *out;
68   } PyStdOut;
69
70 static void
71 PyStdOut_dealloc(PyStdOut *self)
72 {
73   PyObject_Del(self);
74 }
75
76 static PyObject *
77 PyStdOut_write(PyStdOut *self, PyObject *args)
78 {
79   char *c;
80   int l;
81   if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
82     return NULL;
83
84   //std::cerr << c ;
85   *(self->out)=*(self->out)+c;
86
87   Py_INCREF(Py_None);
88   return Py_None;
89 }
90
91 static PyMethodDef PyStdOut_methods[] = {
92   {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
93     PyDoc_STR("write(string) -> None")},
94   {NULL,    NULL}   /* sentinel */
95 };
96
97 static PyMemberDef PyStdOut_memberlist[] = {
98   {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
99    (char*)"flag indicating that a space needs to be printed; used by print"},
100   {NULL} /* Sentinel */
101 };
102
103 static PyTypeObject PyStdOut_Type = {
104   /* The ob_type field must be initialized in the module init function
105    * to be portable to Windows without using C++. */
106   PyObject_HEAD_INIT(NULL)
107   0,                            /*ob_size*/
108   "PyOut",                      /*tp_name*/
109   sizeof(PyStdOut),             /*tp_basicsize*/
110   0,                            /*tp_itemsize*/
111   /* methods */
112   (destructor)PyStdOut_dealloc, /*tp_dealloc*/
113   0,                            /*tp_print*/
114   0,                            /*tp_getattr*/
115   0,                            /*tp_setattr*/
116   0,                            /*tp_compare*/
117   0,                            /*tp_repr*/
118   0,                            /*tp_as_number*/
119   0,                            /*tp_as_sequence*/
120   0,                            /*tp_as_mapping*/
121   0,                            /*tp_hash*/
122   0,                            /*tp_call*/
123   0,                            /*tp_str*/
124   PyObject_GenericGetAttr,      /*tp_getattro*/
125   /* softspace is writable:  we must supply tp_setattro */
126   PyObject_GenericSetAttr,      /* tp_setattro */
127   0,                            /*tp_as_buffer*/
128   Py_TPFLAGS_DEFAULT,           /*tp_flags*/
129   0,                            /*tp_doc*/
130   0,                            /*tp_traverse*/
131   0,                            /*tp_clear*/
132   0,                            /*tp_richcompare*/
133   0,                            /*tp_weaklistoffset*/
134   0,                            /*tp_iter*/
135   0,                            /*tp_iternext*/
136   PyStdOut_methods,             /*tp_methods*/
137   PyStdOut_memberlist,          /*tp_members*/
138   0,                            /*tp_getset*/
139   0,                            /*tp_base*/
140   0,                            /*tp_dict*/
141   0,                            /*tp_descr_get*/
142   0,                            /*tp_descr_set*/
143   0,                            /*tp_dictoffset*/
144   0,                            /*tp_init*/
145   0,                            /*tp_alloc*/
146   0,                            /*tp_new*/
147   0,                            /*tp_free*/
148   0,                            /*tp_is_gc*/
149 };
150
151 PyObject * newPyStdOut( std::string& out )
152 {
153   PyStdOut *self;
154   self = PyObject_New(PyStdOut, &PyStdOut_Type);
155   if (self == NULL)
156     return NULL;
157   self->softspace = 0;
158   self->out=&out;
159   return (PyObject*)self;
160 }
161
162
163 ////////////////////////END PYTHON///////////////////////////
164 //=============================================================================
165 /*!
166  *   constructor:
167  */
168 //=============================================================================
169 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
170 : GEOM_IOperations(theEngine, theDocID)
171 {
172   MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
173 }
174
175 //=============================================================================
176 /*!
177  *  destructor
178  */
179 //=============================================================================
180 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
181 {
182   MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
183 }
184
185
186 //=============================================================================
187 /*!
188  *  MakeCircleThreePnt
189  */
190 //=============================================================================
191 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
192                                                                     Handle(GEOM_Object) thePnt2,
193                                                                     Handle(GEOM_Object) thePnt3)
194 {
195   SetErrorCode(KO);
196
197   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
198
199   //Add a new Circle object
200   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
201
202   //Add a new Circle function for creation a circle relatively to three points
203   Handle(GEOM_Function) aFunction =
204     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
205   if (aFunction.IsNull()) return NULL;
206
207   //Check if the function is set correctly
208   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
209
210   GEOMImpl_ICircle aCI (aFunction);
211
212   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
213   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
214   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
215
216   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
217
218   aCI.SetPoint1(aRefPnt1);
219   aCI.SetPoint2(aRefPnt2);
220   aCI.SetPoint3(aRefPnt3);
221
222   //Compute the Circle value
223   try {
224 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
225     OCC_CATCH_SIGNALS;
226 #endif
227     if (!GetSolver()->ComputeFunction(aFunction)) {
228       SetErrorCode("Circle driver failed");
229       return NULL;
230     }
231   }
232   catch (Standard_Failure) {
233     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
234     SetErrorCode(aFail->GetMessageString());
235     return NULL;
236   }
237
238   //Make a Python command
239   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
240     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
241
242   SetErrorCode(OK);
243   return aCircle;
244 }
245
246 //=============================================================================
247 /*!
248  *  MakeCircleCenter2Pnt
249  */
250 //=============================================================================
251 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
252                                                                       Handle(GEOM_Object) thePnt2,
253                                                                       Handle(GEOM_Object) thePnt3)
254 {
255   SetErrorCode(KO);
256
257   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
258
259   //Add a new Circle object
260   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
261
262   //Add a new Circle function for creation a circle relatively to center and 2 points
263   Handle(GEOM_Function) aFunction =
264     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
265   if (aFunction.IsNull()) return NULL;
266
267   //Check if the function is set correctly
268   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
269
270   GEOMImpl_ICircle aCI (aFunction);
271
272   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
273   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
274   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
275
276   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
277
278   aCI.SetPoint1(aRefPnt1);
279   aCI.SetPoint2(aRefPnt2);
280   aCI.SetPoint3(aRefPnt3);
281
282   //Compute the Circle value
283   try {
284 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
285     OCC_CATCH_SIGNALS;
286 #endif
287     if (!GetSolver()->ComputeFunction(aFunction)) {
288       SetErrorCode("Circle driver failed");
289       return NULL;
290     }
291   }
292   catch (Standard_Failure) {
293     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
294     SetErrorCode(aFail->GetMessageString());
295     return NULL;
296   }
297
298   //Make a Python command
299   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
300     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
301
302   SetErrorCode(OK);
303   return aCircle;
304 }
305
306 //=============================================================================
307 /*!
308  *  MakeCirclePntVecR
309  */
310 //=============================================================================
311 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
312        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
313 {
314   SetErrorCode(KO);
315
316   // Not set thePnt means origin of global CS,
317   // Not set theVec means Z axis of global CS
318   //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
319
320   //Add a new Circle object
321   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
322
323   //Add a new Circle function for creation a circle relatively to point and vector
324   Handle(GEOM_Function) aFunction =
325     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
326   if (aFunction.IsNull()) return NULL;
327
328   //Check if the function is set correctly
329   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
330
331   GEOMImpl_ICircle aCI (aFunction);
332
333   if (!thePnt.IsNull()) {
334     Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
335     if (aRefPnt.IsNull()) return NULL;
336     aCI.SetCenter(aRefPnt);
337   }
338
339   if (!theVec.IsNull()) {
340     Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
341     if (aRefVec.IsNull()) return NULL;
342     aCI.SetVector(aRefVec);
343   }
344
345   aCI.SetRadius(theR);
346
347   //Compute the Circle value
348   try {
349 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
350     OCC_CATCH_SIGNALS;
351 #endif
352     if (!GetSolver()->ComputeFunction(aFunction)) {
353       SetErrorCode("Circle driver failed");
354       return NULL;
355     }
356   }
357   catch (Standard_Failure) {
358     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
359     SetErrorCode(aFail->GetMessageString());
360     return NULL;
361   }
362
363   //Make a Python command
364   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
365     << thePnt << ", " << theVec << ", " << theR << ")";
366
367   SetErrorCode(OK);
368   return aCircle;
369 }
370
371 //=============================================================================
372 /*!
373  *  MakeEllipse
374  */
375 //=============================================================================
376 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
377                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
378                         double theRMajor, double theRMinor,
379                         Handle(GEOM_Object) theVecMaj)
380 {
381   SetErrorCode(KO);
382
383   // Not set thePnt means origin of global CS,
384   // Not set theVec means Z axis of global CS
385   // Not set theVecMaj means X axis of global CS
386   //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
387
388   //Add a new Ellipse object
389   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
390
391   //Add a new Ellipse function
392   Handle(GEOM_Function) aFunction =
393     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
394   if (aFunction.IsNull()) return NULL;
395
396   //Check if the function is set correctly
397   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
398
399   GEOMImpl_IEllipse aCI (aFunction);
400
401   if (!thePnt.IsNull()) {
402     Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
403     if (aRefPnt.IsNull()) return NULL;
404     aCI.SetCenter(aRefPnt);
405   }
406
407   if (!theVec.IsNull()) {
408     Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
409     if (aRefVec.IsNull()) return NULL;
410     aCI.SetVector(aRefVec);
411   }
412
413   aCI.SetRMajor(theRMajor);
414   aCI.SetRMinor(theRMinor);
415
416   if (!theVecMaj.IsNull()) {
417     Handle(GEOM_Function) aRefVecMaj = theVecMaj->GetLastFunction();
418     if (aRefVecMaj.IsNull()) return NULL;
419     aCI.SetVectorMajor(aRefVecMaj);
420   }
421
422   //Compute the Ellipse value
423   try {
424 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
425     OCC_CATCH_SIGNALS;
426 #endif
427     if (!GetSolver()->ComputeFunction(aFunction)) {
428       SetErrorCode("Ellipse driver failed");
429       return NULL;
430     }
431   }
432   catch (Standard_Failure) {
433     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
434     SetErrorCode(aFail->GetMessageString());
435     return NULL;
436   }
437
438   //Make a Python command
439   if (!theVecMaj.IsNull()) {
440     GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
441                                  << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor
442                                  << ", " << theVecMaj << ")";
443   }
444   else {
445     GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
446                                  << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
447   }
448
449   SetErrorCode(OK);
450   return anEll;
451 }
452
453 //=============================================================================
454 /*!
455  *  MakeArc
456  */
457 //=============================================================================
458 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
459                                                          Handle(GEOM_Object) thePnt2,
460                                                          Handle(GEOM_Object) thePnt3)
461 {
462   SetErrorCode(KO);
463
464   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
465
466   //Add a new Circle Arc object
467   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
468
469   //Add a new Circle Arc function
470   Handle(GEOM_Function) aFunction =
471       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);  
472
473   if (aFunction.IsNull()) return NULL;
474   
475   //Check if the function is set correctly
476   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
477   GEOMImpl_IArc aCI (aFunction);
478
479   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
480   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
481   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
482   
483
484   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
485
486   aCI.SetPoint1(aRefPnt1);
487   aCI.SetPoint2(aRefPnt2);
488   aCI.SetPoint3(aRefPnt3);
489   
490   //Compute the Arc value
491   try {
492 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
493     OCC_CATCH_SIGNALS;
494 #endif
495     if (!GetSolver()->ComputeFunction(aFunction)) {
496       SetErrorCode("Arc driver failed");
497       return NULL;
498     }
499   }
500   catch (Standard_Failure) {
501     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
502     SetErrorCode(aFail->GetMessageString());
503     return NULL;
504   }
505
506   //Make a Python command
507   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
508     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
509
510   SetErrorCode(OK);
511   return anArc;
512 }
513
514 //=============================================================================
515 /*!
516  *  MakeArcCenter
517  */
518 //=============================================================================
519 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
520                                                                Handle(GEOM_Object) thePnt2,
521                                                                Handle(GEOM_Object) thePnt3,
522                                                                bool                theSense)
523 {
524   SetErrorCode(KO);
525   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
526
527   //Add a new Circle Arc object
528   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
529
530   //Add a new Circle Arc function
531   Handle(GEOM_Function) aFunction =
532       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
533   if (aFunction.IsNull()) return NULL;
534
535   //Check if the function is set correctly
536   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
537
538   GEOMImpl_IArc aCI (aFunction);
539
540   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
541   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
542   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
543
544   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
545
546   aCI.SetPoint1(aRefPnt1);
547   aCI.SetPoint2(aRefPnt2);
548   aCI.SetPoint3(aRefPnt3);
549   aCI.SetSense(theSense);
550
551   //Compute the Arc value
552   try {
553 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
554     OCC_CATCH_SIGNALS;
555 #endif
556     if (!GetSolver()->ComputeFunction(aFunction)) {
557   SetErrorCode("Arc driver failed");
558   return NULL;
559     }
560   }
561   catch (Standard_Failure) {
562     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
563     SetErrorCode(aFail->GetMessageString());
564     return NULL;
565   }
566   //Make a Python command
567   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
568       << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
569
570   SetErrorCode(OK);
571   return anArc;
572 }
573
574 //=============================================================================
575 /*!
576  *  MakeArcOfEllipse
577  */
578 //=============================================================================
579 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
580                                                                   Handle(GEOM_Object) thePnt2,
581                                                                   Handle(GEOM_Object) thePnt3)
582 {
583   SetErrorCode(KO);
584
585   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
586
587   //Add a new Circle Arc object
588   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
589
590   //Add a new Circle Arc function
591   Handle(GEOM_Function) aFunction =
592       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
593
594   if (aFunction.IsNull()) return NULL;
595   
596   //Check if the function is set correctly
597   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
598   GEOMImpl_IArc aCI (aFunction);
599
600   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
601   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
602   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
603   
604
605   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
606
607   aCI.SetPoint1(aRefPnt1);
608   aCI.SetPoint2(aRefPnt2);
609   aCI.SetPoint3(aRefPnt3);
610   
611   //Compute the Arc value
612   try {
613 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
614     OCC_CATCH_SIGNALS;
615 #endif
616     if (!GetSolver()->ComputeFunction(aFunction)) {
617       SetErrorCode("Arc driver failed");
618       return NULL;
619     }
620   }
621   catch (Standard_Failure) {
622     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
623     SetErrorCode(aFail->GetMessageString());
624     return NULL;
625   }
626
627   //Make a Python command
628   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
629     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
630
631   SetErrorCode(OK);
632   return anArc;
633 }
634
635 //=============================================================================
636 /*!
637  *  MakePolyline
638  */
639 //=============================================================================
640 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (std::list<Handle(GEOM_Object)> thePoints,
641                                                               bool theIsClosed)
642 {
643   SetErrorCode(KO);
644
645   //Add a new Polyline object
646   Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
647
648   //Add a new Polyline function for creation a polyline relatively to points set
649   Handle(GEOM_Function) aFunction =
650     aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
651   if (aFunction.IsNull()) return NULL;
652
653   //Check if the function is set correctly
654   if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
655
656   GEOMImpl_IPolyline aCI (aFunction);
657
658   int aLen = thePoints.size();
659   aCI.SetLength(aLen);
660   aCI.SetConstructorType(POINT_CONSTRUCTOR);
661
662   int ind = 1;
663   std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
664   for (; it != thePoints.end(); it++, ind++) {
665     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
666     if (aRefPnt.IsNull()) {
667       SetErrorCode("NULL point for Polyline");
668       return NULL;
669     }
670     aCI.SetPoint(ind, aRefPnt);
671   }
672
673   aCI.SetIsClosed(theIsClosed);
674
675   //Compute the Polyline value
676   try {
677 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
678     OCC_CATCH_SIGNALS;
679 #endif
680     if (!GetSolver()->ComputeFunction(aFunction)) {
681       SetErrorCode("Polyline driver failed");
682       return NULL;
683     }
684   }
685   catch (Standard_Failure) {
686     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
687     SetErrorCode(aFail->GetMessageString());
688     return NULL;
689   }
690
691   //Make a Python command
692   GEOM::TPythonDump pd (aFunction);
693   pd << aPolyline << " = geompy.MakePolyline([";
694
695   it = thePoints.begin();
696   pd << (*it++);
697   while (it != thePoints.end()) {
698     pd << ", " << (*it++);
699   }
700   pd << "], " << theIsClosed << ")";
701
702   SetErrorCode(OK);
703   return aPolyline;
704 }
705
706 //=============================================================================
707 /*!
708  *  MakeSplineBezier
709  */
710 //=============================================================================
711 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
712                                           (std::list<Handle(GEOM_Object)> thePoints,
713                                            bool theIsClosed)
714 {
715   SetErrorCode(KO);
716
717   //Add a new Spline object
718   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
719
720   //Add a new Spline function for creation a bezier curve relatively to points set
721   Handle(GEOM_Function) aFunction =
722     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
723   if (aFunction.IsNull()) return NULL;
724
725   //Check if the function is set correctly
726   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
727
728   GEOMImpl_ISpline aCI (aFunction);
729
730   int aLen = thePoints.size();
731   aCI.SetLength(aLen);
732   aCI.SetConstructorType(POINT_CONSTRUCTOR);
733
734   int ind = 1;
735   std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
736   for (; it != thePoints.end(); it++, ind++) {
737     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
738
739     if (aRefPnt.IsNull()) return NULL;
740
741     aCI.SetPoint(ind, aRefPnt);
742   }
743
744   aCI.SetIsClosed(theIsClosed);
745
746   //Compute the Spline value
747   try {
748 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
749     OCC_CATCH_SIGNALS;
750 #endif
751     if (!GetSolver()->ComputeFunction(aFunction)) {
752       SetErrorCode("Spline driver failed");
753       return NULL;
754     }
755   }
756   catch (Standard_Failure) {
757     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
758     SetErrorCode(aFail->GetMessageString());
759     return NULL;
760   }
761
762   //Make a Python command
763   GEOM::TPythonDump pd (aFunction);
764   pd << aSpline << " = geompy.MakeBezier([";
765
766   it = thePoints.begin();
767   pd << (*it++);
768   while (it != thePoints.end()) {
769     pd << ", " << (*it++);
770   }
771   pd << "], " << theIsClosed << ")";
772
773   SetErrorCode(OK);
774   return aSpline;
775 }
776
777 //=============================================================================
778 /*!
779  *  MakeSplineInterpolation
780  */
781 //=============================================================================
782 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
783                                           (std::list<Handle(GEOM_Object)> thePoints,
784                                            bool theIsClosed,
785                                            bool theDoReordering)
786 {
787   SetErrorCode(KO);
788
789   //Add a new Spline object
790   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
791
792   //Add a new Spline function for creation a bezier curve relatively to points set
793   Handle(GEOM_Function) aFunction =
794     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
795   if (aFunction.IsNull()) return NULL;
796
797   //Check if the function is set correctly
798   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
799
800   GEOMImpl_ISpline aCI (aFunction);
801
802   int aLen = thePoints.size();
803   aCI.SetConstructorType(POINT_CONSTRUCTOR);
804   aCI.SetLength(aLen);
805
806   int ind = 1;
807   std::list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
808   for (; it != thePoints.end(); it++, ind++) {
809     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
810
811     if (aRefPnt.IsNull()) return NULL;
812
813     aCI.SetPoint(ind, aRefPnt);
814   }
815
816   aCI.SetIsClosed(theIsClosed);
817   aCI.SetDoReordering(theDoReordering);
818
819   //Compute the Spline value
820   try {
821 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
822     OCC_CATCH_SIGNALS;
823 #endif
824     if (!GetSolver()->ComputeFunction(aFunction)) {
825       SetErrorCode("Spline driver failed");
826       return NULL;
827     }
828   }
829   catch (Standard_Failure) {
830     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
831     SetErrorCode(aFail->GetMessageString());
832     return NULL;
833   }
834
835   //Make a Python command
836   GEOM::TPythonDump pd (aFunction);
837   pd << aSpline << " = geompy.MakeInterpol([";
838
839   it = thePoints.begin();
840   pd << (*it++);
841   while (it != thePoints.end()) {
842     pd << ", " << (*it++);
843   }
844   pd << "], " << theIsClosed << ", " << theDoReordering << ")";
845
846   SetErrorCode(OK);
847   return aSpline;
848 }
849
850 //=============================================================================
851 /*!
852  *  MakeCurveParametric
853  */
854 //=============================================================================
855 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCurveParametric(const char* thexExpr, const char* theyExpr, const char* thezExpr, 
856                                                                     double theParamMin, double theParamMax, double theParamStep, 
857                                                                     CurveType theCurveType) {
858   TCollection_AsciiString aPyScript;
859   aPyScript +="from math import *                                          \n";
860   aPyScript +="def X(t):                                                   \n";
861   aPyScript +="    return "; 
862   aPyScript += thexExpr;
863   aPyScript += "\n";                                                             
864   aPyScript +="def Y(t):                                                   \n";
865   aPyScript +="    return ";
866   aPyScript += theyExpr;
867   aPyScript += "\n";
868   
869   aPyScript +="def Z(t):                                                   \n";
870   aPyScript +="    return ";
871   aPyScript += thezExpr;
872   aPyScript += "\n";
873   
874   aPyScript +="def coordCalucator(tmin, tmax, tstep):                      \n";
875   aPyScript +="   coords = []                                              \n";
876   aPyScript +="   while tmin <= tmax :                                     \n";
877   aPyScript +="      coords.append([X(tmin), Y(tmin), Z(tmin)])            \n";
878   aPyScript +="      tmin = tmin + tstep                                   \n";
879   aPyScript +="   return coords                                            \n";
880   
881   SetErrorCode(KO);
882
883   if(theParamMin >= theParamMax) {
884     SetErrorCode("The minimum value of the parameter must be less than maximum value !!!");
885     return NULL;
886   }
887
888   if(theParamStep <= 0.0 ) {
889     SetErrorCode("Value of the step must be positive !!!");
890     return NULL;
891   }
892   
893   /* Initialize the Python interpreter */
894   if (! Py_IsInitialized()) {
895     SetErrorCode("Python interpreter is not initialized !!! ");
896     return NULL;
897   } 
898
899   PyGILState_STATE gstate;
900   gstate = PyGILState_Ensure();
901   
902   PyObject* main_mod = PyImport_AddModule("__main__");
903   PyObject* main_dict = PyModule_GetDict(main_mod);
904
905   PyObject* obj = PyRun_String(aPyScript.ToCString(), Py_file_input, main_dict, NULL);
906
907   if (obj == NULL) {
908     SetErrorCode("Error during run python script !!!");
909     PyGILState_Release(gstate);
910     return NULL;
911   } else {
912     Py_DECREF(obj);
913   }
914
915   PyObject * func = NULL;
916   func = PyObject_GetAttrString(main_mod, "coordCalucator");
917   
918   if (func == NULL){
919     SetErrorCode("Can't get function from python module !!!");
920     PyGILState_Release(gstate);
921     return NULL;
922   }
923   
924   PyObject* coords = PyObject_CallFunction(func,(char*)"(d, d, d)", theParamMin, theParamMax, theParamStep );
925   PyObject* new_stderr = NULL;
926
927   if (coords == NULL){
928     fflush(stderr);
929     std::string err_description="";
930     new_stderr = newPyStdOut(err_description);
931     PySys_SetObject((char*)"stderr", new_stderr);
932     PyErr_Print();
933     PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
934     Py_DECREF(new_stderr);
935     MESSAGE("Can't evaluate coordCalucator()" << " error is " << err_description);
936     SetErrorCode("Can't evaluate the expressions, please check them !!!");
937     PyGILState_Release(gstate);
938     return NULL;
939   }
940
941   Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, PyList_Size( coords ) * 3);
942
943   if(PyList_Size( coords ) <= 0) {
944     SetErrorCode("Empty list of the points, please check input parameters !!!");
945     return NULL;
946   }    
947
948   int k=1;
949   for ( Py_ssize_t i = 0; i< PyList_Size( coords ); ++i ) {
950     PyObject* coord = PyList_GetItem( coords, i );
951     if (coord != NULL) {
952       for ( Py_ssize_t j = 0; j < PyList_Size(coord); ++j) {
953         PyObject* item = PyList_GetItem(coord, j);
954         aCoordsArray->SetValue(k, PyFloat_AsDouble(item));
955         k++;
956       }
957     }
958   }
959
960   Py_DECREF(coords);
961
962   
963   
964   PyGILState_Release(gstate);
965
966   Handle(GEOM_Object) aCurve; 
967   Handle(GEOM_Function) aFunction;
968   TCollection_AsciiString aCurveType;
969   
970   switch(theCurveType) {
971   case Polyline: {
972     //Add a new Polyline object
973     aCurve = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
974     
975     //Add a new Polyline function for creation a polyline relatively to points set
976     aFunction = aCurve->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
977     if (aFunction.IsNull()) return NULL;
978     
979     //Check if the function is set correctly
980     if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
981
982     GEOMImpl_IPolyline aCI (aFunction);
983
984     aCI.SetLength(PyList_Size( coords ));
985     aCI.SetConstructorType(COORD_CONSTRUCTOR);
986     aCI.SetIsClosed(false);
987     aCI.SetCoordinates(aCoordsArray);
988     aCurveType = "geompy.GEOM.Polyline";
989     break;
990   }
991   case Bezier: {
992     //Add a new Spline object
993     aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
994     //Add a new Spline function for creation a bezier curve relatively to points set
995     aFunction =
996       aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
997     if (aFunction.IsNull()) return NULL;
998     
999     //Check if the function is set correctly
1000     if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1001     
1002     GEOMImpl_ISpline aCI (aFunction);
1003
1004     aCI.SetLength(PyList_Size( coords ));
1005     aCI.SetConstructorType(COORD_CONSTRUCTOR);
1006     aCI.SetIsClosed(false);
1007     aCI.SetCoordinates(aCoordsArray);
1008     aCurveType = "geompy.GEOM.Bezier";
1009     break;
1010   }
1011   case Interpolation: {
1012     //Add a new Spline object
1013     aCurve = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
1014
1015     //Add a new Spline function for creation a bezier curve relatively to points set
1016     aFunction = aCurve->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
1017     if (aFunction.IsNull()) return NULL;
1018     
1019     //Check if the function is set correctly
1020     if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
1021
1022     GEOMImpl_ISpline aCI (aFunction);
1023     aCI.SetConstructorType(COORD_CONSTRUCTOR);
1024     aCI.SetLength(PyList_Size( coords ));
1025     aCI.SetIsClosed(false);
1026     aCI.SetDoReordering(false);
1027     aCI.SetCoordinates(aCoordsArray);
1028     aCurveType = "geompy.GEOM.Interpolation";
1029     break;
1030   }
1031   }
1032
1033   //Compute the Curve value
1034   try {
1035 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1036     OCC_CATCH_SIGNALS;
1037 #endif
1038     if (!GetSolver()->ComputeFunction(aFunction)) {
1039       SetErrorCode("Curve driver failed !!!");
1040       return NULL;
1041     }
1042   }
1043   catch (Standard_Failure) {
1044     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1045     SetErrorCode(aFail->GetMessageString());
1046     return NULL;
1047   }
1048   
1049   //Make a Python command
1050   GEOM::TPythonDump pd (aFunction);
1051   pd << aCurve << " = geompy.MakeCurveParametric(";
1052   pd << "\"" << thexExpr << "\", ";
1053   pd << "\"" << theyExpr << "\", ";
1054   pd << "\"" << thezExpr << "\", ";
1055   
1056   pd << theParamMin <<", ";
1057   pd << theParamMax <<", ";
1058   pd << theParamStep <<", ";
1059   pd << aCurveType.ToCString() <<")";
1060   
1061   SetErrorCode(OK);
1062   return aCurve;
1063 }
1064
1065 //=============================================================================
1066 /*!
1067  *  MakeSketcher
1068  */
1069 //=============================================================================
1070 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
1071                                                               std::list<double> theWorkingPlane)
1072 {
1073   SetErrorCode(KO);
1074
1075   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1076
1077   //Add a new Sketcher object
1078   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1079
1080   //Add a new Sketcher function
1081   Handle(GEOM_Function) aFunction =
1082     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
1083   if (aFunction.IsNull()) return NULL;
1084
1085   //Check if the function is set correctly
1086   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1087
1088   GEOMImpl_ISketcher aCI (aFunction);
1089
1090   TCollection_AsciiString aCommand((char*) theCommand);
1091   aCI.SetCommand(aCommand);
1092
1093   int ind = 1;
1094   std::list<double>::iterator it = theWorkingPlane.begin();
1095   for (; it != theWorkingPlane.end(); it++, ind++)
1096     aCI.SetWorkingPlane(ind, *it);
1097
1098   //Compute the Sketcher value
1099   try {
1100 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1101     OCC_CATCH_SIGNALS;
1102 #endif
1103     if (!GetSolver()->ComputeFunction(aFunction)) {
1104       SetErrorCode("Sketcher driver failed");
1105       return NULL;
1106     }
1107   }
1108   catch (Standard_Failure) {
1109     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1110     SetErrorCode(aFail->GetMessageString());
1111     return NULL;
1112   }
1113
1114   //Make a Python command
1115   GEOM::TPythonDump pd (aFunction);
1116   pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
1117
1118   it = theWorkingPlane.begin();
1119   pd << (*it++);
1120   while (it != theWorkingPlane.end()) {
1121     pd << ", " << (*it++);
1122   }
1123   pd << "])";
1124
1125   SetErrorCode(OK);
1126   return aSketcher;
1127 }
1128
1129 //=============================================================================
1130 /*!
1131  *  Make3DSketcher
1132  */
1133 //=============================================================================
1134 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (std::list<double> theCoordinates)
1135 {
1136   SetErrorCode(KO);
1137
1138   //Add a new Sketcher object
1139   Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
1140
1141   //Add a new Sketcher function
1142   Handle(GEOM_Function) aFunction =
1143     a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
1144   if (aFunction.IsNull()) return NULL;
1145
1146   //Check if the function is set correctly
1147   if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
1148
1149   GEOMImpl_I3DSketcher aCI (aFunction);
1150
1151   int nbOfCoords = 0;
1152   std::list<double>::iterator it = theCoordinates.begin();
1153   for (; it != theCoordinates.end(); it++)
1154     nbOfCoords++;
1155
1156   Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
1157
1158   it = theCoordinates.begin();
1159   int ind = 1;
1160   for (; it != theCoordinates.end(); it++, ind++)
1161     aCoordsArray->SetValue(ind, *it);
1162
1163   aCI.SetCoordinates(aCoordsArray);
1164     
1165   //Compute the Sketcher value
1166   try {
1167 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1168     OCC_CATCH_SIGNALS;
1169 #endif
1170     if (!GetSolver()->ComputeFunction(aFunction)) {
1171       SetErrorCode("3D Sketcher driver failed");
1172       return NULL;
1173     }
1174   }
1175   catch (Standard_Failure) {
1176     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1177     SetErrorCode(aFail->GetMessageString());
1178     return NULL;
1179   }
1180
1181   //Make a Python command
1182   GEOM::TPythonDump pd (aFunction);
1183   pd << a3DSketcher << " = geompy.Make3DSketcher([";
1184
1185   it = theCoordinates.begin();
1186   pd << (*it++);
1187   while (it != theCoordinates.end()) {
1188     pd << ", " << (*it++);
1189   }
1190   pd << "])";
1191
1192   SetErrorCode(OK);
1193   return a3DSketcher;
1194 }
1195
1196 //=============================================================================
1197 /*!
1198  *  MakeSketcherOnPlane
1199  */
1200 //=============================================================================
1201 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
1202                                (const char* theCommand,
1203                                 Handle(GEOM_Object)            theWorkingPlane)
1204 {
1205   SetErrorCode(KO);
1206
1207   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
1208
1209   //Add a new Sketcher object
1210   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
1211
1212   //Add a new Sketcher function
1213   Handle(GEOM_Function) aFunction =
1214     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
1215   if (aFunction.IsNull()) return NULL;
1216
1217   //Check if the function is set correctly
1218   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
1219
1220   GEOMImpl_ISketcher aCI (aFunction);
1221
1222   TCollection_AsciiString aCommand((char*) theCommand);
1223   aCI.SetCommand(aCommand);
1224
1225   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
1226   if (aRefPlane.IsNull()) return NULL;
1227   aCI.SetWorkingPlane( aRefPlane );
1228
1229   //Compute the Sketcher value
1230   try {
1231 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1232     OCC_CATCH_SIGNALS;
1233 #endif
1234     if (!GetSolver()->ComputeFunction(aFunction)) {
1235       SetErrorCode("Sketcher driver failed");
1236       return NULL;
1237     }
1238   }
1239   catch (Standard_Failure) {
1240     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1241     SetErrorCode(aFail->GetMessageString());
1242     return NULL;
1243   }
1244
1245   //Make a Python command
1246   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
1247     << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
1248
1249   SetErrorCode(OK);
1250   return aSketcher;
1251 }
1252