1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : SketchAPI_Line.cpp
6 // 07/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Line.h"
10 //--------------------------------------------------------------------------------------
11 #include <GeomAPI_Pnt2d.h>
12 //--------------------------------------------------------------------------------------
13 #include <ModelHighAPI_Dumper.h>
14 #include <ModelHighAPI_Selection.h>
15 #include <ModelHighAPI_Tools.h>
16 //--------------------------------------------------------------------------------------
17 SketchAPI_Line::SketchAPI_Line(
18 const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : SketchAPI_SketchEntity(theFeature)
24 SketchAPI_Line::SketchAPI_Line(
25 const std::shared_ptr<ModelAPI_Feature> & theFeature,
26 double theX1, double theY1, double theX2, double theY2)
27 : SketchAPI_SketchEntity(theFeature)
30 setByCoordinates(theX1, theY1, theX2, theY2);
34 SketchAPI_Line::SketchAPI_Line(
35 const std::shared_ptr<ModelAPI_Feature> & theFeature,
36 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
37 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
38 : SketchAPI_SketchEntity(theFeature)
41 setByPoints(theStartPoint, theEndPoint);
45 SketchAPI_Line::SketchAPI_Line(
46 const std::shared_ptr<ModelAPI_Feature> & theFeature,
47 const ModelHighAPI_Selection & theExternal )
48 : SketchAPI_SketchEntity(theFeature)
51 setByExternal(theExternal);
55 SketchAPI_Line::SketchAPI_Line(
56 const std::shared_ptr<ModelAPI_Feature> & theFeature,
57 const std::string & theExternalName )
58 : SketchAPI_SketchEntity(theFeature)
61 setByExternalName(theExternalName);
65 SketchAPI_Line::~SketchAPI_Line()
70 //--------------------------------------------------------------------------------------
71 void SketchAPI_Line::setByCoordinates(
72 double theX1, double theY1, double theX2, double theY2)
74 fillAttribute(startPoint(), theX1, theY1);
75 fillAttribute(endPoint(), theX2, theY2);
80 void SketchAPI_Line::setByPoints(
81 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
82 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
84 fillAttribute(theStartPoint, startPoint());
85 fillAttribute(theEndPoint, endPoint());
90 void SketchAPI_Line::setByExternal(const ModelHighAPI_Selection & theExternal)
92 fillAttribute(theExternal, external());
97 void SketchAPI_Line::setByExternalName(const std::string & theExternalName)
99 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
104 //--------------------------------------------------------------------------------------
105 void SketchAPI_Line::setStartPoint(double theX, double theY)
107 fillAttribute(startPoint(), theX, theY);
111 void SketchAPI_Line::setStartPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
113 fillAttribute(thePoint, startPoint());
117 void SketchAPI_Line::setEndPoint(double theX, double theY)
119 fillAttribute(endPoint(), theX, theY);
123 void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
125 fillAttribute(thePoint, endPoint());
130 //--------------------------------------------------------------------------------------
132 void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
135 return; // no need to dump copied feature
137 FeaturePtr aBase = feature();
138 const std::string& aSketchName = theDumper.parentName(aBase);
140 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
141 if (anExternal->context()) {
143 theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
145 // segment given by its points
146 theDumper << aBase << " = " << aSketchName << ".addLine("
147 << startPoint() << ", " << endPoint() << ")" << std::endl;
149 // dump "auxiliary" flag if necessary
150 SketchAPI_SketchEntity::dump(theDumper);