Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributePythonObject.cxx
1 //  File   : SALOMEDSImpl_AttributePythonObject.cxx
2 //  Author : Michael Ponikarov
3 //  Module : SALOME
4
5 #include "SALOMEDSImpl_AttributePythonObject.hxx"
6 #include <Standard_GUID.hxx>
7 #include <string>
8
9 using namespace std;
10
11 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute )
12 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute )
13
14 const Standard_GUID& SALOMEDSImpl_AttributePythonObject::GetID() 
15 {
16   static Standard_GUID SALOMEDSImpl_AttributePythonObjectID ("128371A3-8F52-11d6-A8A3-0001021E8C7F");
17   return SALOMEDSImpl_AttributePythonObjectID;
18 }
19
20 Handle(SALOMEDSImpl_AttributePythonObject) SALOMEDSImpl_AttributePythonObject::Set(const TDF_Label& label) 
21 {
22   Handle(SALOMEDSImpl_AttributePythonObject) anAttr;
23   if (!label.FindAttribute(SALOMEDSImpl_AttributePythonObject::GetID(),anAttr)) {
24     anAttr = new SALOMEDSImpl_AttributePythonObject();
25     label.AddAttribute(anAttr);
26   }
27   return anAttr;
28 }
29
30 SALOMEDSImpl_AttributePythonObject::SALOMEDSImpl_AttributePythonObject()
31 :SALOMEDSImpl_GenericAttribute("AttributePythonObject")
32 {
33 }
34
35 void SALOMEDSImpl_AttributePythonObject::SetObject(const TCollection_AsciiString& theSequence,
36                                                    const bool theScript) 
37 {
38   CheckLocked();    
39   Backup();
40   mySequence = theSequence;
41   myIsScript = theScript;
42
43   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
44 }
45
46 TCollection_AsciiString SALOMEDSImpl_AttributePythonObject::GetObject() const
47 {
48   return mySequence;
49 }
50
51 bool SALOMEDSImpl_AttributePythonObject::IsScript() const
52 {
53   return myIsScript;
54 }
55
56 int SALOMEDSImpl_AttributePythonObject::GetLength() const
57 {
58   return mySequence.Length();
59 }
60
61 const Standard_GUID& SALOMEDSImpl_AttributePythonObject::ID() const
62 {
63   return GetID();
64 }
65
66 void SALOMEDSImpl_AttributePythonObject::Restore(const Handle(TDF_Attribute)& with) 
67 {
68   Handle(SALOMEDSImpl_AttributePythonObject) anObj = Handle(SALOMEDSImpl_AttributePythonObject)::DownCast(with);
69   SetObject(anObj->GetObject(),anObj->IsScript());
70 }
71
72 Handle(TDF_Attribute) SALOMEDSImpl_AttributePythonObject::NewEmpty() const
73 {
74   return new SALOMEDSImpl_AttributePythonObject();
75 }
76
77 void SALOMEDSImpl_AttributePythonObject::Paste(const Handle(TDF_Attribute)& into,
78                                                const Handle(TDF_RelocationTable)&) const
79 {
80   Handle(SALOMEDSImpl_AttributePythonObject) anObj = Handle(SALOMEDSImpl_AttributePythonObject)::DownCast(into);
81   anObj->SetObject(GetObject(),IsScript());
82 }
83
84
85 TCollection_AsciiString SALOMEDSImpl_AttributePythonObject::Save() 
86 {
87   char* aString = (char*)GetObject().ToCString();
88   char* aResult = new char[strlen(aString) + 2];
89   aResult[0] = IsScript()?'s':'n';
90   strcpy(aResult+1, aString);
91   TCollection_AsciiString ret(aResult);
92   
93   delete aResult;
94   return ret;
95 }
96           
97 void SALOMEDSImpl_AttributePythonObject::Load(const TCollection_AsciiString& value) 
98 {
99   char* aString = value.ToCString();
100   SetObject(aString + 1, aString[0]=='s');
101 }