]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Cone.cpp
Salome HOME
Merge remote-tracking branch 'origin/Toolbars_Management'
[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(std::shared_ptr<GeomAPI_Ax2> theAxis,
15                                    const double theBaseRadius,
16                                    const double theTopRadius,
17                                    const double theHeight)
18 {
19   myAxis = theAxis;
20   myBaseRadius = theBaseRadius;
21   myTopRadius = theTopRadius;
22   myHeight = theHeight;
23 }
24
25 //=================================================================================================
26 bool GeomAlgoAPI_Cone::check()
27 {
28   if (!myAxis) {
29     myError = "Cone builder :: axis is not valid.";
30     return false;
31   } else if (myBaseRadius < Precision::Confusion() && myTopRadius < Precision::Confusion()) {
32     myError = "Cone builder :: base radius and top radius are negative or null.";
33     return false;
34   } else if (myBaseRadius < 0.) {
35     myError = "Cone builder :: base radius is negative.";
36     return false;
37   } else if (myTopRadius < 0.) {
38     myError = "Cone builder :: top radius is negative.";
39     return false;
40   } else if (fabs(myBaseRadius-myTopRadius) < Precision::Confusion()) {
41     myError = "Cone builder :: base radius and top radius are too close.";
42     return false;
43   } else if (myHeight < Precision::Confusion()) {
44     myError = "Cone builder :: height is negative or null.";
45     return false;
46   }
47   return true;
48 }
49
50 //=================================================================================================
51 void GeomAlgoAPI_Cone::build()
52 {
53   myCreatedFaces.clear();
54
55   const gp_Ax2& anAxis = myAxis->impl<gp_Ax2>();
56
57   // Construct the torus
58   BRepPrimAPI_MakeCone *aConeMaker =
59     new BRepPrimAPI_MakeCone(anAxis, myBaseRadius, myTopRadius, myHeight);
60
61   aConeMaker->Build();
62
63   if (!aConeMaker->IsDone()) {
64     return;
65   }
66
67   TopoDS_Shape aResult = aConeMaker->Shape();
68   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
69   aShape->setImpl(new TopoDS_Shape(aResult));
70   setShape(aShape);
71
72   // Test on the shapes
73   if (!aShape.get() || aShape->isNull()) {
74     myError = "Torus builder :: resulting shape is null.";
75     return;
76   }
77
78   setImpl(aConeMaker);
79
80   setDone(true);
81 }