Salome HOME
b01ec25fa1cd2d2047f7121e0af520bed16fac8b
[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       SetErrorCode("Extrusion can not be created, check input data");
643       return NULL;
644     }
645   }
646   catch (Standard_Failure) {
647     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
648     SetErrorCode(aFail->GetMessageString());
649     return NULL;
650   }
651
652   //Make a Python command
653   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismVecH("
654     << theBase << ", " << theVec << ", " << theH << ")";
655
656   SetErrorCode(OK);
657   return aPrism;
658 }
659
660 //=============================================================================
661 /*!
662  *  MakePrismTwoPnt
663  */
664 //=============================================================================
665 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
666        (Handle(GEOM_Object) theBase,
667         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
668 {
669   SetErrorCode(KO);
670
671   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
672
673   //Add a new Prism object
674   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
675
676   //Add a new Prism function for creation a Prism relatively to two points
677   Handle(GEOM_Function) aFunction =
678     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
679   if (aFunction.IsNull()) return NULL;
680
681   //Check if the function is set correctly
682   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
683
684   GEOMImpl_IPrism aCI (aFunction);
685
686   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
687   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
688   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
689
690   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
691
692   aCI.SetBase(aRefBase);
693   aCI.SetFirstPoint(aRefPnt1);
694   aCI.SetLastPoint(aRefPnt2);
695
696   //Compute the Prism value
697   try {
698     if (!GetSolver()->ComputeFunction(aFunction)) {
699       //SetErrorCode("Prism driver failed");
700       SetErrorCode("Extrusion can not be created, check input data");
701       return NULL;
702     }
703   }
704   catch (Standard_Failure) {
705     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
706     SetErrorCode(aFail->GetMessageString());
707     return NULL;
708   }
709
710   //Make a Python command
711   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism("
712     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
713
714   SetErrorCode(OK);
715   return aPrism;
716 }
717
718
719 //=============================================================================
720 /*!
721  *  MakePipe
722  */
723 //=============================================================================
724 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
725                                                           Handle(GEOM_Object) thePath)
726 {
727   SetErrorCode(KO);
728
729   if (theBase.IsNull() || thePath.IsNull()) return NULL;
730
731   //Add a new Pipe object
732   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
733
734   //Add a new Pipe function
735   Handle(GEOM_Function) aFunction =
736     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
737   if (aFunction.IsNull()) return NULL;
738
739   //Check if the function is set correctly
740   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
741
742   GEOMImpl_IPipe aCI (aFunction);
743
744   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
745   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
746
747   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
748
749   aCI.SetBase(aRefBase);
750   aCI.SetPath(aRefPath);
751
752   //Compute the Pipe value
753   try {
754     if (!GetSolver()->ComputeFunction(aFunction)) {
755       SetErrorCode("Pipe driver failed");
756       return NULL;
757     }
758   }
759   catch (Standard_Failure) {
760     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
761     SetErrorCode(aFail->GetMessageString());
762     return NULL;
763   }
764
765   //Make a Python command
766   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipe("
767     << theBase << ", " << thePath << ")";
768
769   SetErrorCode(OK);
770   return aPipe;
771 }
772
773
774 //=============================================================================
775 /*!
776  *  MakeRevolutionAxisAngle
777  */
778 //=============================================================================
779 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
780                                                                          Handle(GEOM_Object) theAxis,
781                                                                          double theAngle)
782 {
783   SetErrorCode(KO);
784
785   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
786
787   //Add a new Revolution object
788   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
789
790   //Add a new Revolution function for creation a revolution relatively to axis
791   Handle(GEOM_Function) aFunction =
792     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
793   if (aFunction.IsNull()) return NULL;
794
795   //Check if the function is set correctly
796   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
797
798   GEOMImpl_IRevolution aCI (aFunction);
799
800   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
801   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
802
803   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
804
805   aCI.SetBase(aRefBase);
806   aCI.SetAxis(aRefAxis);
807   aCI.SetAngle(theAngle);
808
809   //Compute the Revolution value
810   try {
811     if (!GetSolver()->ComputeFunction(aFunction)) {
812       SetErrorCode("Revolution driver failed");
813       return NULL;
814     }
815   }
816   catch (Standard_Failure) {
817     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
818     SetErrorCode(aFail->GetMessageString());
819     return NULL;
820   }
821
822   //Make a Python command
823   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
824     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
825
826   SetErrorCode(OK);
827   return aRevolution;
828 }
829
830
831 //=============================================================================
832 /*!
833  *  MakeSolidShell
834  */
835 //=============================================================================
836 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
837 {
838   SetErrorCode(KO);
839
840   if (theShell.IsNull()) return NULL;
841
842   //Add a new Solid object
843   Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
844
845   //Add a new Solid function for creation a solid from a shell
846   Handle(GEOM_Function) aFunction =
847     aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
848   if (aFunction.IsNull()) return NULL;
849
850   //Check if the function is set correctly
851   if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
852
853   GEOMImpl_IShapes aCI (aFunction);
854
855   Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
856
857   if (aRefShell.IsNull()) return NULL;
858
859   aCI.SetBase(aRefShell);
860
861   //Compute the Solid value
862   try {
863     if (!GetSolver()->ComputeFunction(aFunction)) {
864       SetErrorCode("Solid driver failed");
865       return NULL;
866     }
867   }
868   catch (Standard_Failure) {
869     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
870     SetErrorCode(aFail->GetMessageString());
871     return NULL;
872   }
873
874   //Make a Python command
875   GEOM::TPythonDump(aFunction) << aSolid << " = geompy.MakeSolid(" << theShell << ")";
876
877   SetErrorCode(OK);
878   return aSolid;
879 }
880
881 //=============================================================================
882 /*!
883  *  MakeFilling
884  */
885 //=============================================================================
886 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFilling
887        (Handle(GEOM_Object) theShape, int theMinDeg, int theMaxDeg,
888         double theTol2D, double theTol3D, int theNbIter)
889 {
890   SetErrorCode(KO);
891
892   if (theShape.IsNull()) return NULL;
893
894   //Add a new Filling object
895   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
896
897   //Add a new Filling function for creation a filling  from a compound
898   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
899   if (aFunction.IsNull()) return NULL;
900
901   //Check if the function is set correctly
902   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
903
904   GEOMImpl_IFilling aFI (aFunction);
905
906   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
907
908   if (aRefShape.IsNull()) return NULL;
909
910   aFI.SetShape(aRefShape);
911   aFI.SetMinDeg(theMinDeg);
912   aFI.SetMaxDeg(theMaxDeg);
913   aFI.SetTol2D(theTol2D);
914   aFI.SetTol3D(theTol3D);
915   aFI.SetNbIter(theNbIter);
916
917   //Compute the Solid value
918   try {
919     if (!GetSolver()->ComputeFunction(aFunction)) {
920       SetErrorCode("Filling driver failed");
921       return NULL;
922     }
923   }
924   catch (Standard_Failure) {
925     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
926     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
927       SetErrorCode("B-Spline surface construction failed");
928     else
929       SetErrorCode(aFail->GetMessageString());
930     return NULL;
931   }
932
933   //Make a Python command
934   GEOM::TPythonDump(aFunction) << aFilling << " = geompy.MakeFilling("
935     << theShape << ", " << theMinDeg << ", " << theMaxDeg << ", "
936       << theTol2D << ", " << theTol3D << ", " << theNbIter << ")";
937
938   SetErrorCode(OK);
939   return aFilling;
940 }
941
942 //=============================================================================
943 /*!
944  *  MakeThruSections
945  */
946 //=============================================================================
947 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThruSections(
948                                                 const Handle(TColStd_HSequenceOfTransient)& theSeqSections,
949                                                 bool theModeSolid,
950                                                 double thePreci,
951                                                 bool theRuled)
952 {
953   Handle(GEOM_Object) anObj;
954   SetErrorCode(KO);
955   if(theSeqSections.IsNull())
956     return anObj;
957
958   Standard_Integer nbObj = theSeqSections->Length();
959   if (!nbObj) 
960     return anObj;
961
962   //Add a new ThruSections object
963   Handle(GEOM_Object) aThruSect = GetEngine()->AddObject(GetDocID(), GEOM_THRUSECTIONS);
964
965  
966   //Add a new ThruSections function
967
968   int aTypeFunc = (theRuled ? THRUSECTIONS_RULED : THRUSECTIONS_SMOOTHED);
969   Handle(GEOM_Function) aFunction =
970     aThruSect->AddFunction(GEOMImpl_ThruSectionsDriver::GetID(), aTypeFunc);
971   if (aFunction.IsNull()) return anObj;
972
973   //Check if the function is set correctly
974   if (aFunction->GetDriverGUID() != GEOMImpl_ThruSectionsDriver::GetID()) return NULL;
975
976   GEOMImpl_IThruSections aCI (aFunction);
977
978   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
979
980   Standard_Integer i =1;
981   for( ; i <= nbObj; i++) {
982
983     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
984     if(anItem.IsNull())
985       continue;
986     
987     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
988     if(!aSectObj.IsNull())
989     {
990       Handle(GEOM_Function) aRefSect = aSectObj->GetLastFunction();
991       if(!aRefSect.IsNull())
992         aSeqSections->Append(aRefSect);
993     }
994   }
995
996   if(!aSeqSections->Length())
997     return anObj;
998
999   aCI.SetSections(aSeqSections);
1000   aCI.SetSolidMode(theModeSolid);
1001   aCI.SetPrecision(thePreci);
1002
1003   //Compute the ThruSections value
1004   try {
1005     if (!GetSolver()->ComputeFunction(aFunction)) {
1006       SetErrorCode("ThruSections driver failed");
1007       return anObj;
1008     }
1009   }
1010   catch (Standard_Failure) {
1011     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1012     SetErrorCode(aFail->GetMessageString());
1013     return anObj;
1014   }
1015
1016   //Make a Python command
1017   GEOM::TPythonDump pyDump(aFunction);
1018   pyDump << aThruSect << " = geompy.MakeThruSections([";
1019
1020   for(i =1 ; i <= nbObj; i++) {
1021
1022     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1023     if(anItem.IsNull())
1024       continue;
1025     
1026     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1027     if(!aSectObj.IsNull()) {
1028       pyDump<< aSectObj;
1029       if(i < nbObj)
1030         pyDump<<", ";
1031     }
1032   }
1033   
1034   pyDump<< "],"<<theModeSolid << "," << thePreci <<","<< theRuled <<")";
1035
1036   SetErrorCode(OK);
1037   return aThruSect;
1038   
1039    
1040 }
1041
1042 //=============================================================================
1043 /*!
1044  *  MakePipeWithDifferentSections
1045  */
1046 //=============================================================================
1047 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipeWithDifferentSections(
1048                                                 const Handle(TColStd_HSequenceOfTransient)& theBases,
1049                                                 const Handle(TColStd_HSequenceOfTransient)& theLocations,
1050                                                 const Handle(GEOM_Object)& thePath,
1051                                                 bool theWithContact,
1052                                                 bool theWithCorrections)
1053 {
1054   Handle(GEOM_Object) anObj;
1055   SetErrorCode(KO);
1056   if(theBases.IsNull())
1057     return anObj;
1058
1059   Standard_Integer nbBases = theBases->Length();
1060   
1061   if (!nbBases)
1062     return anObj;
1063   
1064   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1065   //Add a new Pipe object
1066   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1067  
1068   //Add a new Pipe function
1069
1070   Handle(GEOM_Function) aFunction =
1071     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_DIFFERENT_SECTIONS);
1072   if (aFunction.IsNull()) return anObj;
1073
1074   //Check if the function is set correctly
1075   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return anObj;
1076
1077   GEOMImpl_IPipeDiffSect aCI (aFunction);
1078
1079   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1080   if(aRefPath.IsNull())
1081     return anObj;
1082
1083   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1084   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1085
1086   Standard_Integer i =1;
1087   for( ; i <= nbBases; i++) {
1088
1089     Handle(Standard_Transient) anItem = theBases->Value(i);
1090     if(anItem.IsNull())
1091       continue;
1092     
1093     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1094     if(aBase.IsNull())
1095       continue;
1096     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1097     if(aRefBase.IsNull())
1098       continue;
1099     if(nbLocs)
1100     {
1101       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1102       if(anItemLoc.IsNull())
1103         continue;
1104     
1105       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1106       if(aLoc.IsNull())
1107         continue;
1108       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1109       if(aRefLoc.IsNull())
1110         continue;
1111       aSeqLocs->Append(aRefLoc);
1112     }
1113     aSeqBases->Append(aRefBase);
1114   }
1115
1116   if(!aSeqBases->Length())
1117     return anObj;
1118
1119   aCI.SetBases(aSeqBases);
1120   aCI.SetLocations(aSeqLocs);
1121   aCI.SetPath(aRefPath);
1122   aCI.SetWithContactMode(theWithContact);
1123   aCI.SetWithCorrectionMode(theWithCorrections);
1124   
1125   //Compute the Pipe value
1126   try {
1127     if (!GetSolver()->ComputeFunction(aFunction)) {
1128       SetErrorCode("Pipe with defferent section driver failed");
1129       return anObj;
1130     }
1131   }
1132   catch (Standard_Failure) {
1133     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1134     SetErrorCode(aFail->GetMessageString());
1135     return anObj;
1136   }
1137
1138   //Make a Python command
1139   GEOM::TPythonDump pyDump(aFunction);
1140   pyDump << aPipeDS << " = geompy.MakePipeWithDifferentSections([";
1141
1142   for(i =1 ; i <= nbBases; i++) {
1143
1144     Handle(Standard_Transient) anItem = theBases->Value(i);
1145     if(anItem.IsNull())
1146       continue;
1147     
1148     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1149     if(!anObj.IsNull()) {
1150       pyDump<< anObj;
1151       if(i < nbBases)
1152         pyDump<<", ";
1153     }
1154     
1155   }
1156   
1157   pyDump<< "], [";
1158    
1159   for(i =1 ; i <= nbLocs; i++) {
1160
1161     Handle(Standard_Transient) anItem = theLocations->Value(i);
1162     if(anItem.IsNull())
1163       continue;
1164     
1165     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1166     if(!anObj.IsNull()) {
1167       pyDump<< anObj;
1168       if(i < nbLocs)
1169         pyDump<<", ";
1170     }
1171   }  
1172
1173   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections<<")";
1174
1175   SetErrorCode(OK);
1176   return aPipeDS;
1177   
1178    
1179 }