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, theStartY, theEndX, theEndY, theInversed);
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,
42 : SketchAPI_SketchEntity(theFeature)
45 setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
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)
57 setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
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)
69 setByStartEndPassed(theStart, theEnd, thePassed);
73 //==================================================================================================
74 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
75 const ModelHighAPI_RefAttr& theTangentPoint,
76 double theEndX, double theEndY,
78 : SketchAPI_SketchEntity(theFeature)
81 setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
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,
90 : SketchAPI_SketchEntity(theFeature)
93 setByTangent(theTangentPoint, theEnd, theInversed);
97 //==================================================================================================
98 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
99 const ModelHighAPI_Selection& theExternal)
100 : SketchAPI_SketchEntity(theFeature)
103 setByExternal(theExternal);
107 //==================================================================================================
108 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
109 const std::string& theExternalName)
110 : SketchAPI_SketchEntity(theFeature)
113 setByExternalName(theExternalName);
117 //==================================================================================================
118 SketchAPI_Arc::~SketchAPI_Arc()
123 //==================================================================================================
124 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
125 double theStartX, double theStartY,
126 double theEndX, double theEndY,
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);
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,
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);
153 //==================================================================================================
154 void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
155 double theEndX, double theEndY,
156 double thePassedX, double thePassedY)
158 fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
159 fillAttribute(startPoint(), theStartX, theStartY);
160 fillAttribute(endPoint(), theEndX, theEndY);
161 fillAttribute(passedPoint(), thePassedX, thePassedY);
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)
171 fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
172 fillAttribute(theStart, mystartPoint);
173 fillAttribute(theEnd, myendPoint);
174 fillAttribute(thePassed, mypassedPoint);
179 //==================================================================================================
180 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
181 double theEndX, double theEndY,
184 fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
185 fillAttribute(theTangentPoint, mytangentPoint);
186 fillAttribute(endPoint(), theEndX, theEndY);
187 fillAttribute(theInversed, myinversed);
192 //==================================================================================================
193 void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
194 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
197 fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
198 fillAttribute(theTangentPoint, mytangentPoint);
199 fillAttribute(theEnd, myendPoint);
200 fillAttribute(theInversed, myinversed);
205 //==================================================================================================
206 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
208 fillAttribute(theExternal, external());
213 //==================================================================================================
214 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
216 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
221 //==================================================================================================
222 void SketchAPI_Arc::setRadius(double theRadius)
224 fillAttribute(ModelHighAPI_Double(theRadius), myradius);
229 //==================================================================================================
230 void SketchAPI_Arc::setAngle(double theAngle)
232 fillAttribute(ModelHighAPI_Double(theAngle), myangle);
237 //==================================================================================================
238 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
241 return; // no need to dump copied feature
243 FeaturePtr aBase = feature();
244 const std::string& aSketchName = theDumper.parentName(aBase);
246 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
247 if (anExternal->value()) {
249 theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
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;
262 AttributeRefAttrPtr aTangentPoint = tangentPoint();
263 theDumper << aBase << " = " << aSketchName << ".addArc("
264 << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
267 // dump "auxiliary" flag if necessary
268 SketchAPI_SketchEntity::dump(theDumper);