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