Salome HOME
0021684: EDF 2221 : Display the arguments and the name of the operations
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PipeTShapeDriver.cxx
1 // Copyright (C) 2007-2013  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
20 #include <GEOMImpl_PipeTShapeDriver.hxx>
21
22 #include <GEOMImpl_IPipeTShape.hxx>
23 #include <GEOMImpl_Types.hxx>
24 #include <GEOMImpl_Block6Explorer.hxx>
25 #include <GEOMImpl_IAdvancedOperations.hxx>
26
27 #include <GEOM_Function.hxx>
28 #include <GEOM_IOperations.hxx>
29
30 #include <GEOMUtils.hxx>
31
32 #include <GEOMAlgo_FinderShapeOn1.hxx>
33 #include <GEOMAlgo_FinderShapeOn2.hxx>
34 #include <GEOMAlgo_ClsfBox.hxx>
35
36 #include <TFunction_Logbook.hxx>
37 #include <StdFail_NotDone.hxx>
38
39 // Partition includes
40 #include <GEOMAlgo_Splitter.hxx>
41 #include <Geom_CylindricalSurface.hxx>
42
43 #include <gp_Pnt.hxx>
44 #include <gp_Vec.hxx>
45 #include <gp_Ax2.hxx>
46 #include <gp_Pln.hxx>
47 #include <gp_Dir.hxx>
48 #include <gp_Trsf.hxx>
49
50 #include <BRepPrimAPI_MakeCone.hxx>
51 #include <BRepPrimAPI_MakeCylinder.hxx>
52 #include <BRepAlgoAPI_Fuse.hxx>
53 #include <BRepAlgoAPI_Cut.hxx>
54 #include <BRepPrimAPI_MakeBox.hxx>
55 #include <BRepBuilderAPI_MakeEdge.hxx>
56 #include <BRepBuilderAPI_MakeFace.hxx>
57 #include <BRepBuilderAPI_MakeWire.hxx>
58 #include <BRepBuilderAPI_Transform.hxx>
59 #include <BRepFilletAPI_MakeFillet.hxx>
60 #include <BRepFilletAPI_MakeChamfer.hxx>
61 #include <BRep_Builder.hxx>
62 #include <TopoDS_Compound.hxx>
63 #include <TopExp.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <BRep_Tool.hxx>
66 #include <BRepTools.hxx>
67 #include <TopoDS.hxx>
68 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopTools_ListIteratorOfListOfShape.hxx>
70
71 #include <vector>
72 //@@ include required header files here @@//
73
74 //=======================================================================
75 //function : GetID
76 //purpose  :
77 //=======================================================================
78 const Standard_GUID& GEOMImpl_PipeTShapeDriver::GetID()
79 {
80   static Standard_GUID aGUID("1C3A0F3F-729D-4E83-8232-78E74FC5637C");
81   return aGUID;
82 }
83
84 //=======================================================================
85 //function : GEOMImpl_PipeTShapeDriver
86 //purpose  :
87 //=======================================================================
88 GEOMImpl_PipeTShapeDriver::GEOMImpl_PipeTShapeDriver()
89 {
90 }
91
92 //=======================================================================
93 //function : getShapesOnBoxIDs
94   /*!
95    * \brief Find IDs of sub-shapes complying with given status about surface
96     * \param theBox - the box to check state of sub-shapes against
97     * \param theShape - the shape to explore
98     * \param theShapeType - type of sub-shape of theShape
99     * \param theState - required state
100     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
101    */
102 //=======================================================================
103 Handle(TColStd_HSequenceOfInteger)
104 GEOMImpl_PipeTShapeDriver::GetShapesOnBoxIDs(const TopoDS_Shape& aBox,
105                     const TopoDS_Shape& aShape,
106                     const Standard_Integer theShapeType,
107                     GEOMAlgo_State theState) const
108 {
109   Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
110
111   // Check presence of triangulation, build if need
112   if (!GEOMUtils::CheckTriangulation(aShape)) {
113     StdFail_NotDone::Raise("Cannot build triangulation on the shape");
114     return aSeqOfIDs;
115   }
116
117   // Call algo
118   GEOMAlgo_FinderShapeOn2 aFinder;
119   Standard_Real aTol = 0.0001; // default value
120
121   Handle(GEOMAlgo_ClsfBox) aClsfBox = new GEOMAlgo_ClsfBox;
122   aClsfBox->SetBox(aBox);
123
124   aFinder.SetShape(aShape);
125   aFinder.SetTolerance(aTol);
126   aFinder.SetClsf(aClsfBox);
127   aFinder.SetShapeType( (TopAbs_ShapeEnum)theShapeType );
128   aFinder.SetState(theState);
129   aFinder.Perform();
130
131   // Interprete results
132   Standard_Integer iErr = aFinder.ErrorStatus();
133   // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
134   if (iErr) {
135     TCollection_AsciiString aMsg (" iErr : ");
136     aMsg += TCollection_AsciiString(iErr);
137     StdFail_NotDone::Raise(aMsg.ToCString());
138     return aSeqOfIDs;
139   }
140
141
142   const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
143
144   if (listSS.Extent() < 1) {
145     StdFail_NotDone::Raise(NOT_FOUND_ANY); // NPAL18017
146     return aSeqOfIDs;
147   }
148
149   // Fill sequence of object IDs
150   aSeqOfIDs = new TColStd_HSequenceOfInteger;
151
152   TopTools_IndexedMapOfShape anIndices;
153   TopExp::MapShapes(aShape, anIndices);
154
155   TopTools_ListIteratorOfListOfShape itSub (listSS);
156   for (int index = 1; itSub.More(); itSub.Next(), ++index) {
157     int id = anIndices.FindIndex(itSub.Value());
158 //    std::cerr << "Shape with ID " << id << " found" << std::endl;
159     aSeqOfIDs->Append(id);
160   }
161
162   return aSeqOfIDs;
163 }
164
165 //=======================================================================
166 //function : GetShapesOnSurfaceIDs
167   /*!
168    * \brief Find IDs of sub-shapes complying with given status about surface
169     * \param theSurface - the surface to check state of sub-shapes against
170     * \param theShape - the shape to explore
171     * \param theShapeType - type of sub-shape of theShape
172     * \param theState - required state
173     * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found sub-shapes
174    */
175 //=======================================================================
176 Handle(TColStd_HSequenceOfInteger)
177   GEOMImpl_PipeTShapeDriver::GetShapesOnSurfaceIDs(const Handle(Geom_Surface)& theSurface,
178                                                     const TopoDS_Shape&         theShape,
179                                                     TopAbs_ShapeEnum            theShapeType,
180                                                     GEOMAlgo_State              theState) const
181 {
182   Handle(TColStd_HSequenceOfInteger) aSeqOfIDs;
183
184   // Check presence of triangulation, build if need
185   if (!GEOMUtils::CheckTriangulation(theShape)) {
186     StdFail_NotDone::Raise("Cannot build triangulation on the shape");
187     return aSeqOfIDs;
188   }
189
190   // Call algo
191   GEOMAlgo_FinderShapeOn1 aFinder;
192   Standard_Real aTol = 1e-6;
193
194   aFinder.SetShape(theShape);
195   aFinder.SetTolerance(aTol);
196   aFinder.SetSurface(theSurface);
197   aFinder.SetShapeType(theShapeType);
198   aFinder.SetState(theState);
199
200   // Sets the minimal number of inner points for the faces that do not have own
201   // inner points at all (for e.g. rectangular planar faces have just 2 triangles).
202   // Default value=3
203   aFinder.SetNbPntsMin(3);
204   // Sets the maximal number of inner points for edges or faces.
205   // It is usefull for the cases when this number is very big (e.g =2000) to improve
206   // the performance. If this value =0, all inner points will be taken into account.
207   // Default value=0
208   aFinder.SetNbPntsMax(0);
209
210   aFinder.Perform();
211
212   // Interprete results
213   Standard_Integer iErr = aFinder.ErrorStatus();
214   // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx
215   if (iErr) {
216 //    MESSAGE(" iErr : " << iErr);
217     TCollection_AsciiString aMsg (" iErr : ");
218     aMsg += TCollection_AsciiString(iErr);
219     StdFail_NotDone::Raise(aMsg.ToCString());
220     return aSeqOfIDs;
221   }
222 //  Standard_Integer iWrn = aFinder.WarningStatus();
223   // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx
224 //  if (iWrn) {
225 //    MESSAGE(" *** iWrn : " << iWrn);
226 //  }
227
228   const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result
229
230   if (listSS.Extent() < 1) {
231     //StdFail_NotDone::Raise("Not a single sub-shape of the requested type found on the given surface");
232     StdFail_NotDone::Raise(NOT_FOUND_ANY); // NPAL18017
233     return aSeqOfIDs;
234   }
235
236   // Fill sequence of object IDs
237   aSeqOfIDs = new TColStd_HSequenceOfInteger;
238
239   TopTools_IndexedMapOfShape anIndices;
240   TopExp::MapShapes(theShape, anIndices);
241
242   TopTools_ListIteratorOfListOfShape itSub (listSS);
243   for (int index = 1; itSub.More(); itSub.Next(), ++index) {
244     int id = anIndices.FindIndex(itSub.Value());
245     aSeqOfIDs->Append(id);
246   }
247
248   return aSeqOfIDs;
249 }
250
251 //=======================================================================
252 //function : GetCommonShapesOnCylinders
253 //purpose  : return the common shapes between 2 cylindrical surfaces
254 //           along OX and OZ
255 //=======================================================================
256 void GEOMImpl_PipeTShapeDriver::GetCommonShapesOnCylinders(const TopoDS_Shape& theShape,
257                                                            TopAbs_ShapeEnum theShapeType,
258                                                            double r1,
259                                                            double r2,
260                                                            Handle(TopTools_HSequenceOfShape)& commonShapes) const
261 {
262   gp_Pnt aP0 (0, 0, 0);
263   gp_Vec aVX = gp::DX(), aVZ = gp::DZ();
264   gp_Ax3 anAxis1 (aP0, aVX, aVZ), anAxis2 (aP0, aVZ, aVX);
265
266   TopTools_IndexedMapOfShape aMapOfShapes;
267   aMapOfShapes.Clear();
268   TopExp::MapShapes(theShape, aMapOfShapes);
269
270   commonShapes->Clear();
271
272   int myID;
273   bool found = false;
274
275   // Create a cylinder surface
276   Handle(Geom_Surface) aC1Ext = new Geom_CylindricalSurface(anAxis1, r1);
277   if ( aC1Ext.IsNull() )
278     StdFail_NotDone::Raise("Couldn't build main cylindrical surface");
279   // Find object IDs
280   Handle(TColStd_HSequenceOfInteger) aSeqExt1 = GetShapesOnSurfaceIDs( aC1Ext, theShape, theShapeType, GEOMAlgo_ST_ON );
281   // Create a cylinder surface
282   Handle(Geom_Surface) aC2Ext = new Geom_CylindricalSurface(anAxis2, r2);
283   if ( aC2Ext.IsNull() )
284     StdFail_NotDone::Raise("Couldn't build incident cylindrical surface");
285   // Find object IDs
286   Handle(TColStd_HSequenceOfInteger) aSeqExt2 = GetShapesOnSurfaceIDs( aC2Ext, theShape, theShapeType, GEOMAlgo_ST_ON );
287   // # Recherche (dans le quart de Te) de l'arete d'intersection des 2 cylindres
288   // # Search in theShape for common shape of type theShapeType on the intersection of 2 pipes
289   found = false;
290   for (int i=1; i<=aSeqExt2->Length();i++) {
291 //    std::cerr << "aSeqExt2->Value(i): " << aSeqExt2->Value(i) << std::endl;
292     for (int j=1; j<=aSeqExt1->Length();j++) {
293 //      std::cerr << "aSeqExt1->Value(j): " << aSeqExt1->Value(j) << std::endl;
294       if (aSeqExt1->Value(j) == aSeqExt2->Value(i)) {
295         myID = aSeqExt1->Value(j);
296         commonShapes->Append(aMapOfShapes.FindKey(myID));
297         found = true;
298       }
299     }
300   }
301   if (!found)
302     StdFail_NotDone::Raise("Common shapes couldn't be found");
303 }
304
305 //=======================================================================
306 //function : MakePipeTShape
307 //purpose  :
308 //=======================================================================
309 TopoDS_Shape GEOMImpl_PipeTShapeDriver::MakePipeTShape (const double r1, const double w1, const double l1,
310                                                         const double r2, const double w2, const double l2) const
311 {
312   double r1Ext = r1 + w1;
313   double r2Ext = r2 + w2;
314
315   gp_Pnt aP0 (0, 0, 0);
316   gp_Pnt aP1 (-l1, 0, 0);
317   gp_Vec aVX = gp::DX(), aVY = gp::DY(), aVZ = gp::DZ();
318   gp_Ax2 anAxes1 (aP1, aVX, aVZ);
319   gp_Ax2 anAxes2 (aP0, aVZ, aVX);
320
321   // Build the initial pipes
322   BRepPrimAPI_MakeCylinder C1Int (anAxes1, r1, Abs(2 * l1));
323   BRepPrimAPI_MakeCylinder C1Ext (anAxes1, r1Ext, Abs(2 * l1));
324   BRepPrimAPI_MakeCylinder C2Int (anAxes2, r2, Abs(l2));
325   BRepPrimAPI_MakeCylinder C2Ext (anAxes2, r2Ext, Abs(l2));
326   C1Int.Build();
327   C1Ext.Build();
328   C2Int.Build();
329   C2Ext.Build();
330   if (!C1Int.IsDone() || !C1Ext.IsDone() || !C2Int.IsDone() || !C2Ext.IsDone()) {
331     StdFail_NotDone::Raise("Cannot build cylinders");
332   }
333
334   // Fuse the 2 pipes
335   BRepAlgoAPI_Fuse fuse1 (C1Ext.Shape(), C2Ext.Shape());
336   if (!fuse1.IsDone()) {
337     StdFail_NotDone::Raise("Cannot fuse cylinders");
338   }
339
340   // Remove small radius main pipe
341   BRepAlgoAPI_Cut cut1 (fuse1.Shape(), C1Int.Shape());
342   if (!cut1.IsDone()) {
343     StdFail_NotDone::Raise("Coudn't cut cylinders");
344   }
345
346   // Remove small radius incident pipe => Te
347   BRepAlgoAPI_Cut Te (cut1.Shape(), C2Int.Shape());
348   if (!Te.IsDone()) {
349     StdFail_NotDone::Raise("Coudn't cut cylinders");
350   }
351
352   return Te.Shape();
353 }
354
355 //=======================================================================
356 //function : MakeQuarterPipeTShape
357 //purpose  :
358 //=======================================================================
359 TopoDS_Shape GEOMImpl_PipeTShapeDriver::MakeQuarterPipeTShape (const double r1, const double w1, const double l1,
360                                                                const double r2, const double w2, const double l2) const
361 {
362   TopoDS_Shape Te = MakePipeTShape(r1, w1, l1, r2, w2, l2);
363   if (Te.IsNull())
364     StdFail_NotDone::Raise("Couldn't build Pipe TShape");
365
366   // Get a quarter of shape => Te2
367   double r1Ext = r1 + w1;
368   BRepPrimAPI_MakeBox box1 (gp_Pnt(0, -2*r1Ext, -2*r1Ext), gp_Pnt( Abs(2 * l1), 2*r1Ext, Abs(2*l2)));
369   BRepPrimAPI_MakeBox box2 (gp_Pnt(0,  2*r1Ext, -2*r1Ext), gp_Pnt(-Abs(2 * l1), 0,       Abs(2*l2)));
370   box1.Build();
371   box2.Build();
372   if (!box1.IsDone() || !box2.IsDone()) {
373     StdFail_NotDone::Raise("Couldn't build boxes");
374   }
375   BRepAlgoAPI_Cut cut3 (Te, box1.Shape());
376   if (!cut3.IsDone()) {
377     StdFail_NotDone::Raise("Couldn't cut Pipe Tshape with box");
378   }
379   BRepAlgoAPI_Cut Te4 (cut3.Shape(), box2.Shape());
380   if (!Te4.IsDone()) {
381     StdFail_NotDone::Raise("Couldn't cut Pipe Tshape with box");
382   }
383
384   return Te4.Shape();
385 }
386
387 //=======================================================================
388 //function : Execute
389 //purpose  :
390 //=======================================================================
391 Standard_Integer GEOMImpl_PipeTShapeDriver::Execute (TFunction_Logbook& log) const
392 {
393   if (Label().IsNull()) return 0;
394   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
395
396   GEOMImpl_IPipeTShape aData (aFunction);
397   Standard_Integer aType = aFunction->GetType();
398
399   TopoDS_Shape aShape, Te4, Te4Part;
400   //TopoDS_Edge arete_intersect_int;
401   //Handle(TopTools_HSequenceOfShape) edges_e = new TopTools_HSequenceOfShape;
402   Handle(TColStd_HSequenceOfInteger) edges_e;
403   //Handle(TopTools_HSequenceOfShape) edges_i = new TopTools_HSequenceOfShape;
404   //gp_Pnt aP0 (0, 0, 0);
405   //gp_Vec aVX = gp::DX(), aVY = gp::DY(), aVZ = gp::DZ();
406   bool hexMesh = (bool) aData.GetHexMesh();
407
408   // Useful values
409   //double aSize = 2*(aData.GetL1() + aData.GetL2());
410   double epsilon = Precision::Approximation();
411   double aR1Ext = aData.GetR1() + aData.GetW1();
412   double aR2Ext = aData.GetR2() + aData.GetW2();
413
414   if (aData.GetR2() > aData.GetR1() + epsilon) {
415     StdFail_NotDone::Raise("TShape cannot be computed if R2 > R1");
416   }
417
418   if (aR2Ext > aR1Ext + epsilon) {
419     StdFail_NotDone::Raise("TShape cannot be computed if R2+W2 > R1+W1");
420   }
421
422   // external radius are equal
423   if (fabs(aR2Ext - aR1Ext) < epsilon) {
424     if (aType == TSHAPE_CHAMFER)
425       StdFail_NotDone::Raise("TShape with chamfer cannot be computed if R2+W2 = R1+W1");
426     if (aType == TSHAPE_FILLET)
427       StdFail_NotDone::Raise("TShape with fillet cannot be computed if R2+W2 = R1+W1");
428     // internal radius are different => not possible
429     if (fabs(aData.GetR2() - aData.GetR1()) > epsilon) {
430       StdFail_NotDone::Raise("TShape cannot be computed if R2+W2 = R1+W1 and R2 != R1");
431     }
432   }
433
434   if (aR1Ext >= aData.GetL2() + epsilon) {
435     StdFail_NotDone::Raise("TShape cannot be computed if R1+W1 >= L2");
436   }
437   if (aR2Ext >= aData.GetL1() + epsilon) {
438     StdFail_NotDone::Raise("TShape cannot be computed if R2+W2 >= L1");
439   }
440
441   if (aType == TSHAPE_CHAMFER) {
442     if (aData.GetH() >= (aData.GetL2() - aR1Ext + epsilon)) {
443       StdFail_NotDone::Raise("TShape cannot be computed: height of chamfer is too high");
444     }
445
446     if (aData.GetW() >= (aData.GetL1() - aR2Ext + epsilon))
447       StdFail_NotDone::Raise("TShape cannot be computed: width of chamfer is too high");
448   }
449
450   if (aType == TSHAPE_FILLET) {
451     if (aData.GetRF() >= (aData.GetL2() - aR1Ext + epsilon) ||
452         aData.GetRF() >= (aData.GetL1() - aR2Ext + epsilon))
453       StdFail_NotDone::Raise("TShape cannot be computed: radius of fillet is too high");
454   }
455
456   if (hexMesh) {
457     // Create a quarter of a basic T-Shape pipe
458     //std::cerr << "Create a quarter of a basic T-Shape pipe" << std::endl;
459     Te4 = MakeQuarterPipeTShape(aData.GetR1(), aData.GetW1(), aData.GetL1(),
460                                 aData.GetR2(), aData.GetW2(), aData.GetL2());
461   }
462   else {
463     // No need to cut pipe t-shape
464     //std::cerr << "Create a basic T-Shape pipe" << std::endl;
465     Te4 = MakePipeTShape(aData.GetR1(), aData.GetW1(), aData.GetL1(),
466                          aData.GetR2(), aData.GetW2(), aData.GetL2());
467   }
468   aShape = Te4;
469 /*
470   if (aType == TSHAPE_BASIC) {
471       aShape = Te4;
472 //       aShape = MakeQuarterPipeTShape(aData.GetR1(), aData.GetW1(), aData.GetL1(),
473 //       aData.GetR2(), aData.GetW2(), aData.GetL2());
474   }
475   else if (aType == TSHAPE_CHAMFER) {
476     // TShape with chamfer
477 //     BRep_Builder BB;
478 //     TopoDS_Compound CC;
479 //     BB.MakeCompound(CC);
480     // Create chamfer on the edges edges_e
481     BRepFilletAPI_MakeChamfer chamfer (Te4);
482     TopTools_IndexedMapOfShape anEdgesIndices;
483     TopExp::MapShapes(Te4, anEdgesIndices);
484
485     TopoDS_Shape theBox;
486     if (hexMesh) {
487       BRepPrimAPI_MakeBox aBox (gp_Pnt(0,0,0),gp_Pnt(-aR2Ext, -aR2Ext, aR1Ext));
488       aBox.Build();
489       if (!aBox.IsDone()) {
490         StdFail_NotDone::Raise("Couldn't build box");
491       }
492       theBox = aBox.Shape();
493     }
494     else {
495       BRepPrimAPI_MakeBox aBox (gp_Pnt(aR2Ext,aR2Ext,0),gp_Pnt(-aR2Ext, -aR2Ext, aR1Ext));
496       aBox.Build();
497       if (!aBox.IsDone()) {
498         StdFail_NotDone::Raise("Couldn't build box");
499       }
500       theBox = aBox.Shape();
501     }
502     Handle(TColStd_HSequenceOfInteger) edges_e = new TColStd_HSequenceOfInteger;
503     edges_e = GetShapesOnBoxIDs(theBox, Te4, TopAbs_EDGE, GEOMAlgo_ST_IN);
504     if (edges_e.IsNull() || edges_e->Length() == 0) {
505       StdFail_NotDone::Raise("Common edges not found");
506     }
507
508     TopTools_IndexedDataMapOfShapeListOfShape M;
509     GEOMImpl_Block6Explorer::MapShapesAndAncestors(Te4, TopAbs_EDGE, TopAbs_FACE, M);
510 //     std::cerr << "Number of IDs: " << edges_e->Length() << std::endl;
511     int nbEdgesInChamfer = 0;
512     for (int i=1;i<=edges_e->Length();i++) {
513 //       std::cerr << "Get Edge with ID #" << i << std::endl;
514       int theId = edges_e->Value(i);
515 //       std::cerr << "ID #" << i << "= " << theId << std::endl;
516 //       std::cerr << "Search for edge in shape" << std::endl;
517       TopoDS_Edge theEdge = TopoDS::Edge(anEdgesIndices.FindKey(theId));
518 //       std::cerr << "Found" << std::endl;
519 //       std::cerr << "Keep only edges with a vertex on (x, x, re1)" << std::endl;
520       TopExp_Explorer ExVertices;
521       for (ExVertices.Init(theEdge,TopAbs_VERTEX); ExVertices.More(); ExVertices.Next()) {
522         gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(ExVertices.Current()));
523         if (aPt.Z() - aR1Ext <= epsilon) {
524 //           std::cerr << "aPt.Z() = aR1Ext => keep this edge" << std::endl;
525           nbEdgesInChamfer ++;
526           const TopTools_ListOfShape& aFL = M.FindFromKey(theEdge);
527           TopoDS_Face F = TopoDS::Face( aFL.First() );
528           if (hexMesh)
529             chamfer.Add(aData.GetH(), aData.GetW(), theEdge, F);
530           else
531             chamfer.Add(aData.GetW(), aData.GetH(), theEdge, F);
532           break;
533         }
534       }
535 //       std::cerr << "Test if hexMesh: ";
536       if (hexMesh && nbEdgesInChamfer == 1) {
537 //         std::cerr << "Yes => stop after 1 edge" << std::endl;
538         break;
539       }
540 //       std::cerr << "No => continue for other edges" << std::endl;
541   //  BB.Add(CC, edges_e->Value(i));
542   //  const TopTools_ListOfShape& aFL = M.FindFromKey(TopoDS::Edge(edges_e->Value(i)));
543   //  chamfer.Add(aData.GetW(), aData.GetH(), TopoDS::Edge(edges_e->Value(i)), F);
544     }
545 //     std::cerr << "Build chamfer with " << nbEdgesInChamfer << " edges" << std::endl;
546 //     }
547     chamfer.Build();
548     if (!chamfer.IsDone()) {
549       StdFail_NotDone::Raise("Chamfer can not be computed on the given shape with the given parameters");
550     }
551
552 //     BB.Add(CC, chamfer.Shape());
553
554 //     aShape = CC;
555     aShape = chamfer.Shape();
556   }
557   else if (aType == TSHAPE_FILLET) {
558     // TShape with fillet
559     // Create fillet on the edge arete_intersect_ext
560     BRepFilletAPI_MakeFillet fill (Te4);
561
562     TopTools_IndexedMapOfShape anIndices;
563     TopExp::MapShapes(Te4, anIndices);
564
565     TopoDS_Shape theBox;
566     if (hexMesh) {
567       BRepPrimAPI_MakeBox aBox (gp_Pnt(0,0,0),gp_Pnt(-aR2Ext, -aR2Ext, aR1Ext));
568       aBox.Build();
569       if (!aBox.IsDone()) {
570         StdFail_NotDone::Raise("Couldn't build box");
571       }
572       theBox = aBox.Shape();
573     }
574     else {
575       BRepPrimAPI_MakeBox aBox (gp_Pnt(aR2Ext,aR2Ext,0),gp_Pnt(-aR2Ext, -aR2Ext, aR1Ext));
576       aBox.Build();
577       if (!aBox.IsDone()) {
578         StdFail_NotDone::Raise("Couldn't build box");
579       }
580       theBox = aBox.Shape();
581     }
582     Handle(TColStd_HSequenceOfInteger) edges_e = new TColStd_HSequenceOfInteger;
583     edges_e = GetShapesOnBoxIDs(theBox, Te4, TopAbs_EDGE, GEOMAlgo_ST_IN);
584     if (edges_e.IsNull() || edges_e->Length() == 0) {
585       StdFail_NotDone::Raise("Common edges not found");
586     }
587
588 //     fill.Add(TopoDS::Edge(edges_e->Value(1)));
589 //     if (!hexMesh) {
590     for (int i=1;i<=edges_e->Length();i++) {
591       if (hexMesh && (i > 1))
592         break;
593       TopoDS_Edge theEdge = TopoDS::Edge(anIndices.FindKey(edges_e->Value(i)));
594       fill.Add(theEdge);
595 //             fill.Add(TopoDS::Edge(edges_e->Value(i)));
596     }
597 //     }
598     fill.SetRadius(aData.GetRF(), 1, 1);
599     fill.Build();
600     if (!fill.IsDone()) {
601       StdFail_NotDone::Raise("Fillet can't be computed on the given shape with the given radius");
602     }
603
604     aShape = fill.Shape();
605   }
606   else {
607     // other construction modes here
608   }
609 */
610   if (aShape.IsNull()) return 0;
611
612   aFunction->SetValue(aShape);
613
614   log.SetTouched(Label());
615
616   return 1;
617 }
618
619 //================================================================================
620 /*!
621  * \brief Returns a name of creation operation and names and values of creation parameters
622  */
623 //================================================================================
624
625 bool GEOMImpl_PipeTShapeDriver::
626 GetCreationInformation(std::string&             theOperationName,
627                        std::vector<GEOM_Param>& theParams)
628 {
629   if (Label().IsNull()) return 0;
630   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
631
632   GEOMImpl_IPipeTShape aCI( function );
633   Standard_Integer aType = function->GetType();
634
635   theOperationName = "PIPETSHAPE";
636
637   switch ( aType ) {
638   case TSHAPE_BASIC:
639     AddParam( theParams, "Main radius", aCI.GetR1() );
640     AddParam( theParams, "Main width", aCI.GetW1() );
641     AddParam( theParams, "Main half-length", aCI.GetL1() );
642     AddParam( theParams, "Incident pipe radius", aCI.GetR2() );
643     AddParam( theParams, "Incident pipe width", aCI.GetW2() );
644     AddParam( theParams, "Incident pipe half-length", aCI.GetL2() );
645     AddParam( theParams, "For hex mesh", aCI.GetHexMesh() );
646     break;
647   case TSHAPE_CHAMFER:
648     AddParam( theParams, "Main radius", aCI.GetR1() );
649     AddParam( theParams, "Main width", aCI.GetW1() );
650     AddParam( theParams, "Main half-length", aCI.GetL1() );
651     AddParam( theParams, "Incident pipe radius", aCI.GetR2() );
652     AddParam( theParams, "Incident pipe width", aCI.GetW2() );
653     AddParam( theParams, "Incident pipe half-length", aCI.GetL2() );
654     AddParam( theParams, "Chamfer height", aCI.GetH() );
655     AddParam( theParams, "Chamfer width", aCI.GetW() );
656     AddParam( theParams, "For hex mesh", aCI.GetHexMesh() );
657     break;
658   case TSHAPE_FILLET:
659     AddParam( theParams, "Main radius", aCI.GetR1() );
660     AddParam( theParams, "Main width", aCI.GetW1() );
661     AddParam( theParams, "Main half-length", aCI.GetL1() );
662     AddParam( theParams, "Incident pipe radius", aCI.GetR2() );
663     AddParam( theParams, "Incident pipe width", aCI.GetW2() );
664     AddParam( theParams, "Incident pipe half-length", aCI.GetL2() );
665     AddParam( theParams, "Fillet radius", aCI.GetRF() );
666     AddParam( theParams, "For hex mesh", aCI.GetHexMesh() );
667     break;
668   default:
669     return false;
670   }
671   
672   return true;
673 }
674
675 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_PipeTShapeDriver,GEOM_BaseDriver);
676 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_PipeTShapeDriver,GEOM_BaseDriver);