Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributePythonObject.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_AttributePythonObject.cxx
21 //  Author : Michael Ponikarov
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_AttributePythonObject.hxx"
25 #include <Standard_GUID.hxx>
26 #include <string>
27
28 using namespace std;
29
30 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute )
31 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_AttributePythonObject, SALOMEDSImpl_GenericAttribute )
32
33 const Standard_GUID& SALOMEDSImpl_AttributePythonObject::GetID() 
34 {
35   static Standard_GUID SALOMEDSImpl_AttributePythonObjectID ("128371A3-8F52-11d6-A8A3-0001021E8C7F");
36   return SALOMEDSImpl_AttributePythonObjectID;
37 }
38
39 Handle(SALOMEDSImpl_AttributePythonObject) SALOMEDSImpl_AttributePythonObject::Set(const TDF_Label& label) 
40 {
41   Handle(SALOMEDSImpl_AttributePythonObject) anAttr;
42   if (!label.FindAttribute(SALOMEDSImpl_AttributePythonObject::GetID(),anAttr)) {
43     anAttr = new SALOMEDSImpl_AttributePythonObject();
44     label.AddAttribute(anAttr);
45   }
46   return anAttr;
47 }
48
49 SALOMEDSImpl_AttributePythonObject::SALOMEDSImpl_AttributePythonObject()
50 :SALOMEDSImpl_GenericAttribute("AttributePythonObject")
51 {
52 }
53
54 void SALOMEDSImpl_AttributePythonObject::SetObject(const TCollection_AsciiString& theSequence,
55                                                    const bool theScript) 
56 {
57   CheckLocked();    
58   Backup();
59   mySequence = theSequence;
60   myIsScript = theScript;
61
62   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
63 }
64
65 TCollection_AsciiString SALOMEDSImpl_AttributePythonObject::GetObject() const
66 {
67   return mySequence;
68 }
69
70 bool SALOMEDSImpl_AttributePythonObject::IsScript() const
71 {
72   return myIsScript;
73 }
74
75 int SALOMEDSImpl_AttributePythonObject::GetLength() const
76 {
77   return mySequence.Length();
78 }
79
80 const Standard_GUID& SALOMEDSImpl_AttributePythonObject::ID() const
81 {
82   return GetID();
83 }
84
85 void SALOMEDSImpl_AttributePythonObject::Restore(const Handle(TDF_Attribute)& with) 
86 {
87   Handle(SALOMEDSImpl_AttributePythonObject) anObj = Handle(SALOMEDSImpl_AttributePythonObject)::DownCast(with);
88   SetObject(anObj->GetObject(),anObj->IsScript());
89 }
90
91 Handle(TDF_Attribute) SALOMEDSImpl_AttributePythonObject::NewEmpty() const
92 {
93   return new SALOMEDSImpl_AttributePythonObject();
94 }
95
96 void SALOMEDSImpl_AttributePythonObject::Paste(const Handle(TDF_Attribute)& into,
97                                                const Handle(TDF_RelocationTable)&) const
98 {
99   Handle(SALOMEDSImpl_AttributePythonObject) anObj = Handle(SALOMEDSImpl_AttributePythonObject)::DownCast(into);
100   anObj->SetObject(GetObject(),IsScript());
101 }
102
103
104 TCollection_AsciiString SALOMEDSImpl_AttributePythonObject::Save() 
105 {
106   char* aString = (char*)GetObject().ToCString();
107   char* aResult = new char[strlen(aString) + 2];
108   aResult[0] = IsScript()?'s':'n';
109   strcpy(aResult+1, aString);
110   TCollection_AsciiString ret(aResult);
111   
112   delete aResult;
113   return ret;
114 }
115           
116 void SALOMEDSImpl_AttributePythonObject::Load(const TCollection_AsciiString& value) 
117 {
118   char* aString = value.ToCString();
119   SetObject(aString + 1, aString[0]=='s');
120 }