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::setValue(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 std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
26 setValue(thePoint->x(), thePoint->y());
29 double GeomData_Point2D::x() const
31 return myCoords->Value(0);
34 double GeomData_Point2D::y() const
36 return myCoords->Value(1);
39 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
41 std::shared_ptr<GeomAPI_Pnt2d> aResult(
42 new GeomAPI_Pnt2d(myCoords->Value(0), myCoords->Value(1)));
46 void GeomData_Point2D::setText(const std::string& theX,
47 const std::string& theY)
49 TCollection_ExtendedString aX(theX.c_str());
50 TCollection_ExtendedString aY(theY.c_str());
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);
63 std::string GeomData_Point2D::textX()
65 return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
67 std::string GeomData_Point2D::textY()
69 return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
72 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
74 if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
75 myExpressionInvalidArray->SetValue(theComponent, theFlag);
79 bool GeomData_Point2D::expressionInvalid(int theComponent)
81 return myExpressionInvalidArray->Value(theComponent);
84 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
86 myIsInitialized = true;
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;
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;
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;