Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[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 <GeomAPI_XYZ.h>
10 #include <gp_Dir.hxx>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Data.h>
13
14 using namespace std;
15
16 void GeomData_Dir::setValue(const double theX, const double theY, const double theZ)
17 {
18   if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY
19       || myCoords->Value(2) != theZ) {
20     myCoords->SetValue(0, theX);
21     myCoords->SetValue(1, theY);
22     myCoords->SetValue(2, theZ);
23     owner()->data()->sendAttributeUpdated(this);
24   }
25 }
26
27 void GeomData_Dir::setValue(const std::shared_ptr<GeomAPI_Dir>& theDir)
28 {
29   setValue(theDir->x(), theDir->y(), theDir->z());
30 }
31
32 double GeomData_Dir::x() const
33 {
34   return myCoords->Value(0);
35 }
36
37 double GeomData_Dir::y() const
38 {
39   return myCoords->Value(1);
40 }
41
42 double GeomData_Dir::z() const
43 {
44   return myCoords->Value(2);
45 }
46
47 std::shared_ptr<GeomAPI_Dir> GeomData_Dir::dir()
48 {
49   return std::shared_ptr<GeomAPI_Dir>(
50       new GeomAPI_Dir(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
51 }
52
53 std::shared_ptr<GeomAPI_XYZ> GeomData_Dir::xyz()
54 {
55   return std::shared_ptr<GeomAPI_XYZ>(
56       new GeomAPI_XYZ(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
57 }
58
59 GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
60 {
61   myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
62   if (!myIsInitialized) {
63     // create attribute: not initialized by value yet, just zero
64     myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
65   }
66 }