Salome HOME
Make compilable on Linux
[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   }
37   if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
38     myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
39   }
40 }
41
42 void Model_AttributeDouble::setText(const std::string& theValue)
43 {
44   TCollection_ExtendedString aValue(theValue.c_str());
45   if (myText->Get() != aValue) {
46     myText->Set(aValue);
47     //owner()->data()->sendAttributeUpdated(this); ?
48   }
49 }
50
51 string Model_AttributeDouble::text()
52 {
53   return TCollection_AsciiString(myText->Get()).ToCString();
54 }