1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Expression.cpp
5 // Author: Sergey POKHODENKO
7 #include "Model_Expression.h"
9 #include <TCollection_AsciiString.hxx>
10 #include <TCollection_ExtendedString.hxx>
11 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
12 #include <TDataStd_UAttribute.hxx>
14 Model_Expression::Model_Expression(TDF_Label& theLabel)
16 myIsInitialized = true;
17 if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
18 myReal = TDataStd_Real::Set(theLabel, 0.);
19 myIsInitialized = false;
21 if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
22 myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
23 myIsInitialized = false;
25 if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myError)) {
26 myError = TDataStd_Comment::Set(theLabel, TCollection_ExtendedString());
27 myIsInitialized = false;
29 if (!theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myUsedParameters)) {
30 myUsedParameters = TDataStd_ExtStringList::Set(theLabel);
31 myIsInitialized = false;
35 void Model_Expression::setValue(const double theValue)
37 if (value() != theValue)
38 myReal->Set(theValue);
41 double Model_Expression::value()
46 void Model_Expression::setText(const std::string& theValue)
48 if (text() != theValue)
49 myText->Set(TCollection_ExtendedString(theValue.c_str()));
52 std::string Model_Expression::text() const
54 return TCollection_AsciiString(myText->Get()).ToCString();
57 static Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
59 void Model_Expression::setInvalid(const bool theFlag)
62 TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
64 myReal->Label().ForgetAttribute(kInvalidGUID);
68 bool Model_Expression::isInvalid()
70 return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
73 void Model_Expression::setError(const std::string& theError)
75 if (error() != theError)
76 myError->Set(TCollection_ExtendedString(theError.c_str()));
79 std::string Model_Expression::error()
81 return TCollection_AsciiString(myError->Get()).ToCString();
84 void Model_Expression::setUsedParameters(const std::set<std::string>& theUsedParameters)
86 myUsedParameters->Clear();
87 std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
88 for (; anIt != theUsedParameters.end(); ++anIt)
89 myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
92 std::set<std::string> Model_Expression::usedParameters() const
94 std::set<std::string> aResult;
95 TDataStd_ListIteratorOfListOfExtendedString aIt;
96 for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next())
97 aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString());