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 #include <SketchPlugin_ConstraintCoincidence.h>
17 #include <SketchPlugin_ConstraintTangent.h>
19 /// Obtain constraints prepared by tangent arc
20 static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
22 //================================================================================================
23 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
24 : SketchAPI_SketchEntity(theFeature)
29 //================================================================================================
30 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
31 double theCenterX, double theCenterY,
32 double theStartX, double theStartY,
33 double theEndX, double theEndY,
35 : SketchAPI_SketchEntity(theFeature)
38 setByCenterStartEnd(theCenterX, theCenterY, theStartX,
39 theStartY, theEndX, theEndY, theInversed);
43 //================================================================================================
44 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45 const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
46 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
47 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
49 : SketchAPI_SketchEntity(theFeature)
52 setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
56 //================================================================================================
57 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58 const ModelHighAPI_Selection& theExternal)
59 : SketchAPI_SketchEntity(theFeature)
62 setByExternal(theExternal);
66 //================================================================================================
67 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68 const std::string& theExternalName)
69 : SketchAPI_SketchEntity(theFeature)
72 setByExternalName(theExternalName);
76 //================================================================================================
77 SketchAPI_Arc::~SketchAPI_Arc()
82 //================================================================================================
83 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
84 double theStartX, double theStartY,
85 double theEndX, double theEndY,
88 fillAttribute(center(), theCenterX, theCenterY);
89 fillAttribute(startPoint(), theStartX, theStartY);
90 fillAttribute(endPoint(), theEndX, theEndY);
91 fillAttribute(theInversed, myreversed);
96 //================================================================================================
97 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
98 const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
99 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
102 fillAttribute(theCenter, mycenter);
103 fillAttribute(theStart, mystartPoint);
104 fillAttribute(theEnd, myendPoint);
105 fillAttribute(theInversed, myreversed);
110 //================================================================================================
111 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
113 fillAttribute(theExternal, external());
118 //===============================================================================================
119 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
121 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
126 //================================================================================================
127 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
130 return; // no need to dump copied feature
132 FeaturePtr aBase = feature();
133 const std::string& aSketchName = theDumper.parentName(aBase);
135 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
136 if (anExternal->context()) {
138 theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
140 // arc given by center and start, end points
141 theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
142 << startPoint() << ", " << endPoint() << ", " << reversed() << ")" << std::endl;
144 // dump "auxiliary" flag if necessary
145 SketchAPI_SketchEntity::dump(theDumper);