1 // Copyright (C) 2017-2019 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 // File: GeomAlgoAPI_Cone.cpp
21 // Created: 20 Mar 2017
22 // Author: Clarisse Genrault (CEA)
24 #include <GeomAlgoAPI_Cone.h>
28 #include <BRepPrimAPI_MakeCone.hxx>
30 //=================================================================================================
31 GeomAlgoAPI_Cone::GeomAlgoAPI_Cone(std::shared_ptr<GeomAPI_Ax2> theAxis,
32 const double theBaseRadius,
33 const double theTopRadius,
34 const double theHeight)
37 myBaseRadius = theBaseRadius;
38 myTopRadius = theTopRadius;
42 //=================================================================================================
43 bool GeomAlgoAPI_Cone::check()
46 myError = "Cone builder :: axis is not valid.";
48 } else if (myBaseRadius < Precision::Confusion() && myTopRadius < Precision::Confusion()) {
49 myError = "Cone builder :: base radius and top radius are negative or null.";
51 } else if (myBaseRadius < 0.) {
52 myError = "Cone builder :: base radius is negative.";
54 } else if (myTopRadius < 0.) {
55 myError = "Cone builder :: top radius is negative.";
57 } else if (fabs(myBaseRadius-myTopRadius) < Precision::Confusion()) {
58 myError = "Cone builder :: base radius and top radius are too close.";
60 } else if (myHeight < Precision::Confusion()) {
61 myError = "Cone builder :: height is negative or null.";
67 //=================================================================================================
68 void GeomAlgoAPI_Cone::build()
70 myCreatedFaces.clear();
72 const gp_Ax2& anAxis = myAxis->impl<gp_Ax2>();
74 // Construct the torus
75 BRepPrimAPI_MakeCone *aConeMaker =
76 new BRepPrimAPI_MakeCone(anAxis, myBaseRadius, myTopRadius, myHeight);
80 if (!aConeMaker->IsDone()) {
84 TopoDS_Shape aResult = aConeMaker->Shape();
85 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
86 aShape->setImpl(new TopoDS_Shape(aResult));
90 if (!aShape.get() || aShape->isNull()) {
91 myError = "Torus builder :: resulting shape is null.";