Salome HOME
Issue #1343 Fixes for creating extrusion on vertex
[modules/shaper.git] / src / Model / Model_Expression.cpp
index 27e94d4067eedbd0ab8f78b2d9bc63e36b6d9133..c7ad95c8188ee116a3fc086cbe8ac490a2d61dbc 100644 (file)
 #include <TDataStd_RealArray.hxx>
 #include <TDataStd_ExtStringArray.hxx>
 
+
+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<std::string>& theUsedParameters)
+{
+  myUsedParameters->Clear();
+  std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
+  for (; anIt != theUsedParameters.end(); ++anIt)
+    myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
+}
+
+std::set<std::string> Model_Expression::usedParameters() const
+{
+  std::set<std::string> 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<std::string>& theUsedParameters)
+int Model_ExpressionInteger::value()
 {
-  myUsedParameters->Clear();
-  std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
-  for (; anIt != theUsedParameters.end(); ++anIt)
-    myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
+  return myInteger->Get();
 }
 
-std::set<std::string> Model_Expression::usedParameters() const
+void Model_ExpressionInteger::setInvalid(const bool theFlag)
 {
-  std::set<std::string> 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;
 }