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"
9 #include <GeomAPI_Pnt2d.h>
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_Events.h>
13 #include <ModelAPI_Expression.h>
14 #include <ModelAPI_Feature.h>
18 GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
20 myIsInitialized = true;
23 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
25 if (!myIsInitialized || x() != theX || y() != theY) {
26 myExpression[0]->setValue(theX);
27 myExpression[1]->setValue(theY);
28 owner()->data()->sendAttributeUpdated(this);
32 void GeomData_Point2D::setValue(const double theX, const double theY)
34 setCalculatedValue(textX().empty() ? theX : x(),
35 textY().empty() ? theY : y());
38 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
40 setValue(thePoint->x(), thePoint->y());
43 double GeomData_Point2D::x() const
45 return myExpression[0]->value();
48 double GeomData_Point2D::y() const
50 return myExpression[1]->value();
53 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
55 std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
59 void GeomData_Point2D::setText(const std::string& theX,
60 const std::string& theY)
62 if (!myIsInitialized || textX() != theX || textY() != theY) {
63 myExpression[0]->setText(theX);
64 myExpression[1]->setText(theY);
65 // Send it to evaluator to convert into the double and store in the attribute
66 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
67 owner()->data()->sendAttributeUpdated(this);
71 std::string GeomData_Point2D::textX()
73 return myExpression[0]->text();
75 std::string GeomData_Point2D::textY()
77 return myExpression[1]->text();
80 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
82 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
83 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
84 myExpression[theComponent]->setInvalid(theFlag);
87 bool GeomData_Point2D::expressionInvalid(int theComponent)
89 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
90 return myExpression[theComponent]->isInvalid();
93 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
95 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
96 if (expressionError(theComponent) != theError)
97 myExpression[theComponent]->setError(theError);
100 std::string GeomData_Point2D::expressionError(int theComponent)
102 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
103 return myExpression[theComponent]->error();
106 void GeomData_Point2D::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
108 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
109 myExpression[theComponent]->setUsedParameters(theUsedParameters);
112 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
114 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
115 return myExpression[theComponent]->usedParameters();