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 #include <TDataStd_RealArray.hxx>
15 #include <TDataStd_ExtStringArray.hxx>
18 static Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
21 Model_Expression::Model_Expression(TDF_Label& theLabel)
23 if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
24 myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
26 if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myError)) {
27 myError = TDataStd_Comment::Set(theLabel, TCollection_ExtendedString());
29 if (!theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myUsedParameters)) {
30 myUsedParameters = TDataStd_ExtStringList::Set(theLabel);
34 void Model_Expression::setText(const std::string& theValue)
36 if (text() != theValue)
37 myText->Set(TCollection_ExtendedString(theValue.c_str()));
39 setError(text().empty() ? "" : "Not a double value.");
42 std::string Model_Expression::text() const
44 return TCollection_AsciiString(myText->Get()).ToCString();
47 void Model_Expression::setError(const std::string& theError)
49 if (error() != theError)
50 myError->Set(TCollection_ExtendedString(theError.c_str()));
53 std::string Model_Expression::error()
55 return TCollection_AsciiString(myError->Get()).ToCString();
58 void Model_Expression::setUsedParameters(const std::set<std::string>& theUsedParameters)
60 myUsedParameters->Clear();
61 std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
62 for (; anIt != theUsedParameters.end(); ++anIt)
63 myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
66 std::set<std::string> Model_Expression::usedParameters() const
68 std::set<std::string> aResult;
69 TDataStd_ListIteratorOfListOfExtendedString aIt;
70 for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next())
71 aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString());
75 Model_ExpressionDouble::Model_ExpressionDouble(TDF_Label& theLabel)
76 : Model_Expression(theLabel)
78 if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
79 myReal = TDataStd_Real::Set(theLabel, 0.);
80 myIsInitialized = false;
81 // MPV: temporarily to support the previously saved files (to check and resolve bugs), to be removed
82 Handle(TDataStd_RealArray) anOldArray;
83 if (theLabel.Father().FindAttribute(TDataStd_RealArray::GetID(), anOldArray) == Standard_True) {
84 myReal->Set(anOldArray->Value(theLabel.Tag() - 1));
85 myIsInitialized = true;
86 Handle(TDataStd_ExtStringArray) anOldExp;
87 if (theLabel.Father().FindAttribute(TDataStd_ExtStringArray::GetID(), anOldExp) == Standard_True) {
88 myText->Set(anOldExp->Value(theLabel.Tag() - 1));
91 Handle(TDataStd_Real) anOldReal;
92 if (theLabel.Father().FindAttribute(TDataStd_Real::GetID(), anOldReal)) {
93 myIsInitialized = true;
94 myReal->Set(anOldReal->Get());
95 Handle(TDataStd_Name) aText;
96 if (theLabel.Father().FindAttribute(TDataStd_Name::GetID(), aText)) {
97 myText->Set(aText->Get());
102 myIsInitialized = true;
105 void Model_ExpressionDouble::setValue(const double theValue)
107 if (value() != theValue)
108 myReal->Set(theValue);
111 double Model_ExpressionDouble::value()
113 return myReal->Get();
116 void Model_ExpressionDouble::setInvalid(const bool theFlag)
119 TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
121 myReal->Label().ForgetAttribute(kInvalidGUID);
125 bool Model_ExpressionDouble::isInvalid()
127 return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
131 Model_ExpressionInteger::Model_ExpressionInteger(TDF_Label& theLabel)
132 : Model_Expression(theLabel)
134 if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger)) {
135 myInteger = TDataStd_Integer::Set(theLabel, 0);
136 myIsInitialized = false;
138 myIsInitialized = true;
141 void Model_ExpressionInteger::setValue(const int theValue)
143 if (value() != theValue)
144 myInteger->Set(theValue);
147 int Model_ExpressionInteger::value()
149 return myInteger->Get();
152 void Model_ExpressionInteger::setInvalid(const bool theFlag)
155 TDataStd_UAttribute::Set(myInteger->Label(), kInvalidGUID);
157 myInteger->Label().ForgetAttribute(kInvalidGUID);
161 bool Model_ExpressionInteger::isInvalid()
163 return myInteger->Label().IsAttribute(kInvalidGUID) == Standard_True;