Salome HOME
Copyright update 2022
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_AttributePythonObject.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
23 //  File   : SALOMEDSImpl_AttributePythonObject.cxx
24 //  Author : Michael Ponikarov
25 //  Module : SALOME
26 //
27 #include "SALOMEDSImpl_AttributePythonObject.hxx"
28
29 const std::string& SALOMEDSImpl_AttributePythonObject::GetID() 
30 {
31   static std::string SALOMEDSImpl_AttributePythonObjectID ("128371A3-8F52-11d6-A8A3-0001021E8C7F");
32   return SALOMEDSImpl_AttributePythonObjectID;
33 }
34
35 SALOMEDSImpl_AttributePythonObject* SALOMEDSImpl_AttributePythonObject::Set(const DF_Label& label) 
36 {
37   SALOMEDSImpl_AttributePythonObject* A = NULL;
38   if (!(A = (SALOMEDSImpl_AttributePythonObject*)label.FindAttribute(SALOMEDSImpl_AttributePythonObject::GetID()))) {
39     A = new SALOMEDSImpl_AttributePythonObject();
40     label.AddAttribute(A);
41   }
42   return A;
43 }
44
45 SALOMEDSImpl_AttributePythonObject::SALOMEDSImpl_AttributePythonObject()
46 :SALOMEDSImpl_GenericAttribute("AttributePythonObject")
47 {
48     myIsScript = false;
49 }
50
51 void SALOMEDSImpl_AttributePythonObject::SetObject(const std::string& theSequence,
52                                                    const bool theScript) 
53 {
54   CheckLocked();
55   Backup();
56   mySequence = theSequence;
57   myIsScript = theScript;
58
59   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
60 }
61
62 std::string SALOMEDSImpl_AttributePythonObject::GetObject() const
63 {
64   return mySequence;
65 }
66
67 bool SALOMEDSImpl_AttributePythonObject::IsScript() const
68 {
69   return myIsScript;
70 }
71
72 int SALOMEDSImpl_AttributePythonObject::GetLength() const
73 {
74   return (int)mySequence.size(); //!< TODO: conversion from size_t to int
75 }
76
77 const std::string& SALOMEDSImpl_AttributePythonObject::ID() const
78 {
79   return GetID();
80 }
81
82 void SALOMEDSImpl_AttributePythonObject::Restore(DF_Attribute* with) 
83 {
84   SALOMEDSImpl_AttributePythonObject* anObj = dynamic_cast<SALOMEDSImpl_AttributePythonObject*>(with);
85   SetObject(anObj->GetObject(),anObj->IsScript());
86 }
87
88 DF_Attribute* SALOMEDSImpl_AttributePythonObject::NewEmpty() const
89 {
90   return new SALOMEDSImpl_AttributePythonObject();
91 }
92
93 void SALOMEDSImpl_AttributePythonObject::Paste(DF_Attribute* into)
94 {
95   SALOMEDSImpl_AttributePythonObject* anObj = dynamic_cast<SALOMEDSImpl_AttributePythonObject*>(into);
96   anObj->SetObject(GetObject(),IsScript());
97 }
98
99
100 std::string SALOMEDSImpl_AttributePythonObject::Save() 
101 {
102   std::string aString = GetObject();
103   std::string aResult = IsScript()?"s":"n";
104   aResult += aString;
105   
106   return aResult;
107 }
108           
109 void SALOMEDSImpl_AttributePythonObject::Load(const std::string& value) 
110 {
111   char* aString = (char*)value.c_str();
112   SetObject(aString + 1, aString[0]=='s');
113 }