1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_AttributeDouble.cxx
5 // Author: Mikhail PONIKAROV
7 #include "Model_AttributeDouble.h"
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Events.h>
12 #include <TCollection_AsciiString.hxx>
13 #include <TCollection_ExtendedString.hxx>
14 #include <TDataStd_UAttribute.hxx>
18 void Model_AttributeDouble::setValue(const double theValue)
20 if (!myIsInitialized || myReal->Get() != theValue) {
21 myReal->Set(theValue);
22 owner()->data()->sendAttributeUpdated(this);
26 double Model_AttributeDouble::value()
31 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
33 // check the attribute could be already presented in this doc (after load document)
34 myIsInitialized = theLabel.FindAttribute(TDataStd_Real::GetID(), myReal) == Standard_True;
35 if (!myIsInitialized) {
36 // create attribute: not initialized by value yet, just zero
37 myReal = TDataStd_Real::Set(theLabel, 0.);
39 if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
40 myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
44 void Model_AttributeDouble::setText(const std::string& theValue)
46 TCollection_ExtendedString aValue(theValue.c_str());
47 if (myText->Get() != aValue) {
49 owner()->data()->sendAttributeUpdated(this);
51 // Send it to evaluator to convert into the double and store in the attribute
52 ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
56 string Model_AttributeDouble::text()
58 return TCollection_AsciiString(myText->Get()).ToCString();
61 Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
63 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
66 TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
68 myReal->Label().ForgetAttribute(kInvalidGUID);
72 bool Model_AttributeDouble::expressionInvalid()
74 return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;