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