1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_AttributeDouble.cxx
5 // Author: Mikhail PONIKAROV
7 #include "Model_AttributeDouble.h"
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Events.h>
11 #include <Model_Expression.h>
12 #include <ModelAPI_Object.h>
14 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
16 TDF_Label anExpressionLab = theLabel.FindChild(1);
17 myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
18 myIsInitialized = myExpression->isInitialized();
21 void Model_AttributeDouble::reinit()
23 myExpression->reinit();
24 myIsInitialized = myExpression->isInitialized();
27 void Model_AttributeDouble::reset()
29 myExpression->reset();
30 myIsInitialized = false;
33 void Model_AttributeDouble::setCalculatedValue(const double theValue)
35 if (!myIsInitialized || value() != theValue) {
36 myExpression->setValue(theValue);
37 owner()->data()->sendAttributeUpdated(this);
41 void Model_AttributeDouble::setValue(const double theValue)
43 setCalculatedValue(text().empty() ? theValue : value());
46 double Model_AttributeDouble::value()
48 return myExpression->value();
51 void Model_AttributeDouble::setText(const std::string& theValue)
53 if (text() != theValue) {
54 myExpression->setText(theValue);
55 // Send it to evaluator to convert text to double and store in the attribute
56 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
57 owner()->data()->sendAttributeUpdated(this);
61 std::string Model_AttributeDouble::text()
63 return myExpression->text();
66 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
68 myExpression->setInvalid(theFlag);
71 bool Model_AttributeDouble::expressionInvalid()
73 return myExpression->isInvalid();
76 void Model_AttributeDouble::setExpressionError(const std::string& theError)
78 if (expressionError() != theError)
79 myExpression->setError(theError);
82 std::string Model_AttributeDouble::expressionError()
84 return myExpression->error();
87 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
89 myExpression->setUsedParameters(theUsedParameters);
92 std::set<std::string> Model_AttributeDouble::usedParameters() const
94 return myExpression->usedParameters();