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