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