X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeInteger.cpp;h=3f61cbd966561b8f2598c913ad3cb54e10d35589;hb=bdbfb368d71ed11cc0391354a7d86c880cd94949;hp=b93bfa855cec04391064137e5dea7d054ee32f13;hpb=38afbd899a8645c83e17f2c24a17a2b7414911b4;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeInteger.cpp b/src/Model/Model_AttributeInteger.cpp index b93bfa855..3f61cbd96 100644 --- a/src/Model/Model_AttributeInteger.cpp +++ b/src/Model/Model_AttributeInteger.cpp @@ -6,32 +6,84 @@ #include -#include #include +#include +#include #include -#include -#include +Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel) +{ + // to the same label to support the backward compatibility + myExpression.reset(new Model_ExpressionInteger(theLabel)); + myIsInitialized = myExpression->isInitialized(); +} -void Model_AttributeInteger::setValue(const int theValue) +void Model_AttributeInteger::reinit() { - if (!myIsInitialized || myInteger->Get() != theValue) { - myInteger->Set(theValue); + myExpression->reinit(); + myIsInitialized = myExpression->isInitialized(); +} + +void Model_AttributeInteger::setCalculatedValue(const int theValue) +{ + if (!myIsInitialized || value() != theValue) { + myExpression->setValue(theValue); owner()->data()->sendAttributeUpdated(this); } } +void Model_AttributeInteger::setValue(const int theValue) +{ + setCalculatedValue(text().empty() ? theValue : value()); +} + int Model_AttributeInteger::value() { - return myInteger->Get(); + return myExpression->value(); } -Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel) +void Model_AttributeInteger::setText(const std::string& theValue) { - // check the attribute could be already presented in this doc (after load document) - myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger) == Standard_True; - if (!myIsInitialized) { - // create attribute: not initialized by value yet, just zero - myInteger = TDataStd_Integer::Set(theLabel, 0); + if (text() != theValue) { + myExpression->setText(theValue); + // Send it to evaluator to convert text to integer and store in the attribute + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); + owner()->data()->sendAttributeUpdated(this); } } + +std::string Model_AttributeInteger::text() +{ + return myExpression->text(); +} + +void Model_AttributeInteger::setExpressionInvalid(const bool theFlag) +{ + myExpression->setInvalid(theFlag); +} + +bool Model_AttributeInteger::expressionInvalid() +{ + return myExpression->isInvalid(); +} + +void Model_AttributeInteger::setExpressionError(const std::string& theError) +{ + if (expressionError() != theError) + myExpression->setError(theError); +} + +std::string Model_AttributeInteger::expressionError() +{ + return myExpression->error(); +} + +void Model_AttributeInteger::setUsedParameters(const std::set& theUsedParameters) +{ + myExpression->setUsedParameters(theUsedParameters); +} + +std::set Model_AttributeInteger::usedParameters() const +{ + return myExpression->usedParameters(); +}