Salome HOME
INT PAL 0052642: Notebook variables are not dumped to script with Fillet1D, Fillet2D...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_I3DPrimOperations.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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
23 #include <Standard_Stream.hxx>
24
25 #include <Basics_OCCTVersion.hxx>
26
27 #include <GEOMImpl_I3DPrimOperations.hxx>
28
29 #include "utilities.h"
30 #include <OpUtil.hxx>
31 #include <Utils_ExceptHandlers.hxx>
32
33 #include <TFunction_DriverTable.hxx>
34 #include <TFunction_Driver.hxx>
35 #include <TFunction_Logbook.hxx>
36 #include <TDF_Tool.hxx>
37
38 #include <GEOM_Function.hxx>
39 #include <GEOM_PythonDump.hxx>
40
41 #include <GEOMImpl_Types.hxx>
42
43 #include <GEOMImpl_BoxDriver.hxx>
44 #include <GEOMImpl_FaceDriver.hxx>
45 #include <GEOMImpl_DiskDriver.hxx>
46 #include <GEOMImpl_CylinderDriver.hxx>
47 #include <GEOMImpl_ConeDriver.hxx>
48 #include <GEOMImpl_SphereDriver.hxx>
49 #include <GEOMImpl_TorusDriver.hxx>
50 #include <GEOMImpl_PrismDriver.hxx>
51 #include <GEOMImpl_PipeDriver.hxx>
52 #include <GEOMImpl_PipePathDriver.hxx>
53 #include <GEOMImpl_RevolutionDriver.hxx>
54 #include <GEOMImpl_ShapeDriver.hxx>
55 #include <GEOMImpl_FillingDriver.hxx>
56 #include <GEOMImpl_ThruSectionsDriver.hxx>
57 #include <GEOMImpl_OffsetDriver.hxx>
58
59 #include <GEOMImpl_IBox.hxx>
60 #include <GEOMImpl_IFace.hxx>
61 #include <GEOMImpl_IDisk.hxx>
62 #include <GEOMImpl_ICylinder.hxx>
63 #include <GEOMImpl_ICone.hxx>
64 #include <GEOMImpl_ISphere.hxx>
65 #include <GEOMImpl_ITorus.hxx>
66 #include <GEOMImpl_IPrism.hxx>
67 #include <GEOMImpl_IPipe.hxx>
68 #include <GEOMImpl_IRevolution.hxx>
69 #include <GEOMImpl_IFilling.hxx>
70 #include <GEOMImpl_IThruSections.hxx>
71 #include <GEOMImpl_IPipeDiffSect.hxx>
72 #include <GEOMImpl_IPipeShellSect.hxx>
73 #include <GEOMImpl_IPipeBiNormal.hxx>
74 #include <GEOMImpl_IOffset.hxx>
75 #include <GEOMImpl_IPipePath.hxx>
76
77 #include <Precision.hxx>
78
79 #include <Standard_Failure.hxx>
80 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
81
82 //=============================================================================
83 /*!
84  *   constructor:
85  */
86 //=============================================================================
87 GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, int theDocID)
88 : GEOM_IOperations(theEngine, theDocID)
89 {
90   MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations");
91 }
92
93 //=============================================================================
94 /*!
95  *  destructor
96  */
97 //=============================================================================
98 GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations()
99 {
100   MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations");
101 }
102
103
104 //=============================================================================
105 /*!
106  *  MakeBoxDXDYDZ
107  */
108 //=============================================================================
109 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxDXDYDZ (double theDX, double theDY, double theDZ)
110 {
111   SetErrorCode(KO);
112
113   //Add a new Box object
114   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
115
116   //Add a new Box function with DX_DY_DZ parameters
117   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_DX_DY_DZ);
118   if (aFunction.IsNull()) return NULL;
119
120   //Check if the function is set correctly
121   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return NULL;
122
123   GEOMImpl_IBox aBI (aFunction);
124
125   aBI.SetDX(theDX);
126   aBI.SetDY(theDY);
127   aBI.SetDZ(theDZ);
128
129   //Compute the box value
130   try {
131     OCC_CATCH_SIGNALS;
132     if (!GetSolver()->ComputeFunction(aFunction)) {
133       SetErrorCode("Box driver failed");
134       return NULL;
135     }
136   }
137   catch (Standard_Failure) {
138     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
139     SetErrorCode(aFail->GetMessageString());
140     return NULL;
141   }
142
143   //Make a Python command
144   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxDXDYDZ("
145     << theDX << ", " << theDY << ", " << theDZ << ")";
146
147   SetErrorCode(OK);
148   return aBox;
149 }
150
151
152 //=============================================================================
153 /*!
154  *  MakeBoxTwoPnt
155  */
156 //=============================================================================
157 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxTwoPnt (Handle(GEOM_Object) thePnt1,
158                                                                Handle(GEOM_Object) thePnt2)
159 {
160   SetErrorCode(KO);
161
162   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
163
164   //Add a new Box object
165   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
166
167   //Add a new Box function for creation a box relatively to two points
168   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_TWO_PNT);
169   if (aFunction.IsNull()) return NULL;
170
171   //Check if the function is set correctly
172   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return aBox;
173
174   GEOMImpl_IBox aBI (aFunction);
175
176   Handle(GEOM_Function) aRefFunction1 = thePnt1->GetLastFunction();
177   Handle(GEOM_Function) aRefFunction2 = thePnt2->GetLastFunction();
178
179   if (aRefFunction1.IsNull() || aRefFunction2.IsNull()) return aBox;
180
181   aBI.SetRef1(aRefFunction1);
182   aBI.SetRef2(aRefFunction2);
183
184   //Compute the Box value
185   try {
186     OCC_CATCH_SIGNALS;
187     if (!GetSolver()->ComputeFunction(aFunction)) {
188       SetErrorCode("Box driver failed");
189       return NULL;
190     }
191   }
192   catch (Standard_Failure) {
193     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
194     SetErrorCode(aFail->GetMessageString());
195     return NULL;
196   }
197
198   //Make a Python command
199   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxTwoPnt("
200     << thePnt1 << ", " << thePnt2 << ")";
201
202   SetErrorCode(OK);
203   return aBox;
204 }
205
206 //=============================================================================
207 /*!
208  *  MakeFaceHW
209  */
210 //=============================================================================
211 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFaceHW (double theH, double theW, int theOrientation)
212 {
213   SetErrorCode(KO);
214
215   if (theH == 0 || theW == 0) return NULL;
216
217   //Add a new Face object
218   Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
219
220   //Add a new Box function for creation a box relatively to two points
221   Handle(GEOM_Function) aFunction = aFace->AddFunction(GEOMImpl_FaceDriver::GetID(), FACE_H_W);
222   if (aFunction.IsNull()) return NULL;
223
224   //Check if the function is set correctly
225   if (aFunction->GetDriverGUID() != GEOMImpl_FaceDriver::GetID()) return aFace;
226
227   GEOMImpl_IFace aFI (aFunction);
228
229   aFI.SetH(theH);
230   aFI.SetW(theW);
231   aFI.SetOrientation(theOrientation);
232
233   //Compute the Face
234   try {
235     OCC_CATCH_SIGNALS;
236     if (!GetSolver()->ComputeFunction(aFunction)) {
237       SetErrorCode("Face driver failed");
238       return NULL;
239     }
240   }
241   catch (Standard_Failure) {
242     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
243     SetErrorCode(aFail->GetMessageString());
244     return NULL;
245   }
246
247   //Make a Python command
248   GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFaceHW("
249     << theH << ", " << theW << ", " << theOrientation << ")";
250
251   SetErrorCode(OK);
252   return aFace;
253 }
254
255 //=============================================================================
256 /*!
257  *  MakeFaceObjHW
258  */
259 //=============================================================================
260 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFaceObjHW (Handle(GEOM_Object) theObj,
261                                                                double theH, double theW)
262 {
263   SetErrorCode(KO);
264
265   if (theObj.IsNull()) return NULL;
266
267   //Add a new Face object
268   Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
269
270   //Add a new Box function for creation a box relatively to two points
271   Handle(GEOM_Function) aFunction = aFace->AddFunction(GEOMImpl_FaceDriver::GetID(), FACE_OBJ_H_W);
272   if (aFunction.IsNull()) return NULL;
273
274   //Check if the function is set correctly
275   if (aFunction->GetDriverGUID() != GEOMImpl_FaceDriver::GetID()) return aFace;
276
277   GEOMImpl_IFace aFI (aFunction);
278
279   Handle(GEOM_Function) aRefFunction1 = theObj->GetLastFunction();
280
281   if (aRefFunction1.IsNull())
282     return aFace;
283
284   aFI.SetRef1(aRefFunction1);
285   aFI.SetH(theH);
286   aFI.SetW(theW);
287
288   //Compute the Face
289   try {
290     OCC_CATCH_SIGNALS;
291     if (!GetSolver()->ComputeFunction(aFunction)) {
292       SetErrorCode("Face driver failed");
293       return NULL;
294     }
295   }
296   catch (Standard_Failure) {
297     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
298     SetErrorCode(aFail->GetMessageString());
299     return NULL;
300   }
301
302   //Make a Python command
303   GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFaceObjHW("
304     << theObj << ", " << theH << ", " << theW << ")";
305
306   SetErrorCode(OK);
307   return aFace;
308 }
309
310 //=============================================================================
311 /*!
312  *  MakeDiskPntVecR
313  */
314 //=============================================================================
315 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskPntVecR
316       (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
317 {
318   SetErrorCode(KO);
319
320   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
321
322   //Add a new Disk object
323   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
324
325   //Add a new Disk function for creation a disk relatively to point and vector
326   Handle(GEOM_Function) aFunction =
327     aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_PNT_VEC_R);
328   if (aFunction.IsNull()) return NULL;
329
330   //Check if the function is set correctly
331   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return NULL;
332
333   GEOMImpl_IDisk aCI (aFunction);
334
335   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
336   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
337
338   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
339
340   aCI.SetCenter(aRefPnt);
341   aCI.SetVector(aRefVec);
342   aCI.SetRadius(theR);
343
344   //Compute the Disk value
345   try {
346     OCC_CATCH_SIGNALS;
347     if (!GetSolver()->ComputeFunction(aFunction)) {
348       SetErrorCode("Disk driver failed");
349       return NULL;
350     }
351   }
352   catch (Standard_Failure) {
353     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
354     SetErrorCode(aFail->GetMessageString());
355     return NULL;
356   }
357
358   //Make a Python command
359   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskPntVecR("
360     << thePnt << ", " << theVec << ", " << theR << ")";
361
362   SetErrorCode(OK);
363   return aDisk;
364 }
365
366 //=============================================================================
367 /*!
368  *  MakeDiskThreePnt
369  */
370 //=============================================================================
371 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskThreePnt (Handle(GEOM_Object) thePnt1,
372                                                                   Handle(GEOM_Object) thePnt2,
373                                                                   Handle(GEOM_Object) thePnt3)
374 {
375   SetErrorCode(KO);
376
377   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
378
379   //Add a new Disk object
380   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
381
382   //Add a new Disk function for creation a disk relatively to three points
383   Handle(GEOM_Function) aFunction =
384     aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_THREE_PNT);
385   if (aFunction.IsNull()) return NULL;
386
387   //Check if the function is set correctly
388   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return NULL;
389
390   GEOMImpl_IDisk aCI (aFunction);
391
392   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
393   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
394   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
395
396   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
397
398   aCI.SetPoint1(aRefPnt1);
399   aCI.SetPoint2(aRefPnt2);
400   aCI.SetPoint3(aRefPnt3);
401
402   //Compute the Disk value
403   try {
404     OCC_CATCH_SIGNALS;
405     if (!GetSolver()->ComputeFunction(aFunction)) {
406       SetErrorCode("Disk driver failed");
407       return NULL;
408     }
409   }
410   catch (Standard_Failure) {
411     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
412     SetErrorCode(aFail->GetMessageString());
413     return NULL;
414   }
415
416   //Make a Python command
417   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskThreePnt("
418     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
419
420   SetErrorCode(OK);
421   return aDisk;
422 }
423
424 //=============================================================================
425 /*!
426  *  MakeDiskR
427  */
428 //=============================================================================
429 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskR (double theR, int theOrientation)
430 {
431   SetErrorCode(KO);
432
433   if (theR == 0 ) return NULL;
434
435   //Add a new Disk object
436   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
437
438   //Add a new Box function for creation a box relatively to two points
439   Handle(GEOM_Function) aFunction = aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_R);
440   if (aFunction.IsNull()) return NULL;
441
442   //Check if the function is set correctly
443   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return aDisk;
444
445   GEOMImpl_IDisk aDI (aFunction);
446
447   aDI.SetRadius(theR);
448   aDI.SetOrientation(theOrientation);
449
450   //Compute the Disk
451   try {
452     OCC_CATCH_SIGNALS;
453     if (!GetSolver()->ComputeFunction(aFunction)) {
454       SetErrorCode("Disk driver failed");
455       return NULL;
456     }
457   }
458   catch (Standard_Failure) {
459     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
460     SetErrorCode(aFail->GetMessageString());
461     return NULL;
462   }
463
464   //Make a Python command
465   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskR("
466     << theR << ", " << theOrientation << ")";
467
468   SetErrorCode(OK);
469   return aDisk;
470 }
471
472 //=============================================================================
473 /*!
474  *  MakeCylinderRH
475  */
476 //=============================================================================
477 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRH (double theR, double theH)
478 {
479   SetErrorCode(KO);
480
481   //Add a new Cylinder object
482   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
483
484   //Add a new Cylinder function with R and H parameters
485   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H);
486   if (aFunction.IsNull()) return NULL;
487
488   //Check if the function is set correctly
489   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
490
491   GEOMImpl_ICylinder aCI (aFunction);
492
493   aCI.SetR(theR);
494   aCI.SetH(theH);
495
496   //Compute the Cylinder value
497   try {
498     OCC_CATCH_SIGNALS;
499     if (!GetSolver()->ComputeFunction(aFunction)) {
500       SetErrorCode("Cylinder driver failed");
501       return NULL;
502     }
503   }
504   catch (Standard_Failure) {
505     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
506     SetErrorCode(aFail->GetMessageString());
507     return NULL;
508   }
509
510   //Make a Python command
511   GEOM::TPythonDump(aFunction) << aCylinder
512     << " = geompy.MakeCylinderRH(" << theR << ", " << theH << ")";
513
514   SetErrorCode(OK);
515   return aCylinder;
516 }
517
518 //=============================================================================
519 /*!
520  *  MakeCylinderRHA
521  */
522 //=============================================================================
523 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRHA (double theR, double theH, double theA)
524 {
525   SetErrorCode(KO);
526
527   //Add a new Cylinder object
528   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
529
530   //Add a new Cylinder function with R and H parameters
531   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H_A);
532   if (aFunction.IsNull()) return NULL;
533
534   //Check if the function is set correctly
535   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
536
537   GEOMImpl_ICylinder aCI (aFunction);
538
539   aCI.SetR(theR);
540   aCI.SetH(theH);
541   aCI.SetA(theA);
542
543   //Compute the Cylinder value
544   try {
545     OCC_CATCH_SIGNALS;
546     if (!GetSolver()->ComputeFunction(aFunction)) {
547       SetErrorCode("Cylinder 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(aFunction) << aCylinder
559     << " = geompy.MakeCylinderRHA(" << theR << ", " << theH << ", " << theA*180./M_PI << "*math.pi/180.)";
560
561   SetErrorCode(OK);
562   return aCylinder;
563 }
564
565 //=============================================================================
566 /*!
567  *  MakeCylinderPntVecRH
568  */
569 //=============================================================================
570 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRH (Handle(GEOM_Object) thePnt,
571                                                                       Handle(GEOM_Object) theVec,
572                                                                       double theR, double theH)
573 {
574   SetErrorCode(KO);
575
576   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
577
578   //Add a new Cylinder object
579   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
580
581   //Add a new Cylinder function for creation a cylinder relatively to point and vector
582   Handle(GEOM_Function) aFunction =
583     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H);
584   if (aFunction.IsNull()) return NULL;
585
586   //Check if the function is set correctly
587   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
588
589   GEOMImpl_ICylinder aCI (aFunction);
590
591   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
592   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
593
594   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
595
596   aCI.SetPoint(aRefPnt);
597   aCI.SetVector(aRefVec);
598   aCI.SetR(theR);
599   aCI.SetH(theH);
600
601   //Compute the Cylinder value
602   try {
603     OCC_CATCH_SIGNALS;
604     if (!GetSolver()->ComputeFunction(aFunction)) {
605       SetErrorCode("Cylinder driver failed");
606       return NULL;
607     }
608   }
609   catch (Standard_Failure) {
610     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
611     SetErrorCode(aFail->GetMessageString());
612     return NULL;
613   }
614
615   //Make a Python command
616   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinder("
617     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ")";
618
619   SetErrorCode(OK);
620   return aCylinder;
621 }
622
623 //=============================================================================
624 /*!
625  *  MakeCylinderPntVecRHA
626  */
627 //=============================================================================
628 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRHA (Handle(GEOM_Object) thePnt,
629                                                                        Handle(GEOM_Object) theVec,
630                                                                        double theR, double theH, double theA)
631 {
632   SetErrorCode(KO);
633
634   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
635
636   //Add a new Cylinder object
637   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
638
639   //Add a new Cylinder function for creation a cylinder relatively to point and vector
640   Handle(GEOM_Function) aFunction =
641     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H_A);
642   if (aFunction.IsNull()) return NULL;
643
644   //Check if the function is set correctly
645   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
646
647   GEOMImpl_ICylinder aCI (aFunction);
648
649   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
650   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
651
652   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
653
654   aCI.SetPoint(aRefPnt);
655   aCI.SetVector(aRefVec);
656   aCI.SetR(theR);
657   aCI.SetH(theH);
658   aCI.SetA(theA);
659
660   //Compute the Cylinder value
661   try {
662     OCC_CATCH_SIGNALS;
663     if (!GetSolver()->ComputeFunction(aFunction)) {
664       SetErrorCode("Cylinder driver failed");
665       return NULL;
666     }
667   }
668   catch (Standard_Failure) {
669     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
670     SetErrorCode(aFail->GetMessageString());
671     return NULL;
672   }
673
674   //Make a Python command
675   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinderA("
676     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ", " << theA*180./M_PI << "*math.pi/180.)";
677
678   SetErrorCode(OK);
679   return aCylinder;
680 }
681
682
683 //=============================================================================
684 /*!
685  *  MakeConeR1R2H
686  */
687 //=============================================================================
688 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConeR1R2H (double theR1, double theR2,
689                                                                double theH)
690 {
691   SetErrorCode(KO);
692
693   //Add a new Cone object
694   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
695
696   //Add a new Cone function with R and H parameters
697   Handle(GEOM_Function) aFunction =
698     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_R1_R2_H);
699   if (aFunction.IsNull()) return NULL;
700
701   //Check if the function is set correctly
702   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
703
704   GEOMImpl_ICone aCI (aFunction);
705
706   aCI.SetR1(theR1);
707   aCI.SetR2(theR2);
708   aCI.SetH(theH);
709
710   //Compute the Cone value
711   try {
712     OCC_CATCH_SIGNALS;
713     if (!GetSolver()->ComputeFunction(aFunction)) {
714       SetErrorCode("Cone driver failed");
715       return NULL;
716     }
717   }
718   catch (Standard_Failure) {
719     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
720     SetErrorCode(aFail->GetMessageString());
721     return NULL;
722   }
723
724   //Make a Python command
725   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeConeR1R2H("
726     << theR1 << ", " << theR2 << ", " << theH << ")";
727
728   SetErrorCode(OK);
729   return aCone;
730 }
731
732
733 //=============================================================================
734 /*!
735  *  MakeConePntVecR1R2H
736  */
737 //=============================================================================
738 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConePntVecR1R2H (Handle(GEOM_Object) thePnt,
739                                                                      Handle(GEOM_Object) theVec,
740                                                                      double theR1, double theR2,
741                                                                      double theH)
742 {
743   SetErrorCode(KO);
744
745   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
746
747   //Add a new Cone object
748   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
749
750   //Add a new Cone function for creation a cone relatively to point and vector
751   Handle(GEOM_Function) aFunction =
752     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_PNT_VEC_R1_R2_H);
753   if (aFunction.IsNull()) return NULL;
754
755   //Check if the function is set correctly
756   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
757
758   GEOMImpl_ICone aCI (aFunction);
759
760   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
761   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
762
763   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
764
765   aCI.SetPoint(aRefPnt);
766   aCI.SetVector(aRefVec);
767   aCI.SetR1(theR1);
768   aCI.SetR2(theR2);
769   aCI.SetH(theH);
770
771   //Compute the Cone value
772   try {
773     OCC_CATCH_SIGNALS;
774     if (!GetSolver()->ComputeFunction(aFunction)) {
775       SetErrorCode("Cone driver failed");
776       return NULL;
777     }
778   }
779   catch (Standard_Failure) {
780     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
781     SetErrorCode(aFail->GetMessageString());
782     return NULL;
783   }
784
785   //Make a Python command
786   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeCone(" << thePnt
787     << ", " << theVec << ", " << theR1 << ", " << theR2 << ", " << theH << ")";
788
789   SetErrorCode(OK);
790   return aCone;
791 }
792
793
794 //=============================================================================
795 /*!
796  *  MakeSphereR
797  */
798 //=============================================================================
799 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSphereR (double theR)
800 {
801   SetErrorCode(KO);
802
803   //Add a new Sphere object
804   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
805
806   //Add a new Sphere function with R parameter
807   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_R);
808   if (aFunction.IsNull()) return NULL;
809
810   //Check if the function is set correctly
811   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
812
813   GEOMImpl_ISphere aCI (aFunction);
814
815   aCI.SetR(theR);
816
817   //Compute the Sphere value
818   try {
819     OCC_CATCH_SIGNALS;
820     if (!GetSolver()->ComputeFunction(aFunction)) {
821       SetErrorCode("Sphere driver failed");
822       return NULL;
823     }
824   }
825   catch (Standard_Failure) {
826     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
827     SetErrorCode(aFail->GetMessageString());
828     return NULL;
829   }
830
831   //Make a Python command
832   GEOM::TPythonDump(aFunction) << aSphere << " = geompy.MakeSphereR(" << theR << ")";
833
834   SetErrorCode(OK);
835   return aSphere;
836 }
837
838
839 //=============================================================================
840 /*!
841  *  MakeSpherePntR
842  */
843 //=============================================================================
844 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSpherePntR (Handle(GEOM_Object) thePnt,
845                                                                 double theR)
846 {
847   SetErrorCode(KO);
848
849   if (thePnt.IsNull()) return NULL;
850
851   //Add a new Point object
852   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
853
854   //Add a new Sphere function for creation a sphere relatively to point
855   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_PNT_R);
856   if (aFunction.IsNull()) return NULL;
857
858   //Check if the function is set correctly
859   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
860
861   GEOMImpl_ISphere aCI (aFunction);
862
863   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
864
865   if (aRefPnt.IsNull()) return NULL;
866
867   aCI.SetPoint(aRefPnt);
868   aCI.SetR(theR);
869
870   //Compute the Sphere value
871   try {
872     OCC_CATCH_SIGNALS;
873     if (!GetSolver()->ComputeFunction(aFunction)) {
874       SetErrorCode("Sphere driver failed");
875       return NULL;
876     }
877   }
878   catch (Standard_Failure) {
879     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
880     SetErrorCode(aFail->GetMessageString());
881     return NULL;
882   }
883
884   //Make a Python command
885   GEOM::TPythonDump(aFunction) << aSphere
886     << " = geompy.MakeSpherePntR(" << thePnt << ", " << theR << ")";
887
888   SetErrorCode(OK);
889   return aSphere;
890 }
891
892
893 //=============================================================================
894 /*!
895  *  MakeTorusRR
896  */
897 //=============================================================================
898 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusRR
899                                            (double theRMajor, double theRMinor)
900 {
901   SetErrorCode(KO);
902
903   //Add a new Torus object
904   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
905
906   //Add a new Torus function
907   Handle(GEOM_Function) aFunction =
908     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_RR);
909   if (aFunction.IsNull()) return NULL;
910
911   //Check if the function is set correctly
912   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
913
914   GEOMImpl_ITorus aCI (aFunction);
915
916   aCI.SetRMajor(theRMajor);
917   aCI.SetRMinor(theRMinor);
918
919   //Compute the Torus value
920   try {
921     OCC_CATCH_SIGNALS;
922     if (!GetSolver()->ComputeFunction(aFunction)) {
923       SetErrorCode("Torus driver failed");
924       return NULL;
925     }
926   }
927   catch (Standard_Failure) {
928     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
929     SetErrorCode(aFail->GetMessageString());
930     return NULL;
931   }
932
933   //Make a Python command
934   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorusRR("
935     << theRMajor << ", " << theRMinor << ")";
936
937   SetErrorCode(OK);
938   return anEll;
939 }
940
941 //=============================================================================
942 /*!
943  *  MakeTorusPntVecRR
944  */
945 //=============================================================================
946 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusPntVecRR
947                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
948                         double theRMajor, double theRMinor)
949 {
950   SetErrorCode(KO);
951
952   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
953
954   //Add a new Torus object
955   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
956
957   //Add a new Torus function
958   Handle(GEOM_Function) aFunction =
959     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_PNT_VEC_RR);
960   if (aFunction.IsNull()) return NULL;
961
962   //Check if the function is set correctly
963   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
964
965   GEOMImpl_ITorus aCI (aFunction);
966
967   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
968   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
969
970   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
971
972   aCI.SetCenter(aRefPnt);
973   aCI.SetVector(aRefVec);
974   aCI.SetRMajor(theRMajor);
975   aCI.SetRMinor(theRMinor);
976
977   //Compute the Torus value
978   try {
979     OCC_CATCH_SIGNALS;
980     if (!GetSolver()->ComputeFunction(aFunction)) {
981       SetErrorCode("Torus driver failed");
982       return NULL;
983     }
984   }
985   catch (Standard_Failure) {
986     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
987     SetErrorCode(aFail->GetMessageString());
988     return NULL;
989   }
990
991   //Make a Python command
992   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorus(" << thePnt
993     << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
994
995   SetErrorCode(OK);
996   return anEll;
997 }
998
999
1000 //=============================================================================
1001 /*!
1002  *  MakePrismVecH
1003  */
1004 //=============================================================================
1005 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH (Handle(GEOM_Object) theBase,
1006                                                                Handle(GEOM_Object) theVec,
1007                                                                double theH, double theScaleFactor)
1008 {
1009   SetErrorCode(KO);
1010
1011   if (theBase.IsNull() || theVec.IsNull()) return NULL;
1012
1013   //Add a new Prism object
1014   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1015
1016   //Add a new Prism function for creation a Prism relatively to vector
1017   Handle(GEOM_Function) aFunction =
1018     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H);
1019   if (aFunction.IsNull()) return NULL;
1020
1021   //Check if the function is set correctly
1022   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1023
1024   GEOMImpl_IPrism aCI (aFunction);
1025
1026   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1027   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
1028
1029   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
1030
1031   aCI.SetBase(aRefBase);
1032   aCI.SetVector(aRefVec);
1033   aCI.SetH(theH);
1034   aCI.SetScale(theScaleFactor);
1035
1036   //Compute the Prism value
1037   try {
1038     OCC_CATCH_SIGNALS;
1039     if (!GetSolver()->ComputeFunction(aFunction)) {
1040       //SetErrorCode("Prism driver failed");
1041       SetErrorCode("Extrusion can not be created, check input data");
1042       return NULL;
1043     }
1044   }
1045   catch (Standard_Failure) {
1046     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1047     SetErrorCode(aFail->GetMessageString());
1048     return NULL;
1049   }
1050
1051   //Make a Python command
1052   GEOM::TPythonDump pd (aFunction);
1053   pd << aPrism << " = geompy.MakePrismVecH(" << theBase << ", " << theVec << ", " << theH;
1054   if (theScaleFactor > Precision::Confusion())
1055     pd << ", " << theScaleFactor << ")";
1056   else
1057     pd << ")";
1058
1059   SetErrorCode(OK);
1060   return aPrism;
1061 }
1062
1063 //=============================================================================
1064 /*!
1065  *  MakePrismVecH2Ways
1066  */
1067 //=============================================================================
1068 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH2Ways (Handle(GEOM_Object) theBase,
1069                                                                     Handle(GEOM_Object) theVec,
1070                                                                     double theH)
1071 {
1072   SetErrorCode(KO);
1073
1074   if (theBase.IsNull() || theVec.IsNull()) return NULL;
1075
1076   //Add a new Prism object
1077   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1078
1079   //Add a new Prism function for creation a Prism relatively to vector
1080   Handle(GEOM_Function) aFunction =
1081     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H_2WAYS);
1082   if (aFunction.IsNull()) return NULL;
1083
1084   //Check if the function is set correctly
1085   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1086
1087   GEOMImpl_IPrism aCI (aFunction);
1088
1089   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1090   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
1091
1092   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
1093
1094   aCI.SetBase(aRefBase);
1095   aCI.SetVector(aRefVec);
1096   aCI.SetH(theH);
1097
1098   //Compute the Prism value
1099   try {
1100     OCC_CATCH_SIGNALS;
1101     if (!GetSolver()->ComputeFunction(aFunction)) {
1102       //SetErrorCode("Prism driver failed");
1103       SetErrorCode("Extrusion can not be created, check input data");
1104       return NULL;
1105     }
1106   }
1107   catch (Standard_Failure) {
1108     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1109     SetErrorCode(aFail->GetMessageString());
1110     return NULL;
1111   }
1112
1113   //Make a Python command
1114   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismVecH2Ways("
1115     << theBase << ", " << theVec << ", " << theH << ")";
1116
1117   SetErrorCode(OK);
1118   return aPrism;
1119 }
1120
1121 //=============================================================================
1122 /*!
1123  *  MakePrismTwoPnt
1124  */
1125 //=============================================================================
1126 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
1127        (Handle(GEOM_Object) theBase,
1128         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2,
1129         double theScaleFactor)
1130 {
1131   SetErrorCode(KO);
1132
1133   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1134
1135   //Add a new Prism object
1136   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1137
1138   //Add a new Prism function for creation a Prism relatively to two points
1139   Handle(GEOM_Function) aFunction =
1140     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
1141   if (aFunction.IsNull()) return NULL;
1142
1143   //Check if the function is set correctly
1144   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1145
1146   GEOMImpl_IPrism aCI (aFunction);
1147
1148   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1149   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
1150   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
1151
1152   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
1153
1154   aCI.SetBase(aRefBase);
1155   aCI.SetFirstPoint(aRefPnt1);
1156   aCI.SetLastPoint(aRefPnt2);
1157   aCI.SetScale(theScaleFactor);
1158
1159   //Compute the Prism value
1160   try {
1161     OCC_CATCH_SIGNALS;
1162     if (!GetSolver()->ComputeFunction(aFunction)) {
1163       //SetErrorCode("Prism driver failed");
1164       SetErrorCode("Extrusion can not be created, check input data");
1165       return NULL;
1166     }
1167   }
1168   catch (Standard_Failure) {
1169     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1170     SetErrorCode(aFail->GetMessageString());
1171     return NULL;
1172   }
1173
1174   //Make a Python command
1175   GEOM::TPythonDump pd (aFunction);
1176   pd << aPrism << " = geompy.MakePrism(" << theBase << ", " << thePoint1 << ", " << thePoint2;
1177   if (theScaleFactor > Precision::Confusion())
1178     pd << ", " << theScaleFactor << ")";
1179   else
1180     pd << ")";
1181
1182   SetErrorCode(OK);
1183   return aPrism;
1184 }
1185
1186 //=============================================================================
1187 /*!
1188  *  MakePrismTwoPnt2Ways
1189  */
1190 //=============================================================================
1191 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt2Ways
1192        (Handle(GEOM_Object) theBase,
1193         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
1194 {
1195   SetErrorCode(KO);
1196
1197   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1198
1199   //Add a new Prism object
1200   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1201
1202   //Add a new Prism function for creation a Prism relatively to two points
1203   Handle(GEOM_Function) aFunction =
1204     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT_2WAYS);
1205   if (aFunction.IsNull()) return NULL;
1206
1207   //Check if the function is set correctly
1208   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1209
1210   GEOMImpl_IPrism aCI (aFunction);
1211
1212   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1213   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
1214   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
1215
1216   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
1217
1218   aCI.SetBase(aRefBase);
1219   aCI.SetFirstPoint(aRefPnt1);
1220   aCI.SetLastPoint(aRefPnt2);
1221
1222   //Compute the Prism value
1223   try {
1224     OCC_CATCH_SIGNALS;
1225     if (!GetSolver()->ComputeFunction(aFunction)) {
1226       //SetErrorCode("Prism driver failed");
1227       SetErrorCode("Extrusion can not be created, check input data");
1228       return NULL;
1229     }
1230   }
1231   catch (Standard_Failure) {
1232     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1233     SetErrorCode(aFail->GetMessageString());
1234     return NULL;
1235   }
1236
1237   //Make a Python command
1238   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism2Ways("
1239     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
1240
1241   SetErrorCode(OK);
1242   return aPrism;
1243 }
1244
1245 //=============================================================================
1246 /*!
1247  *  MakePrismDXDYDZ
1248  */
1249 //=============================================================================
1250 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ
1251        (Handle(GEOM_Object) theBase, double theDX, double theDY, double theDZ,
1252         double theScaleFactor)
1253 {
1254   SetErrorCode(KO);
1255
1256   if (theBase.IsNull()) return NULL;
1257
1258   //Add a new Prism object
1259   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1260
1261   //Add a new Prism function for creation a Prism by DXDYDZ
1262   Handle(GEOM_Function) aFunction =
1263     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_DXDYDZ);
1264   if (aFunction.IsNull()) return NULL;
1265
1266   //Check if the function is set correctly
1267   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1268
1269   GEOMImpl_IPrism aCI (aFunction);
1270
1271   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1272
1273   if (aRefBase.IsNull()) return NULL;
1274
1275   aCI.SetBase(aRefBase);
1276   aCI.SetDX(theDX);
1277   aCI.SetDY(theDY);
1278   aCI.SetDZ(theDZ);
1279   aCI.SetScale(theScaleFactor);
1280
1281   //Compute the Prism value
1282   try {
1283     OCC_CATCH_SIGNALS;
1284     if (!GetSolver()->ComputeFunction(aFunction)) {
1285       SetErrorCode("Extrusion can not be created, check input data");
1286       return NULL;
1287     }
1288   }
1289   catch (Standard_Failure) {
1290     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1291     SetErrorCode(aFail->GetMessageString());
1292     return NULL;
1293   }
1294
1295   //Make a Python command
1296   GEOM::TPythonDump pd (aFunction);
1297   pd << aPrism << " = geompy.MakePrismDXDYDZ("
1298      << theBase << ", " << theDX << ", " << theDY << ", " << theDZ;
1299   if (theScaleFactor > Precision::Confusion())
1300     pd << ", " << theScaleFactor << ")";
1301   else
1302     pd << ")";
1303
1304   SetErrorCode(OK);
1305   return aPrism;
1306 }
1307
1308 //=============================================================================
1309 /*!
1310  *  MakePrismDXDYDZ_2WAYS
1311  */
1312 //=============================================================================
1313 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ2Ways
1314        (Handle(GEOM_Object) theBase, double theDX, double theDY, double theDZ)
1315 {
1316   SetErrorCode(KO);
1317
1318   if (theBase.IsNull()) return NULL;
1319
1320   //Add a new Prism object
1321   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1322
1323   //Add a new Prism function for creation a Prism by DXDYDZ
1324   Handle(GEOM_Function) aFunction =
1325     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_DXDYDZ_2WAYS);
1326   if (aFunction.IsNull()) return NULL;
1327
1328   //Check if the function is set correctly
1329   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1330
1331   GEOMImpl_IPrism aCI (aFunction);
1332
1333   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1334
1335   if (aRefBase.IsNull()) return NULL;
1336
1337   aCI.SetBase(aRefBase);
1338   aCI.SetDX(theDX);
1339   aCI.SetDY(theDY);
1340   aCI.SetDZ(theDZ);
1341
1342   //Compute the Prism value
1343   try {
1344     OCC_CATCH_SIGNALS;
1345     if (!GetSolver()->ComputeFunction(aFunction)) {
1346       SetErrorCode("Extrusion can not be created, check input data");
1347       return NULL;
1348     }
1349   }
1350   catch (Standard_Failure) {
1351     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1352     SetErrorCode(aFail->GetMessageString());
1353     return NULL;
1354   }
1355
1356   //Make a Python command
1357   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismDXDYDZ2Ways("
1358     << theBase << ", " << theDX << ", " << theDY << ", " << theDZ << ")";
1359
1360   SetErrorCode(OK);
1361   return aPrism;
1362 }
1363
1364 //=============================================================================
1365 /*!
1366  *  MakeDraftPrism
1367  */
1368 //=============================================================================
1369 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDraftPrism
1370        (Handle(GEOM_Object) theInitShape ,Handle(GEOM_Object) theBase, double theHeight, double theAngle, bool theFuse, bool theInvert)
1371 {
1372   SetErrorCode(KO);
1373
1374   if (theBase.IsNull() || theInitShape.IsNull()) return NULL;
1375
1376   Handle(GEOM_Object) aPrism = NULL;
1377   
1378   if ( theFuse )
1379   {
1380     //Add a new Extruded Boss object  
1381     aPrism = GetEngine()->AddObject(GetDocID(), GEOM_EXTRUDED_BOSS);
1382   }
1383   else
1384   { 
1385     //Add a new Extruded Cut object  
1386     aPrism = GetEngine()->AddObject(GetDocID(), GEOM_EXTRUDED_CUT);
1387   }
1388   
1389   //Add a new Prism function for the creation of a Draft Prism feature
1390   Handle(GEOM_Function) aFunction = 
1391     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), DRAFT_PRISM_FEATURE);
1392   if (aFunction.IsNull()) return NULL;
1393   
1394   //Check if the function is set correctly
1395   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1396   
1397   GEOMImpl_IPrism aCI (aFunction);
1398
1399   Handle(GEOM_Function) aRefInit = theInitShape->GetLastFunction();
1400   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1401  
1402   if (aRefBase.IsNull() || aRefInit.IsNull()) return NULL;
1403   
1404   // Set parameters 
1405   aCI.SetBase(aRefBase);
1406   aCI.SetInitShape(aRefInit);
1407   aCI.SetH(theHeight);
1408   aCI.SetDraftAngle(theAngle);
1409   if ( theFuse )
1410     aCI.SetFuseFlag(1);
1411   else
1412     aCI.SetFuseFlag(0);
1413   aCI.SetInvertFlag(theInvert);
1414   
1415   //Compute the Draft Prism Feature value
1416   try {
1417     OCC_CATCH_SIGNALS;
1418     if (!GetSolver()->ComputeFunction(aFunction)) {
1419       SetErrorCode("Extrusion can not be created, check input data");
1420       return NULL;
1421     }
1422   }
1423   catch (Standard_Failure) {
1424     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1425     SetErrorCode(aFail->GetMessageString());
1426     return NULL;
1427   }
1428   
1429   //Make a Python command
1430   GEOM::TPythonDump pd (aFunction);
1431   if(theFuse)
1432   {
1433     pd << aPrism << " = geompy.MakeExtrudedBoss(" << theInitShape << ", " << theBase << ", "
1434       << theHeight << ", " << theAngle;
1435   }
1436   else
1437   {   
1438     pd << aPrism << " = geompy.MakeExtrudedCut(" << theInitShape << ", " << theBase << ", "
1439       << theHeight << ", " << theAngle;
1440   }
1441   if (theInvert)
1442     pd << ", " << theInvert;
1443   pd << ")";
1444
1445   SetErrorCode(OK);
1446   return aPrism;
1447 }
1448
1449 //=============================================================================
1450 /*!
1451  *  MakePipe
1452  */
1453 //=============================================================================
1454 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
1455                                                           Handle(GEOM_Object) thePath)
1456 {
1457   SetErrorCode(KO);
1458
1459   if (theBase.IsNull() || thePath.IsNull()) return NULL;
1460
1461   //Add a new Pipe object
1462   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1463
1464   //Add a new Pipe function
1465   Handle(GEOM_Function) aFunction =
1466     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
1467   if (aFunction.IsNull()) return NULL;
1468
1469   //Check if the function is set correctly
1470   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
1471
1472   GEOMImpl_IPipe aCI (aFunction);
1473
1474   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1475   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1476
1477   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
1478
1479   aCI.SetBase(aRefBase);
1480   aCI.SetPath(aRefPath);
1481
1482   //Compute the Pipe value
1483   try {
1484     OCC_CATCH_SIGNALS;
1485     if (!GetSolver()->ComputeFunction(aFunction)) {
1486       SetErrorCode("Pipe driver failed");
1487       return NULL;
1488     }
1489   }
1490   catch (Standard_Failure) {
1491     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1492     SetErrorCode(aFail->GetMessageString());
1493     return NULL;
1494   }
1495
1496   //Make a Python command
1497   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipe("
1498     << theBase << ", " << thePath << ")";
1499
1500   SetErrorCode(OK);
1501   return aPipe;
1502 }
1503
1504
1505 //=============================================================================
1506 /*!
1507  *  MakeRevolutionAxisAngle
1508  */
1509 //=============================================================================
1510 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
1511                                                                          Handle(GEOM_Object) theAxis,
1512                                                                          double theAngle)
1513 {
1514   SetErrorCode(KO);
1515
1516   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
1517
1518   //Add a new Revolution object
1519   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
1520
1521   //Add a new Revolution function for creation a revolution relatively to axis
1522   Handle(GEOM_Function) aFunction =
1523     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
1524   if (aFunction.IsNull()) return NULL;
1525
1526   //Check if the function is set correctly
1527   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
1528
1529   GEOMImpl_IRevolution aCI (aFunction);
1530
1531   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1532   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
1533
1534   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
1535
1536   aCI.SetBase(aRefBase);
1537   aCI.SetAxis(aRefAxis);
1538   aCI.SetAngle(theAngle);
1539
1540   //Compute the Revolution value
1541   try {
1542     OCC_CATCH_SIGNALS;
1543     if (!GetSolver()->ComputeFunction(aFunction)) {
1544       SetErrorCode("Revolution driver failed");
1545       return NULL;
1546     }
1547   }
1548   catch (Standard_Failure) {
1549     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1550     SetErrorCode(aFail->GetMessageString());
1551     return NULL;
1552   }
1553
1554   //Make a Python command
1555   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
1556     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1557   
1558   SetErrorCode(OK);
1559   return aRevolution;
1560 }
1561
1562 //=============================================================================
1563 /*!
1564  *  MakeRevolutionAxisAngle2Ways
1565  */
1566 //=============================================================================
1567 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle2Ways
1568                    (Handle(GEOM_Object) theBase, Handle(GEOM_Object) theAxis, double theAngle)
1569 {
1570   SetErrorCode(KO);
1571
1572   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
1573
1574   //Add a new Revolution object
1575   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
1576
1577   //Add a new Revolution function for creation a revolution relatively to axis
1578   Handle(GEOM_Function) aFunction =
1579     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE_2WAYS);
1580   if (aFunction.IsNull()) return NULL;
1581
1582   //Check if the function is set correctly
1583   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
1584
1585   GEOMImpl_IRevolution aCI (aFunction);
1586
1587   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1588   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
1589
1590   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
1591
1592   aCI.SetBase(aRefBase);
1593   aCI.SetAxis(aRefAxis);
1594   aCI.SetAngle(theAngle);
1595
1596   //Compute the Revolution value
1597   try {
1598     OCC_CATCH_SIGNALS;
1599     if (!GetSolver()->ComputeFunction(aFunction)) {
1600       SetErrorCode("Revolution driver failed");
1601       return NULL;
1602     }
1603   }
1604   catch (Standard_Failure) {
1605     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1606     SetErrorCode(aFail->GetMessageString());
1607     return NULL;
1608   }
1609
1610   //Make a Python command
1611   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution2Ways("
1612     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1613
1614   SetErrorCode(OK);
1615   return aRevolution;
1616 }
1617
1618 //=============================================================================
1619 /*!
1620  *  MakeFilling
1621  */
1622 //=============================================================================
1623 Handle(GEOM_Object)
1624 GEOMImpl_I3DPrimOperations::MakeFilling (std::list< Handle(GEOM_Object)> & theContours,
1625                                          int theMinDeg, int theMaxDeg,
1626                                          double theTol2D, double theTol3D, int theNbIter,
1627                                          int theMethod, bool isApprox)
1628 {
1629   SetErrorCode(KO);
1630
1631   Handle(TColStd_HSequenceOfTransient) contours = GEOM_Object::GetLastFunctions( theContours );
1632   if ( contours.IsNull() || contours->IsEmpty() ) {
1633     SetErrorCode("NULL argument shape");
1634     return NULL;
1635   }
1636   //Add a new Filling object
1637   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
1638
1639   //Add a new Filling function for creation a filling  from a compound
1640   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
1641   if (aFunction.IsNull()) return NULL;
1642
1643   //Check if the function is set correctly
1644   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
1645
1646   GEOMImpl_IFilling aFI (aFunction);
1647   aFI.SetShapes(contours);
1648   aFI.SetMinDeg(theMinDeg);
1649   aFI.SetMaxDeg(theMaxDeg);
1650   aFI.SetTol2D(theTol2D);
1651   aFI.SetTol3D(theTol3D);
1652   aFI.SetNbIter(theNbIter);
1653   aFI.SetApprox(isApprox);
1654   aFI.SetMethod(theMethod);
1655
1656   //Compute the Solid value
1657   try {
1658     OCC_CATCH_SIGNALS;
1659     if (!GetSolver()->ComputeFunction(aFunction)) {
1660       SetErrorCode("Filling driver failed");
1661       return NULL;
1662     }
1663   }
1664   catch (Standard_Failure) {
1665     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1666     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
1667       SetErrorCode("B-Spline surface construction failed");
1668     else
1669       SetErrorCode(aFail->GetMessageString());
1670     return NULL;
1671   }
1672
1673   //Make a Python command
1674   GEOM::TPythonDump pd (aFunction);
1675   pd << aFilling << " = geompy.MakeFilling(" << theContours ;
1676   if ( theMinDeg != 2 )   pd << ", theMinDeg=" << theMinDeg ;
1677   if ( theMaxDeg != 5 )   pd << ", theMaxDeg=" << theMaxDeg ;
1678   if ( fabs(theTol2D-0.0001) > Precision::Confusion() )
1679   {                       pd << ", theTol2D=" << theTol2D ; }
1680   if ( fabs(theTol3D-0.0001) > Precision::Confusion() )
1681   {                       pd << ", theTol3D=" << theTol3D ; }
1682   if ( theNbIter != 0 )   pd << ", theNbIter=" << theNbIter ;
1683   if ( theMethod==1 )     pd << ", theMethod=GEOM.FOM_UseOri";
1684   else if( theMethod==2 ) pd << ", theMethod=GEOM.FOM_AutoCorrect";
1685   if ( isApprox )         pd << ", isApprox=" << isApprox ;
1686   pd << ")";
1687
1688   SetErrorCode(OK);
1689   return aFilling;
1690 }
1691
1692 //=============================================================================
1693 /*!
1694  *  MakeThruSections
1695  */
1696 //=============================================================================
1697 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThruSections(
1698                                                 const Handle(TColStd_HSequenceOfTransient)& theSeqSections,
1699                                                 bool theModeSolid,
1700                                                 double thePreci,
1701                                                 bool theRuled)
1702 {
1703   Handle(GEOM_Object) anObj;
1704   SetErrorCode(KO);
1705   if(theSeqSections.IsNull())
1706     return anObj;
1707
1708   Standard_Integer nbObj = theSeqSections->Length();
1709   if (!nbObj)
1710     return anObj;
1711
1712   //Add a new ThruSections object
1713   Handle(GEOM_Object) aThruSect = GetEngine()->AddObject(GetDocID(), GEOM_THRUSECTIONS);
1714
1715
1716   //Add a new ThruSections function
1717
1718   int aTypeFunc = (theRuled ? THRUSECTIONS_RULED : THRUSECTIONS_SMOOTHED);
1719   Handle(GEOM_Function) aFunction =
1720     aThruSect->AddFunction(GEOMImpl_ThruSectionsDriver::GetID(), aTypeFunc);
1721   if (aFunction.IsNull()) return anObj;
1722
1723   //Check if the function is set correctly
1724   if (aFunction->GetDriverGUID() != GEOMImpl_ThruSectionsDriver::GetID()) return NULL;
1725
1726   GEOMImpl_IThruSections aCI (aFunction);
1727
1728   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
1729
1730   Standard_Integer i =1;
1731   for( ; i <= nbObj; i++) {
1732
1733     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1734     if(anItem.IsNull())
1735       continue;
1736
1737     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1738     if(!aSectObj.IsNull())
1739     {
1740       Handle(GEOM_Function) aRefSect = aSectObj->GetLastFunction();
1741       if(!aRefSect.IsNull())
1742         aSeqSections->Append(aRefSect);
1743     }
1744   }
1745
1746   if(!aSeqSections->Length())
1747     return anObj;
1748
1749   aCI.SetSections(aSeqSections);
1750   aCI.SetSolidMode(theModeSolid);
1751   aCI.SetPrecision(thePreci);
1752
1753   //Compute the ThruSections value
1754   try {
1755     OCC_CATCH_SIGNALS;
1756     if (!GetSolver()->ComputeFunction(aFunction)) {
1757       SetErrorCode("ThruSections driver failed");
1758       return anObj;
1759     }
1760   }
1761   catch (Standard_Failure) {
1762     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1763     SetErrorCode(aFail->GetMessageString());
1764     return anObj;
1765   }
1766
1767   //Make a Python command
1768   GEOM::TPythonDump pyDump(aFunction);
1769   pyDump << aThruSect << " = geompy.MakeThruSections([";
1770
1771   for(i =1 ; i <= nbObj; i++) {
1772
1773     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1774     if(anItem.IsNull())
1775       continue;
1776
1777     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1778     if(!aSectObj.IsNull()) {
1779       pyDump<< aSectObj;
1780       if(i < nbObj)
1781         pyDump<<", ";
1782     }
1783   }
1784
1785   pyDump<< "],"<<theModeSolid << "," << thePreci <<","<< theRuled <<")";
1786
1787   SetErrorCode(OK);
1788   return aThruSect;
1789 }
1790
1791
1792 //=============================================================================
1793 /*!
1794  *  MakePipeWithDifferentSections
1795  */
1796 //=============================================================================
1797 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithDifferentSections(
1798                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1799                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1800                 const Handle(GEOM_Object)& thePath,
1801                 bool theWithContact,
1802                 bool theWithCorrections)
1803 {
1804   Handle(GEOM_Object) anObj;
1805   SetErrorCode(KO);
1806   if(theBases.IsNull())
1807     return anObj;
1808
1809   Standard_Integer nbBases = theBases->Length();
1810
1811   if (!nbBases)
1812     return anObj;
1813
1814   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1815   //Add a new Pipe object
1816   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1817
1818   //Add a new Pipe function
1819
1820   Handle(GEOM_Function) aFunction =
1821     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_DIFFERENT_SECTIONS);
1822   if (aFunction.IsNull()) return anObj;
1823
1824   //Check if the function is set correctly
1825   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1826
1827   GEOMImpl_IPipeDiffSect aCI (aFunction);
1828
1829   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1830   if(aRefPath.IsNull())
1831     return anObj;
1832
1833   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1834   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1835
1836   Standard_Integer i =1;
1837   for( ; i <= nbBases; i++) {
1838
1839     Handle(Standard_Transient) anItem = theBases->Value(i);
1840     if(anItem.IsNull())
1841       continue;
1842
1843     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1844     if(aBase.IsNull())
1845       continue;
1846     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1847     if(aRefBase.IsNull())
1848       continue;
1849     if(nbLocs)
1850     {
1851       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1852       if(anItemLoc.IsNull())
1853         continue;
1854
1855       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1856       if(aLoc.IsNull())
1857         continue;
1858       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1859       if(aRefLoc.IsNull())
1860         continue;
1861       aSeqLocs->Append(aRefLoc);
1862     }
1863     aSeqBases->Append(aRefBase);
1864   }
1865
1866   if(!aSeqBases->Length())
1867     return anObj;
1868
1869   aCI.SetBases(aSeqBases);
1870   aCI.SetLocations(aSeqLocs);
1871   aCI.SetPath(aRefPath);
1872   aCI.SetWithContactMode(theWithContact);
1873   aCI.SetWithCorrectionMode(theWithCorrections);
1874
1875   //Compute the Pipe value
1876   try {
1877     OCC_CATCH_SIGNALS;
1878     if (!GetSolver()->ComputeFunction(aFunction)) {
1879       SetErrorCode("Pipe with defferent section driver failed");
1880       return anObj;
1881     }
1882   }
1883   catch (Standard_Failure) {
1884     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1885     SetErrorCode(aFail->GetMessageString());
1886     return anObj;
1887   }
1888
1889   //Make a Python command
1890   GEOM::TPythonDump pyDump(aFunction);
1891   pyDump << aPipeDS << " = geompy.MakePipeWithDifferentSections([";
1892
1893   for(i =1 ; i <= nbBases; i++) {
1894
1895     Handle(Standard_Transient) anItem = theBases->Value(i);
1896     if(anItem.IsNull())
1897       continue;
1898
1899     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1900     if(!anObj.IsNull()) {
1901       pyDump<< anObj;
1902       if(i < nbBases)
1903         pyDump<<", ";
1904     }
1905   }
1906
1907   pyDump<< "], [";
1908
1909   for(i =1 ; i <= nbLocs; i++) {
1910
1911     Handle(Standard_Transient) anItem = theLocations->Value(i);
1912     if(anItem.IsNull())
1913       continue;
1914
1915     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1916     if(!anObj.IsNull()) {
1917       pyDump<< anObj;
1918       if(i < nbLocs)
1919         pyDump<<", ";
1920     }
1921   }
1922
1923   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1924
1925   SetErrorCode(OK);
1926   return aPipeDS;
1927 }
1928
1929
1930 //=============================================================================
1931 /*!
1932  *  MakePipeWithShellSections
1933  */
1934 //=============================================================================
1935 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithShellSections(
1936                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1937                 const Handle(TColStd_HSequenceOfTransient)& theSubBases,
1938                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1939                 const Handle(GEOM_Object)& thePath,
1940                 bool theWithContact,
1941                 bool theWithCorrections)
1942 {
1943   Handle(GEOM_Object) anObj;
1944   SetErrorCode(KO);
1945   if(theBases.IsNull())
1946     return anObj;
1947
1948   Standard_Integer nbBases = theBases->Length();
1949
1950   if (!nbBases)
1951     return anObj;
1952
1953   Standard_Integer nbSubBases =  (theSubBases.IsNull() ? 0 :theSubBases->Length());
1954
1955   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1956
1957   //Add a new Pipe object
1958   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1959
1960   //Add a new Pipe function
1961
1962   Handle(GEOM_Function) aFunction =
1963     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELL_SECTIONS);
1964   if (aFunction.IsNull()) return anObj;
1965
1966   //Check if the function is set correctly
1967   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1968
1969   //GEOMImpl_IPipeDiffSect aCI (aFunction);
1970   GEOMImpl_IPipeShellSect aCI (aFunction);
1971
1972   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1973   if(aRefPath.IsNull())
1974     return anObj;
1975
1976   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1977   Handle(TColStd_HSequenceOfTransient) aSeqSubBases = new TColStd_HSequenceOfTransient;
1978   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1979
1980   Standard_Integer i =1;
1981   for( ; i <= nbBases; i++) {
1982
1983     Handle(Standard_Transient) anItem = theBases->Value(i);
1984     if(anItem.IsNull())
1985       continue;
1986     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1987     if(aBase.IsNull())
1988       continue;
1989     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1990     if(aRefBase.IsNull())
1991       continue;
1992
1993     if( nbSubBases >= nbBases ) {
1994       Handle(Standard_Transient) aSubItem = theSubBases->Value(i);
1995       if(aSubItem.IsNull())
1996         continue;
1997       Handle(GEOM_Object) aSubBase = Handle(GEOM_Object)::DownCast(aSubItem);
1998       if(aSubBase.IsNull())
1999         continue;
2000       Handle(GEOM_Function) aRefSubBase = aSubBase->GetLastFunction();
2001       if(aRefSubBase.IsNull())
2002         continue;
2003       aSeqSubBases->Append(aRefSubBase);
2004     }
2005
2006     if(nbLocs) {
2007       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
2008       if(anItemLoc.IsNull())
2009         continue;
2010       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
2011       if(aLoc.IsNull())
2012         continue;
2013       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
2014       if(aRefLoc.IsNull())
2015         continue;
2016       aSeqLocs->Append(aRefLoc);
2017     }
2018
2019     aSeqBases->Append(aRefBase);
2020   }
2021
2022   if(!aSeqBases->Length())
2023     return anObj;
2024
2025   aCI.SetBases(aSeqBases);
2026   aCI.SetSubBases(aSeqSubBases);
2027   aCI.SetLocations(aSeqLocs);
2028   aCI.SetPath(aRefPath);
2029   aCI.SetWithContactMode(theWithContact);
2030   aCI.SetWithCorrectionMode(theWithCorrections);
2031
2032   //Compute the Pipe value
2033   try {
2034     OCC_CATCH_SIGNALS;
2035     if (!GetSolver()->ComputeFunction(aFunction)) {
2036       SetErrorCode("Pipe with shell sections driver failed");
2037       return anObj;
2038     }
2039   }
2040   catch (Standard_Failure) {
2041     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2042     SetErrorCode(aFail->GetMessageString());
2043     return anObj;
2044   }
2045
2046   //Make a Python command
2047   GEOM::TPythonDump pyDump(aFunction);
2048   pyDump << aPipeDS << " = geompy.MakePipeWithShellSections([";
2049
2050   for(i =1 ; i <= nbBases; i++) {
2051
2052     Handle(Standard_Transient) anItem = theBases->Value(i);
2053     if(anItem.IsNull())
2054       continue;
2055
2056     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2057     if(!anObj.IsNull()) {
2058       pyDump<< anObj;
2059       if(i < nbBases)
2060         pyDump<<", ";
2061     }
2062   }
2063
2064   pyDump<< "], [";
2065
2066   for(i =1 ; i <= nbSubBases; i++) {
2067
2068     Handle(Standard_Transient) anItem = theSubBases->Value(i);
2069     if(anItem.IsNull())
2070       continue;
2071
2072     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2073     if(!anObj.IsNull()) {
2074       pyDump<< anObj;
2075       if(i < nbBases)
2076         pyDump<<", ";
2077     }
2078   }
2079
2080   pyDump<< "], [";
2081
2082   for(i =1 ; i <= nbLocs; i++) {
2083
2084     Handle(Standard_Transient) anItem = theLocations->Value(i);
2085     if(anItem.IsNull())
2086       continue;
2087
2088     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2089     if(!anObj.IsNull()) {
2090       pyDump<< anObj;
2091       if(i < nbLocs)
2092         pyDump<<", ";
2093     }
2094   }
2095
2096   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
2097
2098   SetErrorCode(OK);
2099   return aPipeDS;
2100
2101 }
2102
2103
2104 //=============================================================================
2105 /*!
2106  *  MakePipeShellsWithoutPath
2107  */
2108 //=============================================================================
2109 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeShellsWithoutPath(
2110                 const Handle(TColStd_HSequenceOfTransient)& theBases,
2111                 const Handle(TColStd_HSequenceOfTransient)& theLocations)
2112 {
2113   Handle(GEOM_Object) anObj;
2114   SetErrorCode(KO);
2115   if(theBases.IsNull())
2116     return anObj;
2117
2118   Standard_Integer nbBases = theBases->Length();
2119
2120   if (!nbBases)
2121     return anObj;
2122
2123   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
2124
2125   //Add a new Pipe object
2126   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
2127
2128   //Add a new Pipe function
2129
2130   Handle(GEOM_Function) aFunction =
2131     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELLS_WITHOUT_PATH);
2132   if (aFunction.IsNull()) return anObj;
2133
2134   //Check if the function is set correctly
2135   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
2136
2137   GEOMImpl_IPipeShellSect aCI (aFunction);
2138
2139   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
2140   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
2141
2142   Standard_Integer i =1;
2143   for( ; i <= nbBases; i++) {
2144
2145     Handle(Standard_Transient) anItem = theBases->Value(i);
2146     if(anItem.IsNull())
2147       continue;
2148     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2149     if(aBase.IsNull())
2150       continue;
2151     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2152     if(aRefBase.IsNull())
2153       continue;
2154
2155     if(nbLocs) {
2156       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
2157       if(anItemLoc.IsNull())
2158         continue;
2159       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
2160       if(aLoc.IsNull())
2161         continue;
2162       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
2163       if(aRefLoc.IsNull())
2164         continue;
2165       aSeqLocs->Append(aRefLoc);
2166     }
2167
2168     aSeqBases->Append(aRefBase);
2169   }
2170
2171   if(!aSeqBases->Length())
2172     return anObj;
2173
2174   aCI.SetBases(aSeqBases);
2175   aCI.SetLocations(aSeqLocs);
2176
2177   //Compute the Pipe value
2178   try {
2179     OCC_CATCH_SIGNALS;
2180     if (!GetSolver()->ComputeFunction(aFunction)) {
2181       SetErrorCode("Pipe with shell sections without path driver failed");
2182       return anObj;
2183     }
2184   }
2185   catch (Standard_Failure) {
2186     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2187     SetErrorCode(aFail->GetMessageString());
2188     return anObj;
2189   }
2190
2191   //Make a Python command
2192   GEOM::TPythonDump pyDump(aFunction);
2193   pyDump << aPipeDS << " = geompy.MakePipeShellsWithoutPath([";
2194
2195   for(i =1 ; i <= nbBases; i++) {
2196
2197     Handle(Standard_Transient) anItem = theBases->Value(i);
2198     if(anItem.IsNull())
2199       continue;
2200
2201     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2202     if(!anObj.IsNull()) {
2203       pyDump<< anObj;
2204       if(i < nbBases)
2205         pyDump<<", ";
2206     }
2207   }
2208
2209   pyDump<< "], [";
2210
2211   for(i =1 ; i <= nbLocs; i++) {
2212
2213     Handle(Standard_Transient) anItem = theLocations->Value(i);
2214     if(anItem.IsNull())
2215       continue;
2216
2217     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2218     if(!anObj.IsNull()) {
2219       pyDump<< anObj;
2220       if(i < nbLocs)
2221         pyDump<<", ";
2222     }
2223   }
2224
2225   pyDump<< "])";
2226
2227   SetErrorCode(OK);
2228   return aPipeDS;
2229
2230 }
2231
2232 //=============================================================================
2233 /*!
2234  *  MakePipeBiNormalAlongVector
2235  */
2236 //=============================================================================
2237 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeBiNormalAlongVector (Handle(GEOM_Object) theBase,
2238                                                                              Handle(GEOM_Object) thePath,
2239                                                                              Handle(GEOM_Object) theVec)
2240 {
2241   SetErrorCode(KO);
2242
2243   if (theBase.IsNull() || thePath.IsNull() || theVec.IsNull()) return NULL;
2244
2245   //Add a new Pipe object
2246   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
2247
2248   //Add a new Pipe function
2249   Handle(GEOM_Function) aFunction =
2250     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BI_NORMAL_ALONG_VECTOR);
2251   if (aFunction.IsNull()) return NULL;
2252
2253   //Check if the function is set correctly
2254   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
2255
2256   GEOMImpl_IPipeBiNormal aCI (aFunction);
2257
2258   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
2259   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
2260   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
2261
2262   if (aRefBase.IsNull() || aRefPath.IsNull() || aRefVec.IsNull()) return NULL;
2263
2264   aCI.SetBase(aRefBase);
2265   aCI.SetPath(aRefPath);
2266   aCI.SetVector(aRefVec);
2267
2268   //Compute the Pipe value
2269   try {
2270     OCC_CATCH_SIGNALS;
2271     if (!GetSolver()->ComputeFunction(aFunction)) {
2272       SetErrorCode("Pipe driver failed");
2273       return NULL;
2274     }
2275   }
2276   catch (Standard_Failure) {
2277     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2278     SetErrorCode(aFail->GetMessageString());
2279     return NULL;
2280   }
2281
2282   //Make a Python command
2283   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipeBiNormalAlongVector("
2284     << theBase << ", " << thePath << ", " << theVec << ")";
2285
2286   SetErrorCode(OK);
2287   return aPipe;
2288 }
2289
2290 //=============================================================================
2291 /*!
2292  *  MakeThickening
2293  */
2294 //=============================================================================
2295 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThickening
2296                 (Handle(GEOM_Object)                     theObject,
2297                  const Handle(TColStd_HArray1OfInteger) &theFacesIDs,
2298                  double                                  theOffset,
2299                  bool                                    isCopy,
2300                  bool                                    theInside)
2301 {
2302   SetErrorCode(KO);
2303
2304   if (theObject.IsNull()) return NULL;
2305
2306   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
2307   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
2308
2309   //Add a new Offset function
2310   Handle(GEOM_Function) aFunction;
2311   Handle(GEOM_Object) aCopy; 
2312   if (isCopy)
2313   { 
2314     //Add a new Copy object
2315     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
2316     aFunction = aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_THICKENING_COPY);
2317   }
2318   else
2319     aFunction = theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_THICKENING);
2320   
2321   if (aFunction.IsNull()) return NULL;
2322
2323   //Check if the function is set correctly
2324   if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
2325
2326   GEOMImpl_IOffset aTI (aFunction);
2327   aTI.SetShape(anOriginal);
2328   aTI.SetValue(theOffset);
2329   aTI.SetParam(theInside);
2330
2331   if (theFacesIDs.IsNull() == Standard_False) {
2332     aTI.SetFaceIDs(theFacesIDs);
2333   }
2334
2335   //Compute the offset
2336   try {
2337     OCC_CATCH_SIGNALS;
2338     if (!GetSolver()->ComputeFunction(aFunction)) {
2339       SetErrorCode("Offset driver failed");
2340       return NULL;
2341     }
2342   }
2343   catch (Standard_Failure) {
2344     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2345     SetErrorCode(aFail->GetMessageString());
2346     return NULL;
2347   }
2348
2349   //Make a Python command
2350   GEOM::TPythonDump   pd (aFunction);
2351   Handle(GEOM_Object) aResult; 
2352
2353   if (isCopy) {
2354     pd << aCopy << " = geompy.MakeThickSolid("
2355        << theObject << ", " << theOffset;
2356     aResult = aCopy;
2357   } else {
2358     pd << "geompy.Thicken(" << theObject << ", " << theOffset;
2359     aResult = theObject;
2360   }
2361
2362   pd << ", [";
2363   if (theFacesIDs.IsNull() == Standard_False) {
2364     // Dump faces IDs.
2365     Standard_Integer i;
2366
2367     for (i = theFacesIDs->Lower(); i < theFacesIDs->Upper(); ++i) {
2368       pd << theFacesIDs->Value(i) << ", ";
2369     }
2370     // Dump the last value.
2371     pd << theFacesIDs->Value(i);
2372   }
2373   pd << "]";
2374
2375   if (theInside)
2376     pd << ", " << theInside;
2377
2378   pd << ")";
2379   SetErrorCode(OK);
2380
2381   return aResult;
2382 }
2383
2384 //=============================================================================
2385 /*!
2386  *  RestorePath
2387  */
2388 //=============================================================================
2389 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath (Handle(GEOM_Object) theShape,
2390                                                              Handle(GEOM_Object) theBase1,
2391                                                              Handle(GEOM_Object) theBase2)
2392 {
2393   SetErrorCode(KO);
2394
2395   if (theShape.IsNull() || theBase1.IsNull() || theBase2.IsNull()) return NULL;
2396
2397   // Add a new Path object
2398   Handle(GEOM_Object) aPath = GetEngine()->AddObject(GetDocID(), GEOM_PIPE_PATH);
2399
2400   // Add a new Path function
2401   Handle(GEOM_Function) aFunction =
2402     aPath->AddFunction(GEOMImpl_PipePathDriver::GetID(), PIPE_PATH_TWO_BASES);
2403   if (aFunction.IsNull()) return NULL;
2404
2405   // Check if the function is set correctly
2406   if (aFunction->GetDriverGUID() != GEOMImpl_PipePathDriver::GetID()) return NULL;
2407
2408   GEOMImpl_IPipePath aCI (aFunction);
2409
2410   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2411   Handle(GEOM_Function) aRefBase1 = theBase1->GetLastFunction();
2412   Handle(GEOM_Function) aRefBase2 = theBase2->GetLastFunction();
2413
2414   if (aRefShape.IsNull() || aRefBase1.IsNull() || aRefBase2.IsNull()) return NULL;
2415
2416   aCI.SetShape(aRefShape);
2417   aCI.SetBase1(aRefBase1);
2418   aCI.SetBase2(aRefBase2);
2419
2420   // Compute the Path value
2421   try {
2422     OCC_CATCH_SIGNALS;
2423     if (!GetSolver()->ComputeFunction(aFunction)) {
2424       SetErrorCode("PipePath driver failed");
2425       return NULL;
2426     }
2427   }
2428   catch (Standard_Failure) {
2429     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2430     SetErrorCode("RestorePath: inappropriate arguments given");
2431     return NULL;
2432   }
2433
2434   // Make a Python command
2435   GEOM::TPythonDump(aFunction) << aPath << " = geompy.RestorePath("
2436     << theShape << ", " << theBase1 << ", " << theBase2 << ")";
2437
2438   SetErrorCode(OK);
2439   return aPath;
2440 }
2441
2442 //=============================================================================
2443 /*!
2444  *  RestorePath
2445  */
2446 //=============================================================================
2447 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath
2448                          (Handle(GEOM_Object) theShape,
2449                           const Handle(TColStd_HSequenceOfTransient)& theBase1,
2450                           const Handle(TColStd_HSequenceOfTransient)& theBase2)
2451 {
2452   SetErrorCode(KO);
2453
2454   if (theShape.IsNull() || theBase1.IsNull() || theBase2.IsNull()) return NULL;
2455
2456   Standard_Integer nbBases1 = theBase1->Length();
2457   Standard_Integer nbBases2 = theBase2->Length();
2458
2459   if (!nbBases1 || !nbBases2)
2460     return NULL;
2461
2462   // Add a new Path object
2463   Handle(GEOM_Object) aPath = GetEngine()->AddObject(GetDocID(), GEOM_PIPE_PATH);
2464
2465   // Add a new Path function
2466   Handle(GEOM_Function) aFunction =
2467     aPath->AddFunction(GEOMImpl_PipePathDriver::GetID(), PIPE_PATH_TWO_SEQS);
2468   if (aFunction.IsNull()) return NULL;
2469
2470   // Check if the function is set correctly
2471   if (aFunction->GetDriverGUID() != GEOMImpl_PipePathDriver::GetID()) return NULL;
2472
2473   GEOMImpl_IPipePath aCI (aFunction);
2474
2475   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2476   if (aRefShape.IsNull()) return NULL;
2477
2478   Handle(TColStd_HSequenceOfTransient) aSeqBases1 = new TColStd_HSequenceOfTransient;
2479   Handle(TColStd_HSequenceOfTransient) aSeqBases2 = new TColStd_HSequenceOfTransient;
2480
2481   Standard_Integer i;
2482   for (i = 1; i <= nbBases1; i++) {
2483     Handle(Standard_Transient) anItem = theBase1->Value(i);
2484     if (!anItem.IsNull()) {
2485       Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2486       if (!aBase.IsNull()) {
2487         Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2488         if (!aRefBase.IsNull())
2489           aSeqBases1->Append(aRefBase);
2490       }
2491     }
2492   }
2493   for (i = 1; i <= nbBases2; i++) {
2494     Handle(Standard_Transient) anItem = theBase2->Value(i);
2495     if (!anItem.IsNull()) {
2496       Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2497       if (!aBase.IsNull()) {
2498         Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2499         if (!aRefBase.IsNull())
2500           aSeqBases2->Append(aRefBase);
2501       }
2502     }
2503   }
2504   if (!aSeqBases1->Length() || !aSeqBases2->Length()) return NULL;
2505
2506   aCI.SetShape(aRefShape);
2507   aCI.SetBaseSeq1(aSeqBases1);
2508   aCI.SetBaseSeq2(aSeqBases2);
2509
2510   // Compute the Path value
2511   try {
2512     OCC_CATCH_SIGNALS;
2513     if (!GetSolver()->ComputeFunction(aFunction)) {
2514       SetErrorCode("PipePath driver failed");
2515       return NULL;
2516     }
2517   }
2518   catch (Standard_Failure) {
2519     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2520     SetErrorCode("RestorePath: inappropriate arguments given");
2521     return NULL;
2522   }
2523
2524   // Make a Python command
2525   GEOM::TPythonDump pyDump (aFunction);
2526   pyDump << aPath << " = geompy.RestorePathEdges(" << theShape << ", [";
2527   for (i = 1; i <= nbBases1; i++) {
2528     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theBase1->Value(i));
2529     if (!anObj.IsNull()) {
2530       pyDump << anObj;
2531       if (i < nbBases1)
2532         pyDump << ", ";
2533     }
2534   }
2535   pyDump<< "], [";
2536   for (i = 1; i <= nbBases2; i++) {
2537     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theBase2->Value(i));
2538     if (!anObj.IsNull()) {
2539       pyDump << anObj;
2540       if (i < nbBases2)
2541         pyDump << ", ";
2542     }
2543   }
2544   pyDump << "])";
2545
2546   SetErrorCode(OK);
2547   return aPath;
2548 }