1 // Copyright (C) 2017-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: PrimitivesAPI_Sphere.h
21 // Created: 16 Mar 2017
22 // Author: Clarisse Genrault
24 #include "PrimitivesAPI_Sphere.h"
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
30 //==================================================================================================
31 PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : ModelHighAPI_Interface(theFeature)
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)
44 fillAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD_BY_PT_RADIUS(), creationMethod());
45 fillAttribute(theCenterPoint, centerPoint());
50 //==================================================================================================
51 PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature,
52 const ModelHighAPI_Double& theRMin,
53 const ModelHighAPI_Double& theRMax,
54 const ModelHighAPI_Double& thePhiMin,
55 const ModelHighAPI_Double& thePhiMax,
56 const ModelHighAPI_Double& theThetaMin,
57 const ModelHighAPI_Double& theThetaMax)
58 : ModelHighAPI_Interface(theFeature)
61 fillAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
62 fillAttribute(theRMin, rmin());
63 fillAttribute(theRMax, rmax());
64 fillAttribute(thePhiMin, phimin());
65 fillAttribute(thePhiMax, phimax());
66 fillAttribute(theThetaMin, thetamin());
67 fillAttribute(theThetaMax, thetamax());
72 //==================================================================================================
73 PrimitivesAPI_Sphere::~PrimitivesAPI_Sphere()
77 //==================================================================================================
78 void PrimitivesAPI_Sphere::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
80 fillAttribute(theCenterPoint, centerPoint());
84 //==================================================================================================
85 void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRadius)
87 fillAttribute(theRadius, radius());
91 //==================================================================================================
92 void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRMin,
93 const ModelHighAPI_Double& theRMax)
95 fillAttribute(theRMin, rmin());
96 fillAttribute(theRMax, rmax());
100 //==================================================================================================
101 void PrimitivesAPI_Sphere::setPhi(const ModelHighAPI_Double& thePhiMin,
102 const ModelHighAPI_Double& thePhiMax)
104 fillAttribute(thePhiMin, phimin());
105 fillAttribute(thePhiMax, phimax());
109 //==================================================================================================
110 void PrimitivesAPI_Sphere::setTheta(const ModelHighAPI_Double& theThetaMin,
111 const ModelHighAPI_Double& theThetaMax)
113 fillAttribute(theThetaMin, thetamin());
114 fillAttribute(theThetaMax, thetamax());
118 //==================================================================================================
119 void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const
121 FeaturePtr aBase = feature();
122 const std::string& aDocName = theDumper.name(aBase->document());
124 theDumper << aBase << " = model.addSphere(" << aDocName;
126 std::string aCreationMethod = aBase->string(PrimitivesPlugin_Sphere::CREATION_METHOD())->value();
128 if (aCreationMethod == PrimitivesPlugin_Sphere::CREATION_METHOD_BY_DIMENSIONS()) {
129 AttributeDoublePtr anAttrRMin = aBase->real(PrimitivesPlugin_Sphere::RMIN_ID());
130 AttributeDoublePtr anAttrRMax = aBase->real(PrimitivesPlugin_Sphere::RMAX_ID());
131 AttributeDoublePtr anAttrPhiMin = aBase->real(PrimitivesPlugin_Sphere::PHIMIN_ID());
132 AttributeDoublePtr anAttrPhiMax = aBase->real(PrimitivesPlugin_Sphere::PHIMAX_ID());
133 AttributeDoublePtr anAttrThetaMin = aBase->real(PrimitivesPlugin_Sphere::THETAMIN_ID());
134 AttributeDoublePtr anAttrThetaMax = aBase->real(PrimitivesPlugin_Sphere::THETAMAX_ID());
135 theDumper << ", " << anAttrRMin << ", " << anAttrRMax;
136 theDumper << ", " << anAttrPhiMin << ", " << anAttrPhiMax;
137 theDumper << ", " << anAttrThetaMin << ", " << anAttrThetaMax;
138 } else { // CREATION_METHOD_BY_PT_RADIUS by default to support versions with undefined method
139 AttributeSelectionPtr anAttrCenterPoint =
140 aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
141 AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID());
142 // for old versions radius value was located in another place, so, use the default 10
143 double aRadValue = anAttrRadius->isInitialized() ? anAttrRadius->value() : 10;
144 theDumper << ", " << anAttrCenterPoint << ", " << aRadValue;
147 theDumper << ")" << std::endl;
150 //==================================================================================================
151 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
152 const ModelHighAPI_Selection& theCenterPoint,
153 const ModelHighAPI_Double& theRadius)
155 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
156 return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theCenterPoint, theRadius));
159 //==================================================================================================
160 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
161 const ModelHighAPI_Double& theRadius)
163 ModelHighAPI_Selection aCenterPoint("VERTEX", L"PartSet/Origin");
164 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
165 return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius));
168 //==================================================================================================
169 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
170 const ModelHighAPI_Double& theRMin,
171 const ModelHighAPI_Double& theRMax,
172 const ModelHighAPI_Double& thePhiMin,
173 const ModelHighAPI_Double& thePhiMax,
174 const ModelHighAPI_Double& theThetaMin,
175 const ModelHighAPI_Double& theThetaMax)
177 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
178 return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theRMin, theRMax, thePhiMin, thePhiMax,
179 theThetaMin, theThetaMax));