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::reset()
34 myIsInitialized = false;
35 for(int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
36 myExpression[aComponent]->reset();
40 void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
42 if (!myIsInitialized || x() != theX || y() != theY) {
43 myExpression[0]->setValue(theX);
44 myExpression[1]->setValue(theY);
45 owner()->data()->sendAttributeUpdated(this);
49 void GeomData_Point2D::setValue(const double theX, const double theY)
51 setCalculatedValue(textX().empty() ? theX : x(),
52 textY().empty() ? theY : y());
55 void GeomData_Point2D::setValue(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
57 setValue(thePoint->x(), thePoint->y());
60 double GeomData_Point2D::x() const
62 return myExpression[0]->value();
65 double GeomData_Point2D::y() const
67 return myExpression[1]->value();
70 std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
72 std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
76 void GeomData_Point2D::setText(const std::string& theX,
77 const std::string& theY)
79 if (!myIsInitialized && theX.empty() && theY.empty())
80 return; // empty strings are not good initializers
81 if (!myIsInitialized || textX() != theX || textY() != theY) {
82 myExpression[0]->setText(theX);
83 myExpression[1]->setText(theY);
84 // Send it to evaluator to convert into the double and store in the attribute
85 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
86 owner()->data()->sendAttributeUpdated(this);
90 std::string GeomData_Point2D::textX()
92 return myExpression[0]->text();
94 std::string GeomData_Point2D::textY()
96 return myExpression[1]->text();
99 void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
101 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
102 if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
103 myExpression[theComponent]->setInvalid(theFlag);
106 bool GeomData_Point2D::expressionInvalid(int theComponent)
108 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
109 return myExpression[theComponent]->isInvalid();
112 void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
114 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
115 if (expressionError(theComponent) != theError)
116 myExpression[theComponent]->setError(theError);
119 std::string GeomData_Point2D::expressionError(int theComponent)
121 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
122 return myExpression[theComponent]->error();
125 void GeomData_Point2D::setUsedParameters(int theComponent,
126 const std::set<std::string>& theUsedParameters)
128 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
129 myExpression[theComponent]->setUsedParameters(theUsedParameters);
132 std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
134 assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
135 return myExpression[theComponent]->usedParameters();