1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchAPI_Arc.cpp
4 // Created: 09 June 2016
5 // Author: Dmitry Bobylev
7 #include "SketchAPI_Arc.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_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
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,
29 : SketchAPI_SketchEntity(theFeature)
32 setByCenterStartEnd(theCenterX, theCenterY, theStartX,
33 theStartY, theEndX, theEndY, theInversed);
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,
43 : SketchAPI_SketchEntity(theFeature)
46 setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
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)
58 setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
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)
70 setByStartEndPassed(theStart, theEnd, thePassed);
74 //================================================================================================
75 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
76 const ModelHighAPI_RefAttr& theTangentPoint,
77 double theEndX, double theEndY,
79 : SketchAPI_SketchEntity(theFeature)
82 setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
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,
91 : SketchAPI_SketchEntity(theFeature)
94 setByTangent(theTangentPoint, theEnd, theInversed);
98 //================================================================================================
99 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
100 const ModelHighAPI_Selection& theExternal)
101 : SketchAPI_SketchEntity(theFeature)
104 setByExternal(theExternal);
108 //================================================================================================
109 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
110 const std::string& theExternalName)
111 : SketchAPI_SketchEntity(theFeature)
114 setByExternalName(theExternalName);
118 //================================================================================================
119 SketchAPI_Arc::~SketchAPI_Arc()
124 //================================================================================================
125 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
126 double theStartX, double theStartY,
127 double theEndX, double theEndY,
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);
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,
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);
154 //================================================================================================
155 void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
156 double theEndX, double theEndY,
157 double thePassedX, double thePassedY)
159 fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
160 fillAttribute(startPoint(), theStartX, theStartY);
161 fillAttribute(endPoint(), theEndX, theEndY);
162 fillAttribute(passedPoint(), thePassedX, thePassedY);
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)
172 fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
173 fillAttribute(theStart, mystartPoint);
174 fillAttribute(theEnd, myendPoint);
175 fillAttribute(thePassed, mypassedPoint);
180 //================================================================================================
181 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
182 double theEndX, double theEndY,
185 fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
186 fillAttribute(theTangentPoint, mytangentPoint);
187 fillAttribute(endPoint(), theEndX, theEndY);
188 fillAttribute(theInversed, myinversed);
193 //================================================================================================
194 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
195 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
198 fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
199 fillAttribute(theTangentPoint, mytangentPoint);
200 fillAttribute(theEnd, myendPoint);
201 fillAttribute(theInversed, myinversed);
206 //================================================================================================
207 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
209 fillAttribute(theExternal, external());
214 //===============================================================================================
215 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
217 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
222 //===============================================================================================
223 void SketchAPI_Arc::setRadius(double theRadius)
225 fillAttribute(ModelHighAPI_Double(theRadius), myradius);
230 //================================================================================================
231 void SketchAPI_Arc::setAngle(double theAngle)
233 fillAttribute(ModelHighAPI_Double(theAngle), myangle);
238 //================================================================================================
239 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
242 return; // no need to dump copied feature
244 FeaturePtr aBase = feature();
245 const std::string& aSketchName = theDumper.parentName(aBase);
247 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
248 if (anExternal->context()) {
250 theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
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;
263 AttributeRefAttrPtr aTangentPoint = tangentPoint();
264 theDumper << aBase << " = " << aSketchName << ".addArc("
265 << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
268 // dump "auxiliary" flag if necessary
269 SketchAPI_SketchEntity::dump(theDumper);