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