From 865633bc4662a2ddf099111e13dc9607d2a6d75a Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 12 Feb 2010 08:27:27 +0000 Subject: [PATCH] Issue 20509: EDF 1065 OTHER : Add the Salome version in the header of the dump --- src/SALOMEDSImpl/Makefile.am | 7 +- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 427 ++++++++++++------------ 2 files changed, 223 insertions(+), 211 deletions(-) diff --git a/src/SALOMEDSImpl/Makefile.am b/src/SALOMEDSImpl/Makefile.am index f0cc66340..c7c3a2f60 100644 --- a/src/SALOMEDSImpl/Makefile.am +++ b/src/SALOMEDSImpl/Makefile.am @@ -95,8 +95,9 @@ COMMON_CPPFLAGS=\ -I$(srcdir)/../SALOMELocalTrace \ -I$(srcdir)/../HDFPersist \ -I$(srcdir)/../DF \ - -I$(srcdir)/../GenericObj \ - -I$(top_builddir)/idl \ + -I$(srcdir)/../GenericObj \ + -I$(top_builddir)/idl \ + -I$(top_builddir) \ @HDF5_INCLUDES@ \ @BOOST_CPPFLAGS@ @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ @@ -105,7 +106,7 @@ COMMON_LIBS =\ ../Basics/libSALOMEBasics.la \ ../HDFPersist/libSalomeHDFPersist.la \ ../DF/libDF.la \ - ../GenericObj/libSalomeGenericObj.la \ + ../GenericObj/libSalomeGenericObj.la \ @HDF5_LIBS@ diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index d3f93e848..2c6fcb3c3 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -26,8 +26,7 @@ #include "SALOMEDSImpl_Study.hxx" #include -using namespace std; - +#include #include #include "DF_Application.hxx" @@ -43,6 +42,7 @@ using namespace std; #include "SALOMEDSImpl_ScalarVariable.hxx" #include +#include #define DIRECTORYID 16661 #define FILELOCALID 26662 @@ -56,7 +56,7 @@ using namespace std; */ //============================================================================ SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc, - const string& study_name) + const std::string& study_name) { _name = study_name; _doc = (DF_Document*)doc; @@ -91,7 +91,7 @@ SALOMEDSImpl_Study::~SALOMEDSImpl_Study() * Purpose : Get persistent reference of study (idem URL()) */ //============================================================================ -string SALOMEDSImpl_Study::GetPersistentReference() +std::string SALOMEDSImpl_Study::GetPersistentReference() { _errorCode = ""; return URL(); @@ -101,10 +101,10 @@ string SALOMEDSImpl_Study::GetPersistentReference() * Purpose : Get IOR of the Study (registred in Document in doc->Root) */ //============================================================================ -string SALOMEDSImpl_Study::GetTransientReference() +std::string SALOMEDSImpl_Study::GetTransientReference() { _errorCode = ""; - string IOR = ""; + std::string IOR = ""; SALOMEDSImpl_AttributeIOR* Att; DF_Label _lab = _doc->Root(); @@ -118,7 +118,7 @@ string SALOMEDSImpl_Study::GetTransientReference() return IOR; } -void SALOMEDSImpl_Study::SetTransientReference(const string& theIOR) +void SALOMEDSImpl_Study::SetTransientReference(const std::string& theIOR) { _errorCode = ""; @@ -149,11 +149,11 @@ bool SALOMEDSImpl_Study::IsEmpty() * Purpose : Find a Component with ComponentDataType = aComponentName */ //============================================================================ -SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const string& aComponentName) +SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const std::string& aComponentName) { _errorCode = ""; bool _find = false; - string name; + std::string name; SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator(); SALOMEDSImpl_SComponent compo; @@ -179,14 +179,14 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const string& aCompon * Purpose : Find a Component from it's ID */ //============================================================================ -SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const string& aComponentID) +SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const std::string& aComponentID) { _errorCode = ""; // Iterate on each components defined in the study // Get the component ID and compare with aComponentID bool _find = false; - string ID; + std::string ID; SALOMEDSImpl_SComponent compo; SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator(); @@ -214,7 +214,7 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const string& aCompo * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName */ //============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const string& anObjectName) +SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const std::string& anObjectName) { _errorCode = ""; @@ -247,11 +247,11 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const string& anObjectName) * Purpose : Find an Object with ID = anObjectID */ //============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const string& anObjectID) +SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const std::string& anObjectID) { _errorCode = ""; SALOMEDSImpl_SObject so; - + // Convert aSO->GetID in DF_Label. DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false); @@ -268,7 +268,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const string& anObjectID) * Purpose : Creates an Object with ID = anObjectID */ //============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const string& anObjectID) +SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const std::string& anObjectID) { _errorCode = ""; SALOMEDSImpl_SObject so; @@ -290,12 +290,12 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const string& anObjectID * : with ComponentDataType = aComponentName */ //============================================================================ -vector SALOMEDSImpl_Study::FindObjectByName(const string& anObjectName, - const string& aComponentName) +std::vector SALOMEDSImpl_Study::FindObjectByName(const std::string& anObjectName, + const std::string& aComponentName) { _errorCode = ""; - vector listSO; + std::vector listSO; SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ; if ( !compo ) { @@ -305,9 +305,9 @@ vector SALOMEDSImpl_Study::FindObjectByName(const string& // Iterate on each object and subobject of the component // If objectName is found add it to the list of SObjects - string childName ; + std::string childName ; - string compoId = compo.GetID(); + std::string compoId = compo.GetID(); SALOMEDSImpl_ChildIterator it = NewChildIterator(compo); for ( ; it.More(); it.Next() ) { @@ -335,22 +335,22 @@ vector SALOMEDSImpl_Study::FindObjectByName(const string& * Purpose : Find an Object with IOR = anObjectIOR */ //============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const string& anObjectIOR) +SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const std::string& anObjectIOR) { _errorCode = ""; - + SALOMEDSImpl_SObject aResult ; - + // searching in the datamap for optimization if (myIORLabels.find(anObjectIOR) != myIORLabels.end()) { aResult = GetSObject(myIORLabels[anObjectIOR]); // 11 oct 2002: forbidden attributes must be checked here if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) { myIORLabels.erase(anObjectIOR); - aResult = SALOMEDSImpl_SObject(); - } + aResult = SALOMEDSImpl_SObject(); + } } - + if(!aResult) _errorCode = "No object was found"; return aResult; } @@ -360,11 +360,11 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const string& anObjectIOR * Purpose : Find an Object by its path = thePath */ //============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const string& thePath) +SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const std::string& thePath) { _errorCode = ""; - string aPath(thePath), aToken; + std::string aPath(thePath), aToken; SALOMEDSImpl_SObject aSO; int aLength = aPath.size(); bool isRelative = false; @@ -391,7 +391,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const string& thePath) anIterator.Init(_doc->Main(), false); } - vector vs = SALOMEDSImpl_Tool::splitString(aPath, '/'); + std::vector vs = SALOMEDSImpl_Tool::splitString(aPath, '/'); for(int i = 0, len = vs.size(); i SALOMEDSImpl_Study::GetObjectNames(const string& theContext) +std::vector SALOMEDSImpl_Study::GetObjectNames(const std::string& theContext) { _errorCode = ""; - vector aResultSeq; + std::vector aResultSeq; DF_Label aLabel; if (theContext.empty()) { aLabel = _current; @@ -565,7 +565,7 @@ vector SALOMEDSImpl_Study::GetObjectNames(const string& theContext) for (; anIter.More(); anIter.Next()) { DF_Label aLabel = anIter.Value(); SALOMEDSImpl_AttributeName* aName; - if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) + if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) aResultSeq.push_back(aName->Value()); } @@ -577,11 +577,11 @@ vector SALOMEDSImpl_Study::GetObjectNames(const string& theContext) * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty) */ //============================================================================ -vector SALOMEDSImpl_Study::GetDirectoryNames(const string& theContext) +std::vector SALOMEDSImpl_Study::GetDirectoryNames(const std::string& theContext) { _errorCode = ""; - vector aResultSeq; + std::vector aResultSeq; DF_Label aLabel; if (theContext.empty()) { aLabel = _current; @@ -618,11 +618,11 @@ vector SALOMEDSImpl_Study::GetDirectoryNames(const string& theContext) * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty) */ //============================================================================ -vector SALOMEDSImpl_Study::GetFileNames(const string& theContext) +std::vector SALOMEDSImpl_Study::GetFileNames(const std::string& theContext) { _errorCode = ""; - vector aResultSeq; + std::vector aResultSeq; DF_Label aLabel; if (theContext.empty()) { aLabel = _current; @@ -661,16 +661,16 @@ vector SALOMEDSImpl_Study::GetFileNames(const string& theContext) * Purpose : method to get all components names */ //============================================================================ -vector SALOMEDSImpl_Study::GetComponentNames(const string& theContext) +std::vector SALOMEDSImpl_Study::GetComponentNames(const std::string& theContext) { _errorCode = ""; - vector aResultSeq; + std::vector aResultSeq; DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level for(; anIter.More(); anIter.Next()) { DF_Label aLabel = anIter.Value(); SALOMEDSImpl_AttributeName* aName; - if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) + if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) aResultSeq.push_back(aName->Value()); } @@ -722,7 +722,7 @@ SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder() * Purpose : get study name */ //============================================================================ -string SALOMEDSImpl_Study::Name() +std::string SALOMEDSImpl_Study::Name() { _errorCode = ""; return _name; @@ -733,7 +733,7 @@ string SALOMEDSImpl_Study::Name() * Purpose : set study name */ //============================================================================ -void SALOMEDSImpl_Study::Name(const string& name) +void SALOMEDSImpl_Study::Name(const std::string& name) { _errorCode = ""; _name = name; @@ -782,7 +782,7 @@ bool SALOMEDSImpl_Study::IsModified() * Purpose : get URL of the study (persistent reference of the study) */ //============================================================================ -string SALOMEDSImpl_Study::URL() +std::string SALOMEDSImpl_Study::URL() { _errorCode = ""; return _URL; @@ -793,13 +793,13 @@ string SALOMEDSImpl_Study::URL() * Purpose : set URL of the study (persistent reference of the study) */ //============================================================================ -void SALOMEDSImpl_Study::URL(const string& url) +void SALOMEDSImpl_Study::URL(const std::string& url) { _errorCode = ""; _URL = url; /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study - string tmp(_URL); + std::string tmp(_URL); char *aName = (char*)tmp.ToCString(); char *adr = strtok(aName, "/"); @@ -819,8 +819,8 @@ void SALOMEDSImpl_Study::URL(const string& url) */ //============================================================================ SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO, - const string& theObjectName, - bool& _find) + const std::string& theObjectName, + bool& _find) { SALOMEDSImpl_SObject RefSO; if(!SO) return RefSO; @@ -829,14 +829,14 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& // If objectName find, stop the loop and get the object reference SALOMEDSImpl_AttributeName* anAttr; - string soid = SO.GetID(); + std::string soid = SO.GetID(); DF_ChildIterator it(SO.GetLabel()); for (; it.More(); it.Next()){ if(!_find) { if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) { - string Val(anAttr->Value()); + std::string Val(anAttr->Value()); if (Val == theObjectName) { RefSO = GetSObject(it.Value()); @@ -856,7 +856,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& //============================================================================ SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO, - const string& theObjectIOR, + const std::string& theObjectIOR, bool& _find) { SALOMEDSImpl_SObject RefSO, aSO; @@ -872,7 +872,7 @@ SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO, { if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) { - string Val(anAttr->Value()); + std::string Val(anAttr->Value()); if (Val == theObjectIOR) { RefSO = GetSObject(it.Value()); @@ -891,37 +891,37 @@ SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO, * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR */ //============================================================================ -string SALOMEDSImpl_Study::_GetNoteBookAccessor(){ - return string("notebook"); +std::string SALOMEDSImpl_Study::_GetNoteBookAccessor(){ + return std::string("notebook"); } //============================================================================ /*! Function : _GetStudyVariablesScript - * Purpose : + * Purpose : */ //============================================================================ -string SALOMEDSImpl_Study::_GetStudyVariablesScript() +std::string SALOMEDSImpl_Study::_GetStudyVariablesScript() { - string dump(""); - + std::string dump(""); + if(myNoteBookVars.empty()) return dump; Kernel_Utils::Localizer loc; - + dump += "####################################################\n"; dump += "## Begin of NoteBook variables section ##\n"; dump += "####################################################\n"; - string set_method = _GetNoteBookAccessor()+".set("; - string varName; - string varValue; + std::string set_method = _GetNoteBookAccessor()+".set("; + std::string varName; + std::string varValue; for(int i = 0 ; i < myNoteBookVars.size();i++ ) { varName = myNoteBookVars[i]->Name(); varValue = myNoteBookVars[i]->SaveToScript(); dump+=set_method+"\""+varName+"\", "+varValue+")\n"; } - + dump += "####################################################\n"; dump += "## End of NoteBook variables section ##\n"; dump += "####################################################\n"; @@ -934,12 +934,12 @@ string SALOMEDSImpl_Study::_GetStudyVariablesScript() * Purpose : */ //============================================================================ -string SALOMEDSImpl_Study::_GetNoteBookAccess() +std::string SALOMEDSImpl_Study::_GetNoteBookAccess() { - string accessor = _GetNoteBookAccessor(); - string notebook = "import salome_notebook\n"; - notebook += accessor+" = salome_notebook."+accessor + "\n"; - return notebook; + std::string accessor = _GetNoteBookAccessor(); + std::string notebook = "import salome_notebook\n"; + notebook += accessor+" = salome_notebook."+accessor + "\n"; + return notebook; } bool SALOMEDSImpl_Study::IsLocked() @@ -960,7 +960,7 @@ void SALOMEDSImpl_Study::StudyId(int id) _StudyId = id; } -void SALOMEDSImpl_Study::UpdateIORLabelMap(const string& anIOR,const string& anEntry) +void SALOMEDSImpl_Study::UpdateIORLabelMap(const std::string& anIOR,const std::string& anEntry) { _errorCode = ""; DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true); @@ -970,7 +970,7 @@ void SALOMEDSImpl_Study::UpdateIORLabelMap(const string& anIOR,const string& anE void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR) { - if (myIORLabels.find(anIOR) != myIORLabels.end()) + if (myIORLabels.find(anIOR) != myIORLabels.end()) { //remove the ior entry and decref the genericobj (if it's one) myIORLabels.erase(anIOR); @@ -999,14 +999,14 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel) void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute) { - string aString = theAttribute->Label().Entry(); + std::string aString = theAttribute->Label().Entry(); GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString); } -vector SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject) +std::vector SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject) { _errorCode = ""; - vector aSeq; + std::vector aSeq; SALOMEDSImpl_AttributeTarget* aTarget; if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) { @@ -1023,13 +1023,13 @@ SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties() return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main()); } -string SALOMEDSImpl_Study::GetLastModificationDate() +std::string SALOMEDSImpl_Study::GetLastModificationDate() { _errorCode = ""; SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties(); - vector aNames; - vector aMinutes, aHours, aDays, aMonths, aYears; + std::vector aNames; + std::vector aMinutes, aHours, aDays, aMonths, aYears; aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears); int aLastIndex = aNames.size()-1; @@ -1037,21 +1037,21 @@ string SALOMEDSImpl_Study::GetLastModificationDate() sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]), (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex])); - string aResStr (aResult); + std::string aResStr (aResult); return aResStr; } -vector SALOMEDSImpl_Study::GetModificationsDate() +std::vector SALOMEDSImpl_Study::GetModificationsDate() { _errorCode = ""; SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties(); - vector aNames; - vector aMinutes, aHours, aDays, aMonths, aYears; + std::vector aNames; + std::vector aMinutes, aHours, aDays, aMonths, aYears; aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears); int anIndex, aLength = aNames.size(); - vector aDates; + std::vector aDates; for (anIndex = 1; anIndex < aLength; anIndex++) { char aDate[20]; @@ -1097,7 +1097,7 @@ void SALOMEDSImpl_Study::Close() * Purpose : */ //============================================================================ -SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const string& theEntry) +SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const std::string& theEntry) { SALOMEDSImpl_SComponent aSCO; if(_mapOfSCO.find(theEntry) != _mapOfSCO.end()) @@ -1126,7 +1126,7 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLab * Purpose : */ //============================================================================ -SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const string& theEntry) +SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const std::string& theEntry) { SALOMEDSImpl_SObject aSO; if(_mapOfSO.find(theEntry) != _mapOfSO.end()) @@ -1155,8 +1155,8 @@ SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel) * Purpose : */ //============================================================================ -DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const string& theEntry, - const string& theType) +DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry, + const std::string& theType) { SALOMEDSImpl_SObject aSO = GetSObject(theEntry); DF_Attribute* anAttr; @@ -1169,8 +1169,8 @@ DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const string& theEntry, * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, - const string& theBaseName, +bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath, + const std::string& theBaseName, bool isPublished, SALOMEDSImpl_DriverFactory* theFactory) { @@ -1181,8 +1181,8 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, return false; } - vector aSeq; - string aCompType, aFactoryType; + std::vector aSeq; + std::string aCompType, aFactoryType; //Build a list of all components in the Study SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator(); @@ -1198,16 +1198,16 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, } #ifdef WIN32 - string aFileName = - thePath + string("\\") + theBaseName + string(".py"); + std::string aFileName = + thePath + std::string("\\") + theBaseName + std::string(".py"); #else - string aFileName = - thePath + string("/") + theBaseName + string(".py"); + std::string aFileName = + thePath + std::string("/") + theBaseName + std::string(".py"); #endif //Create a file that will contain a main Study script - fstream fp; - fp.open(aFileName.c_str(), ios::out); + std::fstream fp; + fp.open(aFileName.c_str(), std::ios::out); #ifdef WIN32 bool isOpened = fp.is_open(); @@ -1216,43 +1216,47 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, #endif if(!isOpened) { - _errorCode = string("Can't create a file ")+aFileName; + _errorCode = std::string("Can't create a file ")+aFileName; return false; } - string aBatchModeScript = "salome"; + std::string aBatchModeScript = "salome"; //Output to the main Study script required Python modules import, //set sys.path and add a creation of the study. - fp << "# -*- coding: iso-8859-1 -*-\n" << endl; - fp << GetDumpStudyComment() << endl << endl; - fp << "import sys" << endl; - fp << "import " << aBatchModeScript << endl << endl; + // dump header + fp << GetDumpStudyComment() << std::endl; + + // global imports + fp << "import sys" << std::endl; + fp << "import " << aBatchModeScript << std::endl << std::endl; - fp << aBatchModeScript << ".salome_init()" << endl << endl; + // initialization function + fp << aBatchModeScript << ".salome_init()" << std::endl << std::endl; + // notebook initialization fp << _GetNoteBookAccess(); - fp << "sys.path.insert( 0, r\'" << thePath << "\')" << endl << endl; + // extend sys.path with the directory where the script is being dumped to + fp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl; - //Dump NoteBook Variables + // dump NoteBook variables fp << _GetStudyVariablesScript(); - //Check if it's necessary to dump visual parameters + // dump visual parameters if necessary bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this); int lastSavePoint = -1; if(isDumpVisuals) { lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this); if(lastSavePoint > 0) { - fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << endl << endl; + fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl; } } - - vector aSeqOfFileNames; + std::vector aSeqOfFileNames; - //Iterate all components and create the componponents specific scripts. + // dump all components and create the components specific scripts bool isOk = true; int aLength = aSeq.size(); for(int i = 1; i <= aLength; i++) { @@ -1261,7 +1265,7 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, SALOMEDSImpl_SComponent sco = FindComponent(aCompType); SALOMEDSImpl_Driver* aDriver = NULL; // if there is an associated Engine call its method for saving - string IOREngine; + std::string IOREngine; try { if (!sco.ComponentIOR(IOREngine)) { if (!aCompType.empty()) { @@ -1295,21 +1299,21 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, isOk = false; //Create a file that will contain the component specific script - fstream fp2; + std::fstream fp2; #ifdef WIN32 - aFileName=thePath+string("\\"); + aFileName=thePath+std::string("\\"); #else - aFileName=thePath+string("/"); + aFileName=thePath+std::string("/"); #endif - string aScriptName; + std::string aScriptName; aScriptName += theBaseName; aScriptName += "_"; aScriptName += aCompType; - aFileName += aScriptName+ string(".py"); + aFileName += aScriptName+ std::string(".py"); aSeqOfFileNames.push_back(aFileName); - fp2.open(aFileName.c_str(), ios::out); + fp2.open(aFileName.c_str(), std::ios::out); #ifdef WIN32 isOpened = fp2.is_open(); @@ -1318,28 +1322,29 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, #endif if(!isOpened) { - _errorCode = string("Can't create a file ")+aFileName; + _errorCode = std::string("Can't create a file ")+aFileName; SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false); return false; } //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(); 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 << endl; - fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << endl; + fp << "import " << aScriptName << std::endl; + fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl; } - fp << endl; - fp << "if salome.sg.hasDesktop():" << endl; - fp << "\tsalome.sg.updateObjBrowser(1)" << endl; + fp << std::endl; + fp << "if salome.sg.hasDesktop():" << std::endl; + fp << "\tsalome.sg.updateObjBrowser(1)" << std::endl; if(isDumpVisuals) { //Output the call to Session's method restoreVisualState - fp << "\tiparameters.getSession().restoreVisualState(1)" << endl; + fp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl; } @@ -1352,18 +1357,24 @@ bool SALOMEDSImpl_Study::DumpStudy(const string& thePath, //purpose : return a header comment for a DumpStudy script //======================================================================= -string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName) +std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName) { - string txt - ("### This file is generated by SALOME automatically by dump python functionality"); + std::stringstream txt; + txt << "# -*- coding: iso-8859-1 -*-" << std::endl << std::endl; + txt << "###" << std::endl; + txt << "### This file is generated automatically by SALOME v" + << KERNEL_VERSION_STR + << " with dump python functionality"; if ( theComponentName ) - txt += string(" of ") + (char*) theComponentName + " component"; - return txt; + txt << " (" << theComponentName << " component)"; + txt << std::endl; + txt << "###" << std::endl; + return txt.str(); } void dumpSO(const SALOMEDSImpl_SObject& theSO, - fstream& fp, - const string& Tab, + std::fstream& fp, + const std::string& Tab, SALOMEDSImpl_Study* theStudy); //============================================================================ @@ -1371,11 +1382,11 @@ void dumpSO(const SALOMEDSImpl_SObject& theSO, * Purpose : */ //============================================================================ -void SALOMEDSImpl_Study::dump(const string& theFileName) +void SALOMEDSImpl_Study::dump(const std::string& theFileName) { //Create a file that will contain a main Study script - fstream fp; - fp.open(theFileName.c_str(), ios::out); + std::fstream fp; + fp.open(theFileName.c_str(), std::ios::out); #ifdef WIN32 bool isOpened = fp.is_open(); @@ -1384,15 +1395,15 @@ void SALOMEDSImpl_Study::dump(const string& theFileName) #endif if(!isOpened) { - _errorCode = string("Can't create a file ")+theFileName; - cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << endl; + _errorCode = std::string("Can't create a file ")+theFileName; + std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl; return; } SALOMEDSImpl_SObject aSO = FindObjectID("0:1"); - fp << "0:1" << endl; + fp << "0:1" << std::endl; SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO); - string aTab(" "); + std::string aTab(" "); for(; Itr.More(); Itr.Next()) { dumpSO(Itr.Value(), fp, aTab, this); } @@ -1402,13 +1413,13 @@ void SALOMEDSImpl_Study::dump(const string& theFileName) void dumpSO(const SALOMEDSImpl_SObject& theSO, - fstream& fp, - const string& Tab, + std::fstream& fp, + const std::string& Tab, SALOMEDSImpl_Study* theStudy) { - string aTab(Tab), anID(theSO.GetID()); - fp << aTab << anID << endl; - vector attribs = theSO.GetLabel().GetAttributes(); + std::string aTab(Tab), anID(theSO.GetID()); + fp << aTab << anID << std::endl; + std::vector attribs = theSO.GetLabel().GetAttributes(); for(int i = 0; i(attribs[i]); @@ -1416,29 +1427,29 @@ void dumpSO(const SALOMEDSImpl_SObject& theSO, continue; } - string aType = anAttr->GetClassType(); + std::string aType = anAttr->GetClassType(); fp << Tab << " -- " << aType; - if(aType == string("AttributeReal")) { + if(aType == std::string("AttributeReal")) { fp << " : " << dynamic_cast(anAttr)->Value(); } - else if(aType == string("AttributeInteger")) { + else if(aType == std::string("AttributeInteger")) { fp << " : " << dynamic_cast(anAttr)->Value(); } - else if(aType == string("AttributeName")) { + else if(aType == std::string("AttributeName")) { fp << " : " << dynamic_cast(anAttr)->Value(); } - else if(aType == string("AttributeComment")) { + else if(aType == std::string("AttributeComment")) { fp << " : " << dynamic_cast(anAttr)->Value(); } - else if(aType == string("AttributeReference")) { + else if(aType == std::string("AttributeReference")) { fp << " : " << dynamic_cast(anAttr)->Save(); } - fp << endl; + fp << std::endl; } SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO); - string aNewTab(" "); + std::string aNewTab(" "); aNewTab+=aTab; for(; Itr.More(); Itr.Next()) { dumpSO(Itr.Value(), fp, aNewTab, theStudy); @@ -1454,7 +1465,7 @@ void SALOMEDSImpl_Study::Modify() } //============================================================================ -/*! Function : +/*! Function : * Purpose : */ //============================================================================ @@ -1478,7 +1489,7 @@ SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const c if (so) { builder->FindAttribute(so, A, "AttributeParameter"); if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component - A = builder->FindOrCreateAttribute(so, "AttributeParameter"); + A = builder->FindOrCreateAttribute(so, "AttributeParameter"); } attParam = dynamic_cast( A ); } @@ -1486,11 +1497,11 @@ SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const c } //============================================================================ -/*! Function : +/*! Function : * Purpose : */ //============================================================================ -SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID, +SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID, const char* theModuleName, int theSavePoint) { @@ -1500,7 +1511,7 @@ SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const c SALOMEDSImpl_AttributeParameter* par = NULL; SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so); - string moduleName(theModuleName); + std::string moduleName(theModuleName); for(; it.More(); it.Next()) { SALOMEDSImpl_SObject so(it.Value()); if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) { @@ -1543,10 +1554,10 @@ bool SALOMEDSImpl_Study::IsStudyLocked() //============================================================================ void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID) { - vector::iterator vsI = _lockers.begin(); + std::vector::iterator vsI = _lockers.begin(); int length = _lockers.size(); bool isFound = false; - string id(theLockerID); + std::string id(theLockerID); for(int i = 0; i SALOMEDSImpl_Study::GetLockerID() +std::vector SALOMEDSImpl_Study::GetLockerID() { return _lockers; } @@ -1571,13 +1582,13 @@ vector SALOMEDSImpl_Study::GetLockerID() * Purpose : */ //============================================================================ -void SALOMEDSImpl_Study::SetVariable(const string& theVarName, +void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName, const double theValue, const SALOMEDSImpl_GenericVariable::VariableTypes theType) { bool modified = false; SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); - + if( aGVar == NULL ) { SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName); @@ -1601,17 +1612,17 @@ void SALOMEDSImpl_Study::SetVariable(const string& theVarName, * Purpose : */ //============================================================================ -void SALOMEDSImpl_Study::SetStringVariable(const string& theVarName, - const string& theValue, - const SALOMEDSImpl_GenericVariable::VariableTypes theType) +void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName, + const std::string& theValue, + const SALOMEDSImpl_GenericVariable::VariableTypes theType) { bool modified = false; SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); - + if( aGVar == NULL ) { - + SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName); - + aSVar->setStringValue(theValue); myNoteBookVars.push_back(aSVar); modified = true; @@ -1631,9 +1642,9 @@ void SALOMEDSImpl_Study::SetStringVariable(const string& theVarName, * Purpose : */ //============================================================================ -void SALOMEDSImpl_Study::SetStringVariableAsDouble(const string& theVarName, - const double theValue, - const SALOMEDSImpl_GenericVariable::VariableTypes theType) +void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName, + const double theValue, + const SALOMEDSImpl_GenericVariable::VariableTypes theType) { SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast(aGVar)) @@ -1645,10 +1656,10 @@ void SALOMEDSImpl_Study::SetStringVariableAsDouble(const string& theVarName, * Purpose : */ //============================================================================ -double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName) +double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName) { SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); - + if(aGVar != NULL ) if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast(aGVar)) return aSVar->getValue(); @@ -1661,14 +1672,14 @@ double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName) * Purpose : */ //============================================================================ -string SALOMEDSImpl_Study::GetStringVariableValue(const string& theVarName) +std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName) { SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); - + if(aGVar != NULL ) if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast(aGVar)) return aSVar->getStringValue(); - + return 0; } @@ -1677,15 +1688,15 @@ string SALOMEDSImpl_Study::GetStringVariableValue(const string& theVarName) * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::IsTypeOf(const string& theVarName, +bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName, SALOMEDSImpl_GenericVariable:: VariableTypes theType) const { SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); - + if(aGVar != NULL ) return aGVar->Type() == theType; - + return false; } @@ -1694,7 +1705,7 @@ bool SALOMEDSImpl_Study::IsTypeOf(const string& theVarName, * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const +bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const { SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName); return (aGVar != NULL); @@ -1705,13 +1716,13 @@ bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const * Purpose : */ //============================================================================ -vector SALOMEDSImpl_Study::GetVariableNames() const +std::vector SALOMEDSImpl_Study::GetVariableNames() const { - vector aResult; + std::vector aResult; for(int i = 0; i < myNoteBookVars.size(); i++) aResult.push_back(myNoteBookVars[i]->Name()); - + return aResult; } @@ -1737,7 +1748,7 @@ SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& if(theName.compare(myNoteBookVars[i]->Name()) == 0) { aResult = myNoteBookVars[i]; break; - } + } } return aResult; } @@ -1747,13 +1758,13 @@ SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::RemoveVariable(const string& theVarName) +bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName) { SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName ); if( !aVariable ) return false; - string aValue = aVariable->SaveToScript(); + std::string aValue = aVariable->SaveToScript(); ReplaceVariableAttribute( theVarName, aValue ); std::vector::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end(); @@ -1776,7 +1787,7 @@ bool SALOMEDSImpl_Study::RemoveVariable(const string& theVarName) * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::RenameVariable(const string& theVarName, const string& theNewVarName) +bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName) { SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName ); if( !aVariable ) @@ -1804,7 +1815,7 @@ bool SALOMEDSImpl_Study::RenameVariable(const string& theVarName, const string& * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::IsVariableUsed(const string& theVarName) +bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName) { return FindVariableAttribute( theVarName ); } @@ -1828,15 +1839,15 @@ bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStu { if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr ) { - string aString = aStringAttr->Value(); + std::string aString = aStringAttr->Value(); - vector< vector > aSections = ParseVariables( aString ); + std::vector< std::vector > aSections = ParseVariables( aString ); for( int i = 0, n = aSections.size(); i < n; i++ ) { - vector aVector = aSections[i]; + std::vector aVector = aSections[i]; for( int j = 0, m = aVector.size(); j < m; j++ ) { - string aStr = aVector[j]; + std::string aStr = aVector[j]; if( aStr.compare( theName ) == 0 ) return true; } @@ -1884,15 +1895,15 @@ void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* the if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr ) { bool isChanged = false; - string aNewString, aCurrentString = aStringAttr->Value(); + std::string aNewString, aCurrentString = aStringAttr->Value(); - vector< vector > aSections = ParseVariables( aCurrentString ); + std::vector< std::vector > aSections = ParseVariables( aCurrentString ); for( int i = 0, n = aSections.size(); i < n; i++ ) { - vector aVector = aSections[i]; + std::vector aVector = aSections[i]; for( int j = 0, m = aVector.size(); j < m; j++ ) { - string aStr = aVector[j]; + std::string aStr = aVector[j]; if( aStr.compare( theSource ) == 0 ) { isChanged = true; @@ -1934,7 +1945,7 @@ void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, * Purpose : */ //============================================================================ -vector< vector< string > > SALOMEDSImpl_Study::ParseVariables(const string& theVariables) const +std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const { return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR ); } @@ -1945,8 +1956,8 @@ vector< vector< string > > SALOMEDSImpl_Study::ParseVariables(const string& theV */ //============================================================================ void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled) -{ - _errorCode = ""; _autoFill = isEnabled; +{ + _errorCode = ""; _autoFill = isEnabled; if(isEnabled) { _builder->SetOnAddSObject(_cb); _builder->SetOnRemoveSObject(_cb); @@ -1962,10 +1973,10 @@ void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled) * Purpose : */ //============================================================================ -vector SALOMEDSImpl_Study::GetIORs() +std::vector SALOMEDSImpl_Study::GetIORs() { - vector anIORs; - map::const_iterator MI; + std::vector anIORs; + std::map::const_iterator MI; for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++) anIORs.push_back(MI->first); -- 2.39.2