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