Salome HOME
Merge branch 'V9_8_BR'
[modules/gui.git] / src / SalomeApp / SalomeApp_Engine_i.cxx
index 594ed26892c219c9dc39990ef44b81e640b19da4..760822ae967cc1def1481704f71e770610442edb 100644 (file)
@@ -1,4 +1,4 @@
-// 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
@@ -33,8 +33,8 @@
 
 #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>
 
@@ -48,7 +48,7 @@
   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);
@@ -64,7 +64,7 @@ SalomeApp_Engine_i::~SalomeApp_Engine_i()
 }
 
 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;
@@ -85,7 +85,8 @@ SALOMEDS::TMPFile* SalomeApp_Engine_i::Save (SALOMEDS::SComponent_ptr theCompone
 
   bool manuallySaved = false;
 
-  if ( GetListOfFiles().empty() ) {
+  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
@@ -94,7 +95,7 @@ SALOMEDS::TMPFile* SalomeApp_Engine_i::Save (SALOMEDS::SComponent_ptr theCompone
             qPrintable( myComponentName ) <<
             "it seems Save() was called from outside GUI" );
 
-    // - Get app rnv
+    // - Get app
     SalomeApp_Application* app = 
       dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
     if ( !app )
@@ -125,7 +126,7 @@ SALOMEDS::TMPFile* SalomeApp_Engine_i::Save (SALOMEDS::SComponent_ptr theCompone
       if ( !name.isEmpty() )
         names.push_back(name.toUtf8().data());
     }
-    SetListOfFiles( names );
+    SetListOfFiles( 0, names ); // 0 means persistence file
     manuallySaved = true;
   }
 
@@ -134,26 +135,30 @@ SALOMEDS::TMPFile* SalomeApp_Engine_i::Save (SALOMEDS::SComponent_ptr theCompone
 
   // 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( ListOfFiles());
+    SetListOfFiles(0, ListOfFiles()); // 0 means persistence file
 
   return aStreamFile._retn();
 }
@@ -182,33 +187,34 @@ CORBA::Boolean SalomeApp_Engine_i::Load (SALOMEDS::SComponent_ptr theComponent,
     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 = "<<
          qPrintable( myComponentName ) << ", this = " << this);
@@ -222,13 +228,15 @@ Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Boolean isPublished,
   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();    
@@ -237,8 +245,8 @@ Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Boolean isPublished,
   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() );
@@ -335,8 +343,8 @@ CORBA::ORB_var SalomeApp_Engine_i::orb()
 
   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;
@@ -358,10 +366,9 @@ PortableServer::POA_var SalomeApp_Engine_i::poa()
 /*!
   \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();
 }
 
 /*!