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_AttributeInteger.h>
22 #include <ModelAPI_Data.h>
23 #include <ModelAPI_Events.h>
24 #include <Model_Expression.h>
25 #include <ModelAPI_Object.h>
27 Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel)
29 // to the same label to support the backward compatibility
30 myExpression.reset(new Model_ExpressionInteger(theLabel));
31 myIsInitialized = myExpression->isInitialized();
34 void Model_AttributeInteger::reinit()
36 myExpression->reinit();
37 myIsInitialized = myExpression->isInitialized();
40 void Model_AttributeInteger::setCalculatedValue(const int theValue)
42 if (!myIsInitialized || value() != theValue) {
43 myExpression->setValue(theValue);
44 owner()->data()->sendAttributeUpdated(this);
48 void Model_AttributeInteger::setValue(const int theValue)
50 setCalculatedValue(text().empty() ? theValue : value());
53 int Model_AttributeInteger::value()
55 return myExpression->value();
58 void Model_AttributeInteger::setText(const std::string& theValue)
60 if (text() != theValue) {
61 myExpression->setText(theValue);
62 // Send it to evaluator to convert text to integer and store in the attribute
63 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
64 owner()->data()->sendAttributeUpdated(this);
68 std::string Model_AttributeInteger::text()
70 return myExpression->text();
73 void Model_AttributeInteger::setExpressionInvalid(const bool theFlag)
75 myExpression->setInvalid(theFlag);
78 bool Model_AttributeInteger::expressionInvalid()
80 return myExpression->isInvalid();
83 void Model_AttributeInteger::setExpressionError(const std::string& theError)
85 if (expressionError() != theError)
86 myExpression->setError(theError);
89 std::string Model_AttributeInteger::expressionError()
91 return myExpression->error();
94 void Model_AttributeInteger::setUsedParameters(const std::set<std::string>& theUsedParameters)
96 myExpression->setUsedParameters(theUsedParameters);
99 std::set<std::string> Model_AttributeInteger::usedParameters() const
101 return myExpression->usedParameters();