Salome HOME
Issue #718 - Translation with parameters - wrong coordinates
[modules/shaper.git] / src / GeomData / GeomData_Point.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomData_Point.cxx
4 // Created:     24 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "GeomData_Point.h"
8 #include <GeomAPI_Pnt.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_Events.h>
12
13 using namespace std;
14
15 void GeomData_Point::setCalculatedValue(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_Point::setValue(const double theX, const double theY, const double theZ)
27 {
28   setCalculatedValue(textX().empty() ? theX : x(),
29                      textY().empty() ? theY : y(),
30                      textZ().empty() ? theZ : z());
31 }
32
33 void GeomData_Point::setValue(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
34 {
35   setValue(thePoint->x(), thePoint->y(), thePoint->z());
36 }
37
38 double GeomData_Point::x() const
39 {
40   return myCoords->Value(0);
41 }
42
43 double GeomData_Point::y() const
44 {
45   return myCoords->Value(1);
46 }
47
48 double GeomData_Point::z() const
49 {
50   return myCoords->Value(2);
51 }
52
53 std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
54 {
55   std::shared_ptr<GeomAPI_Pnt> aResult(
56       new GeomAPI_Pnt(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
57   return aResult;
58 }
59
60 void GeomData_Point::setText(const std::string& theX,
61                              const std::string& theY,
62                              const std::string& theZ)
63 {
64   TCollection_ExtendedString aX(theX.c_str());
65   TCollection_ExtendedString aY(theY.c_str());
66   TCollection_ExtendedString aZ(theZ.c_str());
67
68   if (!myIsInitialized ||
69       myTextArray->Value(0) != aX ||
70       myTextArray->Value(1) != aY ||
71       myTextArray->Value(2) != aZ) {
72     myTextArray->SetValue(0, aX);
73     myTextArray->SetValue(1, aY);
74     myTextArray->SetValue(2, aZ);
75     owner()->data()->sendAttributeUpdated(this);
76     // Send it to evaluator to convert into the double and store in the attribute
77     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
78   }
79 }
80
81 std::string GeomData_Point::textX()
82 {
83   return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
84 }
85 std::string GeomData_Point::textY()
86 {
87   return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
88 }
89 std::string GeomData_Point::textZ()
90 {
91   return TCollection_AsciiString(myTextArray->Value(2)).ToCString();;
92 }
93
94 void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
95 {
96   if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
97     myExpressionInvalidArray->SetValue(theComponent, theFlag);
98   }
99 }
100
101 bool GeomData_Point::expressionInvalid(int theComponent)
102 {
103   return myExpressionInvalidArray->Value(theComponent);
104 }
105
106 GeomData_Point::GeomData_Point(TDF_Label& theLabel)
107 {
108   myIsInitialized = true;
109
110   if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
111     // create attribute: not initialized by value yet, just zero
112     myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
113     myIsInitialized = false;
114   }
115   if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
116     // create attribute: not initialized by value yet, just zero
117     myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 2);
118     myIsInitialized = false;
119   }
120   if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
121     // create attribute: not initialized by value yet, just zero
122     myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 2);
123     myIsInitialized = false;
124   }
125 }