1 // Copyright (C) 2014-2017 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<mailto:webmaster.salome@opencascade.com>
20 #include <GeomAlgoAPI_Cylinder.h>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Shape.hxx>
27 #include <BRepPrimAPI_MakeCylinder.hxx>
31 //=================================================================================================
32 GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder()
36 //=================================================================================================
37 GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder(std::shared_ptr<GeomAPI_Ax2> theAxis,
38 const double theRadius,
39 const double theHeight)
47 //=================================================================================================
48 GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder(std::shared_ptr<GeomAPI_Ax2> theAxis,
49 const double theRadius,
50 const double theHeight,
51 const double theAngle)
60 //=================================================================================================
61 bool GeomAlgoAPI_Cylinder::check()
64 myError = "Cylinder builder :: axis is not valid.";
67 if (myRadius < Precision::Confusion()) {
68 myError = "Cylinder builder :: radius is negative or null.";
71 if (myHeight < Precision::Confusion()) {
72 myError = "Cylinder builder :: height is negative or null.";
76 if (myAngle < Precision::Angular() * 180./M_PI) {
77 myError = "Cylinder builder :: angle is negative or null.";
81 myError = "Cylinder builder :: angle greater than 360 degrees.";
88 //=================================================================================================
89 void GeomAlgoAPI_Cylinder::build()
91 myCreatedFaces.clear();
93 const gp_Ax2& anAxis = myAxis->impl<gp_Ax2>();
95 // Construct the cylinder
96 BRepPrimAPI_MakeCylinder *aCylinderMaker;
100 new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight, myAngle * M_PI / 180.);
102 aCylinderMaker = new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight);
105 aCylinderMaker->Build();
107 if (!aCylinderMaker->IsDone()) {
111 TopoDS_Shape aResult = aCylinderMaker->Shape();
112 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
113 aShape->setImpl(new TopoDS_Shape(aResult));
116 // Test on the shapes
117 if (!aShape.get() || aShape->isNull()) {
118 myError = "Cylinder builder :: resulting shape is null.";
122 setImpl(aCylinderMaker);