]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeDouble.cpp
Salome HOME
Issue #718 - Translation with parameters - wrong coordinates
[modules/shaper.git] / src / Model / Model_AttributeDouble.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_AttributeDouble.cxx
4 // Created:     2 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "Model_AttributeDouble.h"
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_Data.h>
10 #include <ModelAPI_Events.h>
11
12 #include <TCollection_AsciiString.hxx>
13 #include <TCollection_ExtendedString.hxx>
14 #include <TDataStd_UAttribute.hxx>
15
16 using namespace std;
17
18 void Model_AttributeDouble::setCalculatedValue(const double theValue)
19 {
20   if (!myIsInitialized || myReal->Get() != theValue) {
21     myReal->Set(theValue);
22     owner()->data()->sendAttributeUpdated(this);
23   }
24 }
25
26 void Model_AttributeDouble::setValue(const double theValue)
27 {
28   setCalculatedValue(text().empty() ? theValue : value());
29 }
30
31 double Model_AttributeDouble::value()
32 {
33   return myReal->Get();
34 }
35
36 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
37 {
38   // check the attribute could be already presented in this doc (after load document)
39   myIsInitialized = theLabel.FindAttribute(TDataStd_Real::GetID(), myReal) == Standard_True;
40   if (!myIsInitialized) {
41     // create attribute: not initialized by value yet, just zero
42     myReal = TDataStd_Real::Set(theLabel, 0.);
43   }
44   if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
45     myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
46   }
47 }
48
49 void Model_AttributeDouble::setText(const std::string& theValue)
50 {
51   TCollection_ExtendedString aValue(theValue.c_str());
52   if (myText->Get() != aValue) {
53     myText->Set(aValue);
54     owner()->data()->sendAttributeUpdated(this);
55
56     // Send it to evaluator to convert into the double and store in the attribute
57     ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
58   }
59 }
60
61 string Model_AttributeDouble::text()
62 {
63   return TCollection_AsciiString(myText->Get()).ToCString();
64 }
65
66 Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
67
68 void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
69 {
70   if (theFlag) {
71     TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
72   } else {
73     myReal->Label().ForgetAttribute(kInvalidGUID);
74   }
75 }
76
77 bool Model_AttributeDouble::expressionInvalid()
78 {
79   return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
80 }