From ee801165a6c6544effb9ed9ac2bf584ed36de123 Mon Sep 17 00:00:00 2001 From: ouv Date: Tue, 29 Mar 2011 07:34:47 +0000 Subject: [PATCH] Issue 0013373: EDF PAL 273 : Option Single/Multi file dump --- idl/SALOMEDS.idl | 5 +- idl/SALOME_Component.idl | 3 +- src/Container/Component_i.cxx | 3 +- src/Container/SALOME_ComponentPy.py | 6 +- src/Container/SALOME_Component_i.hxx | 1 + .../SALOME_ParallelComponent_i.cxx | 3 +- .../SALOME_ParallelComponent_i.hxx | 1 + src/SALOMEDS/SALOMEDS_Driver_i.cxx | 3 +- src/SALOMEDS/SALOMEDS_Driver_i.hxx | 1 + src/SALOMEDS/SALOMEDS_Study.cxx | 7 +- src/SALOMEDS/SALOMEDS_Study.hxx | 2 +- src/SALOMEDS/SALOMEDS_Study_i.cxx | 5 +- src/SALOMEDS/SALOMEDS_Study_i.hxx | 5 +- src/SALOMEDS/Test/SALOMEDSTest_Study.cxx | 2 +- src/SALOMEDSClient/SALOMEDSClient_Study.hxx | 3 +- src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx | 1 + src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 89 +++++++++++-------- src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 7 +- 18 files changed, 93 insertions(+), 54 deletions(-) diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 86da76230..6b0c15abd 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -352,7 +352,10 @@ during each working session. void UndoPostponed(in long theWay); - boolean DumpStudy(in string thePath, in string theBaseName, in boolean isPublished); + boolean DumpStudy(in string thePath, + in string theBaseName, + in boolean isPublished, + in boolean isMultiFile); /*! \brief Get an AttributeParameter used to store common parameters for given %theSavePoint. diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 53209d1e7..9fbfff0f5 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -323,7 +323,8 @@ module Engines the data model of component */ TMPFile DumpPython(in Object theStudy, - in boolean isPublished, + in boolean isPublished, + in boolean isMultiFile, out boolean isValidScript); diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 20c33c439..1a619a7aa 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -882,9 +882,10 @@ std::string Engines_Component_i::GetDynLibraryName(const char *componentName) Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript) { - const char* aScript = "def RebuildData(theStudy): pass"; + const char* aScript = isMultiFile ? "def RebuildData(theStudy): 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 dc6187078..30fedebf7 100755 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -293,8 +293,10 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent): #------------------------------------------------------------------------- - def DumpPython(self, theStudy, isPublished): - aBuffer = "def RebuildData(theStudy): pass\n\0" + def DumpPython(self, theStudy, isPublished, isMultiFile): + aBuffer = "\0" + if isMultiFile : + aBuffer = "def RebuildData(theStudy): pass\n\0" return (aBuffer, 1) #------------------------------------------------------------------------- diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index 04b8b64eb..9faa316fa 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -96,6 +96,7 @@ public: virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript); // CORBA operations for Salome_file diff --git a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx index f45839afa..6a9f198e3 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.cxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.cxx @@ -839,9 +839,10 @@ std::string Engines_Parallel_Component_i::GetDynLibraryName(const char *componen Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript) { - const char* aScript = "def RebuildData(theStudy): pass"; + const char* aScript = isMultiFile ? "def RebuildData(theStudy): 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 0fcb3724c..99597a5d6 100644 --- a/src/ParallelContainer/SALOME_ParallelComponent_i.hxx +++ b/src/ParallelContainer/SALOME_ParallelComponent_i.hxx @@ -95,6 +95,7 @@ public: virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript); // CORBA operations for Salome_file diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.cxx b/src/SALOMEDS/SALOMEDS_Driver_i.cxx index 7d845471c..b5d0b241f 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.cxx @@ -213,6 +213,7 @@ std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream, SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy, bool isPublished, + bool isMultiFile, bool& isValidScript, long& theStreamLength) { @@ -222,7 +223,7 @@ SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy SALOMEDS::unlock(); CORBA::Boolean aValidScript, aPublished = isPublished; - Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, aValidScript); + Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, isMultiFile, aValidScript); SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn()); theStreamLength = aTMPFile->Size(); isValidScript = aValidScript; diff --git a/src/SALOMEDS/SALOMEDS_Driver_i.hxx b/src/SALOMEDS/SALOMEDS_Driver_i.hxx index 3d69eb9d1..9f43fa4d8 100644 --- a/src/SALOMEDS/SALOMEDS_Driver_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Driver_i.hxx @@ -111,6 +111,7 @@ public: virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy, bool isPublished, + bool isMultiFile, bool& isValidScript, long& theStreamLength); }; diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 08d9eb347..edfb93def 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -629,11 +629,14 @@ void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled) else _corba_impl->EnableUseCaseAutoFilling(isEnabled); } -bool SALOMEDS_Study::DumpStudy(const std::string& thePath, const std::string& theBaseName, bool isPublished) +bool SALOMEDS_Study::DumpStudy(const std::string& thePath, + const std::string& theBaseName, + bool isPublished, + bool isMultiFile) { //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it - bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished); + bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished, isMultiFile); return ret; } diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index c84261e24..44cead142 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -90,7 +90,7 @@ public: virtual _PTR(UseCaseBuilder) GetUseCaseBuilder(); virtual void Close(); virtual void EnableUseCaseAutoFilling(bool isEnabled); - virtual bool DumpStudy(const std::string& thePath,const std::string& theBaseName,bool isPublished); + virtual bool DumpStudy(const std::string& thePath,const std::string& theBaseName,bool isPublished,bool isMultiFile); virtual _PTR(AttributeParameter) GetCommonParameters(const std::string& theID, int theSavePoint); virtual _PTR(AttributeParameter) GetModuleParameters(const std::string& theID, const std::string& theModuleName, int theSavePoint); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 4213401ae..e0f1bb365 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -873,13 +873,14 @@ void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) //============================================================================ CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, const char* theBaseName, - CORBA::Boolean isPublished) + CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile) { SALOMEDS::Locker lock; std::string aPath((char*)thePath), aBaseName((char*)theBaseName); SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb); - CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory); + CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory); delete factory; return ret; } diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index a0146ccc9..96c17a8e8 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -342,7 +342,10 @@ public: virtual char* GetDefaultScript(const char* theModuleName, const char* theShift); - virtual CORBA::Boolean DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished); + virtual CORBA::Boolean DumpStudy(const char* thePath, + const char* theBaseName, + CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile); virtual SALOMEDSImpl_Study* GetImpl() { return _impl; } diff --git a/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx b/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx index 1ab19ae46..73878f056 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx @@ -324,7 +324,7 @@ void SALOMEDSTest::testStudy() CPPUNIT_ASSERT(va2.size() == 1); // +AttributeTreeNode //Check method DumpStudy - study->DumpStudy(".", "SRN", false); + study->DumpStudy(".", "SRN", false, false); std::fstream f("SRN.py"); char buffer[128]; diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx index 2ccc8cf91..9406b63e3 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -89,7 +89,8 @@ public: virtual void EnableUseCaseAutoFilling(bool isEnabled) = 0; virtual bool DumpStudy(const std::string& thePath, const std::string& theBaseName, - bool isPublished) = 0; + bool isPublished, + bool isMultiFile) = 0; virtual _PTR(AttributeParameter) GetCommonParameters(const std::string& theID, int theSavePoint) = 0; virtual _PTR(AttributeParameter) GetModuleParameters(const std::string& theID, const std::string& theModuleName, int theSavePoint) = 0; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx index 86be83c42..8180354ab 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx @@ -88,6 +88,7 @@ public: virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy, bool isPublished, + bool isMultiFile, bool& isValidScript, long& theStreamLength) = 0; }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index bf8de48e4..67c8ce04e 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -1189,6 +1189,15 @@ static std::string replace_tabs( const std::string& in ) return out; } +static std::string GetComponentHeader(const char* theComponentName) +{ + std::stringstream txt; + txt << "###" << std::endl; + txt << "### " << theComponentName << " component" << std::endl; + txt << "###" << std::endl; + return txt.str(); +} + //============================================================================ /*! Function : DumpStudy * Purpose : @@ -1197,6 +1206,7 @@ static std::string replace_tabs( const std::string& in ) bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, const std::string& theBaseName, bool isPublished, + bool isMultiFile, SALOMEDSImpl_DriverFactory* theFactory) { _errorCode = ""; @@ -1321,55 +1331,62 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, bool isValidScript; long aStreamLength = 0; - SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength); + SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isMultiFile, isValidScript, aStreamLength); if ( !isValidScript ) isOk = false; - //Create a file that will contain the component specific script - std::fstream fp2; + std::stringstream sfp2; + + //Output the Python script generated by the component in the newly created file. + if ( isMultiFile ) + sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl; + else + sfp2 << GetComponentHeader( aCompType.c_str() ) << std::endl; + sfp2 << aStream->Data(); + + if ( isMultiFile ) { + //Create a file that will contain the component specific script + std::fstream fp2; #ifdef WIN32 - aFileName=thePath+std::string("\\"); + aFileName=thePath+std::string("\\"); #else - aFileName=thePath+std::string("/"); + aFileName=thePath+std::string("/"); #endif - std::string aScriptName; - aScriptName += theBaseName; - aScriptName += "_"; - aScriptName += aCompType; - - aFileName += aScriptName+ std::string(".py"); - aSeqOfFileNames.push_back(aFileName); - - fp2.open(aFileName.c_str(), std::ios::out); - + std::string aScriptName; + aScriptName += theBaseName; + aScriptName += "_"; + aScriptName += aCompType; + + aFileName += aScriptName+ std::string(".py"); + aSeqOfFileNames.push_back(aFileName); + + fp2.open(aFileName.c_str(), std::ios::out); + #ifdef WIN32 - isOpened = fp2.is_open(); + isOpened = fp2.is_open(); #else - isOpened = fp2.rdbuf()->is_open(); + isOpened = fp2.rdbuf()->is_open(); #endif - - if(!isOpened) { - _errorCode = std::string("Can't create a file ")+aFileName; - SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false); - return false; - } + + if(!isOpened) { + _errorCode = std::string("Can't create a file ")+aFileName; + SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false); + return false; + } - std::stringstream sfp2; - - //Output the Python script generated by the component in the newly created file. - sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl; - sfp2 << aStream->Data(); - - // replace '\t' symbols - fp2 << replace_tabs( sfp2.str() ); + // replace '\t' symbols + fp2 << replace_tabs( sfp2.str() ); - fp2.close(); + fp2.close(); - if(aStream) delete aStream; + //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; + } + else + sfp << sfp2.str(); - //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; + if(aStream) delete aStream; } sfp << std::endl; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index a257da08e..0745ef295 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -228,9 +228,10 @@ public: virtual bool HasCurrentContext() { return !_current.IsNull(); } virtual bool DumpStudy(const std::string& thePath, - const std::string& theBaseName, - bool isPublished, - SALOMEDSImpl_DriverFactory* theFactory); + const std::string& theBaseName, + bool isPublished, + bool isMultiFile, + SALOMEDSImpl_DriverFactory* theFactory); static std::string GetDumpStudyComment(const char* theComponentName = 0); -- 2.39.2