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