]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_IAdvancedOperations.cxx
Salome HOME
Porting to OCCT6.5.1
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IAdvancedOperations.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 //  File   : GEOMImpl_IAdvancedOperations.cxx
20 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
21
22 #include <Standard_Stream.hxx>
23
24 #include "GEOMImpl_Types.hxx"
25 #include "GEOMImpl_IAdvancedOperations.hxx"
26 #include "GEOMImpl_IBasicOperations.hxx"
27 #include "GEOMImpl_IBooleanOperations.hxx"
28 #include "GEOMImpl_IShapesOperations.hxx"
29 #include "GEOMImpl_ITransformOperations.hxx"
30 #include "GEOMImpl_IBlocksOperations.hxx"
31 #include "GEOMImpl_I3DPrimOperations.hxx"
32 #include "GEOMImpl_ILocalOperations.hxx"
33 #include "GEOMImpl_IHealingOperations.hxx"
34
35 #include "GEOMImpl_Gen.hxx"
36
37 #include <Basics_OCCTVersion.hxx>
38
39 #include <utilities.h>
40 #include <OpUtil.hxx>
41 #include <Utils_ExceptHandlers.hxx>
42
43 #include "GEOM_Function.hxx"
44 #include "GEOM_PythonDump.hxx"
45
46 #include "GEOMImpl_PipeTShapeDriver.hxx"
47 #include "GEOMImpl_IPipeTShape.hxx"
48 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
49
50 #include <TopExp.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopoDS.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
55
56 #include <gp_Pnt.hxx>
57 #include <gp_Vec.hxx>
58 #include <gp_Ax3.hxx>
59 #include <BRepBuilderAPI_Transform.hxx>
60 #include <BRep_Tool.hxx>
61 #include <cmath>
62
63 #include <TFunction_DriverTable.hxx>
64 #include <TFunction_Driver.hxx>
65 #include <TFunction_Logbook.hxx>
66 #include <TDF_Tool.hxx>
67 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
69
70 #define HALF_LENGTH_MAIN_PIPE     "Main pipe half length" //"Tuyau principal - demi longueur"
71 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
72 #define CIRCULAR_QUARTER_PIPE     "Circular quarter of pipe" //"Circulaire - quart de tuyau"
73 #define THICKNESS                 "Thickness" //"Epaisseur"
74 #define FLANGE                    "Flange" // "Collerette"
75 #define CHAMFER_OR_FILLET         "Chamfer or fillet" //"Chanfrein ou Raccord"
76 #define JUNCTION_FACE_1           "Junction 1" //"Face de jonction 1"
77 #define JUNCTION_FACE_2           "Junction 2" //"Face de jonction 2"
78 #define JUNCTION_FACE_3           "Junction 3" //"Face de jonction 3"
79
80 //=============================================================================
81 /*!
82  *  Constructor
83  */
84 //=============================================================================
85 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
86   GEOM_IOperations(theEngine, theDocID)
87 {
88   MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
89   myBasicOperations     = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
90   myBooleanOperations   = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
91   myShapesOperations    = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
92   myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
93   myBlocksOperations    = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
94   my3DPrimOperations    = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
95   myLocalOperations     = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
96   myHealingOperations   = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());
97 }
98
99 //=============================================================================
100 /*!
101  *  Destructor
102  */
103 //=============================================================================
104 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
105 {
106   MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
107   delete myBasicOperations;
108   delete myBooleanOperations;
109   delete myShapesOperations;
110   delete myTransformOperations;
111   delete myBlocksOperations;
112   delete my3DPrimOperations;
113   delete myLocalOperations;
114   delete myHealingOperations;
115 }
116
117 //=============================================================================
118 /*!
119  *  SetPosition
120  */
121 //=============================================================================
122 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
123                                                       Handle(GEOM_Object) theP1,
124                                                       Handle(GEOM_Object) theP2,
125                                                       Handle(GEOM_Object) theP3)
126 {
127   // Old Local Coordinates System oldLCS
128   gp_Pnt P0(0, 0, 0);
129   gp_Pnt P1(-theL1, 0, 0);
130   gp_Pnt P2(theL1, 0, 0);
131   gp_Pnt P3(0, 0, theL2);
132
133   gp_Dir oldX(gp_Vec(P1, P2));
134   gp_Dir oldZ(gp_Vec(P0, P3));
135   gp_Ax3 oldLCS(P0, oldZ, oldX);
136
137   // New Local Coordinates System newLCS
138   double LocX, LocY, LocZ;
139   gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
140   gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
141   gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
142   LocX = (newP1.X() + newP2.X()) / 2.;
143   LocY = (newP1.Y() + newP2.Y()) / 2.;
144   LocZ = (newP1.Z() + newP2.Z()) / 2.;
145   gp_Pnt newO(LocX, LocY, LocZ);
146
147   gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
148   gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
149   gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
150
151   gp_Trsf aTrsf;
152   aTrsf.SetDisplacement(oldLCS, newLCS);
153
154   return aTrsf;
155 }
156
157 //=============================================================================
158 /*!
159  *  CheckCompatiblePosition
160  *
161  */
162 //=============================================================================
163 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
164                                                            Handle(GEOM_Object) theP1,
165                                                            Handle(GEOM_Object) theP2,
166                                                            Handle(GEOM_Object) theP3,
167                                                            double theTolerance)
168 {
169   SetErrorCode(KO);
170   gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
171   gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
172   gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
173
174   double d12 = P1.Distance(P2);
175   double d13 = P1.Distance(P3);
176   double d23 = P2.Distance(P3);
177   //    double d2 = newO.Distance(P3);
178
179   if (Abs(d12) <= Precision::Confusion()) {
180     SetErrorCode("Junctions points P1 and P2 are identical");
181     return false;
182   }
183   if (Abs(d13) <= Precision::Confusion()) {
184     SetErrorCode("Junctions points P1 and P3 are identical");
185     return false;
186   }
187   if (Abs(d23) <= Precision::Confusion()) {
188     SetErrorCode("Junctions points P2 and P3 are identical");
189     return false;
190   }
191
192
193   double newL1 = 0.5 * d12;
194   double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
195   //
196   // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
197   //
198   if (fabs(newL1 - theL1) > Precision::Approximation()) {
199     if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
200          (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
201       //            std::cerr << "theL1 = newL1" << std::endl;
202       theL1 = newL1;
203     } else {
204       theL1 = -1;
205       SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
206       return false;
207     }
208   }
209
210   //
211   // theL2*(1-theTolerance) <= newL2  <= theL2*(1+theTolerance)
212   //
213   if (fabs(newL2 - theL2) > Precision::Approximation()) {
214     if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
215          (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
216       theL2 = newL2;
217     } else {
218       theL2 = -1;
219       SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
220       return false;
221     }
222   }
223
224   SetErrorCode(OK);
225   return true;
226
227 }
228
229 //=============================================================================
230 /*!
231  *  Generate the propagation groups of a Pipe T-Shape used for hexa mesh
232  */
233 //=============================================================================
234 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
235                                               double theR1, double theW1, double theL1,
236                                               double theR2, double theW2, double theL2,
237                                               Handle(TColStd_HSequenceOfTransient) theSeq,
238                                               gp_Trsf aTrsf)
239 {
240   SetErrorCode(KO);
241
242   if (theShape.IsNull()) return false;
243
244   TopoDS_Shape aShape = theShape->GetValue();
245   if (aShape.IsNull()) {
246     SetErrorCode("Shape is not defined");
247     return false;
248   }
249
250   gp_Trsf aTrsfInv = aTrsf.Inverted();
251
252   int expectedGroups = 0;
253   if (shapeType == TSHAPE_BASIC)
254     if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
255       expectedGroups = 10;
256     else
257       expectedGroups = 11;
258   else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
259     expectedGroups = 12;
260
261   double aR1Ext = theR1 + theW1;
262   double aR2Ext = theR2 + theW2;
263
264   /////////////////////////
265   //// Groups of Faces ////
266   /////////////////////////
267
268   //
269   // Comment the following lines when GetInPlace bug is solved
270   // == BEGIN
271   // Workaround of GetInPlace bug
272   // Create a bounding box that fits the shape
273   Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
274   aBox->GetLastFunction()->SetDescription("");
275   myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
276   aBox->GetLastFunction()->SetDescription("");
277   // Apply transformation to box
278   BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
279   TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
280   aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
281
282   // Get the shell of the box
283   Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast
284     (myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
285   aBox->GetLastFunction()->SetDescription("");
286   aShell->GetLastFunction()->SetDescription("");
287   // Get the common shapes between shell and shape
288   Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
289   if (aCommonCompound.IsNull()) {
290     SetErrorCode(myBooleanOperations->GetErrorCode());
291     return false;
292   }
293   aCommonCompound->GetLastFunction()->SetDescription("");
294   // Explode the faces of common shapes => 3 faces
295   Handle(TColStd_HSequenceOfTransient) aCommonFaces =
296     myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
297   aCommonCompound->GetLastFunction()->SetDescription("");
298   std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
299
300   for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
301     std::list<Handle(GEOM_Object)> aFacesList;
302     for (int j = 1 ; j <= 4 ; j++) {
303       Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
304       if (!aFace.IsNull()) {
305         aFace->GetLastFunction()->SetDescription("");
306         aFacesList.push_back(aFace);
307       }
308     }
309     Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
310     if (!aCompoundOfFaces.IsNull()) {
311       aCompoundOfFaces->GetLastFunction()->SetDescription("");
312       aCompoundOfFacesList.push_back(aCompoundOfFaces);
313     }
314   }
315
316   if (aCompoundOfFacesList.size() == 3) {
317     Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
318     aCompoundOfFacesList.pop_front();
319     Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
320     aCompoundOfFacesList.pop_front();
321     Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
322     aCompoundOfFacesList.pop_front();
323     // == END
324     //
325
326
327     //     Uncomment the following lines when GetInPlace bug is solved
328     //     == BEGIN
329 //     Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
330 //     Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
331 //     Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
332 //     aP1->GetLastFunction()->SetDescription("");
333 //     aP2->GetLastFunction()->SetDescription("");
334 //     aP3->GetLastFunction()->SetDescription("");
335 //     Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
336 //     Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
337 //     Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
338 //     aV1->GetLastFunction()->SetDescription("");
339 //     aV2->GetLastFunction()->SetDescription("");
340 //     aV3->GetLastFunction()->SetDescription("");
341 //     Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
342 //     Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
343 //     Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
344 //     aPln1->GetLastFunction()->SetDescription("");
345 //     aPln2->GetLastFunction()->SetDescription("");
346 //     aPln3->GetLastFunction()->SetDescription("");
347 //
348 //     BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
349 //     TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
350 //     aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
351 //     BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
352 //     TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
353 //     aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
354 //     BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
355 //     TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
356 //     aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
357     //     == END
358     //
359
360     Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
361     if (junctionFaces1.IsNull())
362       junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound
363         (aPln1, theShape, TopAbs_FACE,  GEOMAlgo_ST_ONIN);
364     if (!junctionFaces1.IsNull()) {
365       junctionFaces1->GetLastFunction()->SetDescription("");
366       junctionFaces1->SetName("JUNCTION_FACE_1");
367       theSeq->Append(junctionFaces1);
368     }
369     else {
370       SetErrorCode("Junction face 1 not found");
371       //        theSeq->Append(aPln1);
372       //        return false;
373     }
374     Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
375     if (junctionFaces2.IsNull())
376       junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound
377         (aPln2, theShape, TopAbs_FACE,  GEOMAlgo_ST_ONIN);
378     if (!junctionFaces2.IsNull()) {
379       junctionFaces2->GetLastFunction()->SetDescription("");
380       junctionFaces2->SetName("JUNCTION_FACE_2");
381       theSeq->Append(junctionFaces2);
382     }
383     else {
384       SetErrorCode("Junction face 2 not found");
385       //        theSeq->Append(aPln2);
386       //        return false;
387     }
388     Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
389     if (junctionFaces3.IsNull())
390       junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound
391         (aPln3, theShape, TopAbs_FACE,  GEOMAlgo_ST_ONIN);
392     if (!junctionFaces3.IsNull()) {
393       junctionFaces3->GetLastFunction()->SetDescription("");
394       junctionFaces3->SetName("JUNCTION_FACE_3");
395       theSeq->Append(junctionFaces3);
396     }
397     else {
398       SetErrorCode("Junction face 3 not found");
399       //        theSeq->Append(aPln3);
400       //        return false;
401     }
402   // Comment the following lines when GetInPlace bug is solved
403   // == BEGIN
404   }
405   //     == END
406   /////////////////////////
407   //// Groups of Edges ////
408   /////////////////////////
409   // Result of propagate
410
411   Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
412
413   TCollection_AsciiString theDesc = aFunction->GetDescription();
414   Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
415   if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
416     SetErrorCode("Propagation groups not found");
417     return false;
418   }
419   Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
420   // Recover previous description to get rid of Propagate dump
421   aFunction->SetDescription(theDesc);
422
423   bool addGroup;
424   bool circularFoundAndAdded = false;
425   bool circularFound10 = false;
426   bool incidentPipeFound = false;
427   bool mainPipeFound = false;
428   bool mainPipeFoundAndAdded = false;
429   bool radialFound =false;
430   bool flangeFound = false;
431   bool flangeFoundAndAdded = false;
432   bool chamferOrFilletFound = false;
433
434   for (int i=1 ; i<= aNbGroups; i++) {
435     addGroup = false;
436
437     Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
438     if(aGroup.IsNull())
439       continue;
440
441     TopoDS_Shape aGroupShape = aGroup->GetValue();
442     BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
443     TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
444
445     TopTools_IndexedMapOfShape anEdgesMap;
446     TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
447     nbEdges = anEdgesMap.Extent();
448
449     if (shapeType == TSHAPE_BASIC) {
450       if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
451         addGroup = true;
452         aGroup->SetName("THICKNESS");
453       }
454       else if (nbEdges == 6) {
455         if (!circularFoundAndAdded) {
456           circularFoundAndAdded = true;
457           addGroup = true;
458           aGroup->SetName("CIRCULAR_QUARTER_PIPE");
459         }
460       }
461       else if (nbEdges == 8) {
462         incidentPipeFound = true;
463         mainPipeFound = false;
464         radialFound =false;
465         flangeFound = false;
466
467         TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
468         while (Ex.More()) {
469           gp_Pnt aP =  BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
470           double x=aP.X(), y=aP.Y(), z=aP.Z();
471
472
473           if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
474               (Abs(y) > aR2Ext + Precision::Confusion())) {
475             incidentPipeFound = false;
476           }
477
478           if ( z < -Precision::Confusion()) {
479             // length of main pipe
480             mainPipeFound = true;
481             if (!mainPipeFoundAndAdded) {
482               mainPipeFoundAndAdded = true;
483               addGroup = true;
484               aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
485             }
486           }
487
488           else if (Abs(x) > (theL1-Precision::Confusion())) {
489             // discretisation circulaire
490             radialFound = true;
491             if (!circularFoundAndAdded) {
492               circularFoundAndAdded = true;
493               addGroup = true;
494               aGroup->SetName("CIRCULAR_QUARTER_PIPE");
495             }
496           }
497           Ex.Next();
498         }
499         if (incidentPipeFound) {
500           addGroup = true;
501           aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
502         }
503         if (!addGroup && (!incidentPipeFound &&
504                           !radialFound &&
505                           !mainPipeFound &&
506                           !flangeFound)) {
507           // Flange (collerette)
508           flangeFound = true;
509           addGroup = true;
510           aGroup->SetName("FLANGE");
511         }
512       }
513       else
514         continue;
515     }
516     else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
517       if (nbEdges == 25) {
518         addGroup = true;
519         aGroup->SetName("THICKNESS");
520       }
521       else if ((nbEdges == 10) || (nbEdges == 6)) {
522         if (!circularFoundAndAdded) {
523           addGroup = true;
524           circularFoundAndAdded = true;
525           aGroup->SetName("CIRCULAR_QUARTER_PIPE");
526           if (nbEdges == 10) {
527             circularFound10 = true;
528           }
529         }
530         else if (!circularFound10 && nbEdges == 10) {
531           circularFound10 = true;
532           addGroup = true;
533           aGroup->SetName("CIRCULAR_QUARTER_PIPE");
534         }
535       }
536       else if (nbEdges == 8) {
537         incidentPipeFound = true;
538         mainPipeFound = true;
539         flangeFound = false;
540
541         bool isNearZ0 = false;
542         bool isBelowZ0 = false;
543
544         TopExp_Explorer Ex (aGroupShapeTrsfInv,TopAbs_VERTEX);
545         while (Ex.More()) {
546           gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
547           double x=aP.X(), y=aP.Y(), z=aP.Z();
548
549           // tuy_princ_long_avant & tuy_princ_long_apres
550           //bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
551           //               ((y <= aR1Ext + Precision::Confusion()) ||
552           //                (y <= -(aR1Ext + Precision::Confusion())) ||
553           //                (y <= theR1 + Precision::Confusion()) ||
554           //                (y == -(theR1 + Precision::Confusion()))));
555           bool isMain = ((z < Precision::Confusion() || x < Precision::Confusion()) &&
556                          (fabs(y) > theR1 - Precision::Confusion() ||
557                           fabs(y) < Precision::Confusion()));
558
559           if (!isMain) {
560             mainPipeFound = false;
561           }
562
563           // collerette
564           //if (z < Precision::Confusion() && !isMain) {
565           //  flangeFound = true;
566           //  if (!flangeFoundAndAdded) {
567           //    flangeFoundAndAdded = true;
568           //    addGroup = true;
569           //    aGroup->SetName("FLANGE");
570           //  }
571           //}
572           if (fabs(z) < Precision::Confusion()) isNearZ0 = true;
573           if (z < - Precision::Confusion()) isBelowZ0 = true;
574
575           // tuyau incident
576           if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
577               (Abs(y) > aR2Ext + Precision::Confusion())) {
578             incidentPipeFound = false;
579           }
580           Ex.Next();
581         }
582         if (mainPipeFound) {
583           addGroup = true;
584           aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
585         }
586         if (incidentPipeFound) {
587           addGroup = true;
588           aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
589         }
590         if (isNearZ0 && !isBelowZ0) {
591           flangeFound = true;
592           if (!flangeFoundAndAdded) {
593             flangeFoundAndAdded = true;
594             addGroup = true;
595             aGroup->SetName("FLANGE");
596           }
597         }
598         if (!addGroup && (!incidentPipeFound &&
599                           !mainPipeFound &&
600                           !flangeFound &&
601                           !chamferOrFilletFound)) {
602           addGroup = true;
603           chamferOrFilletFound = true;
604           if (shapeType == TSHAPE_CHAMFER)
605             aGroup->SetName("CHAMFER");
606           else
607             aGroup->SetName("FILLET");
608         }
609       }
610       else
611         continue;
612     }
613     // Add group to the list
614     if (addGroup)
615       theSeq->Append(aGroup);
616   }
617
618   SetErrorCode(OK);
619   return true;
620 }
621
622 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
623                                                            double theR1, double theW1, double theL1,
624                                                            double theR2, double theW2, double theL2,
625                                                            double theH, double theW,
626                                                            double theRF, bool isNormal)
627 {
628   SetErrorCode(KO);
629
630   // Build tools for partition operation:
631   // 1 face and 2 planes
632   // Face
633   Handle(GEOM_Object) arete_intersect_int;
634   Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
635   Handle(GEOM_Object) chan_racc;
636   Handle(GEOM_Object) vi1, vi2;
637
638   Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
639   Vector_Z->GetLastFunction()->SetDescription("");
640
641   // Useful values
642   double aSize = 2*(theL1 + theL2);
643   double aR1Ext = theR1 + theW1;
644   double aR2Ext = theR2 + theW2;
645   double theVertCylinderRadius = aR2Ext + theW + theRF;
646   double theHoriCylinderRadius = aR1Ext + theH + theRF;
647
648   // Common edges on internal cylinder
649   Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
650   box_i->GetLastFunction()->SetDescription("");
651   box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
652   box_i->GetLastFunction()->SetDescription("");
653
654   Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
655   TCollection_AsciiString theDesc = aFunction->GetDescription();
656   Handle(TColStd_HSequenceOfTransient) edges_i =
657     myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
658   // Recover previous description to get rid of Propagate dump
659   aFunction->SetDescription(theDesc);
660   if (edges_i.IsNull() || edges_i->Length() == 0) {
661     SetErrorCode("Internal edges not found");
662     return false;
663   }
664   for (int i=1; i<=edges_i->Length();i++) {
665     Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
666     anObj->GetLastFunction()->SetDescription("");
667   }
668   arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
669
670   // search for vertices located on both internal pipes
671   aFunction = theShape->GetLastFunction();
672   theDesc = aFunction->GetDescription();
673   Handle(TColStd_HSequenceOfTransient) vertices_i =
674     myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
675   // Recover previous description to get rid of Propagate dump
676   aFunction->SetDescription(theDesc);
677   if (vertices_i.IsNull() || vertices_i->Length() == 0) {
678     SetErrorCode("Internal vertices not found");
679     return false;
680   }
681
682   for (int i = 1; i <= vertices_i->Length(); i++) {
683     Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
684     v->GetLastFunction()->SetDescription("");
685     TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
686     gp_Pnt aP = BRep_Tool::Pnt(aVertex);
687     if (Abs(aP.X()) <= Precision::Confusion()) {
688       if (Abs(aP.Y()) - theR2 <= Precision::Confusion())
689         vi1 = v;
690     } else if (Abs(aP.Y()) <= Precision::Confusion()) {
691       if (Abs(aP.X()) - theR1 <= Precision::Confusion())
692         vi2 = v;
693     }
694   }
695
696   std::list<Handle(GEOM_Object)> theShapes;
697
698   if (isNormal) {
699     Handle(GEOM_Object) ve1, ve2;
700
701     Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
702     box_e->GetLastFunction()->SetDescription("");
703     box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
704     box_e->GetLastFunction()->SetDescription("");
705     // Common edges on external cylinder
706     aFunction = theShape->GetLastFunction();
707     theDesc = aFunction->GetDescription();
708     Handle(TColStd_HSequenceOfTransient) edges_e =
709       myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
710     // Recover previous description to get rid of Propagate dump
711     aFunction->SetDescription(theDesc);
712     if (edges_e.IsNull() || edges_e->Length() == 0) {
713       SetErrorCode("External edges not found");
714       return false;
715     }
716     for (int i=1; i<=edges_e->Length();i++) {
717       Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
718       anObj->GetLastFunction()->SetDescription("");
719     }
720
721     // search for vertices located on both external pipes
722     aFunction = theShape->GetLastFunction();
723     theDesc = aFunction->GetDescription();
724     Handle(TColStd_HSequenceOfTransient) vertices_e =
725       myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
726     // Recover previous description to get rid of Propagate dump
727     aFunction->SetDescription(theDesc);
728     if (vertices_e.IsNull() || vertices_e->Length() == 0) {
729       SetErrorCode("External vertices not found");
730       return false;
731     }
732
733     for (int i = 1; i <= vertices_e->Length(); i++) {
734       Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
735       v->GetLastFunction()->SetDescription("");
736       TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
737       gp_Pnt aP = BRep_Tool::Pnt(aVertex);
738       if (Abs(aP.X()) <= Precision::Confusion()) {
739         if (Abs(aP.Y()) - theR2 > Precision::Confusion())
740           ve1 = v;
741       } else if (Abs(aP.Y()) <= Precision::Confusion()) {
742         if (Abs(aP.X()) - theR2 > Precision::Confusion())
743           ve2 = v;
744       }
745     }
746     Handle(GEOM_Object) edge_e1, edge_e2;
747     try {
748 #if OCC_VERSION_LARGE > 0x06010000
749       OCC_CATCH_SIGNALS;
750 #endif
751       edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
752       if (edge_e1.IsNull()) {
753         SetErrorCode("Edge 1 could not be built");
754         return false;
755       }
756     } catch (Standard_Failure) {
757       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
758       SetErrorCode(aFail->GetMessageString());
759       return false;
760     }
761
762     try {
763 #if OCC_VERSION_LARGE > 0x06010000
764       OCC_CATCH_SIGNALS;
765 #endif
766       edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
767       if (edge_e2.IsNull()) {
768         SetErrorCode("Edge 2 could not be built");
769         return false;
770       }
771     } catch (Standard_Failure) {
772       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
773       SetErrorCode(aFail->GetMessageString());
774       return false;
775     }
776
777     edge_e1->GetLastFunction()->SetDescription("");
778     edge_e2->GetLastFunction()->SetDescription("");
779
780     std::list<Handle(GEOM_Object)> edge_e_elist;
781     edge_e_elist.push_back(arete_intersect_int);
782     edge_e_elist.push_back(edge_e1);
783     edge_e_elist.push_back(Handle(GEOM_Object)::DownCast(edges_e->Value(1)));
784     edge_e_elist.push_back(edge_e2);
785     wire_t = myShapesOperations->MakeWire(edge_e_elist, 1e-7);
786     if (wire_t.IsNull()) {
787       SetErrorCode("Impossible to build wire");
788       return false;
789     }
790     wire_t->GetLastFunction()->SetDescription("");
791     face_t = myShapesOperations->MakeFace(wire_t, false);
792     if (face_t.IsNull()) {
793       SetErrorCode("Impossible to build face");
794       return false;
795     }
796     face_t->GetLastFunction()->SetDescription("");
797   }
798   else {
799     Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
800     int idP1, idP2, idP3, idP4;
801     int PZX, PZY;
802     double ZX=0, ZY=0;
803     std::vector<int> LX;
804     std::vector<int> LY;
805     Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ
806       (theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
807     box_e->GetLastFunction()->SetDescription("");
808     box_e = myTransformOperations->TranslateDXDYDZ
809       (box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
810     box_e->GetLastFunction()->SetDescription("");
811
812     aFunction = theShape->GetLastFunction();
813     theDesc = aFunction->GetDescription();
814     Handle(TColStd_HSequenceOfTransient) extremVertices =
815       myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
816     // Recover previous description to get rid of Propagate dump
817     aFunction->SetDescription(theDesc);
818
819     if (extremVertices.IsNull() || extremVertices->Length() == 0) {
820       if (theRF == 0)
821         SetErrorCode("Vertices on chamfer not found");
822       else
823         SetErrorCode("Vertices on fillet not found");
824       return false;
825     }
826
827     theShapes.push_back(theShape);
828     theShapes.push_back(box_e);
829     if (extremVertices->Length() != 6) {
830       //           for (int i=1; i<=extremVertices->Length(); i++){
831       //             theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
832       //           }
833       //           Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
834       //           TopoDS_Shape aCompoundShape = aCompound->GetValue();
835       //           theShape->GetLastFunction()->SetValue(aCompoundShape);
836       SetErrorCode("Bad number of vertices on chamfer found");
837       return false;
838     }
839
840     for (int i=1; i<=extremVertices->Length(); i++){
841       Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
842       aV->GetLastFunction()->SetDescription("");
843       gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
844
845       if (Abs(aP.X()) <= Precision::Confusion()) {
846         if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
847           LX.push_back(i);
848           if  (aP.Z()-ZX > Precision::Confusion()) {
849             ZX = aP.Z();
850             PZX = i;
851           }
852         }
853       }
854       else {
855         if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
856           LY.push_back(i);
857           if (aP.Z() - ZY > Precision::Confusion()) {
858             ZY = aP.Z();
859             PZY = i;
860           }
861         }
862       }
863     }
864
865     idP2 = PZX;
866     idP4 = PZY;
867     idP1 = LX.at(0);
868     if (LX.at(0) == PZX)
869       idP1 = LX.at(1);
870     idP3 = LY.at(0);
871     if (LY.at(0) == PZY)
872       idP3 = LY.at(1);
873
874     P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
875     P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
876     P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
877     P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
878
879     Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
880     if (Cote_1.IsNull()) {
881       SetErrorCode("Impossible to build edge in thickness");
882       return false;
883     }
884     Cote_1->GetLastFunction()->SetDescription("");
885
886     Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
887     if (Cote_2.IsNull()) {
888       SetErrorCode("Impossible to build edge in thickness");
889       return false;
890     }
891     Cote_2->GetLastFunction()->SetDescription("");
892
893     // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
894     // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
895     //         std::cerr << "Getting chamfer edge on main pipe" << std::endl;
896     Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
897     if (edge_chan_princ.IsNull()) {
898       SetErrorCode("Impossible to find edge on main pipe");
899       return false;
900     }
901     edge_chan_princ->GetLastFunction()->SetDescription("");
902
903     Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
904     if (edge_chan_inc.IsNull()) {
905       SetErrorCode("Impossible to find edge on incident pipe");
906       return false;
907     }
908     edge_chan_inc->GetLastFunction()->SetDescription("");
909
910     std::list<Handle(GEOM_Object)> edgeList1;
911     edgeList1.push_back(edge_chan_princ);
912     edgeList1.push_back(Cote_1);
913     edgeList1.push_back(arete_intersect_int);
914     edgeList1.push_back(Cote_2);
915
916     //         std::cerr << "Creating wire 1" << std::endl;
917     wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
918     if (wire_t.IsNull()) {
919       SetErrorCode("Impossible to build wire");
920       return false;
921     }
922     wire_t->GetLastFunction()->SetDescription("");
923
924     //         std::cerr << "Creating face 1" << std::endl;
925     face_t = myShapesOperations->MakeFace(wire_t, false);
926     if (face_t.IsNull()) {
927       SetErrorCode("Impossible to build face");
928       return false;
929     }
930     face_t->GetLastFunction()->SetDescription("");
931     theShapes.push_back(face_t);
932
933     gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
934     gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
935     double deltaZ = aP2.Z() - aP5.Z();
936     //         std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
937     Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
938     if (P5bis.IsNull()) {
939       SetErrorCode("Impossible to translate vertex");
940       return false;
941     }
942     P5bis->GetLastFunction()->SetDescription("");
943
944     gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
945     gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
946     deltaZ = aP4.Z() - aP6.Z();
947     //         std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
948     Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
949     if (P6bis.IsNull()) {
950       SetErrorCode("Impossible to translate vertex");
951       return false;
952     }
953     P6bis->GetLastFunction()->SetDescription("");
954
955     //         std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
956     Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
957     if (Cote_3.IsNull()) {
958       SetErrorCode("Impossible to build edge in thickness");
959       return false;
960     }
961     Cote_3->GetLastFunction()->SetDescription("");
962
963     //         std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
964     Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
965     if (Cote_4.IsNull()) {
966       SetErrorCode("Impossible to build edge in thickness");
967       return false;
968     }
969     Cote_4->GetLastFunction()->SetDescription("");
970
971     //         std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
972     Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
973     if (Cote_4.IsNull()) {
974       SetErrorCode("Impossible to build edge in thickness");
975       return false;
976     }
977     Cote_5->GetLastFunction()->SetDescription("");
978
979     //std::list<Handle(GEOM_Object)> edgeList2;
980     //edgeList2.push_back(edge_chan_inc);
981     //edgeList2.push_back(Cote_3);
982     //edgeList2.push_back(Cote_5);
983     //edgeList2.push_back(Cote_4);
984     //         std::cerr << "Creating wire 2" << std::endl;
985     //wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
986     //if (wire_t2.IsNull()) {
987     //  SetErrorCode("Impossible to build wire");
988     //  return false;
989     //}
990     //wire_t2->GetLastFunction()->SetDescription("");
991     //         std::cerr << "Creating face 2" << std::endl;
992     //face_t2 = myShapesOperations->MakeFace(wire_t2, false);
993     face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - 2.0*theR2);
994     if (face_t2.IsNull()) {
995       SetErrorCode("Impossible to build face");
996       return false;
997     }
998     face_t2->GetLastFunction()->SetDescription("");
999     theShapes.push_back(face_t2);
1000   }
1001
1002   // Planes
1003   Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1004   Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
1005   Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
1006   Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
1007   Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
1008   aP0->GetLastFunction()->SetDescription("");
1009   aVZ->GetLastFunction()->SetDescription("");
1010   aVXZ->GetLastFunction()->SetDescription("");
1011   aPlnOZ->GetLastFunction()->SetDescription("");
1012   aPlnOXZ->GetLastFunction()->SetDescription("");
1013   theShapes.push_back(aPlnOZ);
1014   theShapes.push_back(aPlnOXZ);
1015
1016   // Partition
1017   Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
1018   Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
1019   Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
1020   Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
1021   Handle(TColStd_HArray1OfInteger) theMaterials;
1022   partitionShapes->Append(theShape);
1023   theTools->Append(aPlnOZ);
1024   if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1025     theTools->Append(aPlnOXZ);
1026   theTools->Append(face_t);
1027   if (!isNormal)
1028     theTools->Append(face_t2);
1029
1030   Handle(GEOM_Object) Te3 = myBooleanOperations->MakePartition
1031     (partitionShapes, theTools, theKeepInside, theRemoveInside,
1032      TopAbs_SOLID, false, theMaterials, 0, false);
1033   if (Te3.IsNull()) {
1034     SetErrorCode("Impossible to build partition of TShape");
1035     //         Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
1036     //         TopoDS_Shape aCompoundShape = aCompound->GetValue();
1037     //         theShape->GetLastFunction()->SetValue(aCompoundShape);
1038     return false;
1039   }
1040   Te3->GetLastFunction()->SetDescription("");
1041
1042   // Last verification: result should be a block
1043   std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1044   if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1045     SetErrorCode("TShape is not a block");
1046     return false;
1047   }
1048   TopoDS_Shape aShape = Te3->GetValue();
1049   theShape->GetLastFunction()->SetValue(aShape);
1050
1051   SetErrorCode(OK);
1052   return true;
1053 }
1054
1055 // Mirror and glue faces
1056 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1057                                                                double theR1, double theW1, double theL1,
1058                                                                double theR2, double theW2, double theL2)
1059 {
1060   SetErrorCode(KO);
1061
1062   // Useful values
1063   double aSize = 2*(theL1 + theL2);
1064   double aR1Ext = theR1 + theW1;
1065
1066   // Planes
1067   Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1068   aP0->GetLastFunction()->SetDescription("");
1069   Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1070   Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1071   aVX->GetLastFunction()->SetDescription("");
1072   aVY->GetLastFunction()->SetDescription("");
1073   Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1074   Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1075   aPlane_OX->GetLastFunction()->SetDescription("");
1076   aPlane_OY->GetLastFunction()->SetDescription("");
1077
1078   Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1079   if (Te4.IsNull()) {
1080     SetErrorCode("Impossible to build mirror of quarter TShape");
1081     return false;
1082   }
1083
1084   Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1085   if (Te5.IsNull()) {
1086     SetErrorCode("Impossible to build mirror of half TShape");
1087     return false;
1088   }
1089
1090   Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1091   if (Te6.IsNull()) {
1092     SetErrorCode("Impossible to build mirror of half TShape");
1093     return false;
1094   }
1095
1096   std::list<Handle(GEOM_Object)> aShapesList;
1097   aShapesList.push_back(theShape);
1098   aShapesList.push_back(Te4);
1099   aShapesList.push_back(Te5);
1100   aShapesList.push_back(Te6);
1101   Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1102   if (Te7.IsNull()) {
1103     SetErrorCode("Impossible to build compound");
1104     return false;
1105   }
1106
1107   Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1108   if (Te8.IsNull()) {
1109     SetErrorCode("Impossible to glue faces of TShape");
1110     return false;
1111   }
1112
1113   TopoDS_Shape aShape = Te8->GetValue();
1114
1115   theShape->GetLastFunction()->SetValue(aShape);
1116
1117   Te4->GetLastFunction()->SetDescription("");
1118   Te5->GetLastFunction()->SetDescription("");
1119   Te6->GetLastFunction()->SetDescription("");
1120   Te7->GetLastFunction()->SetDescription("");
1121   Te8->GetLastFunction()->SetDescription("");
1122
1123   SetErrorCode(OK);
1124   return true;
1125 }
1126
1127 //=============================================================================
1128 /*!
1129  *  MakePipeTShape
1130  *  Create a T-shape object with specified caracteristics for the main and
1131  *  the incident pipes (radius, width, half-length).
1132  *  Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1133  *  \param theR1 Internal radius of main pipe
1134  *  \param theW1 Width of main pipe
1135  *  \param theL1 Half-length of main pipe
1136  *  \param theR2 Internal radius of incident pipe (R2 < R1)
1137  *  \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1138  *  \param theL2 Half-length of incident pipe
1139  *  \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1140  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
1141  */
1142 //=============================================================================
1143 Handle(TColStd_HSequenceOfTransient)
1144 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1145                                              double theR2, double theW2, double theL2,
1146                                              bool theHexMesh)
1147 {
1148   MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1149   SetErrorCode(KO);
1150   //Add a new object
1151   Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1152
1153   //Add a new shape function with parameters
1154   Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1155   if (aFunction.IsNull()) return NULL;
1156
1157   //Check if the function is set correctly
1158   if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1159
1160   GEOMImpl_IPipeTShape aData(aFunction);
1161
1162   aData.SetR1(theR1);
1163   aData.SetW1(theW1);
1164   aData.SetL1(theL1);
1165   aData.SetR2(theR2);
1166   aData.SetW2(theW2);
1167   aData.SetL2(theL2);
1168   aData.SetHexMesh(theHexMesh);
1169
1170   //Compute the resulting value
1171   try {
1172 #if OCC_VERSION_LARGE > 0x06010000
1173     OCC_CATCH_SIGNALS;
1174 #endif
1175     if (!GetSolver()->ComputeFunction(aFunction)) {
1176       SetErrorCode("TShape driver failed");
1177       return NULL;
1178     }
1179   } catch (Standard_Failure) {
1180     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1181     SetErrorCode(aFail->GetMessageString());
1182     return NULL;
1183   }
1184
1185   if (theHexMesh) {
1186     if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1187       return NULL;
1188     if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1189       return NULL;
1190   }
1191
1192   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1193   aSeq->Append(aShape);
1194
1195   if (theHexMesh) {
1196     /*
1197      * Get the groups: BEGIN
1198      */
1199     try {
1200       if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1201         return NULL;
1202     }
1203     catch (Standard_Failure) {
1204       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1205       SetErrorCode(aFail->GetMessageString());
1206       return NULL;
1207     }
1208
1209     TCollection_AsciiString aListRes, anEntry;
1210     // Iterate over the sequence aSeq
1211     Standard_Integer aNbGroups = aSeq->Length();
1212     Standard_Integer i = 2;
1213     for (; i <= aNbGroups; i++) {
1214       Handle(Standard_Transient) anItem = aSeq->Value(i);
1215       if (anItem.IsNull()) continue;
1216       Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1217       if (aGroup.IsNull()) continue;
1218       //Make a Python command
1219       TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1220       aListRes += anEntry + ", ";
1221     }
1222
1223     aListRes.Trunc(aListRes.Length() - 2);
1224
1225     //Make a Python command
1226     GEOM::TPythonDump(aFunction)
1227       << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1228       << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1229       << theHexMesh << ")";
1230   }
1231   /*
1232    * Get the groups: END
1233    */
1234   else {
1235     //Make a Python command
1236     GEOM::TPythonDump(aFunction)
1237       << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1238       << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1239   }
1240
1241   SetErrorCode(OK);
1242
1243   return aSeq;
1244 }
1245
1246 //=============================================================================
1247 /*!
1248  *  MakePipeTShapeWithPosition
1249  *  Create a T-shape object with specified caracteristics for the main and
1250  *  the incident pipes (radius, width, half-length).
1251  *  The extremities of the main pipe are located on junctions points P1 and P2.
1252  *  The extremity of the incident pipe is located on junction point P3.
1253  *  \param theR1 Internal radius of main pipe
1254  *  \param theW1 Width of main pipe
1255  *  \param theL1 Half-length of main pipe
1256  *  \param theR2 Internal radius of incident pipe (R2 < R1)
1257  *  \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1258  *  \param theL2 Half-length of incident pipe
1259  *  \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1260  *  \param theP1 1st junction point of main pipe
1261  *  \param theP2 2nd junction point of main pipe
1262  *  \param theP3 Junction point of incident pipe
1263  *  \return List of GEOM_Objects, containing the created shape and propagation groups..
1264  */
1265 //=============================================================================
1266 Handle(TColStd_HSequenceOfTransient)
1267 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1268                                                          double theR2, double theW2, double theL2,
1269                                                          bool theHexMesh,
1270                                                          Handle(GEOM_Object) theP1,
1271                                                          Handle(GEOM_Object) theP2,
1272                                                          Handle(GEOM_Object) theP3)
1273 {
1274   SetErrorCode(KO);
1275   //Add a new object
1276   Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1277   /////////////////
1278   // TSHAPE CODE
1279   /////////////////
1280   //Add a new shape function with parameters
1281   Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1282   if (aFunction.IsNull()) return NULL;
1283
1284   //Check if the function is set correctly
1285   if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1286
1287   // Check new position
1288   if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1289     return NULL;
1290   }
1291
1292   GEOMImpl_IPipeTShape aData(aFunction);
1293
1294   aData.SetR1(theR1);
1295   aData.SetW1(theW1);
1296   aData.SetL1(theL1);
1297   aData.SetR2(theR2);
1298   aData.SetW2(theW2);
1299   aData.SetL2(theL2);
1300   aData.SetHexMesh(theHexMesh);
1301
1302   //Compute the resulting value
1303   try {
1304 #if OCC_VERSION_LARGE > 0x06010000
1305     OCC_CATCH_SIGNALS;
1306 #endif
1307     if (!GetSolver()->ComputeFunction(aFunction)) {
1308       SetErrorCode("TShape driver failed");
1309       return NULL;
1310     }
1311   } catch (Standard_Failure) {
1312     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1313     SetErrorCode(aFail->GetMessageString());
1314     return NULL;
1315   }
1316
1317   if (theHexMesh) {
1318     if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1319       return NULL;
1320     if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1321       return NULL;
1322   }
1323
1324   TopoDS_Shape Te = aShape->GetValue();
1325
1326   // Set Position
1327   gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1328   BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1329   TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1330   aFunction->SetValue(aTrsf_Shape);
1331   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1332   aSeq->Append(aShape);
1333
1334   if (theHexMesh) {
1335     //
1336     // Get the groups: BEGIN
1337     //
1338     try {
1339       if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1340         return NULL;
1341       }
1342     }
1343     catch (Standard_Failure) {
1344       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1345       SetErrorCode(aFail->GetMessageString());
1346       return NULL;
1347     }
1348
1349     TCollection_AsciiString aListRes, anEntry;
1350     // Iterate over the sequence aSeq
1351     Standard_Integer aNbGroups = aSeq->Length();
1352     Standard_Integer i = 2;
1353     for (; i <= aNbGroups; i++) {
1354       Handle(Standard_Transient) anItem = aSeq->Value(i);
1355       if (anItem.IsNull()) continue;
1356       Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1357       if (aGroup.IsNull()) continue;
1358       //Make a Python command
1359       TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1360       aListRes += anEntry + ", ";
1361     }
1362
1363     aListRes.Trunc(aListRes.Length() - 2);
1364
1365     //Make a Python command
1366     GEOM::TPythonDump(aFunction)
1367       << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1368       << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1369       << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1370   }
1371   //
1372   // Get the groups: END
1373   //
1374
1375   else {
1376     //Make a Python command
1377     GEOM::TPythonDump(aFunction)
1378       << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1379       << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1380       << ", " << theP2 << ", " << theP3 << ")";
1381   }
1382
1383   SetErrorCode(OK);
1384
1385   return aSeq;
1386 }
1387
1388 //=============================================================================
1389 /*!
1390  *  MakePipeTShapeChamfer
1391  *  Create a T-shape object with specified caracteristics for the main and
1392  *  the incident pipes (radius, width, half-length). A chamfer is created
1393  *  on the junction of the pipes.
1394  *  Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1395  *  \param theR1 Internal radius of main pipe
1396  *  \param theW1 Width of main pipe
1397  *  \param theL1 Half-length of main pipe
1398  *  \param theR2 Internal radius of incident pipe (R2 < R1)
1399  *  \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1400  *  \param theL2 Half-length of incident pipe
1401  *  \param theH Height of chamfer.
1402  *  \param theW Width of chamfer.
1403  *  \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1404  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
1405  */
1406 //=============================================================================
1407 Handle(TColStd_HSequenceOfTransient)
1408 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1409                                                     double theR2, double theW2, double theL2,
1410                                                     double theH, double theW,
1411                                                     bool theHexMesh)
1412 {
1413   SetErrorCode(KO);
1414   //Add a new object
1415   Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1416   //Add a new shape function with parameters
1417   Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1418   if (aFunction.IsNull()) return NULL;
1419
1420   //Check if the function is set correctly
1421   if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1422
1423   GEOMImpl_IPipeTShape aData(aFunction);
1424
1425   aData.SetR1(theR1);
1426   aData.SetW1(theW1);
1427   aData.SetL1(theL1);
1428   aData.SetR2(theR2);
1429   aData.SetW2(theW2);
1430   aData.SetL2(theL2);
1431   aData.SetH(theH);
1432   aData.SetW(theW);
1433   aData.SetHexMesh(theHexMesh);
1434
1435   //Compute the resulting value
1436   try {
1437 #if OCC_VERSION_LARGE > 0x06010000
1438     OCC_CATCH_SIGNALS;
1439 #endif
1440     if (!GetSolver()->ComputeFunction(aFunction)) {
1441       SetErrorCode("TShape driver failed");
1442       return NULL;
1443     }
1444   } catch (Standard_Failure) {
1445     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1446     SetErrorCode(aFail->GetMessageString());
1447     return NULL;
1448   }
1449
1450   // BEGIN of chamfer
1451   TopoDS_Shape aShapeShape = aShape->GetValue();
1452   TopTools_IndexedMapOfShape anEdgesIndices;
1453   TopExp::MapShapes(aShapeShape, anEdgesIndices);
1454   // Common edges on external cylinders
1455   Handle(GEOM_Object) box_e;
1456   if (theHexMesh) {
1457     box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1458   }
1459   else {
1460     box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1461   }
1462   box_e->GetLastFunction()->SetDescription("");
1463   box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1464   box_e->GetLastFunction()->SetDescription("");
1465
1466   Handle(TColStd_HSequenceOfInteger) edges_e =
1467     myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1468   box_e->GetLastFunction()->SetDescription("");
1469
1470   if (edges_e.IsNull() || edges_e->Length() == 0) {
1471     SetErrorCode("External edges not found");
1472     return NULL;
1473   }
1474   int nbEdgesInChamfer = 0;
1475   std::list<int> theEdges;
1476   for (int i=1; i<=edges_e->Length();i++) {
1477     int edgeID = edges_e->Value(i);
1478     TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1479     TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1480     int iv=0;
1481     while (Ex.More()) {
1482       iv ++;
1483       gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1484       if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1485         nbEdgesInChamfer ++;
1486         theEdges.push_back(edgeID);
1487       }
1488       Ex.Next();
1489     }
1490     if (theHexMesh && nbEdgesInChamfer == 1)
1491       break;
1492   }
1493   Handle(GEOM_Object) aChamfer;
1494   try {
1495     aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1496   }
1497   catch (Standard_Failure) {
1498     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1499     SetErrorCode(aFail->GetMessageString());
1500     return NULL;
1501   }
1502   if (aChamfer.IsNull()) {
1503     SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1504     return NULL;
1505   }
1506   aChamfer->GetLastFunction()->SetDescription("");
1507
1508   TopoDS_Shape aChamferShape = aChamfer->GetValue();
1509   aFunction->SetValue(aChamferShape);
1510   // END of chamfer
1511
1512   //   bool doMesh = false;
1513   if (theHexMesh) {
1514     //        doMesh = true;
1515     if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1516       MESSAGE("PipeTShape partition failed");
1517       //            doMesh = false;
1518       return NULL;
1519     }
1520     if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1521       MESSAGE("PipeTShape mirrors and glue failed");
1522       //          doMesh = false;
1523       return NULL;
1524     }
1525   }
1526
1527   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1528   aSeq->Append(aShape);
1529
1530   //    if (doMesh) {
1531   if (theHexMesh) {
1532     //
1533     //         Get the groups: BEGIN
1534     //
1535     //if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1536     //  //Make a Python command
1537     //  GEOM::TPythonDump(aFunction)
1538     //    << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1539     //    << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1540     //    << ", " << theHexMesh << ")";
1541     //}
1542     //else {
1543     try {
1544       if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1545         return NULL;
1546     }
1547     catch (Standard_Failure) {
1548       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1549       SetErrorCode(aFail->GetMessageString());
1550       return NULL;
1551     }
1552
1553     TCollection_AsciiString aListRes, anEntry;
1554     // Iterate over the sequence aSeq
1555     Standard_Integer aNbGroups = aSeq->Length();
1556     Standard_Integer i = 2;
1557     for (; i <= aNbGroups; i++) {
1558       Handle(Standard_Transient) anItem = aSeq->Value(i);
1559       if (anItem.IsNull()) continue;
1560       Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1561       if (aGroup.IsNull()) continue;
1562       //Make a Python command
1563       TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1564       aListRes += anEntry + ", ";
1565     }
1566
1567     aListRes.Trunc(aListRes.Length() - 2);
1568
1569     //Make a Python command
1570     GEOM::TPythonDump(aFunction)
1571       << "[" << aShape << ", " << aListRes.ToCString()
1572       << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1573       << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1574     //}
1575   }
1576   //
1577   //     Get the groups: END
1578   //
1579   else {
1580     //Make a Python command
1581     GEOM::TPythonDump(aFunction)
1582       << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1583       << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1584       << ", " << theHexMesh << ")";
1585   }
1586
1587   SetErrorCode(OK);
1588
1589   return aSeq;
1590 }
1591
1592 //=============================================================================
1593 /*!
1594  *  MakePipeTShapeChamferWithPosition
1595  *  Create a T-shape object with specified caracteristics for the main and
1596  *  the incident pipes (radius, width, half-length). A chamfer is created
1597  *  on the junction of the pipes.
1598  *  The extremities of the main pipe are located on junctions points P1 and P2.
1599  *  The extremity of the incident pipe is located on junction point P3.
1600  *  \param theR1 Internal radius of main pipe
1601  *  \param theW1 Width of main pipe
1602  *  \param theL1 Half-length of main pipe
1603  *  \param theR2 Internal radius of incident pipe (R2 < R1)
1604  *  \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1605  *  \param theL2 Half-length of incident pipe
1606  *  \param theH Height of chamfer.
1607  *  \param theW Width of chamfer.
1608  *  \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1609  *  \param theP1 1st junction point of main pipe
1610  *  \param theP2 2nd junction point of main pipe
1611  *  \param theP3 Junction point of incident pipe
1612  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
1613  */
1614 //=============================================================================
1615 Handle(TColStd_HSequenceOfTransient)
1616 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1617                                                                 double theR2, double theW2, double theL2,
1618                                                                 double theH, double theW,
1619                                                                 bool theHexMesh,
1620                                                                 Handle(GEOM_Object) theP1,
1621                                                                 Handle(GEOM_Object) theP2,
1622                                                                 Handle(GEOM_Object) theP3)
1623 {
1624   SetErrorCode(KO);
1625   //Add a new object
1626   Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1627   //Add a new shape function with parameters
1628   Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1629   if (aFunction.IsNull()) return NULL;
1630
1631   //Check if the function is set correctly
1632   if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1633
1634   // Check new position
1635   if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1636     return NULL;
1637   }
1638
1639   GEOMImpl_IPipeTShape aData(aFunction);
1640
1641   aData.SetR1(theR1);
1642   aData.SetW1(theW1);
1643   aData.SetL1(theL1);
1644   aData.SetR2(theR2);
1645   aData.SetW2(theW2);
1646   aData.SetL2(theL2);
1647   aData.SetH(theH);
1648   aData.SetW(theW);
1649   aData.SetHexMesh(theHexMesh);
1650
1651   //Compute the resulting value
1652   try {
1653 #if OCC_VERSION_LARGE > 0x06010000
1654     OCC_CATCH_SIGNALS;
1655 #endif
1656     if (!GetSolver()->ComputeFunction(aFunction)) {
1657       SetErrorCode("TShape driver failed");
1658       return NULL;
1659     }
1660   } catch (Standard_Failure) {
1661     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1662     SetErrorCode(aFail->GetMessageString());
1663     return NULL;
1664   }
1665
1666   // BEGIN of chamfer
1667   TopoDS_Shape aShapeShape = aShape->GetValue();
1668   TopTools_IndexedMapOfShape anEdgesIndices;
1669   TopExp::MapShapes(aShapeShape, anEdgesIndices);
1670   // Common edges on external cylinders
1671   Handle(GEOM_Object) box_e;
1672   if (theHexMesh) {
1673     box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1674   }
1675   else {
1676     box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1677   }
1678   box_e->GetLastFunction()->SetDescription("");
1679   box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1680   box_e->GetLastFunction()->SetDescription("");
1681
1682   Handle(TColStd_HSequenceOfInteger) edges_e =
1683     myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1684   box_e->GetLastFunction()->SetDescription("");
1685
1686   if (edges_e.IsNull() || edges_e->Length() == 0) {
1687     SetErrorCode("External edges not found");
1688     return NULL;
1689   }
1690   int nbEdgesInChamfer = 0;
1691   std::list<int> theEdges;
1692   for (int i=1; i<=edges_e->Length();i++) {
1693     int edgeID = edges_e->Value(i);
1694     TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1695     TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1696     while (Ex.More()) {
1697       gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1698       if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1699         nbEdgesInChamfer ++;
1700         theEdges.push_back(edgeID);
1701       }
1702       Ex.Next();
1703     }
1704     if (theHexMesh && nbEdgesInChamfer == 1)
1705       break;
1706   }
1707   Handle(GEOM_Object) aChamfer;
1708   try {
1709     aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1710   }
1711   catch (Standard_Failure) {
1712     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1713     SetErrorCode(aFail->GetMessageString());
1714     return NULL;
1715   }
1716   if (aChamfer.IsNull()) {
1717     SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1718     return NULL;
1719   }
1720   aChamfer->GetLastFunction()->SetDescription("");
1721
1722   TopoDS_Shape aChamferShape = aChamfer->GetValue();
1723   aFunction->SetValue(aChamferShape);
1724   // END of chamfer
1725
1726   if (theHexMesh) {
1727     if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1728       return NULL;
1729     if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1730       return NULL;
1731   }
1732
1733   TopoDS_Shape Te = aShape->GetValue();
1734
1735   // Set Position
1736   gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1737   BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1738   TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1739   aFunction->SetValue(aTrsf_Shape);
1740   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1741   aSeq->Append(aShape);
1742   if (theHexMesh) {
1743     /*
1744      * Get the groups: BEGIN
1745      */
1746     try {
1747       if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1748         return NULL;
1749     }
1750     catch (Standard_Failure) {
1751       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1752       SetErrorCode(aFail->GetMessageString());
1753       return NULL;
1754     }
1755
1756     TCollection_AsciiString aListRes, anEntry;
1757     // Iterate over the sequence aSeq
1758     Standard_Integer aNbGroups = aSeq->Length();
1759     Standard_Integer i = 2;
1760     for (; i <= aNbGroups; i++) {
1761       Handle(Standard_Transient) anItem = aSeq->Value(i);
1762       if (anItem.IsNull()) continue;
1763       Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1764       if (aGroup.IsNull()) continue;
1765       //Make a Python command
1766       TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1767       aListRes += anEntry + ", ";
1768     }
1769
1770     aListRes.Trunc(aListRes.Length() - 2);
1771
1772     //Make a Python command
1773     GEOM::TPythonDump(aFunction)
1774       << "[" << aShape << ", " << aListRes.ToCString()
1775       << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1776       << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1777       << theP1 << ", " << theP2 << ", " << theP3 << ")";
1778   }
1779   /*
1780    * Get the groups: END
1781    */
1782   else {
1783     //Make a Python command
1784     GEOM::TPythonDump(aFunction)
1785       << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1786       << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1787       << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1788   }
1789
1790   SetErrorCode(OK);
1791
1792   return aSeq;
1793 }
1794
1795 //=============================================================================
1796 /*!
1797  *  MakePipeTShapeFillet
1798  *  Create a T-shape object with specified caracteristics for the main and
1799  *  the incident pipes (radius, width, half-length). A fillet is created
1800  *  on the junction of the pipes.
1801  *  Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1802  *  \param theR1 Internal radius of main pipe
1803  *  \param theW1 Width of main pipe
1804  *  \param theL1 Half-length of main pipe
1805  *  \param theR2 Internal radius of incident pipe (R2 < R1)
1806  *  \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1807  *  \param theL2 Half-length of incident pipe
1808  *  \param theRF Radius of curvature of fillet.
1809  *  \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1810  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
1811  */
1812 //=============================================================================
1813 Handle(TColStd_HSequenceOfTransient)
1814 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1815                                                    double theR2, double theW2, double theL2,
1816                                                    double theRF, bool theHexMesh)
1817 {
1818   SetErrorCode(KO);
1819   //Add a new object
1820   Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1821   //Add a new shape function with parameters
1822   Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1823   if (aFunction.IsNull()) return NULL;
1824
1825   //Check if the function is set correctly
1826   if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1827
1828   GEOMImpl_IPipeTShape aData(aFunction);
1829
1830   aData.SetR1(theR1);
1831   aData.SetW1(theW1);
1832   aData.SetL1(theL1);
1833   aData.SetR2(theR2);
1834   aData.SetW2(theW2);
1835   aData.SetL2(theL2);
1836   aData.SetRF(theRF);
1837   aData.SetHexMesh(theHexMesh);
1838
1839   //Compute the resulting value
1840   try {
1841 #if OCC_VERSION_LARGE > 0x06010000
1842     OCC_CATCH_SIGNALS;
1843 #endif
1844     if (!GetSolver()->ComputeFunction(aFunction)) {
1845       SetErrorCode("TShape driver failed");
1846       return NULL;
1847     }
1848   } catch (Standard_Failure) {
1849     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1850     SetErrorCode(aFail->GetMessageString());
1851     return NULL;
1852   }
1853
1854   // BEGIN of fillet
1855   TopoDS_Shape aShapeShape = aShape->GetValue();
1856   TopTools_IndexedMapOfShape anEdgesIndices;
1857   TopExp::MapShapes(aShapeShape, anEdgesIndices);
1858   // Common edges on external cylinders
1859   Handle(GEOM_Object) box_e;
1860   if (theHexMesh) {
1861     box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1862   }
1863   else {
1864     box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1865   }
1866   box_e->GetLastFunction()->SetDescription("");
1867   box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1868   box_e->GetLastFunction()->SetDescription("");
1869
1870   Handle(TColStd_HSequenceOfInteger) edges_e =
1871     myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1872   box_e->GetLastFunction()->SetDescription("");
1873
1874   if (edges_e.IsNull() || edges_e->Length() == 0) {
1875     SetErrorCode("External edges not found");
1876     return NULL;
1877   }
1878   int nbEdgesInFillet = 0;
1879   std::list<int> theEdges;
1880   for (int i=1; i<=edges_e->Length();i++) {
1881     int edgeID = edges_e->Value(i);
1882     TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1883     TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1884     while (Ex.More()) {
1885       gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1886       if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1887         nbEdgesInFillet ++;
1888         theEdges.push_back(edgeID);
1889       }
1890       Ex.Next();
1891     }
1892     if (theHexMesh && nbEdgesInFillet == 1)
1893       break;
1894   }
1895
1896   Handle(GEOM_Object) aFillet;
1897   try {
1898     aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1899   }
1900   catch (Standard_Failure) {
1901     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1902     SetErrorCode(aFail->GetMessageString());
1903     return NULL;
1904   }
1905   if (aFillet.IsNull()) {
1906     //SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1907     SetErrorCode(myLocalOperations->GetErrorCode());
1908     return NULL;
1909   }
1910   aFillet->GetLastFunction()->SetDescription("");
1911
1912   TopoDS_Shape aFilletShape = aFillet->GetValue();
1913   aFunction->SetValue(aFilletShape);
1914   // END of fillet
1915
1916   // BEGIN: Limit tolerances (debug)
1917   Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
1918   TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
1919   aShape->GetLastFunction()->SetValue(aCorr1Shape);
1920   aCorr1->GetLastFunction()->SetDescription("");
1921   // END: Limit tolerances (debug)
1922
1923   if (theHexMesh) {
1924     if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1925       return NULL;
1926     if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1927       return NULL;
1928   }
1929
1930   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1931   aSeq->Append(aShape);
1932   if (theHexMesh) {
1933     /*
1934      * Get the groups: BEGIN
1935      */
1936     try {
1937       if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1938         return NULL;
1939     }
1940     catch (Standard_Failure) {
1941       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1942       SetErrorCode(aFail->GetMessageString());
1943       return NULL;
1944     }
1945
1946     TCollection_AsciiString aListRes, anEntry;
1947     // Iterate over the sequence aSeq
1948     Standard_Integer aNbGroups = aSeq->Length();
1949     Standard_Integer i = 2;
1950     for (; i <= aNbGroups; i++) {
1951       Handle(Standard_Transient) anItem = aSeq->Value(i);
1952       if (anItem.IsNull()) continue;
1953       Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1954       if (aGroup.IsNull()) continue;
1955       //Make a Python command
1956       TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1957       aListRes += anEntry + ", ";
1958     }
1959
1960     aListRes.Trunc(aListRes.Length() - 2);
1961
1962     //Make a Python command
1963     GEOM::TPythonDump(aFunction)
1964       << "[" << aShape << ", " << aListRes.ToCString()
1965       << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1966       << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
1967   }
1968   /*
1969    * Get the groups: END
1970    */
1971   else {
1972     //Make a Python command
1973     GEOM::TPythonDump(aFunction)
1974       << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
1975       << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
1976       << theHexMesh << ")";
1977   }
1978
1979   SetErrorCode(OK);
1980
1981   return aSeq;
1982 }
1983
1984 //=============================================================================
1985 /*!
1986  *  MakePipeTShapeFilletWithPosition
1987  *  Create a T-shape object with specified caracteristics for the main and
1988  *  the incident pipes (radius, width, half-length). A fillet is created
1989  *  on the junction of the pipes.
1990  *  The extremities of the main pipe are located on junctions points P1 and P2.
1991  *  The extremity of the incident pipe is located on junction point P3.
1992  *  \param theR1 Internal radius of main pipe
1993  *  \param theW1 Width of main pipe
1994  *  \param theL1 Half-length of main pipe
1995  *  \param theR2 Internal radius of incident pipe (R2 < R1)
1996  *  \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1997  *  \param theL2 Half-length of incident pipe
1998  *  \param theRF Radius of curvature of fillet
1999  *  \param theHexMesh Boolean indicating if shape is prepared for hex mesh
2000  *  \param theP1 1st junction point of main pipe
2001  *  \param theP2 2nd junction point of main pipe
2002  *  \param theP3 Junction point of incident pipe
2003  *  \return List of GEOM_Objects, containing the created shape and propagation groups.
2004  */
2005 //=============================================================================
2006 Handle(TColStd_HSequenceOfTransient)
2007 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
2008                                                                double theR2, double theW2, double theL2,
2009                                                                double theRF, bool theHexMesh,
2010                                                                Handle(GEOM_Object) theP1,
2011                                                                Handle(GEOM_Object) theP2,
2012                                                                Handle(GEOM_Object) theP3)
2013 {
2014   SetErrorCode(KO);
2015   //Add a new object
2016   Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
2017   //Add a new shape function with parameters
2018   Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
2019   if (aFunction.IsNull()) return NULL;
2020
2021   //Check if the function is set correctly
2022   if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
2023
2024   // Check new position
2025   if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
2026     return NULL;
2027   }
2028
2029   GEOMImpl_IPipeTShape aData(aFunction);
2030
2031   aData.SetR1(theR1);
2032   aData.SetW1(theW1);
2033   aData.SetL1(theL1);
2034   aData.SetR2(theR2);
2035   aData.SetW2(theW2);
2036   aData.SetL2(theL2);
2037   aData.SetRF(theRF);
2038   aData.SetHexMesh(theHexMesh);
2039
2040   //Compute the resulting value
2041   try {
2042 #if OCC_VERSION_LARGE > 0x06010000
2043     OCC_CATCH_SIGNALS;
2044 #endif
2045     if (!GetSolver()->ComputeFunction(aFunction)) {
2046       SetErrorCode("TShape driver failed");
2047       return NULL;
2048     }
2049   } catch (Standard_Failure) {
2050     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2051     SetErrorCode(aFail->GetMessageString());
2052     return NULL;
2053   }
2054
2055   // BEGIN of fillet
2056   TopoDS_Shape aShapeShape = aShape->GetValue();
2057   TopTools_IndexedMapOfShape anEdgesIndices;
2058   TopExp::MapShapes(aShapeShape, anEdgesIndices);
2059   // Common edges on external cylinders
2060   Handle(GEOM_Object) box_e;
2061   if (theHexMesh) {
2062     box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2063   }
2064   else {
2065     box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2066   }
2067   box_e->GetLastFunction()->SetDescription("");
2068   box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2069   box_e->GetLastFunction()->SetDescription("");
2070
2071   Handle(TColStd_HSequenceOfInteger) edges_e =
2072     myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2073   box_e->GetLastFunction()->SetDescription("");
2074
2075   if (edges_e.IsNull() || edges_e->Length() == 0) {
2076     SetErrorCode("External edges not found");
2077     return NULL;
2078   }
2079   int nbEdgesInFillet = 0;
2080   std::list<int> theEdges;
2081   for (int i=1; i<=edges_e->Length();i++) {
2082     int edgeID = edges_e->Value(i);
2083     TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2084     TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2085     while (Ex.More()) {
2086       gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2087       if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2088         nbEdgesInFillet ++;
2089         theEdges.push_back(edgeID);
2090       }
2091       Ex.Next();
2092     }
2093     if (theHexMesh && nbEdgesInFillet == 1)
2094       break;
2095   }
2096
2097   Handle(GEOM_Object) aFillet;
2098   try {
2099     aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2100   }
2101   catch (Standard_Failure) {
2102     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2103     SetErrorCode(aFail->GetMessageString());
2104     return NULL;
2105   }
2106   if (aFillet.IsNull()) {
2107     SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2108     return NULL;
2109   }
2110   aFillet->GetLastFunction()->SetDescription("");
2111
2112   TopoDS_Shape aFilletShape = aFillet->GetValue();
2113   aFunction->SetValue(aFilletShape);
2114   // END of fillet
2115
2116   // BEGIN: Limit tolerances (debug)
2117   Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
2118   TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
2119   aShape->GetLastFunction()->SetValue(aCorr1Shape);
2120   aCorr1->GetLastFunction()->SetDescription("");
2121   // END: Limit tolerances (debug)
2122
2123   if (theHexMesh) {
2124     if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2125       return NULL;
2126     if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2127       return NULL;
2128   }
2129
2130   TopoDS_Shape Te = aShape->GetValue();
2131
2132   // Set Position
2133   gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2134   BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2135   TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2136   aFunction->SetValue(aTrsf_Shape);
2137   Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2138   aSeq->Append(aShape);
2139   if (theHexMesh) {
2140     /*
2141      * Get the groups: BEGIN
2142      */
2143     try {
2144       if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2145         return NULL;
2146     }
2147     catch (Standard_Failure) {
2148       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2149       SetErrorCode(aFail->GetMessageString());
2150       return NULL;
2151     }
2152
2153     TCollection_AsciiString aListRes, anEntry;
2154     // Iterate over the sequence aSeq
2155     Standard_Integer aNbGroups = aSeq->Length();
2156     Standard_Integer i = 2;
2157     for (; i <= aNbGroups; i++) {
2158       Handle(Standard_Transient) anItem = aSeq->Value(i);
2159       if (anItem.IsNull()) continue;
2160       Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2161       if (aGroup.IsNull()) continue;
2162       //Make a Python command
2163       TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2164       aListRes += anEntry + ", ";
2165     }
2166
2167     aListRes.Trunc(aListRes.Length() - 2);
2168
2169     //Make a Python command
2170     GEOM::TPythonDump(aFunction)
2171       << "[" << aShape << ", " << aListRes.ToCString()
2172       << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2173       << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2174       << theP2 << ", " << theP3 << ")";
2175   }
2176   /*
2177    * Get the groups: END
2178    */
2179   else {
2180     //Make a Python command
2181     GEOM::TPythonDump(aFunction)
2182       << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2183       << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2184       << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2185   }
2186
2187   SetErrorCode(OK);
2188
2189   return aSeq;
2190 }
2191
2192 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/