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