From 2b8ea8694fde14b8536ace837c4e3b87cbb88b93 Mon Sep 17 00:00:00 2001 From: adv Date: Wed, 29 Jan 2014 09:08:50 +0000 Subject: [PATCH] Dump model to python. --- src/HYDROData/HYDROData_Document.cxx | 64 ++++++++++++++++++++-------- src/HYDROData/HYDROData_Document.h | 7 ++- src/HYDROData/HYDROData_Obstacle.cxx | 2 +- src/HYDROGUI/HYDROGUI_DataModel.cxx | 10 ++--- 4 files changed, 58 insertions(+), 25 deletions(-) diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index c195b9d5..89469757 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -175,7 +175,8 @@ void HYDROData_Document::Close() HYDROData_Application::GetApplication()->RemoveDocument(this); } -bool HYDROData_Document::DumpToPython( const QString& theFileName ) const +bool HYDROData_Document::DumpToPython( const QString& theFileName, + const bool theIsMultiFile ) const { // Try to open the file QFile aFile( theFileName ); @@ -185,7 +186,7 @@ bool HYDROData_Document::DumpToPython( const QString& theFileName ) const MapOfTreatedObjects aTreatedObjects; // Dump header for python script - QStringList aHeaderDump = DumpToPython( aTreatedObjects ); + QStringList aHeaderDump = DumpToPython( aTreatedObjects, theIsMultiFile ); if ( aHeaderDump.isEmpty() ) return false; @@ -194,17 +195,27 @@ bool HYDROData_Document::DumpToPython( const QString& theFileName ) const bool aRes = true; // Dump all model objects to Python script - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_IMAGE ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_POLYLINEXY ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_BATHYMETRY ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_PROFILE ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_POLYLINE ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_STREAM ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_CHANNEL ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_DIGUE ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_OBSTACLE ); - aRes = aRes && dumpPartitionToPython( aFile, aTreatedObjects, KIND_CALCULATION ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_IMAGE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_PROFILE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_POLYLINE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_STREAM ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_CHANNEL ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_DIGUE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE ); + aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_CALCULATION ); + + // Dump code to close python fuction + if ( aRes && theIsMultiFile ) + { + QStringList aFooterScript; + aFooterScript << QString( "" ); + aFooterScript << QString( " pass" ); + HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript ); + } + return aRes; } @@ -221,7 +232,8 @@ QString HYDROData_Document::GetDocPyName() const return aDocName; } -QStringList HYDROData_Document::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Document::DumpToPython( MapOfTreatedObjects& theTreatedObjects, + const bool theIsMultiFile ) const { QString aDocName = GetDocPyName(); @@ -237,14 +249,24 @@ QStringList HYDROData_Document::DumpToPython( MapOfTreatedObjects& theTreatedObj aResScript << QString( "from HYDROPy import *" ); aResScript << QString( "from PyQt4.QtCore import *" ); aResScript << QString( "from PyQt4.QtGui import *" ); - aResScript << QString( "import salome" ); - aResScript << QString( "" ); - aResScript << QString( "%1 = HYDROData_Document.Document( salome.sg.getActiveStudyId() );" ).arg( aDocName ); + + if ( theIsMultiFile ) + { + aResScript << QString( "" ); + aResScript << QString( "def RebuildData( theStudy ):" ); + aResScript << QString( " %1 = HYDROData_Document.Document( theStudy._get_StudyId() );" ).arg( aDocName ); + } + else + { + aResScript << QString( "" ); + aResScript << QString( "%1 = HYDROData_Document.Document( theStudy._get_StudyId() );" ).arg( aDocName ); + } return aResScript; } bool HYDROData_Document::dumpPartitionToPython( QFile& theFile, + const bool theIsMultiFile, MapOfTreatedObjects& theTreatedObjects, const ObjectKind& theObjectKind ) const { @@ -269,6 +291,14 @@ bool HYDROData_Document::dumpPartitionToPython( QFile& theFile, theTreatedObjects.insert( anObjName, anObject ); QStringList anObjDump = anObject->DumpToPython( theTreatedObjects ); + + if ( theIsMultiFile ) + { + // For multifile dump we use the function, see the document dump header + QStringList::iterator anIt = anObjDump.begin(); + for ( ; anIt != anObjDump.end(); ++anIt ) + anIt->prepend( " " ); + } HYDROData_Tool::WriteStringsToFile( theFile, anObjDump ); } diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 1de23428..b583787d 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -78,10 +78,12 @@ public: //! Dump study document to Python script representation. //! \param theFileName full name of the file to store //! \returns true if document has been successfuly dumped - HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName ) const; + HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName, + const bool theIsMultiFile ) const; //! Dump model data to Python script representation. - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects, + const bool theIsMultiFile ) const; public: @@ -161,6 +163,7 @@ private: // Dump objects of type \c theObjectKind to file \c theFile bool dumpPartitionToPython( QFile& theFile, + const bool theIsMultiFile, MapOfTreatedObjects& theDumpedObjects, const ObjectKind& theObjectKind ) const; diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index bde8f4fc..5a108d6e 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -66,7 +66,7 @@ QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObj if ( !aGeomObjectEntry.IsEmpty() ) { QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "obstacle_sobj" ); - aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" );" ) + aResList << QString( "%1 = theStudy.FindObjectID( \"%2\" );" ) .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() ); aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" ) diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index f4cb0c9a..0476f169 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -186,13 +186,13 @@ bool HYDROGUI_DataModel::dumpPython( const QString& theURL, if ( aDocument.IsNull() || !aStudy ) return false; - QString aFileToExport = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str(); - aFileToExport += QString( QDir::separator() ) + "HYDRO.py"; - - bool aRes = aDocument->DumpToPython( aFileToExport ); + QString aDir = aStudy->GetTmpDir( theURL.toLatin1().constData(), isMultiFile ).c_str(); + QString aFileToExport = aDir + QString( QDir::separator() ) + "HYDRO.py"; + bool aRes = aDocument->DumpToPython( aFileToExport, isMultiFile ); if ( aRes ) { + theListOfFiles.append( aDir ); theListOfFiles.append( aFileToExport ); } @@ -880,7 +880,7 @@ void HYDROGUI_DataModel::buildObjectTree( SUIT_DataObject* theParent, } #ifdef DEB_GROUPS - HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetSplittedGroups(); + HYDROData_SequenceOfObjects aCalcGroups = aCaseObj->GetGeometryGroups(); buildObjectPartition( aGuiObj, aCalcGroups, tr( "OBJECT_GROUPS" ), false ); HYDROData_SequenceOfObjects aCalcSplitGroups = aCaseObj->GetSplittedGroups(); -- 2.39.2