1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketchAPI_Circle.h"
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModelHighAPI_Double.h>
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
30 //==================================================================================================
31 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
32 : SketchAPI_SketchEntity(theFeature)
37 //==================================================================================================
38 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
42 : SketchAPI_SketchEntity(theFeature)
45 setByCenterAndRadius(theCenterX, theCenterY, theRadius);
49 //==================================================================================================
50 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
51 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
53 : SketchAPI_SketchEntity(theFeature)
56 setByCenterAndRadius(theCenter, theRadius);
60 //==================================================================================================
61 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
62 const ModelHighAPI_Selection& theExternal)
63 : SketchAPI_SketchEntity(theFeature)
66 setByExternal(theExternal);
70 //==================================================================================================
71 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72 const std::string& theExternalName)
73 : SketchAPI_SketchEntity(theFeature)
76 setByExternalName(theExternalName);
80 //==================================================================================================
81 SketchAPI_Circle::~SketchAPI_Circle()
86 //==================================================================================================
87 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
89 fillAttribute(center(), theCenterX, theCenterY);
90 fillAttribute(theRadius, myradius);
95 //==================================================================================================
96 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
99 fillAttribute(theCenter, mycenter);
100 fillAttribute(theRadius, myradius);
105 //==================================================================================================
106 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
108 fillAttribute(theExternal, external());
113 //==================================================================================================
114 void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
116 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
121 //==================================================================================================
122 void SketchAPI_Circle::setCenter(double theX, double theY)
124 fillAttribute(center(), theX, theY);
129 //==================================================================================================
130 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
132 fillAttribute(theCenter, mycenter);
137 //==================================================================================================
138 void SketchAPI_Circle::setRadius(double theRadius)
140 fillAttribute(ModelHighAPI_Double(theRadius), myradius);
145 //==================================================================================================
146 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
149 return; // no need to dump copied feature
151 FeaturePtr aBase = feature();
152 const std::string& aSketchName = theDumper.parentName(aBase);
154 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
155 if (anExternal->context()) {
156 // circle is external
157 theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
159 // circle given by center and radius
160 theDumper << aBase << " = " << aSketchName << ".addCircle("
161 << center() << ", " << radius() << ")" << std::endl;
163 // dump "auxiliary" flag if necessary
164 SketchAPI_SketchEntity::dump(theDumper);