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