Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 "Model_Events.h"
7 #include <Events_Loop.h>
8 #include <GeomAPI_Pnt.h>
9
10 using namespace std;
11
12 void GeomData_Point::setValue(const double theX, const double theY, const double theZ)
13 {
14   if (myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) {
15     myCoords->SetValue(0, theX);
16     myCoords->SetValue(1, theY);
17     myCoords->SetValue(2, theZ);
18     static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
19     Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
20     Events_Loop::loop()->send(aMsg);
21   }
22 }
23
24 void GeomData_Point::setValue(const boost::shared_ptr<GeomAPI_Pnt>& thePoint)
25 {
26   setValue(thePoint->x(), thePoint->y(), thePoint->z());
27 }
28
29 double GeomData_Point::x() const
30 {
31   return myCoords->Value(0);
32 }
33
34 double GeomData_Point::y() const
35 {
36   return myCoords->Value(1);
37 }
38
39 double GeomData_Point::z() const
40 {
41   return myCoords->Value(2);
42 }
43
44 boost::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
45 {
46   boost::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(
47     myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
48   return aResult;
49 }
50
51 GeomData_Point::GeomData_Point(TDF_Label& theLabel)
52 {
53   // check the attribute could be already presented in this doc (after load document)
54   if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) {
55     // create attribute: not initialized by value yet, just zero
56     myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
57   }
58 }