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