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