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