Salome HOME
Merge branch 'master' of newgeom:newgeom.git into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / GeomData / GeomData_Point.cpp
1 // File:        GeomData_Point.cxx
2 // Created:     24 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "GeomData_Point.h"
6 #include <GeomAPI_Pnt.h>
7 #include <ModelAPI_Feature.h>
8 #include <ModelAPI_Data.h>
9
10 using namespace std;
11
12 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
13 {
14   if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY
15       || myCoords->Value(2) != theZ) {
16     myCoords->SetValue(0, theX);
17     myCoords->SetValue(1, theY);
18     myCoords->SetValue(2, theZ);
19     owner()->data()->sendAttributeUpdated(this);
20   }
21 }
22
23 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
24 {
25   setValue(thePoint->x(), thePoint->y(), thePoint->z());
26 }
27
28 double GeomData_Point::x() const
29 {
30   return myCoords->Value(0);
31 }
32
33 double GeomData_Point::y() const
34 {
35   return myCoords->Value(1);
36 }
37
38 double GeomData_Point::z() const
39 {
40   return myCoords->Value(2);
41 }
42
43 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
44 {
45   std::shared_ptr<GeomAPI_Pnt> aResult(
46       new GeomAPI_Pnt(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
47   return aResult;
48 }
49
50 GeomData_Point::GeomData_Point(TDF_Label& theLabel)
51 {
52   myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
53   if (!myIsInitialized) {
54     // create attribute: not initialized by value yet, just zero
55     myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
56   }
57 }