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