From c6bb3fcfe0d5bd72f65e343643369f8537eefc3e Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 16 Mar 2011 12:34:52 +0000 Subject: [PATCH] 0021133: EDF 1605 ALL: Space in dump files instead of tabulations --- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 66 ++++++++++++++++++------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index a3450207e..bf8de48e4 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -45,6 +45,9 @@ #include #include +// comment out the following define to enable \t symbols in in the python dump files +#define WITHOUT_TABS + #define DIRECTORYID 16661 #define FILELOCALID 26662 #define FILEID "FILE: " @@ -1170,6 +1173,22 @@ DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry, return anAttr; } +//! number of spaces for indentation in Python dump files (to replace \t symbols) +static const int indent_size = 2; + +static std::string replace_tabs( const std::string& in ) +{ + std::string out = in; +#ifdef WITHOUT_TABS + size_t pos = out.find( '\t' ); + while ( pos != std::string::npos ) { + out.replace( pos, 1, indent_size, ' ' ); + pos = out.find( '\t' ); + } +#endif + return out; +} + //============================================================================ /*! Function : DumpStudy * Purpose : @@ -1226,29 +1245,31 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, return false; } + std::stringstream sfp; + std::string aBatchModeScript = "salome"; //Output to the main Study script required Python modules import, //set sys.path and add a creation of the study. // dump header - fp << GetDumpStudyComment() << std::endl; + sfp << GetDumpStudyComment() << std::endl; // global imports - fp << "import sys" << std::endl; - fp << "import " << aBatchModeScript << std::endl << std::endl; + sfp << "import sys" << std::endl; + sfp << "import " << aBatchModeScript << std::endl << std::endl; // initialization function - fp << aBatchModeScript << ".salome_init()" << std::endl << std::endl; + sfp << aBatchModeScript << ".salome_init()" << std::endl << std::endl; // notebook initialization - fp << _GetNoteBookAccess(); + sfp << _GetNoteBookAccess(); // extend sys.path with the directory where the script is being dumped to - fp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl; + sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl; // dump NoteBook variables - fp << _GetStudyVariablesScript(); + sfp << _GetStudyVariablesScript(); // dump visual parameters if necessary bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this); @@ -1256,7 +1277,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, if(isDumpVisuals) { lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this); if(lastSavePoint > 0) { - fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl; + sfp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl; } } @@ -1332,29 +1353,38 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false); return false; } - + + std::stringstream sfp2; + //Output the Python script generated by the component in the newly created file. - fp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl; - fp2 << aStream->Data(); + sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl; + sfp2 << aStream->Data(); + + // replace '\t' symbols + fp2 << replace_tabs( sfp2.str() ); + fp2.close(); if(aStream) delete aStream; //Add to the main script a call to RebuildData of the generated by the component the Python script - fp << "import " << aScriptName << std::endl; - fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl; + sfp << "import " << aScriptName << std::endl; + sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl; } - fp << std::endl; - fp << "if salome.sg.hasDesktop():" << std::endl; - fp << "\tsalome.sg.updateObjBrowser(1)" << std::endl; + sfp << std::endl; + sfp << "if salome.sg.hasDesktop():" << std::endl; + sfp << "\tsalome.sg.updateObjBrowser(1)" << std::endl; if(isDumpVisuals) { //Output the call to Session's method restoreVisualState - fp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl; + sfp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl; } - + // replace '\t' symbols + fp << replace_tabs( sfp.str() ); + fp.close(); + return isOk; } -- 2.39.2