-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#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>
#include <iostream>
-namespace
-{
- SalomeApp_Study* getStudyById( int id )
- {
- SalomeApp_Study* study = 0;
- QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
- for ( int i = 0; i < apps.count() && !study; i++ )
- {
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( apps[i]->activeStudy() );
- if ( appStudy && appStudy->id() == id )
- study = appStudy;
- }
- return study;
- }
-}
-
/*!
Constructor
*/
SalomeApp_Engine_i::SalomeApp_Engine_i( const char* theComponentName )
- : myComponentName( theComponentName )
+ : myKeepFiles( false ), myComponentName( theComponentName )
{
MESSAGE("SalomeApp_Engine_i::SalomeApp_Engine_i(): myComponentName = " <<
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) || 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();
bool manuallySaved = false;
- if ( !myMap.count( studyId ) ) {
+ 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
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 = 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???
if ( !name.isEmpty() )
names.push_back(name.toUtf8().data());
}
- SetListOfFiles( names, studyId );
+ 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();
- 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
+ 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 = 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(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
+ 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( ListOfFiles(), studyId );
+ SetListOfFiles(0, ListOfFiles()); // 0 means persistence file
return aStreamFile._retn();
}
bool isMultiFile)
{
std::cout << "SalomeApp_Engine_i::Load() isMultiFile = " << isMultiFile << std::endl;
- if (CORBA::is_nil(theComponent) || CORBA::is_nil(theComponent->GetStudy()))
+ if (CORBA::is_nil(theComponent))
return false;
// Error somewhere outside - Load() called with
if ( myComponentName != componentName )
return false;
- const int studyId = theComponent->GetStudy()->StudyId();
-
// Create a temporary directory for the component's data files
std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
// Convert the byte stream theStream to a files and place them in the tmp directory.
// The files and temporary directory must be deleted by the component loading procedure.
- SALOMEDS::ListOfFileNames_var aSeq =
+ ListOfFiles aSeq =
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->length() + 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, studyId);
+ SetListOfFiles(0, listOfFiles); // 0 means persistence file
+ keepFiles( true );
return true;
}
-SalomeApp_Engine_i::ListOfFiles SalomeApp_Engine_i::GetListOfFiles (const int theStudyId)
+SalomeApp_Engine_i::ListOfFiles SalomeApp_Engine_i::GetListOfFiles(int type)
{
- ListOfFiles aListOfFiles;
-
- if (myMap.find(theStudyId) != myMap.end())
- {
- aListOfFiles = myMap[theStudyId];
- }
-
- return aListOfFiles;
+ return myListOfFiles.count(type) ? myListOfFiles[type] : ListOfFiles();
}
-void SalomeApp_Engine_i::SetListOfFiles (const ListOfFiles& theListOfFiles,
- const int theStudyId)
+void SalomeApp_Engine_i::SetListOfFiles (int type, const ListOfFiles& theListOfFiles)
{
- if ( theListOfFiles.empty() )
- myMap.erase( theStudyId );
- else
- myMap[theStudyId] = theListOfFiles;
+ myListOfFiles[type] = theListOfFiles;
}
/*!
* 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 = "<<
qPrintable( myComponentName ) << ", this = " << this);
aStreamFile[0] = '\0';
isValidScript = true;
- if (CORBA::is_nil(theStudy))
- return aStreamFile._retn();
-
- SALOMEDS::Study_var studyDS = SALOMEDS::Study::_narrow( theStudy );
- const int studyId = studyDS->StudyId();
-
- if (!myMap.count(studyId))
- return aStreamFile._retn();
-
- ListOfFiles listOfFiles = myMap[studyId];
+ 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 ( listOfFiles.size() < 2 )
+ if ( listOfFiles.size() < 2 )
return aStreamFile._retn();
// there are some files, containing persistent data of the component
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();
}
/*!