Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Sphere.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Sphere.h
4 // Created:     16 Mar 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <GeomAlgoAPI_Sphere.h>
8
9 #include <BRepPrimAPI_MakeSphere.hxx>
10
11 //=================================================================================================
12 GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere()
13 {
14 }
15
16 //=================================================================================================
17 GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere(std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
18                                        const double theRadius)
19 {
20   myCenterPoint = theCenterPoint;
21   myRadius = theRadius;
22 }
23
24 //=================================================================================================
25 bool GeomAlgoAPI_Sphere::check()
26 {
27   if (!myCenterPoint) {
28     myError = "Sphere builder :: center is not valid.";
29     return false;
30   }
31   if (myRadius < Precision::Confusion()) {
32     myError = "Sphere builder :: radius is negative or null.";
33     return false;
34   }
35   return true;
36 }
37
38 //=================================================================================================
39 void GeomAlgoAPI_Sphere::build()
40 {
41   myCreatedFaces.clear();
42
43   const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
44
45   // Construct the sphere
46   BRepPrimAPI_MakeSphere *aSphereMaker = new BRepPrimAPI_MakeSphere(aCenterPoint, myRadius);
47
48   aSphereMaker->Build();
49
50   if (!aSphereMaker->IsDone()) {
51     return;
52   }
53
54   TopoDS_Shape aResult = aSphereMaker->Shape();
55   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
56   aShape->setImpl(new TopoDS_Shape(aResult));
57   setShape(aShape);
58
59   // Test on the shapes
60   if (!aShape.get() || aShape->isNull()) {
61     myError = "Sphere builder :: resulting shape is null.";
62     return;
63   }
64
65   setImpl(aSphereMaker);
66
67   setDone(true);
68 }