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