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