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