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