Salome HOME
1fd9e6a5b33a714f5d515d5adb2a53f9d0fbc4c9
[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
63 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
64
65 //=============================================================================
66 /*!
67  *   constructor:
68  */
69 //=============================================================================
70 GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, int theDocID)
71 : GEOM_IOperations(theEngine, theDocID)
72 {
73   MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations");
74 }
75
76 //=============================================================================
77 /*!
78  *  destructor
79  */
80 //=============================================================================
81 GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations()
82 {
83   MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations");
84 }
85
86
87 //=============================================================================
88 /*!
89  *  MakeBoxDXDYDZ
90  */
91 //=============================================================================
92 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxDXDYDZ (double theDX, double theDY, double theDZ)
93 {
94   SetErrorCode(KO);
95
96   //Add a new Box object
97   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
98
99   //Add a new Box function with DX_DY_DZ parameters
100   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_DX_DY_DZ);
101   if (aFunction.IsNull()) return NULL;
102
103   //Check if the function is set correctly
104   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return NULL;
105
106   GEOMImpl_IBox aBI (aFunction);
107
108   aBI.SetDX(theDX);
109   aBI.SetDY(theDY);
110   aBI.SetDZ(theDZ);
111
112   //Compute the box value
113   try {
114     if (!GetSolver()->ComputeFunction(aFunction)) {
115       SetErrorCode("Box driver failed");
116       return NULL;
117     }
118   }
119   catch (Standard_Failure) {
120     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
121     SetErrorCode(aFail->GetMessageString());
122     return NULL;
123   }
124
125   //Make a Python command
126   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxDXDYDZ("
127     << theDX << ", " << theDY << ", " << theDZ << ")";
128
129   SetErrorCode(OK);
130   return aBox;
131 }
132
133
134 //=============================================================================
135 /*!
136  *  MakeBoxTwoPnt
137  */
138 //=============================================================================
139 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxTwoPnt (Handle(GEOM_Object) thePnt1,
140                                                                Handle(GEOM_Object) thePnt2)
141 {
142   SetErrorCode(KO);
143
144   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
145
146   //Add a new Box object
147   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
148
149   //Add a new Box function for creation a box relatively to two points
150   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_TWO_PNT);
151   if (aFunction.IsNull()) return NULL;
152
153   //Check if the function is set correctly
154   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return aBox;
155
156   GEOMImpl_IBox aBI (aFunction);
157
158   Handle(GEOM_Function) aRefFunction1 = thePnt1->GetLastFunction();
159   Handle(GEOM_Function) aRefFunction2 = thePnt2->GetLastFunction();
160
161   if (aRefFunction1.IsNull() || aRefFunction2.IsNull()) return aBox;
162
163   aBI.SetRef1(aRefFunction1);
164   aBI.SetRef2(aRefFunction2);
165
166   //Compute the Box value
167   try {
168     if (!GetSolver()->ComputeFunction(aFunction)) {
169       SetErrorCode("Box driver failed");
170       return NULL;
171     }
172   }
173   catch (Standard_Failure) {
174     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
175     SetErrorCode(aFail->GetMessageString());
176     return NULL;
177   }
178
179   //Make a Python command
180   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxTwoPnt("
181     << thePnt1 << ", " << thePnt2 << ")";
182
183   SetErrorCode(OK);
184   return aBox;
185 }
186
187
188 //=============================================================================
189 /*!
190  *  MakeCylinderRH
191  */
192 //=============================================================================
193 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRH (double theR, double theH)
194 {
195   SetErrorCode(KO);
196
197   //Add a new Cylinder object
198   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
199
200   //Add a new Cylinder function with R and H parameters
201   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H);
202   if (aFunction.IsNull()) return NULL;
203
204   //Check if the function is set correctly
205   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
206
207   GEOMImpl_ICylinder aCI (aFunction);
208
209   aCI.SetR(theR);
210   aCI.SetH(theH);
211
212   //Compute the Cylinder value
213   try {
214     if (!GetSolver()->ComputeFunction(aFunction)) {
215       SetErrorCode("Cylinder driver failed");
216       return NULL;
217     }
218   }
219   catch (Standard_Failure) {
220     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
221     SetErrorCode(aFail->GetMessageString());
222     return NULL;
223   }
224
225   //Make a Python command
226   GEOM::TPythonDump(aFunction) << aCylinder
227     << " = geompy.MakeCylinderRH(" << theR << ", " << theH << ")";
228
229   SetErrorCode(OK);
230   return aCylinder;
231 }
232
233
234 //=============================================================================
235 /*!
236  *  MakeCylinderPntVecRH
237  */
238 //=============================================================================
239 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRH (Handle(GEOM_Object) thePnt,
240                                                                       Handle(GEOM_Object) theVec,
241                                                                       double theR, double theH)
242 {
243   SetErrorCode(KO);
244
245   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
246
247   //Add a new Cylinder object
248   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
249
250   //Add a new Cylinder function for creation a cylinder relatively to point and vector
251   Handle(GEOM_Function) aFunction =
252     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H);
253   if (aFunction.IsNull()) return NULL;
254
255   //Check if the function is set correctly
256   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
257
258   GEOMImpl_ICylinder aCI (aFunction);
259
260   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
261   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
262
263   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
264
265   aCI.SetPoint(aRefPnt);
266   aCI.SetVector(aRefVec);
267   aCI.SetR(theR);
268   aCI.SetH(theH);
269
270   //Compute the Cylinder value
271   try {
272     if (!GetSolver()->ComputeFunction(aFunction)) {
273       SetErrorCode("Cylinder driver failed");
274       return NULL;
275     }
276   }
277   catch (Standard_Failure) {
278     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
279     SetErrorCode(aFail->GetMessageString());
280     return NULL;
281   }
282
283   //Make a Python command
284   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinder("
285     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ")";
286
287   SetErrorCode(OK);
288   return aCylinder;
289 }
290
291
292 //=============================================================================
293 /*!
294  *  MakeConeR1R2H
295  */
296 //=============================================================================
297 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConeR1R2H (double theR1, double theR2,
298                                                                double theH)
299 {
300   SetErrorCode(KO);
301
302   //Add a new Cone object
303   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
304
305   //Add a new Cone function with R and H parameters
306   Handle(GEOM_Function) aFunction =
307     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_R1_R2_H);
308   if (aFunction.IsNull()) return NULL;
309
310   //Check if the function is set correctly
311   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
312
313   GEOMImpl_ICone aCI (aFunction);
314
315   aCI.SetR1(theR1);
316   aCI.SetR2(theR2);
317   aCI.SetH(theH);
318
319   //Compute the Cone value
320   try {
321     if (!GetSolver()->ComputeFunction(aFunction)) {
322       SetErrorCode("Cone driver failed");
323       return NULL;
324     }
325   }
326   catch (Standard_Failure) {
327     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
328     SetErrorCode(aFail->GetMessageString());
329     return NULL;
330   }
331
332   //Make a Python command
333   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeConeR1R2H("
334     << theR1 << ", " << theR2 << ", " << theH << ")";
335
336   SetErrorCode(OK);
337   return aCone;
338 }
339
340
341 //=============================================================================
342 /*!
343  *  MakeConePntVecR1R2H
344  */
345 //=============================================================================
346 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConePntVecR1R2H (Handle(GEOM_Object) thePnt,
347                                                                      Handle(GEOM_Object) theVec,
348                                                                      double theR1, double theR2,
349                                                                      double theH)
350 {
351   SetErrorCode(KO);
352
353   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
354
355   //Add a new Cone object
356   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
357
358   //Add a new Cone function for creation a cone relatively to point and vector
359   Handle(GEOM_Function) aFunction =
360     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_PNT_VEC_R1_R2_H);
361   if (aFunction.IsNull()) return NULL;
362
363   //Check if the function is set correctly
364   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
365
366   GEOMImpl_ICone aCI (aFunction);
367
368   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
369   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
370
371   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
372
373   aCI.SetPoint(aRefPnt);
374   aCI.SetVector(aRefVec);
375   aCI.SetR1(theR1);
376   aCI.SetR2(theR2);
377   aCI.SetH(theH);
378
379   //Compute the Cone value
380   try {
381     if (!GetSolver()->ComputeFunction(aFunction)) {
382       SetErrorCode("Cone driver failed");
383       return NULL;
384     }
385   }
386   catch (Standard_Failure) {
387     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
388     SetErrorCode(aFail->GetMessageString());
389     return NULL;
390   }
391
392   //Make a Python command
393   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeCone(" << thePnt
394     << ", " << theVec << ", " << theR1 << ", " << theR2 << ", " << theH << ")";
395
396   SetErrorCode(OK);
397   return aCone;
398 }
399
400
401 //=============================================================================
402 /*!
403  *  MakeSphereR
404  */
405 //=============================================================================
406 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSphereR (double theR)
407 {
408   SetErrorCode(KO);
409
410   //Add a new Sphere object
411   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
412
413   //Add a new Sphere function with R parameter
414   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_R);
415   if (aFunction.IsNull()) return NULL;
416
417   //Check if the function is set correctly
418   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
419
420   GEOMImpl_ISphere aCI (aFunction);
421
422   aCI.SetR(theR);
423
424   //Compute the Sphere value
425   try {
426     if (!GetSolver()->ComputeFunction(aFunction)) {
427       SetErrorCode("Sphere driver failed");
428       return NULL;
429     }
430   }
431   catch (Standard_Failure) {
432     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
433     SetErrorCode(aFail->GetMessageString());
434     return NULL;
435   }
436
437   //Make a Python command
438   GEOM::TPythonDump(aFunction) << aSphere << " = geompy.MakeSphereR(" << theR << ")";
439
440   SetErrorCode(OK);
441   return aSphere;
442 }
443
444
445 //=============================================================================
446 /*!
447  *  MakeSpherePntR
448  */
449 //=============================================================================
450 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSpherePntR (Handle(GEOM_Object) thePnt,
451                                                                 double theR)
452 {
453   SetErrorCode(KO);
454
455   if (thePnt.IsNull()) return NULL;
456
457   //Add a new Point object
458   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
459
460   //Add a new Sphere function for creation a sphere relatively to point
461   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_PNT_R);
462   if (aFunction.IsNull()) return NULL;
463
464   //Check if the function is set correctly
465   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
466
467   GEOMImpl_ISphere aCI (aFunction);
468
469   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
470
471   if (aRefPnt.IsNull()) return NULL;
472
473   aCI.SetPoint(aRefPnt);
474   aCI.SetR(theR);
475
476   //Compute the Sphere value
477   try {
478     if (!GetSolver()->ComputeFunction(aFunction)) {
479       SetErrorCode("Sphere driver failed");
480       return NULL;
481     }
482   }
483   catch (Standard_Failure) {
484     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
485     SetErrorCode(aFail->GetMessageString());
486     return NULL;
487   }
488
489   //Make a Python command
490   GEOM::TPythonDump(aFunction) << aSphere
491     << " = geompy.MakeSpherePntR(" << thePnt << ", " << theR << ")";
492
493   SetErrorCode(OK);
494   return aSphere;
495 }
496
497
498 //=============================================================================
499 /*!
500  *  MakeTorusRR
501  */
502 //=============================================================================
503 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusRR
504                                            (double theRMajor, double theRMinor)
505 {
506   SetErrorCode(KO);
507
508   //Add a new Torus object
509   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
510
511   //Add a new Torus function
512   Handle(GEOM_Function) aFunction =
513     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_RR);
514   if (aFunction.IsNull()) return NULL;
515
516   //Check if the function is set correctly
517   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
518
519   GEOMImpl_ITorus aCI (aFunction);
520
521   aCI.SetRMajor(theRMajor);
522   aCI.SetRMinor(theRMinor);
523
524   //Compute the Torus value
525   try {
526     if (!GetSolver()->ComputeFunction(aFunction)) {
527       SetErrorCode("Torus driver failed");
528       return NULL;
529     }
530   }
531   catch (Standard_Failure) {
532     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
533     SetErrorCode(aFail->GetMessageString());
534     return NULL;
535   }
536
537   //Make a Python command
538   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorusRR("
539     << theRMajor << ", " << theRMinor << ")";
540
541   SetErrorCode(OK);
542   return anEll;
543 }
544
545 //=============================================================================
546 /*!
547  *  MakeTorusPntVecRR
548  */
549 //=============================================================================
550 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusPntVecRR
551                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
552                         double theRMajor, double theRMinor)
553 {
554   SetErrorCode(KO);
555
556   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
557
558   //Add a new Torus object
559   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
560
561   //Add a new Torus function
562   Handle(GEOM_Function) aFunction =
563     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_PNT_VEC_RR);
564   if (aFunction.IsNull()) return NULL;
565
566   //Check if the function is set correctly
567   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
568
569   GEOMImpl_ITorus aCI (aFunction);
570
571   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
572   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
573
574   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
575
576   aCI.SetCenter(aRefPnt);
577   aCI.SetVector(aRefVec);
578   aCI.SetRMajor(theRMajor);
579   aCI.SetRMinor(theRMinor);
580
581   //Compute the Torus value
582   try {
583     if (!GetSolver()->ComputeFunction(aFunction)) {
584       SetErrorCode("Torus driver failed");
585       return NULL;
586     }
587   }
588   catch (Standard_Failure) {
589     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
590     SetErrorCode(aFail->GetMessageString());
591     return NULL;
592   }
593
594   //Make a Python command
595   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorus(" << thePnt
596     << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
597
598   SetErrorCode(OK);
599   return anEll;
600 }
601
602
603 //=============================================================================
604 /*!
605  *  MakePrismVecH
606  */
607 //=============================================================================
608 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH (Handle(GEOM_Object) theBase,
609                                                                Handle(GEOM_Object) theVec,
610                                                                double theH)
611 {
612   SetErrorCode(KO);
613
614   if (theBase.IsNull() || theVec.IsNull()) return NULL;
615
616   //Add a new Prism object
617   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
618
619   //Add a new Prism function for creation a Prism relatively to vector
620   Handle(GEOM_Function) aFunction =
621     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H);
622   if (aFunction.IsNull()) return NULL;
623
624   //Check if the function is set correctly
625   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
626
627   GEOMImpl_IPrism aCI (aFunction);
628
629   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
630   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
631
632   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
633
634   aCI.SetBase(aRefBase);
635   aCI.SetVector(aRefVec);
636   aCI.SetH(theH);
637
638   //Compute the Prism value
639   try {
640     if (!GetSolver()->ComputeFunction(aFunction)) {
641       SetErrorCode("Prism driver failed");
642       return NULL;
643     }
644   }
645   catch (Standard_Failure) {
646     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
647     SetErrorCode(aFail->GetMessageString());
648     return NULL;
649   }
650
651   //Make a Python command
652   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismVecH("
653     << theBase << ", " << theVec << ", " << theH << ")";
654
655   SetErrorCode(OK);
656   return aPrism;
657 }
658
659 //=============================================================================
660 /*!
661  *  MakePrismTwoPnt
662  */
663 //=============================================================================
664 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
665        (Handle(GEOM_Object) theBase,
666         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
667 {
668   SetErrorCode(KO);
669
670   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
671
672   //Add a new Prism object
673   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
674
675   //Add a new Prism function for creation a Prism relatively to two points
676   Handle(GEOM_Function) aFunction =
677     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
678   if (aFunction.IsNull()) return NULL;
679
680   //Check if the function is set correctly
681   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
682
683   GEOMImpl_IPrism aCI (aFunction);
684
685   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
686   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
687   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
688
689   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
690
691   aCI.SetBase(aRefBase);
692   aCI.SetFirstPoint(aRefPnt1);
693   aCI.SetLastPoint(aRefPnt2);
694
695   //Compute the Prism value
696   try {
697     if (!GetSolver()->ComputeFunction(aFunction)) {
698       SetErrorCode("Prism driver failed");
699       return NULL;
700     }
701   }
702   catch (Standard_Failure) {
703     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
704     SetErrorCode(aFail->GetMessageString());
705     return NULL;
706   }
707
708   //Make a Python command
709   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism("
710     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
711
712   SetErrorCode(OK);
713   return aPrism;
714 }
715
716
717 //=============================================================================
718 /*!
719  *  MakePipe
720  */
721 //=============================================================================
722 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
723                                                           Handle(GEOM_Object) thePath)
724 {
725   SetErrorCode(KO);
726
727   if (theBase.IsNull() || thePath.IsNull()) return NULL;
728
729   //Add a new Pipe object
730   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
731
732   //Add a new Pipe function
733   Handle(GEOM_Function) aFunction =
734     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
735   if (aFunction.IsNull()) return NULL;
736
737   //Check if the function is set correctly
738   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
739
740   GEOMImpl_IPipe aCI (aFunction);
741
742   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
743   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
744
745   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
746
747   aCI.SetBase(aRefBase);
748   aCI.SetPath(aRefPath);
749
750   //Compute the Pipe value
751   try {
752     if (!GetSolver()->ComputeFunction(aFunction)) {
753       SetErrorCode("Pipe driver failed");
754       return NULL;
755     }
756   }
757   catch (Standard_Failure) {
758     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
759     SetErrorCode(aFail->GetMessageString());
760     return NULL;
761   }
762
763   //Make a Python command
764   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipe("
765     << theBase << ", " << thePath << ")";
766
767   SetErrorCode(OK);
768   return aPipe;
769 }
770
771
772 //=============================================================================
773 /*!
774  *  MakeRevolutionAxisAngle
775  */
776 //=============================================================================
777 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
778                                                                          Handle(GEOM_Object) theAxis,
779                                                                          double theAngle)
780 {
781   SetErrorCode(KO);
782
783   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
784
785   //Add a new Revolution object
786   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
787
788   //Add a new Revolution function for creation a revolution relatively to axis
789   Handle(GEOM_Function) aFunction =
790     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
791   if (aFunction.IsNull()) return NULL;
792
793   //Check if the function is set correctly
794   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
795
796   GEOMImpl_IRevolution aCI (aFunction);
797
798   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
799   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
800
801   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
802
803   aCI.SetBase(aRefBase);
804   aCI.SetAxis(aRefAxis);
805   aCI.SetAngle(theAngle);
806
807   //Compute the Revolution value
808   try {
809     if (!GetSolver()->ComputeFunction(aFunction)) {
810       SetErrorCode("Revolution driver failed");
811       return NULL;
812     }
813   }
814   catch (Standard_Failure) {
815     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
816     SetErrorCode(aFail->GetMessageString());
817     return NULL;
818   }
819
820   //Make a Python command
821   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
822     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
823
824   SetErrorCode(OK);
825   return aRevolution;
826 }
827
828
829 //=============================================================================
830 /*!
831  *  MakeSolidShell
832  */
833 //=============================================================================
834 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
835 {
836   SetErrorCode(KO);
837
838   if (theShell.IsNull()) return NULL;
839
840   //Add a new Solid object
841   Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
842
843   //Add a new Solid function for creation a solid from a shell
844   Handle(GEOM_Function) aFunction =
845     aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
846   if (aFunction.IsNull()) return NULL;
847
848   //Check if the function is set correctly
849   if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
850
851   GEOMImpl_IShapes aCI (aFunction);
852
853   Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
854
855   if (aRefShell.IsNull()) return NULL;
856
857   aCI.SetBase(aRefShell);
858
859   //Compute the Solid value
860   try {
861     if (!GetSolver()->ComputeFunction(aFunction)) {
862       SetErrorCode("Solid driver failed");
863       return NULL;
864     }
865   }
866   catch (Standard_Failure) {
867     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
868     SetErrorCode(aFail->GetMessageString());
869     return NULL;
870   }
871
872   //Make a Python command
873   GEOM::TPythonDump(aFunction) << aSolid << " = geompy.MakeSolid(" << theShell << ")";
874
875   SetErrorCode(OK);
876   return aSolid;
877 }
878
879 //=============================================================================
880 /*!
881  *  MakeFilling
882  */
883 //=============================================================================
884 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFilling
885        (Handle(GEOM_Object) theShape, int theMinDeg, int theMaxDeg,
886         double theTol2D, double theTol3D, int theNbIter)
887 {
888   SetErrorCode(KO);
889
890   if (theShape.IsNull()) return NULL;
891
892   //Add a new Filling object
893   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
894
895   //Add a new Filling function for creation a filling  from a compound
896   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
897   if (aFunction.IsNull()) return NULL;
898
899   //Check if the function is set correctly
900   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
901
902   GEOMImpl_IFilling aFI (aFunction);
903
904   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
905
906   if (aRefShape.IsNull()) return NULL;
907
908   aFI.SetShape(aRefShape);
909   aFI.SetMinDeg(theMinDeg);
910   aFI.SetMaxDeg(theMaxDeg);
911   aFI.SetTol2D(theTol2D);
912   aFI.SetTol3D(theTol3D);
913   aFI.SetNbIter(theNbIter);
914
915   //Compute the Solid value
916   try {
917     if (!GetSolver()->ComputeFunction(aFunction)) {
918       SetErrorCode("Filling driver failed");
919       return NULL;
920     }
921   }
922   catch (Standard_Failure) {
923     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
924     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
925       SetErrorCode("B-Spline surface construction failed");
926     else
927       SetErrorCode(aFail->GetMessageString());
928     return NULL;
929   }
930
931   //Make a Python command
932   GEOM::TPythonDump(aFunction) << aFilling << " = geompy.MakeFilling("
933     << theShape << ", " << theMinDeg << ", " << theMaxDeg << ", "
934       << theTol2D << ", " << theTol3D << ", " << theNbIter << ")";
935
936   SetErrorCode(OK);
937   return aFilling;
938 }
939
940 //=============================================================================
941 /*!
942  *  MakeThruSections
943  */
944 //=============================================================================
945 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThruSections(
946                                                 const Handle(TColStd_HSequenceOfTransient)& theSeqSections,
947                                                 bool theModeSolid,
948                                                 double thePreci,
949                                                 bool theRuled)
950 {
951   Handle(GEOM_Object) anObj;
952   SetErrorCode(KO);
953   if(theSeqSections.IsNull())
954     return anObj;
955
956   Standard_Integer nbObj = theSeqSections->Length();
957   if (!nbObj) 
958     return anObj;
959
960   //Add a new ThruSections object
961   Handle(GEOM_Object) aThruSect = GetEngine()->AddObject(GetDocID(), GEOM_THRUSECTIONS);
962
963  
964   //Add a new ThruSections function
965
966   int aTypeFunc = (theRuled ? THRUSECTIONS_RULED : THRUSECTIONS_SMOOTHED);
967   Handle(GEOM_Function) aFunction =
968     aThruSect->AddFunction(GEOMImpl_ThruSectionsDriver::GetID(), aTypeFunc);
969   if (aFunction.IsNull()) return anObj;
970
971   //Check if the function is set correctly
972   if (aFunction->GetDriverGUID() != GEOMImpl_ThruSectionsDriver::GetID()) return NULL;
973
974   GEOMImpl_IThruSections aCI (aFunction);
975
976   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
977
978   Standard_Integer i =1;
979   for( ; i <= nbObj; i++) {
980
981     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
982     if(anItem.IsNull())
983       continue;
984     
985     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
986     if(!aSectObj.IsNull())
987     {
988       Handle(GEOM_Function) aRefSect = aSectObj->GetLastFunction();
989       if(!aRefSect.IsNull())
990         aSeqSections->Append(aRefSect);
991     }
992   }
993
994   if(!aSeqSections->Length())
995     return anObj;
996
997   aCI.SetSections(aSeqSections);
998   aCI.SetSolidMode(theModeSolid);
999   aCI.SetPrecision(thePreci);
1000
1001   //Compute the ThruSections value
1002   try {
1003     if (!GetSolver()->ComputeFunction(aFunction)) {
1004       SetErrorCode("ThruSections driver failed");
1005       return anObj;
1006     }
1007   }
1008   catch (Standard_Failure) {
1009     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1010     SetErrorCode(aFail->GetMessageString());
1011     return anObj;
1012   }
1013
1014   //Make a Python command
1015   GEOM::TPythonDump pyDump(aFunction);
1016   pyDump << aThruSect << " = geompy.MakeThruSections([";
1017
1018   for(i =1 ; i <= nbObj; i++) {
1019
1020     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1021     if(anItem.IsNull())
1022       continue;
1023     
1024     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1025     if(!aSectObj.IsNull()) {
1026       pyDump<< aSectObj;
1027       if(i < nbObj)
1028         pyDump<<", ";
1029     }
1030   }
1031   
1032   pyDump<< "],"<<theModeSolid << "," << thePreci <<","<< theRuled <<")";
1033
1034   SetErrorCode(OK);
1035   return aThruSect;
1036   
1037    
1038 }
1039
1040 //=============================================================================
1041 /*!
1042  *  MakePipeWithDifferentSections
1043  */
1044 //=============================================================================
1045 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithDifferentSections(
1046                                                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1047                                                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1048                                                 const Handle(GEOM_Object)& thePath,
1049                                                 bool theWithContact,
1050                                                 bool theWithCorrections)
1051 {
1052   Handle(GEOM_Object) anObj;
1053   SetErrorCode(KO);
1054   if(theBases.IsNull())
1055     return anObj;
1056
1057   Standard_Integer nbBases = theBases->Length();
1058   
1059   if (!nbBases)
1060     return anObj;
1061   
1062   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1063   //Add a new Pipe object
1064   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1065  
1066   //Add a new Pipe function
1067
1068   Handle(GEOM_Function) aFunction =
1069     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_DIFFERENT_SECTIONS);
1070   if (aFunction.IsNull()) return anObj;
1071
1072   //Check if the function is set correctly
1073   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1074
1075   GEOMImpl_IPipeDiffSect aCI (aFunction);
1076
1077   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1078   if(aRefPath.IsNull())
1079     return anObj;
1080
1081   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1082   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1083
1084   Standard_Integer i =1;
1085   for( ; i <= nbBases; i++) {
1086
1087     Handle(Standard_Transient) anItem = theBases->Value(i);
1088     if(anItem.IsNull())
1089       continue;
1090     
1091     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1092     if(aBase.IsNull())
1093       continue;
1094     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1095     if(aRefBase.IsNull())
1096       continue;
1097     if(nbLocs)
1098     {
1099       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1100       if(anItemLoc.IsNull())
1101         continue;
1102     
1103       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1104       if(aLoc.IsNull())
1105         continue;
1106       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1107       if(aRefLoc.IsNull())
1108         continue;
1109       aSeqLocs->Append(aRefLoc);
1110     }
1111     aSeqBases->Append(aRefBase);
1112   }
1113
1114   if(!aSeqBases->Length())
1115     return anObj;
1116
1117   aCI.SetBases(aSeqBases);
1118   aCI.SetLocations(aSeqLocs);
1119   aCI.SetPath(aRefPath);
1120   aCI.SetWithContactMode(theWithContact);
1121   aCI.SetWithCorrectionMode(theWithCorrections);
1122   
1123   //Compute the Pipe value
1124   try {
1125     if (!GetSolver()->ComputeFunction(aFunction)) {
1126       SetErrorCode("Pipe with defferent section driver failed");
1127       return anObj;
1128     }
1129   }
1130   catch (Standard_Failure) {
1131     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1132     SetErrorCode(aFail->GetMessageString());
1133     return anObj;
1134   }
1135
1136   //Make a Python command
1137   GEOM::TPythonDump pyDump(aFunction);
1138   pyDump << aPipeDS << " = geompy.MakePipeWithDifferentSections([";
1139
1140   for(i =1 ; i <= nbBases; i++) {
1141
1142     Handle(Standard_Transient) anItem = theBases->Value(i);
1143     if(anItem.IsNull())
1144       continue;
1145     
1146     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1147     if(!anObj.IsNull()) {
1148       pyDump<< anObj;
1149       if(i < nbBases)
1150         pyDump<<", ";
1151     }
1152     
1153   }
1154   
1155   pyDump<< "], [";
1156    
1157   for(i =1 ; i <= nbLocs; i++) {
1158
1159     Handle(Standard_Transient) anItem = theLocations->Value(i);
1160     if(anItem.IsNull())
1161       continue;
1162     
1163     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1164     if(!anObj.IsNull()) {
1165       pyDump<< anObj;
1166       if(i < nbLocs)
1167         pyDump<<", ";
1168     }
1169   }  
1170
1171   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1172
1173   SetErrorCode(OK);
1174   return aPipeDS;
1175   
1176    
1177 }