Salome HOME
9637c248e4bfbf1c4670a09e7cbf61d05f9e7b8d
[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     static Events_ID anId = ModelAPI_AttributeEvalMessage::eventId();
60     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
61       std::shared_ptr<ModelAPI_AttributeEvalMessage>(new ModelAPI_AttributeEvalMessage(anId, this));
62     aMessage->setAttribute(owner()->data()->attribute(id())); // to get shared pointer to this
63     Events_Loop::loop()->send(aMessage);
64   }
65 }
66
67 std::string GeomData_Point2D::textX()
68 {
69   return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
70 }
71 std::string GeomData_Point2D::textY()
72 {
73   return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
74 }
75
76 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
77 {
78   if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
79     myExpressionInvalidArray->SetValue(theComponent, theFlag);
80   }
81 }
82
83 bool GeomData_Point2D::expressionInvalid(int theComponent)
84 {
85   return myExpressionInvalidArray->Value(theComponent);
86 }
87
88 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
89 {
90   myIsInitialized = true;
91
92   if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
93     // create attribute: not initialized by value yet, just zero
94     myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
95     myIsInitialized = false;
96   }
97   if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
98     // create attribute: not initialized by value yet, just zero
99     myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 1);
100     myIsInitialized = false;
101   }
102   if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
103     // create attribute: not initialized by value yet, just zero
104     myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 1);
105     myIsInitialized = false;
106   }
107 }