/*! An unbounded sequence of strings
*/
typedef sequence<string> ListOfStrings ;
+/*! An unbounded sequence of sequence of strings
+*/
+ typedef sequence<ListOfStrings> ListOfListOfStrings ;
/*! A byte stream which is used for binary data transfer between different components
*/
typedef sequence<octet> TMPFile;
*/
ListOfStrings GetLockerID();
+/*!
+ Create real variable with Name theVarName value theValue
+ (or set if variable value in to theValue already exists)
+ \param theVarName is a name of the variable
+ \param theVarName is a value of the variable.
+*/
+ void SetReal( in string theVarName, in double theValue );
+
+/*!
+ Create integer variable with Name theVarName value theValue
+ (or set if variable value in to theValue already exists)
+ \param theVarName is a name of the variable
+ \param theVarName is a value of the variable.
+*/
+ void SetInteger( in string theVarName, in long theValue );
+/*!
+ Create boolean variable with Name theVarName value theValue
+ (or set if variable value in to theValue already exists)
+ \param theVarName is a name of the variable
+ \param theVarName is a value of the variable.
+*/
+ void SetBoolean( in string theVarName, in boolean theValue );
+
+/*!
+ Return real value of the variable
+ \param theVarName is a name of the variable.
+*/
+ double GetReal( in string theVarName );
+
+/*!
+ Return integer value of the variable
+ \param theVarName is a name of the variable.
+*/
+ long GetInteger( in string theVarName );
+
+/*!
+ Return boolean value of the variable
+ \param theVarName is a name of the variable.
+*/
+ boolean GetBoolean( in string theVarName );
+
+
+/*!
+ Return true if variable is real otherwise return false.
+ \param theVarName is a name of the variable.
+*/
+ boolean IsReal( in string theVarName );
+
+/*!
+ Return true if variable is integer otherwise return false.
+ \param theVarName is a name of the variable.
+*/
+ boolean IsInteger( in string theVarName );
+
+/*!
+ Return true if variable is boolean otherwise return false.
+ \param theVarName is a name of the variable.
+*/
+ boolean IsBoolean( in string theVarName );
+
+/*!
+ Return true if variable exists in the study,
+ otherwise return false.
+ \param theVarName is a name of the variable.
+*/
+ boolean IsVariable( in string theVarName );
+
+/*!
+ Return names of all variables from the study.
+*/
+ ListOfStrings GetVariableNames();
+
+/*! \brief Removing variable
+
+ Remove variable with the specified name from the study with substitution of its value.
+
+ \param theVarName Name of the variable.
+ \return Status of operation.
+*/
+ boolean RemoveVariable( in string theVarName );
+
+/*! \brief Renaming variable
+
+ Rename variable with the specified name within the study.
+
+ \param theVarName Name of the variable.
+ \param theNewVarName New name for the variable.
+ \return Status of operation.
+*/
+ boolean RenameVariable( in string theVarName, in string theNewVarName );
+
+/*! \brief Checking variable usage
+ Check that variable is used in the study.
+
+ \param theVarName Name of the variable.
+ \return Variable usage.
+*/
+ boolean IsVariableUsed( in string theVarName );
+
+/*! \brief Parse variables used for object creation
+
+ \param string with variables, separated by special symbol.
+ \return Variables list.
+*/
+ ListOfListOfStrings ParseVariables( in string theVars );
+
};
//==========================================================================
salome_ComponentGUI.py \
omnipatch.py \
iparameters.py \
- salome_version.py
+ salome_version.py \
+ salome_notebook.py
sharedpkgpython_PYTHON = kernel_shared_modules.py
--- /dev/null
+# 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):
+ """
+ Create (or modify) variable with name "variableName"
+ and value equal "theValue".
+ """
+ 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):
+ """
+ Return value of the variable with name "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
+
+ def isVariable(self, variableName):
+ """
+ Return true if variable with name "variableName"
+ exists in the study, otherwise return false.
+ """
+ return self.myStudy.IsVariable(variableName)
+
+notebook = NoteBook(salome.myStudy)
\ No newline at end of file
#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"
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->GetVariableValue(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->GetVariableValue(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->GetVariableValue(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<string> SALOMEDS_Study::GetVariableNames()
+{
+ vector<string> 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;
+}
+
+bool SALOMEDS_Study::RemoveVariable(const string& theVarName)
+{
+ bool aResult;
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ aResult = _local_impl->RemoveVariable(theVarName);
+ }
+ else
+ aResult = _corba_impl->RemoveVariable((char*)theVarName.c_str());
+ return aResult;
+}
+
+bool SALOMEDS_Study::RenameVariable(const string& theVarName, const string& theNewVarName)
+{
+ bool aResult;
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ aResult = _local_impl->RenameVariable(theVarName, theNewVarName);
+ }
+ else
+ aResult = _corba_impl->RenameVariable((char*)theVarName.c_str(), (char*)theNewVarName.c_str());
+ return aResult;
+}
+
+bool SALOMEDS_Study::IsVariableUsed(const string& theVarName)
+{
+ bool aResult;
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ aResult = _local_impl->IsVariableUsed(theVarName);
+ }
+ else
+ aResult = _corba_impl->IsVariableUsed((char*)theVarName.c_str());
+ return aResult;
+}
+
+vector< vector<string> > SALOMEDS_Study::ParseVariables(const string& theVars)
+{
+ vector< vector<string> > aResult;
+ if (_isLocal) {
+ SALOMEDS::Locker lock;
+ aResult = _local_impl->ParseVariables(theVars);
+ }
+ else {
+ SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
+ for (int i = 0, n = aSeq->length(); i < n; i++) {
+ vector<string> aVector;
+ SALOMEDS::ListOfStrings aSection = aSeq[i];
+ for (int j = 0, m = aSection.length(); j < m; j++) {
+ aVector.push_back( string(aSection[j].in()) );
+ }
+ aResult.push_back( aVector );
+ }
+ }
+ return aResult;
+}
+
std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject)
{
return _orb->object_to_string(theObject);
virtual void UnLockStudy(const std::string& theLockerID);
virtual std::vector<std::string> 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<std::string> GetVariableNames();
+
+ virtual bool RemoveVariable(const std::string& theVarName);
+ virtual bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName);
+ virtual bool IsVariableUsed(const std::string& theVarName);
+ virtual std::vector< std::vector<std::string> > ParseVariables(const std::string& theVars);
+
std::string ConvertObjectToIOR(CORBA::Object_ptr theObject);
CORBA::Object_ptr ConvertIORToObject(const std::string& theIOR);
}
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->GetVariableValue(string(theVarName));
+}
+
+//============================================================================
+/*! Function : GetInteger
+ * Purpose :
+ */
+//============================================================================
+CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
+{
+ return (int)_impl->GetVariableValue(string(theVarName));
+}
+
+//============================================================================
+/*! Function : GetBoolean
+ * Purpose :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
+{
+ return (bool)_impl->GetVariableValue(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<string> 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 : RemoveVariable
+ * Purpose :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
+{
+ return _impl->RemoveVariable(string(theVarName));
+}
+
+//============================================================================
+/*! Function : RenameVariable
+ * Purpose :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
+{
+ return _impl->RenameVariable(string(theVarName), string(theNewVarName));
+}
+
+//============================================================================
+/*! Function : IsVariableUsed
+ * Purpose :
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
+{
+ return _impl->IsVariableUsed(string(theVarName));
+}
+
+
+//============================================================================
+/*! Function : ParseVariables
+ * Purpose :
+ */
+//============================================================================
+SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
+{
+ vector< vector<string> > aSections = _impl->ParseVariables(string(theVarName));
+
+ SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
+
+ int aSectionsLen = aSections.size();
+ aResult->length(aSectionsLen);
+
+ for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
+ vector<string> aVarNames = aSections[aSectionInd];
+
+ SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
+
+ int aLen = aVarNames.size();
+ aList->length(aLen);
+
+ for (int anInd = 0; anInd < aLen; anInd++)
+ aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
+
+ aResult[aSectionInd] = aList;
+ }
+
+ return aResult._retn();
+}
//============================================================================
/*! Function : GetDefaultScript
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 CORBA::Boolean RemoveVariable(const char* theVarName);
+
+ virtual CORBA::Boolean RenameVariable(const char* theVarName, const char* theNewVarName);
+
+ virtual CORBA::Boolean IsVariableUsed(const char* theVarName);
+
+ virtual SALOMEDS::ListOfListOfStrings* ParseVariables(const char* theVars);
+
virtual char* GetDefaultScript(const char* theModuleName, const char* theShift);
virtual CORBA::Boolean DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished);
virtual bool IsStudyLocked() = 0;
virtual void UnLockStudy(const std::string& theLockerID) = 0;
virtual std::vector<std::string> 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<std::string> GetVariableNames() = 0;
+
+ virtual bool RemoveVariable(const std::string& theVarName) = 0;
+ virtual bool RenameVariable(const std::string& theVarName,
+ const std::string& theNewVarName) = 0;
+ virtual bool IsVariableUsed(const std::string& theVarName) = 0;
+
+ virtual std::vector< std::vector<std::string> > ParseVariables(const std::string& theVars) = 0;
+
};
SALOMEDSImpl_ChildNodeIterator.hxx \
SALOMEDSImpl_Defines.hxx \
SALOMEDSImpl_IParameters.hxx \
- SALOMEDSImpl_TMPFile.hxx
+ SALOMEDSImpl_TMPFile.hxx \
+ SALOMEDSImpl_GenericVariable.hxx \
+ SALOMEDSImpl_ScalarVariable.hxx
#
# ===============================================================
SALOMEDSImpl_StudyManager.cxx \
SALOMEDSImpl_IParameters.cxx \
SALOMEDSImpl_TMPFile.cxx \
+ SALOMEDSImpl_GenericVariable.cxx \
+ SALOMEDSImpl_ScalarVariable.cxx \
\
SALOMEDSImpl_AttributeComment.hxx \
SALOMEDSImpl_AttributeDrawable.hxx \
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
--- /dev/null
+// 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 <string>
+
+
+using namespace std;
+
+//============================================================================
+/*! Function : SALOMEDSImpl_GenericVariable
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_GenericVariable::
+SALOMEDSImpl_GenericVariable(SALOMEDSImpl_GenericVariable::VariableTypes theType,
+ const string& theName):
+ _type(theType),
+ _name(theName)
+{}
+
+//============================================================================
+/*! Function : ~SALOMEDSImpl_GenericVariable
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_GenericVariable::~SALOMEDSImpl_GenericVariable()
+{}
+
+//============================================================================
+/*! Function : Type
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_GenericVariable::VariableTypes SALOMEDSImpl_GenericVariable::Type() const
+{
+ return _type;
+}
+
+//============================================================================
+/*! Function : Name
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_GenericVariable::Name() const
+{
+ return _name;
+}
+
+//============================================================================
+/*! Function : setType
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_GenericVariable::setType(const SALOMEDSImpl_GenericVariable::VariableTypes theType)
+{
+ if(_type == theType)
+ return false;
+
+ _type = theType;
+ return true;
+}
+
+//============================================================================
+/*! Function : setName
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_GenericVariable::setName(const std::string& theName)
+{
+ if(_name.compare(theName) == 0)
+ return false;
+
+ _name = theName;
+ return true;
+}
+
+//============================================================================
+/*! 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 : SaveToScript
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_GenericVariable::SaveToScript() const
+{
+ return string();
+}
+//============================================================================
+/*! Function : SaveType
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_GenericVariable::SaveType() const
+{
+ return string();
+}
+
+//============================================================================
+/*! Function : Load
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_GenericVariable::Load(const string& theStrValue)
+{
+}
--- /dev/null
+// 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 <string>
+
+//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, const std::string& theName);
+ ~SALOMEDSImpl_GenericVariable();
+
+ VariableTypes Type() const;
+
+ std::string Name() const;
+
+ static VariableTypes String2VariableType(const std::string& theStrType);
+
+ bool setType(const VariableTypes theType);
+
+ bool setName(const std::string& theName);
+
+ virtual std::string Save() const;
+ virtual std::string SaveToScript() const;
+ virtual std::string SaveType() const;
+
+ virtual void Load(const std::string& theStrValue);
+
+ private:
+ VariableTypes _type;
+ std::string _name;
+};
+
+#endif //_GENERICIMPL_VARIABLE_HXX_
--- /dev/null
+// 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 <iostream>
+using namespace std;
+
+//============================================================================
+/*! Function : SALOMEDSImpl_ScalarVariable
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_ScalarVariable::
+SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type,
+ const string& theName):
+ SALOMEDSImpl_GenericVariable(type,theName)
+{}
+
+//============================================================================
+/*! Function : ~SALOMEDSImpl_ScalarVariable()
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){}
+
+//============================================================================
+/*! Function :
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_ScalarVariable::setValue(const double theValue)
+{
+
+ if(myValue == theValue)
+ return false;
+
+ myValue = theValue;
+ return true;
+}
+
+//============================================================================
+/*! 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);
+ break;
+ }
+ default:break;
+ }
+ return string(buffer);
+}
+
+//============================================================================
+/*! Function : SaveToScript()
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_ScalarVariable::SaveToScript() const
+{
+ char buffer[255];
+ switch(Type())
+ {
+ case SALOMEDSImpl_GenericVariable::REAL_VAR:
+ {
+ sprintf(buffer, "%g", myValue);
+ break;
+ }
+ case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
+ {
+ sprintf(buffer, "%d", (int)myValue);
+ break;
+ }
+ case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
+ {
+ if((bool)myValue)
+ sprintf(buffer, "%s", "True");
+ else
+ sprintf(buffer, "%s", "False");
+ break;
+ }
+ 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);
+}
--- /dev/null
+// 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,
+ const std::string& theName);
+ ~SALOMEDSImpl_ScalarVariable();
+
+ bool setValue(const double theValue);
+ double getValue() const;
+
+ virtual std::string Save() const;
+ virtual std::string SaveToScript() const;
+ virtual std::string SaveType() const;
+
+ virtual void Load(const std::string& theStrValue);
+
+private:
+ double myValue;
+};
+
+
+#endif //_SALOMEDSImpl_ScalarVariable_HeaderFile
#include "SALOMEDSImpl_StudyHandle.hxx"
#include "SALOMEDSImpl_Tool.hxx"
#include "SALOMEDSImpl_IParameters.hxx"
+#include "SALOMEDSImpl_ScalarVariable.hxx"
#include <fstream>
#define DIRECTORYID 16661
#define FILELOCALID 26662
#define FILEID "FILE: "
+#define VARIABLE_SEPARATOR ':'
+#define OPERATION_SEPARATOR '|'
//============================================================================
return RefSO;
}
+//============================================================================
+/*! Function : _GetNoteBookAccessor
+ * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
+ */
+//============================================================================
+string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
+ return string("notebook");
+}
+
+//============================================================================
+/*! Function : _GetStudyVariablesScript
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_Study::_GetStudyVariablesScript()
+{
+ string dump("");
+
+ if(myNoteBookVars.empty())
+ return dump;
+
+ dump += "####################################################\n";
+ dump += "## Begin of NoteBook variables section ##\n";
+ dump += "####################################################\n";
+
+ string set_method = _GetNoteBookAccessor()+".set(";
+ string varName;
+ string varValue;
+ for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
+ varName = myNoteBookVars[i]->Name();
+ varValue = myNoteBookVars[i]->SaveToScript();
+ dump+=set_method+"\""+varName+"\", "+varValue+")\n";
+ }
+
+ dump += "####################################################\n";
+ dump += "## End of NoteBook variables section ##\n";
+ dump += "####################################################\n";
+
+ return dump;
+}
+
+//============================================================================
+/*! Function : _GetNoteBookAccess
+ * Purpose :
+ */
+//============================================================================
+string SALOMEDSImpl_Study::_GetNoteBookAccess()
+{
+ string accessor = _GetNoteBookAccessor();
+ string notebook = "import salome_notebook\n";
+ notebook += accessor+" = salome_notebook."+accessor + "\n";
+ return notebook;
+}
+
bool SALOMEDSImpl_Study::IsLocked()
{
_errorCode = "";
fp << aBatchModeScript << ".salome_init()" << endl << endl;
+ fp << _GetNoteBookAccess();
+
fp << "sys.path.insert( 0, \'" << thePath << "\')" << endl << endl;
+ //Dump NoteBook Variables
+ fp << _GetStudyVariablesScript();
//Check if it's necessary to dump visual parameters
bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
return _lockers;
}
+//============================================================================
+/*! Function : SetVariable
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::SetVariable(const string& theVarName,
+ const double theValue,
+ const SALOMEDSImpl_GenericVariable::VariableTypes theType)
+{
+ bool modified = false;
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if( aGVar == NULL ) {
+
+ SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
+
+ aSVar->setValue(theValue);
+ myNoteBookVars.push_back(aSVar);
+ modified = true;
+ }
+ else {
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
+ modified = aSVar->setValue(theValue) || modified;
+ modified = aSVar->setType(theType) || modified;
+ }
+ }
+ if(modified)
+ Modify();
+}
+
+//============================================================================
+/*! Function : GetReal
+ * Purpose :
+ */
+//============================================================================
+double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName)
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if(aGVar != NULL )
+ if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
+ return aSVar->getValue();
+
+ return 0;
+}
+
+//============================================================================
+/*! Function : IsTypeOf
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsTypeOf(const string& theVarName,
+ SALOMEDSImpl_GenericVariable::
+ VariableTypes theType) const
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+
+ if(aGVar != NULL )
+ return aGVar->Type() == theType;
+
+ return false;
+}
+
+//============================================================================
+/*! Function : IsVariable
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const
+{
+ SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
+ return (aGVar != NULL);
+}
+
+//============================================================================
+/*! Function : GetVariableNames
+ * Purpose :
+ */
+//============================================================================
+vector<string> SALOMEDSImpl_Study::GetVariableNames() const
+{
+ vector<string> aResult;
+
+ for(int i = 0; i < myNoteBookVars.size(); i++)
+ aResult.push_back(myNoteBookVars[i]->Name());
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : AddVariable
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
+{
+ myNoteBookVars.push_back(theVariable);
+}
+
+//============================================================================
+/*! Function : AddVariable
+ * Purpose :
+ */
+//============================================================================
+SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
+{
+ SALOMEDSImpl_GenericVariable* aResult = NULL;
+ for(int i = 0; i < myNoteBookVars.size();i++) {
+ if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
+ aResult = myNoteBookVars[i];
+ break;
+ }
+ }
+ return aResult;
+}
+
+//============================================================================
+/*! Function : RemoveVariable
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::RemoveVariable(const string& theVarName)
+{
+ SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
+ if( !aVariable )
+ return false;
+
+ string aValue = aVariable->SaveToScript();
+ ReplaceVariableAttribute( theVarName, aValue );
+
+ std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
+ for( ; it != itEnd; it++ )
+ {
+ SALOMEDSImpl_GenericVariable* aVariableRef = *it;
+ if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
+ {
+ myNoteBookVars.erase( it );
+ Modify();
+ break;
+ }
+ }
+
+ return true;
+}
+
+//============================================================================
+/*! Function : RenameVariable
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::RenameVariable(const string& theVarName, const string& theNewVarName)
+{
+ SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
+ if( !aVariable )
+ return false;
+
+ ReplaceVariableAttribute( theVarName, theNewVarName );
+
+ std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
+ for( ; it != itEnd; it++ )
+ {
+ SALOMEDSImpl_GenericVariable* aVariableRef = *it;
+ if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
+ {
+ aVariableRef->setName( theNewVarName );
+ Modify();
+ break;
+ }
+ }
+
+ return true;
+}
+
+//============================================================================
+/*! Function : IsVariableUsed
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::IsVariableUsed(const string& theVarName)
+{
+ return FindVariableAttribute( theVarName );
+}
+
+//============================================================================
+/*! Function : FindVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theName)
+{
+ SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
+ for( ; anIter.More(); anIter.Next() )
+ if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
+ return true;
+
+ DF_Attribute* anAttr;
+ if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
+ {
+ if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
+ {
+ string aString = aStringAttr->Value();
+
+ vector< vector<string> > aSections = ParseVariables( aString );
+ for( int i = 0, n = aSections.size(); i < n; i++ )
+ {
+ vector<string> aVector = aSections[i];
+ for( int j = 0, m = aVector.size(); j < m; j++ )
+ {
+ string aStr = aVector[j];
+ if( aStr.compare( theName ) == 0 )
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+//============================================================================
+/*! Function : FindVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
+{
+ SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
+ SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
+ for( ; aCompIter.More(); aCompIter.Next() )
+ {
+ SALOMEDSImpl_SObject aComp = aCompIter.Value();
+ if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
+ return true;
+ }
+ return false;
+}
+
+//============================================================================
+/*! Function : ReplaceVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theSource,
+ const std::string& theDest)
+{
+ SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
+ for( ; anIter.More(); anIter.Next() )
+ ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
+
+ DF_Attribute* anAttr;
+ if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
+ {
+ if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
+ {
+ bool isChanged = false;
+ string aNewString, aCurrentString = aStringAttr->Value();
+
+ vector< vector<string> > aSections = ParseVariables( aCurrentString );
+ for( int i = 0, n = aSections.size(); i < n; i++ )
+ {
+ vector<string> aVector = aSections[i];
+ for( int j = 0, m = aVector.size(); j < m; j++ )
+ {
+ string aStr = aVector[j];
+ if( aStr.compare( theSource ) == 0 )
+ {
+ isChanged = true;
+ aStr = theDest;
+ }
+
+ aNewString.append( aStr );
+ if( j != m - 1 )
+ aNewString.append( ":" );
+ }
+ if( i != n - 1 )
+ aNewString.append( "|" );
+ }
+
+ if( isChanged )
+ aStringAttr->SetValue( aNewString );
+ }
+ }
+}
+
+//============================================================================
+/*! Function : ReplaceVariableAttribute
+ * Purpose :
+ */
+//============================================================================
+void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
+{
+ SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
+ SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
+ for( ; aCompIter.More(); aCompIter.Next() )
+ {
+ SALOMEDSImpl_SObject aComp = aCompIter.Value();
+ ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
+ }
+}
+
+//============================================================================
+/*! Function : ParseVariables
+ * Purpose :
+ */
+//============================================================================
+vector< vector< string > > SALOMEDSImpl_Study::ParseVariables(const string& theVariables) const
+{
+ return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
+}
+
//============================================================================
/*! Function : EnableUseCaseAutoFilling
* Purpose :
#include "SALOMEDSImpl_Callback.hxx"
#include "SALOMEDSImpl_Driver.hxx"
#include "SALOMEDSImpl_ChildIterator.hxx"
+#include "SALOMEDSImpl_GenericVariable.hxx"
class SALOMEDSImpl_StudyManager;
class SALOMEDSImpl_GenericAttribute;
std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
std::map<std::string, DF_Label> myIORLabels;
-
+ std::vector<SALOMEDSImpl_GenericVariable*> myNoteBookVars;
SALOMEDSImpl_SObject _FindObject(const SALOMEDSImpl_SObject& SO,
const std::string& anObjectName,
const std::string& anObjectIOR,
bool& _find);
+ std::string _GetStudyVariablesScript();
+ std::string _GetNoteBookAccessor();
+ std::string _GetNoteBookAccess();
+
public:
static SALOMEDSImpl_Study* GetStudy(const DF_Label& theLabel);
//Returns an ID of the study locker
std::vector<std::string> GetLockerID();
+ //Managing of variables
+ void SetVariable(const std::string& theVarName,
+ const double theValue,
+ const SALOMEDSImpl_GenericVariable::VariableTypes);
+
+ double GetVariableValue(const std::string& theVarName);
+
+ bool IsTypeOf(const std::string& theVarName,
+ SALOMEDSImpl_GenericVariable::VariableTypes theType) const;
+
+ bool IsVariable(const std::string& theVarName) const;
+
+
+ std::vector<std::string> GetVariableNames() const;
+
+ void AddVariable(SALOMEDSImpl_GenericVariable* theVariable);
+
+ SALOMEDSImpl_GenericVariable* GetVariable(const std::string& theName) const;
+
+ bool RemoveVariable(const std::string& theVarName);
+
+ bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName);
+
+ bool IsVariableUsed(const std::string& theVarName);
+
+ bool FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theName);
+ bool FindVariableAttribute(const std::string& theName);
+
+ void ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
+ SALOMEDSImpl_SObject theSObject,
+ const std::string& theSource,
+ const std::string& theDest);
+ void ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest);
+
+ std::vector< std::vector<std::string> > ParseVariables(const std::string& theVariables) const;
+
//Returns a callback
SALOMEDSImpl_Callback* GetCallback() { return _cb; }
friend class SALOMEDSImpl_StudyManager;
friend class SALOMEDSImpl_GenericAttribute;
+ friend class SALOMEDSImpl_GenericVariable;
};
#endif
#include "SALOMEDSImpl_Tool.hxx"
#include "SALOMEDSImpl_SComponent.hxx"
#include "SALOMEDSImpl_GenericAttribute.hxx"
+#include "SALOMEDSImpl_ScalarVariable.hxx"
#include <map>
#include "HDFOI.hxx"
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
// open the HDFFile
HDFfile *hdf_file =0;
HDFgroup *hdf_group_study_structure =0;
+ HDFgroup *hdf_notebook_vars = 0;
char* aC_HDFUrl;
string aHDFUrl;
return NULL;
}
- hdf_file->CloseOnDisk();
+ //Read and create notebook variables
+ if(hdf_file->ExistInternalObject("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<string> aFilesToRemove;
aFilesToRemove.push_back("hdf_from_ascii.hdf");
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;
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();
+
+ string varValue;
+ string varType;
+ string varIndex;
+
+ for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
+ // For each variable create HDF group
+ hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
+ hdf_notebook_var->CreateOnDisk();
+
+ // Save Variable type
+ varType = aStudy->myNoteBookVars[i]->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
+
+ char buffer[256];
+ sprintf(buffer,"%d",i);
+ varIndex= string(buffer);
+ name_len = (hdf_int32) varIndex.length();
+ size[0] = name_len +1 ;
+ hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
+ hdf_dataset->CreateOnDisk();
+ hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
+ hdf_dataset->CloseOnDisk();
+ hdf_dataset=0; //will be deleted by hdf_sco_group destructor
+
+
+ // Save Variable value
+ varValue = aStudy->myNoteBookVars[i]->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();
}
}
+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;
+ char *currentVarIndex = 0;
+ int order = 0;
+ //Open HDF group with notebook variables
+ theGroup->OpenOnDisk();
+
+ //Get Nb of variables
+ int aNbVars = theGroup->nInternalObjects();
+
+ map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
+
+ 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 Order
+ if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
+ new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
+ new_dataset->OpenOnDisk();
+ currentVarIndex = new char[new_dataset->GetSize()+1];
+ new_dataset->ReadFromDisk(currentVarIndex);
+ new_dataset->CloseOnDisk();
+ new_dataset = 0; //will be deleted by hdf_sco_group destructor
+ order = atoi(currentVarIndex);
+ delete currentVarIndex;
+ }
+ else
+ order = iVar;
+
+ //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
+
+ new_group->CloseOnDisk();
+ new_group = 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,string(aVarName));
+ aVariable->Load(string(currentVarValue));
+ aVarsMap.insert(make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
+ delete currentVarValue;
+ }
+ }
+
+ map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
+ for(;it!=aVarsMap.end();it++)
+ theStudy->AddVariable((*it).second);
+
+ theGroup->CloseOnDisk();
+}
return vs;
}
+//============================================================================
+// function :
+// purpose : The functions returns a list of substring of initial string
+// divided by given separator include empty strings
+//============================================================================
+vector<string> SALOMEDSImpl_Tool::splitStringWithEmpty(const string& theValue, char sep)
+{
+ vector<string> aResult;
+ if(theValue[0] == sep ) aResult.push_back(string());
+ int pos = theValue.find(sep);
+ if(pos < 0 ) {
+ aResult.push_back(theValue);
+ return aResult;
+ }
+
+ string s = theValue;
+ if(s[0] == sep) s = s.substr(1, s.size());
+ while((pos = s.find(sep)) >= 0) {
+ aResult.push_back(s.substr(0, pos));
+ s = s.substr(pos+1, s.size());
+ }
+
+ if(!s.empty() && s[0] != sep) aResult.push_back(s);
+ if(theValue[theValue.size()-1] == sep) aResult.push_back(string());
+
+ return aResult;
+}
+
+//============================================================================
+// function :
+// purpose : The functions returns a list of lists of substrings of initial string
+// divided by two given separators include empty strings
+//============================================================================
+vector< vector<string> > SALOMEDSImpl_Tool::splitStringWithEmpty(const string& theValue, char sep1, char sep2)
+{
+ vector< vector<string> > aResult;
+ if(theValue.size() > 0) {
+ vector<string> aSections = splitStringWithEmpty( theValue, sep1 );
+ for( int i = 0, n = aSections.size(); i < n; i++ )
+ aResult.push_back( splitStringWithEmpty( aSections[i], sep2 ) );
+ }
+ return aResult;
+}
+
void SALOMEDSImpl_Tool::GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds)
{
//The functions returns a list of substring of initial string divided by given separator
static std::vector<std::string> splitString(const std::string& theValue, char separator);
+ //The functions returns a list of substring of initial string divided by given separator,
+ //include empty strings
+ static std::vector<std::string> splitStringWithEmpty(const std::string& theValue, char separator);
+
+ //The functions returns a list of substring of initial string divided by given separator,
+ //include empty strings
+ static std::vector< std::vector<std::string> > splitStringWithEmpty(const std::string& theValue,
+ char separator1,
+ char separator2);
+
+
//Returns a system date
static void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds);