Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[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  *  MakeCircleCenter2Pnt
202  */
203 //=============================================================================
204 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCircleCenter2Pnt (Handle(GEOM_Object) thePnt1,
205                                                                       Handle(GEOM_Object) thePnt2,
206                                                                       Handle(GEOM_Object) thePnt3)
207 {
208   SetErrorCode(KO);
209
210   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.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 center and 2 points
216   Handle(GEOM_Function) aFunction =
217     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_CENTER_TWO_PNT);
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   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
226   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
227   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
228
229   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
230
231   aCI.SetPoint1(aRefPnt1);
232   aCI.SetPoint2(aRefPnt2);
233   aCI.SetPoint3(aRefPnt3);
234
235   //Compute the Circle value
236   try {
237 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
238     OCC_CATCH_SIGNALS;
239 #endif
240     if (!GetSolver()->ComputeFunction(aFunction)) {
241       SetErrorCode("Circle driver failed");
242       return NULL;
243     }
244   }
245   catch (Standard_Failure) {
246     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
247     SetErrorCode(aFail->GetMessageString());
248     return NULL;
249   }
250
251   //Make a Python command
252   GEOM::TPythonDump(aFunction) << aCircle << " = geompy.MakeCircleCenter2Pnt("
253     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
254
255   SetErrorCode(OK);
256   return aCircle;
257 }
258
259 //=============================================================================
260 /*!
261  *  MakeCirclePntVecR
262  */
263 //=============================================================================
264 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeCirclePntVecR
265        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
266 {
267   SetErrorCode(KO);
268
269   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
270
271   //Add a new Circle object
272   Handle(GEOM_Object) aCircle = GetEngine()->AddObject(GetDocID(), GEOM_CIRCLE);
273
274   //Add a new Circle function for creation a circle relatively to point and vector
275   Handle(GEOM_Function) aFunction =
276     aCircle->AddFunction(GEOMImpl_CircleDriver::GetID(), CIRCLE_PNT_VEC_R);
277   if (aFunction.IsNull()) return NULL;
278
279   //Check if the function is set correctly
280   if (aFunction->GetDriverGUID() != GEOMImpl_CircleDriver::GetID()) return NULL;
281
282   GEOMImpl_ICircle aCI (aFunction);
283
284   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
285   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
286
287   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
288
289   aCI.SetCenter(aRefPnt);
290   aCI.SetVector(aRefVec);
291   aCI.SetRadius(theR);
292
293   //Compute the Circle 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("Circle 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) << aCircle << " = geompy.MakeCircle("
311     << thePnt << ", " << theVec << ", " << theR << ")";
312
313   SetErrorCode(OK);
314   return aCircle;
315 }
316
317 //=============================================================================
318 /*!
319  *  MakeEllipse
320  */
321 //=============================================================================
322 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeEllipse
323                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
324                         double theRMajor, double theRMinor)
325 {
326   SetErrorCode(KO);
327
328   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
329
330   //Add a new Ellipse object
331   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_ELLIPSE);
332
333   //Add a new Ellipse function
334   Handle(GEOM_Function) aFunction =
335     anEll->AddFunction(GEOMImpl_EllipseDriver::GetID(), ELLIPSE_PNT_VEC_RR);
336   if (aFunction.IsNull()) return NULL;
337
338   //Check if the function is set correctly
339   if (aFunction->GetDriverGUID() != GEOMImpl_EllipseDriver::GetID()) return NULL;
340
341   GEOMImpl_IEllipse aCI (aFunction);
342
343   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
344   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
345
346   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
347
348   aCI.SetCenter(aRefPnt);
349   aCI.SetVector(aRefVec);
350   aCI.SetRMajor(theRMajor);
351   aCI.SetRMinor(theRMinor);
352
353   //Compute the Ellipse value
354   try {
355 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
356     OCC_CATCH_SIGNALS;
357 #endif
358     if (!GetSolver()->ComputeFunction(aFunction)) {
359       SetErrorCode("Ellipse driver failed");
360       return NULL;
361     }
362   }
363   catch (Standard_Failure) {
364     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
365     SetErrorCode(aFail->GetMessageString());
366     return NULL;
367   }
368
369   //Make a Python command
370   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeEllipse("
371     << thePnt << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
372
373   SetErrorCode(OK);
374   return anEll;
375 }
376
377 //=============================================================================
378 /*!
379  *  MakeArc
380  */
381 //=============================================================================
382 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArc (Handle(GEOM_Object) thePnt1,
383                                                          Handle(GEOM_Object) thePnt2,
384                                                          Handle(GEOM_Object) thePnt3)
385 {
386   SetErrorCode(KO);
387
388   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
389
390   //Add a new Circle Arc object
391   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
392
393   //Add a new Circle Arc function
394   Handle(GEOM_Function) aFunction =
395       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_THREE_PNT);  
396
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   GEOMImpl_IArc aCI (aFunction);
402
403   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
404   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
405   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
406   
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   
414   //Compute the Arc value
415   try {
416 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
417     OCC_CATCH_SIGNALS;
418 #endif
419     if (!GetSolver()->ComputeFunction(aFunction)) {
420       SetErrorCode("Arc driver failed");
421       return NULL;
422     }
423   }
424   catch (Standard_Failure) {
425     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
426     SetErrorCode(aFail->GetMessageString());
427     return NULL;
428   }
429
430   //Make a Python command
431   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArc("
432     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
433
434   SetErrorCode(OK);
435   return anArc;
436 }
437
438 //=============================================================================
439 /*!
440  *  MakeArcCenter
441  */
442 //=============================================================================
443 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeArcCenter (Handle(GEOM_Object) thePnt1,
444                                                                Handle(GEOM_Object) thePnt2,
445                                                                Handle(GEOM_Object) thePnt3,
446                                                                bool                theSense)
447 {
448   SetErrorCode(KO);
449   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
450
451   //Add a new Circle Arc object
452   Handle(GEOM_Object) anArc = GetEngine()->AddObject(GetDocID(), GEOM_CIRC_ARC);
453
454   //Add a new Circle Arc function
455   Handle(GEOM_Function) aFunction =
456       anArc->AddFunction(GEOMImpl_ArcDriver::GetID(), CIRC_ARC_CENTER);
457   if (aFunction.IsNull()) return NULL;
458
459   //Check if the function is set correctly
460   if (aFunction->GetDriverGUID() != GEOMImpl_ArcDriver::GetID()) return NULL;
461
462   GEOMImpl_IArc aCI (aFunction);
463
464   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
465   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
466   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
467
468   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
469
470   aCI.SetPoint1(aRefPnt1);
471   aCI.SetPoint2(aRefPnt2);
472   aCI.SetPoint3(aRefPnt3);
473   aCI.SetSense(theSense);
474
475   //Compute the Arc value
476   try {
477 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
478     OCC_CATCH_SIGNALS;
479 #endif
480     if (!GetSolver()->ComputeFunction(aFunction)) {
481   SetErrorCode("Arc driver failed");
482   return NULL;
483     }
484   }
485   catch (Standard_Failure) {
486     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
487     SetErrorCode(aFail->GetMessageString());
488     return NULL;
489   }
490   //Make a Python command
491   GEOM::TPythonDump(aFunction) << anArc << " = geompy.MakeArcCenter("
492       << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << "," << theSense << ")";
493
494   SetErrorCode(OK);
495   return anArc;
496 }
497
498 //=============================================================================
499 /*!
500  *  MakeSplineBezier
501  */
502 //=============================================================================
503 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineBezier
504                                           (list<Handle(GEOM_Object)> thePoints)
505 {
506   SetErrorCode(KO);
507
508   //Add a new Spline object
509   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
510
511   //Add a new Spline function for creation a bezier curve relatively to points set
512   Handle(GEOM_Function) aFunction =
513     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_BEZIER);
514   if (aFunction.IsNull()) return NULL;
515
516   //Check if the function is set correctly
517   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
518
519   GEOMImpl_ISpline aCI (aFunction);
520
521   int aLen = thePoints.size();
522   aCI.SetLength(aLen);
523
524   int ind = 1;
525   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
526   for (; it != thePoints.end(); it++, ind++) {
527     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
528
529     if (aRefPnt.IsNull()) return NULL;
530
531     aCI.SetPoint(ind, aRefPnt);
532   }
533
534   //Compute the Spline value
535   try {
536 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
537     OCC_CATCH_SIGNALS;
538 #endif
539     if (!GetSolver()->ComputeFunction(aFunction)) {
540       SetErrorCode("Spline driver failed");
541       return NULL;
542     }
543   }
544   catch (Standard_Failure) {
545     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
546     SetErrorCode(aFail->GetMessageString());
547     return NULL;
548   }
549
550   //Make a Python command
551   GEOM::TPythonDump pd (aFunction);
552   pd << aSpline << " = geompy.MakeBezier([";
553
554   it = thePoints.begin();
555   pd << (*it++);
556   while (it != thePoints.end()) {
557     pd << ", " << (*it++);
558   }
559   pd << "])";
560
561   SetErrorCode(OK);
562   return aSpline;
563 }
564
565 //=============================================================================
566 /*!
567  *  MakeSplineInterpolation
568  */
569 //=============================================================================
570 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSplineInterpolation
571                                           (list<Handle(GEOM_Object)> thePoints)
572 {
573   SetErrorCode(KO);
574
575   //Add a new Spline object
576   Handle(GEOM_Object) aSpline = GetEngine()->AddObject(GetDocID(), GEOM_SPLINE);
577
578   //Add a new Spline function for creation a bezier curve relatively to points set
579   Handle(GEOM_Function) aFunction =
580     aSpline->AddFunction(GEOMImpl_SplineDriver::GetID(), SPLINE_INTERPOLATION);
581   if (aFunction.IsNull()) return NULL;
582
583   //Check if the function is set correctly
584   if (aFunction->GetDriverGUID() != GEOMImpl_SplineDriver::GetID()) return NULL;
585
586   GEOMImpl_ISpline aCI (aFunction);
587
588   int aLen = thePoints.size();
589   aCI.SetLength(aLen);
590
591   int ind = 1;
592   list<Handle(GEOM_Object)>::iterator it = thePoints.begin();
593   for (; it != thePoints.end(); it++, ind++) {
594     Handle(GEOM_Function) aRefPnt = (*it)->GetLastFunction();
595
596     if (aRefPnt.IsNull()) return NULL;
597
598     aCI.SetPoint(ind, aRefPnt);
599   }
600
601   //Compute the Spline value
602   try {
603 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
604     OCC_CATCH_SIGNALS;
605 #endif
606     if (!GetSolver()->ComputeFunction(aFunction)) {
607       SetErrorCode("Spline driver failed");
608       return NULL;
609     }
610   }
611   catch (Standard_Failure) {
612     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
613     SetErrorCode(aFail->GetMessageString());
614     return NULL;
615   }
616
617   //Make a Python command
618   GEOM::TPythonDump pd (aFunction);
619   pd << aSpline << " = geompy.MakeInterpol([";
620
621   it = thePoints.begin();
622   pd << (*it++);
623   while (it != thePoints.end()) {
624     pd << ", " << (*it++);
625   }
626   pd << "])";
627
628   SetErrorCode(OK);
629   return aSpline;
630 }
631
632 //=============================================================================
633 /*!
634  *  MakeSketcher
635  */
636 //=============================================================================
637 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher
638                                (const TCollection_AsciiString& theCommand,
639                                 list<double>                   theWorkingPlane)
640 {
641   SetErrorCode(KO);
642
643   if (theCommand.IsEmpty()) return NULL;
644
645   //Add a new Sketcher object
646   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
647
648   //Add a new Sketcher function
649   Handle(GEOM_Function) aFunction =
650     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS);
651   if (aFunction.IsNull()) return NULL;
652
653   //Check if the function is set correctly
654   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
655
656   GEOMImpl_ISketcher aCI (aFunction);
657
658   aCI.SetCommand(theCommand);
659
660   int ind = 1;
661   list<double>::iterator it = theWorkingPlane.begin();
662   for (; it != theWorkingPlane.end(); it++, ind++)
663     aCI.SetWorkingPlane(ind, *it);
664
665   //Compute the Sketcher value
666   try {
667 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
668     OCC_CATCH_SIGNALS;
669 #endif
670     if (!GetSolver()->ComputeFunction(aFunction)) {
671       SetErrorCode("Sketcher driver failed");
672       return NULL;
673     }
674   }
675   catch (Standard_Failure) {
676     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
677     SetErrorCode(aFail->GetMessageString());
678     return NULL;
679   }
680
681   //Make a Python command
682   GEOM::TPythonDump pd (aFunction);
683   pd << aSketcher << " = geompy.MakeSketcher(\"" << theCommand.ToCString() << "\", [";
684
685   it = theWorkingPlane.begin();
686   pd << (*it++);
687   while (it != theWorkingPlane.end()) {
688     pd << ", " << (*it++);
689   }
690   pd << "])";
691
692   SetErrorCode(OK);
693   return aSketcher;
694 }
695
696 //=============================================================================
697 /*!
698  *  MakeSketcherOnPlane
699  */
700 //=============================================================================
701 Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane
702                                (const TCollection_AsciiString& theCommand,
703                                 Handle(GEOM_Object)            theWorkingPlane)
704 {
705   SetErrorCode(KO);
706
707   if (theCommand.IsEmpty()) return NULL;
708
709   //Add a new Sketcher object
710   Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER);
711
712   //Add a new Sketcher function
713   Handle(GEOM_Function) aFunction =
714     aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE);
715   if (aFunction.IsNull()) return NULL;
716
717   //Check if the function is set correctly
718   if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL;
719
720   GEOMImpl_ISketcher aCI (aFunction);
721   aCI.SetCommand(theCommand);
722
723   Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction();
724   if (aRefPlane.IsNull()) return NULL;
725   aCI.SetWorkingPlane( aRefPlane );
726
727   //Compute the Sketcher value
728   try {
729 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
730     OCC_CATCH_SIGNALS;
731 #endif
732     if (!GetSolver()->ComputeFunction(aFunction)) {
733       SetErrorCode("Sketcher driver failed");
734       return NULL;
735     }
736   }
737   catch (Standard_Failure) {
738     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
739     SetErrorCode(aFail->GetMessageString());
740     return NULL;
741   }
742
743   //Make a Python command
744   GEOM::TPythonDump (aFunction) << aSketcher << " = geompy.MakeSketcherOnPlane(\""
745     << theCommand.ToCString() << "\", " << theWorkingPlane << " )";
746
747   SetErrorCode(OK);
748   return aSketcher;
749 }