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 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);
67 std::string GeomData_Point2D::textX()
69 return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
71 std::string GeomData_Point2D::textY()
73 return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
76 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
78 if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
79 myExpressionInvalidArray->SetValue(theComponent, theFlag);
83 bool GeomData_Point2D::expressionInvalid(int theComponent)
85 return myExpressionInvalidArray->Value(theComponent);
88 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
90 myIsInitialized = true;
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;
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;
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;