-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021 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
#include "SalomeApp_Engine_i.h"
#include "SalomeApp_Application.h"
+#include "SalomeApp_Study.h"
+#include "SUIT_Session.h"
+#include "CAM_Module.h"
+#include "LightApp_DataModel.h"
#include <SALOME_NamingService.hxx>
#include <SALOMEDS_Tool.hxx>
-#include <Utils_ORB_INIT.hxx>
-#include <Utils_SINGLETON.hxx>
+#include <ArgvKeeper.hxx>
+#include <OpUtil.hxx>
#include <Utils_SALOME_Exception.hxx>
#include <utilities.h>
Constructor
*/
SalomeApp_Engine_i::SalomeApp_Engine_i( const char* theComponentName )
+ : myKeepFiles( false ), myComponentName( theComponentName )
{
- myComponentName = theComponentName;
MESSAGE("SalomeApp_Engine_i::SalomeApp_Engine_i(): myComponentName = " <<
- myComponentName << ", this = " << this);
+ qPrintable( myComponentName ) << ", this = " << this);
}
/*!
SalomeApp_Engine_i::~SalomeApp_Engine_i()
{
MESSAGE("SalomeApp_Engine_i::~SalomeApp_Engine_i(): myComponentName = " <<
- myComponentName << ", this = " << this);
+ qPrintable( myComponentName ) << ", this = " << this);
}
SALOMEDS::TMPFile* SalomeApp_Engine_i::Save (SALOMEDS::SComponent_ptr theComponent,
- const char* theURL,
+ const char* /*theURL*/,
bool isMultiFile)
{
SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
+
if (CORBA::is_nil(theComponent))
return aStreamFile._retn();
+
+ // Component type
+ QString componentName (theComponent->ComponentDataType());
+ // Error somewhere outside - Save() called with wrong SComponent instance
+ if ( myComponentName != componentName )
+ return aStreamFile._retn();
+
// 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 ( GetListOfFiles(0).empty() ) // 0 means persistence file
+ {
+
+ // 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
+ SalomeApp_Application* app =
+ dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
+ if ( !app )
+ return aStreamFile._retn();
+
+ // - Get study
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+
+ if ( !study )
+ return aStreamFile._retn();
+ QString url = QString::fromStdString(study->studyDS()->URL());
+
+ // - 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( 0, names ); // 0 means persistence file
+ manuallySaved = true;
+ }
+
+ // Get a temporary directory to store a file
+ //std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
// 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;
-
+ ListOfFiles listOfFiles = GetListOfFiles( 0 ); // 0 means persistence file
+ const int n = (int)listOfFiles.size() - 1; //!< TODO: conversion from size_t to int
+
if (n > 0) { // there are some files, containing persistent data of the component
- std::string aTmpDir = myListOfFiles[0];
-
+ std::string aTmpDir = listOfFiles[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()));
-
+ aSeq.push_back(CORBA::string_dup(listOfFiles[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);
+ SalomeApp_Application* app =
+ dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+ study->RemoveTemporaryFiles( myComponentName.toStdString().c_str(), isMultiFile );
}
+
+ if ( manuallySaved )
+ SetListOfFiles(0, ListOfFiles()); // 0 means persistence file
return aStreamFile._retn();
}
// Error somewhere outside - Load() called with
// wrong SComponent instance
- std::string componentName (theComponent->ComponentDataType());
+ QString componentName = theComponent->ComponentDataType();
if ( myComponentName != componentName )
return false;
SALOMEDS_Tool::PutStreamToFiles(theFile, aTmpDir.c_str(), isMultiFile);
// Store list of file names to be used by the component loading procedure
- const int n = aSeq.size() + 1;
+ const int n = (int)aSeq.size() + 1; //!< TODO: conversion from size_t to int
ListOfFiles listOfFiles (n);
listOfFiles[0] = aTmpDir;
for (int i = 1; i < n; i++)
listOfFiles[i] = std::string(aSeq[i - 1]);
- SetListOfFiles(listOfFiles);
+ SetListOfFiles(0, listOfFiles); // 0 means persistence file
+ keepFiles( true );
return true;
}
-SalomeApp_Engine_i::ListOfFiles SalomeApp_Engine_i::GetListOfFiles()
+SalomeApp_Engine_i::ListOfFiles SalomeApp_Engine_i::GetListOfFiles(int type)
{
- return myListOfFiles;
+ return myListOfFiles.count(type) ? myListOfFiles[type] : ListOfFiles();
}
-void SalomeApp_Engine_i::SetListOfFiles (const ListOfFiles& theListOfFiles)
+void SalomeApp_Engine_i::SetListOfFiles (int type, const ListOfFiles& theListOfFiles)
{
- myListOfFiles = theListOfFiles;
+ myListOfFiles[type] = theListOfFiles;
}
/*!
* DumpPython implementation for light modules
*/
-Engines::TMPFile* SalomeApp_Engine_i::DumpPython(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
aStreamFile[0] = '\0';
isValidScript = true;
+ ListOfFiles listOfFiles = GetListOfFiles( 1 ); // 1 means dump file
+
// listOfFiles must contain temporary directory name in its first item
// and names of files (relatively the temporary directory) in the others
- if ( myListOfFiles.size() < 2 )
+ if ( listOfFiles.size() < 2 )
return aStreamFile._retn();
// there are some files, containing persistent data of the component
- QString aTmpPath( myListOfFiles.front().c_str() );
+ QString aTmpPath( listOfFiles.front().c_str() );
QDir aTmpDir( aTmpPath );
if ( !aTmpDir.exists() )
return aStreamFile._retn();
QStringList aFilePaths;
QList<qint64> aFileSizes;
qint64 aBuffSize = 0;
- ListOfFiles::const_iterator aFIt = myListOfFiles.begin();
- ListOfFiles::const_iterator aFEnd = myListOfFiles.end();
+ ListOfFiles::const_iterator aFIt = listOfFiles.begin();
+ ListOfFiles::const_iterator aFEnd = listOfFiles.end();
aFIt++;
for (; aFIt != aFEnd; aFIt++){
QString aFileName( (*aFIt).c_str() );
*/
char* SalomeApp_Engine_i::ComponentDataType()
{
- return const_cast<char*>( myComponentName.c_str() );
+ return CORBA::string_dup( myComponentName.toLatin1().constData() );
}
/*!
QString version;
SalomeApp_Application::ModuleShortInfo version_info;
foreach ( version_info, versions ) {
- if ( SalomeApp_Application::moduleName( version_info.name ) == myComponentName.c_str() ) {
+ if ( SalomeApp_Application::moduleName( version_info.name ) == myComponentName ) {
version = version_info.version;
break;
}
if ( CORBA::is_nil( _orb ) ) {
Qtx::CmdLineArgs args;
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
- _orb = init( args.argc(), args.argv() );
+ SetArgcArgv( args.argc(), args.argv() );
+ _orb = KERNEL::GetRefToORB();
}
return _orb;
/*!
\return
*/
-SALOME_NamingService* SalomeApp_Engine_i::namingService()
+SALOME_NamingService_Abstract* SalomeApp_Engine_i::namingService()
{
- static SALOME_NamingService _ns(orb());
- return &_ns;
+ return SalomeApp_Application::namingService();
}
/*!