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 theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius;
145 theDumper << ")" << std::endl;
148 //==================================================================================================
149 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
150 const ModelHighAPI_Selection& theCenterPoint,
151 const ModelHighAPI_Double& theRadius)
153 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
154 return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theCenterPoint, theRadius));
157 //==================================================================================================
158 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
159 const ModelHighAPI_Double& theRadius)
161 ModelHighAPI_Selection aCenterPoint("VERTEX", L"PartSet/Origin");
162 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
163 return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius));
166 //==================================================================================================
167 SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
168 const ModelHighAPI_Double& theRMin,
169 const ModelHighAPI_Double& theRMax,
170 const ModelHighAPI_Double& thePhiMin,
171 const ModelHighAPI_Double& thePhiMax,
172 const ModelHighAPI_Double& theThetaMin,
173 const ModelHighAPI_Double& theThetaMax)
175 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
176 return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theRMin, theRMax, thePhiMin, thePhiMax,
177 theThetaMin, theThetaMax));