1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchAPI_Circle.cpp
4 // Created: 09 June 2016
5 // Author: Dmitry Bobylev
7 #include "SketchAPI_Circle.h"
9 #include <GeomAPI_Pnt2d.h>
11 #include <ModelHighAPI_Double.h>
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
16 //==================================================================================================
17 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
23 //==================================================================================================
24 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
28 : SketchAPI_SketchEntity(theFeature)
31 setByCenterAndRadius(theCenterX, theCenterY, theRadius);
35 //==================================================================================================
36 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
39 : SketchAPI_SketchEntity(theFeature)
42 setByCenterAndRadius(theCenter, theRadius);
46 //==================================================================================================
47 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48 double theX1, double theY1,
49 double theX2, double theY2,
50 double theX3, double theY3)
51 : SketchAPI_SketchEntity(theFeature)
54 setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
58 //==================================================================================================
59 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
60 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
61 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
62 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
63 : SketchAPI_SketchEntity(theFeature)
66 setByThreePoints(thePoint1, thePoint2, thePoint3);
70 //==================================================================================================
71 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72 const ModelHighAPI_Selection& theExternal)
73 : SketchAPI_SketchEntity(theFeature)
76 setByExternal(theExternal);
80 //==================================================================================================
81 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
82 const std::string& theExternalName)
83 : SketchAPI_SketchEntity(theFeature)
86 setByExternalName(theExternalName);
90 //==================================================================================================
91 SketchAPI_Circle::~SketchAPI_Circle()
96 //==================================================================================================
97 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
99 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
100 fillAttribute(center(), theCenterX, theCenterY);
101 fillAttribute(theRadius, myradius);
106 //==================================================================================================
107 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
110 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
111 fillAttribute(theCenter, mycenter);
112 fillAttribute(theRadius, myradius);
117 //==================================================================================================
118 void SketchAPI_Circle::setByThreePoints(double theX1, double theY1,
119 double theX2, double theY2,
120 double theX3, double theY3)
122 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
123 fillAttribute(firstPoint(), theX1, theY1);
124 fillAttribute(secondPoint(), theX2, theY2);
125 fillAttribute(thirdPoint(), theX3, theY3);
130 //==================================================================================================
131 void SketchAPI_Circle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
132 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
133 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
135 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
136 fillAttribute(thePoint1, myfirstPoint);
137 fillAttribute(thePoint2, mysecondPoint);
138 fillAttribute(thePoint3, mythirdPoint);
143 //==================================================================================================
144 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
146 fillAttribute(theExternal, external());
151 //==================================================================================================
152 void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
154 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
159 //==================================================================================================
160 void SketchAPI_Circle::setCenter(double theX, double theY)
162 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
163 fillAttribute(center(), theX, theY);
168 //==================================================================================================
169 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
171 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
172 fillAttribute(theCenter, mycenter);
177 //==================================================================================================
178 void SketchAPI_Circle::setRadius(double theRadius)
180 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
181 fillAttribute(ModelHighAPI_Double(theRadius), myradius);
186 //==================================================================================================
187 void SketchAPI_Circle::setFirstPoint(double theX, double theY)
189 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
190 fillAttribute(firstPoint(), theX, theY);
195 //==================================================================================================
196 void SketchAPI_Circle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
198 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
199 fillAttribute(thePoint, myfirstPoint);
204 //==================================================================================================
205 void SketchAPI_Circle::setSecondPoint(double theX, double theY)
207 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
208 fillAttribute(secondPoint(), theX, theY);
213 //==================================================================================================
214 void SketchAPI_Circle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
216 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
217 fillAttribute(thePoint, mysecondPoint);
222 //==================================================================================================
223 void SketchAPI_Circle::setThirdPoint(double theX, double theY)
225 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
226 fillAttribute(thirdPoint(), theX, theY);
231 //==================================================================================================
232 void SketchAPI_Circle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
234 fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
235 fillAttribute(thePoint, mythirdPoint);
240 //==================================================================================================
241 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
244 return; // no need to dump copied feature
246 FeaturePtr aBase = feature();
247 const std::string& aSketchName = theDumper.parentName(aBase);
249 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
250 if (anExternal->context()) {
251 // circle is external
252 theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
254 AttributeStringPtr aType = circleType();
255 if (aType->value() == SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS()) {
256 // circle given by center and radius
257 theDumper << aBase << " = " << aSketchName << ".addCircle("
258 << center() << ", " << radius() << ")" << std::endl;
260 // circle given by three points
261 theDumper << aBase << " = " << aSketchName << ".addCircle(" << firstPoint() << ", "
262 << secondPoint() << ", " << thirdPoint() << ")" << std::endl;
265 // dump "auxiliary" flag if necessary
266 SketchAPI_SketchEntity::dump(theDumper);