Back to index

salome-kernel  6.5.0
SALOMEDSImpl_AttributePythonObject.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SALOMEDSImpl_AttributePythonObject.cxx
00024 //  Author : Michael Ponikarov
00025 //  Module : SALOME
00026 //
00027 #include "SALOMEDSImpl_AttributePythonObject.hxx"
00028 
00029 const std::string& SALOMEDSImpl_AttributePythonObject::GetID() 
00030 {
00031   static std::string SALOMEDSImpl_AttributePythonObjectID ("128371A3-8F52-11d6-A8A3-0001021E8C7F");
00032   return SALOMEDSImpl_AttributePythonObjectID;
00033 }
00034 
00035 SALOMEDSImpl_AttributePythonObject* SALOMEDSImpl_AttributePythonObject::Set(const DF_Label& label) 
00036 {
00037   SALOMEDSImpl_AttributePythonObject* A = NULL;
00038   if (!(A = (SALOMEDSImpl_AttributePythonObject*)label.FindAttribute(SALOMEDSImpl_AttributePythonObject::GetID()))) {
00039     A = new SALOMEDSImpl_AttributePythonObject();
00040     label.AddAttribute(A);
00041   }
00042   return A;
00043 }
00044 
00045 SALOMEDSImpl_AttributePythonObject::SALOMEDSImpl_AttributePythonObject()
00046 :SALOMEDSImpl_GenericAttribute("AttributePythonObject")
00047 {
00048     myIsScript = false;
00049 }
00050 
00051 void SALOMEDSImpl_AttributePythonObject::SetObject(const std::string& theSequence,
00052                                                    const bool theScript) 
00053 {
00054   CheckLocked();
00055   Backup();
00056   mySequence = theSequence;
00057   myIsScript = theScript;
00058 
00059   SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved 
00060 }
00061 
00062 std::string SALOMEDSImpl_AttributePythonObject::GetObject() const
00063 {
00064   return mySequence;
00065 }
00066 
00067 bool SALOMEDSImpl_AttributePythonObject::IsScript() const
00068 {
00069   return myIsScript;
00070 }
00071 
00072 int SALOMEDSImpl_AttributePythonObject::GetLength() const
00073 {
00074   return mySequence.size();
00075 }
00076 
00077 const std::string& SALOMEDSImpl_AttributePythonObject::ID() const
00078 {
00079   return GetID();
00080 }
00081 
00082 void SALOMEDSImpl_AttributePythonObject::Restore(DF_Attribute* with) 
00083 {
00084   SALOMEDSImpl_AttributePythonObject* anObj = dynamic_cast<SALOMEDSImpl_AttributePythonObject*>(with);
00085   SetObject(anObj->GetObject(),anObj->IsScript());
00086 }
00087 
00088 DF_Attribute* SALOMEDSImpl_AttributePythonObject::NewEmpty() const
00089 {
00090   return new SALOMEDSImpl_AttributePythonObject();
00091 }
00092 
00093 void SALOMEDSImpl_AttributePythonObject::Paste(DF_Attribute* into)
00094 {
00095   SALOMEDSImpl_AttributePythonObject* anObj = dynamic_cast<SALOMEDSImpl_AttributePythonObject*>(into);
00096   anObj->SetObject(GetObject(),IsScript());
00097 }
00098 
00099 
00100 std::string SALOMEDSImpl_AttributePythonObject::Save() 
00101 {
00102   std::string aString = GetObject();
00103   std::string aResult = IsScript()?"s":"n";
00104   aResult += aString;
00105   
00106   return aResult;
00107 }
00108           
00109 void SALOMEDSImpl_AttributePythonObject::Load(const std::string& value) 
00110 {
00111   char* aString = (char*)value.c_str();
00112   SetObject(aString + 1, aString[0]=='s');
00113 }