X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_AttributeInteger.cpp;h=ef60113dda1edf8ba8376da3ae23170787d21430;hb=77ce6d35ac8d2f0fdaecb4f23e0870bf74e36103;hp=b93bfa855cec04391064137e5dea7d054ee32f13;hpb=f1cd93fd02a54259f72e3191d037323a496b2bef;p=modules%2Fshaper.git diff --git a/src/Model/Model_AttributeInteger.cpp b/src/Model/Model_AttributeInteger.cpp index b93bfa855..ef60113dd 100644 --- a/src/Model/Model_AttributeInteger.cpp +++ b/src/Model/Model_AttributeInteger.cpp @@ -1,37 +1,102 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: Model_AttributeInteger.cpp -// Created: 03 sep 2014 -// Author: sbh +// Copyright (C) 2014-2024 CEA, EDF +// +// 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::wstring& 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::wstring 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(); +}