Salome HOME
Update from BR_V5_DEV 13Feb2009
[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 {
339   SetErrorCode(KO);
340
341   // Not set thePnt means origin of global CS,
342   // Not set theVec means Z axis of global CS
343   //if (thePnt.IsNull() || theVec.IsNull()) return NULL;
344
345   //Add a new Ellipse object
346   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
347
348   //Add a new Ellipse function
349   Handle(GEOM_Function) aFunction =
350     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
351   if (aFunction.IsNull()) return NULL;
352
353   //Check if the function is set correctly
354   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
355
356   GEOMImpl_IEllipse aCI (aFunction);
357
358   if (!thePnt.IsNull()) {
359     Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
360     if (aRefPnt.IsNull()) return NULL;
361     aCI.SetCenter(aRefPnt);
362   }
363
364   if (!theVec.IsNull()) {
365     Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
366     if (aRefVec.IsNull()) return NULL;
367     aCI.SetVector(aRefVec);
368   }
369
370   aCI.SetRMajor(theRMajor);
371   aCI.SetRMinor(theRMinor);
372
373   //Compute the Ellipse value
374   try {
375 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
376     OCC_CATCH_SIGNALS;
377 #endif
378     if (!GetSolver()->ComputeFunction(aFunction)) {
379       SetErrorCode("Ellipse driver failed");
380       return NULL;
381     }
382   }
383   catch (Standard_Failure) {
384     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
385     SetErrorCode(aFail->GetMessageString());
386     return NULL;
387   }
388
389   //Make a Python command
390   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
391     << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
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  *  MakeArcOfEllipse
521  */
522 //=============================================================================
523 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcOfEllipse (Handle(GEOM_Object) thePnt1,
524                                                                   Handle(GEOM_Object) thePnt2,
525                                                                   Handle(GEOM_Object) thePnt3)
526 {
527   SetErrorCode(KO);
528
529   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
530
531   //Add a new Circle Arc object
532   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE_ARC);
533
534   //Add a new Circle Arc function
535   Handle(GEOM_Function) aFunction =
536       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), ELLIPSE_ARC_CENTER_TWO_PNT);
537
538   if (aFunction.IsNull()) return NULL;
539   
540   //Check if the function is set correctly
541   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
542   GEOMImpl_IArc aCI (aFunction);
543
544   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
545   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
546   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
547   
548
549   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
550
551   aCI.SetPoint1(aRefPnt1);
552   aCI.SetPoint2(aRefPnt2);
553   aCI.SetPoint3(aRefPnt3);
554   
555   //Compute the Arc value
556   try {
557 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
558     OCC_CATCH_SIGNALS;
559 #endif
560     if (!GetSolver()->ComputeFunction(aFunction)) {
561       SetErrorCode("Arc driver failed");
562       return NULL;
563     }
564   }
565   catch (Standard_Failure) {
566     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
567     SetErrorCode(aFail->GetMessageString());
568     return NULL;
569   }
570
571   //Make a Python command
572   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcOfEllipse("
573     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
574
575   SetErrorCode(OK);
576   return anArc;
577 }
578
579 //=============================================================================
580 /*!
581  *  MakeSplineBezier
582  */
583 //=============================================================================
584 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
585                                           (list<Handle(GEOM_Object)> thePoints)
586 {
587   SetErrorCode(KO);
588
589   //Add a new Spline object
590   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
591
592   //Add a new Spline function for creation a bezier curve relatively to points set
593   Handle(GEOM_Function) aFunction =
594     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
595   if (aFunction.IsNull()) return NULL;
596
597   //Check if the function is set correctly
598   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
599
600   GEOMImpl_ISpline aCI (aFunction);
601
602   int aLen = thePoints.size();
603   aCI.SetLength(aLen);
604
605   int ind = 1;
606   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
607   for (; it != thePoints.end(); it++, ind++) {
608     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
609
610     if (aRefPnt.IsNull()) return NULL;
611
612     aCI.SetPoint(ind, aRefPnt);
613   }
614
615   //Compute the Spline value
616   try {
617 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
618     OCC_CATCH_SIGNALS;
619 #endif
620     if (!GetSolver()->ComputeFunction(aFunction)) {
621       SetErrorCode("Spline driver failed");
622       return NULL;
623     }
624   }
625   catch (Standard_Failure) {
626     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
627     SetErrorCode(aFail->GetMessageString());
628     return NULL;
629   }
630
631   //Make a Python command
632   GEOM::TPythonDump pd (aFunction);
633   pd << aSpline << " = geompy.MakeBezier([";
634
635   it = thePoints.begin();
636   pd << (*it++);
637   while (it != thePoints.end()) {
638     pd << ", " << (*it++);
639   }
640   pd << "])";
641
642   SetErrorCode(OK);
643   return aSpline;
644 }
645
646 //=============================================================================
647 /*!
648  *  MakeSplineInterpolation
649  */
650 //=============================================================================
651 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
652                                           (list<Handle(GEOM_Object)> thePoints)
653 {
654   SetErrorCode(KO);
655
656   //Add a new Spline object
657   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
658
659   //Add a new Spline function for creation a bezier curve relatively to points set
660   Handle(GEOM_Function) aFunction =
661     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
662   if (aFunction.IsNull()) return NULL;
663
664   //Check if the function is set correctly
665   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
666
667   GEOMImpl_ISpline aCI (aFunction);
668
669   int aLen = thePoints.size();
670   aCI.SetLength(aLen);
671
672   int ind = 1;
673   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
674   for (; it != thePoints.end(); it++, ind++) {
675     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
676
677     if (aRefPnt.IsNull()) return NULL;
678
679     aCI.SetPoint(ind, aRefPnt);
680   }
681
682   //Compute the Spline value
683   try {
684 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
685     OCC_CATCH_SIGNALS;
686 #endif
687     if (!GetSolver()->ComputeFunction(aFunction)) {
688       SetErrorCode("Spline driver failed");
689       return NULL;
690     }
691   }
692   catch (Standard_Failure) {
693     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
694     SetErrorCode(aFail->GetMessageString());
695     return NULL;
696   }
697
698   //Make a Python command
699   GEOM::TPythonDump pd (aFunction);
700   pd << aSpline << " = geompy.MakeInterpol([";
701
702   it = thePoints.begin();
703   pd << (*it++);
704   while (it != thePoints.end()) {
705     pd << ", " << (*it++);
706   }
707   pd << "])";
708
709   SetErrorCode(OK);
710   return aSpline;
711 }
712
713 //=============================================================================
714 /*!
715  *  MakeSketcher
716  */
717 //=============================================================================
718 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCommand,
719                                                               list<double> theWorkingPlane)
720 {
721   SetErrorCode(KO);
722
723   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
724
725   //Add a new Sketcher object
726   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
727
728   //Add a new Sketcher function
729   Handle(GEOM_Function) aFunction =
730     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
731   if (aFunction.IsNull()) return NULL;
732
733   //Check if the function is set correctly
734   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
735
736   GEOMImpl_ISketcher aCI (aFunction);
737
738   TCollection_AsciiString aCommand((char*) theCommand);
739   aCI.SetCommand(aCommand);
740
741   int ind = 1;
742   list<double>::iterator it = theWorkingPlane.begin();
743   for (; it != theWorkingPlane.end(); it++, ind++)
744     aCI.SetWorkingPlane(ind, *it);
745
746   //Compute the Sketcher value
747   try {
748 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
749     OCC_CATCH_SIGNALS;
750 #endif
751     if (!GetSolver()->ComputeFunction(aFunction)) {
752       SetErrorCode("Sketcher driver failed");
753       return NULL;
754     }
755   }
756   catch (Standard_Failure) {
757     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
758     SetErrorCode(aFail->GetMessageString());
759     return NULL;
760   }
761
762   //Make a Python command
763   GEOM::TPythonDump pd (aFunction);
764   pd << aSketcher << " = geompy.MakeSketcher(\"" << aCommand.ToCString() << "\", [";
765
766   it = theWorkingPlane.begin();
767   pd << (*it++);
768   while (it != theWorkingPlane.end()) {
769     pd << ", " << (*it++);
770   }
771   pd << "])";
772
773   SetErrorCode(OK);
774   return aSketcher;
775 }
776
777 //=============================================================================
778 /*!
779  *  Make3DSketcher
780  */
781 //=============================================================================
782 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::Make3DSketcher (list<double> theCoordinates)
783 {
784   SetErrorCode(KO);
785
786   //Add a new Sketcher object
787   Handle(GEOM_Object) a3DSketcher = GetEngine()->AddObject(GetDocID(), GEOM_3DSKETCHER);
788
789   //Add a new Sketcher function
790   Handle(GEOM_Function) aFunction =
791     a3DSketcher->AddFunction(GEOMImpl_3DSketcherDriver::GetID(), GEOM_3DSKETCHER);
792   if (aFunction.IsNull()) return NULL;
793
794   //Check if the function is set correctly
795   if (aFunction->GetDriverGUID() != GEOMImpl_3DSketcherDriver::GetID()) return NULL;
796
797   GEOMImpl_I3DSketcher aCI (aFunction);
798
799   int nbOfCoords = 0;
800   list<double>::iterator it = theCoordinates.begin();
801   for (; it != theCoordinates.end(); it++)
802     nbOfCoords++;
803
804   Handle(TColStd_HArray1OfReal) aCoordsArray = new TColStd_HArray1OfReal (1, nbOfCoords);
805
806   it = theCoordinates.begin();
807   int ind = 1;
808   for (; it != theCoordinates.end(); it++, ind++)
809     aCoordsArray->SetValue(ind, *it);
810
811   aCI.SetCoordinates(aCoordsArray);
812     
813   //Compute the Sketcher value
814   try {
815 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
816     OCC_CATCH_SIGNALS;
817 #endif
818     if (!GetSolver()->ComputeFunction(aFunction)) {
819       SetErrorCode("3D Sketcher driver failed");
820       return NULL;
821     }
822   }
823   catch (Standard_Failure) {
824     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
825     SetErrorCode(aFail->GetMessageString());
826     return NULL;
827   }
828
829   //Make a Python command
830   GEOM::TPythonDump pd (aFunction);
831   pd << a3DSketcher << " = geompy.Make3DSketcher([";
832
833   it = theCoordinates.begin();
834   pd << (*it++);
835   while (it != theCoordinates.end()) {
836     pd << ", " << (*it++);
837   }
838   pd << "])";
839
840   SetErrorCode(OK);
841   return a3DSketcher;
842 }
843
844 //=============================================================================
845 /*!
846  *  MakeSketcherOnPlane
847  */
848 //=============================================================================
849 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
850                                (const char* theCommand,
851                                 Handle(GEOM_Object)            theWorkingPlane)
852 {
853   SetErrorCode(KO);
854
855   if (!theCommand || strcmp(theCommand, "") == 0) return NULL;
856
857   //Add a new Sketcher object
858   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
859
860   //Add a new Sketcher function
861   Handle(GEOM_Function) aFunction =
862     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
863   if (aFunction.IsNull()) return NULL;
864
865   //Check if the function is set correctly
866   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
867
868   GEOMImpl_ISketcher aCI (aFunction);
869
870   TCollection_AsciiString aCommand((char*) theCommand);
871   aCI.SetCommand(aCommand);
872
873   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
874   if (aRefPlane.IsNull()) return NULL;
875   aCI.SetWorkingPlane( aRefPlane );
876
877   //Compute the Sketcher value
878   try {
879 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
880     OCC_CATCH_SIGNALS;
881 #endif
882     if (!GetSolver()->ComputeFunction(aFunction)) {
883       SetErrorCode("Sketcher driver failed");
884       return NULL;
885     }
886   }
887   catch (Standard_Failure) {
888     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
889     SetErrorCode(aFail->GetMessageString());
890     return NULL;
891   }
892
893   //Make a Python command
894   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
895     << aCommand.ToCString() << "\", " << theWorkingPlane << " )";
896
897   SetErrorCode(OK);
898   return aSketcher;
899 }