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