1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomData_Point2D.cxx
4 // Created: 24 Apr 2014
5 // Author: Mikhail PONIKAROV
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>
15 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
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);
24 void GeomData_Point2D::setValue(const double theX, const double theY)
26 setCalculatedValue(textX().empty() ? theX : x(),
27 textY().empty() ? theY : y());
30 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
32 setValue(thePoint->x(), thePoint->y());
35 double GeomData_Point2D::x() const
37 return myCoords->Value(0);
40 double GeomData_Point2D::y() const
42 return myCoords->Value(1);
45 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
47 std::shared_ptr<GeomAPI_Pnt2d> aResult(
48 new GeomAPI_Pnt2d(myCoords->Value(0), myCoords->Value(1)));
52 void GeomData_Point2D::setText(const std::string& theX,
53 const std::string& theY)
55 TCollection_ExtendedString aX(theX.c_str());
56 TCollection_ExtendedString aY(theY.c_str());
58 if (!myIsInitialized ||
59 myTextArray->Value(0) != aX ||
60 myTextArray->Value(1) != aY) {
61 myTextArray->SetValue(0, aX);
62 myTextArray->SetValue(1, aY);
63 owner()->data()->sendAttributeUpdated(this);
64 // Send it to evaluator to convert into the double and store in the attribute
65 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
69 std::string GeomData_Point2D::textX()
71 return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
73 std::string GeomData_Point2D::textY()
75 return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
78 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
80 if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
81 myExpressionInvalidArray->SetValue(theComponent, theFlag);
85 bool GeomData_Point2D::expressionInvalid(int theComponent)
87 return myExpressionInvalidArray->Value(theComponent);
90 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
92 myIsInitialized = true;
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;
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;
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;