From f2d7bee74f47cd695b4c4b9b0921424837140d0c Mon Sep 17 00:00:00 2001 From: imn Date: Mon, 28 Nov 2016 17:33:53 +0300 Subject: [PATCH] Fixed problem with dump study and small optimization: - Remove parameter "theStudy" in python function "RebuildData()" - Remove NoteBook repeated initialization after DumpStudy ("import salome_notebook" first time initialization notebook) --- idl/SALOME_Component.idl | 3 +-- src/Container/Component_i.cxx | 5 ++--- src/Container/SALOME_ComponentPy.py | 4 ++-- src/Container/SALOME_Component_i.hxx | 3 +-- .../SALOME_ParallelComponent_i.cxx | 5 ++--- .../SALOME_ParallelComponent_i.hxx | 3 +-- src/SALOMEDS/SALOMEDS_Driver_i.cxx | 2 +- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 16 +++++----------- src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 2 +- 9 files changed, 16 insertions(+), 27 deletions(-) diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index c18277c90..ff1e97141 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -336,8 +336,7 @@ module Engines Returns a python script, which is being played back reproduces the data model of component */ - TMPFile DumpPython(in Object theStudy, - in boolean isPublished, + TMPFile DumpPython(in boolean isPublished, in boolean isMultiFile, out boolean isValidScript); diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 7857a5d10..6b4676f05 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -869,12 +869,11 @@ std::string Engines_Component_i::GetDynLibraryName(const char *componentName) */ //============================================================================= -Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, +Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Boolean isPublished, CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript) { - const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : ""; + const char* aScript = isMultiFile ? "def RebuildData(): pass" : ""; char* aBuffer = new char[strlen(aScript)+1]; strcpy(aBuffer, aScript); CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 89d1ab0aa..e02ed1b30 100755 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -292,10 +292,10 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent): #------------------------------------------------------------------------- - def DumpPython(self, theStudy, isPublished, isMultiFile): + def DumpPython(self, isPublished, isMultiFile): aBuffer = "\0" if isMultiFile : - aBuffer = "def RebuildData(theStudy): pass\n\0" + aBuffer = "def RebuildData(): pass\n\0" return (aBuffer, 1) #------------------------------------------------------------------------- diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index a69339168..ca1f7cf4f 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -96,8 +96,7 @@ public: bool Resume_impl(); CORBA::Long CpuUsed_impl() ; - virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, + virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished, CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript); diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx index 112132bab..597ef48cc 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx @@ -802,12 +802,11 @@ std::string Engines_Parallel_Component_i::GetDynLibraryName(const char *componen */ //============================================================================= -Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, +Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Boolean isPublished, CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript) { - const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : ""; + const char* aScript = isMultiFile ? "def RebuildData(): pass" : ""; char* aBuffer = new char[strlen(aScript)+1]; strcpy(aBuffer, aScript); CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx index d7bcbf38d..98fe0e9ea 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx @@ -92,8 +92,7 @@ public: bool Resume_impl(); CORBA::Long CpuUsed_impl() ; - virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, + virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished, CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript); diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index 488b07f74..04469f922 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -332,7 +332,7 @@ SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(bool isPublished, CORBA::Boolean aValidScript = true; // VSR: maybe should be false by default ??? if ( !CORBA::is_nil( _engine ) ) - aStream = _engine->DumpPython(st.in(), isPublished, isMultiFile, aValidScript); + aStream = _engine->DumpPython(isPublished, isMultiFile, aValidScript); SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn()); theStreamLength = aTMPFile->Size(); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index a9fae3dae..dd39cc41a 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -2049,11 +2049,9 @@ std::string SALOMEDSImpl_Study::_GetStudyVariablesScript() * Purpose : */ //============================================================================ -std::string SALOMEDSImpl_Study::_GetNoteBookAccess(const std::string& theStudyVar) +std::string SALOMEDSImpl_Study::_GetNoteBookAccess() { - std::string notebook = "import salome_notebook\n"; - notebook += _GetNoteBookAccessor() + " = salome_notebook.NoteBook(" + theStudyVar + ")" ; - return notebook; + return std::string("import salome_notebook\n"); } bool SALOMEDSImpl_Study::IsLocked() @@ -2368,15 +2366,11 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, sfp << "import sys" << std::endl; sfp << "import " << aBatchModeScript << std::endl << std::endl; - std::string aStudyVar = "salome.myStudy"; // initialization function sfp << aBatchModeScript << ".salome_init()" << std::endl; - if ( !isMultiFile ) { - sfp << "theStudy = " << aStudyVar << std::endl << std::endl; - aStudyVar = "theStudy"; - } + // notebook initialization - sfp << _GetNoteBookAccess(aStudyVar) << std::endl; + sfp << _GetNoteBookAccess() << std::endl; // extend sys.path with the directory where the script is being dumped to sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl; @@ -2484,7 +2478,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, //Add to the main script a call to RebuildData of the generated by the component the Python script sfp << "import " << aScriptName << std::endl; - sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl; + sfp << aScriptName << ".RebuildData()" << std::endl; } else sfp << sfp2.str(); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index bd8f55faf..297a3c738 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -89,7 +89,7 @@ private: std::string _GetStudyVariablesScript(); std::string _GetNoteBookAccessor(); - std::string _GetNoteBookAccess(const std::string& theStudyVar); + std::string _GetNoteBookAccess(); public: -- 2.39.2