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