1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "Model_AttributeDouble.h"
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Events.h>
25 #include <Model_Expression.h>
26 #include <ModelAPI_Object.h>
28 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
30 TDF_Label anExpressionLab = theLabel.FindChild(1);
31 myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
32 myIsInitialized = myExpression->isInitialized();
35 void Model_AttributeDouble::reinit()
37 myExpression->reinit();
38 myIsInitialized = myExpression->isInitialized();
41 void Model_AttributeDouble::reset()
43 myExpression->reset();
44 myIsInitialized = false;
47 void Model_AttributeDouble::setCalculatedValue(const double theValue)
49 if (!myIsInitialized || value() != theValue) {
50 myExpression->setValue(theValue);
51 owner()->data()->sendAttributeUpdated(this);
55 void Model_AttributeDouble::setValue(const double theValue)
57 setCalculatedValue(text().empty() ? theValue : value());
60 double Model_AttributeDouble::value()
62 return myExpression->value();
65 void Model_AttributeDouble::setText(const std::string& theValue)
67 if (text() != theValue) {
68 myExpression->setText(theValue);
69 // Send it to evaluator to convert text to double and store in the attribute
70 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
71 owner()->data()->sendAttributeUpdated(this);
75 std::string Model_AttributeDouble::text()
77 return myExpression->text();
80 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
82 myExpression->setInvalid(theFlag);
85 bool Model_AttributeDouble::expressionInvalid()
87 return myExpression->isInvalid();
90 void Model_AttributeDouble::setExpressionError(const std::string& theError)
92 if (expressionError() != theError)
93 myExpression->setError(theError);
96 std::string Model_AttributeDouble::expressionError()
98 return myExpression->error();
101 void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
103 myExpression->setUsedParameters(theUsedParameters);
106 std::set<std::string> Model_AttributeDouble::usedParameters() const
108 return myExpression->usedParameters();