]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp
Salome HOME
[Code coverage GeomAlgoAPI]: Remove default constructors of algorithms
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Torus.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Torus.cpp
4 // Created:     20 Mar 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <GeomAlgoAPI_Torus.h>
8
9 #include <gp_Ax2.hxx>
10
11 #include <BRepPrimAPI_MakeTorus.hxx>
12
13 //=================================================================================================
14 GeomAlgoAPI_Torus::GeomAlgoAPI_Torus(std::shared_ptr<GeomAPI_Ax2> theAxis,
15                                      const double theRadius,
16                                      const double theRingRadius)
17 {
18   myAxis = theAxis;
19   myRadius = theRadius;
20   myRingRadius = theRingRadius;
21 }
22
23 //=================================================================================================
24 bool GeomAlgoAPI_Torus::check()
25 {
26   if (!myAxis) {
27     myError = "Torus builder :: axis is not valid.";
28     return false;
29   } else if (myRadius < Precision::Confusion()) {
30     myError = "Torus builder :: radius is negative or null.";
31     return false;
32   } else if (myRingRadius < Precision::Confusion()) {
33     myError = "Torus builder :: ring radius is negative or null.";
34     return false;
35   } else if (myRadius < myRingRadius) {
36     myError = "Torus builder :: ring radius is greater than the radius.";
37     return false;
38   }
39   return true;
40 }
41
42 //=================================================================================================
43 void GeomAlgoAPI_Torus::build()
44 {
45   myCreatedFaces.clear();
46
47   const gp_Ax2& anAxis = myAxis->impl<gp_Ax2>();
48
49   // Construct the torus
50   BRepPrimAPI_MakeTorus *aTorusMaker =
51     new BRepPrimAPI_MakeTorus(anAxis, myRadius, myRingRadius);
52
53   aTorusMaker->Build();
54
55   if (!aTorusMaker->IsDone()) {
56     return;
57   }
58
59   TopoDS_Shape aResult = aTorusMaker->Shape();
60   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
61   aShape->setImpl(new TopoDS_Shape(aResult));
62   setShape(aShape);
63
64   // Test on the shapes
65   if (!aShape.get() || aShape->isNull()) {
66     myError = "Torus builder :: resulting shape is null.";
67     return;
68   }
69
70   setImpl(aTorusMaker);
71
72   setDone(true);
73 }