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