1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GeomAlgoAPI_Tube.h>
22 #include <BRepAlgo_FaceRestrictor.hxx>
24 #include <BRepBuilderAPI_MakeEdge.hxx>
25 #include <BRepBuilderAPI_MakeFace.hxx>
26 #include <BRepBuilderAPI_MakeWire.hxx>
27 #include <BRepBuilderAPI_Transform.hxx>
29 #include <BRepPrimAPI_MakePrism.hxx>
31 #include <gp_Circ.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopoDS_Face.hxx>
36 //=================================================================================================
37 GeomAlgoAPI_Tube::GeomAlgoAPI_Tube()
41 //=================================================================================================
42 GeomAlgoAPI_Tube::GeomAlgoAPI_Tube(const double theRMin, const double theRMax, const double theZ)
49 //=================================================================================================
50 bool GeomAlgoAPI_Tube::check()
52 if ((myRMax -myRMin) < Precision::Confusion()) {
53 myError = "Tube builder :: rmin is greater then or equal to rmax.";
55 } else if (myRMin < 0.) {
56 myError = "Tube builder :: rmin is negative.";
58 } else if (myZ < Precision::Confusion()) {
59 myError = "Tube builder :: z is negative or null.";
66 //=================================================================================================
67 void GeomAlgoAPI_Tube::build()
72 //=================================================================================================
73 void GeomAlgoAPI_Tube::buildTube()
75 myCreatedFaces.clear();
77 // Construct the inner and outer circles
78 gp_Pnt anOrigin(0., 0., 0.);
79 gp_Dir aNormal(0., 0., 1.);
80 gp_Circ anInnerCircle(gp_Ax2(anOrigin, aNormal), myRMin);
81 gp_Circ anOuterCircle(gp_Ax2(anOrigin, aNormal), myRMax);
83 // Construct the inner wire
84 BRepBuilderAPI_MakeEdge anInnerCircleBuilder(anInnerCircle);
85 anInnerCircleBuilder.Build();
86 BRepBuilderAPI_MakeWire anInnerWireBuilder;
87 anInnerWireBuilder.Add(anInnerCircleBuilder.Edge());
88 anInnerWireBuilder.Build();
89 TopoDS_Wire anInnerWire(anInnerWireBuilder.Wire());
91 // Construct the outer wire
92 BRepBuilderAPI_MakeEdge anOuterCircleBuilder(anOuterCircle);
93 anOuterCircleBuilder.Build();
94 BRepBuilderAPI_MakeWire anOuterWireBuilder;
95 anOuterWireBuilder.Add(anOuterCircleBuilder.Edge());
96 anOuterWireBuilder.Build();
97 TopoDS_Wire anOuterWire(anOuterWireBuilder.Wire());
99 // Construct the face withe the outer wire
100 BRepBuilderAPI_MakeFace aFaceBuilder(anOuterWire);
101 aFaceBuilder.Build();
102 TopoDS_Face aFace(aFaceBuilder.Face());
104 // Construct the hole face
105 BRepAlgo_FaceRestrictor aFaceRestrictor;
106 aFaceRestrictor.Init(aFace, Standard_False, Standard_True);
107 aFaceRestrictor.Add(anInnerWire);
108 aFaceRestrictor.Add(anOuterWire);
109 aFaceRestrictor.Perform();
110 aFace = TopoDS_Face(aFaceRestrictor.Current());
112 // Construct the tube
113 gp_Vec aVec(aNormal);
115 aTrsf.SetTranslation(aVec * -myZ/2);
116 BRepBuilderAPI_Transform *aTranformBuilder = new BRepBuilderAPI_Transform(aFace, aTrsf);
117 if (!aTranformBuilder || !aTranformBuilder->IsDone()) {
118 myError = "Tube builder :: algorithm failed";
121 TopoDS_Shape aMovedBase = aTranformBuilder->Shape();
122 BRepPrimAPI_MakePrism *aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aVec * myZ);
124 std::shared_ptr<GeomAPI_Shape> aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
125 aShape->setImpl(new TopoDS_Shape(aPrismBuilder->Shape()));
128 setImpl(aPrismBuilder);
129 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);