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::reinit()
25 myIsInitialized = true;
26 for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
27 myExpression[aComponent]->reinit();
28 myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
32 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
34 if (!myIsInitialized || x() != theX || y() != theY) {
35 myExpression[0]->setValue(theX);
36 myExpression[1]->setValue(theY);
37 owner()->data()->sendAttributeUpdated(this);
41 void GeomData_Point2D::setValue(const double theX, const double theY)
43 setCalculatedValue(textX().empty() ? theX : x(),
44 textY().empty() ? theY : y());
47 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
49 setValue(thePoint->x(), thePoint->y());
52 double GeomData_Point2D::x() const
54 return myExpression[0]->value();
57 double GeomData_Point2D::y() const
59 return myExpression[1]->value();
62 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
64 std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
68 void GeomData_Point2D::setText(const std::string& theX,
69 const std::string& theY)
71 if (!myIsInitialized && theX.empty() && theY.empty())
72 return; // empty strings are not good initializers
73 if (!myIsInitialized || textX() != theX || textY() != theY) {
74 myExpression[0]->setText(theX);
75 myExpression[1]->setText(theY);
76 // Send it to evaluator to convert into the double and store in the attribute
77 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
78 owner()->data()->sendAttributeUpdated(this);
82 std::string GeomData_Point2D::textX()
84 return myExpression[0]->text();
86 std::string GeomData_Point2D::textY()
88 return myExpression[1]->text();
91 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
93 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
94 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
95 myExpression[theComponent]->setInvalid(theFlag);
98 bool GeomData_Point2D::expressionInvalid(int theComponent)
100 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
101 return myExpression[theComponent]->isInvalid();
104 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
106 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
107 if (expressionError(theComponent) != theError)
108 myExpression[theComponent]->setError(theError);
111 std::string GeomData_Point2D::expressionError(int theComponent)
113 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
114 return myExpression[theComponent]->error();
117 void GeomData_Point2D::setUsedParameters(int theComponent,
118 const std::set<std::string>& theUsedParameters)
120 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
121 myExpression[theComponent]->setUsedParameters(theUsedParameters);
124 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
126 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
127 return myExpression[theComponent]->usedParameters();