Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Cone.cpp
1 // Copyright (C) 2017-2023  CEA, EDF
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 // File:        GeomAlgoAPI_Cone.cpp
21 // Created:     20 Mar 2017
22 // Author:      Clarisse Genrault (CEA)
23
24 #include <GeomAlgoAPI_Cone.h>
25
26 #include <gp_Ax2.hxx>
27
28 #include <BRepPrimAPI_MakeCone.hxx>
29
30 //=================================================================================================
31 GeomAlgoAPI_Cone::GeomAlgoAPI_Cone(std::shared_ptr<GeomAPI_Ax2> theAxis,
32                                    const double theBaseRadius,
33                                    const double theTopRadius,
34                                    const double theHeight)
35 {
36   myAxis = theAxis;
37   myBaseRadius = theBaseRadius;
38   myTopRadius = theTopRadius;
39   myHeight = theHeight;
40 }
41
42 //=================================================================================================
43 bool GeomAlgoAPI_Cone::check()
44 {
45   if (!myAxis) {
46     myError = "Cone builder :: axis is not valid.";
47     return false;
48   } else if (myBaseRadius < Precision::Confusion() && myTopRadius < Precision::Confusion()) {
49     myError = "Cone builder :: base radius and top radius are negative or null.";
50     return false;
51   } else if (myBaseRadius < 0.) {
52     myError = "Cone builder :: base radius is negative.";
53     return false;
54   } else if (myTopRadius < 0.) {
55     myError = "Cone builder :: top radius is negative.";
56     return false;
57   } else if (fabs(myBaseRadius-myTopRadius) < Precision::Confusion()) {
58     myError = "Cone builder :: base radius and top radius are too close.";
59     return false;
60   } else if (myHeight < Precision::Confusion()) {
61     myError = "Cone builder :: height is negative or null.";
62     return false;
63   }
64   return true;
65 }
66
67 //=================================================================================================
68 void GeomAlgoAPI_Cone::build()
69 {
70   myCreatedFaces.clear();
71
72   const gp_Ax2& anAxis = myAxis->impl<gp_Ax2>();
73
74   // Construct the torus
75   BRepPrimAPI_MakeCone *aConeMaker =
76     new BRepPrimAPI_MakeCone(anAxis, myBaseRadius, myTopRadius, myHeight);
77
78   aConeMaker->Build();
79
80   if (!aConeMaker->IsDone()) {
81     return;
82   }
83
84   TopoDS_Shape aResult = aConeMaker->Shape();
85   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
86   aShape->setImpl(new TopoDS_Shape(aResult));
87   setShape(aShape);
88
89   // Test on the shapes
90   if (!aShape.get() || aShape->isNull()) {
91     myError = "Torus builder :: resulting shape is null.";
92     return;
93   }
94
95   setImpl(aConeMaker);
96
97   setDone(true);
98 }