Salome HOME
IMP 0020308: EDF 995 GEOM : Closed Polyline with tangence.
[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                                            bool                      theIsClosed)
669 {
670   SetErrorCode(KO);
671
672   //Add a new Spline object
673   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
674
675   //Add a new Spline function for creation a bezier curve relatively to points set
676   Handle(GEOM_Function) aFunction =
677     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
678   if (aFunction.IsNull()) return NULL;
679
680   //Check if the function is set correctly
681   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
682
683   GEOMImpl_ISpline aCI (aFunction);
684
685   int aLen = thePoints.size();
686   aCI.SetLength(aLen);
687
688   int ind = 1;
689   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
690   for (; it != thePoints.end(); it++, ind++) {
691     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
692
693     if (aRefPnt.IsNull()) return NULL;
694
695     aCI.SetPoint(ind, aRefPnt);
696   }
697
698   aCI.SetIsClosed(theIsClosed);
699
700   //Compute the Spline value
701   try {
702 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
703     OCC_CATCH_SIGNALS;
704 #endif
705     if (!GetSolver()->ComputeFunction(aFunction)) {
706       SetErrorCode("Spline driver failed");
707       return NULL;
708     }
709   }
710   catch (Standard_Failure) {
711     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
712     SetErrorCode(aFail->GetMessageString());
713     return NULL;
714   }
715
716   //Make a Python command
717   GEOM::TPythonDump pd (aFunction);
718   pd << aSpline << " = geompy.MakeInterpol([";
719
720   it = thePoints.begin();
721   pd << (*it++);
722   while (it != thePoints.end()) {
723     pd << ", " << (*it++);
724   }
725   pd << "])";
726
727   SetErrorCode(OK);
728   return aSpline;
729 }
730
731 //=============================================================================
732 /*!
733  *  MakeSketcher
734  */
735 //=============================================================================
736 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
737                                                               list<double> theWorkingPlane)
738 {
739   SetErrorCode(KO);
740
741   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
742
743   //Add a new Sketcher object
744   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
745
746   //Add a new Sketcher function
747   Handle(GEOM_Function) aFunction =
748     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
749   if (aFunction.IsNull()) return NULL;
750
751   //Check if the function is set correctly
752   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
753
754   GEOMImpl_ISketcher aCI (aFunction);
755
756   TCollection_AsciiString aCommand((char*) theCommand);
757   aCI.SetCommand(aCommand);
758
759   int ind = 1;
760   list<double>::iterator it = theWorkingPlane.begin();
761   for (; it != theWorkingPlane.end(); it++, ind++)
762     aCI.SetWorkingPlane(ind, *it);
763
764   //Compute the Sketcher value
765   try {
766 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
767     OCC_CATCH_SIGNALS;
768 #endif
769     if (!GetSolver()->ComputeFunction(aFunction)) {
770       SetErrorCode("Sketcher driver failed");
771       return NULL;
772     }
773   }
774   catch (Standard_Failure) {
775     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
776     SetErrorCode(aFail->GetMessageString());
777     return NULL;
778   }
779
780   //Make a Python command
781   GEOM::TPythonDump pd (aFunction);
782   pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
783
784   it = theWorkingPlane.begin();
785   pd << (*it++);
786   while (it != theWorkingPlane.end()) {
787     pd << ", " << (*it++);
788   }
789   pd << "])";
790
791   SetErrorCode(OK);
792   return aSketcher;
793 }
794
795 //=============================================================================
796 /*!
797  *  Make3DSketcher
798  */
799 //=============================================================================
800 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (list<double> theCoordinates)
801 {
802   SetErrorCode(KO);
803
804   //Add a new Sketcher object
805   Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
806
807   //Add a new Sketcher function
808   Handle(GEOM_Function) aFunction =
809     a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
810   if (aFunction.IsNull()) return NULL;
811
812   //Check if the function is set correctly
813   if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
814
815   GEOMImpl_I3DSketcher aCI (aFunction);
816
817   int nbOfCoords = 0;
818   list<double>::iterator it = theCoordinates.begin();
819   for (; it != theCoordinates.end(); it++)
820     nbOfCoords++;
821
822   Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
823
824   it = theCoordinates.begin();
825   int ind = 1;
826   for (; it != theCoordinates.end(); it++, ind++)
827     aCoordsArray->SetValue(ind, *it);
828
829   aCI.SetCoordinates(aCoordsArray);
830     
831   //Compute the Sketcher value
832   try {
833 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
834     OCC_CATCH_SIGNALS;
835 #endif
836     if (!GetSolver()->ComputeFunction(aFunction)) {
837       SetErrorCode("3D Sketcher driver failed");
838       return NULL;
839     }
840   }
841   catch (Standard_Failure) {
842     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
843     SetErrorCode(aFail->GetMessageString());
844     return NULL;
845   }
846
847   //Make a Python command
848   GEOM::TPythonDump pd (aFunction);
849   pd << a3DSketcher << " = geompy.Make3DSketcher([";
850
851   it = theCoordinates.begin();
852   pd << (*it++);
853   while (it != theCoordinates.end()) {
854     pd << ", " << (*it++);
855   }
856   pd << "])";
857
858   SetErrorCode(OK);
859   return a3DSketcher;
860 }
861
862 //=============================================================================
863 /*!
864  *  MakeSketcherOnPlane
865  */
866 //=============================================================================
867 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
868                                (const char* theCommand,
869                                 Handle(GEOM_Object)            theWorkingPlane)
870 {
871   SetErrorCode(KO);
872
873   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
874
875   //Add a new Sketcher object
876   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
877
878   //Add a new Sketcher function
879   Handle(GEOM_Function) aFunction =
880     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
881   if (aFunction.IsNull()) return NULL;
882
883   //Check if the function is set correctly
884   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
885
886   GEOMImpl_ISketcher aCI (aFunction);
887
888   TCollection_AsciiString aCommand((char*) theCommand);
889   aCI.SetCommand(aCommand);
890
891   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
892   if (aRefPlane.IsNull()) return NULL;
893   aCI.SetWorkingPlane( aRefPlane );
894
895   //Compute the Sketcher value
896   try {
897 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
898     OCC_CATCH_SIGNALS;
899 #endif
900     if (!GetSolver()->ComputeFunction(aFunction)) {
901       SetErrorCode("Sketcher driver failed");
902       return NULL;
903     }
904   }
905   catch (Standard_Failure) {
906     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
907     SetErrorCode(aFail->GetMessageString());
908     return NULL;
909   }
910
911   //Make a Python command
912   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
913     << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
914
915   SetErrorCode(OK);
916   return aSketcher;
917 }