{
SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
- if ( CORBA::is_nil(theComponent) || CORBA::is_nil( theComponent->GetStudy() ) )
- return aStreamFile._retn();
+
+ if (CORBA::is_nil(theComponent))
+ return aStreamFile._retn();
++
+ // Component type
- QString componentName = theComponent->ComponentDataType();
++ QString componentName (theComponent->ComponentDataType());
+
+ // Error somewhere outside - Save() called with wrong SComponent instance
+ if ( myComponentName != componentName )
+ return aStreamFile._retn();
-
- // Get study ID
- const int studyId = theComponent->GetStudy()->StudyId();
++
+ // Get a temporary directory to store a file
+ //std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
- std::string componentName (theComponent->ComponentDataType());
+ bool manuallySaved = false;
- // Error somewhere outside - Save() called with
- // wrong SComponent instance
- if ( myComponentName != componentName )
- return aStreamFile._retn();
- if ( !myMap.count( studyId ) ) {
++ if ( GetListOfFiles().empty() ) {
++
+ // Save was probably called from outside GUI, so SetListOfFiles was not called!
+ // Try to get list of files from directly from data model
+
+ MESSAGE("SalomeApp_Engine_i::Save(): myComponentName = " <<
+ qPrintable( myComponentName ) <<
+ "it seems Save() was called from outside GUI" );
+
++ // - Get app rnv
++ SalomeApp_Application* app =
++ dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
++ if ( !app )
++ return aStreamFile._retn();
++
+ // - Get study
- SalomeApp_Study* study = getStudyById( studyId );
++ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
++
+ if ( !study )
+ return aStreamFile._retn();
+ QString url = QString::fromStdString(study->studyDS()->URL());
- // - Get app
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
- if ( !app )
- return aStreamFile._retn();
++
+ // - Get module
+ CAM_Module* module = app->module( SalomeApp_Application::moduleTitle( componentName ) );
+ if ( !module ) // load module???
+ return aStreamFile._retn();
+ // - Get data model
+ LightApp_DataModel* dataModel = dynamic_cast<LightApp_DataModel*>( module->dataModel() );
+ if ( !dataModel )
+ return aStreamFile._retn();
+ // - Save data files
+ QStringList dataFiles;
+ // we use 'url' instead of 'theURL' as latter normally contains path to the tmp dir,
+ // but not actual study's URL
+ dataModel->saveAs( url, study, dataFiles );
+ std::vector<std::string> names;
+ foreach ( QString name, dataFiles ) {
+ if ( !name.isEmpty() )
+ names.push_back(name.toUtf8().data());
+ }
- SetListOfFiles( names, studyId );
++ SetListOfFiles( names );
+ manuallySaved = true;
+ }
+
+ // Get a temporary directory to store a file
+ //std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
- if ( myMap.count( studyId ) ) {
-
- const ListOfFiles& listOfFiles = myMap[studyId];
-
- // listOfFiles must contain temporary directory name in its first item
- // and names of files (relatively the temporary directory) in the others
- const int n = listOfFiles.size() - 1;
-
- if (n > 0) { // there are some files, containing persistent data of the component
- std::string aTmpDir = listOfFiles[0];
-
- // Create a list to store names of created files
- SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
- aSeq->length(n);
- for (int i = 0; i < n; i++)
- aSeq[i] = CORBA::string_dup(listOfFiles[i + 1].c_str());
-
- // Convert a file to the byte stream
- aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
-
- // Remove the files and tmp directory, created by the component storage procedure
- if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
- }
+ // listOfFiles must contain temporary directory name in its first item
+ // and names of files (relatively the temporary directory) in the others
+ const int n = myListOfFiles.size() - 1;
-
++
+ if (n > 0) { // there are some files, containing persistent data of the component
+ std::string aTmpDir = myListOfFiles[0];
-
++
+ // Create a list to store names of created files
+ ListOfFiles aSeq;
+ aSeq.reserve(n);
+ for (int i = 0; i < n; i++)
+ aSeq.push_back(CORBA::string_dup(myListOfFiles[i + 1].c_str()));
-
++
+ // Convert a file to the byte stream
+ aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq, isMultiFile);
-
++
+ // Remove the files and tmp directory, created by the component storage procedure
+ if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true);
}
-
++
+ if ( manuallySaved )
- SetListOfFiles( ListOfFiles(), studyId );
++ SetListOfFiles( ListOfFiles());
return aStreamFile._retn();
}
/*!
* DumpPython implementation for light modules
*/
-Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Object_ptr theStudy,
- CORBA::Boolean isPublished,
- CORBA::Boolean isMultiFile,
- CORBA::Boolean& isValidScript)
+Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Boolean isPublished,
+ CORBA::Boolean isMultiFile,
+ CORBA::Boolean& isValidScript)
{
MESSAGE("SalomeApp_Engine_i::DumpPython(): myComponentName = "<<
- myComponentName << ", this = " << this);
+ qPrintable( myComponentName ) << ", this = " << this);
// Temporary solution: returning a non-empty sequence
// even if there's nothing to dump, to avoid crashes in SALOMEDS