Salome HOME
Fix for import/export features
[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::setValue(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 std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
25 {
26   setValue(thePoint->x(), thePoint->y());
27 }
28
29 double GeomData_Point2D::x() const
30 {
31   return myCoords->Value(0);
32 }
33
34 double GeomData_Point2D::y() const
35 {
36   return myCoords->Value(1);
37 }
38
39 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
40 {
41   std::shared_ptr<GeomAPI_Pnt2d> aResult(
42       new GeomAPI_Pnt2d(myCoords->Value(0), myCoords->Value(1)));
43   return aResult;
44 }
45
46 void GeomData_Point2D::setText(const std::string& theX,
47                                const std::string& theY)
48 {
49   TCollection_ExtendedString aX(theX.c_str());
50   TCollection_ExtendedString aY(theY.c_str());
51
52   if (!myIsInitialized ||
53       myTextArray->Value(0) != aX ||
54       myTextArray->Value(1) != aY) {
55     myTextArray->SetValue(0, aX);
56     myTextArray->SetValue(1, aY);
57     owner()->data()->sendAttributeUpdated(this);
58     // Send it to evaluator to convert into the double and store in the attribute
59     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
60   }
61 }
62
63 std::string GeomData_Point2D::textX()
64 {
65   return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
66 }
67 std::string GeomData_Point2D::textY()
68 {
69   return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
70 }
71
72 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
73 {
74   if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
75     myExpressionInvalidArray->SetValue(theComponent, theFlag);
76   }
77 }
78
79 bool GeomData_Point2D::expressionInvalid(int theComponent)
80 {
81   return myExpressionInvalidArray->Value(theComponent);
82 }
83
84 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
85 {
86   myIsInitialized = true;
87
88   if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
89     // create attribute: not initialized by value yet, just zero
90     myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
91     myIsInitialized = false;
92   }
93   if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
94     // create attribute: not initialized by value yet, just zero
95     myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 1);
96     myIsInitialized = false;
97   }
98   if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
99     // create attribute: not initialized by value yet, just zero
100     myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 1);
101     myIsInitialized = false;
102   }
103 }