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