1 // Name : SketchAPI_Line.cpp
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Line.h"
9 //--------------------------------------------------------------------------------------
10 #include <GeomAPI_Pnt2d.h>
11 //--------------------------------------------------------------------------------------
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
15 //--------------------------------------------------------------------------------------
16 SketchAPI_Line::SketchAPI_Line(
17 const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
23 SketchAPI_Line::SketchAPI_Line(
24 const std::shared_ptr<ModelAPI_Feature> & theFeature,
25 double theX1, double theY1, double theX2, double theY2)
26 : SketchAPI_SketchEntity(theFeature)
29 setByCoordinates(theX1, theY1, theX2, theY2);
33 SketchAPI_Line::SketchAPI_Line(
34 const std::shared_ptr<ModelAPI_Feature> & theFeature,
35 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
36 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
37 : SketchAPI_SketchEntity(theFeature)
40 setByPoints(theStartPoint, theEndPoint);
44 SketchAPI_Line::SketchAPI_Line(
45 const std::shared_ptr<ModelAPI_Feature> & theFeature,
46 const ModelHighAPI_Selection & theExternal )
47 : SketchAPI_SketchEntity(theFeature)
50 setByExternal(theExternal);
54 SketchAPI_Line::SketchAPI_Line(
55 const std::shared_ptr<ModelAPI_Feature> & theFeature,
56 const std::string & theExternalName )
57 : SketchAPI_SketchEntity(theFeature)
60 setByExternalName(theExternalName);
64 SketchAPI_Line::~SketchAPI_Line()
69 //--------------------------------------------------------------------------------------
70 void SketchAPI_Line::setByCoordinates(
71 double theX1, double theY1, double theX2, double theY2)
73 fillAttribute(startPoint(), theX1, theY1);
74 fillAttribute(endPoint(), theX2, theY2);
79 void SketchAPI_Line::setByPoints(
80 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
81 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
83 fillAttribute(theStartPoint, startPoint());
84 fillAttribute(theEndPoint, endPoint());
89 void SketchAPI_Line::setByExternal(const ModelHighAPI_Selection & theExternal)
91 fillAttribute(theExternal, external());
96 void SketchAPI_Line::setByExternalName(const std::string & theExternalName)
98 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
103 //--------------------------------------------------------------------------------------
104 void SketchAPI_Line::setStartPoint(double theX, double theY)
106 fillAttribute(startPoint(), theX, theY);
110 void SketchAPI_Line::setStartPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
112 fillAttribute(thePoint, startPoint());
116 void SketchAPI_Line::setEndPoint(double theX, double theY)
118 fillAttribute(endPoint(), theX, theY);
122 void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
124 fillAttribute(thePoint, endPoint());
129 //--------------------------------------------------------------------------------------
131 void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
133 FeaturePtr aBase = feature();
134 const std::string& aSketchName = theDumper.parentName(aBase);
136 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
137 if (anExternal->value()) {
139 theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
141 // segment given by its points
142 theDumper << aBase << " = " << aSketchName << ".addLine("
143 << startPoint() << ", " << endPoint() << ")" << std::endl;
145 // dump "auxiliary" flag if necessary
146 SketchAPI_SketchEntity::dump(theDumper);