Salome HOME
Using variables in WidgetDoubleValue
[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
11 #include <TCollection_AsciiString.hxx>
12 #include <TCollection_ExtendedString.hxx>
13
14 using namespace std;
15
16 void Model_AttributeDouble::setValue(const double theValue)
17 {
18   if (!myIsInitialized || myReal->Get() != theValue) {
19     myReal->Set(theValue);
20     owner()->data()->sendAttributeUpdated(this);
21   }
22 }
23
24 double Model_AttributeDouble::value()
25 {
26   return myReal->Get();
27 }
28
29 Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
30 {
31   // check the attribute could be already presented in this doc (after load document)
32   myIsInitialized = theLabel.FindAttribute(TDataStd_Real::GetID(), myReal) == Standard_True;
33   if (!myIsInitialized) {
34     // create attribute: not initialized by value yet, just zero
35     myReal = TDataStd_Real::Set(theLabel, 0.);
36     myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
37   }
38 }
39
40 void Model_AttributeDouble::setText(const std::string& theValue)
41 {
42   TCollection_ExtendedString aValue(theValue.c_str());
43   if (myText->Get() != aValue) {
44     myText->Set(aValue);
45     //owner()->data()->sendAttributeUpdated(this); ?
46   }
47 }
48
49 string Model_AttributeDouble::text()
50 {
51   return TCollection_AsciiString(myText->Get()).ToCString();
52 }