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()
20 myIsInitialized = false;
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 && theX.empty() && theY.empty())
63 return; // empty strings are not good initializers
64 if (!myIsInitialized || textX() != theX || textY() != theY) {
65 myExpression[0]->setText(theX);
66 myExpression[1]->setText(theY);
67 // Send it to evaluator to convert into the double and store in the attribute
68 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
69 owner()->data()->sendAttributeUpdated(this);
73 std::string GeomData_Point2D::textX()
75 return myExpression[0]->text();
77 std::string GeomData_Point2D::textY()
79 return myExpression[1]->text();
82 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
84 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
85 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
86 myExpression[theComponent]->setInvalid(theFlag);
89 bool GeomData_Point2D::expressionInvalid(int theComponent)
91 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
92 return myExpression[theComponent]->isInvalid();
95 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
97 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
98 if (expressionError(theComponent) != theError)
99 myExpression[theComponent]->setError(theError);
102 std::string GeomData_Point2D::expressionError(int theComponent)
104 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
105 return myExpression[theComponent]->error();
108 void GeomData_Point2D::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
110 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
111 myExpression[theComponent]->setUsedParameters(theUsedParameters);
114 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
116 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
117 return myExpression[theComponent]->usedParameters();