X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeInteger.cpp;h=cd939550bb9cb1a2ca21bc976342351f082a5f55;hb=b0196aeefbaa53754b1052fab904386707caad87;hp=1d72baa40b37afe5d52534d5a237087d0755b103;hpb=af168c107750e3c62fc487ae55b3ac9a1ab67435;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeInteger.cpp b/src/Model/Model_AttributeInteger.cpp index 1d72baa40..cd939550b 100644 --- a/src/Model/Model_AttributeInteger.cpp +++ b/src/Model/Model_AttributeInteger.cpp @@ -1,35 +1,103 @@ -// File: Model_AttributeInteger.cpp -// Created: 03 sep 2014 -// Author: sbh +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #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(); +}