Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / SketchAPI / SketchAPI_Arc.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchAPI_Arc.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "SketchAPI_Arc.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_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
19 {
20   initialize();
21 }
22
23 //==================================================================================================
24 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
25                              double theCenterX, double theCenterY,
26                              double theStartX, double theStartY,
27                              double theEndX, double theEndY,
28                              bool theInversed)
29 : SketchAPI_SketchEntity(theFeature)
30 {
31   if(initialize()) {
32     setByCenterStartEnd(theCenterX, theCenterY, theStartX, theStartY, theEndX, theEndY, theInversed);
33   }
34 }
35
36 //==================================================================================================
37 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
38                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
39                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
40                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
41                              bool theInversed)
42 : SketchAPI_SketchEntity(theFeature)
43 {
44   if(initialize()) {
45     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
46   }
47 }
48
49 //==================================================================================================
50 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
51                              double theStartX, double theStartY,
52                              double theEndX, double theEndY,
53                              double thePassedX, double thePassedY)
54 : SketchAPI_SketchEntity(theFeature)
55 {
56   if (initialize()) {
57     setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
58   }
59 }
60
61 //==================================================================================================
62 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
63                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
64                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
65                              const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
66 : SketchAPI_SketchEntity(theFeature)
67 {
68   if (initialize()) {
69     setByStartEndPassed(theStart, theEnd, thePassed);
70   }
71 }
72
73 //==================================================================================================
74 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
75                              const ModelHighAPI_RefAttr& theTangentPoint,
76                              double theEndX, double theEndY,
77                              bool theInversed)
78 : SketchAPI_SketchEntity(theFeature)
79 {
80   if (initialize()) {
81     setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
82   }
83 }
84
85 //==================================================================================================
86 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
87                              const ModelHighAPI_RefAttr& theTangentPoint,
88                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
89                              bool theInversed)
90 : SketchAPI_SketchEntity(theFeature)
91 {
92   if (initialize()) {
93     setByTangent(theTangentPoint, theEnd, theInversed);
94   }
95 }
96
97 //==================================================================================================
98 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
99                              const ModelHighAPI_Selection& theExternal)
100 : SketchAPI_SketchEntity(theFeature)
101 {
102   if (initialize()) {
103     setByExternal(theExternal);
104   }
105 }
106
107 //==================================================================================================
108 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
109                              const std::string& theExternalName)
110 : SketchAPI_SketchEntity(theFeature)
111 {
112   if (initialize()) {
113     setByExternalName(theExternalName);
114   }
115 }
116
117 //==================================================================================================
118 SketchAPI_Arc::~SketchAPI_Arc()
119 {
120
121 }
122
123 //==================================================================================================
124 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
125                                         double theStartX, double theStartY,
126                                         double theEndX, double theEndY,
127                                         bool theInversed)
128 {
129   fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType);
130   fillAttribute(center(), theCenterX, theCenterY);
131   fillAttribute(startPoint(), theStartX, theStartY);
132   fillAttribute(endPoint(), theEndX, theEndY);
133   fillAttribute(theInversed, myinversed);
134
135   execute();
136 }
137
138 //==================================================================================================
139 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
140                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
141                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
142                                         bool theInversed)
143 {
144   fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType);
145   fillAttribute(theCenter, mycenter);
146   fillAttribute(theStart, mystartPoint);
147   fillAttribute(theEnd, myendPoint);
148   fillAttribute(theInversed, myinversed);
149
150   execute();
151 }
152
153 //==================================================================================================
154 void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
155                                         double theEndX, double theEndY,
156                                         double thePassedX, double thePassedY)
157 {
158   fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
159   fillAttribute(startPoint(), theStartX, theStartY);
160   fillAttribute(endPoint(), theEndX, theEndY);
161   fillAttribute(passedPoint(), thePassedX, thePassedY);
162
163   execute();
164 }
165
166 //==================================================================================================
167 void SketchAPI_Arc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
168                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
169                                         const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
170 {
171   fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
172   fillAttribute(theStart, mystartPoint);
173   fillAttribute(theEnd, myendPoint);
174   fillAttribute(thePassed, mypassedPoint);
175
176   execute();
177 }
178
179 //==================================================================================================
180 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
181                                  double theEndX, double theEndY,
182                                  bool theInversed)
183 {
184   fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
185   fillAttribute(theTangentPoint, mytangentPoint);
186   fillAttribute(endPoint(), theEndX, theEndY);
187   fillAttribute(theInversed, myinversed);
188
189   execute();
190 }
191
192 //==================================================================================================
193 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
194                                  const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
195                                  bool theInversed)
196 {
197   fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
198   fillAttribute(theTangentPoint, mytangentPoint);
199   fillAttribute(theEnd, myendPoint);
200   fillAttribute(theInversed, myinversed);
201
202   execute();
203 }
204
205 //==================================================================================================
206 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
207 {
208   fillAttribute(theExternal, external());
209
210   execute();
211 }
212
213 //==================================================================================================
214 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
215 {
216   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
217
218   execute();
219 }
220
221 //==================================================================================================
222 void SketchAPI_Arc::setRadius(double theRadius)
223 {
224   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
225
226   execute();
227 }
228
229 //==================================================================================================
230 void SketchAPI_Arc::setAngle(double theAngle)
231 {
232   fillAttribute(ModelHighAPI_Double(theAngle), myangle);
233
234   execute();
235 }
236
237 //==================================================================================================
238 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
239 {
240   if (isCopy())
241     return; // no need to dump copied feature
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     // arc is external
249     theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
250   } else {
251     AttributeStringPtr aType = arcType();
252     if (aType->value() == SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()) {
253       // arc given by center and start, end points
254       theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
255                 << startPoint() << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
256     } else if (aType->value() == SketchPlugin_Arc::ARC_TYPE_THREE_POINTS()) {
257       // arc given by three points
258       theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", "
259                 << endPoint() << ", " << passedPoint() << ")" << std::endl;
260     } else {
261       // tangent arc
262       AttributeRefAttrPtr aTangentPoint = tangentPoint();
263       theDumper << aBase << " = " << aSketchName << ".addArc("
264                 << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
265     }
266   }
267   // dump "auxiliary" flag if necessary
268   SketchAPI_SketchEntity::dump(theDumper);
269 }