Salome HOME
0023450: Fields are not displayed in GEOM
[modules/geom.git] / src / GEOMImpl / GEOMImpl_I3DPrimOperations.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_I3DPrimOperations.hxx>
26
27 #include "utilities.h"
28 #include <OpUtil.hxx>
29 #include <Utils_ExceptHandlers.hxx>
30
31 #include <TFunction_DriverTable.hxx>
32 #include <TFunction_Driver.hxx>
33 #include <TDF_Tool.hxx>
34
35 #include <GEOM_Function.hxx>
36 #include <GEOM_PythonDump.hxx>
37
38 #include <GEOMImpl_Types.hxx>
39
40 #include <GEOMImpl_BoxDriver.hxx>
41 #include <GEOMImpl_FaceDriver.hxx>
42 #include <GEOMImpl_DiskDriver.hxx>
43 #include <GEOMImpl_CylinderDriver.hxx>
44 #include <GEOMImpl_ConeDriver.hxx>
45 #include <GEOMImpl_SphereDriver.hxx>
46 #include <GEOMImpl_TorusDriver.hxx>
47 #include <GEOMImpl_PrismDriver.hxx>
48 #include <GEOMImpl_PipeDriver.hxx>
49 #include <GEOMImpl_PipePathDriver.hxx>
50 #include <GEOMImpl_RevolutionDriver.hxx>
51 #include <GEOMImpl_ShapeDriver.hxx>
52 #include <GEOMImpl_FillingDriver.hxx>
53 #include <GEOMImpl_ThruSectionsDriver.hxx>
54 #include <GEOMImpl_OffsetDriver.hxx>
55
56 #include <GEOMImpl_IBox.hxx>
57 #include <GEOMImpl_IFace.hxx>
58 #include <GEOMImpl_IDisk.hxx>
59 #include <GEOMImpl_ICylinder.hxx>
60 #include <GEOMImpl_ICone.hxx>
61 #include <GEOMImpl_IGroupOperations.hxx>
62 #include <GEOMImpl_ISphere.hxx>
63 #include <GEOMImpl_ITorus.hxx>
64 #include <GEOMImpl_IPrism.hxx>
65 #include <GEOMImpl_IPipe.hxx>
66 #include <GEOMImpl_IRevolution.hxx>
67 #include <GEOMImpl_IFilling.hxx>
68 #include <GEOMImpl_IThruSections.hxx>
69 #include <GEOMImpl_IPipeDiffSect.hxx>
70 #include <GEOMImpl_IPipeShellSect.hxx>
71 #include <GEOMImpl_IPipeBiNormal.hxx>
72 #include <GEOMImpl_IOffset.hxx>
73 #include <GEOMImpl_IPipePath.hxx>
74
75 #include <Precision.hxx>
76 #include <TopExp.hxx>
77
78 #include <Standard_Failure.hxx>
79 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
80
81 //=============================================================================
82 /*!
83  *   constructor:
84  */
85 //=============================================================================
86 GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, int theDocID)
87 : GEOM_IOperations(theEngine, theDocID)
88 {
89   MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations");
90   myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID());
91 }
92
93 //=============================================================================
94 /*!
95  *  destructor
96  */
97 //=============================================================================
98 GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations()
99 {
100   MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations");
101   delete myGroupOperations;
102 }
103
104
105 //=============================================================================
106 /*!
107  *  MakeBoxDXDYDZ
108  */
109 //=============================================================================
110 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxDXDYDZ (double theDX, double theDY, double theDZ)
111 {
112   SetErrorCode(KO);
113
114   //Add a new Box object
115   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
116
117   //Add a new Box function with DX_DY_DZ parameters
118   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_DX_DY_DZ);
119   if (aFunction.IsNull()) return NULL;
120
121   //Check if the function is set correctly
122   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return NULL;
123
124   GEOMImpl_IBox aBI (aFunction);
125
126   aBI.SetDX(theDX);
127   aBI.SetDY(theDY);
128   aBI.SetDZ(theDZ);
129
130   //Compute the box value
131   try {
132     OCC_CATCH_SIGNALS;
133     if (!GetSolver()->ComputeFunction(aFunction)) {
134       SetErrorCode("Box driver failed");
135       return NULL;
136     }
137   }
138   catch (Standard_Failure) {
139     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
140     SetErrorCode(aFail->GetMessageString());
141     return NULL;
142   }
143
144   //Make a Python command
145   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxDXDYDZ("
146     << theDX << ", " << theDY << ", " << theDZ << ")";
147
148   SetErrorCode(OK);
149   return aBox;
150 }
151
152
153 //=============================================================================
154 /*!
155  *  MakeBoxTwoPnt
156  */
157 //=============================================================================
158 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeBoxTwoPnt (Handle(GEOM_Object) thePnt1,
159                                                                Handle(GEOM_Object) thePnt2)
160 {
161   SetErrorCode(KO);
162
163   if (thePnt1.IsNull() || thePnt2.IsNull()) return NULL;
164
165   //Add a new Box object
166   Handle(GEOM_Object) aBox = GetEngine()->AddObject(GetDocID(), GEOM_BOX);
167
168   //Add a new Box function for creation a box relatively to two points
169   Handle(GEOM_Function) aFunction = aBox->AddFunction(GEOMImpl_BoxDriver::GetID(), BOX_TWO_PNT);
170   if (aFunction.IsNull()) return NULL;
171
172   //Check if the function is set correctly
173   if (aFunction->GetDriverGUID() != GEOMImpl_BoxDriver::GetID()) return aBox;
174
175   GEOMImpl_IBox aBI (aFunction);
176
177   Handle(GEOM_Function) aRefFunction1 = thePnt1->GetLastFunction();
178   Handle(GEOM_Function) aRefFunction2 = thePnt2->GetLastFunction();
179
180   if (aRefFunction1.IsNull() || aRefFunction2.IsNull()) return aBox;
181
182   aBI.SetRef1(aRefFunction1);
183   aBI.SetRef2(aRefFunction2);
184
185   //Compute the Box value
186   try {
187     OCC_CATCH_SIGNALS;
188     if (!GetSolver()->ComputeFunction(aFunction)) {
189       SetErrorCode("Box driver failed");
190       return NULL;
191     }
192   }
193   catch (Standard_Failure) {
194     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
195     SetErrorCode(aFail->GetMessageString());
196     return NULL;
197   }
198
199   //Make a Python command
200   GEOM::TPythonDump(aFunction) << aBox << " = geompy.MakeBoxTwoPnt("
201     << thePnt1 << ", " << thePnt2 << ")";
202
203   SetErrorCode(OK);
204   return aBox;
205 }
206
207 //=============================================================================
208 /*!
209  *  MakeFaceHW
210  */
211 //=============================================================================
212 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFaceHW (double theH, double theW, int theOrientation)
213 {
214   SetErrorCode(KO);
215
216   if (theH == 0 || theW == 0) return NULL;
217
218   //Add a new Face object
219   Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
220
221   //Add a new Box function for creation a box relatively to two points
222   Handle(GEOM_Function) aFunction = aFace->AddFunction(GEOMImpl_FaceDriver::GetID(), FACE_H_W);
223   if (aFunction.IsNull()) return NULL;
224
225   //Check if the function is set correctly
226   if (aFunction->GetDriverGUID() != GEOMImpl_FaceDriver::GetID()) return aFace;
227
228   GEOMImpl_IFace aFI (aFunction);
229
230   aFI.SetH(theH);
231   aFI.SetW(theW);
232   aFI.SetOrientation(theOrientation);
233
234   //Compute the Face
235   try {
236     OCC_CATCH_SIGNALS;
237     if (!GetSolver()->ComputeFunction(aFunction)) {
238       SetErrorCode("Face driver failed");
239       return NULL;
240     }
241   }
242   catch (Standard_Failure) {
243     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
244     SetErrorCode(aFail->GetMessageString());
245     return NULL;
246   }
247
248   //Make a Python command
249   GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFaceHW("
250     << theH << ", " << theW << ", " << theOrientation << ")";
251
252   SetErrorCode(OK);
253   return aFace;
254 }
255
256 //=============================================================================
257 /*!
258  *  MakeFaceObjHW
259  */
260 //=============================================================================
261 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeFaceObjHW (Handle(GEOM_Object) theObj,
262                                                                double theH, double theW)
263 {
264   SetErrorCode(KO);
265
266   if (theObj.IsNull()) return NULL;
267
268   //Add a new Face object
269   Handle(GEOM_Object) aFace = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
270
271   //Add a new Box function for creation a box relatively to two points
272   Handle(GEOM_Function) aFunction = aFace->AddFunction(GEOMImpl_FaceDriver::GetID(), FACE_OBJ_H_W);
273   if (aFunction.IsNull()) return NULL;
274
275   //Check if the function is set correctly
276   if (aFunction->GetDriverGUID() != GEOMImpl_FaceDriver::GetID()) return aFace;
277
278   GEOMImpl_IFace aFI (aFunction);
279
280   Handle(GEOM_Function) aRefFunction1 = theObj->GetLastFunction();
281
282   if (aRefFunction1.IsNull())
283     return aFace;
284
285   aFI.SetRef1(aRefFunction1);
286   aFI.SetH(theH);
287   aFI.SetW(theW);
288
289   //Compute the Face
290   try {
291     OCC_CATCH_SIGNALS;
292     if (!GetSolver()->ComputeFunction(aFunction)) {
293       SetErrorCode("Face driver failed");
294       return NULL;
295     }
296   }
297   catch (Standard_Failure) {
298     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
299     SetErrorCode(aFail->GetMessageString());
300     return NULL;
301   }
302
303   //Make a Python command
304   GEOM::TPythonDump(aFunction) << aFace << " = geompy.MakeFaceObjHW("
305     << theObj << ", " << theH << ", " << theW << ")";
306
307   SetErrorCode(OK);
308   return aFace;
309 }
310
311 //=============================================================================
312 /*!
313  *  MakeDiskPntVecR
314  */
315 //=============================================================================
316 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskPntVecR
317       (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec, double theR)
318 {
319   SetErrorCode(KO);
320
321   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
322
323   //Add a new Disk object
324   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
325
326   //Add a new Disk function for creation a disk relatively to point and vector
327   Handle(GEOM_Function) aFunction =
328     aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_PNT_VEC_R);
329   if (aFunction.IsNull()) return NULL;
330
331   //Check if the function is set correctly
332   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return NULL;
333
334   GEOMImpl_IDisk aCI (aFunction);
335
336   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
337   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
338
339   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
340
341   aCI.SetCenter(aRefPnt);
342   aCI.SetVector(aRefVec);
343   aCI.SetRadius(theR);
344
345   //Compute the Disk value
346   try {
347     OCC_CATCH_SIGNALS;
348     if (!GetSolver()->ComputeFunction(aFunction)) {
349       SetErrorCode("Disk driver failed");
350       return NULL;
351     }
352   }
353   catch (Standard_Failure) {
354     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
355     SetErrorCode(aFail->GetMessageString());
356     return NULL;
357   }
358
359   //Make a Python command
360   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskPntVecR("
361     << thePnt << ", " << theVec << ", " << theR << ")";
362
363   SetErrorCode(OK);
364   return aDisk;
365 }
366
367 //=============================================================================
368 /*!
369  *  MakeDiskThreePnt
370  */
371 //=============================================================================
372 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskThreePnt (Handle(GEOM_Object) thePnt1,
373                                                                   Handle(GEOM_Object) thePnt2,
374                                                                   Handle(GEOM_Object) thePnt3)
375 {
376   SetErrorCode(KO);
377
378   if (thePnt1.IsNull() || thePnt2.IsNull() || thePnt3.IsNull()) return NULL;
379
380   //Add a new Disk object
381   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
382
383   //Add a new Disk function for creation a disk relatively to three points
384   Handle(GEOM_Function) aFunction =
385     aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_THREE_PNT);
386   if (aFunction.IsNull()) return NULL;
387
388   //Check if the function is set correctly
389   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return NULL;
390
391   GEOMImpl_IDisk aCI (aFunction);
392
393   Handle(GEOM_Function) aRefPnt1 = thePnt1->GetLastFunction();
394   Handle(GEOM_Function) aRefPnt2 = thePnt2->GetLastFunction();
395   Handle(GEOM_Function) aRefPnt3 = thePnt3->GetLastFunction();
396
397   if (aRefPnt1.IsNull() || aRefPnt2.IsNull() || aRefPnt3.IsNull()) return NULL;
398
399   aCI.SetPoint1(aRefPnt1);
400   aCI.SetPoint2(aRefPnt2);
401   aCI.SetPoint3(aRefPnt3);
402
403   //Compute the Disk value
404   try {
405     OCC_CATCH_SIGNALS;
406     if (!GetSolver()->ComputeFunction(aFunction)) {
407       SetErrorCode("Disk driver failed");
408       return NULL;
409     }
410   }
411   catch (Standard_Failure) {
412     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
413     SetErrorCode(aFail->GetMessageString());
414     return NULL;
415   }
416
417   //Make a Python command
418   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskThreePnt("
419     << thePnt1 << ", " << thePnt2 << ", " << thePnt3 << ")";
420
421   SetErrorCode(OK);
422   return aDisk;
423 }
424
425 //=============================================================================
426 /*!
427  *  MakeDiskR
428  */
429 //=============================================================================
430 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDiskR (double theR, int theOrientation)
431 {
432   SetErrorCode(KO);
433
434   if (theR == 0 ) return NULL;
435
436   //Add a new Disk object
437   Handle(GEOM_Object) aDisk = GetEngine()->AddObject(GetDocID(), GEOM_FACE);
438
439   //Add a new Box function for creation a box relatively to two points
440   Handle(GEOM_Function) aFunction = aDisk->AddFunction(GEOMImpl_DiskDriver::GetID(), DISK_R);
441   if (aFunction.IsNull()) return NULL;
442
443   //Check if the function is set correctly
444   if (aFunction->GetDriverGUID() != GEOMImpl_DiskDriver::GetID()) return aDisk;
445
446   GEOMImpl_IDisk aDI (aFunction);
447
448   aDI.SetRadius(theR);
449   aDI.SetOrientation(theOrientation);
450
451   //Compute the Disk
452   try {
453     OCC_CATCH_SIGNALS;
454     if (!GetSolver()->ComputeFunction(aFunction)) {
455       SetErrorCode("Disk driver failed");
456       return NULL;
457     }
458   }
459   catch (Standard_Failure) {
460     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
461     SetErrorCode(aFail->GetMessageString());
462     return NULL;
463   }
464
465   //Make a Python command
466   GEOM::TPythonDump(aFunction) << aDisk << " = geompy.MakeDiskR("
467     << theR << ", " << theOrientation << ")";
468
469   SetErrorCode(OK);
470   return aDisk;
471 }
472
473 //=============================================================================
474 /*!
475  *  MakeCylinderRH
476  */
477 //=============================================================================
478 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRH (double theR, double theH)
479 {
480   SetErrorCode(KO);
481
482   //Add a new Cylinder object
483   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
484
485   //Add a new Cylinder function with R and H parameters
486   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H);
487   if (aFunction.IsNull()) return NULL;
488
489   //Check if the function is set correctly
490   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
491
492   GEOMImpl_ICylinder aCI (aFunction);
493
494   aCI.SetR(theR);
495   aCI.SetH(theH);
496
497   //Compute the Cylinder value
498   try {
499     OCC_CATCH_SIGNALS;
500     if (!GetSolver()->ComputeFunction(aFunction)) {
501       SetErrorCode("Cylinder driver failed");
502       return NULL;
503     }
504   }
505   catch (Standard_Failure) {
506     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
507     SetErrorCode(aFail->GetMessageString());
508     return NULL;
509   }
510
511   //Make a Python command
512   GEOM::TPythonDump(aFunction) << aCylinder
513     << " = geompy.MakeCylinderRH(" << theR << ", " << theH << ")";
514
515   SetErrorCode(OK);
516   return aCylinder;
517 }
518
519 //=============================================================================
520 /*!
521  *  MakeCylinderRHA
522  */
523 //=============================================================================
524 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderRHA (double theR, double theH, double theA)
525 {
526   SetErrorCode(KO);
527
528   //Add a new Cylinder object
529   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
530
531   //Add a new Cylinder function with R and H parameters
532   Handle(GEOM_Function) aFunction = aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_R_H_A);
533   if (aFunction.IsNull()) return NULL;
534
535   //Check if the function is set correctly
536   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
537
538   GEOMImpl_ICylinder aCI (aFunction);
539
540   aCI.SetR(theR);
541   aCI.SetH(theH);
542   aCI.SetA(theA);
543
544   //Compute the Cylinder value
545   try {
546     OCC_CATCH_SIGNALS;
547     if (!GetSolver()->ComputeFunction(aFunction)) {
548       SetErrorCode("Cylinder driver failed");
549       return NULL;
550     }
551   }
552   catch (Standard_Failure) {
553     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
554     SetErrorCode(aFail->GetMessageString());
555     return NULL;
556   }
557
558   //Make a Python command
559   GEOM::TPythonDump(aFunction) << aCylinder
560     << " = geompy.MakeCylinderRHA(" << theR << ", " << theH << ", " << theA*180./M_PI << "*math.pi/180.)";
561
562   SetErrorCode(OK);
563   return aCylinder;
564 }
565
566 //=============================================================================
567 /*!
568  *  MakeCylinderPntVecRH
569  */
570 //=============================================================================
571 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRH (Handle(GEOM_Object) thePnt,
572                                                                       Handle(GEOM_Object) theVec,
573                                                                       double theR, double theH)
574 {
575   SetErrorCode(KO);
576
577   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
578
579   //Add a new Cylinder object
580   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
581
582   //Add a new Cylinder function for creation a cylinder relatively to point and vector
583   Handle(GEOM_Function) aFunction =
584     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H);
585   if (aFunction.IsNull()) return NULL;
586
587   //Check if the function is set correctly
588   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
589
590   GEOMImpl_ICylinder aCI (aFunction);
591
592   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
593   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
594
595   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
596
597   aCI.SetPoint(aRefPnt);
598   aCI.SetVector(aRefVec);
599   aCI.SetR(theR);
600   aCI.SetH(theH);
601
602   //Compute the Cylinder value
603   try {
604     OCC_CATCH_SIGNALS;
605     if (!GetSolver()->ComputeFunction(aFunction)) {
606       SetErrorCode("Cylinder driver failed");
607       return NULL;
608     }
609   }
610   catch (Standard_Failure) {
611     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
612     SetErrorCode(aFail->GetMessageString());
613     return NULL;
614   }
615
616   //Make a Python command
617   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinder("
618     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ")";
619
620   SetErrorCode(OK);
621   return aCylinder;
622 }
623
624 //=============================================================================
625 /*!
626  *  MakeCylinderPntVecRHA
627  */
628 //=============================================================================
629 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeCylinderPntVecRHA (Handle(GEOM_Object) thePnt,
630                                                                        Handle(GEOM_Object) theVec,
631                                                                        double theR, double theH, double theA)
632 {
633   SetErrorCode(KO);
634
635   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
636
637   //Add a new Cylinder object
638   Handle(GEOM_Object) aCylinder = GetEngine()->AddObject(GetDocID(), GEOM_CYLINDER);
639
640   //Add a new Cylinder function for creation a cylinder relatively to point and vector
641   Handle(GEOM_Function) aFunction =
642     aCylinder->AddFunction(GEOMImpl_CylinderDriver::GetID(), CYLINDER_PNT_VEC_R_H_A);
643   if (aFunction.IsNull()) return NULL;
644
645   //Check if the function is set correctly
646   if (aFunction->GetDriverGUID() != GEOMImpl_CylinderDriver::GetID()) return NULL;
647
648   GEOMImpl_ICylinder aCI (aFunction);
649
650   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
651   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
652
653   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
654
655   aCI.SetPoint(aRefPnt);
656   aCI.SetVector(aRefVec);
657   aCI.SetR(theR);
658   aCI.SetH(theH);
659   aCI.SetA(theA);
660
661   //Compute the Cylinder value
662   try {
663     OCC_CATCH_SIGNALS;
664     if (!GetSolver()->ComputeFunction(aFunction)) {
665       SetErrorCode("Cylinder driver failed");
666       return NULL;
667     }
668   }
669   catch (Standard_Failure) {
670     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
671     SetErrorCode(aFail->GetMessageString());
672     return NULL;
673   }
674
675   //Make a Python command
676   GEOM::TPythonDump(aFunction) << aCylinder << " = geompy.MakeCylinderA("
677     << thePnt << ", " << theVec << ", " << theR << ", " << theH << ", " << theA*180./M_PI << "*math.pi/180.)";
678
679   SetErrorCode(OK);
680   return aCylinder;
681 }
682
683
684 //=============================================================================
685 /*!
686  *  MakeConeR1R2H
687  */
688 //=============================================================================
689 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConeR1R2H (double theR1, double theR2,
690                                                                double theH)
691 {
692   SetErrorCode(KO);
693
694   //Add a new Cone object
695   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
696
697   //Add a new Cone function with R and H parameters
698   Handle(GEOM_Function) aFunction =
699     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_R1_R2_H);
700   if (aFunction.IsNull()) return NULL;
701
702   //Check if the function is set correctly
703   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
704
705   GEOMImpl_ICone aCI (aFunction);
706
707   aCI.SetR1(theR1);
708   aCI.SetR2(theR2);
709   aCI.SetH(theH);
710
711   //Compute the Cone value
712   try {
713     OCC_CATCH_SIGNALS;
714     if (!GetSolver()->ComputeFunction(aFunction)) {
715       SetErrorCode("Cone driver failed");
716       return NULL;
717     }
718   }
719   catch (Standard_Failure) {
720     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
721     SetErrorCode(aFail->GetMessageString());
722     return NULL;
723   }
724
725   //Make a Python command
726   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeConeR1R2H("
727     << theR1 << ", " << theR2 << ", " << theH << ")";
728
729   SetErrorCode(OK);
730   return aCone;
731 }
732
733
734 //=============================================================================
735 /*!
736  *  MakeConePntVecR1R2H
737  */
738 //=============================================================================
739 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeConePntVecR1R2H (Handle(GEOM_Object) thePnt,
740                                                                      Handle(GEOM_Object) theVec,
741                                                                      double theR1, double theR2,
742                                                                      double theH)
743 {
744   SetErrorCode(KO);
745
746   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
747
748   //Add a new Cone object
749   Handle(GEOM_Object) aCone = GetEngine()->AddObject(GetDocID(), GEOM_CONE);
750
751   //Add a new Cone function for creation a cone relatively to point and vector
752   Handle(GEOM_Function) aFunction =
753     aCone->AddFunction(GEOMImpl_ConeDriver::GetID(), CONE_PNT_VEC_R1_R2_H);
754   if (aFunction.IsNull()) return NULL;
755
756   //Check if the function is set correctly
757   if (aFunction->GetDriverGUID() != GEOMImpl_ConeDriver::GetID()) return NULL;
758
759   GEOMImpl_ICone aCI (aFunction);
760
761   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
762   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
763
764   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
765
766   aCI.SetPoint(aRefPnt);
767   aCI.SetVector(aRefVec);
768   aCI.SetR1(theR1);
769   aCI.SetR2(theR2);
770   aCI.SetH(theH);
771
772   //Compute the Cone value
773   try {
774     OCC_CATCH_SIGNALS;
775     if (!GetSolver()->ComputeFunction(aFunction)) {
776       SetErrorCode("Cone driver failed");
777       return NULL;
778     }
779   }
780   catch (Standard_Failure) {
781     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
782     SetErrorCode(aFail->GetMessageString());
783     return NULL;
784   }
785
786   //Make a Python command
787   GEOM::TPythonDump(aFunction) << aCone << " = geompy.MakeCone(" << thePnt
788     << ", " << theVec << ", " << theR1 << ", " << theR2 << ", " << theH << ")";
789
790   SetErrorCode(OK);
791   return aCone;
792 }
793
794
795 //=============================================================================
796 /*!
797  *  MakeSphereR
798  */
799 //=============================================================================
800 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSphereR (double theR)
801 {
802   SetErrorCode(KO);
803
804   //Add a new Sphere object
805   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
806
807   //Add a new Sphere function with R parameter
808   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_R);
809   if (aFunction.IsNull()) return NULL;
810
811   //Check if the function is set correctly
812   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
813
814   GEOMImpl_ISphere aCI (aFunction);
815
816   aCI.SetR(theR);
817
818   //Compute the Sphere value
819   try {
820     OCC_CATCH_SIGNALS;
821     if (!GetSolver()->ComputeFunction(aFunction)) {
822       SetErrorCode("Sphere driver failed");
823       return NULL;
824     }
825   }
826   catch (Standard_Failure) {
827     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
828     SetErrorCode(aFail->GetMessageString());
829     return NULL;
830   }
831
832   //Make a Python command
833   GEOM::TPythonDump(aFunction) << aSphere << " = geompy.MakeSphereR(" << theR << ")";
834
835   SetErrorCode(OK);
836   return aSphere;
837 }
838
839
840 //=============================================================================
841 /*!
842  *  MakeSpherePntR
843  */
844 //=============================================================================
845 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeSpherePntR (Handle(GEOM_Object) thePnt,
846                                                                 double theR)
847 {
848   SetErrorCode(KO);
849
850   if (thePnt.IsNull()) return NULL;
851
852   //Add a new Point object
853   Handle(GEOM_Object) aSphere = GetEngine()->AddObject(GetDocID(), GEOM_SPHERE);
854
855   //Add a new Sphere function for creation a sphere relatively to point
856   Handle(GEOM_Function) aFunction = aSphere->AddFunction(GEOMImpl_SphereDriver::GetID(), SPHERE_PNT_R);
857   if (aFunction.IsNull()) return NULL;
858
859   //Check if the function is set correctly
860   if (aFunction->GetDriverGUID() != GEOMImpl_SphereDriver::GetID()) return NULL;
861
862   GEOMImpl_ISphere aCI (aFunction);
863
864   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
865
866   if (aRefPnt.IsNull()) return NULL;
867
868   aCI.SetPoint(aRefPnt);
869   aCI.SetR(theR);
870
871   //Compute the Sphere value
872   try {
873     OCC_CATCH_SIGNALS;
874     if (!GetSolver()->ComputeFunction(aFunction)) {
875       SetErrorCode("Sphere driver failed");
876       return NULL;
877     }
878   }
879   catch (Standard_Failure) {
880     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
881     SetErrorCode(aFail->GetMessageString());
882     return NULL;
883   }
884
885   //Make a Python command
886   GEOM::TPythonDump(aFunction) << aSphere
887     << " = geompy.MakeSpherePntR(" << thePnt << ", " << theR << ")";
888
889   SetErrorCode(OK);
890   return aSphere;
891 }
892
893
894 //=============================================================================
895 /*!
896  *  MakeTorusRR
897  */
898 //=============================================================================
899 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusRR
900                                            (double theRMajor, double theRMinor)
901 {
902   SetErrorCode(KO);
903
904   //Add a new Torus object
905   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
906
907   //Add a new Torus function
908   Handle(GEOM_Function) aFunction =
909     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_RR);
910   if (aFunction.IsNull()) return NULL;
911
912   //Check if the function is set correctly
913   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
914
915   GEOMImpl_ITorus aCI (aFunction);
916
917   aCI.SetRMajor(theRMajor);
918   aCI.SetRMinor(theRMinor);
919
920   //Compute the Torus value
921   try {
922     OCC_CATCH_SIGNALS;
923     if (!GetSolver()->ComputeFunction(aFunction)) {
924       SetErrorCode("Torus driver failed");
925       return NULL;
926     }
927   }
928   catch (Standard_Failure) {
929     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
930     SetErrorCode(aFail->GetMessageString());
931     return NULL;
932   }
933
934   //Make a Python command
935   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorusRR("
936     << theRMajor << ", " << theRMinor << ")";
937
938   SetErrorCode(OK);
939   return anEll;
940 }
941
942 //=============================================================================
943 /*!
944  *  MakeTorusPntVecRR
945  */
946 //=============================================================================
947 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeTorusPntVecRR
948                        (Handle(GEOM_Object) thePnt, Handle(GEOM_Object) theVec,
949                         double theRMajor, double theRMinor)
950 {
951   SetErrorCode(KO);
952
953   if (thePnt.IsNull() || theVec.IsNull()) return NULL;
954
955   //Add a new Torus object
956   Handle(GEOM_Object) anEll = GetEngine()->AddObject(GetDocID(), GEOM_TORUS);
957
958   //Add a new Torus function
959   Handle(GEOM_Function) aFunction =
960     anEll->AddFunction(GEOMImpl_TorusDriver::GetID(), TORUS_PNT_VEC_RR);
961   if (aFunction.IsNull()) return NULL;
962
963   //Check if the function is set correctly
964   if (aFunction->GetDriverGUID() != GEOMImpl_TorusDriver::GetID()) return NULL;
965
966   GEOMImpl_ITorus aCI (aFunction);
967
968   Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
969   Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
970
971   if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
972
973   aCI.SetCenter(aRefPnt);
974   aCI.SetVector(aRefVec);
975   aCI.SetRMajor(theRMajor);
976   aCI.SetRMinor(theRMinor);
977
978   //Compute the Torus value
979   try {
980     OCC_CATCH_SIGNALS;
981     if (!GetSolver()->ComputeFunction(aFunction)) {
982       SetErrorCode("Torus driver failed");
983       return NULL;
984     }
985   }
986   catch (Standard_Failure) {
987     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
988     SetErrorCode(aFail->GetMessageString());
989     return NULL;
990   }
991
992   //Make a Python command
993   GEOM::TPythonDump(aFunction) << anEll << " = geompy.MakeTorus(" << thePnt
994     << ", " << theVec << ", " << theRMajor << ", " << theRMinor << ")";
995
996   SetErrorCode(OK);
997   return anEll;
998 }
999
1000
1001 //=============================================================================
1002 /*!
1003  *  MakePrismVecH
1004  */
1005 //=============================================================================
1006 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH (Handle(GEOM_Object) theBase,
1007                                                                Handle(GEOM_Object) theVec,
1008                                                                double theH, double theScaleFactor)
1009 {
1010   SetErrorCode(KO);
1011
1012   if (theBase.IsNull() || theVec.IsNull()) return NULL;
1013
1014   //Add a new Prism object
1015   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1016
1017   //Add a new Prism function for creation a Prism relatively to vector
1018   Handle(GEOM_Function) aFunction =
1019     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H);
1020   if (aFunction.IsNull()) return NULL;
1021
1022   //Check if the function is set correctly
1023   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1024
1025   GEOMImpl_IPrism aCI (aFunction);
1026
1027   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1028   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
1029
1030   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
1031
1032   aCI.SetBase(aRefBase);
1033   aCI.SetVector(aRefVec);
1034   aCI.SetH(theH);
1035   aCI.SetScale(theScaleFactor);
1036
1037   //Compute the Prism value
1038   try {
1039     OCC_CATCH_SIGNALS;
1040     if (!GetSolver()->ComputeFunction(aFunction)) {
1041       //SetErrorCode("Prism driver failed");
1042       SetErrorCode("Extrusion can not be created, check input data");
1043       return NULL;
1044     }
1045   }
1046   catch (Standard_Failure) {
1047     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1048     SetErrorCode(aFail->GetMessageString());
1049     return NULL;
1050   }
1051
1052   //Make a Python command
1053   GEOM::TPythonDump pd (aFunction);
1054   pd << aPrism << " = geompy.MakePrismVecH(" << theBase << ", " << theVec << ", " << theH;
1055   if (theScaleFactor > Precision::Confusion())
1056     pd << ", " << theScaleFactor << ")";
1057   else
1058     pd << ")";
1059
1060   SetErrorCode(OK);
1061   return aPrism;
1062 }
1063
1064 //=============================================================================
1065 /*!
1066  *  MakePrismVecH2Ways
1067  */
1068 //=============================================================================
1069 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismVecH2Ways (Handle(GEOM_Object) theBase,
1070                                                                     Handle(GEOM_Object) theVec,
1071                                                                     double theH)
1072 {
1073   SetErrorCode(KO);
1074
1075   if (theBase.IsNull() || theVec.IsNull()) return NULL;
1076
1077   //Add a new Prism object
1078   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1079
1080   //Add a new Prism function for creation a Prism relatively to vector
1081   Handle(GEOM_Function) aFunction =
1082     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_VEC_H_2WAYS);
1083   if (aFunction.IsNull()) return NULL;
1084
1085   //Check if the function is set correctly
1086   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1087
1088   GEOMImpl_IPrism aCI (aFunction);
1089
1090   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1091   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
1092
1093   if (aRefBase.IsNull() || aRefVec.IsNull()) return NULL;
1094
1095   aCI.SetBase(aRefBase);
1096   aCI.SetVector(aRefVec);
1097   aCI.SetH(theH);
1098
1099   //Compute the Prism value
1100   try {
1101     OCC_CATCH_SIGNALS;
1102     if (!GetSolver()->ComputeFunction(aFunction)) {
1103       //SetErrorCode("Prism driver failed");
1104       SetErrorCode("Extrusion can not be created, check input data");
1105       return NULL;
1106     }
1107   }
1108   catch (Standard_Failure) {
1109     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1110     SetErrorCode(aFail->GetMessageString());
1111     return NULL;
1112   }
1113
1114   //Make a Python command
1115   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismVecH2Ways("
1116     << theBase << ", " << theVec << ", " << theH << ")";
1117
1118   SetErrorCode(OK);
1119   return aPrism;
1120 }
1121
1122 //=============================================================================
1123 /*!
1124  *  MakePrismTwoPnt
1125  */
1126 //=============================================================================
1127 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt
1128        (Handle(GEOM_Object) theBase,
1129         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2,
1130         double theScaleFactor)
1131 {
1132   SetErrorCode(KO);
1133
1134   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1135
1136   //Add a new Prism object
1137   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1138
1139   //Add a new Prism function for creation a Prism relatively to two points
1140   Handle(GEOM_Function) aFunction =
1141     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT);
1142   if (aFunction.IsNull()) return NULL;
1143
1144   //Check if the function is set correctly
1145   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1146
1147   GEOMImpl_IPrism aCI (aFunction);
1148
1149   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1150   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
1151   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
1152
1153   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
1154
1155   aCI.SetBase(aRefBase);
1156   aCI.SetFirstPoint(aRefPnt1);
1157   aCI.SetLastPoint(aRefPnt2);
1158   aCI.SetScale(theScaleFactor);
1159
1160   //Compute the Prism value
1161   try {
1162     OCC_CATCH_SIGNALS;
1163     if (!GetSolver()->ComputeFunction(aFunction)) {
1164       //SetErrorCode("Prism driver failed");
1165       SetErrorCode("Extrusion can not be created, check input data");
1166       return NULL;
1167     }
1168   }
1169   catch (Standard_Failure) {
1170     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1171     SetErrorCode(aFail->GetMessageString());
1172     return NULL;
1173   }
1174
1175   //Make a Python command
1176   GEOM::TPythonDump pd (aFunction);
1177   pd << aPrism << " = geompy.MakePrism(" << theBase << ", " << thePoint1 << ", " << thePoint2;
1178   if (theScaleFactor > Precision::Confusion())
1179     pd << ", " << theScaleFactor << ")";
1180   else
1181     pd << ")";
1182
1183   SetErrorCode(OK);
1184   return aPrism;
1185 }
1186
1187 //=============================================================================
1188 /*!
1189  *  MakePrismTwoPnt2Ways
1190  */
1191 //=============================================================================
1192 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismTwoPnt2Ways
1193        (Handle(GEOM_Object) theBase,
1194         Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
1195 {
1196   SetErrorCode(KO);
1197
1198   if (theBase.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1199
1200   //Add a new Prism object
1201   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1202
1203   //Add a new Prism function for creation a Prism relatively to two points
1204   Handle(GEOM_Function) aFunction =
1205     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_TWO_PNT_2WAYS);
1206   if (aFunction.IsNull()) return NULL;
1207
1208   //Check if the function is set correctly
1209   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1210
1211   GEOMImpl_IPrism aCI (aFunction);
1212
1213   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1214   Handle(GEOM_Function) aRefPnt1 = thePoint1->GetLastFunction();
1215   Handle(GEOM_Function) aRefPnt2 = thePoint2->GetLastFunction();
1216
1217   if (aRefBase.IsNull() || aRefPnt1.IsNull() || aRefPnt2.IsNull()) return NULL;
1218
1219   aCI.SetBase(aRefBase);
1220   aCI.SetFirstPoint(aRefPnt1);
1221   aCI.SetLastPoint(aRefPnt2);
1222
1223   //Compute the Prism value
1224   try {
1225     OCC_CATCH_SIGNALS;
1226     if (!GetSolver()->ComputeFunction(aFunction)) {
1227       //SetErrorCode("Prism driver failed");
1228       SetErrorCode("Extrusion can not be created, check input data");
1229       return NULL;
1230     }
1231   }
1232   catch (Standard_Failure) {
1233     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1234     SetErrorCode(aFail->GetMessageString());
1235     return NULL;
1236   }
1237
1238   //Make a Python command
1239   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrism2Ways("
1240     << theBase << ", " << thePoint1 << ", " << thePoint2 << ")";
1241
1242   SetErrorCode(OK);
1243   return aPrism;
1244 }
1245
1246 //=============================================================================
1247 /*!
1248  *  MakePrismDXDYDZ
1249  */
1250 //=============================================================================
1251 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ
1252        (Handle(GEOM_Object) theBase, double theDX, double theDY, double theDZ,
1253         double theScaleFactor)
1254 {
1255   SetErrorCode(KO);
1256
1257   if (theBase.IsNull()) return NULL;
1258
1259   //Add a new Prism object
1260   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1261
1262   //Add a new Prism function for creation a Prism by DXDYDZ
1263   Handle(GEOM_Function) aFunction =
1264     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_DXDYDZ);
1265   if (aFunction.IsNull()) return NULL;
1266
1267   //Check if the function is set correctly
1268   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1269
1270   GEOMImpl_IPrism aCI (aFunction);
1271
1272   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1273
1274   if (aRefBase.IsNull()) return NULL;
1275
1276   aCI.SetBase(aRefBase);
1277   aCI.SetDX(theDX);
1278   aCI.SetDY(theDY);
1279   aCI.SetDZ(theDZ);
1280   aCI.SetScale(theScaleFactor);
1281
1282   //Compute the Prism value
1283   try {
1284     OCC_CATCH_SIGNALS;
1285     if (!GetSolver()->ComputeFunction(aFunction)) {
1286       SetErrorCode("Extrusion can not be created, check input data");
1287       return NULL;
1288     }
1289   }
1290   catch (Standard_Failure) {
1291     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1292     SetErrorCode(aFail->GetMessageString());
1293     return NULL;
1294   }
1295
1296   //Make a Python command
1297   GEOM::TPythonDump pd (aFunction);
1298   pd << aPrism << " = geompy.MakePrismDXDYDZ("
1299      << theBase << ", " << theDX << ", " << theDY << ", " << theDZ;
1300   if (theScaleFactor > Precision::Confusion())
1301     pd << ", " << theScaleFactor << ")";
1302   else
1303     pd << ")";
1304
1305   SetErrorCode(OK);
1306   return aPrism;
1307 }
1308
1309 //=============================================================================
1310 /*!
1311  *  MakePrismDXDYDZ_2WAYS
1312  */
1313 //=============================================================================
1314 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakePrismDXDYDZ2Ways
1315        (Handle(GEOM_Object) theBase, double theDX, double theDY, double theDZ)
1316 {
1317   SetErrorCode(KO);
1318
1319   if (theBase.IsNull()) return NULL;
1320
1321   //Add a new Prism object
1322   Handle(GEOM_Object) aPrism = GetEngine()->AddObject(GetDocID(), GEOM_PRISM);
1323
1324   //Add a new Prism function for creation a Prism by DXDYDZ
1325   Handle(GEOM_Function) aFunction =
1326     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), PRISM_BASE_DXDYDZ_2WAYS);
1327   if (aFunction.IsNull()) return NULL;
1328
1329   //Check if the function is set correctly
1330   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1331
1332   GEOMImpl_IPrism aCI (aFunction);
1333
1334   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1335
1336   if (aRefBase.IsNull()) return NULL;
1337
1338   aCI.SetBase(aRefBase);
1339   aCI.SetDX(theDX);
1340   aCI.SetDY(theDY);
1341   aCI.SetDZ(theDZ);
1342
1343   //Compute the Prism value
1344   try {
1345     OCC_CATCH_SIGNALS;
1346     if (!GetSolver()->ComputeFunction(aFunction)) {
1347       SetErrorCode("Extrusion can not be created, check input data");
1348       return NULL;
1349     }
1350   }
1351   catch (Standard_Failure) {
1352     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1353     SetErrorCode(aFail->GetMessageString());
1354     return NULL;
1355   }
1356
1357   //Make a Python command
1358   GEOM::TPythonDump(aFunction) << aPrism << " = geompy.MakePrismDXDYDZ2Ways("
1359     << theBase << ", " << theDX << ", " << theDY << ", " << theDZ << ")";
1360
1361   SetErrorCode(OK);
1362   return aPrism;
1363 }
1364
1365 //=============================================================================
1366 /*!
1367  *  MakeDraftPrism
1368  */
1369 //=============================================================================
1370 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeDraftPrism
1371        (Handle(GEOM_Object) theInitShape ,Handle(GEOM_Object) theBase, double theHeight, double theAngle, bool theFuse, bool theInvert)
1372 {
1373   SetErrorCode(KO);
1374
1375   if (theBase.IsNull() || theInitShape.IsNull()) return NULL;
1376
1377   Handle(GEOM_Object) aPrism = NULL;
1378   
1379   if ( theFuse )
1380   {
1381     //Add a new Extruded Boss object  
1382     aPrism = GetEngine()->AddObject(GetDocID(), GEOM_EXTRUDED_BOSS);
1383   }
1384   else
1385   { 
1386     //Add a new Extruded Cut object  
1387     aPrism = GetEngine()->AddObject(GetDocID(), GEOM_EXTRUDED_CUT);
1388   }
1389   
1390   //Add a new Prism function for the creation of a Draft Prism feature
1391   Handle(GEOM_Function) aFunction = 
1392     aPrism->AddFunction(GEOMImpl_PrismDriver::GetID(), DRAFT_PRISM_FEATURE);
1393   if (aFunction.IsNull()) return NULL;
1394   
1395   //Check if the function is set correctly
1396   if (aFunction->GetDriverGUID() != GEOMImpl_PrismDriver::GetID()) return NULL;
1397   
1398   GEOMImpl_IPrism aCI (aFunction);
1399
1400   Handle(GEOM_Function) aRefInit = theInitShape->GetLastFunction();
1401   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1402  
1403   if (aRefBase.IsNull() || aRefInit.IsNull()) return NULL;
1404   
1405   // Set parameters 
1406   aCI.SetBase(aRefBase);
1407   aCI.SetInitShape(aRefInit);
1408   aCI.SetH(theHeight);
1409   aCI.SetDraftAngle(theAngle);
1410   if ( theFuse )
1411     aCI.SetFuseFlag(1);
1412   else
1413     aCI.SetFuseFlag(0);
1414   aCI.SetInvertFlag(theInvert);
1415   
1416   //Compute the Draft Prism Feature value
1417   try {
1418     OCC_CATCH_SIGNALS;
1419     if (!GetSolver()->ComputeFunction(aFunction)) {
1420       SetErrorCode("Extrusion can not be created, check input data");
1421       return NULL;
1422     }
1423   }
1424   catch (Standard_Failure) {
1425     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1426     SetErrorCode(aFail->GetMessageString());
1427     return NULL;
1428   }
1429   
1430   //Make a Python command
1431   GEOM::TPythonDump pd (aFunction);
1432   if(theFuse)
1433   {
1434     pd << aPrism << " = geompy.MakeExtrudedBoss(" << theInitShape << ", " << theBase << ", "
1435       << theHeight << ", " << theAngle;
1436   }
1437   else
1438   {   
1439     pd << aPrism << " = geompy.MakeExtrudedCut(" << theInitShape << ", " << theBase << ", "
1440       << theHeight << ", " << theAngle;
1441   }
1442   if (theInvert)
1443     pd << ", " << theInvert;
1444   pd << ")";
1445
1446   SetErrorCode(OK);
1447   return aPrism;
1448 }
1449
1450 //=============================================================================
1451 /*!
1452  *  MakePipe
1453  */
1454 //=============================================================================
1455 Handle(TColStd_HSequenceOfTransient) GEOMImpl_I3DPrimOperations::MakePipe
1456                             (const Handle(GEOM_Object) &theBase,
1457                              const Handle(GEOM_Object) &thePath,
1458                              const bool                 IsGenerateGroups)
1459 {
1460   SetErrorCode(KO);
1461
1462   if (theBase.IsNull() || thePath.IsNull()) return NULL;
1463
1464   //Add a new Pipe object
1465   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1466
1467   //Add a new Pipe function
1468   Handle(GEOM_Function) aFunction =
1469     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BASE_PATH);
1470   if (aFunction.IsNull()) return NULL;
1471
1472   //Check if the function is set correctly
1473   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
1474
1475   GEOMImpl_IPipe aCI (aFunction);
1476
1477   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1478   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1479
1480   if (aRefBase.IsNull() || aRefPath.IsNull()) return NULL;
1481
1482   aCI.SetBase(aRefBase);
1483   aCI.SetPath(aRefPath);
1484   aCI.SetGenerateGroups(IsGenerateGroups);
1485
1486   //Compute the Pipe value
1487   try {
1488     OCC_CATCH_SIGNALS;
1489     if (!GetSolver()->ComputeFunction(aFunction)) {
1490       SetErrorCode("Pipe driver failed");
1491       return NULL;
1492     }
1493   }
1494   catch (Standard_Failure) {
1495     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1496     SetErrorCode(aFail->GetMessageString());
1497     return NULL;
1498   }
1499
1500   // Create the sequence of objects.
1501   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1502
1503   aSeq->Append(aPipe);
1504   createGroups(aPipe, &aCI, aSeq);
1505
1506   //Make a Python command
1507   GEOM::TPythonDump pyDump(aFunction);
1508
1509   if (IsGenerateGroups) {
1510     pyDump << aSeq;
1511   } else {
1512     pyDump << aPipe;
1513   }
1514
1515   pyDump << " = geompy.MakePipe(" << theBase << ", " << thePath;
1516
1517   if (IsGenerateGroups) {
1518     pyDump << ", True";
1519   }
1520
1521   pyDump << ")";
1522
1523   SetErrorCode(OK);
1524   return aSeq;
1525 }
1526
1527
1528 //=============================================================================
1529 /*!
1530  *  MakeRevolutionAxisAngle
1531  */
1532 //=============================================================================
1533 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle (Handle(GEOM_Object) theBase,
1534                                                                          Handle(GEOM_Object) theAxis,
1535                                                                          double theAngle)
1536 {
1537   SetErrorCode(KO);
1538
1539   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
1540
1541   //Add a new Revolution object
1542   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
1543
1544   //Add a new Revolution function for creation a revolution relatively to axis
1545   Handle(GEOM_Function) aFunction =
1546     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE);
1547   if (aFunction.IsNull()) return NULL;
1548
1549   //Check if the function is set correctly
1550   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
1551
1552   GEOMImpl_IRevolution aCI (aFunction);
1553
1554   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1555   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
1556
1557   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
1558
1559   aCI.SetBase(aRefBase);
1560   aCI.SetAxis(aRefAxis);
1561   aCI.SetAngle(theAngle);
1562
1563   //Compute the Revolution value
1564   try {
1565     OCC_CATCH_SIGNALS;
1566     if (!GetSolver()->ComputeFunction(aFunction)) {
1567       SetErrorCode("Revolution driver failed");
1568       return NULL;
1569     }
1570   }
1571   catch (Standard_Failure) {
1572     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1573     SetErrorCode(aFail->GetMessageString());
1574     return NULL;
1575   }
1576
1577   //Make a Python command
1578   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution("
1579     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1580   
1581   SetErrorCode(OK);
1582   return aRevolution;
1583 }
1584
1585 //=============================================================================
1586 /*!
1587  *  MakeRevolutionAxisAngle2Ways
1588  */
1589 //=============================================================================
1590 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeRevolutionAxisAngle2Ways
1591                    (Handle(GEOM_Object) theBase, Handle(GEOM_Object) theAxis, double theAngle)
1592 {
1593   SetErrorCode(KO);
1594
1595   if (theBase.IsNull() || theAxis.IsNull()) return NULL;
1596
1597   //Add a new Revolution object
1598   Handle(GEOM_Object) aRevolution = GetEngine()->AddObject(GetDocID(), GEOM_REVOLUTION);
1599
1600   //Add a new Revolution function for creation a revolution relatively to axis
1601   Handle(GEOM_Function) aFunction =
1602     aRevolution->AddFunction(GEOMImpl_RevolutionDriver::GetID(), REVOLUTION_BASE_AXIS_ANGLE_2WAYS);
1603   if (aFunction.IsNull()) return NULL;
1604
1605   //Check if the function is set correctly
1606   if (aFunction->GetDriverGUID() != GEOMImpl_RevolutionDriver::GetID()) return NULL;
1607
1608   GEOMImpl_IRevolution aCI (aFunction);
1609
1610   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
1611   Handle(GEOM_Function) aRefAxis = theAxis->GetLastFunction();
1612
1613   if (aRefBase.IsNull() || aRefAxis.IsNull()) return NULL;
1614
1615   aCI.SetBase(aRefBase);
1616   aCI.SetAxis(aRefAxis);
1617   aCI.SetAngle(theAngle);
1618
1619   //Compute the Revolution value
1620   try {
1621     OCC_CATCH_SIGNALS;
1622     if (!GetSolver()->ComputeFunction(aFunction)) {
1623       SetErrorCode("Revolution driver failed");
1624       return NULL;
1625     }
1626   }
1627   catch (Standard_Failure) {
1628     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1629     SetErrorCode(aFail->GetMessageString());
1630     return NULL;
1631   }
1632
1633   //Make a Python command
1634   GEOM::TPythonDump(aFunction) << aRevolution << " = geompy.MakeRevolution2Ways("
1635     << theBase << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1636
1637   SetErrorCode(OK);
1638   return aRevolution;
1639 }
1640
1641 //=============================================================================
1642 /*!
1643  *  MakeFilling
1644  */
1645 //=============================================================================
1646 Handle(GEOM_Object)
1647 GEOMImpl_I3DPrimOperations::MakeFilling (std::list< Handle(GEOM_Object)> & theContours,
1648                                          int theMinDeg, int theMaxDeg,
1649                                          double theTol2D, double theTol3D, int theNbIter,
1650                                          int theMethod, bool isApprox)
1651 {
1652   SetErrorCode(KO);
1653
1654   Handle(TColStd_HSequenceOfTransient) contours = GEOM_Object::GetLastFunctions( theContours );
1655   if ( contours.IsNull() || contours->IsEmpty() ) {
1656     SetErrorCode("NULL argument shape");
1657     return NULL;
1658   }
1659   //Add a new Filling object
1660   Handle(GEOM_Object) aFilling = GetEngine()->AddObject(GetDocID(), GEOM_FILLING);
1661
1662   //Add a new Filling function for creation a filling  from a compound
1663   Handle(GEOM_Function) aFunction = aFilling->AddFunction(GEOMImpl_FillingDriver::GetID(), BASIC_FILLING);
1664   if (aFunction.IsNull()) return NULL;
1665
1666   //Check if the function is set correctly
1667   if (aFunction->GetDriverGUID() != GEOMImpl_FillingDriver::GetID()) return NULL;
1668
1669   GEOMImpl_IFilling aFI (aFunction);
1670   aFI.SetShapes(contours);
1671   aFI.SetMinDeg(theMinDeg);
1672   aFI.SetMaxDeg(theMaxDeg);
1673   aFI.SetTol2D(theTol2D);
1674   aFI.SetTol3D(theTol3D);
1675   aFI.SetNbIter(theNbIter);
1676   aFI.SetApprox(isApprox);
1677   aFI.SetMethod(theMethod);
1678
1679   //Compute the Solid value
1680   try {
1681     OCC_CATCH_SIGNALS;
1682     if (!GetSolver()->ComputeFunction(aFunction)) {
1683       SetErrorCode("Filling driver failed");
1684       return NULL;
1685     }
1686   }
1687   catch (Standard_Failure) {
1688     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1689     if (strcmp(aFail->GetMessageString(), "Geom_BSplineSurface") == 0)
1690       SetErrorCode("B-Spline surface construction failed");
1691     else
1692       SetErrorCode(aFail->GetMessageString());
1693     return NULL;
1694   }
1695
1696   //Make a Python command
1697   GEOM::TPythonDump pd (aFunction);
1698   pd << aFilling << " = geompy.MakeFilling(" << theContours ;
1699   if ( theMinDeg != 2 )   pd << ", theMinDeg=" << theMinDeg ;
1700   if ( theMaxDeg != 5 )   pd << ", theMaxDeg=" << theMaxDeg ;
1701   if ( fabs(theTol2D-0.0001) > Precision::Confusion() )
1702   {                       pd << ", theTol2D=" << theTol2D ; }
1703   if ( fabs(theTol3D-0.0001) > Precision::Confusion() )
1704   {                       pd << ", theTol3D=" << theTol3D ; }
1705   if ( theNbIter != 0 )   pd << ", theNbIter=" << theNbIter ;
1706   if ( theMethod==1 )     pd << ", theMethod=GEOM.FOM_UseOri";
1707   else if( theMethod==2 ) pd << ", theMethod=GEOM.FOM_AutoCorrect";
1708   if ( isApprox )         pd << ", isApprox=" << isApprox ;
1709   pd << ")";
1710
1711   SetErrorCode(OK);
1712   return aFilling;
1713 }
1714
1715 //=============================================================================
1716 /*!
1717  *  MakeThruSections
1718  */
1719 //=============================================================================
1720 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThruSections(
1721                                                 const Handle(TColStd_HSequenceOfTransient)& theSeqSections,
1722                                                 bool theModeSolid,
1723                                                 double thePreci,
1724                                                 bool theRuled)
1725 {
1726   Handle(GEOM_Object) anObj;
1727   SetErrorCode(KO);
1728   if(theSeqSections.IsNull())
1729     return anObj;
1730
1731   Standard_Integer nbObj = theSeqSections->Length();
1732   if (!nbObj)
1733     return anObj;
1734
1735   //Add a new ThruSections object
1736   Handle(GEOM_Object) aThruSect = GetEngine()->AddObject(GetDocID(), GEOM_THRUSECTIONS);
1737
1738
1739   //Add a new ThruSections function
1740
1741   int aTypeFunc = (theRuled ? THRUSECTIONS_RULED : THRUSECTIONS_SMOOTHED);
1742   Handle(GEOM_Function) aFunction =
1743     aThruSect->AddFunction(GEOMImpl_ThruSectionsDriver::GetID(), aTypeFunc);
1744   if (aFunction.IsNull()) return anObj;
1745
1746   //Check if the function is set correctly
1747   if (aFunction->GetDriverGUID() != GEOMImpl_ThruSectionsDriver::GetID()) return NULL;
1748
1749   GEOMImpl_IThruSections aCI (aFunction);
1750
1751   Handle(TColStd_HSequenceOfTransient) aSeqSections = new TColStd_HSequenceOfTransient;
1752
1753   Standard_Integer i =1;
1754   for( ; i <= nbObj; i++) {
1755
1756     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1757     if(anItem.IsNull())
1758       continue;
1759
1760     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1761     if(!aSectObj.IsNull())
1762     {
1763       Handle(GEOM_Function) aRefSect = aSectObj->GetLastFunction();
1764       if(!aRefSect.IsNull())
1765         aSeqSections->Append(aRefSect);
1766     }
1767   }
1768
1769   if(!aSeqSections->Length())
1770     return anObj;
1771
1772   aCI.SetSections(aSeqSections);
1773   aCI.SetSolidMode(theModeSolid);
1774   aCI.SetPrecision(thePreci);
1775
1776   //Compute the ThruSections value
1777   try {
1778     OCC_CATCH_SIGNALS;
1779     if (!GetSolver()->ComputeFunction(aFunction)) {
1780       SetErrorCode("ThruSections driver failed");
1781       return anObj;
1782     }
1783   }
1784   catch (Standard_Failure) {
1785     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1786     SetErrorCode(aFail->GetMessageString());
1787     return anObj;
1788   }
1789
1790   //Make a Python command
1791   GEOM::TPythonDump pyDump(aFunction);
1792   pyDump << aThruSect << " = geompy.MakeThruSections([";
1793
1794   for(i =1 ; i <= nbObj; i++) {
1795
1796     Handle(Standard_Transient) anItem = theSeqSections->Value(i);
1797     if(anItem.IsNull())
1798       continue;
1799
1800     Handle(GEOM_Object) aSectObj = Handle(GEOM_Object)::DownCast(anItem);
1801     if(!aSectObj.IsNull()) {
1802       pyDump<< aSectObj;
1803       if(i < nbObj)
1804         pyDump<<", ";
1805     }
1806   }
1807
1808   pyDump<< "],"<<theModeSolid << "," << thePreci <<","<< theRuled <<")";
1809
1810   SetErrorCode(OK);
1811   return aThruSect;
1812 }
1813
1814
1815 //=============================================================================
1816 /*!
1817  *  MakePipeWithDifferentSections
1818  */
1819 //=============================================================================
1820 Handle(TColStd_HSequenceOfTransient)
1821   GEOMImpl_I3DPrimOperations::MakePipeWithDifferentSections
1822               (const Handle(TColStd_HSequenceOfTransient) &theBases,
1823                const Handle(TColStd_HSequenceOfTransient) &theLocations,
1824                const Handle(GEOM_Object)                  &thePath,
1825                const bool                                  theWithContact,
1826                const bool                                  theWithCorrections,
1827                const bool                                  IsBySteps,
1828                const bool                                  IsGenerateGroups)
1829 {
1830   SetErrorCode(KO);
1831   if(theBases.IsNull())
1832     return NULL;
1833
1834   Standard_Integer nbBases = theBases->Length();
1835
1836   if (!nbBases)
1837     return NULL;
1838
1839   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
1840   //Add a new Pipe object
1841   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
1842
1843   //Add a new Pipe function
1844
1845   Handle(GEOM_Function) aFunction =
1846     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_DIFFERENT_SECTIONS);
1847   if (aFunction.IsNull()) return NULL;
1848
1849   //Check if the function is set correctly
1850   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
1851
1852   GEOMImpl_IPipeDiffSect aCI (aFunction);
1853
1854   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
1855   if(aRefPath.IsNull())
1856     return NULL;
1857
1858   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
1859   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
1860
1861   Standard_Integer i =1;
1862   for( ; i <= nbBases; i++) {
1863
1864     Handle(Standard_Transient) anItem = theBases->Value(i);
1865     if(anItem.IsNull())
1866       continue;
1867
1868     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
1869     if(aBase.IsNull())
1870       continue;
1871     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
1872     if(aRefBase.IsNull())
1873       continue;
1874     if(nbLocs)
1875     {
1876       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
1877       if(anItemLoc.IsNull())
1878         continue;
1879
1880       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
1881       if(aLoc.IsNull())
1882         continue;
1883       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
1884       if(aRefLoc.IsNull())
1885         continue;
1886       aSeqLocs->Append(aRefLoc);
1887     }
1888     aSeqBases->Append(aRefBase);
1889   }
1890
1891   if(!aSeqBases->Length())
1892     return NULL;
1893
1894   aCI.SetBases(aSeqBases);
1895   aCI.SetLocations(aSeqLocs);
1896   aCI.SetPath(aRefPath);
1897
1898   if (!IsBySteps) {
1899     aCI.SetWithContactMode(theWithContact);
1900     aCI.SetWithCorrectionMode(theWithCorrections);
1901   }
1902
1903   aCI.SetIsBySteps(IsBySteps);
1904   aCI.SetGenerateGroups(IsGenerateGroups);
1905
1906   //Compute the Pipe value
1907   try {
1908     OCC_CATCH_SIGNALS;
1909     if (!GetSolver()->ComputeFunction(aFunction)) {
1910       SetErrorCode("Pipe with defferent section driver failed");
1911       return NULL;
1912     }
1913   }
1914   catch (Standard_Failure) {
1915     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1916     SetErrorCode(aFail->GetMessageString());
1917     return NULL;
1918   }
1919
1920   // Create the sequence of objects.
1921   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1922
1923   aSeq->Append(aPipeDS);
1924   createGroups(aPipeDS, &aCI, aSeq);
1925
1926   //Make a Python command
1927   GEOM::TPythonDump pyDump(aFunction);
1928
1929   if (IsGenerateGroups) {
1930     pyDump << aSeq;
1931   } else {
1932     pyDump << aPipeDS;
1933   }
1934
1935   if (IsBySteps) {
1936     pyDump << " = geompy.MakePipeWithDifferentSectionsBySteps([";
1937   } else {
1938     pyDump << " = geompy.MakePipeWithDifferentSections([";
1939   }
1940
1941   for(i =1 ; i <= nbBases; i++) {
1942
1943     Handle(Standard_Transient) anItem = theBases->Value(i);
1944     if(anItem.IsNull())
1945       continue;
1946
1947     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1948     if(!anObj.IsNull()) {
1949       pyDump<< anObj;
1950       if(i < nbBases)
1951         pyDump<<", ";
1952     }
1953   }
1954
1955   pyDump<< "], [";
1956
1957   for(i =1 ; i <= nbLocs; i++) {
1958
1959     Handle(Standard_Transient) anItem = theLocations->Value(i);
1960     if(anItem.IsNull())
1961       continue;
1962
1963     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
1964     if(!anObj.IsNull()) {
1965       pyDump<< anObj;
1966       if(i < nbLocs)
1967         pyDump<<", ";
1968     }
1969   }
1970
1971   pyDump<< "], "<<thePath;
1972
1973   if (!IsBySteps) {
1974     pyDump<<","<<theWithContact << "," << theWithCorrections;
1975   }
1976
1977   if (IsGenerateGroups) {
1978     pyDump << ", True";
1979   }
1980
1981   pyDump << ")";
1982
1983   SetErrorCode(OK);
1984   return aSeq;
1985 }
1986
1987
1988 //=============================================================================
1989 /*!
1990  *  MakePipeWithShellSections
1991  */
1992 //=============================================================================
1993 Handle(TColStd_HSequenceOfTransient)
1994       GEOMImpl_I3DPrimOperations::MakePipeWithShellSections
1995               (const Handle(TColStd_HSequenceOfTransient) &theBases,
1996                const Handle(TColStd_HSequenceOfTransient) &theSubBases,
1997                const Handle(TColStd_HSequenceOfTransient) &theLocations,
1998                const Handle(GEOM_Object)                  &thePath,
1999                const bool                                  theWithContact,
2000                const bool                                  theWithCorrections,
2001                const bool                                  IsGenerateGroups)
2002 {
2003   SetErrorCode(KO);
2004   if(theBases.IsNull())
2005     return NULL;
2006
2007   Standard_Integer nbBases = theBases->Length();
2008
2009   if (!nbBases)
2010     return NULL;
2011
2012   Standard_Integer nbSubBases =  (theSubBases.IsNull() ? 0 :theSubBases->Length());
2013
2014   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
2015
2016   //Add a new Pipe object
2017   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
2018
2019   //Add a new Pipe function
2020
2021   Handle(GEOM_Function) aFunction =
2022     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELL_SECTIONS);
2023   if (aFunction.IsNull()) return NULL;
2024
2025   //Check if the function is set correctly
2026   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
2027
2028   //GEOMImpl_IPipeDiffSect aCI (aFunction);
2029   GEOMImpl_IPipeShellSect aCI (aFunction);
2030
2031   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
2032   if(aRefPath.IsNull())
2033     return NULL;
2034
2035   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
2036   Handle(TColStd_HSequenceOfTransient) aSeqSubBases = new TColStd_HSequenceOfTransient;
2037   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
2038
2039   Standard_Integer i =1;
2040   for( ; i <= nbBases; i++) {
2041
2042     Handle(Standard_Transient) anItem = theBases->Value(i);
2043     if(anItem.IsNull())
2044       continue;
2045     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2046     if(aBase.IsNull())
2047       continue;
2048     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2049     if(aRefBase.IsNull())
2050       continue;
2051
2052     if( nbSubBases >= nbBases ) {
2053       Handle(Standard_Transient) aSubItem = theSubBases->Value(i);
2054       if(aSubItem.IsNull())
2055         continue;
2056       Handle(GEOM_Object) aSubBase = Handle(GEOM_Object)::DownCast(aSubItem);
2057       if(aSubBase.IsNull())
2058         continue;
2059       Handle(GEOM_Function) aRefSubBase = aSubBase->GetLastFunction();
2060       if(aRefSubBase.IsNull())
2061         continue;
2062       aSeqSubBases->Append(aRefSubBase);
2063     }
2064
2065     if(nbLocs) {
2066       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
2067       if(anItemLoc.IsNull())
2068         continue;
2069       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
2070       if(aLoc.IsNull())
2071         continue;
2072       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
2073       if(aRefLoc.IsNull())
2074         continue;
2075       aSeqLocs->Append(aRefLoc);
2076     }
2077
2078     aSeqBases->Append(aRefBase);
2079   }
2080
2081   if(!aSeqBases->Length())
2082     return NULL;
2083
2084   aCI.SetBases(aSeqBases);
2085   aCI.SetSubBases(aSeqSubBases);
2086   aCI.SetLocations(aSeqLocs);
2087   aCI.SetPath(aRefPath);
2088   aCI.SetWithContactMode(theWithContact);
2089   aCI.SetWithCorrectionMode(theWithCorrections);
2090   aCI.SetGenerateGroups(IsGenerateGroups);
2091
2092   //Compute the Pipe value
2093   try {
2094     OCC_CATCH_SIGNALS;
2095     if (!GetSolver()->ComputeFunction(aFunction)) {
2096       SetErrorCode("Pipe with shell sections driver failed");
2097       return NULL;
2098     }
2099   }
2100   catch (Standard_Failure) {
2101     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2102     SetErrorCode(aFail->GetMessageString());
2103     return NULL;
2104   }
2105
2106   // Create the sequence of objects.
2107   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2108
2109   aSeq->Append(aPipeDS);
2110   createGroups(aPipeDS, &aCI, aSeq);
2111
2112   //Make a Python command
2113   GEOM::TPythonDump pyDump(aFunction);
2114
2115   if (IsGenerateGroups) {
2116     pyDump << aSeq;
2117   } else {
2118     pyDump << aPipeDS;
2119   }
2120
2121   pyDump << " = geompy.MakePipeWithShellSections([";
2122
2123   for(i =1 ; i <= nbBases; i++) {
2124
2125     Handle(Standard_Transient) anItem = theBases->Value(i);
2126     if(anItem.IsNull())
2127       continue;
2128
2129     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2130     if(!anObj.IsNull()) {
2131       pyDump<< anObj;
2132       if(i < nbBases)
2133         pyDump<<", ";
2134     }
2135   }
2136
2137   pyDump<< "], [";
2138
2139   for(i =1 ; i <= nbSubBases; i++) {
2140
2141     Handle(Standard_Transient) anItem = theSubBases->Value(i);
2142     if(anItem.IsNull())
2143       continue;
2144
2145     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2146     if(!anObj.IsNull()) {
2147       pyDump<< anObj;
2148       if(i < nbBases)
2149         pyDump<<", ";
2150     }
2151   }
2152
2153   pyDump<< "], [";
2154
2155   for(i =1 ; i <= nbLocs; i++) {
2156
2157     Handle(Standard_Transient) anItem = theLocations->Value(i);
2158     if(anItem.IsNull())
2159       continue;
2160
2161     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2162     if(!anObj.IsNull()) {
2163       pyDump<< anObj;
2164       if(i < nbLocs)
2165         pyDump<<", ";
2166     }
2167   }
2168
2169   pyDump<< "], "<<thePath<<","<<theWithContact << "," << theWithCorrections;
2170
2171   if (IsGenerateGroups) {
2172     pyDump << ", True";
2173   }
2174
2175   pyDump << ")";
2176
2177   SetErrorCode(OK);
2178   return aSeq;
2179
2180 }
2181
2182
2183 //=============================================================================
2184 /*!
2185  *  MakePipeShellsWithoutPath
2186  */
2187 //=============================================================================
2188 Handle(TColStd_HSequenceOfTransient)
2189       GEOMImpl_I3DPrimOperations::MakePipeShellsWithoutPath
2190               (const Handle(TColStd_HSequenceOfTransient) &theBases,
2191                const Handle(TColStd_HSequenceOfTransient) &theLocations,
2192                const bool                                  IsGenerateGroups)
2193 {
2194   SetErrorCode(KO);
2195   if(theBases.IsNull())
2196     return NULL;
2197
2198   Standard_Integer nbBases = theBases->Length();
2199
2200   if (!nbBases)
2201     return NULL;
2202
2203   Standard_Integer nbLocs =  (theLocations.IsNull() ? 0 :theLocations->Length());
2204
2205   //Add a new Pipe object
2206   Handle(GEOM_Object) aPipeDS = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
2207
2208   //Add a new Pipe function
2209
2210   Handle(GEOM_Function) aFunction =
2211     aPipeDS->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_SHELLS_WITHOUT_PATH);
2212   if (aFunction.IsNull()) return NULL;
2213
2214   //Check if the function is set correctly
2215   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
2216
2217   GEOMImpl_IPipeShellSect aCI (aFunction);
2218
2219   Handle(TColStd_HSequenceOfTransient) aSeqBases = new TColStd_HSequenceOfTransient;
2220   Handle(TColStd_HSequenceOfTransient) aSeqLocs = new TColStd_HSequenceOfTransient;
2221
2222   Standard_Integer i =1;
2223   for( ; i <= nbBases; i++) {
2224
2225     Handle(Standard_Transient) anItem = theBases->Value(i);
2226     if(anItem.IsNull())
2227       continue;
2228     Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2229     if(aBase.IsNull())
2230       continue;
2231     Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2232     if(aRefBase.IsNull())
2233       continue;
2234
2235     if(nbLocs) {
2236       Handle(Standard_Transient) anItemLoc = theLocations->Value(i);
2237       if(anItemLoc.IsNull())
2238         continue;
2239       Handle(GEOM_Object) aLoc = Handle(GEOM_Object)::DownCast(anItemLoc);
2240       if(aLoc.IsNull())
2241         continue;
2242       Handle(GEOM_Function) aRefLoc = aLoc->GetLastFunction();
2243       if(aRefLoc.IsNull())
2244         continue;
2245       aSeqLocs->Append(aRefLoc);
2246     }
2247
2248     aSeqBases->Append(aRefBase);
2249   }
2250
2251   if(!aSeqBases->Length())
2252     return NULL;
2253
2254   aCI.SetBases(aSeqBases);
2255   aCI.SetLocations(aSeqLocs);
2256   aCI.SetGenerateGroups(IsGenerateGroups);
2257
2258   //Compute the Pipe value
2259   try {
2260     OCC_CATCH_SIGNALS;
2261     if (!GetSolver()->ComputeFunction(aFunction)) {
2262       SetErrorCode("Pipe with shell sections without path driver failed");
2263       return NULL;
2264     }
2265   }
2266   catch (Standard_Failure) {
2267     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2268     SetErrorCode(aFail->GetMessageString());
2269     return NULL;
2270   }
2271
2272   // Create the sequence of objects.
2273   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2274
2275   aSeq->Append(aPipeDS);
2276   createGroups(aPipeDS, &aCI, aSeq);
2277
2278   //Make a Python command
2279   GEOM::TPythonDump pyDump(aFunction);
2280
2281   if (IsGenerateGroups) {
2282     pyDump << aSeq;
2283   } else {
2284     pyDump << aPipeDS;
2285   }
2286
2287   pyDump << " = geompy.MakePipeShellsWithoutPath([";
2288
2289   for(i =1 ; i <= nbBases; i++) {
2290
2291     Handle(Standard_Transient) anItem = theBases->Value(i);
2292     if(anItem.IsNull())
2293       continue;
2294
2295     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2296     if(!anObj.IsNull()) {
2297       pyDump<< anObj;
2298       if(i < nbBases)
2299         pyDump<<", ";
2300     }
2301   }
2302
2303   pyDump<< "], [";
2304
2305   for(i =1 ; i <= nbLocs; i++) {
2306
2307     Handle(Standard_Transient) anItem = theLocations->Value(i);
2308     if(anItem.IsNull())
2309       continue;
2310
2311     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(anItem);
2312     if(!anObj.IsNull()) {
2313       pyDump<< anObj;
2314       if(i < nbLocs)
2315         pyDump<<", ";
2316     }
2317   }
2318
2319   pyDump<< "]";
2320
2321   if (IsGenerateGroups) {
2322     pyDump << ", True";
2323   }
2324
2325   pyDump << ")";
2326
2327   SetErrorCode(OK);
2328   return aSeq;
2329
2330 }
2331
2332 //=============================================================================
2333 /*!
2334  *  MakePipeBiNormalAlongVector
2335  */
2336 //=============================================================================
2337 Handle(TColStd_HSequenceOfTransient)
2338   GEOMImpl_I3DPrimOperations::MakePipeBiNormalAlongVector
2339                 (const Handle(GEOM_Object) &theBase,
2340                  const Handle(GEOM_Object) &thePath,
2341                  const Handle(GEOM_Object) &theVec,
2342                  const bool                 IsGenerateGroups)
2343 {
2344   SetErrorCode(KO);
2345
2346   if (theBase.IsNull() || thePath.IsNull() || theVec.IsNull()) return NULL;
2347
2348   //Add a new Pipe object
2349   Handle(GEOM_Object) aPipe = GetEngine()->AddObject(GetDocID(), GEOM_PIPE);
2350
2351   //Add a new Pipe function
2352   Handle(GEOM_Function) aFunction =
2353     aPipe->AddFunction(GEOMImpl_PipeDriver::GetID(), PIPE_BI_NORMAL_ALONG_VECTOR);
2354   if (aFunction.IsNull()) return NULL;
2355
2356   //Check if the function is set correctly
2357   if (aFunction->GetDriverGUID() != GEOMImpl_PipeDriver::GetID()) return NULL;
2358
2359   GEOMImpl_IPipeBiNormal aCI (aFunction);
2360
2361   Handle(GEOM_Function) aRefBase = theBase->GetLastFunction();
2362   Handle(GEOM_Function) aRefPath = thePath->GetLastFunction();
2363   Handle(GEOM_Function) aRefVec  = theVec->GetLastFunction();
2364
2365   if (aRefBase.IsNull() || aRefPath.IsNull() || aRefVec.IsNull()) return NULL;
2366
2367   aCI.SetBase(aRefBase);
2368   aCI.SetPath(aRefPath);
2369   aCI.SetVector(aRefVec);
2370   aCI.SetGenerateGroups(IsGenerateGroups);
2371
2372   //Compute the Pipe value
2373   try {
2374     OCC_CATCH_SIGNALS;
2375     if (!GetSolver()->ComputeFunction(aFunction)) {
2376       SetErrorCode("Pipe driver failed");
2377       return NULL;
2378     }
2379   }
2380   catch (Standard_Failure) {
2381     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2382     SetErrorCode(aFail->GetMessageString());
2383     return NULL;
2384   }
2385
2386   // Create the sequence of objects.
2387   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2388
2389   aSeq->Append(aPipe);
2390   createGroups(aPipe, &aCI, aSeq);
2391
2392   //Make a Python command
2393   GEOM::TPythonDump pyDump(aFunction);
2394
2395   if (IsGenerateGroups) {
2396     pyDump << aSeq;
2397   } else {
2398     pyDump << aPipe;
2399   }
2400
2401   pyDump << " = geompy.MakePipeBiNormalAlongVector("
2402          << theBase << ", " << thePath << ", " << theVec;
2403
2404   if (IsGenerateGroups) {
2405     pyDump << ", True";
2406   }
2407
2408   pyDump << ")";
2409
2410   SetErrorCode(OK);
2411   return aSeq;
2412 }
2413
2414 //=============================================================================
2415 /*!
2416  *  MakeThickening
2417  */
2418 //=============================================================================
2419 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::MakeThickening
2420                 (Handle(GEOM_Object)                     theObject,
2421                  const Handle(TColStd_HArray1OfInteger) &theFacesIDs,
2422                  double                                  theOffset,
2423                  bool                                    isCopy,
2424                  bool                                    theInside)
2425 {
2426   SetErrorCode(KO);
2427
2428   if (theObject.IsNull()) return NULL;
2429
2430   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
2431   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
2432
2433   //Add a new Offset function
2434   Handle(GEOM_Function) aFunction;
2435   Handle(GEOM_Object) aCopy; 
2436   if (isCopy)
2437   { 
2438     //Add a new Copy object
2439     aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
2440     aFunction = aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_THICKENING_COPY);
2441   }
2442   else
2443     aFunction = theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_THICKENING);
2444   
2445   if (aFunction.IsNull()) return NULL;
2446
2447   //Check if the function is set correctly
2448   if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
2449
2450   GEOMImpl_IOffset aTI (aFunction);
2451   aTI.SetShape(anOriginal);
2452   aTI.SetValue(theOffset);
2453   aTI.SetParam(theInside);
2454
2455   if (theFacesIDs.IsNull() == Standard_False) {
2456     aTI.SetFaceIDs(theFacesIDs);
2457   }
2458
2459   //Compute the offset
2460   try {
2461     OCC_CATCH_SIGNALS;
2462     if (!GetSolver()->ComputeFunction(aFunction)) {
2463       SetErrorCode("Offset driver failed");
2464       return NULL;
2465     }
2466   }
2467   catch (Standard_Failure) {
2468     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2469     SetErrorCode(aFail->GetMessageString());
2470     return NULL;
2471   }
2472
2473   //Make a Python command
2474   GEOM::TPythonDump   pd (aFunction);
2475   Handle(GEOM_Object) aResult; 
2476
2477   if (isCopy) {
2478     pd << aCopy << " = geompy.MakeThickSolid("
2479        << theObject << ", " << theOffset;
2480     aResult = aCopy;
2481   } else {
2482     pd << "geompy.Thicken(" << theObject << ", " << theOffset;
2483     aResult = theObject;
2484   }
2485
2486   pd << ", [";
2487   if (theFacesIDs.IsNull() == Standard_False) {
2488     // Dump faces IDs.
2489     Standard_Integer i;
2490
2491     for (i = theFacesIDs->Lower(); i < theFacesIDs->Upper(); ++i) {
2492       pd << theFacesIDs->Value(i) << ", ";
2493     }
2494     // Dump the last value.
2495     pd << theFacesIDs->Value(i);
2496   }
2497   pd << "]";
2498
2499   if (theInside)
2500     pd << ", " << theInside;
2501
2502   pd << ")";
2503   SetErrorCode(OK);
2504
2505   return aResult;
2506 }
2507
2508 //=============================================================================
2509 /*!
2510  *  RestorePath
2511  */
2512 //=============================================================================
2513 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath (Handle(GEOM_Object) theShape,
2514                                                              Handle(GEOM_Object) theBase1,
2515                                                              Handle(GEOM_Object) theBase2)
2516 {
2517   SetErrorCode(KO);
2518
2519   if (theShape.IsNull() || theBase1.IsNull() || theBase2.IsNull()) return NULL;
2520
2521   // Add a new Path object
2522   Handle(GEOM_Object) aPath = GetEngine()->AddObject(GetDocID(), GEOM_PIPE_PATH);
2523
2524   // Add a new Path function
2525   Handle(GEOM_Function) aFunction =
2526     aPath->AddFunction(GEOMImpl_PipePathDriver::GetID(), PIPE_PATH_TWO_BASES);
2527   if (aFunction.IsNull()) return NULL;
2528
2529   // Check if the function is set correctly
2530   if (aFunction->GetDriverGUID() != GEOMImpl_PipePathDriver::GetID()) return NULL;
2531
2532   GEOMImpl_IPipePath aCI (aFunction);
2533
2534   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2535   Handle(GEOM_Function) aRefBase1 = theBase1->GetLastFunction();
2536   Handle(GEOM_Function) aRefBase2 = theBase2->GetLastFunction();
2537
2538   if (aRefShape.IsNull() || aRefBase1.IsNull() || aRefBase2.IsNull()) return NULL;
2539
2540   aCI.SetShape(aRefShape);
2541   aCI.SetBase1(aRefBase1);
2542   aCI.SetBase2(aRefBase2);
2543
2544   // Compute the Path value
2545   try {
2546     OCC_CATCH_SIGNALS;
2547     if (!GetSolver()->ComputeFunction(aFunction)) {
2548       SetErrorCode("PipePath driver failed");
2549       return NULL;
2550     }
2551   }
2552   catch (Standard_Failure) {
2553     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2554     SetErrorCode("RestorePath: inappropriate arguments given");
2555     return NULL;
2556   }
2557
2558   // Make a Python command
2559   GEOM::TPythonDump(aFunction) << aPath << " = geompy.RestorePath("
2560     << theShape << ", " << theBase1 << ", " << theBase2 << ")";
2561
2562   SetErrorCode(OK);
2563   return aPath;
2564 }
2565
2566 //=============================================================================
2567 /*!
2568  *  RestorePath
2569  */
2570 //=============================================================================
2571 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath
2572                          (Handle(GEOM_Object) theShape,
2573                           const Handle(TColStd_HSequenceOfTransient)& theBase1,
2574                           const Handle(TColStd_HSequenceOfTransient)& theBase2)
2575 {
2576   SetErrorCode(KO);
2577
2578   if (theShape.IsNull() || theBase1.IsNull() || theBase2.IsNull()) return NULL;
2579
2580   Standard_Integer nbBases1 = theBase1->Length();
2581   Standard_Integer nbBases2 = theBase2->Length();
2582
2583   if (!nbBases1 || !nbBases2)
2584     return NULL;
2585
2586   // Add a new Path object
2587   Handle(GEOM_Object) aPath = GetEngine()->AddObject(GetDocID(), GEOM_PIPE_PATH);
2588
2589   // Add a new Path function
2590   Handle(GEOM_Function) aFunction =
2591     aPath->AddFunction(GEOMImpl_PipePathDriver::GetID(), PIPE_PATH_TWO_SEQS);
2592   if (aFunction.IsNull()) return NULL;
2593
2594   // Check if the function is set correctly
2595   if (aFunction->GetDriverGUID() != GEOMImpl_PipePathDriver::GetID()) return NULL;
2596
2597   GEOMImpl_IPipePath aCI (aFunction);
2598
2599   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
2600   if (aRefShape.IsNull()) return NULL;
2601
2602   Handle(TColStd_HSequenceOfTransient) aSeqBases1 = new TColStd_HSequenceOfTransient;
2603   Handle(TColStd_HSequenceOfTransient) aSeqBases2 = new TColStd_HSequenceOfTransient;
2604
2605   Standard_Integer i;
2606   for (i = 1; i <= nbBases1; i++) {
2607     Handle(Standard_Transient) anItem = theBase1->Value(i);
2608     if (!anItem.IsNull()) {
2609       Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2610       if (!aBase.IsNull()) {
2611         Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2612         if (!aRefBase.IsNull())
2613           aSeqBases1->Append(aRefBase);
2614       }
2615     }
2616   }
2617   for (i = 1; i <= nbBases2; i++) {
2618     Handle(Standard_Transient) anItem = theBase2->Value(i);
2619     if (!anItem.IsNull()) {
2620       Handle(GEOM_Object) aBase = Handle(GEOM_Object)::DownCast(anItem);
2621       if (!aBase.IsNull()) {
2622         Handle(GEOM_Function) aRefBase = aBase->GetLastFunction();
2623         if (!aRefBase.IsNull())
2624           aSeqBases2->Append(aRefBase);
2625       }
2626     }
2627   }
2628   if (!aSeqBases1->Length() || !aSeqBases2->Length()) return NULL;
2629
2630   aCI.SetShape(aRefShape);
2631   aCI.SetBaseSeq1(aSeqBases1);
2632   aCI.SetBaseSeq2(aSeqBases2);
2633
2634   // Compute the Path value
2635   try {
2636     OCC_CATCH_SIGNALS;
2637     if (!GetSolver()->ComputeFunction(aFunction)) {
2638       SetErrorCode("PipePath driver failed");
2639       return NULL;
2640     }
2641   }
2642   catch (Standard_Failure) {
2643     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2644     SetErrorCode("RestorePath: inappropriate arguments given");
2645     return NULL;
2646   }
2647
2648   // Make a Python command
2649   GEOM::TPythonDump pyDump (aFunction);
2650   pyDump << aPath << " = geompy.RestorePathEdges(" << theShape << ", [";
2651   for (i = 1; i <= nbBases1; i++) {
2652     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theBase1->Value(i));
2653     if (!anObj.IsNull()) {
2654       pyDump << anObj;
2655       if (i < nbBases1)
2656         pyDump << ", ";
2657     }
2658   }
2659   pyDump<< "], [";
2660   for (i = 1; i <= nbBases2; i++) {
2661     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(theBase2->Value(i));
2662     if (!anObj.IsNull()) {
2663       pyDump << anObj;
2664       if (i < nbBases2)
2665         pyDump << ", ";
2666     }
2667   }
2668   pyDump << "])";
2669
2670   SetErrorCode(OK);
2671   return aPath;
2672 }
2673
2674 //=============================================================================
2675 /*!
2676  *  createGroup
2677  */
2678 //=============================================================================
2679 Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::createGroup
2680                   (const Handle(GEOM_Object)              &theBaseObject,
2681                    const Handle(TColStd_HArray1OfInteger) &theGroupIDs,
2682                    const TCollection_AsciiString          &theName,
2683                    const TopTools_IndexedMapOfShape       &theIndices)
2684 {
2685   if (theBaseObject.IsNull() || theGroupIDs.IsNull()) {
2686     return NULL;
2687   }
2688
2689   // Get the Shape type.
2690   const Standard_Integer anID      = theGroupIDs->Value(theGroupIDs->Lower());
2691   const Standard_Integer aNbShapes = theIndices.Extent();
2692
2693   if (anID < 1 || anID > aNbShapes) {
2694     return NULL;
2695   }
2696
2697   const TopoDS_Shape aSubShape = theIndices.FindKey(anID);
2698
2699   if (aSubShape.IsNull()) {
2700     return NULL;
2701   }
2702
2703   // Create a group.
2704   const TopAbs_ShapeEnum aGroupType = aSubShape.ShapeType();
2705   Handle(GEOM_Object)    aGroup     =
2706     myGroupOperations->CreateGroup(theBaseObject, aGroupType);
2707
2708   if (aGroup.IsNull() == Standard_False) {
2709     aGroup->GetLastFunction()->SetDescription("");
2710     aGroup->SetName(theName.ToCString());
2711
2712     Handle(TColStd_HSequenceOfInteger) aSeqIDs = new TColStd_HSequenceOfInteger;
2713     Standard_Integer                   i;
2714
2715     for (i = theGroupIDs->Lower(); i <= theGroupIDs->Upper(); ++i) {
2716       // Get and check the index.
2717       const Standard_Integer anIndex = theGroupIDs->Value(i);
2718
2719       if (anIndex < 1 || anIndex > aNbShapes) {
2720         return NULL;
2721       }
2722
2723       // Get and check the sub-shape.
2724       const TopoDS_Shape aSubShape = theIndices.FindKey(anIndex);
2725
2726       if (aSubShape.IsNull()) {
2727         return NULL;
2728       }
2729
2730       // Check the shape type.
2731       if (aSubShape.ShapeType() != aGroupType) {
2732         return NULL;
2733       }
2734
2735       aSeqIDs->Append(anIndex);
2736     }
2737
2738     myGroupOperations->UnionIDs(aGroup, aSeqIDs);
2739     aGroup->GetLastFunction()->SetDescription("");
2740   }
2741
2742   return aGroup;
2743 }
2744
2745 //=============================================================================
2746 /*!
2747  *  createGroups
2748  */
2749 //=============================================================================
2750 void GEOMImpl_I3DPrimOperations::createGroups
2751                    (const Handle(GEOM_Object)                  &theBaseObject,
2752                           GEOMImpl_IPipe                       *thePipe,
2753                           Handle(TColStd_HSequenceOfTransient) &theSequence)
2754 {
2755   if (theBaseObject.IsNull() || thePipe == NULL || theSequence.IsNull()) {
2756     return;
2757   }
2758
2759   TopoDS_Shape aShape = theBaseObject->GetValue();
2760
2761   if (aShape.IsNull()) {
2762     return;
2763   }
2764
2765   TopTools_IndexedMapOfShape       anIndices;
2766   Handle(TColStd_HArray1OfInteger) aGroupIDs;
2767   TopoDS_Shape                     aShapeType;
2768   const Standard_Integer           aNbGroups = 5;
2769   Handle(GEOM_Object)              aGrps[aNbGroups];
2770   Standard_Integer                 i;
2771
2772   TopExp::MapShapes(aShape, anIndices);
2773
2774   // Create groups.
2775   aGroupIDs = thePipe->GetGroupDown();
2776   aGrps[0]  = createGroup(theBaseObject, aGroupIDs, "GROUP_DOWN", anIndices);
2777   aGroupIDs = thePipe->GetGroupUp();
2778   aGrps[1]  = createGroup(theBaseObject, aGroupIDs, "GROUP_UP", anIndices);
2779   aGroupIDs = thePipe->GetGroupSide1();
2780   aGrps[2]  = createGroup(theBaseObject, aGroupIDs, "GROUP_SIDE1", anIndices);
2781   aGroupIDs = thePipe->GetGroupSide2();
2782   aGrps[3]  = createGroup(theBaseObject, aGroupIDs, "GROUP_SIDE2", anIndices);
2783   aGroupIDs = thePipe->GetGroupOther();
2784   aGrps[4]  = createGroup(theBaseObject, aGroupIDs, "GROUP_OTHER", anIndices);
2785
2786   for (i = 0; i < aNbGroups; ++i) {
2787     if (aGrps[i].IsNull() == Standard_False) {
2788       theSequence->Append(aGrps[i]);
2789     }
2790   }
2791 }