Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / SketchAPI / SketchAPI_Point.cpp
1 // Name   : SketchAPI_Point.cpp
2 // Purpose: 
3 //
4 // History:
5 // 15/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Point.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_Point::SketchAPI_Point(
17     const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
19 {
20   initialize();
21 }
22
23 SketchAPI_Point::SketchAPI_Point(
24     const std::shared_ptr<ModelAPI_Feature> & theFeature,
25     double theX, double theY)
26 : SketchAPI_SketchEntity(theFeature)
27 {
28   if (initialize()) {
29     setCoordinates(theX, theY);
30   }
31 }
32
33 SketchAPI_Point::SketchAPI_Point(
34     const std::shared_ptr<ModelAPI_Feature> & theFeature,
35     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
36 : SketchAPI_SketchEntity(theFeature)
37 {
38   if (initialize()) {
39     setCoordinates(thePoint);
40   }
41 }
42
43 SketchAPI_Point::SketchAPI_Point(
44     const std::shared_ptr<ModelAPI_Feature> & theFeature,
45     const ModelHighAPI_Selection & theExternal )
46 : SketchAPI_SketchEntity(theFeature)
47 {
48   if (initialize()) {
49     setByExternal(theExternal);
50   }
51 }
52
53 SketchAPI_Point::SketchAPI_Point(
54     const std::shared_ptr<ModelAPI_Feature> & theFeature,
55     const std::string & theExternalName )
56 : SketchAPI_SketchEntity(theFeature)
57 {
58   if (initialize()) {
59     setByExternalName(theExternalName);
60   }
61 }
62
63 SketchAPI_Point::~SketchAPI_Point()
64 {
65
66 }
67
68 //--------------------------------------------------------------------------------------
69 void SketchAPI_Point::setCoordinates(
70     double theX, double theY)
71 {
72   fillAttribute(coordinates(), theX, theY);
73
74   execute();
75 }
76
77 void SketchAPI_Point::setCoordinates(
78     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
79 {
80   fillAttribute(thePoint, coordinates());
81
82   execute();
83 }
84
85 void SketchAPI_Point::setByExternal(const ModelHighAPI_Selection & theExternal)
86 {
87   fillAttribute(theExternal, external());
88
89   execute();
90 }
91
92 void SketchAPI_Point::setByExternalName(const std::string & theExternalName)
93 {
94   fillAttribute(ModelHighAPI_Selection("VERTEX", theExternalName), external());
95
96   execute();
97 }
98
99 //--------------------------------------------------------------------------------------
100
101 void SketchAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
102 {
103   if (isCopy())
104     return; // no need to dump copied feature
105
106   FeaturePtr aBase = feature();
107   const std::string& aSketchName = theDumper.parentName(aBase);
108
109   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
110   if (anExternal->value()) {
111     // point is external
112     theDumper << aBase << " = " << aSketchName << ".addPoint(" << anExternal << ")" << std::endl;
113   } else {
114     // point given by coordinates
115     std::shared_ptr<GeomDataAPI_Point2D> aPoint = coordinates();
116     theDumper << aBase << " = " << aSketchName << ".addPoint(" << aPoint << ")" << std::endl;
117   }
118   // dump "auxiliary" flag if necessary
119   SketchAPI_SketchEntity::dump(theDumper);
120 }