#include <fstream>
#include <sstream>
+// 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: "
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 :
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);
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;
}
}
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;
}