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