Salome HOME
NPAL14856: Get The Normal of a Face.
[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  *  MakePrismTwoPnt
698  */
699 //=============================================================================
700 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
701        (Handle(GEOM_Object) theBase,
702         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
703 {
704   SetErrorCode(KO);
705
706   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.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 two points
712   Handle(GEOM_Function) aFunction =
713     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
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) aRefPnt1 = thePoint1->GetLastFunction();
723   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
724
725   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
726
727   aCI.SetBase(aRefBase);
728   aCI.SetFirstPoint(aRefPnt1);
729   aCI.SetLastPoint(aRefPnt2);
730
731   //Compute the Prism value
732   try {
733 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
734     OCC_CATCH_SIGNALS;
735 #endif
736     if (!GetSolver()->ComputeFunction(aFunction)) {
737       //SetErrorCode("Prism driver failed");
738       SetErrorCode("Extrusion can not be created, check input data");
739       return NULL;
740     }
741   }
742   catch (Standard_Failure) {
743     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
744     SetErrorCode(aFail->GetMessageString());
745     return NULL;
746   }
747
748   //Make a Python command
749   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism("
750     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
751
752   SetErrorCode(OK);
753   return aPrism;
754 }
755
756
757 //=============================================================================
758 /*!
759  *  MakePipe
760  */
761 //=============================================================================
762 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
763                                                           Handle(GEOM_Object) thePath)
764 {
765   SetErrorCode(KO);
766
767   if (theBase.IsNull() || thePath.IsNull()) return NULL;
768
769   //Add a new Pipe object
770   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
771
772   //Add a new Pipe function
773   Handle(GEOM_Function) aFunction =
774     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
775   if (aFunction.IsNull()) return NULL;
776
777   //Check if the function is set correctly
778   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
779
780   GEOMImpl_IPipe aCI (aFunction);
781
782   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
783   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
784
785   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
786
787   aCI.SetBase(aRefBase);
788   aCI.SetPath(aRefPath);
789
790   //Compute the Pipe value
791   try {
792 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
793     OCC_CATCH_SIGNALS;
794 #endif
795     if (!GetSolver()->ComputeFunction(aFunction)) {
796       SetErrorCode("Pipe driver failed");
797       return NULL;
798     }
799   }
800   catch (Standard_Failure) {
801     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
802     SetErrorCode(aFail->GetMessageString());
803     return NULL;
804   }
805
806   //Make a Python command
807   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipe("
808     << theBase << ", " << thePath << ")";
809
810   SetErrorCode(OK);
811   return aPipe;
812 }
813
814
815 //=============================================================================
816 /*!
817  *  MakeRevolutionAxisAngle
818  */
819 //=============================================================================
820 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
821                                                                          Handle(GEOM_Object) theAxis,
822                                                                          double theAngle)
823 {
824   SetErrorCode(KO);
825
826   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
827
828   //Add a new Revolution object
829   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
830
831   //Add a new Revolution function for creation a revolution relatively to axis
832   Handle(GEOM_Function) aFunction =
833     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
834   if (aFunction.IsNull()) return NULL;
835
836   //Check if the function is set correctly
837   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
838
839   GEOMImpl_IRevolution aCI (aFunction);
840
841   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
842   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
843
844   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
845
846   aCI.SetBase(aRefBase);
847   aCI.SetAxis(aRefAxis);
848   aCI.SetAngle(theAngle);
849
850   //Compute the Revolution value
851   try {
852 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
853     OCC_CATCH_SIGNALS;
854 #endif
855     if (!GetSolver()->ComputeFunction(aFunction)) {
856       SetErrorCode("Revolution driver failed");
857       return NULL;
858     }
859   }
860   catch (Standard_Failure) {
861     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
862     SetErrorCode(aFail->GetMessageString());
863     return NULL;
864   }
865
866   //Make a Python command
867   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
868     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
869
870   SetErrorCode(OK);
871   return aRevolution;
872 }
873
874
875 //=============================================================================
876 /*!
877  *  MakeSolidShell
878  */
879 //=============================================================================
880 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
881 {
882   SetErrorCode(KO);
883
884   if (theShell.IsNull()) return NULL;
885
886   //Add a new Solid object
887   Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
888
889   //Add a new Solid function for creation a solid from a shell
890   Handle(GEOM_Function) aFunction =
891     aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
892   if (aFunction.IsNull()) return NULL;
893
894   //Check if the function is set correctly
895   if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
896
897   GEOMImpl_IShapes aCI (aFunction);
898
899   Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
900
901   if (aRefShell.IsNull()) return NULL;
902
903   aCI.SetBase(aRefShell);
904
905   //Compute the Solid value
906   try {
907 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
908     OCC_CATCH_SIGNALS;
909 #endif
910     if (!GetSolver()->ComputeFunction(aFunction)) {
911       SetErrorCode("Solid driver failed");
912       return NULL;
913     }
914   }
915   catch (Standard_Failure) {
916     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
917     SetErrorCode(aFail->GetMessageString());
918     return NULL;
919   }
920
921   //Make a Python command
922   GEOM::TPythonDump(aFunction) << aSolid << " = geompy.MakeSolid(" << theShell << ")";
923
924   SetErrorCode(OK);
925   return aSolid;
926 }
927
928 //=============================================================================
929 /*!
930  *  MakeFilling
931  */
932 //=============================================================================
933 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFilling
934        (Handle(GEOM_Object) theShape, int theMinDeg, int theMaxDeg,
935         double theTol2D, double theTol3D, int theNbIter)
936 {
937   SetErrorCode(KO);
938
939   if (theShape.IsNull()) return NULL;
940
941   //Add a new Filling object
942   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
943
944   //Add a new Filling function for creation a filling  from a compound
945   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
946   if (aFunction.IsNull()) return NULL;
947
948   //Check if the function is set correctly
949   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
950
951   GEOMImpl_IFilling aFI (aFunction);
952
953   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
954
955   if (aRefShape.IsNull()) return NULL;
956
957   aFI.SetShape(aRefShape);
958   aFI.SetMinDeg(theMinDeg);
959   aFI.SetMaxDeg(theMaxDeg);
960   aFI.SetTol2D(theTol2D);
961   aFI.SetTol3D(theTol3D);
962   aFI.SetNbIter(theNbIter);
963
964   //Compute the Solid value
965   try {
966 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
967     OCC_CATCH_SIGNALS;
968 #endif
969     if (!GetSolver()->ComputeFunction(aFunction)) {
970       SetErrorCode("Filling driver failed");
971       return NULL;
972     }
973   }
974   catch (Standard_Failure) {
975     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
976     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
977       SetErrorCode("B-Spline surface construction failed");
978     else
979       SetErrorCode(aFail->GetMessageString());
980     return NULL;
981   }
982
983   //Make a Python command
984   GEOM::TPythonDump(aFunction) << aFilling << " = geompy.MakeFilling("
985     << theShape << ", " << theMinDeg << ", " << theMaxDeg << ", "
986       << theTol2D << ", " << theTol3D << ", " << theNbIter << ")";
987
988   SetErrorCode(OK);
989   return aFilling;
990 }
991
992 //=============================================================================
993 /*!
994  *  MakeThruSections
995  */
996 //=============================================================================
997 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThruSections(
998                                                 const Handle(TColStd_HSequenceOfTransient)& theSeqSections,
999                                                 bool theModeSolid,
1000                                                 double thePreci,
1001                                                 bool theRuled)
1002 {
1003   Handle(GEOM_Object) anObj;
1004   SetErrorCode(KO);
1005   if(theSeqSections.IsNull())
1006     return anObj;
1007
1008   Standard_Integer nbObj = theSeqSections->Length();
1009   if (!nbObj) 
1010     return anObj;
1011
1012   //Add a new ThruSections object
1013   Handle(GEOM_Object) aThruSect = GetEngine()->AddObject(GetDocID(), GEOM_THRUSECTIONS);
1014
1015  
1016   //Add a new ThruSections function
1017
1018   int aTypeFunc = (theRuled ? THRUSECTIONS_RULED : THRUSECTIONS_SMOOTHED);
1019   Handle(GEOM_Function) aFunction =
1020     aThruSect->AddFunction(GEOMImpl_ThruSectionsDriver::GetID(), aTypeFunc);
1021   if (aFunction.IsNull()) return anObj;
1022
1023   //Check if the function is set correctly
1024   if (aFunction->GetDriverGUID() != GEOMImpl_ThruSectionsDriver::GetID()) return NULL;
1025
1026   GEOMImpl_IThruSections aCI (aFunction);
1027
1028   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
1029
1030   Standard_Integer i =1;
1031   for( ; i <= nbObj; i++) {
1032
1033     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1034     if(anItem.IsNull())
1035       continue;
1036     
1037     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1038     if(!aSectObj.IsNull())
1039     {
1040       Handle(GEOM_Function) aRefSect = aSectObj->GetLastFunction();
1041       if(!aRefSect.IsNull())
1042         aSeqSections->Append(aRefSect);
1043     }
1044   }
1045
1046   if(!aSeqSections->Length())
1047     return anObj;
1048
1049   aCI.SetSections(aSeqSections);
1050   aCI.SetSolidMode(theModeSolid);
1051   aCI.SetPrecision(thePreci);
1052
1053   //Compute the ThruSections value
1054   try {
1055 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1056     OCC_CATCH_SIGNALS;
1057 #endif
1058     if (!GetSolver()->ComputeFunction(aFunction)) {
1059       SetErrorCode("ThruSections driver failed");
1060       return anObj;
1061     }
1062   }
1063   catch (Standard_Failure) {
1064     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1065     SetErrorCode(aFail->GetMessageString());
1066     return anObj;
1067   }
1068
1069   //Make a Python command
1070   GEOM::TPythonDump pyDump(aFunction);
1071   pyDump << aThruSect << " = geompy.MakeThruSections([";
1072
1073   for(i =1 ; i <= nbObj; i++) {
1074
1075     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1076     if(anItem.IsNull())
1077       continue;
1078     
1079     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1080     if(!aSectObj.IsNull()) {
1081       pyDump<< aSectObj;
1082       if(i < nbObj)
1083         pyDump<<", ";
1084     }
1085   }
1086   
1087   pyDump<< "],"<<theModeSolid << "," << thePreci <<","<< theRuled <<")";
1088
1089   SetErrorCode(OK);
1090   return aThruSect;
1091   
1092    
1093 }
1094
1095
1096 //=============================================================================
1097 /*!
1098  *  MakePipeWithDifferentSections
1099  */
1100 //=============================================================================
1101 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithDifferentSections(
1102                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1103                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1104                 const Handle(GEOM_Object)& thePath,
1105                 bool theWithContact,
1106                 bool theWithCorrections)
1107 {
1108   Handle(GEOM_Object) anObj;
1109   SetErrorCode(KO);
1110   if(theBases.IsNull())
1111     return anObj;
1112
1113   Standard_Integer nbBases = theBases->Length();
1114   
1115   if (!nbBases)
1116     return anObj;
1117   
1118   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1119   //Add a new Pipe object
1120   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1121  
1122   //Add a new Pipe function
1123
1124   Handle(GEOM_Function) aFunction =
1125     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_DIFFERENT_SECTIONS);
1126   if (aFunction.IsNull()) return anObj;
1127
1128   //Check if the function is set correctly
1129   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1130
1131   GEOMImpl_IPipeDiffSect aCI (aFunction);
1132
1133   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1134   if(aRefPath.IsNull())
1135     return anObj;
1136
1137   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1138   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1139
1140   Standard_Integer i =1;
1141   for( ; i <= nbBases; i++) {
1142
1143     Handle(Standard_Transient) anItem = theBases->Value(i);
1144     if(anItem.IsNull())
1145       continue;
1146     
1147     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1148     if(aBase.IsNull())
1149       continue;
1150     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1151     if(aRefBase.IsNull())
1152       continue;
1153     if(nbLocs)
1154     {
1155       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1156       if(anItemLoc.IsNull())
1157         continue;
1158     
1159       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1160       if(aLoc.IsNull())
1161         continue;
1162       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1163       if(aRefLoc.IsNull())
1164         continue;
1165       aSeqLocs->Append(aRefLoc);
1166     }
1167     aSeqBases->Append(aRefBase);
1168   }
1169
1170   if(!aSeqBases->Length())
1171     return anObj;
1172
1173   aCI.SetBases(aSeqBases);
1174   aCI.SetLocations(aSeqLocs);
1175   aCI.SetPath(aRefPath);
1176   aCI.SetWithContactMode(theWithContact);
1177   aCI.SetWithCorrectionMode(theWithCorrections);
1178   
1179   //Compute the Pipe value
1180   try {
1181 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1182     OCC_CATCH_SIGNALS;
1183 #endif
1184     if (!GetSolver()->ComputeFunction(aFunction)) {
1185       SetErrorCode("Pipe with defferent section driver failed");
1186       return anObj;
1187     }
1188   }
1189   catch (Standard_Failure) {
1190     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1191     SetErrorCode(aFail->GetMessageString());
1192     return anObj;
1193   }
1194
1195   //Make a Python command
1196   GEOM::TPythonDump pyDump(aFunction);
1197   pyDump << aPipeDS << " = geompy.MakePipeWithDifferentSections([";
1198
1199   for(i =1 ; i <= nbBases; i++) {
1200
1201     Handle(Standard_Transient) anItem = theBases->Value(i);
1202     if(anItem.IsNull())
1203       continue;
1204     
1205     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1206     if(!anObj.IsNull()) {
1207       pyDump<< anObj;
1208       if(i < nbBases)
1209         pyDump<<", ";
1210     }
1211     
1212   }
1213   
1214   pyDump<< "], [";
1215    
1216   for(i =1 ; i <= nbLocs; i++) {
1217
1218     Handle(Standard_Transient) anItem = theLocations->Value(i);
1219     if(anItem.IsNull())
1220       continue;
1221     
1222     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1223     if(!anObj.IsNull()) {
1224       pyDump<< anObj;
1225       if(i < nbLocs)
1226         pyDump<<", ";
1227     }
1228   }  
1229
1230   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1231
1232   SetErrorCode(OK);
1233   return aPipeDS;
1234   
1235    
1236 }
1237
1238
1239 //=============================================================================
1240 /*!
1241  *  MakePipeWithShellSections
1242  */
1243 //=============================================================================
1244 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithShellSections(
1245                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1246                 const Handle(TColStd_HSequenceOfTransient)& theSubBases,
1247                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1248                 const Handle(GEOM_Object)& thePath,
1249                 bool theWithContact,
1250                 bool theWithCorrections)
1251 {
1252   Handle(GEOM_Object) anObj;
1253   SetErrorCode(KO);
1254   if(theBases.IsNull())
1255     return anObj;
1256
1257   Standard_Integer nbBases = theBases->Length();
1258   
1259   if (!nbBases)
1260     return anObj;
1261   
1262   Standard_Integer nbSubBases =  (theSubBases.IsNull() ? 0 :theSubBases->Length());
1263
1264   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1265
1266   //Add a new Pipe object
1267   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1268  
1269   //Add a new Pipe function
1270
1271   Handle(GEOM_Function) aFunction =
1272     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELL_SECTIONS);
1273   if (aFunction.IsNull()) return anObj;
1274
1275   //Check if the function is set correctly
1276   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1277
1278   //GEOMImpl_IPipeDiffSect aCI (aFunction);
1279   GEOMImpl_IPipeShellSect aCI (aFunction);
1280
1281   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1282   if(aRefPath.IsNull())
1283     return anObj;
1284
1285   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1286   Handle(TColStd_HSequenceOfTransient) aSeqSubBases = new TColStd_HSequenceOfTransient;
1287   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1288
1289   Standard_Integer i =1;
1290   for( ; i <= nbBases; i++) {
1291
1292     Handle(Standard_Transient) anItem = theBases->Value(i);
1293     if(anItem.IsNull())
1294       continue;
1295     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1296     if(aBase.IsNull())
1297       continue;
1298     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1299     if(aRefBase.IsNull())
1300       continue;
1301
1302     if( nbSubBases >= nbBases ) {
1303       Handle(Standard_Transient) aSubItem = theSubBases->Value(i);
1304       if(aSubItem.IsNull())
1305         continue;
1306       Handle(GEOM_Object) aSubBase = Handle(GEOM_Object)::DownCast(aSubItem);
1307       if(aSubBase.IsNull())
1308         continue;
1309       Handle(GEOM_Function) aRefSubBase = aSubBase->GetLastFunction();
1310       if(aRefSubBase.IsNull())
1311         continue;
1312       aSeqSubBases->Append(aRefSubBase);
1313     }
1314
1315     if(nbLocs) {
1316       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1317       if(anItemLoc.IsNull())
1318         continue;
1319       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1320       if(aLoc.IsNull())
1321         continue;
1322       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1323       if(aRefLoc.IsNull())
1324         continue;
1325       aSeqLocs->Append(aRefLoc);
1326     }
1327
1328     aSeqBases->Append(aRefBase);
1329   }
1330
1331   if(!aSeqBases->Length())
1332     return anObj;
1333
1334   aCI.SetBases(aSeqBases);
1335   aCI.SetSubBases(aSeqSubBases);
1336   aCI.SetLocations(aSeqLocs);
1337   aCI.SetPath(aRefPath);
1338   aCI.SetWithContactMode(theWithContact);
1339   aCI.SetWithCorrectionMode(theWithCorrections);
1340   
1341   //Compute the Pipe value
1342   try {
1343 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1344     OCC_CATCH_SIGNALS;
1345 #endif
1346     if (!GetSolver()->ComputeFunction(aFunction)) {
1347       SetErrorCode("Pipe with shell sections driver failed");
1348       return anObj;
1349     }
1350   }
1351   catch (Standard_Failure) {
1352     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1353     SetErrorCode(aFail->GetMessageString());
1354     return anObj;
1355   }
1356
1357   //Make a Python command
1358   GEOM::TPythonDump pyDump(aFunction);
1359   pyDump << aPipeDS << " = geompy.MakePipeWithShellSections([";
1360
1361   for(i =1 ; i <= nbBases; i++) {
1362
1363     Handle(Standard_Transient) anItem = theBases->Value(i);
1364     if(anItem.IsNull())
1365       continue;
1366     
1367     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1368     if(!anObj.IsNull()) {
1369       pyDump<< anObj;
1370       if(i < nbBases)
1371         pyDump<<", ";
1372     }
1373     
1374   }
1375   
1376   pyDump<< "], [";
1377    
1378   for(i =1 ; i <= nbSubBases; i++) {
1379
1380     Handle(Standard_Transient) anItem = theSubBases->Value(i);
1381     if(anItem.IsNull())
1382       continue;
1383     
1384     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1385     if(!anObj.IsNull()) {
1386       pyDump<< anObj;
1387       if(i < nbBases)
1388         pyDump<<", ";
1389     }
1390     
1391   }
1392   
1393   pyDump<< "], [";
1394    
1395   for(i =1 ; i <= nbLocs; i++) {
1396
1397     Handle(Standard_Transient) anItem = theLocations->Value(i);
1398     if(anItem.IsNull())
1399       continue;
1400     
1401     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1402     if(!anObj.IsNull()) {
1403       pyDump<< anObj;
1404       if(i < nbLocs)
1405         pyDump<<", ";
1406     }
1407   }  
1408
1409   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1410
1411   SetErrorCode(OK);
1412   return aPipeDS;
1413
1414 }
1415
1416
1417 //=============================================================================
1418 /*!
1419  *  MakePipeShellsWithoutPath
1420  */
1421 //=============================================================================
1422 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeShellsWithoutPath(
1423                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1424                 const Handle(TColStd_HSequenceOfTransient)& theLocations)
1425 {
1426   Handle(GEOM_Object) anObj;
1427   SetErrorCode(KO);
1428   if(theBases.IsNull())
1429     return anObj;
1430
1431   Standard_Integer nbBases = theBases->Length();
1432   
1433   if (!nbBases)
1434     return anObj;
1435   
1436   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1437
1438   //Add a new Pipe object
1439   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1440  
1441   //Add a new Pipe function
1442
1443   Handle(GEOM_Function) aFunction =
1444     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELLS_WITHOUT_PATH);
1445   if (aFunction.IsNull()) return anObj;
1446
1447   //Check if the function is set correctly
1448   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1449
1450   GEOMImpl_IPipeShellSect aCI (aFunction);
1451
1452   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1453   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1454
1455   Standard_Integer i =1;
1456   for( ; i <= nbBases; i++) {
1457
1458     Handle(Standard_Transient) anItem = theBases->Value(i);
1459     if(anItem.IsNull())
1460       continue;
1461     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1462     if(aBase.IsNull())
1463       continue;
1464     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1465     if(aRefBase.IsNull())
1466       continue;
1467
1468     if(nbLocs) {
1469       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1470       if(anItemLoc.IsNull())
1471         continue;
1472       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1473       if(aLoc.IsNull())
1474         continue;
1475       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1476       if(aRefLoc.IsNull())
1477         continue;
1478       aSeqLocs->Append(aRefLoc);
1479     }
1480
1481     aSeqBases->Append(aRefBase);
1482   }
1483
1484   if(!aSeqBases->Length())
1485     return anObj;
1486
1487   aCI.SetBases(aSeqBases);
1488   aCI.SetLocations(aSeqLocs);
1489   
1490   //Compute the Pipe value
1491   try {
1492 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1493     OCC_CATCH_SIGNALS;
1494 #endif
1495     if (!GetSolver()->ComputeFunction(aFunction)) {
1496       SetErrorCode("Pipe with shell sections without path driver failed");
1497       return anObj;
1498     }
1499   }
1500   catch (Standard_Failure) {
1501     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1502     SetErrorCode(aFail->GetMessageString());
1503     return anObj;
1504   }
1505
1506   //Make a Python command
1507   GEOM::TPythonDump pyDump(aFunction);
1508   pyDump << aPipeDS << " = geompy.MakePipeShellsWithoutPath([";
1509
1510   for(i =1 ; i <= nbBases; i++) {
1511
1512     Handle(Standard_Transient) anItem = theBases->Value(i);
1513     if(anItem.IsNull())
1514       continue;
1515     
1516     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1517     if(!anObj.IsNull()) {
1518       pyDump<< anObj;
1519       if(i < nbBases)
1520         pyDump<<", ";
1521     }
1522     
1523   }
1524   
1525   pyDump<< "], [";
1526    
1527   for(i =1 ; i <= nbLocs; i++) {
1528
1529     Handle(Standard_Transient) anItem = theLocations->Value(i);
1530     if(anItem.IsNull())
1531       continue;
1532     
1533     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1534     if(!anObj.IsNull()) {
1535       pyDump<< anObj;
1536       if(i < nbLocs)
1537         pyDump<<", ";
1538     }
1539   }  
1540
1541   pyDump<< "])";
1542
1543   SetErrorCode(OK);
1544   return aPipeDS;
1545
1546 }
1547