Salome HOME
e6e6922ae94178d0d93fdf86d35873fa9f474031
[modules/shaper.git] / src / ConstructionAPI / ConstructionAPI_Point.cpp
1 // Name   : ConstructionAPI_Point.cpp
2 // Purpose: 
3 //
4 // History:
5 // 29/03/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ConstructionAPI_Point.h"
9 //--------------------------------------------------------------------------------------
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_Feature.h>
12
13 #include <ModelHighAPI_Double.h>
14 //--------------------------------------------------------------------------------------
15 ConstructionAPI_Point::ConstructionAPI_Point(
16     const std::shared_ptr<ModelAPI_Feature> & theFeature)
17 : ModelHighAPI_Interface(theFeature)
18 {
19   initialize();
20 }
21
22 ConstructionAPI_Point::ConstructionAPI_Point(
23     const std::shared_ptr<ModelAPI_Feature> & theFeature,
24     const ModelHighAPI_Double & theX,
25     const ModelHighAPI_Double & theY,
26     const ModelHighAPI_Double & theZ)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   if (initialize()) {
30     setPoint(theX, theY, theZ);
31     execute();
32   }
33 }
34
35 ConstructionAPI_Point::~ConstructionAPI_Point()
36 {
37
38 }
39
40 //--------------------------------------------------------------------------------------
41 bool ConstructionAPI_Point::initialize()
42 {
43   if (!myFeature) {
44     throwException("ConstructionAPI_Point exception: The feature is NULL.");
45     return false;
46   }
47
48   if (feature()->getKind() != "Point") {
49     throwException("ConstructionAPI_Point exception: Wrong feature kind.");
50     return false;
51   }
52
53   // data() throws exceptions if the attribute is invalid
54   myX = feature()->real("x");
55   myY = feature()->real("y");
56   myZ = feature()->real("z");
57
58   if (!myX || !myY || !myZ)
59     return false;
60
61   return true;
62 }
63
64 //--------------------------------------------------------------------------------------
65 void ConstructionAPI_Point::setPoint(const ModelHighAPI_Double & theX,
66                                      const ModelHighAPI_Double & theY,
67                                      const ModelHighAPI_Double & theZ)
68 {
69   theX.fillAttribute(myX);
70   theY.fillAttribute(myY);
71   theZ.fillAttribute(myZ);
72 }
73
74 //--------------------------------------------------------------------------------------
75 std::shared_ptr<ModelAPI_AttributeDouble> ConstructionAPI_Point::x() const
76 {
77   return myX;
78 }
79 std::shared_ptr<ModelAPI_AttributeDouble> ConstructionAPI_Point::y() const
80 {
81   return myY;
82 }
83 std::shared_ptr<ModelAPI_AttributeDouble> ConstructionAPI_Point::z() const
84 {
85   return myZ;
86 }