Salome HOME
837c94073dad6d2af33c8b060a7f1461de72ec1e
[modules/shaper.git] / src / GeomData / GeomData_Dir.cpp
1 // File:        GeomData_Dir.cxx
2 // Created:     2 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "GeomData_Dir.h"
6 #include "GeomAPI_Dir.h"
7 #include <gp_Dir.hxx>
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_Data.h>
10
11 using namespace std;
12
13 void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
14 {
15   if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY
16       || myCoords->Value(2) != theZ) {
17     myCoords->SetValue(0, theX);
18     myCoords->SetValue(1, theY);
19     myCoords->SetValue(2, theZ);
20     owner()->data()->sendAttributeUpdated(this);
21   }
22 }
23
24 void GeomData_Dir::setValue(const std::shared_ptr<GeomAPI_Dir>& theDir)
25 {
26   setValue(theDir->x(), theDir->y(), theDir->z());
27 }
28
29 double GeomData_Dir::x() const
30 {
31   return myCoords->Value(0);
32 }
33
34 double GeomData_Dir::y() const
35 {
36   return myCoords->Value(1);
37 }
38
39 double GeomData_Dir::z() const
40 {
41   return myCoords->Value(2);
42 }
43
44 std::shared_ptr<GeomAPI_Dir> GeomData_Dir::dir()
45 {
46   return std::shared_ptr<GeomAPI_Dir>(
47       new GeomAPI_Dir(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
48 }
49
50 GeomData_Dir::GeomData_Dir(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 }