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