Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / SketchAPI / SketchAPI_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : SketchAPI_Point.cpp
3 // Purpose:
4 //
5 // History:
6 // 15/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Point.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_Point::SketchAPI_Point(
18     const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : SketchAPI_SketchEntity(theFeature)
20 {
21   initialize();
22 }
23
24 SketchAPI_Point::SketchAPI_Point(
25     const std::shared_ptr<ModelAPI_Feature> & theFeature,
26     double theX, double theY)
27 : SketchAPI_SketchEntity(theFeature)
28 {
29   if (initialize()) {
30     setCoordinates(theX, theY);
31   }
32 }
33
34 SketchAPI_Point::SketchAPI_Point(
35     const std::shared_ptr<ModelAPI_Feature> & theFeature,
36     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
37 : SketchAPI_SketchEntity(theFeature)
38 {
39   if (initialize()) {
40     setCoordinates(thePoint);
41   }
42 }
43
44 SketchAPI_Point::SketchAPI_Point(
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_Point::SketchAPI_Point(
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_Point::~SketchAPI_Point()
65 {
66
67 }
68
69 //--------------------------------------------------------------------------------------
70 void SketchAPI_Point::setCoordinates(
71     double theX, double theY)
72 {
73   fillAttribute(coordinates(), theX, theY);
74
75   execute();
76 }
77
78 void SketchAPI_Point::setCoordinates(
79     const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
80 {
81   fillAttribute(thePoint, coordinates());
82
83   execute();
84 }
85
86 void SketchAPI_Point::setByExternal(const ModelHighAPI_Selection & theExternal)
87 {
88   fillAttribute(theExternal, external());
89
90   execute();
91 }
92
93 void SketchAPI_Point::setByExternalName(const std::string & theExternalName)
94 {
95   fillAttribute(ModelHighAPI_Selection("VERTEX", theExternalName), external());
96
97   execute();
98 }
99
100 //--------------------------------------------------------------------------------------
101
102 void SketchAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
103 {
104   if (isCopy())
105     return; // no need to dump copied feature
106
107   FeaturePtr aBase = feature();
108   const std::string& aSketchName = theDumper.parentName(aBase);
109
110   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
111   if (anExternal->context()) {
112     // point is external
113     theDumper << aBase << " = " << aSketchName << ".addPoint(" << anExternal << ")" << std::endl;
114   } else {
115     // point given by coordinates
116     std::shared_ptr<GeomDataAPI_Point2D> aPoint = coordinates();
117     theDumper << aBase << " = " << aSketchName << ".addPoint(" << aPoint << ")" << std::endl;
118   }
119   // dump "auxiliary" flag if necessary
120   SketchAPI_SketchEntity::dump(theDumper);
121 }