Salome HOME
rollback IPAL8963 3.0.0: "Incorrect input data" message
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ICurvesOperations.cxx
1 //  Copyright (C) 2007-2008  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.
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 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_ICurvesOperations.hxx>
25
26 #include <GEOM_Function.hxx>
27 #include <GEOM_PythonDump.hxx>
28
29 #include <GEOMImpl_Types.hxx>
30
31 #include <GEOMImpl_PolylineDriver.hxx>
32 #include <GEOMImpl_CircleDriver.hxx>
33 #include <GEOMImpl_SplineDriver.hxx>
34 #include <GEOMImpl_EllipseDriver.hxx>
35 #include <GEOMImpl_ArcDriver.hxx>
36 #include <GEOMImpl_SketcherDriver.hxx>
37
38 #include <GEOMImpl_IPolyline.hxx>
39 #include <GEOMImpl_ICircle.hxx>
40 #include <GEOMImpl_ISpline.hxx>
41 #include <GEOMImpl_IEllipse.hxx>
42 #include <GEOMImpl_IArc.hxx>
43 #include <GEOMImpl_ISketcher.hxx>
44
45 #include "utilities.h"
46
47 #include <TDF_Tool.hxx>
48
49 #include <Standard_Failure.hxx>
50 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
51
52 using namespace std;
53
54 //=============================================================================
55 /*!
56  *   constructor:
57  */
58 //=============================================================================
59 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
60 : GEOM_IOperations(theEngine, theDocID)
61 {
62   MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
63 }
64
65 //=============================================================================
66 /*!
67  *  destructor
68  */
69 //=============================================================================
70 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
71 {
72   MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
73 }
74
75
76 //=============================================================================
77 /*!
78  *  MakePolyline
79  */
80 //=============================================================================
81 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
82 {
83   SetErrorCode(KO);
84
85   //Add a new Polyline object
86   Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
87
88   //Add a new Polyline function for creation a polyline relatively to points set
89   Handle(GEOM_Function) aFunction =
90     aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
91   if (aFunction.IsNull()) return NULL;
92
93   //Check if the function is set correctly
94   if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
95
96   GEOMImpl_IPolyline aCI (aFunction);
97
98   int aLen = thePoints.size();
99   aCI.SetLength(aLen);
100
101   int ind = 1;
102   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
103   for (; it != thePoints.end(); it++, ind++) {
104     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
105     if (aRefPnt.IsNull()) {
106       SetErrorCode("NULL point for Polyline");
107       return NULL;
108     }
109     aCI.SetPoint(ind, aRefPnt);
110   }
111
112   //Compute the Polyline value
113   try {
114 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
115     OCC_CATCH_SIGNALS;
116 #endif
117     if (!GetSolver()->ComputeFunction(aFunction)) {
118       SetErrorCode("Polyline driver failed");
119       return NULL;
120     }
121   }
122   catch (Standard_Failure) {
123     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
124     SetErrorCode(aFail->GetMessageString());
125     return NULL;
126   }
127
128   //Make a Python command
129   GEOM::TPythonDump pd (aFunction);
130   pd << aPolyline << " = geompy.MakePolyline([";
131
132   it = thePoints.begin();
133   pd << (*it++);
134   while (it != thePoints.end()) {
135     pd << ", " << (*it++);
136   }
137   pd << "])";
138
139   SetErrorCode(OK);
140   return aPolyline;
141 }
142
143 //=============================================================================
144 /*!
145  *  MakeCircleThreePnt
146  */
147 //=============================================================================
148 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
149                                                                     Handle(GEOM_Object) thePnt2,
150                                                                     Handle(GEOM_Object) thePnt3)
151 {
152   SetErrorCode(KO);
153
154   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
155
156   //Add a new Circle object
157   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
158
159   //Add a new Circle function for creation a circle relatively to three points
160   Handle(GEOM_Function) aFunction =
161     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
162   if (aFunction.IsNull()) return NULL;
163
164   //Check if the function is set correctly
165   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
166
167   GEOMImpl_ICircle aCI (aFunction);
168
169   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
170   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
171   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
172
173   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
174
175   aCI.SetPoint1(aRefPnt1);
176   aCI.SetPoint2(aRefPnt2);
177   aCI.SetPoint3(aRefPnt3);
178
179   //Compute the Circle value
180   try {
181 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
182     OCC_CATCH_SIGNALS;
183 #endif
184     if (!GetSolver()->ComputeFunction(aFunction)) {
185       SetErrorCode("Circle driver failed");
186       return NULL;
187     }
188   }
189   catch (Standard_Failure) {
190     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
191     SetErrorCode(aFail->GetMessageString());
192     return NULL;
193   }
194
195   //Make a Python command
196   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
197     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
198
199   SetErrorCode(OK);
200   return aCircle;
201 }
202
203 //=============================================================================
204 /*!
205  *  MakeCircleCenter2Pnt
206  */
207 //=============================================================================
208 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
209                                                                       Handle(GEOM_Object) thePnt2,
210                                                                       Handle(GEOM_Object) thePnt3)
211 {
212   SetErrorCode(KO);
213
214   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
215
216   //Add a new Circle object
217   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
218
219   //Add a new Circle function for creation a circle relatively to center and 2 points
220   Handle(GEOM_Function) aFunction =
221     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
222   if (aFunction.IsNull()) return NULL;
223
224   //Check if the function is set correctly
225   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
226
227   GEOMImpl_ICircle aCI (aFunction);
228
229   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
230   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
231   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
232
233   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
234
235   aCI.SetPoint1(aRefPnt1);
236   aCI.SetPoint2(aRefPnt2);
237   aCI.SetPoint3(aRefPnt3);
238
239   //Compute the Circle value
240   try {
241 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
242     OCC_CATCH_SIGNALS;
243 #endif
244     if (!GetSolver()->ComputeFunction(aFunction)) {
245       SetErrorCode("Circle driver failed");
246       return NULL;
247     }
248   }
249   catch (Standard_Failure) {
250     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
251     SetErrorCode(aFail->GetMessageString());
252     return NULL;
253   }
254
255   //Make a Python command
256   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
257     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
258
259   SetErrorCode(OK);
260   return aCircle;
261 }
262
263 //=============================================================================
264 /*!
265  *  MakeCirclePntVecR
266  */
267 //=============================================================================
268 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
269        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
270 {
271   SetErrorCode(KO);
272
273   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
274
275   //Add a new Circle object
276   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
277
278   //Add a new Circle function for creation a circle relatively to point and vector
279   Handle(GEOM_Function) aFunction =
280     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
281   if (aFunction.IsNull()) return NULL;
282
283   //Check if the function is set correctly
284   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
285
286   GEOMImpl_ICircle aCI (aFunction);
287
288   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
289   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
290
291   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
292
293   aCI.SetCenter(aRefPnt);
294   aCI.SetVector(aRefVec);
295   aCI.SetRadius(theR);
296
297   //Compute the Circle value
298   try {
299 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
300     OCC_CATCH_SIGNALS;
301 #endif
302     if (!GetSolver()->ComputeFunction(aFunction)) {
303       SetErrorCode("Circle driver failed");
304       return NULL;
305     }
306   }
307   catch (Standard_Failure) {
308     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
309     SetErrorCode(aFail->GetMessageString());
310     return NULL;
311   }
312
313   //Make a Python command
314   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
315     << thePnt << ", " << theVec << ", " << theR << ")";
316
317   SetErrorCode(OK);
318   return aCircle;
319 }
320
321 //=============================================================================
322 /*!
323  *  MakeEllipse
324  */
325 //=============================================================================
326 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
327                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
328                         double theRMajor, double theRMinor)
329 {
330   SetErrorCode(KO);
331
332   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
333
334   //Add a new Ellipse object
335   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
336
337   //Add a new Ellipse function
338   Handle(GEOM_Function) aFunction =
339     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
340   if (aFunction.IsNull()) return NULL;
341
342   //Check if the function is set correctly
343   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
344
345   GEOMImpl_IEllipse aCI (aFunction);
346
347   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
348   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
349
350   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
351
352   aCI.SetCenter(aRefPnt);
353   aCI.SetVector(aRefVec);
354   aCI.SetRMajor(theRMajor);
355   aCI.SetRMinor(theRMinor);
356
357   //Compute the Ellipse value
358   try {
359 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
360     OCC_CATCH_SIGNALS;
361 #endif
362     if (!GetSolver()->ComputeFunction(aFunction)) {
363       SetErrorCode("Ellipse driver failed");
364       return NULL;
365     }
366   }
367   catch (Standard_Failure) {
368     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
369     SetErrorCode(aFail->GetMessageString());
370     return NULL;
371   }
372
373   //Make a Python command
374   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
375     << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
376
377   SetErrorCode(OK);
378   return anEll;
379 }
380
381 //=============================================================================
382 /*!
383  *  MakeArc
384  */
385 //=============================================================================
386 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
387                                                          Handle(GEOM_Object) thePnt2,
388                                                          Handle(GEOM_Object) thePnt3)
389 {
390   SetErrorCode(KO);
391
392   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
393
394   //Add a new Circle Arc object
395   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
396
397   //Add a new Circle Arc function
398   Handle(GEOM_Function) aFunction =
399       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);  
400
401   if (aFunction.IsNull()) return NULL;
402   
403   //Check if the function is set correctly
404   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
405   GEOMImpl_IArc aCI (aFunction);
406
407   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
408   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
409   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
410   
411
412   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
413
414   aCI.SetPoint1(aRefPnt1);
415   aCI.SetPoint2(aRefPnt2);
416   aCI.SetPoint3(aRefPnt3);
417   
418   //Compute the Arc value
419   try {
420 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
421     OCC_CATCH_SIGNALS;
422 #endif
423     if (!GetSolver()->ComputeFunction(aFunction)) {
424       SetErrorCode("Arc driver failed");
425       return NULL;
426     }
427   }
428   catch (Standard_Failure) {
429     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
430     SetErrorCode(aFail->GetMessageString());
431     return NULL;
432   }
433
434   //Make a Python command
435   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
436     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
437
438   SetErrorCode(OK);
439   return anArc;
440 }
441
442 //=============================================================================
443 /*!
444  *  MakeArcCenter
445  */
446 //=============================================================================
447 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
448                                                                Handle(GEOM_Object) thePnt2,
449                                                                Handle(GEOM_Object) thePnt3,
450                                                                bool                theSense)
451 {
452   SetErrorCode(KO);
453   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
454
455   //Add a new Circle Arc object
456   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
457
458   //Add a new Circle Arc function
459   Handle(GEOM_Function) aFunction =
460       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
461   if (aFunction.IsNull()) return NULL;
462
463   //Check if the function is set correctly
464   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
465
466   GEOMImpl_IArc aCI (aFunction);
467
468   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
469   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
470   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
471
472   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
473
474   aCI.SetPoint1(aRefPnt1);
475   aCI.SetPoint2(aRefPnt2);
476   aCI.SetPoint3(aRefPnt3);
477   aCI.SetSense(theSense);
478
479   //Compute the Arc value
480   try {
481 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
482     OCC_CATCH_SIGNALS;
483 #endif
484     if (!GetSolver()->ComputeFunction(aFunction)) {
485   SetErrorCode("Arc driver failed");
486   return NULL;
487     }
488   }
489   catch (Standard_Failure) {
490     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
491     SetErrorCode(aFail->GetMessageString());
492     return NULL;
493   }
494   //Make a Python command
495   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
496       << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
497
498   SetErrorCode(OK);
499   return anArc;
500 }
501
502 //=============================================================================
503 /*!
504  *  MakeSplineBezier
505  */
506 //=============================================================================
507 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
508                                           (list<Handle(GEOM_Object)> thePoints)
509 {
510   SetErrorCode(KO);
511
512   //Add a new Spline object
513   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
514
515   //Add a new Spline function for creation a bezier curve relatively to points set
516   Handle(GEOM_Function) aFunction =
517     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
518   if (aFunction.IsNull()) return NULL;
519
520   //Check if the function is set correctly
521   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
522
523   GEOMImpl_ISpline aCI (aFunction);
524
525   int aLen = thePoints.size();
526   aCI.SetLength(aLen);
527
528   int ind = 1;
529   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
530   for (; it != thePoints.end(); it++, ind++) {
531     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
532
533     if (aRefPnt.IsNull()) return NULL;
534
535     aCI.SetPoint(ind, aRefPnt);
536   }
537
538   //Compute the Spline value
539   try {
540 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
541     OCC_CATCH_SIGNALS;
542 #endif
543     if (!GetSolver()->ComputeFunction(aFunction)) {
544       SetErrorCode("Spline driver failed");
545       return NULL;
546     }
547   }
548   catch (Standard_Failure) {
549     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
550     SetErrorCode(aFail->GetMessageString());
551     return NULL;
552   }
553
554   //Make a Python command
555   GEOM::TPythonDump pd (aFunction);
556   pd << aSpline << " = geompy.MakeBezier([";
557
558   it = thePoints.begin();
559   pd << (*it++);
560   while (it != thePoints.end()) {
561     pd << ", " << (*it++);
562   }
563   pd << "])";
564
565   SetErrorCode(OK);
566   return aSpline;
567 }
568
569 //=============================================================================
570 /*!
571  *  MakeSplineInterpolation
572  */
573 //=============================================================================
574 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
575                                           (list<Handle(GEOM_Object)> thePoints)
576 {
577   SetErrorCode(KO);
578
579   //Add a new Spline object
580   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
581
582   //Add a new Spline function for creation a bezier curve relatively to points set
583   Handle(GEOM_Function) aFunction =
584     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
585   if (aFunction.IsNull()) return NULL;
586
587   //Check if the function is set correctly
588   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
589
590   GEOMImpl_ISpline aCI (aFunction);
591
592   int aLen = thePoints.size();
593   aCI.SetLength(aLen);
594
595   int ind = 1;
596   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
597   for (; it != thePoints.end(); it++, ind++) {
598     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
599
600     if (aRefPnt.IsNull()) return NULL;
601
602     aCI.SetPoint(ind, aRefPnt);
603   }
604
605   //Compute the Spline value
606   try {
607 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
608     OCC_CATCH_SIGNALS;
609 #endif
610     if (!GetSolver()->ComputeFunction(aFunction)) {
611       SetErrorCode("Spline driver failed");
612       return NULL;
613     }
614   }
615   catch (Standard_Failure) {
616     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
617     SetErrorCode(aFail->GetMessageString());
618     return NULL;
619   }
620
621   //Make a Python command
622   GEOM::TPythonDump pd (aFunction);
623   pd << aSpline << " = geompy.MakeInterpol([";
624
625   it = thePoints.begin();
626   pd << (*it++);
627   while (it != thePoints.end()) {
628     pd << ", " << (*it++);
629   }
630   pd << "])";
631
632   SetErrorCode(OK);
633   return aSpline;
634 }
635
636 //=============================================================================
637 /*!
638  *  MakeSketcher
639  */
640 //=============================================================================
641 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
642                                                               list<double> theWorkingPlane)
643 {
644   SetErrorCode(KO);
645
646   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
647   
648   //Add a new Sketcher object
649   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
650
651   //Add a new Sketcher function
652   Handle(GEOM_Function) aFunction =
653     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
654   if (aFunction.IsNull()) return NULL;
655
656   //Check if the function is set correctly
657   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
658
659   GEOMImpl_ISketcher aCI (aFunction);
660   
661   TCollection_AsciiString aCommand((char*) theCommand);   
662   aCI.SetCommand(aCommand);
663
664   int ind = 1;
665   list<double>::iterator it = theWorkingPlane.begin();
666   for (; it != theWorkingPlane.end(); it++, ind++)
667     aCI.SetWorkingPlane(ind, *it);
668
669   //Compute the Sketcher value
670   try {
671 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
672     OCC_CATCH_SIGNALS;
673 #endif
674     if (!GetSolver()->ComputeFunction(aFunction)) {
675       SetErrorCode("Sketcher driver failed");
676       return NULL;
677     }
678   }
679   catch (Standard_Failure) {
680     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
681     SetErrorCode(aFail->GetMessageString());
682     return NULL;
683   }
684
685   //Make a Python command
686   GEOM::TPythonDump pd (aFunction);
687   pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
688
689   it = theWorkingPlane.begin();
690   pd << (*it++);
691   while (it != theWorkingPlane.end()) {
692     pd << ", " << (*it++);
693   }
694   pd << "])";
695
696   SetErrorCode(OK);
697   return aSketcher;
698 }
699
700 //=============================================================================
701 /*!
702  *  MakeSketcherOnPlane
703  */
704 //=============================================================================
705 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char* theCommand,
706                                                                      Handle(GEOM_Object) theWorkingPlane)
707 {
708   SetErrorCode(KO);
709
710   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
711
712   //Add a new Sketcher object
713   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
714
715   //Add a new Sketcher function
716   Handle(GEOM_Function) aFunction =
717     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
718   if (aFunction.IsNull()) return NULL;
719
720   //Check if the function is set correctly
721   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
722
723   GEOMImpl_ISketcher aCI (aFunction);
724
725   TCollection_AsciiString aCommand((char*) theCommand);  
726   aCI.SetCommand(aCommand);
727
728   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
729   if (aRefPlane.IsNull()) return NULL;
730   aCI.SetWorkingPlane( aRefPlane );
731
732   //Compute the Sketcher value
733   try {
734 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
735     OCC_CATCH_SIGNALS;
736 #endif
737     if (!GetSolver()->ComputeFunction(aFunction)) {
738       SetErrorCode("Sketcher driver failed");
739       return NULL;
740     }
741   }
742   catch (Standard_Failure) {
743     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
744     SetErrorCode(aFail->GetMessageString());
745     return NULL;
746   }
747
748   //Make a Python command
749   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
750     << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
751
752   SetErrorCode(OK);
753   return aSketcher;
754 }