Salome HOME
[Code coverage GeomAlgoAPI]: Remove default constructors of algorithms
[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(std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
13                                        const double theRadius)
14 {
15   myCenterPoint = theCenterPoint;
16   myRadius = theRadius;
17 }
18
19 //=================================================================================================
20 bool GeomAlgoAPI_Sphere::check()
21 {
22   if (!myCenterPoint) {
23     myError = "Sphere builder :: center is not valid.";
24     return false;
25   }
26   if (myRadius < Precision::Confusion()) {
27     myError = "Sphere builder :: radius is negative or null.";
28     return false;
29   }
30   return true;
31 }
32
33 //=================================================================================================
34 void GeomAlgoAPI_Sphere::build()
35 {
36   myCreatedFaces.clear();
37
38   const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
39
40   // Construct the sphere
41   BRepPrimAPI_MakeSphere *aSphereMaker = new BRepPrimAPI_MakeSphere(aCenterPoint, myRadius);
42
43   aSphereMaker->Build();
44
45   if (!aSphereMaker->IsDone()) {
46     return;
47   }
48
49   TopoDS_Shape aResult = aSphereMaker->Shape();
50   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
51   aShape->setImpl(new TopoDS_Shape(aResult));
52   setShape(aShape);
53
54   // Test on the shapes
55   if (!aShape.get() || aShape->isNull()) {
56     myError = "Sphere builder :: resulting shape is null.";
57     return;
58   }
59
60   setImpl(aSphereMaker);
61
62   setDone(true);
63 }