Salome HOME
Updated for PAL14857.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ICurvesOperations.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include <Standard_Stream.hxx>
21
22 #include <GEOMImpl_ICurvesOperations.hxx>
23
24 #include <GEOM_Function.hxx>
25 #include <GEOM_PythonDump.hxx>
26
27 #include <GEOMImpl_Types.hxx>
28
29 #include <GEOMImpl_PolylineDriver.hxx>
30 #include <GEOMImpl_CircleDriver.hxx>
31 #include <GEOMImpl_SplineDriver.hxx>
32 #include <GEOMImpl_EllipseDriver.hxx>
33 #include <GEOMImpl_ArcDriver.hxx>
34 #include <GEOMImpl_SketcherDriver.hxx>
35
36 #include <GEOMImpl_IPolyline.hxx>
37 #include <GEOMImpl_ICircle.hxx>
38 #include <GEOMImpl_ISpline.hxx>
39 #include <GEOMImpl_IEllipse.hxx>
40 #include <GEOMImpl_IArc.hxx>
41 #include <GEOMImpl_ISketcher.hxx>
42
43 #include "utilities.h"
44
45 #include <TDF_Tool.hxx>
46
47 #include <Standard_Failure.hxx>
48 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
49
50 //=============================================================================
51 /*!
52  *   constructor:
53  */
54 //=============================================================================
55 GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations (GEOM_Engine* theEngine, int theDocID)
56 : GEOM_IOperations(theEngine, theDocID)
57 {
58   MESSAGE("GEOMImpl_ICurvesOperations::GEOMImpl_ICurvesOperations");
59 }
60
61 //=============================================================================
62 /*!
63  *  destructor
64  */
65 //=============================================================================
66 GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations()
67 {
68   MESSAGE("GEOMImpl_ICurvesOperations::~GEOMImpl_ICurvesOperations");
69 }
70
71
72 //=============================================================================
73 /*!
74  *  MakePolyline
75  */
76 //=============================================================================
77 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakePolyline (list<Handle(GEOM_Object)> thePoints)
78 {
79   SetErrorCode(KO);
80
81   //Add a new Polyline object
82   Handle(GEOM_Object) aPolyline = GetEngine()->AddObject(GetDocID(), GEOM_POLYLINE);
83
84   //Add a new Polyline function for creation a polyline relatively to points set
85   Handle(GEOM_Function) aFunction =
86     aPolyline->AddFunction(GEOMImpl_PolylineDriver::GetID(), POLYLINE_POINTS);
87   if (aFunction.IsNull()) return NULL;
88
89   //Check if the function is set correctly
90   if (aFunction->GetDriverGUID() != GEOMImpl_PolylineDriver::GetID()) return NULL;
91
92   GEOMImpl_IPolyline aCI (aFunction);
93
94   int aLen = thePoints.size();
95   aCI.SetLength(aLen);
96
97   int ind = 1;
98   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
99   for (; it != thePoints.end(); it++, ind++) {
100     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
101     if (aRefPnt.IsNull()) {
102       SetErrorCode("NULL point for Polyline");
103       return NULL;
104     }
105     aCI.SetPoint(ind, aRefPnt);
106   }
107
108   //Compute the Polyline value
109   try {
110 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
111     OCC_CATCH_SIGNALS;
112 #endif
113     if (!GetSolver()->ComputeFunction(aFunction)) {
114       SetErrorCode("Polyline driver failed");
115       return NULL;
116     }
117   }
118   catch (Standard_Failure) {
119     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
120     SetErrorCode(aFail->GetMessageString());
121     return NULL;
122   }
123
124   //Make a Python command
125   GEOM::TPythonDump pd (aFunction);
126   pd << aPolyline << " = geompy.MakePolyline([";
127
128   it = thePoints.begin();
129   pd << (*it++);
130   while (it != thePoints.end()) {
131     pd << ", " << (*it++);
132   }
133   pd << "])";
134
135   SetErrorCode(OK);
136   return aPolyline;
137 }
138
139 //=============================================================================
140 /*!
141  *  MakeCircleThreePnt
142  */
143 //=============================================================================
144 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleThreePnt (Handle(GEOM_Object) thePnt1,
145                                                                     Handle(GEOM_Object) thePnt2,
146                                                                     Handle(GEOM_Object) thePnt3)
147 {
148   SetErrorCode(KO);
149
150   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
151
152   //Add a new Circle object
153   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
154
155   //Add a new Circle function for creation a circle relatively to three points
156   Handle(GEOM_Function) aFunction =
157     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_THREE_PNT);
158   if (aFunction.IsNull()) return NULL;
159
160   //Check if the function is set correctly
161   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
162
163   GEOMImpl_ICircle aCI (aFunction);
164
165   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
166   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
167   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
168
169   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
170
171   aCI.SetPoint1(aRefPnt1);
172   aCI.SetPoint2(aRefPnt2);
173   aCI.SetPoint3(aRefPnt3);
174
175   //Compute the Circle value
176   try {
177 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
178     OCC_CATCH_SIGNALS;
179 #endif
180     if (!GetSolver()->ComputeFunction(aFunction)) {
181       SetErrorCode("Circle driver failed");
182       return NULL;
183     }
184   }
185   catch (Standard_Failure) {
186     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
187     SetErrorCode(aFail->GetMessageString());
188     return NULL;
189   }
190
191   //Make a Python command
192   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleThreePnt("
193     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
194
195   SetErrorCode(OK);
196   return aCircle;
197 }
198
199 //=============================================================================
200 /*!
201  *  MakeCirclePntVecR
202  */
203 //=============================================================================
204 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
205        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
206 {
207   SetErrorCode(KO);
208
209   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
210
211   //Add a new Circle object
212   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
213
214   //Add a new Circle function for creation a circle relatively to point and vector
215   Handle(GEOM_Function) aFunction =
216     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
217   if (aFunction.IsNull()) return NULL;
218
219   //Check if the function is set correctly
220   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
221
222   GEOMImpl_ICircle aCI (aFunction);
223
224   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
225   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
226
227   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
228
229   aCI.SetCenter(aRefPnt);
230   aCI.SetVector(aRefVec);
231   aCI.SetRadius(theR);
232
233   //Compute the Circle value
234   try {
235 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
236     OCC_CATCH_SIGNALS;
237 #endif
238     if (!GetSolver()->ComputeFunction(aFunction)) {
239       SetErrorCode("Circle driver failed");
240       return NULL;
241     }
242   }
243   catch (Standard_Failure) {
244     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
245     SetErrorCode(aFail->GetMessageString());
246     return NULL;
247   }
248
249   //Make a Python command
250   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircle("
251     << thePnt << ", " << theVec << ", " << theR << ")";
252
253   SetErrorCode(OK);
254   return aCircle;
255 }
256
257 //=============================================================================
258 /*!
259  *  MakeEllipse
260  */
261 //=============================================================================
262 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
263                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
264                         double theRMajor, double theRMinor)
265 {
266   SetErrorCode(KO);
267
268   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
269
270   //Add a new Ellipse object
271   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
272
273   //Add a new Ellipse function
274   Handle(GEOM_Function) aFunction =
275     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
276   if (aFunction.IsNull()) return NULL;
277
278   //Check if the function is set correctly
279   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
280
281   GEOMImpl_IEllipse aCI (aFunction);
282
283   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
284   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
285
286   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
287
288   aCI.SetCenter(aRefPnt);
289   aCI.SetVector(aRefVec);
290   aCI.SetRMajor(theRMajor);
291   aCI.SetRMinor(theRMinor);
292
293   //Compute the Ellipse value
294   try {
295 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
296     OCC_CATCH_SIGNALS;
297 #endif
298     if (!GetSolver()->ComputeFunction(aFunction)) {
299       SetErrorCode("Ellipse driver failed");
300       return NULL;
301     }
302   }
303   catch (Standard_Failure) {
304     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
305     SetErrorCode(aFail->GetMessageString());
306     return NULL;
307   }
308
309   //Make a Python command
310   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
311     << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
312
313   SetErrorCode(OK);
314   return anEll;
315 }
316
317 //=============================================================================
318 /*!
319  *  MakeArc
320  */
321 //=============================================================================
322 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
323                                                          Handle(GEOM_Object) thePnt2,
324                                                          Handle(GEOM_Object) thePnt3)
325 {
326   SetErrorCode(KO);
327
328   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
329
330   //Add a new Circle Arc object
331   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
332
333   //Add a new Circle Arc function
334   Handle(GEOM_Function) aFunction =
335       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);  
336
337   if (aFunction.IsNull()) return NULL;
338   
339   //Check if the function is set correctly
340   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
341   GEOMImpl_IArc aCI (aFunction);
342
343   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
344   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
345   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
346   
347
348   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
349
350   aCI.SetPoint1(aRefPnt1);
351   aCI.SetPoint2(aRefPnt2);
352   aCI.SetPoint3(aRefPnt3);
353   
354   //Compute the Arc value
355   try {
356 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
357     OCC_CATCH_SIGNALS;
358 #endif
359     if (!GetSolver()->ComputeFunction(aFunction)) {
360       SetErrorCode("Arc driver failed");
361       return NULL;
362     }
363   }
364   catch (Standard_Failure) {
365     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
366     SetErrorCode(aFail->GetMessageString());
367     return NULL;
368   }
369
370   //Make a Python command
371   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
372     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
373
374   SetErrorCode(OK);
375   return anArc;
376 }
377
378 //=============================================================================
379 /*!
380  *  MakeArcCenter
381  */
382 //=============================================================================
383 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
384                                                                Handle(GEOM_Object) thePnt2,
385                                                                Handle(GEOM_Object) thePnt3,
386                                                                bool                theSense)
387 {
388   SetErrorCode(KO);
389   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
390
391   //Add a new Circle Arc object
392   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
393
394   //Add a new Circle Arc function
395   Handle(GEOM_Function) aFunction =
396       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
397   if (aFunction.IsNull()) return NULL;
398
399   //Check if the function is set correctly
400   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
401
402   GEOMImpl_IArc aCI (aFunction);
403
404   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
405   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
406   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
407
408   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
409
410   aCI.SetPoint1(aRefPnt1);
411   aCI.SetPoint2(aRefPnt2);
412   aCI.SetPoint3(aRefPnt3);
413   aCI.SetSense(theSense);
414
415   //Compute the Arc value
416   try {
417 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
418     OCC_CATCH_SIGNALS;
419 #endif
420     if (!GetSolver()->ComputeFunction(aFunction)) {
421   SetErrorCode("Arc driver failed");
422   return NULL;
423     }
424   }
425   catch (Standard_Failure) {
426     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
427     SetErrorCode(aFail->GetMessageString());
428     return NULL;
429   }
430   //Make a Python command
431   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
432       << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
433
434   SetErrorCode(OK);
435   return anArc;
436 }
437
438 //=============================================================================
439 /*!
440  *  MakeSplineBezier
441  */
442 //=============================================================================
443 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
444                                           (list<Handle(GEOM_Object)> thePoints)
445 {
446   SetErrorCode(KO);
447
448   //Add a new Spline object
449   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
450
451   //Add a new Spline function for creation a bezier curve relatively to points set
452   Handle(GEOM_Function) aFunction =
453     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
454   if (aFunction.IsNull()) return NULL;
455
456   //Check if the function is set correctly
457   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
458
459   GEOMImpl_ISpline aCI (aFunction);
460
461   int aLen = thePoints.size();
462   aCI.SetLength(aLen);
463
464   int ind = 1;
465   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
466   for (; it != thePoints.end(); it++, ind++) {
467     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
468
469     if (aRefPnt.IsNull()) return NULL;
470
471     aCI.SetPoint(ind, aRefPnt);
472   }
473
474   //Compute the Spline value
475   try {
476 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
477     OCC_CATCH_SIGNALS;
478 #endif
479     if (!GetSolver()->ComputeFunction(aFunction)) {
480       SetErrorCode("Spline driver failed");
481       return NULL;
482     }
483   }
484   catch (Standard_Failure) {
485     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
486     SetErrorCode(aFail->GetMessageString());
487     return NULL;
488   }
489
490   //Make a Python command
491   GEOM::TPythonDump pd (aFunction);
492   pd << aSpline << " = geompy.MakeBezier([";
493
494   it = thePoints.begin();
495   pd << (*it++);
496   while (it != thePoints.end()) {
497     pd << ", " << (*it++);
498   }
499   pd << "])";
500
501   SetErrorCode(OK);
502   return aSpline;
503 }
504
505 //=============================================================================
506 /*!
507  *  MakeSplineInterpolation
508  */
509 //=============================================================================
510 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
511                                           (list<Handle(GEOM_Object)> thePoints)
512 {
513   SetErrorCode(KO);
514
515   //Add a new Spline object
516   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
517
518   //Add a new Spline function for creation a bezier curve relatively to points set
519   Handle(GEOM_Function) aFunction =
520     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
521   if (aFunction.IsNull()) return NULL;
522
523   //Check if the function is set correctly
524   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
525
526   GEOMImpl_ISpline aCI (aFunction);
527
528   int aLen = thePoints.size();
529   aCI.SetLength(aLen);
530
531   int ind = 1;
532   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
533   for (; it != thePoints.end(); it++, ind++) {
534     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
535
536     if (aRefPnt.IsNull()) return NULL;
537
538     aCI.SetPoint(ind, aRefPnt);
539   }
540
541   //Compute the Spline value
542   try {
543 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
544     OCC_CATCH_SIGNALS;
545 #endif
546     if (!GetSolver()->ComputeFunction(aFunction)) {
547       SetErrorCode("Spline driver failed");
548       return NULL;
549     }
550   }
551   catch (Standard_Failure) {
552     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
553     SetErrorCode(aFail->GetMessageString());
554     return NULL;
555   }
556
557   //Make a Python command
558   GEOM::TPythonDump pd (aFunction);
559   pd << aSpline << " = geompy.MakeInterpol([";
560
561   it = thePoints.begin();
562   pd << (*it++);
563   while (it != thePoints.end()) {
564     pd << ", " << (*it++);
565   }
566   pd << "])";
567
568   SetErrorCode(OK);
569   return aSpline;
570 }
571
572 //=============================================================================
573 /*!
574  *  MakeSketcher
575  */
576 //=============================================================================
577 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
578                                (const TCollection_AsciiString& theCommand,
579                                 list<double>                   theWorkingPlane)
580 {
581   SetErrorCode(KO);
582
583   if (theCommand.IsEmpty()) return NULL;
584
585   //Add a new Sketcher object
586   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
587
588   //Add a new Sketcher function
589   Handle(GEOM_Function) aFunction =
590     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
591   if (aFunction.IsNull()) return NULL;
592
593   //Check if the function is set correctly
594   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
595
596   GEOMImpl_ISketcher aCI (aFunction);
597
598   aCI.SetCommand(theCommand);
599
600   int ind = 1;
601   list<double>::iterator it = theWorkingPlane.begin();
602   for (; it != theWorkingPlane.end(); it++, ind++)
603     aCI.SetWorkingPlane(ind, *it);
604
605   //Compute the Sketcher value
606   try {
607 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
608     OCC_CATCH_SIGNALS;
609 #endif
610     if (!GetSolver()->ComputeFunction(aFunction)) {
611       SetErrorCode("Sketcher driver failed");
612       return NULL;
613     }
614   }
615   catch (Standard_Failure) {
616     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
617     SetErrorCode(aFail->GetMessageString());
618     return NULL;
619   }
620
621   //Make a Python command
622   GEOM::TPythonDump pd (aFunction);
623   pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
624
625   it = theWorkingPlane.begin();
626   pd << (*it++);
627   while (it != theWorkingPlane.end()) {
628     pd << ", " << (*it++);
629   }
630   pd << "])";
631
632   SetErrorCode(OK);
633   return aSketcher;
634 }
635
636 //=============================================================================
637 /*!
638  *  MakeSketcherOnPlane
639  */
640 //=============================================================================
641 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
642                                (const TCollection_AsciiString& theCommand,
643                                 Handle(GEOM_Object)            theWorkingPlane)
644 {
645   SetErrorCode(KO);
646
647   if (theCommand.IsEmpty()) return NULL;
648
649   //Add a new Sketcher object
650   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
651
652   //Add a new Sketcher function
653   Handle(GEOM_Function) aFunction =
654     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
655   if (aFunction.IsNull()) return NULL;
656
657   //Check if the function is set correctly
658   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
659
660   GEOMImpl_ISketcher aCI (aFunction);
661   aCI.SetCommand(theCommand);
662
663   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
664   if (aRefPlane.IsNull()) return NULL;
665   aCI.SetWorkingPlane( aRefPlane );
666
667   //Compute the Sketcher value
668   try {
669 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
670     OCC_CATCH_SIGNALS;
671 #endif
672     if (!GetSolver()->ComputeFunction(aFunction)) {
673       SetErrorCode("Sketcher driver failed");
674       return NULL;
675     }
676   }
677   catch (Standard_Failure) {
678     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
679     SetErrorCode(aFail->GetMessageString());
680     return NULL;
681   }
682
683   //Make a Python command
684   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
685     << theCommand.ToCString() << "\", " << theWorkingPlane << " )";
686
687   SetErrorCode(OK);
688   return aSketcher;
689 }