Salome HOME
Copyrights update
[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/
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
49 #include <GEOMImpl_IBox.hxx>
50 #include <GEOMImpl_ICylinder.hxx>
51 #include <GEOMImpl_ICone.hxx>
52 #include <GEOMImpl_ISphere.hxx>
53 #include <GEOMImpl_ITorus.hxx>
54 #include <GEOMImpl_IPrism.hxx>
55 #include <GEOMImpl_IPipe.hxx>
56 #include <GEOMImpl_IRevolution.hxx>
57 #include <GEOMImpl_IShapes.hxx>
58 #include <GEOMImpl_IFilling.hxx>
59
60 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
61
62 //=============================================================================
63 /*!
64  *   constructor:
65  */
66 //=============================================================================
67 GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, int theDocID)
68 : GEOM_IOperations(theEngine, theDocID)
69 {
70   MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations");
71 }
72
73 //=============================================================================
74 /*!
75  *  destructor
76  */
77 //=============================================================================
78 GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations()
79 {
80   MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations");
81 }
82
83
84 //=============================================================================
85 /*!
86  *  MakeBoxDXDYDZ
87  */
88 //=============================================================================
89 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxDXDYDZ (double theDX, double theDY, double theDZ)
90 {
91   SetErrorCode(KO);
92
93   //Add a new Box object
94   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
95
96   //Add a new Box function with DX_DY_DZ parameters
97   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_DX_DY_DZ);
98   if (aFunction.IsNull()) return NULL;
99
100   //Check if the function is set correctly
101   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return NULL;
102
103   GEOMImpl_IBox aBI (aFunction);
104
105   aBI.SetDX(theDX);
106   aBI.SetDY(theDY);
107   aBI.SetDZ(theDZ);
108
109   //Compute the box value
110   try {
111     if (!GetSolver()->ComputeFunction(aFunction)) {
112       SetErrorCode("Box driver failed");
113       return NULL;
114     }
115   }
116   catch (Standard_Failure) {
117     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
118     SetErrorCode(aFail->GetMessageString());
119     return NULL;
120   }
121
122   //Make a Python command
123   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxDXDYDZ("
124     << theDX << ", " << theDY << ", " << theDZ << ")";
125
126   SetErrorCode(OK);
127   return aBox;
128 }
129
130
131 //=============================================================================
132 /*!
133  *  MakeBoxTwoPnt
134  */
135 //=============================================================================
136 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxTwoPnt (Handle(GEOM_Object) thePnt1,
137                                                                Handle(GEOM_Object) thePnt2)
138 {
139   SetErrorCode(KO);
140
141   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
142
143   //Add a new Box object
144   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
145
146   //Add a new Box function for creation a box relatively to two points
147   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_TWO_PNT);
148   if (aFunction.IsNull()) return NULL;
149
150   //Check if the function is set correctly
151   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return aBox;
152
153   GEOMImpl_IBox aBI (aFunction);
154
155   Handle(GEOM_Function) aRefFunction1 = thePnt1->GetLastFunction();
156   Handle(GEOM_Function) aRefFunction2 = thePnt2->GetLastFunction();
157
158   if (aRefFunction1.IsNull() || aRefFunction2.IsNull()) return aBox;
159
160   aBI.SetRef1(aRefFunction1);
161   aBI.SetRef2(aRefFunction2);
162
163   //Compute the Box value
164   try {
165     if (!GetSolver()->ComputeFunction(aFunction)) {
166       SetErrorCode("Box driver failed");
167       return NULL;
168     }
169   }
170   catch (Standard_Failure) {
171     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
172     SetErrorCode(aFail->GetMessageString());
173     return NULL;
174   }
175
176   //Make a Python command
177   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxTwoPnt("
178     << thePnt1 << ", " << thePnt2 << ")";
179
180   SetErrorCode(OK);
181   return aBox;
182 }
183
184
185 //=============================================================================
186 /*!
187  *  MakeCylinderRH
188  */
189 //=============================================================================
190 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRH (double theR, double theH)
191 {
192   SetErrorCode(KO);
193
194   //Add a new Cylinder object
195   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
196
197   //Add a new Cylinder function with R and H parameters
198   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H);
199   if (aFunction.IsNull()) return NULL;
200
201   //Check if the function is set correctly
202   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
203
204   GEOMImpl_ICylinder aCI (aFunction);
205
206   aCI.SetR(theR);
207   aCI.SetH(theH);
208
209   //Compute the Cylinder value
210   try {
211     if (!GetSolver()->ComputeFunction(aFunction)) {
212       SetErrorCode("Cylinder driver failed");
213       return NULL;
214     }
215   }
216   catch (Standard_Failure) {
217     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
218     SetErrorCode(aFail->GetMessageString());
219     return NULL;
220   }
221
222   //Make a Python command
223   GEOM::TPythonDump(aFunction) << aCylinder
224     << " = geompy.MakeCylinderRH(" << theR << ", " << theH << ")";
225
226   SetErrorCode(OK);
227   return aCylinder;
228 }
229
230
231 //=============================================================================
232 /*!
233  *  MakeCylinderPntVecRH
234  */
235 //=============================================================================
236 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRH (Handle(GEOM_Object) thePnt,
237                                                                       Handle(GEOM_Object) theVec,
238                                                                       double theR, double theH)
239 {
240   SetErrorCode(KO);
241
242   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
243
244   //Add a new Cylinder object
245   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
246
247   //Add a new Cylinder function for creation a cylinder relatively to point and vector
248   Handle(GEOM_Function) aFunction =
249     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H);
250   if (aFunction.IsNull()) return NULL;
251
252   //Check if the function is set correctly
253   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
254
255   GEOMImpl_ICylinder aCI (aFunction);
256
257   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
258   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
259
260   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
261
262   aCI.SetPoint(aRefPnt);
263   aCI.SetVector(aRefVec);
264   aCI.SetR(theR);
265   aCI.SetH(theH);
266
267   //Compute the Cylinder value
268   try {
269     if (!GetSolver()->ComputeFunction(aFunction)) {
270       SetErrorCode("Cylinder driver failed");
271       return NULL;
272     }
273   }
274   catch (Standard_Failure) {
275     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
276     SetErrorCode(aFail->GetMessageString());
277     return NULL;
278   }
279
280   //Make a Python command
281   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinder("
282     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ")";
283
284   SetErrorCode(OK);
285   return aCylinder;
286 }
287
288
289 //=============================================================================
290 /*!
291  *  MakeConeR1R2H
292  */
293 //=============================================================================
294 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConeR1R2H (double theR1, double theR2,
295                                                                double theH)
296 {
297   SetErrorCode(KO);
298
299   //Add a new Cone object
300   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
301
302   //Add a new Cone function with R and H parameters
303   Handle(GEOM_Function) aFunction =
304     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_R1_R2_H);
305   if (aFunction.IsNull()) return NULL;
306
307   //Check if the function is set correctly
308   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
309
310   GEOMImpl_ICone aCI (aFunction);
311
312   aCI.SetR1(theR1);
313   aCI.SetR2(theR2);
314   aCI.SetH(theH);
315
316   //Compute the Cone value
317   try {
318     if (!GetSolver()->ComputeFunction(aFunction)) {
319       SetErrorCode("Cone driver failed");
320       return NULL;
321     }
322   }
323   catch (Standard_Failure) {
324     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
325     SetErrorCode(aFail->GetMessageString());
326     return NULL;
327   }
328
329   //Make a Python command
330   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeConeR1R2H("
331     << theR1 << ", " << theR2 << ", " << theH << ")";
332
333   SetErrorCode(OK);
334   return aCone;
335 }
336
337
338 //=============================================================================
339 /*!
340  *  MakeConePntVecR1R2H
341  */
342 //=============================================================================
343 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConePntVecR1R2H (Handle(GEOM_Object) thePnt,
344                                                                      Handle(GEOM_Object) theVec,
345                                                                      double theR1, double theR2,
346                                                                      double theH)
347 {
348   SetErrorCode(KO);
349
350   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
351
352   //Add a new Cone object
353   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
354
355   //Add a new Cone function for creation a cone relatively to point and vector
356   Handle(GEOM_Function) aFunction =
357     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_PNT_VEC_R1_R2_H);
358   if (aFunction.IsNull()) return NULL;
359
360   //Check if the function is set correctly
361   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
362
363   GEOMImpl_ICone aCI (aFunction);
364
365   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
366   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
367
368   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
369
370   aCI.SetPoint(aRefPnt);
371   aCI.SetVector(aRefVec);
372   aCI.SetR1(theR1);
373   aCI.SetR2(theR2);
374   aCI.SetH(theH);
375
376   //Compute the Cone value
377   try {
378     if (!GetSolver()->ComputeFunction(aFunction)) {
379       SetErrorCode("Cone driver failed");
380       return NULL;
381     }
382   }
383   catch (Standard_Failure) {
384     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
385     SetErrorCode(aFail->GetMessageString());
386     return NULL;
387   }
388
389   //Make a Python command
390   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeCone(" << thePnt
391     << ", " << theVec << ", " << theR1 << ", " << theR2 << ", " << theH << ")";
392
393   SetErrorCode(OK);
394   return aCone;
395 }
396
397
398 //=============================================================================
399 /*!
400  *  MakeSphereR
401  */
402 //=============================================================================
403 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSphereR (double theR)
404 {
405   SetErrorCode(KO);
406
407   //Add a new Sphere object
408   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
409
410   //Add a new Sphere function with R parameter
411   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_R);
412   if (aFunction.IsNull()) return NULL;
413
414   //Check if the function is set correctly
415   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
416
417   GEOMImpl_ISphere aCI (aFunction);
418
419   aCI.SetR(theR);
420
421   //Compute the Sphere value
422   try {
423     if (!GetSolver()->ComputeFunction(aFunction)) {
424       SetErrorCode("Sphere driver failed");
425       return NULL;
426     }
427   }
428   catch (Standard_Failure) {
429     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
430     SetErrorCode(aFail->GetMessageString());
431     return NULL;
432   }
433
434   //Make a Python command
435   GEOM::TPythonDump(aFunction) << aSphere << " = geompy.MakeSphereR(" << theR << ")";
436
437   SetErrorCode(OK);
438   return aSphere;
439 }
440
441
442 //=============================================================================
443 /*!
444  *  MakeSpherePntR
445  */
446 //=============================================================================
447 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSpherePntR (Handle(GEOM_Object) thePnt,
448                                                                 double theR)
449 {
450   SetErrorCode(KO);
451
452   if (thePnt.IsNull()) return NULL;
453
454   //Add a new Point object
455   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
456
457   //Add a new Sphere function for creation a sphere relatively to point
458   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_PNT_R);
459   if (aFunction.IsNull()) return NULL;
460
461   //Check if the function is set correctly
462   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
463
464   GEOMImpl_ISphere aCI (aFunction);
465
466   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
467
468   if (aRefPnt.IsNull()) return NULL;
469
470   aCI.SetPoint(aRefPnt);
471   aCI.SetR(theR);
472
473   //Compute the Sphere value
474   try {
475     if (!GetSolver()->ComputeFunction(aFunction)) {
476       SetErrorCode("Sphere driver failed");
477       return NULL;
478     }
479   }
480   catch (Standard_Failure) {
481     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
482     SetErrorCode(aFail->GetMessageString());
483     return NULL;
484   }
485
486   //Make a Python command
487   GEOM::TPythonDump(aFunction) << aSphere
488     << " = geompy.MakeSpherePntR(" << thePnt << ", " << theR << ")";
489
490   SetErrorCode(OK);
491   return aSphere;
492 }
493
494
495 //=============================================================================
496 /*!
497  *  MakeTorusRR
498  */
499 //=============================================================================
500 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusRR
501                                            (double theRMajor, double theRMinor)
502 {
503   SetErrorCode(KO);
504
505   //Add a new Torus object
506   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
507
508   //Add a new Torus function
509   Handle(GEOM_Function) aFunction =
510     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_RR);
511   if (aFunction.IsNull()) return NULL;
512
513   //Check if the function is set correctly
514   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
515
516   GEOMImpl_ITorus aCI (aFunction);
517
518   aCI.SetRMajor(theRMajor);
519   aCI.SetRMinor(theRMinor);
520
521   //Compute the Torus value
522   try {
523     if (!GetSolver()->ComputeFunction(aFunction)) {
524       SetErrorCode("Torus driver failed");
525       return NULL;
526     }
527   }
528   catch (Standard_Failure) {
529     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
530     SetErrorCode(aFail->GetMessageString());
531     return NULL;
532   }
533
534   //Make a Python command
535   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorusRR("
536     << theRMajor << ", " << theRMinor << ")";
537
538   SetErrorCode(OK);
539   return anEll;
540 }
541
542 //=============================================================================
543 /*!
544  *  MakeTorusPntVecRR
545  */
546 //=============================================================================
547 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusPntVecRR
548                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
549                         double theRMajor, double theRMinor)
550 {
551   SetErrorCode(KO);
552
553   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
554
555   //Add a new Torus object
556   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
557
558   //Add a new Torus function
559   Handle(GEOM_Function) aFunction =
560     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_PNT_VEC_RR);
561   if (aFunction.IsNull()) return NULL;
562
563   //Check if the function is set correctly
564   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
565
566   GEOMImpl_ITorus aCI (aFunction);
567
568   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
569   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
570
571   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
572
573   aCI.SetCenter(aRefPnt);
574   aCI.SetVector(aRefVec);
575   aCI.SetRMajor(theRMajor);
576   aCI.SetRMinor(theRMinor);
577
578   //Compute the Torus value
579   try {
580     if (!GetSolver()->ComputeFunction(aFunction)) {
581       SetErrorCode("Torus driver failed");
582       return NULL;
583     }
584   }
585   catch (Standard_Failure) {
586     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
587     SetErrorCode(aFail->GetMessageString());
588     return NULL;
589   }
590
591   //Make a Python command
592   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorus(" << thePnt
593     << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
594
595   SetErrorCode(OK);
596   return anEll;
597 }
598
599
600 //=============================================================================
601 /*!
602  *  MakePrismVecH
603  */
604 //=============================================================================
605 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH (Handle(GEOM_Object) theBase,
606                                                                Handle(GEOM_Object) theVec,
607                                                                double theH)
608 {
609   SetErrorCode(KO);
610
611   if (theBase.IsNull() || theVec.IsNull()) return NULL;
612
613   //Add a new Prism object
614   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
615
616   //Add a new Prism function for creation a Prism relatively to vector
617   Handle(GEOM_Function) aFunction =
618     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H);
619   if (aFunction.IsNull()) return NULL;
620
621   //Check if the function is set correctly
622   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
623
624   GEOMImpl_IPrism aCI (aFunction);
625
626   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
627   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
628
629   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
630
631   aCI.SetBase(aRefBase);
632   aCI.SetVector(aRefVec);
633   aCI.SetH(theH);
634
635   //Compute the Prism value
636   try {
637     if (!GetSolver()->ComputeFunction(aFunction)) {
638       SetErrorCode("Prism driver failed");
639       return NULL;
640     }
641   }
642   catch (Standard_Failure) {
643     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
644     SetErrorCode(aFail->GetMessageString());
645     return NULL;
646   }
647
648   //Make a Python command
649   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismVecH("
650     << theBase << ", " << theVec << ", " << theH << ")";
651
652   SetErrorCode(OK);
653   return aPrism;
654 }
655
656 //=============================================================================
657 /*!
658  *  MakePrismTwoPnt
659  */
660 //=============================================================================
661 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
662        (Handle(GEOM_Object) theBase,
663         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
664 {
665   SetErrorCode(KO);
666
667   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
668
669   //Add a new Prism object
670   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
671
672   //Add a new Prism function for creation a Prism relatively to two points
673   Handle(GEOM_Function) aFunction =
674     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
675   if (aFunction.IsNull()) return NULL;
676
677   //Check if the function is set correctly
678   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
679
680   GEOMImpl_IPrism aCI (aFunction);
681
682   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
683   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
684   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
685
686   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
687
688   aCI.SetBase(aRefBase);
689   aCI.SetFirstPoint(aRefPnt1);
690   aCI.SetLastPoint(aRefPnt2);
691
692   //Compute the Prism value
693   try {
694     if (!GetSolver()->ComputeFunction(aFunction)) {
695       SetErrorCode("Prism driver failed");
696       return NULL;
697     }
698   }
699   catch (Standard_Failure) {
700     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
701     SetErrorCode(aFail->GetMessageString());
702     return NULL;
703   }
704
705   //Make a Python command
706   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism("
707     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
708
709   SetErrorCode(OK);
710   return aPrism;
711 }
712
713
714 //=============================================================================
715 /*!
716  *  MakePipe
717  */
718 //=============================================================================
719 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
720                                                           Handle(GEOM_Object) thePath)
721 {
722   SetErrorCode(KO);
723
724   if (theBase.IsNull() || thePath.IsNull()) return NULL;
725
726   //Add a new Pipe object
727   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
728
729   //Add a new Pipe function
730   Handle(GEOM_Function) aFunction =
731     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
732   if (aFunction.IsNull()) return NULL;
733
734   //Check if the function is set correctly
735   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
736
737   GEOMImpl_IPipe aCI (aFunction);
738
739   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
740   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
741
742   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
743
744   aCI.SetBase(aRefBase);
745   aCI.SetPath(aRefPath);
746
747   //Compute the Pipe value
748   try {
749     if (!GetSolver()->ComputeFunction(aFunction)) {
750       SetErrorCode("Pipe driver failed");
751       return NULL;
752     }
753   }
754   catch (Standard_Failure) {
755     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
756     SetErrorCode(aFail->GetMessageString());
757     return NULL;
758   }
759
760   //Make a Python command
761   GEOM::TPythonDump(aFunction) << aPipe << " = geompy.MakePipe("
762     << theBase << ", " << thePath << ")";
763
764   SetErrorCode(OK);
765   return aPipe;
766 }
767
768
769 //=============================================================================
770 /*!
771  *  MakeRevolutionAxisAngle
772  */
773 //=============================================================================
774 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
775                                                                          Handle(GEOM_Object) theAxis,
776                                                                          double theAngle)
777 {
778   SetErrorCode(KO);
779
780   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
781
782   //Add a new Revolution object
783   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
784
785   //Add a new Revolution function for creation a revolution relatively to axis
786   Handle(GEOM_Function) aFunction =
787     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
788   if (aFunction.IsNull()) return NULL;
789
790   //Check if the function is set correctly
791   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
792
793   GEOMImpl_IRevolution aCI (aFunction);
794
795   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
796   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
797
798   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
799
800   aCI.SetBase(aRefBase);
801   aCI.SetAxis(aRefAxis);
802   aCI.SetAngle(theAngle);
803
804   //Compute the Revolution value
805   try {
806     if (!GetSolver()->ComputeFunction(aFunction)) {
807       SetErrorCode("Revolution driver failed");
808       return NULL;
809     }
810   }
811   catch (Standard_Failure) {
812     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
813     SetErrorCode(aFail->GetMessageString());
814     return NULL;
815   }
816
817   //Make a Python command
818   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
819     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
820
821   SetErrorCode(OK);
822   return aRevolution;
823 }
824
825
826 //=============================================================================
827 /*!
828  *  MakeSolidShell
829  */
830 //=============================================================================
831 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
832 {
833   SetErrorCode(KO);
834
835   if (theShell.IsNull()) return NULL;
836
837   //Add a new Solid object
838   Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
839
840   //Add a new Solid function for creation a solid from a shell
841   Handle(GEOM_Function) aFunction =
842     aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
843   if (aFunction.IsNull()) return NULL;
844
845   //Check if the function is set correctly
846   if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
847
848   GEOMImpl_IShapes aCI (aFunction);
849
850   Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
851
852   if (aRefShell.IsNull()) return NULL;
853
854   aCI.SetBase(aRefShell);
855
856   //Compute the Solid value
857   try {
858     if (!GetSolver()->ComputeFunction(aFunction)) {
859       SetErrorCode("Solid driver failed");
860       return NULL;
861     }
862   }
863   catch (Standard_Failure) {
864     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
865     SetErrorCode(aFail->GetMessageString());
866     return NULL;
867   }
868
869   //Make a Python command
870   GEOM::TPythonDump(aFunction) << aSolid << " = geompy.MakeSolid(" << theShell << ")";
871
872   SetErrorCode(OK);
873   return aSolid;
874 }
875
876 //=============================================================================
877 /*!
878  *  MakeFilling
879  */
880 //=============================================================================
881 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFilling
882        (Handle(GEOM_Object) theShape, int theMinDeg, int theMaxDeg,
883         double theTol2D, double theTol3D, int theNbIter)
884 {
885   SetErrorCode(KO);
886
887   if (theShape.IsNull()) return NULL;
888
889   //Add a new Filling object
890   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
891
892   //Add a new Filling function for creation a filling  from a compound
893   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
894   if (aFunction.IsNull()) return NULL;
895
896   //Check if the function is set correctly
897   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
898
899   GEOMImpl_IFilling aFI (aFunction);
900
901   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
902
903   if (aRefShape.IsNull()) return NULL;
904
905   aFI.SetShape(aRefShape);
906   aFI.SetMinDeg(theMinDeg);
907   aFI.SetMaxDeg(theMaxDeg);
908   aFI.SetTol2D(theTol2D);
909   aFI.SetTol3D(theTol3D);
910   aFI.SetNbIter(theNbIter);
911
912   //Compute the Solid value
913   try {
914     if (!GetSolver()->ComputeFunction(aFunction)) {
915       SetErrorCode("Filling driver failed");
916       return NULL;
917     }
918   }
919   catch (Standard_Failure) {
920     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
921     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
922       SetErrorCode("B-Spline surface construction failed");
923     else
924       SetErrorCode(aFail->GetMessageString());
925     return NULL;
926   }
927
928   //Make a Python command
929   GEOM::TPythonDump(aFunction) << aFilling << " = geompy.MakeFilling("
930     << theShape << ", " << theMinDeg << ", " << theMaxDeg << ", "
931       << theTol2D << ", " << theTol3D << ", " << theNbIter << ")";
932
933   SetErrorCode(OK);
934   return aFilling;
935 }