-// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007 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 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : SALOMEDSImpl_Study.cxx
#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;
+}
+
+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 :
bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
const std::string& theBaseName,
bool isPublished,
+ bool isMultiFile,
SALOMEDSImpl_DriverFactory* theFactory)
{
_errorCode = "";
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;
+ if ( !isMultiFile )
+ sfp << "theStudy = salome.myStudy" <<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;
}
}
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;
+ }
+
+ // replace '\t' symbols
+ fp2 << replace_tabs( sfp2.str() );
- if(!isOpened) {
- _errorCode = std::string("Can't create a file ")+aFileName;
- SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
- return false;
- }
+ fp2.close();
- //Output the Python script generated by the component in the newly created file.
- fp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
- fp2 << aStream->Data();
- fp2.close();
+ //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();
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;
}
- 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;
}
//============================================================================
SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
{
- if (theSavePoint < 0) return NULL;
+ if (theSavePoint < -1) return NULL;
SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
SALOMEDSImpl_SObject so = FindComponent((char*)theID);
if (!so) so = builder->NewComponent((char*)theID);
SALOMEDSImpl_AttributeParameter* attParam = NULL;
+ if (theSavePoint == -1) {
+ int ctag = 1;
+ DF_Label savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
+ DF_Label prevPointLabel;
+ while ( !savePointLabel.IsNull() ) {
+ ctag++;
+ prevPointLabel = savePointLabel;
+ savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
+ }
+ if ( !prevPointLabel.IsNull() )
+ so = GetSObject( prevPointLabel );
+ }
if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
if ( !savePointLabel.IsNull() )
const char* theModuleName,
int theSavePoint)
{
- if(theSavePoint <= 0) return NULL;
+ if(theSavePoint < -1) return NULL;
SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
SALOMEDSImpl_AttributeParameter* par = NULL;
//============================================================================
/*! Function : modifySO_Notification
- * Purpose : This function tells all the observers that a SO has been modified
+ * Purpose : This function tells all the observers that a SO has been modified and
+ pass the mofification reason
*/
//============================================================================
-bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject)
+bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
{
if(_notifier)
- return _notifier->modifySO_Notification(theSObject);
+ return _notifier->modifySO_Notification(theSObject, reason);
else
return false;
}