]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp
Salome HOME
Merge branch 'master' into cgt/devCEA
[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()
15 {
16 }
17
18 //=================================================================================================
19 GeomAlgoAPI_Torus::GeomAlgoAPI_Torus(std::shared_ptr<GeomAPI_Ax2> theAxis,
20                                      const double theRadius,
21                                      const double theRingRadius)
22 {
23   myAxis = theAxis;
24   myRadius = theRadius;
25   myRingRadius = theRingRadius;
26 }
27
28 //=================================================================================================
29 bool GeomAlgoAPI_Torus::check()
30 {
31   if (!myAxis) {
32     myError = "Torus builder :: axis is not valid.";
33     return false;
34   } else if (myRadius < Precision::Confusion()) {
35     myError = "Torus builder :: radius is negative or null.";
36     return false;
37   } else if (myRingRadius < Precision::Confusion()) {
38     myError = "Torus builder :: ring radius is negative or null.";
39     return false;
40   } else if (myRadius < myRingRadius) {
41     myError = "Torus builder :: ring radius is greater than the radius.";
42     return false;
43   }
44   return true;
45 }
46
47 //=================================================================================================
48 void GeomAlgoAPI_Torus::build()
49 {
50   myCreatedFaces.clear();
51
52   const gp_Ax2& anAxis = myAxis->impl<gp_Ax2>();
53
54   // Construct the torus
55   BRepPrimAPI_MakeTorus *aTorusMaker =
56     new BRepPrimAPI_MakeTorus(anAxis, myRadius, myRingRadius);
57
58   aTorusMaker->Build();
59
60   if (!aTorusMaker->IsDone()) {
61     return;
62   }
63
64   TopoDS_Shape aResult = aTorusMaker->Shape();
65   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
66   aShape->setImpl(new TopoDS_Shape(aResult));
67   setShape(aShape);
68
69   // Test on the shapes
70   if (!aShape.get() || aShape->isNull()) {
71     myError = "Torus builder :: resulting shape is null.";
72     return;
73   }
74
75   setImpl(aTorusMaker);
76
77   setDone(true);
78 }