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