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