X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Expression.cpp;h=c7ad95c8188ee116a3fc086cbe8ac490a2d61dbc;hb=530f5aff42069e844c4a4ef164088ea23ba0e2dd;hp=27e94d4067eedbd0ab8f78b2d9bc63e36b6d9133;hpb=c80b46cd0d67df6fbb1f9dc1aa43f50f1e8ae9e9;p=modules%2Fshaper.git diff --git a/src/Model/Model_Expression.cpp b/src/Model/Model_Expression.cpp index 27e94d406..c7ad95c81 100644 --- a/src/Model/Model_Expression.cpp +++ b/src/Model/Model_Expression.cpp @@ -14,21 +14,67 @@ #include #include + +static Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096"); + + Model_Expression::Model_Expression(TDF_Label& theLabel) { - myIsInitialized = true; if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) { myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString()); - myIsInitialized = false; } if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myError)) { myError = TDataStd_Comment::Set(theLabel, TCollection_ExtendedString()); - myIsInitialized = false; } if (!theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myUsedParameters)) { myUsedParameters = TDataStd_ExtStringList::Set(theLabel); - myIsInitialized = false; } +} + +void Model_Expression::setText(const std::string& theValue) +{ + if (text() != theValue) + myText->Set(TCollection_ExtendedString(theValue.c_str())); + + setError(text().empty() ? "" : "Not a double value."); +} + +std::string Model_Expression::text() const +{ + return TCollection_AsciiString(myText->Get()).ToCString(); +} + +void Model_Expression::setError(const std::string& theError) +{ + if (error() != theError) + myError->Set(TCollection_ExtendedString(theError.c_str())); +} + +std::string Model_Expression::error() +{ + return TCollection_AsciiString(myError->Get()).ToCString(); +} + +void Model_Expression::setUsedParameters(const std::set& theUsedParameters) +{ + myUsedParameters->Clear(); + std::set::const_iterator anIt = theUsedParameters.begin(); + for (; anIt != theUsedParameters.end(); ++anIt) + myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str())); +} + +std::set Model_Expression::usedParameters() const +{ + std::set aResult; + TDataStd_ListIteratorOfListOfExtendedString aIt; + for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next()) + aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString()); + return aResult; +} + +Model_ExpressionDouble::Model_ExpressionDouble(TDF_Label& theLabel) + : Model_Expression(theLabel) +{ if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) { myReal = TDataStd_Real::Set(theLabel, 0.); myIsInitialized = false; @@ -52,37 +98,22 @@ Model_Expression::Model_Expression(TDF_Label& theLabel) } } } - - } + } else + myIsInitialized = true; } -void Model_Expression::setValue(const double theValue) +void Model_ExpressionDouble::setValue(const double theValue) { if (value() != theValue) myReal->Set(theValue); } -double Model_Expression::value() +double Model_ExpressionDouble::value() { return myReal->Get(); } -void Model_Expression::setText(const std::string& theValue) -{ - if (text() != theValue) - myText->Set(TCollection_ExtendedString(theValue.c_str())); - - setError(text().empty() ? "" : "Not a double value."); -} - -std::string Model_Expression::text() const -{ - return TCollection_AsciiString(myText->Get()).ToCString(); -} - -static Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096"); - -void Model_Expression::setInvalid(const bool theFlag) +void Model_ExpressionDouble::setInvalid(const bool theFlag) { if (theFlag) { TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID); @@ -91,35 +122,43 @@ void Model_Expression::setInvalid(const bool theFlag) } } -bool Model_Expression::isInvalid() +bool Model_ExpressionDouble::isInvalid() { return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True; } -void Model_Expression::setError(const std::string& theError) + +Model_ExpressionInteger::Model_ExpressionInteger(TDF_Label& theLabel) + : Model_Expression(theLabel) { - if (error() != theError) - myError->Set(TCollection_ExtendedString(theError.c_str())); + if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger)) { + myInteger = TDataStd_Integer::Set(theLabel, 0); + myIsInitialized = false; + } else + myIsInitialized = true; } -std::string Model_Expression::error() +void Model_ExpressionInteger::setValue(const int theValue) { - return TCollection_AsciiString(myError->Get()).ToCString(); + if (value() != theValue) + myInteger->Set(theValue); } -void Model_Expression::setUsedParameters(const std::set& theUsedParameters) +int Model_ExpressionInteger::value() { - myUsedParameters->Clear(); - std::set::const_iterator anIt = theUsedParameters.begin(); - for (; anIt != theUsedParameters.end(); ++anIt) - myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str())); + return myInteger->Get(); } -std::set Model_Expression::usedParameters() const +void Model_ExpressionInteger::setInvalid(const bool theFlag) { - std::set aResult; - TDataStd_ListIteratorOfListOfExtendedString aIt; - for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next()) - aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString()); - return aResult; + if (theFlag) { + TDataStd_UAttribute::Set(myInteger->Label(), kInvalidGUID); + } else { + myInteger->Label().ForgetAttribute(kInvalidGUID); + } +} + +bool Model_ExpressionInteger::isInvalid() +{ + return myInteger->Label().IsAttribute(kInvalidGUID) == Standard_True; }