1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "Model_AttributeDouble.h"
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Events.h>
24 #include <Model_Expression.h>
25 #include <ModelAPI_Object.h>
27 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
29 TDF_Label anExpressionLab = theLabel.FindChild(1);
30 myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
31 myIsInitialized = myExpression->isInitialized();
34 void Model_AttributeDouble::reinit()
36 myExpression->reinit();
37 myIsInitialized = myExpression->isInitialized();
40 void Model_AttributeDouble::reset()
42 myExpression->reset();
43 myIsInitialized = false;
46 void Model_AttributeDouble::setCalculatedValue(const double theValue)
48 if (!myIsInitialized || value() != theValue) {
49 myExpression->setValue(theValue);
50 owner()->data()->sendAttributeUpdated(this);
54 void Model_AttributeDouble::setValue(const double theValue)
56 setCalculatedValue(text().empty() ? theValue : value());
59 double Model_AttributeDouble::value()
61 return myExpression->value();
64 void Model_AttributeDouble::setText(const std::string& theValue)
66 if (text() != theValue) {
67 myExpression->setText(theValue);
68 // Send it to evaluator to convert text to double and store in the attribute
69 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
70 owner()->data()->sendAttributeUpdated(this);
74 std::string Model_AttributeDouble::text()
76 return myExpression->text();
79 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
81 myExpression->setInvalid(theFlag);
84 bool Model_AttributeDouble::expressionInvalid()
86 return myExpression->isInvalid();
89 void Model_AttributeDouble::setExpressionError(const std::string& theError)
91 if (expressionError() != theError)
92 myExpression->setError(theError);
95 std::string Model_AttributeDouble::expressionError()
97 return myExpression->error();
100 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
102 myExpression->setUsedParameters(theUsedParameters);
105 std::set<std::string> Model_AttributeDouble::usedParameters() const
107 return myExpression->usedParameters();