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