Salome HOME
Add "Torus" primitive and "Cone" primitive.
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Sphere.cpp
1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
2
3 // File:        PrimitivesAPI_Sphere.h
4 // Created:     16 Mar 2017
5 // Author:      Clarisse Genrault
6
7 #include "PrimitivesAPI_Sphere.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Selection.h>
11 #include <ModelHighAPI_Tools.h>
12
13 //==================================================================================================
14 PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                            const ModelHighAPI_Selection& theCenterPoint,
23                                            const ModelHighAPI_Double& theRadius)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if (initialize()) {
27     fillAttribute(theCenterPoint, centerPoint());
28     setRadius(theRadius);
29   }
30 }
31
32 //==================================================================================================
33 PrimitivesAPI_Sphere::~PrimitivesAPI_Sphere()
34 {
35 }
36
37 //==================================================================================================
38 void PrimitivesAPI_Sphere::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
39 {
40   fillAttribute(theCenterPoint, centerPoint());
41   execute();
42 }
43
44 //==================================================================================================
45 void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRadius)
46 {
47   fillAttribute(theRadius, radius());
48   execute();
49 }
50
51 //==================================================================================================
52 void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const
53 {
54   FeaturePtr aBase = feature();
55   const std::string& aDocName = theDumper.name(aBase->document());
56
57   theDumper << aBase << " = model.addSphere(" << aDocName;
58
59   AttributeSelectionPtr anAttrCenterPoint =
60       aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
61   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID());
62   theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius;
63
64   theDumper << ")" << std::endl;
65 }
66
67 //==================================================================================================
68 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
69                     const ModelHighAPI_Selection& theCenterPoint,
70                     const ModelHighAPI_Double& theRadius)
71 {
72   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
73   return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theCenterPoint, theRadius));
74 }
75
76 //==================================================================================================
77 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
78                     const ModelHighAPI_Double& theRadius)
79 {
80   ModelHighAPI_Selection aCenterPoint("VERTEX", "PartSet/Origin");
81   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
82   return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius));
83 }