Salome HOME
Merge remote-tracking branch 'remotes/origin/EDF_2020_Lot2'
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Sphere.cpp
1 // Copyright (C) 2017-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        PrimitivesAPI_Sphere.h
21 // Created:     16 Mar 2017
22 // Author:      Clarisse Genrault
23
24 #include "PrimitivesAPI_Sphere.h"
25
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
29
30 //==================================================================================================
31 PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : ModelHighAPI_Interface(theFeature)
33 {
34   initialize();
35 }
36
37 //==================================================================================================
38 PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature,
39                                            const ModelHighAPI_Selection& theCenterPoint,
40                                            const ModelHighAPI_Double& theRadius)
41 : ModelHighAPI_Interface(theFeature)
42 {
43   if (initialize()) {
44     fillAttribute(theCenterPoint, centerPoint());
45     setRadius(theRadius);
46   }
47 }
48
49 //==================================================================================================
50 PrimitivesAPI_Sphere::~PrimitivesAPI_Sphere()
51 {
52 }
53
54 //==================================================================================================
55 void PrimitivesAPI_Sphere::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
56 {
57   fillAttribute(theCenterPoint, centerPoint());
58   execute();
59 }
60
61 //==================================================================================================
62 void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRadius)
63 {
64   fillAttribute(theRadius, radius());
65   execute();
66 }
67
68 //==================================================================================================
69 void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const
70 {
71   FeaturePtr aBase = feature();
72   const std::string& aDocName = theDumper.name(aBase->document());
73
74   theDumper << aBase << " = model.addSphere(" << aDocName;
75
76   AttributeSelectionPtr anAttrCenterPoint =
77       aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
78   AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID());
79   theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius;
80
81   theDumper << ")" << std::endl;
82 }
83
84 //==================================================================================================
85 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
86                     const ModelHighAPI_Selection& theCenterPoint,
87                     const ModelHighAPI_Double& theRadius)
88 {
89   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
90   return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theCenterPoint, theRadius));
91 }
92
93 //==================================================================================================
94 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
95                     const ModelHighAPI_Double& theRadius)
96 {
97   ModelHighAPI_Selection aCenterPoint("VERTEX", L"PartSet/Origin");
98   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
99   return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius));
100 }