Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / SketchAPI / SketchAPI_Circle.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchAPI_Circle.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "SketchAPI_Circle.h"
8
9 #include <GeomAPI_Pnt2d.h>
10
11 #include <ModelHighAPI_Double.h>
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
15
16 //==================================================================================================
17 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
19 {
20   initialize();
21 }
22
23 //==================================================================================================
24 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
25                                    double theCenterX,
26                                    double theCenterY,
27                                    double theRadius)
28 : SketchAPI_SketchEntity(theFeature)
29 {
30   if(initialize()) {
31     setByCenterAndRadius(theCenterX, theCenterY, theRadius);
32   }
33 }
34
35 //==================================================================================================
36 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                                    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
38                                    double theRadius)
39 : SketchAPI_SketchEntity(theFeature)
40 {
41   if(initialize()) {
42     setByCenterAndRadius(theCenter, theRadius);
43   }
44 }
45
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)
52 {
53   if (initialize()) {
54     setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
55   }
56 }
57
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)
64 {
65   if (initialize()) {
66     setByThreePoints(thePoint1, thePoint2, thePoint3);
67   }
68 }
69
70 //==================================================================================================
71 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72                                    const ModelHighAPI_Selection& theExternal)
73 : SketchAPI_SketchEntity(theFeature)
74 {
75   if (initialize()) {
76     setByExternal(theExternal);
77   }
78 }
79
80 //==================================================================================================
81 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
82                                    const std::string& theExternalName)
83 : SketchAPI_SketchEntity(theFeature)
84 {
85   if (initialize()) {
86     setByExternalName(theExternalName);
87   }
88 }
89
90 //==================================================================================================
91 SketchAPI_Circle::~SketchAPI_Circle()
92 {
93
94 }
95
96 //==================================================================================================
97 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
98 {
99   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
100   fillAttribute(center(), theCenterX, theCenterY);
101   fillAttribute(theRadius, myradius);
102
103   execute();
104 }
105
106 //==================================================================================================
107 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
108                                             double theRadius)
109 {
110   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
111   fillAttribute(theCenter, mycenter);
112   fillAttribute(theRadius, myradius);
113
114   execute();
115 }
116
117 //==================================================================================================
118 void SketchAPI_Circle::setByThreePoints(double theX1, double theY1,
119                                         double theX2, double theY2,
120                                         double theX3, double theY3)
121 {
122   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
123   fillAttribute(firstPoint(), theX1, theY1);
124   fillAttribute(secondPoint(), theX2, theY2);
125   fillAttribute(thirdPoint(), theX3, theY3);
126
127   execute();
128 }
129
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)
134 {
135   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
136   fillAttribute(thePoint1, myfirstPoint);
137   fillAttribute(thePoint2, mysecondPoint);
138   fillAttribute(thePoint3, mythirdPoint);
139
140   execute();
141 }
142
143 //==================================================================================================
144 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
145 {
146   fillAttribute(theExternal, external());
147
148   execute();
149 }
150
151 //==================================================================================================
152 void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
153 {
154   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
155
156   execute();
157 }
158
159 //==================================================================================================
160 void SketchAPI_Circle::setCenter(double theX, double theY)
161 {
162   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
163   fillAttribute(center(), theX, theY);
164
165   execute();
166 }
167
168 //==================================================================================================
169 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
170 {
171   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
172   fillAttribute(theCenter, mycenter);
173
174   execute();
175 }
176
177 //==================================================================================================
178 void SketchAPI_Circle::setRadius(double theRadius)
179 {
180   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
181   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
182
183   execute();
184 }
185
186 //==================================================================================================
187 void SketchAPI_Circle::setFirstPoint(double theX, double theY)
188 {
189   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
190   fillAttribute(firstPoint(), theX, theY);
191
192   execute();
193 }
194
195 //==================================================================================================
196 void SketchAPI_Circle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
197 {
198   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
199   fillAttribute(thePoint, myfirstPoint);
200
201   execute();
202 }
203
204 //==================================================================================================
205 void SketchAPI_Circle::setSecondPoint(double theX, double theY)
206 {
207   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
208   fillAttribute(secondPoint(), theX, theY);
209
210   execute();
211 }
212
213 //==================================================================================================
214 void SketchAPI_Circle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
215 {
216   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
217   fillAttribute(thePoint, mysecondPoint);
218
219   execute();
220 }
221
222 //==================================================================================================
223 void SketchAPI_Circle::setThirdPoint(double theX, double theY)
224 {
225   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
226   fillAttribute(thirdPoint(), theX, theY);
227
228   execute();
229 }
230
231 //==================================================================================================
232 void SketchAPI_Circle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
233 {
234   fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
235   fillAttribute(thePoint, mythirdPoint);
236
237   execute();
238 }
239
240 //==================================================================================================
241 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
242 {
243   FeaturePtr aBase = feature();
244   const std::string& aSketchName = theDumper.parentName(aBase);
245
246   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
247   if (anExternal->value()) {
248     // circle is external
249     theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
250   } else {
251     AttributeStringPtr aType = circleType();
252     if (aType->value() == SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS()) {
253       // circle given by center and radius
254       theDumper << aBase << " = " << aSketchName << ".addCircle("
255                 << center() << ", " << radius() << ")" << std::endl;
256     } else {
257       // circle given by three points
258       theDumper << aBase << " = " << aSketchName << ".addCircle(" << firstPoint() << ", "
259                 << secondPoint() << ", " << thirdPoint() << ")" << std::endl;
260     }
261   }
262   // dump "auxiliary" flag if necessary
263   SketchAPI_SketchEntity::dump(theDumper);
264 }