Salome HOME
56eb0762bc04d628777b7ef5af7feec063bb832f
[modules/geom.git] / src / GEOMImpl / GEOMImpl_I3DPrimOperations.cxx
1 using namespace std;
2
3 #include "GEOMImpl_I3DPrimOperations.hxx"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7 #include "Utils_ExceptHandlers.hxx"
8
9 #include <TFunction_DriverTable.hxx>
10 #include <TFunction_Driver.hxx>
11 #include <TFunction_Logbook.hxx>
12 #include <TDF_Tool.hxx>
13
14 #include "GEOM_Function.hxx"
15 #include "GEOMImpl_Types.hxx"
16
17 #include "GEOMImpl_BoxDriver.hxx"
18 #include "GEOMImpl_CylinderDriver.hxx"
19 #include "GEOMImpl_ConeDriver.hxx"
20 #include "GEOMImpl_SphereDriver.hxx"
21 #include "GEOMImpl_TorusDriver.hxx"
22 #include "GEOMImpl_PrismDriver.hxx"
23 #include "GEOMImpl_PipeDriver.hxx"
24 #include "GEOMImpl_RevolutionDriver.hxx"
25 #include "GEOMImpl_ShapeDriver.hxx"
26 #include "GEOMImpl_FillingDriver.hxx"
27
28 #include "GEOMImpl_IBox.hxx"
29 #include "GEOMImpl_ICylinder.hxx"
30 #include "GEOMImpl_ICone.hxx"
31 #include "GEOMImpl_ISphere.hxx"
32 #include "GEOMImpl_ITorus.hxx"
33 #include "GEOMImpl_IPrism.hxx"
34 #include "GEOMImpl_IPipe.hxx"
35 #include "GEOMImpl_IRevolution.hxx"
36 #include "GEOMImpl_IShapes.hxx"
37 #include "GEOMImpl_IFilling.hxx"
38
39 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
40
41 //=============================================================================
42 /*!
43  *   constructor:
44  */
45 //=============================================================================
46 GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, int theDocID)
47 : GEOM_IOperations(theEngine, theDocID)
48 {
49   MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations");
50 }
51
52 //=============================================================================
53 /*!
54  *  destructor
55  */
56 //=============================================================================
57 GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations()
58 {
59   MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations");
60 }
61
62
63 //=============================================================================
64 /*!
65  *  MakeBoxDXDYDZ
66  */
67 //=============================================================================
68 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxDXDYDZ (double theDX, double theDY, double theDZ)
69 {
70   SetErrorCode(KO);
71
72   //Add a new Box object
73   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
74
75   //Add a new Box function with DX_DY_DZ parameters
76   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_DX_DY_DZ);
77   if (aFunction.IsNull()) return NULL;
78
79   //Check if the function is set correctly
80   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return NULL;
81
82   GEOMImpl_IBox aBI (aFunction);
83
84   aBI.SetDX(theDX);
85   aBI.SetDY(theDY);
86   aBI.SetDZ(theDZ);
87
88   //Compute the box value
89   try {
90     if (!GetSolver()->ComputeFunction(aFunction)) {
91       SetErrorCode("Box driver failed");
92       return NULL;
93     }
94   }
95   catch (Standard_Failure) {
96     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
97     SetErrorCode(aFail->GetMessageString());
98     return NULL;
99   }
100
101   //Make a Python command
102   TCollection_AsciiString anEntry, aDescr("");
103   TDF_Tool::Entry(aBox->GetEntry(), anEntry);
104   aDescr += anEntry;
105   aDescr += " = I3DPrimOperations.MakeBoxDXDYDZ(";
106   aDescr += (TCollection_AsciiString(theDX)+", ");
107   aDescr += (TCollection_AsciiString(theDY)+", ");
108   aDescr += (TCollection_AsciiString(theDZ)+")");
109
110   aFunction->SetDescription(aDescr);
111
112   SetErrorCode(OK);
113   return aBox;
114 }
115
116
117 //=============================================================================
118 /*!
119  *  MakeBoxTwoPnt
120  */
121 //=============================================================================
122 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxTwoPnt (Handle(GEOM_Object) thePnt1,
123                                                                Handle(GEOM_Object) thePnt2)
124 {
125   SetErrorCode(KO);
126
127   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
128
129   //Add a new Box object
130   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
131
132   //Add a new Box function for creation a box relatively to two points
133   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_TWO_PNT);
134   if (aFunction.IsNull()) return NULL;
135
136   //Check if the function is set correctly
137   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return aBox;
138
139   GEOMImpl_IBox aBI (aFunction);
140
141   Handle(GEOM_Function) aRefFunction1 = thePnt1->GetLastFunction();
142   Handle(GEOM_Function) aRefFunction2 = thePnt2->GetLastFunction();
143
144   if (aRefFunction1.IsNull() || aRefFunction2.IsNull()) return aBox;
145
146   aBI.SetRef1(aRefFunction1);
147   aBI.SetRef2(aRefFunction2);
148
149   //Compute the Box value
150   try {
151     if (!GetSolver()->ComputeFunction(aFunction)) {
152       SetErrorCode("Box driver failed");
153       return NULL;
154     }
155   }
156   catch (Standard_Failure) {
157     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
158     SetErrorCode(aFail->GetMessageString());
159     return NULL;
160   }
161
162   //Make a Python command
163   TCollection_AsciiString anEntry, aDescr("");
164   TDF_Tool::Entry(aBox->GetEntry(), anEntry);
165   aDescr += anEntry;
166   aDescr += " = I3DPrimOperations.MakeBoxTwoPnt(";
167   TDF_Tool::Entry(thePnt1->GetEntry(), anEntry);
168   aDescr += (anEntry+", ");
169   TDF_Tool::Entry(thePnt2->GetEntry(), anEntry);
170   aDescr += (anEntry+")");
171
172   aFunction->SetDescription(aDescr);
173
174   SetErrorCode(OK);
175   return aBox;
176 }
177
178
179 //=============================================================================
180 /*!
181  *  MakeCylinderRH
182  */
183 //=============================================================================
184 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRH (double theR, double theH)
185 {
186   SetErrorCode(KO);
187
188   //Add a new Cylinder object
189   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
190
191   //Add a new Cylinder function with R and H parameters
192   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H);
193   if (aFunction.IsNull()) return NULL;
194
195   //Check if the function is set correctly
196   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
197
198   GEOMImpl_ICylinder aCI (aFunction);
199
200   aCI.SetR(theR);
201   aCI.SetH(theH);
202
203   //Compute the Cylinder value
204   try {
205     if (!GetSolver()->ComputeFunction(aFunction)) {
206       SetErrorCode("Cylinder driver failed");
207       return NULL;
208     }
209   }
210   catch (Standard_Failure) {
211     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
212     SetErrorCode(aFail->GetMessageString());
213     return NULL;
214   }
215
216   //Make a Python command
217   TCollection_AsciiString anEntry, aDescr("");
218   TDF_Tool::Entry(aCylinder->GetEntry(), anEntry);
219   aDescr += anEntry;
220   aDescr += " = I3DPrimOperations.MakeCylinderRH(";
221   aDescr += (TCollection_AsciiString(theR)+", ");
222   aDescr += (TCollection_AsciiString(theH)+")");
223
224   aFunction->SetDescription(aDescr);
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   TCollection_AsciiString anEntry, aDescr("");
282   TDF_Tool::Entry(aCylinder->GetEntry(), anEntry);
283   aDescr += anEntry;
284   aDescr += " = I3DPrimOperations.MakeCylinderPntVecRH(";
285   TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
286   aDescr += (anEntry+", ");
287   TDF_Tool::Entry(theVec->GetEntry(), anEntry);
288   aDescr += (anEntry+", ");
289   aDescr += (TCollection_AsciiString(theR)+", ");
290   aDescr += (TCollection_AsciiString(theH)+")");
291
292   aFunction->SetDescription(aDescr);
293
294   SetErrorCode(OK);
295   return aCylinder;
296 }
297
298
299 //=============================================================================
300 /*!
301  *  MakeConeR1R2H
302  */
303 //=============================================================================
304 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConeR1R2H (double theR1, double theR2,
305                                                                double theH)
306 {
307   SetErrorCode(KO);
308
309   //Add a new Cone object
310   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
311
312   //Add a new Cone function with R and H parameters
313   Handle(GEOM_Function) aFunction =
314     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_R1_R2_H);
315   if (aFunction.IsNull()) return NULL;
316
317   //Check if the function is set correctly
318   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
319
320   GEOMImpl_ICone aCI (aFunction);
321
322   aCI.SetR1(theR1);
323   aCI.SetR2(theR2);
324   aCI.SetH(theH);
325
326   //Compute the Cone value
327   try {
328     if (!GetSolver()->ComputeFunction(aFunction)) {
329       SetErrorCode("Cone driver failed");
330       return NULL;
331     }
332   }
333   catch (Standard_Failure) {
334     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
335     SetErrorCode(aFail->GetMessageString());
336     return NULL;
337   }
338
339   //Make a Python command
340   TCollection_AsciiString anEntry, aDescr("");
341   TDF_Tool::Entry(aCone->GetEntry(), anEntry);
342   aDescr += anEntry;
343   aDescr += " = I3DPrimOperations.MakeConeR1R2H(";
344   aDescr += (TCollection_AsciiString(theR1)+", ");
345   aDescr += (TCollection_AsciiString(theR2)+", ");
346   aDescr += (TCollection_AsciiString(theH)+")");
347
348   aFunction->SetDescription(aDescr);
349
350   SetErrorCode(OK);
351   return aCone;
352 }
353
354
355 //=============================================================================
356 /*!
357  *  MakeConePntVecR1R2H
358  */
359 //=============================================================================
360 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConePntVecR1R2H (Handle(GEOM_Object) thePnt,
361                                                                      Handle(GEOM_Object) theVec,
362                                                                      double theR1, double theR2,
363                                                                      double theH)
364 {
365   SetErrorCode(KO);
366
367   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
368
369   //Add a new Cone object
370   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
371
372   //Add a new Cone function for creation a cone relatively to point and vector
373   Handle(GEOM_Function) aFunction =
374     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_PNT_VEC_R1_R2_H);
375   if (aFunction.IsNull()) return NULL;
376
377   //Check if the function is set correctly
378   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
379
380   GEOMImpl_ICone aCI (aFunction);
381
382   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
383   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
384
385   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
386
387   aCI.SetPoint(aRefPnt);
388   aCI.SetVector(aRefVec);
389   aCI.SetR1(theR1);
390   aCI.SetR2(theR2);
391   aCI.SetH(theH);
392
393   //Compute the Cone value
394   try {
395     if (!GetSolver()->ComputeFunction(aFunction)) {
396       SetErrorCode("Cone driver failed");
397       return NULL;
398     }
399   }
400   catch (Standard_Failure) {
401     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
402     SetErrorCode(aFail->GetMessageString());
403     return NULL;
404   }
405
406   //Make a Python command
407   TCollection_AsciiString anEntry, aDescr("");
408   TDF_Tool::Entry(aCone->GetEntry(), anEntry);
409   aDescr += anEntry;
410   aDescr += " = I3DPrimOperations.MakeConePntVecR1R2H(";
411   TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
412   aDescr += (anEntry+", ");
413   TDF_Tool::Entry(theVec->GetEntry(), anEntry);
414   aDescr += (anEntry+", ");
415   aDescr += (TCollection_AsciiString(theR1)+", ");
416   aDescr += (TCollection_AsciiString(theR2)+", ");
417   aDescr += (TCollection_AsciiString(theH)+")");
418
419   aFunction->SetDescription(aDescr);
420
421   SetErrorCode(OK);
422   return aCone;
423 }
424
425
426 //=============================================================================
427 /*!
428  *  MakeSphereR
429  */
430 //=============================================================================
431 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSphereR (double theR)
432 {
433   SetErrorCode(KO);
434
435   //Add a new Sphere object
436   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
437
438   //Add a new Sphere function with R parameter
439   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_R);
440   if (aFunction.IsNull()) return NULL;
441
442   //Check if the function is set correctly
443   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
444
445   GEOMImpl_ISphere aCI (aFunction);
446
447   aCI.SetR(theR);
448
449   //Compute the Sphere value
450   try {
451     if (!GetSolver()->ComputeFunction(aFunction)) {
452       SetErrorCode("Sphere driver failed");
453       return NULL;
454     }
455   }
456   catch (Standard_Failure) {
457     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
458     SetErrorCode(aFail->GetMessageString());
459     return NULL;
460   }
461
462   //Make a Python command
463   TCollection_AsciiString anEntry, aDescr("");
464   TDF_Tool::Entry(aSphere->GetEntry(), anEntry);
465   aDescr += anEntry;
466   aDescr += " = I3DPrimOperations.MakeSphereR(";
467   aDescr += (TCollection_AsciiString(theR)+")");
468
469   aFunction->SetDescription(aDescr);
470
471   SetErrorCode(OK);
472   return aSphere;
473 }
474
475
476 //=============================================================================
477 /*!
478  *  MakeSpherePntR
479  */
480 //=============================================================================
481 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSpherePntR (Handle(GEOM_Object) thePnt,
482                                                                 double theR)
483 {
484   SetErrorCode(KO);
485
486   if (thePnt.IsNull()) return NULL;
487
488   //Add a new Point object
489   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
490
491   //Add a new Sphere function for creation a sphere relatively to point
492   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_PNT_R);
493   if (aFunction.IsNull()) return NULL;
494
495   //Check if the function is set correctly
496   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
497
498   GEOMImpl_ISphere aCI (aFunction);
499
500   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
501
502   if (aRefPnt.IsNull()) return NULL;
503
504   aCI.SetPoint(aRefPnt);
505   aCI.SetR(theR);
506
507   //Compute the Sphere value
508   try {
509     if (!GetSolver()->ComputeFunction(aFunction)) {
510       SetErrorCode("Sphere driver failed");
511       return NULL;
512     }
513   }
514   catch (Standard_Failure) {
515     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
516     SetErrorCode(aFail->GetMessageString());
517     return NULL;
518   }
519
520   //Make a Python command
521   TCollection_AsciiString anEntry, aDescr("");
522   TDF_Tool::Entry(aSphere->GetEntry(), anEntry);
523   aDescr += anEntry;
524   aDescr += " = I3DPrimOperations.MakeSpherePntR(";
525   TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
526   aDescr += (anEntry+", ");
527   aDescr += (TCollection_AsciiString(theR)+")");
528
529   aFunction->SetDescription(aDescr);
530
531   SetErrorCode(OK);
532   return aSphere;
533 }
534
535
536 //=============================================================================
537 /*!
538  *  MakeTorusRR
539  */
540 //=============================================================================
541 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusRR
542                                            (double theRMajor, double theRMinor)
543 {
544   SetErrorCode(KO);
545
546   //Add a new Torus object
547   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
548
549   //Add a new Torus function
550   Handle(GEOM_Function) aFunction =
551     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_RR);
552   if (aFunction.IsNull()) return NULL;
553
554   //Check if the function is set correctly
555   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
556
557   GEOMImpl_ITorus aCI (aFunction);
558
559   aCI.SetRMajor(theRMajor);
560   aCI.SetRMinor(theRMinor);
561
562   //Compute the Torus value
563   try {
564     if (!GetSolver()->ComputeFunction(aFunction)) {
565       SetErrorCode("Torus driver failed");
566       return NULL;
567     }
568   }
569   catch (Standard_Failure) {
570     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
571     SetErrorCode(aFail->GetMessageString());
572     return NULL;
573   }
574
575   //Make a Python command
576   TCollection_AsciiString anEntry, aDescr("");
577   TDF_Tool::Entry(anEll->GetEntry(), anEntry);
578   aDescr += anEntry;
579   aDescr += " = ICurvesOperations.MakeTorusRR(";
580   aDescr += (TCollection_AsciiString(theRMajor)+", ");
581   aDescr += (TCollection_AsciiString(theRMinor)+")");
582
583   aFunction->SetDescription(aDescr);
584
585   SetErrorCode(OK);
586   return anEll;
587 }
588
589 //=============================================================================
590 /*!
591  *  MakeTorusPntVecRR
592  */
593 //=============================================================================
594 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusPntVecRR
595                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
596                         double theRMajor, double theRMinor)
597 {
598   SetErrorCode(KO);
599
600   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
601
602   //Add a new Torus object
603   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
604
605   //Add a new Torus function
606   Handle(GEOM_Function) aFunction =
607     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_PNT_VEC_RR);
608   if (aFunction.IsNull()) return NULL;
609
610   //Check if the function is set correctly
611   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
612
613   GEOMImpl_ITorus aCI (aFunction);
614
615   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
616   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
617
618   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
619
620   aCI.SetCenter(aRefPnt);
621   aCI.SetVector(aRefVec);
622   aCI.SetRMajor(theRMajor);
623   aCI.SetRMinor(theRMinor);
624
625   //Compute the Torus value
626   try {
627     if (!GetSolver()->ComputeFunction(aFunction)) {
628       SetErrorCode("Torus driver failed");
629       return NULL;
630     }
631   }
632   catch (Standard_Failure) {
633     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
634     SetErrorCode(aFail->GetMessageString());
635     return NULL;
636   }
637
638   //Make a Python command
639   TCollection_AsciiString anEntry, aDescr("");
640   TDF_Tool::Entry(anEll->GetEntry(), anEntry);
641   aDescr += anEntry;
642   aDescr += " = ICurvesOperations.MakeTorusPntVecRR(";
643   TDF_Tool::Entry(thePnt->GetEntry(), anEntry);
644   aDescr += (anEntry+", ");
645   TDF_Tool::Entry(theVec->GetEntry(), anEntry);
646   aDescr += (anEntry+", ");
647   aDescr += (TCollection_AsciiString(theRMajor)+", ");
648   aDescr += (TCollection_AsciiString(theRMinor)+")");
649
650   aFunction->SetDescription(aDescr);
651
652   SetErrorCode(OK);
653   return anEll;
654 }
655
656
657 //=============================================================================
658 /*!
659  *  MakePrismVecH
660  */
661 //=============================================================================
662 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH (Handle(GEOM_Object) theBase,
663                                                                Handle(GEOM_Object) theVec,
664                                                                double theH)
665 {
666   SetErrorCode(KO);
667
668   if (theBase.IsNull() || theVec.IsNull()) return NULL;
669
670   //Add a new Prism object
671   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
672
673   //Add a new Prism function for creation a Prism relatively to vector
674   Handle(GEOM_Function) aFunction =
675     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H);
676   if (aFunction.IsNull()) return NULL;
677
678   //Check if the function is set correctly
679   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
680
681   GEOMImpl_IPrism aCI (aFunction);
682
683   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
684   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
685
686   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
687
688   aCI.SetBase(aRefBase);
689   aCI.SetVector(aRefVec);
690   aCI.SetH(theH);
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   TCollection_AsciiString anEntry, aDescr("");
707   TDF_Tool::Entry(aPrism->GetEntry(), anEntry);
708   aDescr += anEntry;
709   aDescr += " = I3DPrimOperations.MakePrismVecH(";
710   TDF_Tool::Entry(theBase->GetEntry(), anEntry);
711   aDescr += (anEntry+", ");
712   TDF_Tool::Entry(theVec->GetEntry(), anEntry);
713   aDescr += (anEntry+", ");
714   aDescr += (TCollection_AsciiString(theH)+")");
715
716   aFunction->SetDescription(aDescr);
717
718   SetErrorCode(OK);
719   return aPrism;
720 }
721
722 //=============================================================================
723 /*!
724  *  MakePrismTwoPnt
725  */
726 //=============================================================================
727 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
728        (Handle(GEOM_Object) theBase,
729         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
730 {
731   SetErrorCode(KO);
732
733   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
734
735   //Add a new Prism object
736   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
737
738   //Add a new Prism function for creation a Prism relatively to two points
739   Handle(GEOM_Function) aFunction =
740     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
741   if (aFunction.IsNull()) return NULL;
742
743   //Check if the function is set correctly
744   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
745
746   GEOMImpl_IPrism aCI (aFunction);
747
748   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
749   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
750   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
751
752   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
753
754   aCI.SetBase(aRefBase);
755   aCI.SetFirstPoint(aRefPnt1);
756   aCI.SetLastPoint(aRefPnt2);
757
758   //Compute the Prism value
759   try {
760     if (!GetSolver()->ComputeFunction(aFunction)) {
761       SetErrorCode("Prism driver failed");
762       return NULL;
763     }
764   }
765   catch (Standard_Failure) {
766     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
767     SetErrorCode(aFail->GetMessageString());
768     return NULL;
769   }
770
771   //Make a Python command
772   TCollection_AsciiString anEntry, aDescr("");
773   TDF_Tool::Entry(aPrism->GetEntry(), anEntry);
774   aDescr += anEntry;
775   aDescr += " = I3DPrimOperations.MakePrismVecH(";
776   TDF_Tool::Entry(theBase->GetEntry(), anEntry);
777   aDescr += (anEntry+", ");
778   TDF_Tool::Entry(thePoint1->GetEntry(), anEntry);
779   aDescr += (anEntry+", ");
780   TDF_Tool::Entry(thePoint2->GetEntry(), anEntry);
781   aDescr += (anEntry+")");
782
783   aFunction->SetDescription(aDescr);
784
785   SetErrorCode(OK);
786   return aPrism;
787 }
788
789
790 //=============================================================================
791 /*!
792  *  MakePipe
793  */
794 //=============================================================================
795 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePipe (Handle(GEOM_Object) theBase,
796                                                           Handle(GEOM_Object) thePath)
797 {
798   SetErrorCode(KO);
799
800   if (theBase.IsNull() || thePath.IsNull()) return NULL;
801
802   //Add a new Pipe object
803   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
804
805   //Add a new Pipe function
806   Handle(GEOM_Function) aFunction =
807     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
808   if (aFunction.IsNull()) return NULL;
809
810   //Check if the function is set correctly
811   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
812
813   GEOMImpl_IPipe aCI (aFunction);
814
815   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
816   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
817
818   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
819
820   aCI.SetBase(aRefBase);
821   aCI.SetPath(aRefPath);
822
823   //Compute the Pipe value
824   try {
825     if (!GetSolver()->ComputeFunction(aFunction)) {
826       SetErrorCode("Pipe driver failed");
827       return NULL;
828     }
829   }
830   catch (Standard_Failure) {
831     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
832     SetErrorCode(aFail->GetMessageString());
833     return NULL;
834   }
835
836   //Make a Python command
837   TCollection_AsciiString anEntry, aDescr;
838   TDF_Tool::Entry(aPipe->GetEntry(), anEntry);
839   aDescr += (anEntry + " = I3DPrimOperations.MakePipe(");
840   TDF_Tool::Entry(theBase->GetEntry(), anEntry);
841   aDescr += (anEntry + ", ");
842   TDF_Tool::Entry(thePath->GetEntry(), anEntry);
843   aDescr += (anEntry + ")");
844
845   aFunction->SetDescription(aDescr);
846
847   SetErrorCode(OK);
848   return aPipe;
849 }
850
851
852 //=============================================================================
853 /*!
854  *  MakeRevolutionAxisAngle
855  */
856 //=============================================================================
857 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
858                                                                          Handle(GEOM_Object) theAxis,
859                                                                          double theAngle)
860 {
861   SetErrorCode(KO);
862
863   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
864
865   //Add a new Revolution object
866   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
867
868   //Add a new Revolution function for creation a revolution relatively to axis
869   Handle(GEOM_Function) aFunction =
870     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
871   if (aFunction.IsNull()) return NULL;
872
873   //Check if the function is set correctly
874   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
875
876   GEOMImpl_IRevolution aCI (aFunction);
877
878   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
879   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
880
881   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
882
883   aCI.SetBase(aRefBase);
884   aCI.SetAxis(aRefAxis);
885   aCI.SetAngle(theAngle);
886
887   //Compute the Revolution value
888   try {
889     if (!GetSolver()->ComputeFunction(aFunction)) {
890       SetErrorCode("Revolution driver failed");
891       return NULL;
892     }
893   }
894   catch (Standard_Failure) {
895     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
896     SetErrorCode(aFail->GetMessageString());
897     return NULL;
898   }
899
900   //Make a Python command
901   TCollection_AsciiString anEntry, aDescr("");
902   TDF_Tool::Entry(aRevolution->GetEntry(), anEntry);
903   aDescr += anEntry;
904   aDescr += " = I3DPrimOperations.MakeRevolutionAxisAngle(";
905   TDF_Tool::Entry(theBase->GetEntry(), anEntry);
906   aDescr += (anEntry+", ");
907   TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
908   aDescr += (anEntry+", ");
909   aDescr += (TCollection_AsciiString(theAngle)+")");
910
911   aFunction->SetDescription(aDescr);
912
913   SetErrorCode(OK);
914   return aRevolution;
915 }
916
917
918 //=============================================================================
919 /*!
920  *  MakeSolidShell
921  */
922 //=============================================================================
923 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSolidShell (Handle(GEOM_Object) theShell)
924 {
925   SetErrorCode(KO);
926
927   if (theShell.IsNull()) return NULL;
928
929   //Add a new Solid object
930   Handle(GEOM_Object) aSolid = GetEngine()->AddObject(GetDocID(), GEOM_SOLID);
931
932   //Add a new Solid function for creation a solid from a shell
933   Handle(GEOM_Function) aFunction =
934     aSolid->AddFunction(GEOMImpl_ShapeDriver::GetID(), SOLID_SHELL);
935   if (aFunction.IsNull()) return NULL;
936
937   //Check if the function is set correctly
938   if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) return NULL;
939
940   GEOMImpl_IShapes aCI (aFunction);
941
942   Handle(GEOM_Function) aRefShell = theShell->GetLastFunction();
943
944   if (aRefShell.IsNull()) return NULL;
945
946   aCI.SetBase(aRefShell);
947
948   //Compute the Solid value
949   try {
950     if (!GetSolver()->ComputeFunction(aFunction)) {
951       SetErrorCode("Solid driver failed");
952       return NULL;
953     }
954   }
955   catch (Standard_Failure) {
956     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
957     SetErrorCode(aFail->GetMessageString());
958     return NULL;
959   }
960
961   //Make a Python command
962   TCollection_AsciiString anEntry, aDescr("");
963   TDF_Tool::Entry(aSolid->GetEntry(), anEntry);
964   aDescr += anEntry;
965   aDescr += " = I3DPrimOperations.MakeSolidShell(";
966   TDF_Tool::Entry(theShell->GetEntry(), anEntry);
967   aDescr += (anEntry+")");
968
969   aFunction->SetDescription(aDescr);
970
971   SetErrorCode(OK);
972   return aSolid;
973 }
974
975 //=============================================================================
976 /*!
977  *  MakeFilling
978  */
979 //=============================================================================
980 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFilling (Handle(GEOM_Object) theShape, int theMinDeg, int theMaxDeg, double theTol2D, double theTol3D, int theNbIter)
981 {
982   SetErrorCode(KO);
983
984   if (theShape.IsNull()) return NULL;
985
986   //Add a new Filling object
987   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
988
989   //Add a new Filling function for creation a filling  from a compound
990   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
991   if (aFunction.IsNull()) return NULL;
992
993   //Check if the function is set correctly
994   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
995
996   GEOMImpl_IFilling aFI (aFunction);
997
998   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
999
1000   if (aRefShape.IsNull()) return NULL;
1001
1002   aFI.SetShape(aRefShape);
1003   aFI.SetMinDeg(theMinDeg);
1004   aFI.SetMaxDeg(theMaxDeg);
1005   aFI.SetTol2D(theTol2D);
1006   aFI.SetTol3D(theTol3D);
1007   aFI.SetNbIter(theNbIter);
1008
1009   //Compute the Solid value
1010   try {
1011     if (!GetSolver()->ComputeFunction(aFunction)) {
1012       SetErrorCode("Fiiling driver failed");
1013       return NULL;
1014     }
1015   }
1016   catch (Standard_Failure) {
1017     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1018     SetErrorCode(aFail->GetMessageString());
1019     return NULL;
1020   }
1021
1022   //Make a Python command
1023   TCollection_AsciiString anEntry, aDescr("");
1024   TDF_Tool::Entry(aFilling->GetEntry(), anEntry);
1025   aDescr += anEntry;
1026   aDescr += " = ICurvesOperations.MakeFilling(";
1027   TDF_Tool::Entry(theShape->GetEntry(), anEntry);
1028   aDescr += (anEntry+", ");
1029   aDescr += (TCollection_AsciiString(theMinDeg)+", ");
1030   aDescr += (TCollection_AsciiString(theMaxDeg)+", ");
1031   aDescr += (TCollection_AsciiString(theTol2D)+", ");
1032   aDescr += (TCollection_AsciiString(theTol3D)+", ");
1033   aDescr += (TCollection_AsciiString(theNbIter)+")");
1034
1035   aFunction->SetDescription(aDescr);
1036
1037   SetErrorCode(OK);
1038   return aFilling;
1039 }