From: rnv Date: Tue, 28 Oct 2008 11:29:30 +0000 (+0000) Subject: Start Dump Python extension task. X-Git-Tag: TG_DumpPython_Extension_1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c2671d27296822a8a6e8fb5cbe4264ba0305e272;p=modules%2Fkernel.git Start Dump Python extension task. --- diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 6fd42cd02..80c75954b 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -427,7 +427,55 @@ during each working session. */ ListOfStrings GetLockerID(); +/*! + TODO: Write comments. +*/ + void SetReal( in string theVarName, in double theValue ); +/*! + + TODO: Write comments. +*/ + void SetInteger( in string theVarName, in long theValue ); +/*! + TODO: Write comments. +*/ + void SetBoolean( in string theVarName, in boolean theValue ); + +/*! + TODO: Write comments. +*/ + double GetReal( in string theVarName ); +/*! + TODO: Write comments. +*/ + long GetInteger( in string theVarName ); + +/*! + TODO: Write comments. +*/ + boolean GetBoolean( in string theVarName ); + + +/*! + TODO: Write comments. +*/ + boolean IsReal( in string theVarName ); + +/*! + TODO: Write comments. +*/ + boolean IsInteger( in string theVarName ); +/*! + TODO: Write comments. +*/ + boolean IsBoolean( in string theVarName ); + +/*! + TODO: Write comments. +*/ + boolean IsVariable( in string theVarName ); + ListOfStrings GetVariableNames(); }; //========================================================================== diff --git a/src/KERNEL_PY/Makefile.am b/src/KERNEL_PY/Makefile.am index 3b4e96641..1819be4de 100755 --- a/src/KERNEL_PY/Makefile.am +++ b/src/KERNEL_PY/Makefile.am @@ -40,7 +40,8 @@ salomepython_PYTHON = \ salome_ComponentGUI.py \ omnipatch.py \ iparameters.py \ - salome_version.py + salome_version.py \ + salome_notebook.py sharedpkgpython_PYTHON = kernel_shared_modules.py diff --git a/src/KERNEL_PY/salome_notebook.py b/src/KERNEL_PY/salome_notebook.py new file mode 100644 index 000000000..08da078ff --- /dev/null +++ b/src/KERNEL_PY/salome_notebook.py @@ -0,0 +1,62 @@ +# Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# +# +# File : salome_notebook.py +# Author : Roman NIKOLAEV, Open CASCADE S.A.S. +# Module : SALOME +# $Header: +""" +Module salome_notebook gives access to Salome Notebook. +""" + +import salome + +class NoteBook: + + def __init__(self, Study): + self.myStudy = Study + + def set(self, variableName, variable): + if type(variable) == float: + self.myStudy.SetReal(variableName, variable) + + elif type(variable) == int: + self.myStudy.SetInteger(variableName, variable) + + elif type(variable) == bool: + self.myStudy.SetBoolean(variableName, variable) + + def get(self, variableName): + aResult = None + if self.myStudy.IsVariable(variableName): + + if self.myStudy.IsReal(variableName): + aResult = self.myStudy.GetReal(variableName) + + elif self.myStudy.IsInteger(variableName): + aResult = self.myStudy.GetInteger(variableName) + + elif self.myStudy.IsBoolean(variableName): + aResult = self.myStudy.GetBoolean(variableName) + + return aResult + +notebook = NoteBook(salome.myStudy) diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 3bfebc5b0..14797c541 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -44,6 +44,7 @@ #include "SALOMEDSImpl_SComponentIterator.hxx" #include "SALOMEDSImpl_AttributeStudyProperties.hxx" #include "SALOMEDSImpl_AttributeParameter.hxx" +#include "SALOMEDSImpl_GenericVariable.hxx" #include "SALOMEDSImpl_UseCaseBuilder.hxx" #include "SALOMEDS_Driver_i.hxx" @@ -679,6 +680,146 @@ vector SALOMEDS_Study::GetLockerID() return aVector; } + +void SALOMEDS_Study::SetReal(const string& theVarName, const double theValue) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetVariable(theVarName, + theValue, + SALOMEDSImpl_GenericVariable::REAL_VAR); + } + else + _corba_impl->SetReal((char*)theVarName.c_str(),theValue); +} + +void SALOMEDS_Study::SetInteger(const string& theVarName, const int theValue) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetVariable(theVarName, + theValue, + SALOMEDSImpl_GenericVariable::INTEGER_VAR); + } + else + _corba_impl->SetInteger((char*)theVarName.c_str(),theValue); +} + +void SALOMEDS_Study::SetBoolean(const string& theVarName, const bool theValue) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetVariable(theVarName, + theValue, + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); + } + else + _corba_impl->SetBoolean((char*)theVarName.c_str(),theValue); +} + +double SALOMEDS_Study::GetReal(const string& theVarName) +{ + double aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->GetVariable(theVarName); + } + else + aResult = _corba_impl->GetReal((char*)theVarName.c_str()); + return aResult; +} + +int SALOMEDS_Study::GetInteger(const string& theVarName) +{ + int aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = (int) _local_impl->GetVariable(theVarName); + } + else + aResult = _corba_impl->GetInteger((char*)theVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::GetBoolean(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = (bool) _local_impl->GetVariable(theVarName); + } + else + aResult = _corba_impl->GetBoolean((char*)theVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::IsReal(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->IsTypeOf(theVarName, + SALOMEDSImpl_GenericVariable::REAL_VAR); + } + else + aResult = _corba_impl->IsReal((char*)theVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::IsInteger(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->IsTypeOf(theVarName, + SALOMEDSImpl_GenericVariable::INTEGER_VAR); + } + else + aResult = _corba_impl->IsInteger((char*)theVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::IsBoolean(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->IsTypeOf(theVarName, + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); + } + else + aResult = _corba_impl->IsBoolean((char*)theVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::IsVariable(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->IsVariable(theVarName); + } + else + aResult = _corba_impl->IsVariable((char*)theVarName.c_str()); + return aResult; +} + +vector SALOMEDS_Study::GetVariableNames() +{ + vector aVector; + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetVariableNames(); + } + else { + SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames(); + int aLength = aSeq->length(); + for (int i = 0; i < aLength; i++) + aVector.push_back( string(aSeq[i].in()) ); + } + return aVector; +} + std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) { return _orb->object_to_string(theObject); diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index e893ce684..2a0775ee4 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -96,6 +96,21 @@ public: virtual void UnLockStudy(const std::string& theLockerID); virtual std::vector GetLockerID(); + virtual void SetReal(const std::string& theVarName, const double theValue); + virtual void SetInteger(const std::string& theVarName, const int theValue); + virtual void SetBoolean(const std::string& theVarName, const bool theValue); + + virtual double GetReal(const std::string& theVarName); + virtual int GetInteger(const std::string& theVarName); + virtual bool GetBoolean(const std::string& theVarName); + + virtual bool IsReal(const std::string& theVarName); + virtual bool IsInteger(const std::string& theVarName); + virtual bool IsBoolean(const std::string& theVarName); + + virtual bool IsVariable(const std::string& theVarName); + virtual std::vector GetVariableNames(); + std::string ConvertObjectToIOR(CORBA::Object_ptr theObject); CORBA::Object_ptr ConvertIORToObject(const std::string& theIOR); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 1f5f2a127..3f161946c 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -843,6 +843,133 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID() } return aResult._retn(); } +//============================================================================ +/*! Function : SetReal + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue) +{ + _impl->SetVariable(string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::REAL_VAR); +} + +//============================================================================ +/*! Function : SetInteger + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue) +{ + _impl->SetVariable(string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::INTEGER_VAR); +} + +//============================================================================ +/*! Function : SetBoolean + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue) +{ + _impl->SetVariable(string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); +} + +//============================================================================ +/*! Function : GetReal + * Purpose : + */ +//============================================================================ +CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName) +{ + return _impl->GetVariable(string(theVarName)); +} + +//============================================================================ +/*! Function : GetInteger + * Purpose : + */ +//============================================================================ +CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName) +{ + return (int)_impl->GetVariable(string(theVarName)); +} + +//============================================================================ +/*! Function : GetBoolean + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName) +{ + return (bool)_impl->GetVariable(string(theVarName)); +} + +//============================================================================ +/*! Function : IsReal + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName) +{ + return _impl->IsTypeOf(string(theVarName), + SALOMEDSImpl_GenericVariable::REAL_VAR); +} + +//============================================================================ +/*! Function : IsInteger + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName) +{ + return _impl->IsTypeOf(string(theVarName), + SALOMEDSImpl_GenericVariable::INTEGER_VAR); +} + +//============================================================================ +/*! Function : IsBoolean + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName) +{ + return _impl->IsTypeOf(string(theVarName), + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); +} + +//============================================================================ +/*! Function : IsVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName) +{ + return _impl->IsVariable(string(theVarName)); +} + +//============================================================================ +/*! Function : GetVariableNames + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames() +{ + vector aVarNames = _impl->GetVariableNames(); + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; + + int aLen = aVarNames.size(); + aResult->length(aLen); + + for (int anInd = 0; anInd < aLen; anInd++) + aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str()); + + return aResult._retn(); +} //============================================================================ /*! Function : GetDefaultScript diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index efb31e66e..fa59532c6 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -294,6 +294,28 @@ public: virtual SALOMEDS::ListOfStrings* GetLockerID(); + virtual void SetReal(const char* theVarName, CORBA::Double theValue); + + virtual void SetInteger(const char* theVarName, CORBA::Long theValue); + + virtual void SetBoolean(const char* theVarName, CORBA::Boolean theValue); + + virtual CORBA::Double GetReal(const char* theVarName); + + virtual CORBA::Long GetInteger(const char* theVarName); + + virtual CORBA::Boolean GetBoolean(const char* theVarName); + + virtual CORBA::Boolean IsReal(const char* theVarName); + + virtual CORBA::Boolean IsInteger(const char* theVarName); + + virtual CORBA::Boolean IsBoolean(const char* theVarName); + + virtual CORBA::Boolean IsVariable(const char* theVarName); + + virtual SALOMEDS::ListOfStrings* GetVariableNames(); + virtual char* GetDefaultScript(const char* theModuleName, const char* theShift); virtual CORBA::Boolean DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished); diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx index 33182f673..d2f48e16e 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -91,6 +91,22 @@ public: virtual bool IsStudyLocked() = 0; virtual void UnLockStudy(const std::string& theLockerID) = 0; virtual std::vector GetLockerID() = 0; + + virtual void SetReal(const std::string& theVarName, const double theValue) = 0; + virtual void SetInteger(const std::string& theVarName, const int theValue) = 0; + virtual void SetBoolean(const std::string& theVarName, const bool theValue) = 0; + + virtual double GetReal(const std::string& theVarName) = 0; + virtual int GetInteger(const std::string& theVarName) = 0; + virtual bool GetBoolean(const std::string& theVarName) = 0; + + virtual bool IsReal(const std::string& theVarName) = 0; + virtual bool IsInteger(const std::string& theVarName) = 0; + virtual bool IsBoolean(const std::string& theVarName) = 0; + + virtual bool IsVariable(const std::string& theVarName) = 0; + virtual std::vector GetVariableNames() = 0; + }; diff --git a/src/SALOMEDSImpl/Makefile.am b/src/SALOMEDSImpl/Makefile.am index de0b5f12e..7678cdd3e 100644 --- a/src/SALOMEDSImpl/Makefile.am +++ b/src/SALOMEDSImpl/Makefile.am @@ -76,7 +76,9 @@ salomeinclude_HEADERS= \ SALOMEDSImpl_ChildNodeIterator.hxx \ SALOMEDSImpl_Defines.hxx \ SALOMEDSImpl_IParameters.hxx \ - SALOMEDSImpl_TMPFile.hxx + SALOMEDSImpl_TMPFile.hxx \ + SALOMEDSImpl_GenericVariable.hxx \ + SALOMEDSImpl_ScalarVariable.hxx # # =============================================================== @@ -154,6 +156,8 @@ libSalomeDSImpl_la_SOURCES =\ SALOMEDSImpl_StudyManager.cxx \ SALOMEDSImpl_IParameters.cxx \ SALOMEDSImpl_TMPFile.cxx \ + SALOMEDSImpl_GenericVariable.cxx \ + SALOMEDSImpl_ScalarVariable.cxx \ \ SALOMEDSImpl_AttributeComment.hxx \ SALOMEDSImpl_AttributeDrawable.hxx \ @@ -202,7 +206,9 @@ libSalomeDSImpl_la_SOURCES =\ SALOMEDSImpl_StudyManager.hxx \ SALOMEDSImpl_Tool.hxx \ SALOMEDSImpl_UseCaseBuilder.hxx \ - SALOMEDSImpl_UseCaseIterator.hxx + SALOMEDSImpl_UseCaseIterator.hxx \ + SALOMEDSImpl_GenericVariable.hxx \ + SALOMEDSImpl_ScalarVariable.hxx libSalomeDSImpl_la_CPPFLAGS = $(COMMON_CPPFLAGS) libSalomeDSImpl_la_LDFLAGS = -no-undefined -version-info=0:0:0 diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx new file mode 100644 index 000000000..5c6840b72 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx @@ -0,0 +1,141 @@ +// Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SALOMEDSImpl_GenericVariable.cxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. +// Module : SALOME + +#include "SALOMEDSImpl_GenericVariable.hxx" +#include "SALOMEDSImpl_Attributes.hxx" +#include "SALOMEDSImpl_Study.hxx" + +#include + + +using namespace std; + +//============================================================================ +/*! Function : SALOMEDSImpl_GenericVariable + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_GenericVariable:: +SALOMEDSImpl_GenericVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType): + _type(theType) +{} + +//============================================================================ +/*! Function : ~SALOMEDSImpl_GenericVariable + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_GenericVariable::~SALOMEDSImpl_GenericVariable() +{} + +//============================================================================ +/*! Function : Type + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_GenericVariable::VariableTypes SALOMEDSImpl_GenericVariable::Type() const +{ + return _type; +} + +//============================================================================ +/*! Function : setType + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_GenericVariable::setType(const SALOMEDSImpl_GenericVariable::VariableTypes theType) +{ + _type = theType; +} + +//============================================================================ +/*! Function : CheckLocked + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_GenericVariable::CheckLocked() +{ + DF_Label aLabel = DF_Label(); + if(aLabel.IsNull()) return; + + SALOMEDSImpl_Study* aStudy = SALOMEDSImpl_Study::GetStudy(aLabel); + if(!aStudy) return; + if(aStudy->IsLocked()) { + aStudy->_errorCode = "LockProtection"; + throw LockProtection("LockProtection"); + } +} + +//============================================================================ +/*! Function : SetModifyFlag + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_GenericVariable::SetModifyFlag() +{ + DF_Label aLabel = DF_Label(); + if(aLabel.IsNull()) return; + + SALOMEDSImpl_Study* aStudy = SALOMEDSImpl_Study::GetStudy(aLabel); + if(aStudy) aStudy->Modify(); +} + + +//============================================================================ +/*! Function : String2VariableType + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_GenericVariable::VariableTypes SALOMEDSImpl_GenericVariable::String2VariableType(const string& theStrType) +{ + return(SALOMEDSImpl_GenericVariable::VariableTypes)atoi((char*)theStrType.c_str()); +} + +//============================================================================ +/*! Function : Save + * Purpose : + */ +//============================================================================ +string SALOMEDSImpl_GenericVariable::Save() const +{ + return string(); +} + +//============================================================================ +/*! Function : SaveType + * Purpose : + */ +//============================================================================ +string SALOMEDSImpl_GenericVariable::SaveType() const +{ + return string(); +} + +//============================================================================ +/*! Function : Load + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_GenericVariable::Load(const string& theStrValue) +{ +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx new file mode 100644 index 000000000..d40d5cd53 --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx @@ -0,0 +1,62 @@ +// Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SALOMEDSImpl_GenericVariable.hxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. +// Module : SALOME + +#ifndef _GENERICIMPL_VARIABLE_HXX_ +#define _GENERICIMPL_VARIABLE_HXX_ + +#include "SALOMEDSImpl_Defines.hxx" + +#include + +//This is base class for all variable of the Salome notebook + +class SALOMEDSIMPL_EXPORT SALOMEDSImpl_GenericVariable +{ + public: + + //Supported types of the nootebook variables + enum VariableTypes{REAL_VAR, INTEGER_VAR, BOOLEAN_VAR}; + + SALOMEDSImpl_GenericVariable(VariableTypes theType); + ~SALOMEDSImpl_GenericVariable(); + + VariableTypes Type() const; + + static VariableTypes String2VariableType(const std::string& theStrType); + + void setType(const VariableTypes theType); + + virtual void CheckLocked(); + + virtual void SetModifyFlag(); + + virtual std::string Save() const; + virtual std::string SaveType() const; + + virtual void Load(const std::string& theStrValue); + + private: + VariableTypes _type; +}; + +#endif //_GENERICIMPL_VARIABLE_HXX_ diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.cxx new file mode 100644 index 000000000..036c5c0ae --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.cxx @@ -0,0 +1,118 @@ +// Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SALOMEDSImpl_ScalarVariable.cxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. +// Module : SALOME + +#include "SALOMEDSImpl_ScalarVariable.hxx" +#include "SALOMEDSImpl_GenericVariable.hxx" +#include +using namespace std; + +//============================================================================ +/*! Function : SALOMEDSImpl_ScalarVariable + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_ScalarVariable:: +SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type): + SALOMEDSImpl_GenericVariable(type) +{} + +//============================================================================ +/*! Function : ~SALOMEDSImpl_ScalarVariable() + * Purpose : + */ +//============================================================================ +SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){} + +//============================================================================ +/*! Function : + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_ScalarVariable::setValue(const double theValue) +{ + CheckLocked(); + + if(myValue == theValue) + return; + + myValue = theValue; + + SetModifyFlag(); +} + +//============================================================================ +/*! Function : getValue() + * Purpose : + */ +//============================================================================ +double SALOMEDSImpl_ScalarVariable::getValue() const +{ + return myValue; +} + +//============================================================================ +/*! Function : Save() + * Purpose : + */ +//============================================================================ +string SALOMEDSImpl_ScalarVariable::Save() const{ + char buffer[255]; + switch(Type()) + { + case SALOMEDSImpl_GenericVariable::REAL_VAR: + { + sprintf(buffer, "%.64e", myValue); + break; + } + case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR: + case SALOMEDSImpl_GenericVariable::INTEGER_VAR: + { + sprintf(buffer, "%d", (int)myValue); + } + default:break; + } + return string(buffer); +} + + +//============================================================================ +/*! Function : SaveType() + * Purpose : + */ +//============================================================================ +string SALOMEDSImpl_ScalarVariable::SaveType() const{ + char buffer[255]; + sprintf(buffer, "%d", (int)Type()); + return string(buffer); +} + +//============================================================================ +/*! Function : Load() + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_ScalarVariable::Load(const string& theStrValue) +{ + double aValue = atof(theStrValue.c_str()); + setValue(aValue); +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.hxx new file mode 100644 index 000000000..94316a47c --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_ScalarVariable.hxx @@ -0,0 +1,50 @@ +// Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SALOMEDSImpl_ScalarVariable.hxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. +// Module : SALOME + +#ifndef _SALOMEDSImpl_ScalarVariable_HeaderFile +#define _SALOMEDSImpl_ScalarVariable_HeaderFile + +#include "SALOMEDSImpl_Defines.hxx" +#include "SALOMEDSImpl_GenericVariable.hxx" + +class SALOMEDSIMPL_EXPORT SALOMEDSImpl_ScalarVariable : + public SALOMEDSImpl_GenericVariable +{ +public: + SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType); + ~SALOMEDSImpl_ScalarVariable(); + + void setValue(const double theValue); + double getValue() const; + + virtual std::string Save() const; + virtual std::string SaveType() const; + + virtual void Load(const std::string& theStrValue); + +private: + double myValue; +}; + + +#endif //_SALOMEDSImpl_ScalarVariable_HeaderFile diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 34ee8ed7b..5b1b02411 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -36,6 +36,7 @@ using namespace std; #include "SALOMEDSImpl_StudyHandle.hxx" #include "SALOMEDSImpl_Tool.hxx" #include "SALOMEDSImpl_IParameters.hxx" +#include "SALOMEDSImpl_ScalarVariable.hxx" #include @@ -1485,6 +1486,106 @@ vector SALOMEDSImpl_Study::GetLockerID() return _lockers; } +//============================================================================ +/*! Function : SetVariable + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::SetVariable(const string& theVarName, + const double theValue, + const SALOMEDSImpl_GenericVariable::VariableTypes theType) +{ + std::map::iterator it + = myNoteBookVars.find(theVarName); + + SALOMEDSImpl_ScalarVariable* aVar = NULL; + if( it == myNoteBookVars.end() ) { + + aVar = new SALOMEDSImpl_ScalarVariable(theType); + + aVar->setValue(theValue); + myNoteBookVars[theVarName] = aVar; + } + else { + if(aVar = dynamic_cast((*it).second)) { + aVar->setValue(theValue); + if(aVar->Type() != theType) + aVar->setType(theType); + } + } +} + +//============================================================================ +/*! Function : GetReal + * Purpose : + */ +//============================================================================ +double SALOMEDSImpl_Study::GetVariable(const string& theVarName) +{ + std::map::const_iterator it = + myNoteBookVars.find(theVarName); + + if(it != myNoteBookVars.end()) + if(SALOMEDSImpl_ScalarVariable* aVar = dynamic_cast((*it).second)) + return aVar->getValue(); +} + +//============================================================================ +/*! Function : IsTypeOf + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::IsTypeOf(const string& theVarName, + SALOMEDSImpl_GenericVariable:: + VariableTypes theType) const +{ + std::map::const_iterator it = + myNoteBookVars.find(theVarName); + + if(it != myNoteBookVars.end()) + return (*it).second->Type() == theType; + + return false; +} + +//============================================================================ +/*! Function : IsVariable + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const +{ + return myNoteBookVars.find(theVarName) != myNoteBookVars.end(); +} + +//============================================================================ +/*! Function : GetVariableNames + * Purpose : + */ +//============================================================================ +vector SALOMEDSImpl_Study::GetVariableNames() const +{ + vector aResult; + std::map::const_iterator it = + myNoteBookVars.begin(); + + for(; it != myNoteBookVars.end(); it++) + aResult.push_back((*it).first); + + return aResult; +} + +//============================================================================ +/*! Function : AddVariable + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::AddVariable(const string& theVarName, + SALOMEDSImpl_GenericVariable* theVariable) +{ + myNoteBookVars[theVarName] = theVariable; +} + //============================================================================ /*! Function : EnableUseCaseAutoFilling * Purpose : diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index a28f2d164..ed7982084 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -46,11 +46,11 @@ #include "SALOMEDSImpl_Callback.hxx" #include "SALOMEDSImpl_Driver.hxx" #include "SALOMEDSImpl_ChildIterator.hxx" +#include "SALOMEDSImpl_GenericVariable.hxx" class SALOMEDSImpl_StudyManager; class SALOMEDSImpl_GenericAttribute; - class SALOMEDSIMPL_EXPORT SALOMEDSImpl_Study { private: @@ -70,7 +70,7 @@ private: std::map _mapOfSO; std::map _mapOfSCO; std::map myIORLabels; - + std::map myNoteBookVars; SALOMEDSImpl_SObject _FindObject(const SALOMEDSImpl_SObject& SO, const std::string& anObjectName, @@ -250,6 +250,27 @@ public: //Returns an ID of the study locker std::vector GetLockerID(); + /*! + TODO: Write comments for new functions. + */ + + void SetVariable(const std::string& theVarName, + const double theValue, + const SALOMEDSImpl_GenericVariable::VariableTypes); + + double GetVariable(const std::string& theVarName); + + bool IsTypeOf(const std::string& theVarName, + SALOMEDSImpl_GenericVariable::VariableTypes theType) const; + + bool IsVariable(const std::string& theVarName) const; + + std::vector GetVariableNames() const; + + void AddVariable(const std::string& theVarName, + SALOMEDSImpl_GenericVariable* theVariable); + + //Returns a callback SALOMEDSImpl_Callback* GetCallback() { return _cb; } @@ -258,5 +279,6 @@ public: friend class SALOMEDSImpl_StudyManager; friend class SALOMEDSImpl_GenericAttribute; + friend class SALOMEDSImpl_GenericVariable; }; #endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index bd904c91b..9fb0cbefe 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -30,6 +30,7 @@ #include "SALOMEDSImpl_Tool.hxx" #include "SALOMEDSImpl_SComponent.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_ScalarVariable.hxx" #include #include "HDFOI.hxx" @@ -45,6 +46,7 @@ static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDF static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*); static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&, SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII); +static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup); //============================================================================ /*! Function : SALOMEDSImpl_StudyManager @@ -111,6 +113,7 @@ SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl) // open the HDFFile HDFfile *hdf_file =0; HDFgroup *hdf_group_study_structure =0; + HDFgroup *hdf_notebook_vars = 0; char* aC_HDFUrl; string aHDFUrl; @@ -164,8 +167,8 @@ SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl) if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) { _errorCode = "Study is empty"; return Study; - } - + } + //Create the Structure of the Document hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); @@ -184,8 +187,14 @@ SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl) return NULL; } - hdf_file->CloseOnDisk(); + //Read and create notebook variables + hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); + ReadNoteBookVariables(Study,hdf_notebook_vars); + hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor + hdf_file->CloseOnDisk(); + hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); + if (isASCII) { vector aFilesToRemove; aFilesToRemove.push_back("hdf_from_ascii.hdf"); @@ -457,6 +466,8 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, HDFgroup *hdf_group_study_structure =0; HDFgroup *hdf_sco_group =0; HDFgroup *hdf_sco_group2 =0; + HDFgroup *hdf_notebook_vars =0; + HDFgroup *hdf_notebook_var = 0; HDFgroup *hdf_group_datacomponent =0; HDFdataset *hdf_dataset =0; @@ -633,10 +644,52 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, hdf_soo_group->CloseOnDisk(); hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor } + //----------------------------------------------------------------------- + //5 - Write the NoteBook Variables + //----------------------------------------------------------------------- + //5.1 Create group to store all note book variables + hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); + hdf_notebook_vars->CreateOnDisk(); + + map ::const_iterator it = + aStudy->myNoteBookVars.begin(); + string varValue; + string varType; + + for( ;it != aStudy->myNoteBookVars.end(); it++ ){ + // For each variable create HDF group + hdf_notebook_var = new HDFgroup((char*)(*it).first.c_str(),hdf_notebook_vars); + hdf_notebook_var->CreateOnDisk(); + + // Save Variable type + varType = (*it).second->SaveType(); + name_len = (hdf_int32) varType.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)varType.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + + // Save Variable value + varValue = (*it).second->Save(); + name_len = (hdf_int32) varValue.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)varValue.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + hdf_notebook_var->CloseOnDisk(); + hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor + } + hdf_notebook_vars->CloseOnDisk(); + hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor + if (aLocked) aStudy->GetProperties()->SetLocked(true); //----------------------------------------------------------------------- - //5 - Write the Study Properties + //6 - Write the Study Properties //----------------------------------------------------------------------- string study_name = aStudy->Name(); name_len = (hdf_int32) study_name.size(); @@ -1214,3 +1267,60 @@ static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so, } } +void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup) +{ + if(!theGroup) + return; + + HDFgroup* new_group =0; + HDFdataset* new_dataset =0; + + char aVarName[HDF_NAME_MAX_LEN+1]; + char *currentVarType = 0; + char *currentVarValue = 0; + //Open HDF group with notebook variables + theGroup->OpenOnDisk(); + + //Get Nb of variables + int aNbVars = theGroup->nInternalObjects(); + + for( int iVar=0;iVar < aNbVars;iVar++ ) { + theGroup->InternalObjectIndentify(iVar,aVarName); + hdf_object_type type = theGroup->InternalObjectType(aVarName); + if(type == HDF_GROUP) { + + //Read Variable + new_group = new HDFgroup(aVarName,theGroup); + new_group->OpenOnDisk(); + + //Read Type + new_dataset = new HDFdataset("VARIABLE_TYPE",new_group); + new_dataset->OpenOnDisk(); + currentVarType = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarType); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + + //Read Value + new_dataset = new HDFdataset("VARIABLE_VALUE",new_group); + new_dataset->OpenOnDisk(); + currentVarValue = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarValue); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + + SALOMEDSImpl_GenericVariable::VariableTypes aVarType = + SALOMEDSImpl_GenericVariable::String2VariableType(string(currentVarType)); + delete currentVarType; + + //Create variable and add it in the study + SALOMEDSImpl_GenericVariable* aVariable = + new SALOMEDSImpl_ScalarVariable(aVarType); + aVariable->Load(string(currentVarValue)); + delete currentVarValue; + + theStudy->AddVariable(string(aVarName),aVariable); + } + } + theGroup->CloseOnDisk(); +}