Salome HOME
"Integer" Attribute added.
[modules/shaper.git] / src / Model / Model_AttributeString.cpp
1 // File:        Model_AttributeString.cpp
2 // Created:     25 august 2014
3 // Author:      sbh
4
5 #include <Model_AttributeString.h>
6 #include <ModelAPI_AttributeString.h>
7 #include <ModelAPI_Attribute.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_Object.h>
10
11 #include <Standard_TypeDef.hxx>
12 #include <TCollection_AsciiString.hxx>
13 #include <TCollection_ExtendedString.hxx>
14 #include <TDataStd_Integer.hxx>
15 #include <TDataStd_Name.hxx>
16
17 #include <string>
18
19 void Model_AttributeString::setValue(const std::string& theValue)
20 {
21   TCollection_ExtendedString aValue(theValue.c_str());
22   if (!myIsInitialized || myString->Get() != aValue) {
23     myString->Set(aValue);
24     owner()->data()->sendAttributeUpdated(this);
25   }
26 }
27
28 std::string Model_AttributeString::value()
29 {
30   return TCollection_AsciiString(myString->Get()).ToCString();
31 }
32
33 Model_AttributeString::Model_AttributeString(TDF_Label& theLabel)
34 {
35   // check the attribute could be already presented in this doc (after load document)
36   myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myString) == Standard_True;
37   if (!myIsInitialized) {
38     // create attribute: not initialized by value yet, just empty string
39     myString = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
40   }
41 }