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_AttributeInteger.h>
23 #include <ModelAPI_Data.h>
24 #include <ModelAPI_Events.h>
25 #include <Model_Expression.h>
26 #include <ModelAPI_Object.h>
28 Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel)
30 // to the same label to support the backward compatibility
31 myExpression.reset(new Model_ExpressionInteger(theLabel));
32 myIsInitialized = myExpression->isInitialized();
35 void Model_AttributeInteger::reinit()
37 myExpression->reinit();
38 myIsInitialized = myExpression->isInitialized();
41 void Model_AttributeInteger::setCalculatedValue(const int theValue)
43 if (!myIsInitialized || value() != theValue) {
44 myExpression->setValue(theValue);
45 owner()->data()->sendAttributeUpdated(this);
49 void Model_AttributeInteger::setValue(const int theValue)
51 setCalculatedValue(text().empty() ? theValue : value());
54 int Model_AttributeInteger::value()
56 return myExpression->value();
59 void Model_AttributeInteger::setText(const std::string& theValue)
61 if (text() != theValue) {
62 myExpression->setText(theValue);
63 // Send it to evaluator to convert text to integer and store in the attribute
64 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
65 owner()->data()->sendAttributeUpdated(this);
69 std::string Model_AttributeInteger::text()
71 return myExpression->text();
74 void Model_AttributeInteger::setExpressionInvalid(const bool theFlag)
76 myExpression->setInvalid(theFlag);
79 bool Model_AttributeInteger::expressionInvalid()
81 return myExpression->isInvalid();
84 void Model_AttributeInteger::setExpressionError(const std::string& theError)
86 if (expressionError() != theError)
87 myExpression->setError(theError);
90 std::string Model_AttributeInteger::expressionError()
92 return myExpression->error();
95 void Model_AttributeInteger::setUsedParameters(const std::set<std::string>& theUsedParameters)
97 myExpression->setUsedParameters(theUsedParameters);
100 std::set<std::string> Model_AttributeInteger::usedParameters() const
102 return myExpression->usedParameters();