]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Line.cpp
Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / SketchAPI / SketchAPI_Line.cpp
1 // Name   : SketchAPI_Line.cpp
2 // Purpose: 
3 //
4 // History:
5 // 07/06/16 - Sergey POKHODENKO - Creation of the file
6
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)
19 {
20   initialize();
21 }
22
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)
27 {
28   if (initialize()) {
29     setByCoordinates(theX1, theY1, theX2, theY2);
30   }
31 }
32
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)
38 {
39   if (initialize()) {
40     setByPoints(theStartPoint, theEndPoint);
41   }
42 }
43
44 SketchAPI_Line::SketchAPI_Line(
45     const std::shared_ptr<ModelAPI_Feature> & theFeature,
46     const ModelHighAPI_Selection & theExternal )
47 : SketchAPI_SketchEntity(theFeature)
48 {
49   if (initialize()) {
50     setByExternal(theExternal);
51   }
52 }
53
54 SketchAPI_Line::SketchAPI_Line(
55     const std::shared_ptr<ModelAPI_Feature> & theFeature,
56     const std::string & theExternalName )
57 : SketchAPI_SketchEntity(theFeature)
58 {
59   if (initialize()) {
60     setByExternalName(theExternalName);
61   }
62 }
63
64 SketchAPI_Line::~SketchAPI_Line()
65 {
66
67 }
68
69 //--------------------------------------------------------------------------------------
70 void SketchAPI_Line::setByCoordinates(
71     double theX1, double theY1, double theX2, double theY2)
72 {
73   fillAttribute(startPoint(), theX1, theY1);
74   fillAttribute(endPoint(), theX2, theY2);
75
76   execute();
77 }
78
79 void SketchAPI_Line::setByPoints(
80     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
81     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
82 {
83   fillAttribute(theStartPoint, startPoint());
84   fillAttribute(theEndPoint, endPoint());
85
86   execute();
87 }
88
89 void SketchAPI_Line::setByExternal(const ModelHighAPI_Selection & theExternal)
90 {
91   fillAttribute(theExternal, external());
92
93   execute();
94 }
95
96 void SketchAPI_Line::setByExternalName(const std::string & theExternalName)
97 {
98   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
99
100   execute();
101 }
102
103 //--------------------------------------------------------------------------------------
104 void SketchAPI_Line::setStartPoint(double theX, double theY)
105 {
106   fillAttribute(startPoint(), theX, theY);
107
108   execute();
109 }
110 void SketchAPI_Line::setStartPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
111 {
112   fillAttribute(thePoint, startPoint());
113
114   execute();
115 }
116 void SketchAPI_Line::setEndPoint(double theX, double theY)
117 {
118   fillAttribute(endPoint(), theX, theY);
119
120   execute();
121 }
122 void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
123 {
124   fillAttribute(thePoint, endPoint());
125
126   execute();
127 }
128
129 //--------------------------------------------------------------------------------------
130
131 void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
132 {
133   FeaturePtr aBase = feature();
134   const std::string& aSketchName = theDumper.parentName(aBase);
135
136   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
137   if (anExternal->value()) {
138     // line is external
139     theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
140   } else {
141     // segment given by its points
142     theDumper << aBase << " = " << aSketchName << ".addLine("
143               << startPoint() << ", " << endPoint() << ")" << std::endl;
144   }
145   // dump "auxiliary" flag if necessary
146   SketchAPI_SketchEntity::dump(theDumper);
147 }