]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx
Salome HOME
Bug 0020029: EDF 845 GEOM: impossible to set a negative angle for the revolution...
[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 using namespace std;
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   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   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
287   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
288
289   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
290
291   aCI.SetCenter(aRefPnt);
292   aCI.SetVector(aRefVec);
293   aCI.SetRadius(theR);
294
295   //Compute the Circle value
296   try {
297 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
298     OCC_CATCH_SIGNALS;
299 #endif
300     if (!GetSolver()->ComputeFunction(aFunction)) {
301       SetErrorCode("Circle driver failed");
302       return NULL;
303     }
304   }
305   catch (Standard_Failure) {
306     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
307     SetErrorCode(aFail->GetMessageString());
308     return NULL;
309   }
310
311   //Make a Python command
312   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
313     << thePnt << ", " << theVec << ", " << theR << ")";
314
315   SetErrorCode(OK);
316   return aCircle;
317 }
318
319 //=============================================================================
320 /*!
321  *  MakeEllipse
322  */
323 //=============================================================================
324 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
325                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
326                         double theRMajor, double theRMinor)
327 {
328   SetErrorCode(KO);
329
330   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
331
332   //Add a new Ellipse object
333   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
334
335   //Add a new Ellipse function
336   Handle(GEOM_Function) aFunction =
337     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
338   if (aFunction.IsNull()) return NULL;
339
340   //Check if the function is set correctly
341   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
342
343   GEOMImpl_IEllipse aCI (aFunction);
344
345   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
346   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
347
348   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
349
350   aCI.SetCenter(aRefPnt);
351   aCI.SetVector(aRefVec);
352   aCI.SetRMajor(theRMajor);
353   aCI.SetRMinor(theRMinor);
354
355   //Compute the Ellipse value
356   try {
357 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
358     OCC_CATCH_SIGNALS;
359 #endif
360     if (!GetSolver()->ComputeFunction(aFunction)) {
361       SetErrorCode("Ellipse 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) << anEll << " = geompy.MakeEllipse("
373     << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
374
375   SetErrorCode(OK);
376   return anEll;
377 }
378
379 //=============================================================================
380 /*!
381  *  MakeArc
382  */
383 //=============================================================================
384 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
385                                                          Handle(GEOM_Object) thePnt2,
386                                                          Handle(GEOM_Object) thePnt3)
387 {
388   SetErrorCode(KO);
389
390   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
391
392   //Add a new Circle Arc object
393   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
394
395   //Add a new Circle Arc function
396   Handle(GEOM_Function) aFunction =
397       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);  
398
399   if (aFunction.IsNull()) return NULL;
400   
401   //Check if the function is set correctly
402   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
403   GEOMImpl_IArc aCI (aFunction);
404
405   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
406   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
407   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
408   
409
410   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
411
412   aCI.SetPoint1(aRefPnt1);
413   aCI.SetPoint2(aRefPnt2);
414   aCI.SetPoint3(aRefPnt3);
415   
416   //Compute the Arc value
417   try {
418 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
419     OCC_CATCH_SIGNALS;
420 #endif
421     if (!GetSolver()->ComputeFunction(aFunction)) {
422       SetErrorCode("Arc driver failed");
423       return NULL;
424     }
425   }
426   catch (Standard_Failure) {
427     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
428     SetErrorCode(aFail->GetMessageString());
429     return NULL;
430   }
431
432   //Make a Python command
433   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
434     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
435
436   SetErrorCode(OK);
437   return anArc;
438 }
439
440 //=============================================================================
441 /*!
442  *  MakeArcCenter
443  */
444 //=============================================================================
445 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
446                                                                Handle(GEOM_Object) thePnt2,
447                                                                Handle(GEOM_Object) thePnt3,
448                                                                bool                theSense)
449 {
450   SetErrorCode(KO);
451   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
452
453   //Add a new Circle Arc object
454   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
455
456   //Add a new Circle Arc function
457   Handle(GEOM_Function) aFunction =
458       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
459   if (aFunction.IsNull()) return NULL;
460
461   //Check if the function is set correctly
462   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
463
464   GEOMImpl_IArc aCI (aFunction);
465
466   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
467   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
468   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
469
470   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
471
472   aCI.SetPoint1(aRefPnt1);
473   aCI.SetPoint2(aRefPnt2);
474   aCI.SetPoint3(aRefPnt3);
475   aCI.SetSense(theSense);
476
477   //Compute the Arc value
478   try {
479 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
480     OCC_CATCH_SIGNALS;
481 #endif
482     if (!GetSolver()->ComputeFunction(aFunction)) {
483   SetErrorCode("Arc driver failed");
484   return NULL;
485     }
486   }
487   catch (Standard_Failure) {
488     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
489     SetErrorCode(aFail->GetMessageString());
490     return NULL;
491   }
492   //Make a Python command
493   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
494       << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
495
496   SetErrorCode(OK);
497   return anArc;
498 }
499
500 //=============================================================================
501 /*!
502  *  MakeSplineBezier
503  */
504 //=============================================================================
505 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
506                                           (list<Handle(GEOM_Object)> thePoints)
507 {
508   SetErrorCode(KO);
509
510   //Add a new Spline object
511   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
512
513   //Add a new Spline function for creation a bezier curve relatively to points set
514   Handle(GEOM_Function) aFunction =
515     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
516   if (aFunction.IsNull()) return NULL;
517
518   //Check if the function is set correctly
519   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
520
521   GEOMImpl_ISpline aCI (aFunction);
522
523   int aLen = thePoints.size();
524   aCI.SetLength(aLen);
525
526   int ind = 1;
527   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
528   for (; it != thePoints.end(); it++, ind++) {
529     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
530
531     if (aRefPnt.IsNull()) return NULL;
532
533     aCI.SetPoint(ind, aRefPnt);
534   }
535
536   //Compute the Spline value
537   try {
538 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
539     OCC_CATCH_SIGNALS;
540 #endif
541     if (!GetSolver()->ComputeFunction(aFunction)) {
542       SetErrorCode("Spline driver failed");
543       return NULL;
544     }
545   }
546   catch (Standard_Failure) {
547     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
548     SetErrorCode(aFail->GetMessageString());
549     return NULL;
550   }
551
552   //Make a Python command
553   GEOM::TPythonDump pd (aFunction);
554   pd << aSpline << " = geompy.MakeBezier([";
555
556   it = thePoints.begin();
557   pd << (*it++);
558   while (it != thePoints.end()) {
559     pd << ", " << (*it++);
560   }
561   pd << "])";
562
563   SetErrorCode(OK);
564   return aSpline;
565 }
566
567 //=============================================================================
568 /*!
569  *  MakeSplineInterpolation
570  */
571 //=============================================================================
572 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
573                                           (list<Handle(GEOM_Object)> thePoints)
574 {
575   SetErrorCode(KO);
576
577   //Add a new Spline object
578   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
579
580   //Add a new Spline function for creation a bezier curve relatively to points set
581   Handle(GEOM_Function) aFunction =
582     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
583   if (aFunction.IsNull()) return NULL;
584
585   //Check if the function is set correctly
586   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
587
588   GEOMImpl_ISpline aCI (aFunction);
589
590   int aLen = thePoints.size();
591   aCI.SetLength(aLen);
592
593   int ind = 1;
594   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
595   for (; it != thePoints.end(); it++, ind++) {
596     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
597
598     if (aRefPnt.IsNull()) return NULL;
599
600     aCI.SetPoint(ind, aRefPnt);
601   }
602
603   //Compute the Spline value
604   try {
605 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
606     OCC_CATCH_SIGNALS;
607 #endif
608     if (!GetSolver()->ComputeFunction(aFunction)) {
609       SetErrorCode("Spline driver failed");
610       return NULL;
611     }
612   }
613   catch (Standard_Failure) {
614     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
615     SetErrorCode(aFail->GetMessageString());
616     return NULL;
617   }
618
619   //Make a Python command
620   GEOM::TPythonDump pd (aFunction);
621   pd << aSpline << " = geompy.MakeInterpol([";
622
623   it = thePoints.begin();
624   pd << (*it++);
625   while (it != thePoints.end()) {
626     pd << ", " << (*it++);
627   }
628   pd << "])";
629
630   SetErrorCode(OK);
631   return aSpline;
632 }
633
634 //=============================================================================
635 /*!
636  *  MakeSketcher
637  */
638 //=============================================================================
639 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
640                                                               list<double> theWorkingPlane)
641 {
642   SetErrorCode(KO);
643
644   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
645   
646   //Add a new Sketcher object
647   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
648
649   //Add a new Sketcher function
650   Handle(GEOM_Function) aFunction =
651     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
652   if (aFunction.IsNull()) return NULL;
653
654   //Check if the function is set correctly
655   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
656
657   GEOMImpl_ISketcher aCI (aFunction);
658   
659   TCollection_AsciiString aCommand((char*) theCommand);   
660   aCI.SetCommand(aCommand);
661
662   int ind = 1;
663   list<double>::iterator it = theWorkingPlane.begin();
664   for (; it != theWorkingPlane.end(); it++, ind++)
665     aCI.SetWorkingPlane(ind, *it);
666
667   //Compute the Sketcher value
668   try {
669 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
670     OCC_CATCH_SIGNALS;
671 #endif
672     if (!GetSolver()->ComputeFunction(aFunction)) {
673       SetErrorCode("Sketcher driver failed");
674       return NULL;
675     }
676   }
677   catch (Standard_Failure) {
678     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
679     SetErrorCode(aFail->GetMessageString());
680     return NULL;
681   }
682
683   //Make a Python command
684   GEOM::TPythonDump pd (aFunction);
685   pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
686
687   it = theWorkingPlane.begin();
688   pd << (*it++);
689   while (it != theWorkingPlane.end()) {
690     pd << ", " << (*it++);
691   }
692   pd << "])";
693
694   SetErrorCode(OK);
695   return aSketcher;
696 }
697
698 //=============================================================================
699 /*!
700  *  MakeSketcherOnPlane
701  */
702 //=============================================================================
703 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char* theCommand,
704                                                                      Handle(GEOM_Object) theWorkingPlane)
705 {
706   SetErrorCode(KO);
707
708   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
709
710   //Add a new Sketcher object
711   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
712
713   //Add a new Sketcher function
714   Handle(GEOM_Function) aFunction =
715     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
716   if (aFunction.IsNull()) return NULL;
717
718   //Check if the function is set correctly
719   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
720
721   GEOMImpl_ISketcher aCI (aFunction);
722
723   TCollection_AsciiString aCommand((char*) theCommand);  
724   aCI.SetCommand(aCommand);
725
726   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
727   if (aRefPlane.IsNull()) return NULL;
728   aCI.SetWorkingPlane( aRefPlane );
729
730   //Compute the Sketcher value
731   try {
732 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
733     OCC_CATCH_SIGNALS;
734 #endif
735     if (!GetSolver()->ComputeFunction(aFunction)) {
736       SetErrorCode("Sketcher driver failed");
737       return NULL;
738     }
739   }
740   catch (Standard_Failure) {
741     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
742     SetErrorCode(aFail->GetMessageString());
743     return NULL;
744   }
745
746   //Make a Python command
747   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
748     << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
749
750   SetErrorCode(OK);
751   return aSketcher;
752 }