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