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