Salome HOME
IMPs 21044, 21057, 21067
[modules/geom.git] / src / GEOMImpl / GEOMImpl_I3DPrimOperations.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_I3DPrimOperations.hxx>
25
26 #include "utilities.h"
27 #include <OpUtil.hxx>
28 #include <Utils_ExceptHandlers.hxx>
29
30 #include <TFunction_DriverTable.hxx>
31 #include <TFunction_Driver.hxx>
32 #include <TFunction_Logbook.hxx>
33 #include <TDF_Tool.hxx>
34
35 #include <GEOM_Function.hxx>
36 #include <GEOM_PythonDump.hxx>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <GEOMImpl_BoxDriver.hxx>
41 #include <GEOMImpl_FaceDriver.hxx>
42 #include <GEOMImpl_DiskDriver.hxx>
43 #include <GEOMImpl_CylinderDriver.hxx>
44 #include <GEOMImpl_ConeDriver.hxx>
45 #include <GEOMImpl_SphereDriver.hxx>
46 #include <GEOMImpl_TorusDriver.hxx>
47 #include <GEOMImpl_PrismDriver.hxx>
48 #include <GEOMImpl_PipeDriver.hxx>
49 #include <GEOMImpl_RevolutionDriver.hxx>
50 #include <GEOMImpl_ShapeDriver.hxx>
51 #include <GEOMImpl_FillingDriver.hxx>
52 #include <GEOMImpl_ThruSectionsDriver.hxx>
53
54 #include <GEOMImpl_IBox.hxx>
55 #include <GEOMImpl_IFace.hxx>
56 #include <GEOMImpl_IDisk.hxx>
57 #include <GEOMImpl_ICylinder.hxx>
58 #include <GEOMImpl_ICone.hxx>
59 #include <GEOMImpl_ISphere.hxx>
60 #include <GEOMImpl_ITorus.hxx>
61 #include <GEOMImpl_IPrism.hxx>
62 #include <GEOMImpl_IPipe.hxx>
63 #include <GEOMImpl_IRevolution.hxx>
64 #include <GEOMImpl_IFilling.hxx>
65 #include <GEOMImpl_IThruSections.hxx>
66 #include <GEOMImpl_IPipeDiffSect.hxx>
67 #include <GEOMImpl_IPipeShellSect.hxx>
68 #include <GEOMImpl_IPipeBiNormal.hxx>
69
70 #include <Precision.hxx>
71
72 #include <Standard_Failure.hxx>
73 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
74
75 //=============================================================================
76 /*!
77  *   constructor:
78  */
79 //=============================================================================
80 GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, int theDocID)
81 : GEOM_IOperations(theEngine, theDocID)
82 {
83   MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations");
84 }
85
86 //=============================================================================
87 /*!
88  *  destructor
89  */
90 //=============================================================================
91 GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations()
92 {
93   MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations");
94 }
95
96
97 //=============================================================================
98 /*!
99  *  MakeBoxDXDYDZ
100  */
101 //=============================================================================
102 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxDXDYDZ (double theDX, double theDY, double theDZ)
103 {
104   SetErrorCode(KO);
105
106   //Add a new Box object
107   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
108
109   //Add a new Box function with DX_DY_DZ parameters
110   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_DX_DY_DZ);
111   if (aFunction.IsNull()) return NULL;
112
113   //Check if the function is set correctly
114   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return NULL;
115
116   GEOMImpl_IBox aBI (aFunction);
117
118   aBI.SetDX(theDX);
119   aBI.SetDY(theDY);
120   aBI.SetDZ(theDZ);
121
122   //Compute the box value
123   try {
124 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
125     OCC_CATCH_SIGNALS;
126 #endif
127     if (!GetSolver()->ComputeFunction(aFunction)) {
128       SetErrorCode("Box driver failed");
129       return NULL;
130     }
131   }
132   catch (Standard_Failure) {
133     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
134     SetErrorCode(aFail->GetMessageString());
135     return NULL;
136   }
137
138   //Make a Python command
139   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxDXDYDZ("
140     << theDX << ", " << theDY << ", " << theDZ << ")";
141
142   SetErrorCode(OK);
143   return aBox;
144 }
145
146
147 //=============================================================================
148 /*!
149  *  MakeBoxTwoPnt
150  */
151 //=============================================================================
152 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxTwoPnt (Handle(GEOM_Object) thePnt1,
153                                                                Handle(GEOM_Object) thePnt2)
154 {
155   SetErrorCode(KO);
156
157   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
158
159   //Add a new Box object
160   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
161
162   //Add a new Box function for creation a box relatively to two points
163   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_TWO_PNT);
164   if (aFunction.IsNull()) return NULL;
165
166   //Check if the function is set correctly
167   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return aBox;
168
169   GEOMImpl_IBox aBI (aFunction);
170
171   Handle(GEOM_Function) aRefFunction1 = thePnt1->GetLastFunction();
172   Handle(GEOM_Function) aRefFunction2 = thePnt2->GetLastFunction();
173
174   if (aRefFunction1.IsNull() || aRefFunction2.IsNull()) return aBox;
175
176   aBI.SetRef1(aRefFunction1);
177   aBI.SetRef2(aRefFunction2);
178
179   //Compute the Box value
180   try {
181 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
182     OCC_CATCH_SIGNALS;
183 #endif
184     if (!GetSolver()->ComputeFunction(aFunction)) {
185       SetErrorCode("Box driver failed");
186       return NULL;
187     }
188   }
189   catch (Standard_Failure) {
190     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
191     SetErrorCode(aFail->GetMessageString());
192     return NULL;
193   }
194
195   //Make a Python command
196   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxTwoPnt("
197     << thePnt1 << ", " << thePnt2 << ")";
198
199   SetErrorCode(OK);
200   return aBox;
201 }
202
203 //=============================================================================
204 /*!
205  *  MakeFaceHW
206  */
207 //=============================================================================
208 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFaceHW (double theH, double theW, int theOrientation)
209 {
210   SetErrorCode(KO);
211
212   if (theH == 0 || theW == 0) return NULL;
213
214   //Add a new Face object
215   Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
216
217   //Add a new Box function for creation a box relatively to two points
218   Handle(GEOM_Function) aFunction = aFace->AddFunction(GEOMImpl_FaceDriver::GetID(), FACE_H_W);
219   if (aFunction.IsNull()) return NULL;
220
221   //Check if the function is set correctly
222   if (aFunction->GetDriverGUID() != GEOMImpl_FaceDriver::GetID()) return aFace;
223
224   GEOMImpl_IFace aFI (aFunction);
225
226   aFI.SetH(theH);
227   aFI.SetW(theW);
228   aFI.SetOrientation(theOrientation);
229
230   //Compute the Face
231   try {
232 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
233     OCC_CATCH_SIGNALS;
234 #endif
235     if (!GetSolver()->ComputeFunction(aFunction)) {
236       SetErrorCode("Face driver failed");
237       return NULL;
238     }
239   }
240   catch (Standard_Failure) {
241     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
242     SetErrorCode(aFail->GetMessageString());
243     return NULL;
244   }
245
246   //Make a Python command
247   GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFaceHW("
248     << theH << ", " << theW << ", " << theOrientation << ")";
249
250   SetErrorCode(OK);
251   return aFace;
252 }
253
254 //=============================================================================
255 /*!
256  *  MakeFaceObjHW
257  */
258 //=============================================================================
259 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFaceObjHW (Handle(GEOM_Object) theObj,
260                                                                double theH, double theW)
261 {
262   SetErrorCode(KO);
263
264   if (theObj.IsNull()) return NULL;
265
266   //Add a new Face object
267   Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
268
269   //Add a new Box function for creation a box relatively to two points
270   Handle(GEOM_Function) aFunction = aFace->AddFunction(GEOMImpl_FaceDriver::GetID(), FACE_OBJ_H_W);
271   if (aFunction.IsNull()) return NULL;
272
273   //Check if the function is set correctly
274   if (aFunction->GetDriverGUID() != GEOMImpl_FaceDriver::GetID()) return aFace;
275
276   GEOMImpl_IFace aFI (aFunction);
277
278   Handle(GEOM_Function) aRefFunction1 = theObj->GetLastFunction();
279
280   if (aRefFunction1.IsNull())
281     return aFace;
282
283   aFI.SetRef1(aRefFunction1);
284   aFI.SetH(theH);
285   aFI.SetW(theW);
286
287   //Compute the Face
288   try {
289 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
290     OCC_CATCH_SIGNALS;
291 #endif
292     if (!GetSolver()->ComputeFunction(aFunction)) {
293       SetErrorCode("Face driver failed");
294       return NULL;
295     }
296   }
297   catch (Standard_Failure) {
298     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
299     SetErrorCode(aFail->GetMessageString());
300     return NULL;
301   }
302
303   //Make a Python command
304   GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFaceObjHW("
305     << theObj << ", " << theH << ", " << theW << ")";
306
307   SetErrorCode(OK);
308   return aFace;
309 }
310
311 //=============================================================================
312 /*!
313  *  MakeDiskPntVecR
314  */
315 //=============================================================================
316 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskPntVecR
317       (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
318 {
319   SetErrorCode(KO);
320
321   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
322
323   //Add a new Disk object
324   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
325
326   //Add a new Disk function for creation a disk relatively to point and vector
327   Handle(GEOM_Function) aFunction =
328     aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_PNT_VEC_R);
329   if (aFunction.IsNull()) return NULL;
330
331   //Check if the function is set correctly
332   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return NULL;
333
334   GEOMImpl_IDisk aCI (aFunction);
335
336   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
337   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
338
339   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
340
341   aCI.SetCenter(aRefPnt);
342   aCI.SetVector(aRefVec);
343   aCI.SetRadius(theR);
344
345   //Compute the Disk value
346   try {
347 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
348     OCC_CATCH_SIGNALS;
349 #endif
350     if (!GetSolver()->ComputeFunction(aFunction)) {
351       SetErrorCode("Disk driver failed");
352       return NULL;
353     }
354   }
355   catch (Standard_Failure) {
356     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
357     SetErrorCode(aFail->GetMessageString());
358     return NULL;
359   }
360
361   //Make a Python command
362   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskPntVecR("
363     << thePnt << ", " << theVec << ", " << theR << ")";
364
365   SetErrorCode(OK);
366   return aDisk;
367 }
368
369 //=============================================================================
370 /*!
371  *  MakeDiskThreePnt
372  */
373 //=============================================================================
374 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskThreePnt (Handle(GEOM_Object) thePnt1,
375                                                                   Handle(GEOM_Object) thePnt2,
376                                                                   Handle(GEOM_Object) thePnt3)
377 {
378   SetErrorCode(KO);
379
380   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
381
382   //Add a new Disk object
383   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
384
385   //Add a new Disk function for creation a disk relatively to three points
386   Handle(GEOM_Function) aFunction =
387     aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_THREE_PNT);
388   if (aFunction.IsNull()) return NULL;
389
390   //Check if the function is set correctly
391   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return NULL;
392
393   GEOMImpl_IDisk aCI (aFunction);
394
395   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
396   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
397   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
398
399   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
400
401   aCI.SetPoint1(aRefPnt1);
402   aCI.SetPoint2(aRefPnt2);
403   aCI.SetPoint3(aRefPnt3);
404
405   //Compute the Disk value
406   try {
407 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
408     OCC_CATCH_SIGNALS;
409 #endif
410     if (!GetSolver()->ComputeFunction(aFunction)) {
411       SetErrorCode("Disk driver failed");
412       return NULL;
413     }
414   }
415   catch (Standard_Failure) {
416     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
417     SetErrorCode(aFail->GetMessageString());
418     return NULL;
419   }
420
421   //Make a Python command
422   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskThreePnt("
423     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
424
425   SetErrorCode(OK);
426   return aDisk;
427 }
428
429 //=============================================================================
430 /*!
431  *  MakeDiskR
432  */
433 //=============================================================================
434 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskR (double theR, int theOrientation)
435 {
436   SetErrorCode(KO);
437
438   if (theR == 0 ) return NULL;
439
440   //Add a new Disk object
441   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
442
443   //Add a new Box function for creation a box relatively to two points
444   Handle(GEOM_Function) aFunction = aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_R);
445   if (aFunction.IsNull()) return NULL;
446
447   //Check if the function is set correctly
448   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return aDisk;
449
450   GEOMImpl_IDisk aDI (aFunction);
451
452   aDI.SetRadius(theR);
453   aDI.SetOrientation(theOrientation);
454
455   //Compute the Disk
456   try {
457 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
458     OCC_CATCH_SIGNALS;
459 #endif
460     if (!GetSolver()->ComputeFunction(aFunction)) {
461       SetErrorCode("Disk driver failed");
462       return NULL;
463     }
464   }
465   catch (Standard_Failure) {
466     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
467     SetErrorCode(aFail->GetMessageString());
468     return NULL;
469   }
470
471   //Make a Python command
472   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskR("
473     << theR << ", " << theOrientation << ")";
474
475   SetErrorCode(OK);
476   return aDisk;
477 }
478
479 //=============================================================================
480 /*!
481  *  MakeCylinderRH
482  */
483 //=============================================================================
484 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRH (double theR, double theH)
485 {
486   SetErrorCode(KO);
487
488   //Add a new Cylinder object
489   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
490
491   //Add a new Cylinder function with R and H parameters
492   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H);
493   if (aFunction.IsNull()) return NULL;
494
495   //Check if the function is set correctly
496   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
497
498   GEOMImpl_ICylinder aCI (aFunction);
499
500   aCI.SetR(theR);
501   aCI.SetH(theH);
502
503   //Compute the Cylinder value
504   try {
505 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
506     OCC_CATCH_SIGNALS;
507 #endif
508     if (!GetSolver()->ComputeFunction(aFunction)) {
509       SetErrorCode("Cylinder driver failed");
510       return NULL;
511     }
512   }
513   catch (Standard_Failure) {
514     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
515     SetErrorCode(aFail->GetMessageString());
516     return NULL;
517   }
518
519   //Make a Python command
520   GEOM::TPythonDump(aFunction) << aCylinder
521     << " = geompy.MakeCylinderRH(" << theR << ", " << theH << ")";
522
523   SetErrorCode(OK);
524   return aCylinder;
525 }
526
527
528 //=============================================================================
529 /*!
530  *  MakeCylinderPntVecRH
531  */
532 //=============================================================================
533 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRH (Handle(GEOM_Object) thePnt,
534                                                                       Handle(GEOM_Object) theVec,
535                                                                       double theR, double theH)
536 {
537   SetErrorCode(KO);
538
539   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
540
541   //Add a new Cylinder object
542   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
543
544   //Add a new Cylinder function for creation a cylinder relatively to point and vector
545   Handle(GEOM_Function) aFunction =
546     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H);
547   if (aFunction.IsNull()) return NULL;
548
549   //Check if the function is set correctly
550   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
551
552   GEOMImpl_ICylinder aCI (aFunction);
553
554   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
555   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
556
557   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
558
559   aCI.SetPoint(aRefPnt);
560   aCI.SetVector(aRefVec);
561   aCI.SetR(theR);
562   aCI.SetH(theH);
563
564   //Compute the Cylinder value
565   try {
566 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
567     OCC_CATCH_SIGNALS;
568 #endif
569     if (!GetSolver()->ComputeFunction(aFunction)) {
570       SetErrorCode("Cylinder driver failed");
571       return NULL;
572     }
573   }
574   catch (Standard_Failure) {
575     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
576     SetErrorCode(aFail->GetMessageString());
577     return NULL;
578   }
579
580   //Make a Python command
581   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinder("
582     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ")";
583
584   SetErrorCode(OK);
585   return aCylinder;
586 }
587
588
589 //=============================================================================
590 /*!
591  *  MakeConeR1R2H
592  */
593 //=============================================================================
594 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConeR1R2H (double theR1, double theR2,
595                                                                double theH)
596 {
597   SetErrorCode(KO);
598
599   //Add a new Cone object
600   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
601
602   //Add a new Cone function with R and H parameters
603   Handle(GEOM_Function) aFunction =
604     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_R1_R2_H);
605   if (aFunction.IsNull()) return NULL;
606
607   //Check if the function is set correctly
608   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
609
610   GEOMImpl_ICone aCI (aFunction);
611
612   aCI.SetR1(theR1);
613   aCI.SetR2(theR2);
614   aCI.SetH(theH);
615
616   //Compute the Cone value
617   try {
618 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
619     OCC_CATCH_SIGNALS;
620 #endif
621     if (!GetSolver()->ComputeFunction(aFunction)) {
622       SetErrorCode("Cone driver failed");
623       return NULL;
624     }
625   }
626   catch (Standard_Failure) {
627     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
628     SetErrorCode(aFail->GetMessageString());
629     return NULL;
630   }
631
632   //Make a Python command
633   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeConeR1R2H("
634     << theR1 << ", " << theR2 << ", " << theH << ")";
635
636   SetErrorCode(OK);
637   return aCone;
638 }
639
640
641 //=============================================================================
642 /*!
643  *  MakeConePntVecR1R2H
644  */
645 //=============================================================================
646 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConePntVecR1R2H (Handle(GEOM_Object) thePnt,
647                                                                      Handle(GEOM_Object) theVec,
648                                                                      double theR1, double theR2,
649                                                                      double theH)
650 {
651   SetErrorCode(KO);
652
653   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
654
655   //Add a new Cone object
656   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
657
658   //Add a new Cone function for creation a cone relatively to point and vector
659   Handle(GEOM_Function) aFunction =
660     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_PNT_VEC_R1_R2_H);
661   if (aFunction.IsNull()) return NULL;
662
663   //Check if the function is set correctly
664   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
665
666   GEOMImpl_ICone aCI (aFunction);
667
668   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
669   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
670
671   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
672
673   aCI.SetPoint(aRefPnt);
674   aCI.SetVector(aRefVec);
675   aCI.SetR1(theR1);
676   aCI.SetR2(theR2);
677   aCI.SetH(theH);
678
679   //Compute the Cone value
680   try {
681 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
682     OCC_CATCH_SIGNALS;
683 #endif
684     if (!GetSolver()->ComputeFunction(aFunction)) {
685       SetErrorCode("Cone driver failed");
686       return NULL;
687     }
688   }
689   catch (Standard_Failure) {
690     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
691     SetErrorCode(aFail->GetMessageString());
692     return NULL;
693   }
694
695   //Make a Python command
696   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeCone(" << thePnt
697     << ", " << theVec << ", " << theR1 << ", " << theR2 << ", " << theH << ")";
698
699   SetErrorCode(OK);
700   return aCone;
701 }
702
703
704 //=============================================================================
705 /*!
706  *  MakeSphereR
707  */
708 //=============================================================================
709 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSphereR (double theR)
710 {
711   SetErrorCode(KO);
712
713   //Add a new Sphere object
714   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
715
716   //Add a new Sphere function with R parameter
717   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_R);
718   if (aFunction.IsNull()) return NULL;
719
720   //Check if the function is set correctly
721   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
722
723   GEOMImpl_ISphere aCI (aFunction);
724
725   aCI.SetR(theR);
726
727   //Compute the Sphere value
728   try {
729 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
730     OCC_CATCH_SIGNALS;
731 #endif
732     if (!GetSolver()->ComputeFunction(aFunction)) {
733       SetErrorCode("Sphere driver failed");
734       return NULL;
735     }
736   }
737   catch (Standard_Failure) {
738     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
739     SetErrorCode(aFail->GetMessageString());
740     return NULL;
741   }
742
743   //Make a Python command
744   GEOM::TPythonDump(aFunction) << aSphere << " = geompy.MakeSphereR(" << theR << ")";
745
746   SetErrorCode(OK);
747   return aSphere;
748 }
749
750
751 //=============================================================================
752 /*!
753  *  MakeSpherePntR
754  */
755 //=============================================================================
756 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSpherePntR (Handle(GEOM_Object) thePnt,
757                                                                 double theR)
758 {
759   SetErrorCode(KO);
760
761   if (thePnt.IsNull()) return NULL;
762
763   //Add a new Point object
764   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
765
766   //Add a new Sphere function for creation a sphere relatively to point
767   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_PNT_R);
768   if (aFunction.IsNull()) return NULL;
769
770   //Check if the function is set correctly
771   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
772
773   GEOMImpl_ISphere aCI (aFunction);
774
775   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
776
777   if (aRefPnt.IsNull()) return NULL;
778
779   aCI.SetPoint(aRefPnt);
780   aCI.SetR(theR);
781
782   //Compute the Sphere value
783   try {
784 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
785     OCC_CATCH_SIGNALS;
786 #endif
787     if (!GetSolver()->ComputeFunction(aFunction)) {
788       SetErrorCode("Sphere driver failed");
789       return NULL;
790     }
791   }
792   catch (Standard_Failure) {
793     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
794     SetErrorCode(aFail->GetMessageString());
795     return NULL;
796   }
797
798   //Make a Python command
799   GEOM::TPythonDump(aFunction) << aSphere
800     << " = geompy.MakeSpherePntR(" << thePnt << ", " << theR << ")";
801
802   SetErrorCode(OK);
803   return aSphere;
804 }
805
806
807 //=============================================================================
808 /*!
809  *  MakeTorusRR
810  */
811 //=============================================================================
812 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusRR
813                                            (double theRMajor, double theRMinor)
814 {
815   SetErrorCode(KO);
816
817   //Add a new Torus object
818   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
819
820   //Add a new Torus function
821   Handle(GEOM_Function) aFunction =
822     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_RR);
823   if (aFunction.IsNull()) return NULL;
824
825   //Check if the function is set correctly
826   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
827
828   GEOMImpl_ITorus aCI (aFunction);
829
830   aCI.SetRMajor(theRMajor);
831   aCI.SetRMinor(theRMinor);
832
833   //Compute the Torus value
834   try {
835 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
836     OCC_CATCH_SIGNALS;
837 #endif
838     if (!GetSolver()->ComputeFunction(aFunction)) {
839       SetErrorCode("Torus driver failed");
840       return NULL;
841     }
842   }
843   catch (Standard_Failure) {
844     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
845     SetErrorCode(aFail->GetMessageString());
846     return NULL;
847   }
848
849   //Make a Python command
850   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorusRR("
851     << theRMajor << ", " << theRMinor << ")";
852
853   SetErrorCode(OK);
854   return anEll;
855 }
856
857 //=============================================================================
858 /*!
859  *  MakeTorusPntVecRR
860  */
861 //=============================================================================
862 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusPntVecRR
863                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
864                         double theRMajor, double theRMinor)
865 {
866   SetErrorCode(KO);
867
868   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
869
870   //Add a new Torus object
871   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
872
873   //Add a new Torus function
874   Handle(GEOM_Function) aFunction =
875     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_PNT_VEC_RR);
876   if (aFunction.IsNull()) return NULL;
877
878   //Check if the function is set correctly
879   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
880
881   GEOMImpl_ITorus aCI (aFunction);
882
883   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
884   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
885
886   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
887
888   aCI.SetCenter(aRefPnt);
889   aCI.SetVector(aRefVec);
890   aCI.SetRMajor(theRMajor);
891   aCI.SetRMinor(theRMinor);
892
893   //Compute the Torus value
894   try {
895 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
896     OCC_CATCH_SIGNALS;
897 #endif
898     if (!GetSolver()->ComputeFunction(aFunction)) {
899       SetErrorCode("Torus driver failed");
900       return NULL;
901     }
902   }
903   catch (Standard_Failure) {
904     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
905     SetErrorCode(aFail->GetMessageString());
906     return NULL;
907   }
908
909   //Make a Python command
910   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorus(" << thePnt
911     << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
912
913   SetErrorCode(OK);
914   return anEll;
915 }
916
917
918 //=============================================================================
919 /*!
920  *  MakePrismVecH
921  */
922 //=============================================================================
923 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH (Handle(GEOM_Object) theBase,
924                                                                Handle(GEOM_Object) theVec,
925                                                                double theH, double theScaleFactor)
926 {
927   SetErrorCode(KO);
928
929   if (theBase.IsNull() || theVec.IsNull()) return NULL;
930
931   //Add a new Prism object
932   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
933
934   //Add a new Prism function for creation a Prism relatively to vector
935   Handle(GEOM_Function) aFunction =
936     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H);
937   if (aFunction.IsNull()) return NULL;
938
939   //Check if the function is set correctly
940   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
941
942   GEOMImpl_IPrism aCI (aFunction);
943
944   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
945   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
946
947   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
948
949   aCI.SetBase(aRefBase);
950   aCI.SetVector(aRefVec);
951   aCI.SetH(theH);
952   aCI.SetScale(theScaleFactor);
953
954   //Compute the Prism value
955   try {
956 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
957     OCC_CATCH_SIGNALS;
958 #endif
959     if (!GetSolver()->ComputeFunction(aFunction)) {
960       //SetErrorCode("Prism driver failed");
961       SetErrorCode("Extrusion can not be created, check input data");
962       return NULL;
963     }
964   }
965   catch (Standard_Failure) {
966     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
967     SetErrorCode(aFail->GetMessageString());
968     return NULL;
969   }
970
971   //Make a Python command
972   GEOM::TPythonDump pd (aFunction);
973   pd << aPrism << " = geompy.MakePrismVecH(" << theBase << ", " << theVec << ", " << theH;
974   if (theScaleFactor > Precision::Confusion())
975     pd << ", " << theScaleFactor << ")";
976   else
977     pd << ")";
978
979   SetErrorCode(OK);
980   return aPrism;
981 }
982
983 //=============================================================================
984 /*!
985  *  MakePrismVecH2Ways
986  */
987 //=============================================================================
988 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH2Ways (Handle(GEOM_Object) theBase,
989                                                                     Handle(GEOM_Object) theVec,
990                                                                     double theH)
991 {
992   SetErrorCode(KO);
993
994   if (theBase.IsNull() || theVec.IsNull()) return NULL;
995
996   //Add a new Prism object
997   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
998
999   //Add a new Prism function for creation a Prism relatively to vector
1000   Handle(GEOM_Function) aFunction =
1001     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H_2WAYS);
1002   if (aFunction.IsNull()) return NULL;
1003
1004   //Check if the function is set correctly
1005   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1006
1007   GEOMImpl_IPrism aCI (aFunction);
1008
1009   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1010   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
1011
1012   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
1013
1014   aCI.SetBase(aRefBase);
1015   aCI.SetVector(aRefVec);
1016   aCI.SetH(theH);
1017
1018   //Compute the Prism value
1019   try {
1020 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1021     OCC_CATCH_SIGNALS;
1022 #endif
1023     if (!GetSolver()->ComputeFunction(aFunction)) {
1024       //SetErrorCode("Prism driver failed");
1025       SetErrorCode("Extrusion can not be created, check input data");
1026       return NULL;
1027     }
1028   }
1029   catch (Standard_Failure) {
1030     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1031     SetErrorCode(aFail->GetMessageString());
1032     return NULL;
1033   }
1034
1035   //Make a Python command
1036   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismVecH2Ways("
1037     << theBase << ", " << theVec << ", " << theH << ")";
1038
1039   SetErrorCode(OK);
1040   return aPrism;
1041 }
1042
1043 //=============================================================================
1044 /*!
1045  *  MakePrismTwoPnt
1046  */
1047 //=============================================================================
1048 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
1049        (Handle(GEOM_Object) theBase,
1050         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2,
1051         double theScaleFactor)
1052 {
1053   SetErrorCode(KO);
1054
1055   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1056
1057   //Add a new Prism object
1058   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1059
1060   //Add a new Prism function for creation a Prism relatively to two points
1061   Handle(GEOM_Function) aFunction =
1062     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
1063   if (aFunction.IsNull()) return NULL;
1064
1065   //Check if the function is set correctly
1066   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1067
1068   GEOMImpl_IPrism aCI (aFunction);
1069
1070   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1071   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
1072   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
1073
1074   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
1075
1076   aCI.SetBase(aRefBase);
1077   aCI.SetFirstPoint(aRefPnt1);
1078   aCI.SetLastPoint(aRefPnt2);
1079   aCI.SetScale(theScaleFactor);
1080
1081   //Compute the Prism value
1082   try {
1083 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1084     OCC_CATCH_SIGNALS;
1085 #endif
1086     if (!GetSolver()->ComputeFunction(aFunction)) {
1087       //SetErrorCode("Prism driver failed");
1088       SetErrorCode("Extrusion can not be created, check input data");
1089       return NULL;
1090     }
1091   }
1092   catch (Standard_Failure) {
1093     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1094     SetErrorCode(aFail->GetMessageString());
1095     return NULL;
1096   }
1097
1098   //Make a Python command
1099   GEOM::TPythonDump pd (aFunction);
1100   pd << aPrism << " = geompy.MakePrism(" << theBase << ", " << thePoint1 << ", " << thePoint2;
1101   if (theScaleFactor > Precision::Confusion())
1102     pd << ", " << theScaleFactor << ")";
1103   else
1104     pd << ")";
1105
1106   SetErrorCode(OK);
1107   return aPrism;
1108 }
1109
1110 //=============================================================================
1111 /*!
1112  *  MakePrismTwoPnt2Ways
1113  */
1114 //=============================================================================
1115 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt2Ways
1116        (Handle(GEOM_Object) theBase,
1117         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
1118 {
1119   SetErrorCode(KO);
1120
1121   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1122
1123   //Add a new Prism object
1124   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1125
1126   //Add a new Prism function for creation a Prism relatively to two points
1127   Handle(GEOM_Function) aFunction =
1128     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT_2WAYS);
1129   if (aFunction.IsNull()) return NULL;
1130
1131   //Check if the function is set correctly
1132   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1133
1134   GEOMImpl_IPrism aCI (aFunction);
1135
1136   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1137   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
1138   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
1139
1140   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
1141
1142   aCI.SetBase(aRefBase);
1143   aCI.SetFirstPoint(aRefPnt1);
1144   aCI.SetLastPoint(aRefPnt2);
1145
1146   //Compute the Prism value
1147   try {
1148 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1149     OCC_CATCH_SIGNALS;
1150 #endif
1151     if (!GetSolver()->ComputeFunction(aFunction)) {
1152       //SetErrorCode("Prism driver failed");
1153       SetErrorCode("Extrusion can not be created, check input data");
1154       return NULL;
1155     }
1156   }
1157   catch (Standard_Failure) {
1158     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1159     SetErrorCode(aFail->GetMessageString());
1160     return NULL;
1161   }
1162
1163   //Make a Python command
1164   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism2Ways("
1165     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
1166
1167   SetErrorCode(OK);
1168   return aPrism;
1169 }
1170
1171 //=============================================================================
1172 /*!
1173  *  MakePrismDXDYDZ
1174  */
1175 //=============================================================================
1176 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ
1177        (Handle(GEOM_Object) theBase, double theDX, double theDY, double theDZ,
1178         double theScaleFactor)
1179 {
1180   SetErrorCode(KO);
1181
1182   if (theBase.IsNull()) return NULL;
1183
1184   //Add a new Prism object
1185   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1186
1187   //Add a new Prism function for creation a Prism by DXDYDZ
1188   Handle(GEOM_Function) aFunction =
1189     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_DXDYDZ);
1190   if (aFunction.IsNull()) return NULL;
1191
1192   //Check if the function is set correctly
1193   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1194
1195   GEOMImpl_IPrism aCI (aFunction);
1196
1197   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1198
1199   if (aRefBase.IsNull()) return NULL;
1200
1201   aCI.SetBase(aRefBase);
1202   aCI.SetDX(theDX);
1203   aCI.SetDY(theDY);
1204   aCI.SetDZ(theDZ);
1205   aCI.SetScale(theScaleFactor);
1206
1207   //Compute the Prism value
1208   try {
1209 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1210     OCC_CATCH_SIGNALS;
1211 #endif
1212     if (!GetSolver()->ComputeFunction(aFunction)) {
1213       SetErrorCode("Extrusion can not be created, check input data");
1214       return NULL;
1215     }
1216   }
1217   catch (Standard_Failure) {
1218     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1219     SetErrorCode(aFail->GetMessageString());
1220     return NULL;
1221   }
1222
1223   //Make a Python command
1224   GEOM::TPythonDump pd (aFunction);
1225   pd << aPrism << " = geompy.MakePrismDXDYDZ("
1226      << theBase << ", " << theDX << ", " << theDY << ", " << theDZ;
1227   if (theScaleFactor > Precision::Confusion())
1228     pd << ", " << theScaleFactor << ")";
1229   else
1230     pd << ")";
1231
1232   SetErrorCode(OK);
1233   return aPrism;
1234 }
1235
1236 //=============================================================================
1237 /*!
1238  *  MakePrismDXDYDZ_2WAYS
1239  */
1240 //=============================================================================
1241 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ2Ways
1242        (Handle(GEOM_Object) theBase, double theDX, double theDY, double theDZ)
1243 {
1244   SetErrorCode(KO);
1245
1246   if (theBase.IsNull()) return NULL;
1247
1248   //Add a new Prism object
1249   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1250
1251   //Add a new Prism function for creation a Prism by DXDYDZ
1252   Handle(GEOM_Function) aFunction =
1253     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_DXDYDZ_2WAYS);
1254   if (aFunction.IsNull()) return NULL;
1255
1256   //Check if the function is set correctly
1257   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1258
1259   GEOMImpl_IPrism aCI (aFunction);
1260
1261   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1262
1263   if (aRefBase.IsNull()) return NULL;
1264
1265   aCI.SetBase(aRefBase);
1266   aCI.SetDX(theDX);
1267   aCI.SetDY(theDY);
1268   aCI.SetDZ(theDZ);
1269
1270   //Compute the Prism value
1271   try {
1272 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1273     OCC_CATCH_SIGNALS;
1274 #endif
1275     if (!GetSolver()->ComputeFunction(aFunction)) {
1276       SetErrorCode("Extrusion can not be created, check input data");
1277       return NULL;
1278     }
1279   }
1280   catch (Standard_Failure) {
1281     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1282     SetErrorCode(aFail->GetMessageString());
1283     return NULL;
1284   }
1285
1286   //Make a Python command
1287   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismDXDYDZ2Ways("
1288     << theBase << ", " << theDX << ", " << theDY << ", " << theDZ << ")";
1289
1290   SetErrorCode(OK);
1291   return aPrism;
1292 }
1293
1294 //=============================================================================
1295 /*!
1296  *  MakePipe
1297  */
1298 //=============================================================================
1299 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
1300                                                           Handle(GEOM_Object) thePath)
1301 {
1302   SetErrorCode(KO);
1303
1304   if (theBase.IsNull() || thePath.IsNull()) return NULL;
1305
1306   //Add a new Pipe object
1307   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1308
1309   //Add a new Pipe function
1310   Handle(GEOM_Function) aFunction =
1311     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
1312   if (aFunction.IsNull()) return NULL;
1313
1314   //Check if the function is set correctly
1315   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
1316
1317   GEOMImpl_IPipe aCI (aFunction);
1318
1319   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1320   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1321
1322   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
1323
1324   aCI.SetBase(aRefBase);
1325   aCI.SetPath(aRefPath);
1326
1327   //Compute the Pipe value
1328   try {
1329 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1330     OCC_CATCH_SIGNALS;
1331 #endif
1332     if (!GetSolver()->ComputeFunction(aFunction)) {
1333       SetErrorCode("Pipe driver failed");
1334       return NULL;
1335     }
1336   }
1337   catch (Standard_Failure) {
1338     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1339     SetErrorCode(aFail->GetMessageString());
1340     return NULL;
1341   }
1342
1343   //Make a Python command
1344   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipe("
1345     << theBase << ", " << thePath << ")";
1346
1347   SetErrorCode(OK);
1348   return aPipe;
1349 }
1350
1351
1352 //=============================================================================
1353 /*!
1354  *  MakeRevolutionAxisAngle
1355  */
1356 //=============================================================================
1357 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
1358                                                                          Handle(GEOM_Object) theAxis,
1359                                                                          double theAngle)
1360 {
1361   SetErrorCode(KO);
1362
1363   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
1364
1365   //Add a new Revolution object
1366   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
1367
1368   //Add a new Revolution function for creation a revolution relatively to axis
1369   Handle(GEOM_Function) aFunction =
1370     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
1371   if (aFunction.IsNull()) return NULL;
1372
1373   //Check if the function is set correctly
1374   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
1375
1376   GEOMImpl_IRevolution aCI (aFunction);
1377
1378   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1379   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
1380
1381   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
1382
1383   aCI.SetBase(aRefBase);
1384   aCI.SetAxis(aRefAxis);
1385   aCI.SetAngle(theAngle);
1386
1387   //Compute the Revolution value
1388   try {
1389 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1390     OCC_CATCH_SIGNALS;
1391 #endif
1392     if (!GetSolver()->ComputeFunction(aFunction)) {
1393       SetErrorCode("Revolution driver failed");
1394       return NULL;
1395     }
1396   }
1397   catch (Standard_Failure) {
1398     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1399     SetErrorCode(aFail->GetMessageString());
1400     return NULL;
1401   }
1402
1403   //Make a Python command
1404   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
1405     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1406
1407   SetErrorCode(OK);
1408   return aRevolution;
1409 }
1410
1411 //=============================================================================
1412 /*!
1413  *  MakeRevolutionAxisAngle2Ways
1414  */
1415 //=============================================================================
1416 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle2Ways
1417                    (Handle(GEOM_Object) theBase, Handle(GEOM_Object) theAxis, double theAngle)
1418 {
1419   SetErrorCode(KO);
1420
1421   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
1422
1423   //Add a new Revolution object
1424   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
1425
1426   //Add a new Revolution function for creation a revolution relatively to axis
1427   Handle(GEOM_Function) aFunction =
1428     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE_2WAYS);
1429   if (aFunction.IsNull()) return NULL;
1430
1431   //Check if the function is set correctly
1432   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
1433
1434   GEOMImpl_IRevolution aCI (aFunction);
1435
1436   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1437   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
1438
1439   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
1440
1441   aCI.SetBase(aRefBase);
1442   aCI.SetAxis(aRefAxis);
1443   aCI.SetAngle(theAngle);
1444
1445   //Compute the Revolution value
1446   try {
1447 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1448     OCC_CATCH_SIGNALS;
1449 #endif
1450     if (!GetSolver()->ComputeFunction(aFunction)) {
1451       SetErrorCode("Revolution driver failed");
1452       return NULL;
1453     }
1454   }
1455   catch (Standard_Failure) {
1456     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1457     SetErrorCode(aFail->GetMessageString());
1458     return NULL;
1459   }
1460
1461   //Make a Python command
1462   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution2Ways("
1463     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1464
1465   SetErrorCode(OK);
1466   return aRevolution;
1467 }
1468
1469 //=============================================================================
1470 /*!
1471  *  MakeFilling
1472  */
1473 //=============================================================================
1474 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFilling
1475        (Handle(GEOM_Object) theShape, int theMinDeg, int theMaxDeg,
1476         double theTol2D, double theTol3D, int theNbIter,
1477         int theMethod, bool isApprox)
1478 {
1479   SetErrorCode(KO);
1480
1481   if (theShape.IsNull()) return NULL;
1482
1483   //Add a new Filling object
1484   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
1485
1486   //Add a new Filling function for creation a filling  from a compound
1487   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
1488   if (aFunction.IsNull()) return NULL;
1489
1490   //Check if the function is set correctly
1491   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
1492
1493   GEOMImpl_IFilling aFI (aFunction);
1494
1495   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1496
1497   if (aRefShape.IsNull()) return NULL;
1498
1499   aFI.SetShape(aRefShape);
1500   aFI.SetMinDeg(theMinDeg);
1501   aFI.SetMaxDeg(theMaxDeg);
1502   aFI.SetTol2D(theTol2D);
1503   aFI.SetTol3D(theTol3D);
1504   aFI.SetNbIter(theNbIter);
1505   aFI.SetApprox(isApprox);
1506   aFI.SetMethod(theMethod);
1507
1508   //Compute the Solid value
1509   try {
1510 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1511     OCC_CATCH_SIGNALS;
1512 #endif
1513     if (!GetSolver()->ComputeFunction(aFunction)) {
1514       SetErrorCode("Filling driver failed");
1515       return NULL;
1516     }
1517   }
1518   catch (Standard_Failure) {
1519     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1520     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
1521       SetErrorCode("B-Spline surface construction failed");
1522     else
1523       SetErrorCode(aFail->GetMessageString());
1524     return NULL;
1525   }
1526
1527   //Make a Python command
1528   GEOM::TPythonDump pd (aFunction);
1529   pd << aFilling << " = geompy.MakeFilling("
1530      << theShape << ", " << theMinDeg << ", " << theMaxDeg << ", "
1531      << theTol2D << ", " << theTol3D << ", " << theNbIter  << ", ";
1532   if( theMethod==1 ) pd << "GEOM.FOM_UseOri";
1533   else if( theMethod==2 ) pd << "GEOM.FOM_AutoCorrect";
1534   else pd << "GEOM.FOM_Default";
1535   if(isApprox)
1536     pd << ", " << isApprox ;
1537   pd << ")";
1538
1539   SetErrorCode(OK);
1540   return aFilling;
1541 }
1542
1543 //=============================================================================
1544 /*!
1545  *  MakeThruSections
1546  */
1547 //=============================================================================
1548 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThruSections(
1549                                                 const Handle(TColStd_HSequenceOfTransient)& theSeqSections,
1550                                                 bool theModeSolid,
1551                                                 double thePreci,
1552                                                 bool theRuled)
1553 {
1554   Handle(GEOM_Object) anObj;
1555   SetErrorCode(KO);
1556   if(theSeqSections.IsNull())
1557     return anObj;
1558
1559   Standard_Integer nbObj = theSeqSections->Length();
1560   if (!nbObj)
1561     return anObj;
1562
1563   //Add a new ThruSections object
1564   Handle(GEOM_Object) aThruSect = GetEngine()->AddObject(GetDocID(), GEOM_THRUSECTIONS);
1565
1566
1567   //Add a new ThruSections function
1568
1569   int aTypeFunc = (theRuled ? THRUSECTIONS_RULED : THRUSECTIONS_SMOOTHED);
1570   Handle(GEOM_Function) aFunction =
1571     aThruSect->AddFunction(GEOMImpl_ThruSectionsDriver::GetID(), aTypeFunc);
1572   if (aFunction.IsNull()) return anObj;
1573
1574   //Check if the function is set correctly
1575   if (aFunction->GetDriverGUID() != GEOMImpl_ThruSectionsDriver::GetID()) return NULL;
1576
1577   GEOMImpl_IThruSections aCI (aFunction);
1578
1579   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
1580
1581   Standard_Integer i =1;
1582   for( ; i <= nbObj; i++) {
1583
1584     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1585     if(anItem.IsNull())
1586       continue;
1587
1588     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1589     if(!aSectObj.IsNull())
1590     {
1591       Handle(GEOM_Function) aRefSect = aSectObj->GetLastFunction();
1592       if(!aRefSect.IsNull())
1593         aSeqSections->Append(aRefSect);
1594     }
1595   }
1596
1597   if(!aSeqSections->Length())
1598     return anObj;
1599
1600   aCI.SetSections(aSeqSections);
1601   aCI.SetSolidMode(theModeSolid);
1602   aCI.SetPrecision(thePreci);
1603
1604   //Compute the ThruSections value
1605   try {
1606 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1607     OCC_CATCH_SIGNALS;
1608 #endif
1609     if (!GetSolver()->ComputeFunction(aFunction)) {
1610       SetErrorCode("ThruSections driver failed");
1611       return anObj;
1612     }
1613   }
1614   catch (Standard_Failure) {
1615     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1616     SetErrorCode(aFail->GetMessageString());
1617     return anObj;
1618   }
1619
1620   //Make a Python command
1621   GEOM::TPythonDump pyDump(aFunction);
1622   pyDump << aThruSect << " = geompy.MakeThruSections([";
1623
1624   for(i =1 ; i <= nbObj; i++) {
1625
1626     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1627     if(anItem.IsNull())
1628       continue;
1629
1630     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1631     if(!aSectObj.IsNull()) {
1632       pyDump<< aSectObj;
1633       if(i < nbObj)
1634         pyDump<<", ";
1635     }
1636   }
1637
1638   pyDump<< "],"<<theModeSolid << "," << thePreci <<","<< theRuled <<")";
1639
1640   SetErrorCode(OK);
1641   return aThruSect;
1642 }
1643
1644
1645 //=============================================================================
1646 /*!
1647  *  MakePipeWithDifferentSections
1648  */
1649 //=============================================================================
1650 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithDifferentSections(
1651                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1652                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1653                 const Handle(GEOM_Object)& thePath,
1654                 bool theWithContact,
1655                 bool theWithCorrections)
1656 {
1657   Handle(GEOM_Object) anObj;
1658   SetErrorCode(KO);
1659   if(theBases.IsNull())
1660     return anObj;
1661
1662   Standard_Integer nbBases = theBases->Length();
1663
1664   if (!nbBases)
1665     return anObj;
1666
1667   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1668   //Add a new Pipe object
1669   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1670
1671   //Add a new Pipe function
1672
1673   Handle(GEOM_Function) aFunction =
1674     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_DIFFERENT_SECTIONS);
1675   if (aFunction.IsNull()) return anObj;
1676
1677   //Check if the function is set correctly
1678   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1679
1680   GEOMImpl_IPipeDiffSect aCI (aFunction);
1681
1682   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1683   if(aRefPath.IsNull())
1684     return anObj;
1685
1686   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1687   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1688
1689   Standard_Integer i =1;
1690   for( ; i <= nbBases; i++) {
1691
1692     Handle(Standard_Transient) anItem = theBases->Value(i);
1693     if(anItem.IsNull())
1694       continue;
1695
1696     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1697     if(aBase.IsNull())
1698       continue;
1699     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1700     if(aRefBase.IsNull())
1701       continue;
1702     if(nbLocs)
1703     {
1704       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1705       if(anItemLoc.IsNull())
1706         continue;
1707
1708       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1709       if(aLoc.IsNull())
1710         continue;
1711       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1712       if(aRefLoc.IsNull())
1713         continue;
1714       aSeqLocs->Append(aRefLoc);
1715     }
1716     aSeqBases->Append(aRefBase);
1717   }
1718
1719   if(!aSeqBases->Length())
1720     return anObj;
1721
1722   aCI.SetBases(aSeqBases);
1723   aCI.SetLocations(aSeqLocs);
1724   aCI.SetPath(aRefPath);
1725   aCI.SetWithContactMode(theWithContact);
1726   aCI.SetWithCorrectionMode(theWithCorrections);
1727
1728   //Compute the Pipe value
1729   try {
1730 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1731     OCC_CATCH_SIGNALS;
1732 #endif
1733     if (!GetSolver()->ComputeFunction(aFunction)) {
1734       SetErrorCode("Pipe with defferent section driver failed");
1735       return anObj;
1736     }
1737   }
1738   catch (Standard_Failure) {
1739     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1740     SetErrorCode(aFail->GetMessageString());
1741     return anObj;
1742   }
1743
1744   //Make a Python command
1745   GEOM::TPythonDump pyDump(aFunction);
1746   pyDump << aPipeDS << " = geompy.MakePipeWithDifferentSections([";
1747
1748   for(i =1 ; i <= nbBases; i++) {
1749
1750     Handle(Standard_Transient) anItem = theBases->Value(i);
1751     if(anItem.IsNull())
1752       continue;
1753
1754     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1755     if(!anObj.IsNull()) {
1756       pyDump<< anObj;
1757       if(i < nbBases)
1758         pyDump<<", ";
1759     }
1760   }
1761
1762   pyDump<< "], [";
1763
1764   for(i =1 ; i <= nbLocs; i++) {
1765
1766     Handle(Standard_Transient) anItem = theLocations->Value(i);
1767     if(anItem.IsNull())
1768       continue;
1769
1770     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1771     if(!anObj.IsNull()) {
1772       pyDump<< anObj;
1773       if(i < nbLocs)
1774         pyDump<<", ";
1775     }
1776   }
1777
1778   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1779
1780   SetErrorCode(OK);
1781   return aPipeDS;
1782 }
1783
1784
1785 //=============================================================================
1786 /*!
1787  *  MakePipeWithShellSections
1788  */
1789 //=============================================================================
1790 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithShellSections(
1791                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1792                 const Handle(TColStd_HSequenceOfTransient)& theSubBases,
1793                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1794                 const Handle(GEOM_Object)& thePath,
1795                 bool theWithContact,
1796                 bool theWithCorrections)
1797 {
1798   Handle(GEOM_Object) anObj;
1799   SetErrorCode(KO);
1800   if(theBases.IsNull())
1801     return anObj;
1802
1803   Standard_Integer nbBases = theBases->Length();
1804
1805   if (!nbBases)
1806     return anObj;
1807
1808   Standard_Integer nbSubBases =  (theSubBases.IsNull() ? 0 :theSubBases->Length());
1809
1810   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1811
1812   //Add a new Pipe object
1813   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1814
1815   //Add a new Pipe function
1816
1817   Handle(GEOM_Function) aFunction =
1818     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELL_SECTIONS);
1819   if (aFunction.IsNull()) return anObj;
1820
1821   //Check if the function is set correctly
1822   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1823
1824   //GEOMImpl_IPipeDiffSect aCI (aFunction);
1825   GEOMImpl_IPipeShellSect aCI (aFunction);
1826
1827   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1828   if(aRefPath.IsNull())
1829     return anObj;
1830
1831   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1832   Handle(TColStd_HSequenceOfTransient) aSeqSubBases = new TColStd_HSequenceOfTransient;
1833   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1834
1835   Standard_Integer i =1;
1836   for( ; i <= nbBases; i++) {
1837
1838     Handle(Standard_Transient) anItem = theBases->Value(i);
1839     if(anItem.IsNull())
1840       continue;
1841     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1842     if(aBase.IsNull())
1843       continue;
1844     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1845     if(aRefBase.IsNull())
1846       continue;
1847
1848     if( nbSubBases >= nbBases ) {
1849       Handle(Standard_Transient) aSubItem = theSubBases->Value(i);
1850       if(aSubItem.IsNull())
1851         continue;
1852       Handle(GEOM_Object) aSubBase = Handle(GEOM_Object)::DownCast(aSubItem);
1853       if(aSubBase.IsNull())
1854         continue;
1855       Handle(GEOM_Function) aRefSubBase = aSubBase->GetLastFunction();
1856       if(aRefSubBase.IsNull())
1857         continue;
1858       aSeqSubBases->Append(aRefSubBase);
1859     }
1860
1861     if(nbLocs) {
1862       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1863       if(anItemLoc.IsNull())
1864         continue;
1865       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1866       if(aLoc.IsNull())
1867         continue;
1868       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1869       if(aRefLoc.IsNull())
1870         continue;
1871       aSeqLocs->Append(aRefLoc);
1872     }
1873
1874     aSeqBases->Append(aRefBase);
1875   }
1876
1877   if(!aSeqBases->Length())
1878     return anObj;
1879
1880   aCI.SetBases(aSeqBases);
1881   aCI.SetSubBases(aSeqSubBases);
1882   aCI.SetLocations(aSeqLocs);
1883   aCI.SetPath(aRefPath);
1884   aCI.SetWithContactMode(theWithContact);
1885   aCI.SetWithCorrectionMode(theWithCorrections);
1886
1887   //Compute the Pipe value
1888   try {
1889 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1890     OCC_CATCH_SIGNALS;
1891 #endif
1892     if (!GetSolver()->ComputeFunction(aFunction)) {
1893       SetErrorCode("Pipe with shell sections driver failed");
1894       return anObj;
1895     }
1896   }
1897   catch (Standard_Failure) {
1898     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1899     SetErrorCode(aFail->GetMessageString());
1900     return anObj;
1901   }
1902
1903   //Make a Python command
1904   GEOM::TPythonDump pyDump(aFunction);
1905   pyDump << aPipeDS << " = geompy.MakePipeWithShellSections([";
1906
1907   for(i =1 ; i <= nbBases; i++) {
1908
1909     Handle(Standard_Transient) anItem = theBases->Value(i);
1910     if(anItem.IsNull())
1911       continue;
1912
1913     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1914     if(!anObj.IsNull()) {
1915       pyDump<< anObj;
1916       if(i < nbBases)
1917         pyDump<<", ";
1918     }
1919   }
1920
1921   pyDump<< "], [";
1922
1923   for(i =1 ; i <= nbSubBases; i++) {
1924
1925     Handle(Standard_Transient) anItem = theSubBases->Value(i);
1926     if(anItem.IsNull())
1927       continue;
1928
1929     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1930     if(!anObj.IsNull()) {
1931       pyDump<< anObj;
1932       if(i < nbBases)
1933         pyDump<<", ";
1934     }
1935   }
1936
1937   pyDump<< "], [";
1938
1939   for(i =1 ; i <= nbLocs; i++) {
1940
1941     Handle(Standard_Transient) anItem = theLocations->Value(i);
1942     if(anItem.IsNull())
1943       continue;
1944
1945     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1946     if(!anObj.IsNull()) {
1947       pyDump<< anObj;
1948       if(i < nbLocs)
1949         pyDump<<", ";
1950     }
1951   }
1952
1953   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1954
1955   SetErrorCode(OK);
1956   return aPipeDS;
1957
1958 }
1959
1960
1961 //=============================================================================
1962 /*!
1963  *  MakePipeShellsWithoutPath
1964  */
1965 //=============================================================================
1966 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeShellsWithoutPath(
1967                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1968                 const Handle(TColStd_HSequenceOfTransient)& theLocations)
1969 {
1970   Handle(GEOM_Object) anObj;
1971   SetErrorCode(KO);
1972   if(theBases.IsNull())
1973     return anObj;
1974
1975   Standard_Integer nbBases = theBases->Length();
1976
1977   if (!nbBases)
1978     return anObj;
1979
1980   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1981
1982   //Add a new Pipe object
1983   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1984
1985   //Add a new Pipe function
1986
1987   Handle(GEOM_Function) aFunction =
1988     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELLS_WITHOUT_PATH);
1989   if (aFunction.IsNull()) return anObj;
1990
1991   //Check if the function is set correctly
1992   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1993
1994   GEOMImpl_IPipeShellSect aCI (aFunction);
1995
1996   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1997   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1998
1999   Standard_Integer i =1;
2000   for( ; i <= nbBases; i++) {
2001
2002     Handle(Standard_Transient) anItem = theBases->Value(i);
2003     if(anItem.IsNull())
2004       continue;
2005     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2006     if(aBase.IsNull())
2007       continue;
2008     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2009     if(aRefBase.IsNull())
2010       continue;
2011
2012     if(nbLocs) {
2013       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
2014       if(anItemLoc.IsNull())
2015         continue;
2016       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
2017       if(aLoc.IsNull())
2018         continue;
2019       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
2020       if(aRefLoc.IsNull())
2021         continue;
2022       aSeqLocs->Append(aRefLoc);
2023     }
2024
2025     aSeqBases->Append(aRefBase);
2026   }
2027
2028   if(!aSeqBases->Length())
2029     return anObj;
2030
2031   aCI.SetBases(aSeqBases);
2032   aCI.SetLocations(aSeqLocs);
2033
2034   //Compute the Pipe value
2035   try {
2036 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2037     OCC_CATCH_SIGNALS;
2038 #endif
2039     if (!GetSolver()->ComputeFunction(aFunction)) {
2040       SetErrorCode("Pipe with shell sections without path driver failed");
2041       return anObj;
2042     }
2043   }
2044   catch (Standard_Failure) {
2045     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2046     SetErrorCode(aFail->GetMessageString());
2047     return anObj;
2048   }
2049
2050   //Make a Python command
2051   GEOM::TPythonDump pyDump(aFunction);
2052   pyDump << aPipeDS << " = geompy.MakePipeShellsWithoutPath([";
2053
2054   for(i =1 ; i <= nbBases; i++) {
2055
2056     Handle(Standard_Transient) anItem = theBases->Value(i);
2057     if(anItem.IsNull())
2058       continue;
2059
2060     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2061     if(!anObj.IsNull()) {
2062       pyDump<< anObj;
2063       if(i < nbBases)
2064         pyDump<<", ";
2065     }
2066   }
2067
2068   pyDump<< "], [";
2069
2070   for(i =1 ; i <= nbLocs; i++) {
2071
2072     Handle(Standard_Transient) anItem = theLocations->Value(i);
2073     if(anItem.IsNull())
2074       continue;
2075
2076     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2077     if(!anObj.IsNull()) {
2078       pyDump<< anObj;
2079       if(i < nbLocs)
2080         pyDump<<", ";
2081     }
2082   }
2083
2084   pyDump<< "])";
2085
2086   SetErrorCode(OK);
2087   return aPipeDS;
2088
2089 }
2090
2091
2092 //=============================================================================
2093 /*!
2094  *  MakePipeBiNormalAlongVector
2095  */
2096 //=============================================================================
2097 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeBiNormalAlongVector (Handle(GEOM_Object) theBase,
2098                                                                              Handle(GEOM_Object) thePath,
2099                                                                              Handle(GEOM_Object) theVec)
2100 {
2101   SetErrorCode(KO);
2102
2103   if (theBase.IsNull() || thePath.IsNull() || theVec.IsNull()) return NULL;
2104
2105   //Add a new Pipe object
2106   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
2107
2108   //Add a new Pipe function
2109   Handle(GEOM_Function) aFunction =
2110     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BI_NORMAL_ALONG_VECTOR);
2111   if (aFunction.IsNull()) return NULL;
2112
2113   //Check if the function is set correctly
2114   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
2115
2116   GEOMImpl_IPipeBiNormal aCI (aFunction);
2117
2118   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
2119   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
2120   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
2121
2122   if (aRefBase.IsNull() || aRefPath.IsNull() || aRefVec.IsNull()) return NULL;
2123
2124   aCI.SetBase(aRefBase);
2125   aCI.SetPath(aRefPath);
2126   aCI.SetVector(aRefVec);
2127
2128   //Compute the Pipe value
2129   try {
2130 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2131     OCC_CATCH_SIGNALS;
2132 #endif
2133     if (!GetSolver()->ComputeFunction(aFunction)) {
2134       SetErrorCode("Pipe driver failed");
2135       return NULL;
2136     }
2137   }
2138   catch (Standard_Failure) {
2139     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2140     SetErrorCode(aFail->GetMessageString());
2141     return NULL;
2142   }
2143
2144   //Make a Python command
2145   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipeBiNormalAlongVector("
2146     << theBase << ", " << thePath << ", " << theVec << ")";
2147
2148   SetErrorCode(OK);
2149   return aPipe;
2150 }