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