Salome HOME
Debug from CATHARE GUI team:
authorsan <san@opencascade.com>
Tue, 15 Nov 2005 15:21:47 +0000 (15:21 +0000)
committersan <san@opencascade.com>
Tue, 15 Nov 2005 15:21:47 +0000 (15:21 +0000)
1. Persistence problems in light configuration solved:
- from now on, temporary files extracted from the study file are not removed until the study is closed or renamed;
- "isSaved" status managed by the study, not by data models.

2. LightApp_Driver.h removed from LIB_MOC makefile variable to suppress warnings.

src/LightApp/LightApp.h
src/LightApp/LightApp_Driver.cxx
src/LightApp/LightApp_Driver.h
src/LightApp/LightApp_Study.cxx
src/LightApp/Makefile.in

index bfbe7e24a6d4c8b5b6602e1a2ce2b9e03c53f67f..1d0f5e196e15b9285b1f9c9ab520dbf66f5fc4e9 100644 (file)
@@ -1,28 +1,29 @@
-// File:      LightApp.h\r
-// Created:   June, 2005\r
-// Author:    OCC team\r
-// Copyright (C) CEA 2005\r
-\r
-\r
-// The following ifdef block is the standard way of creating macros which make exporting \r
-// from a DLL simpler. All files within this DLL are compiled with the LightApp_EXPORTS\r
-// symbol defined on the command line. this symbol should not be defined on any project\r
-// that uses this DLL. This way any other project whose source files include this file see \r
-// LightApp_API functions as being imported from a DLL, wheras this DLL sees symbols\r
-// defined with this macro as being exported.\r
-#ifdef WNT\r
-\r
-#ifdef LIGHTAPP_EXPORTS\r
-#define LIGHTAPP_EXPORT __declspec(dllexport)\r
-#else\r
-#define LIGHTAPP_EXPORT __declspec(dllimport)\r
-#endif\r
-\r
-#else\r
-#define LIGHTAPP_EXPORT\r
-#endif               //WNT\r
-\r
-#define APP_VERSION "0.1"\r
-\r
-#pragma warning ( disable:4251 )\r
-#pragma warning ( disable:4786 )\r
+// File:      LightApp.h
+// Created:   June, 2005
+// Author:    OCC team
+// Copyright (C) CEA 2005
+
+
+// The following ifdef block is the standard way of creating macros which make exporting 
+// from a DLL simpler. All files within this DLL are compiled with the LightApp_EXPORTS
+// symbol defined on the command line. this symbol should not be defined on any project
+// that uses this DLL. This way any other project whose source files include this file see 
+// LightApp_API functions as being imported from a DLL, wheras this DLL sees symbols
+// defined with this macro as being exported.
+#ifdef WNT
+
+#ifdef LIGHTAPP_EXPORTS
+#define LIGHTAPP_EXPORT __declspec(dllexport)
+#else
+#define LIGHTAPP_EXPORT __declspec(dllimport)
+#endif
+
+#pragma warning ( disable:4251 )
+#pragma warning ( disable:4786 )
+#pragma warning ( disable:4503 )
+
+#else
+#define LIGHTAPP_EXPORT
+#endif               //WNT
+
+#define APP_VERSION "0.1"
index a37f4f5d23361c8be7abf93e3159d0122533729f..a10d2be1e9cf34e4761278182402f6ddf7b17393 100644 (file)
-#include "LightApp_Driver.h"\r
-\r
-#include <TCollection_AsciiString.hxx> \r
-\r
-#include <OSD_Path.hxx>\r
-#include <OSD_File.hxx>\r
-#include <OSD_Directory.hxx>\r
-#include <OSD_Process.hxx>\r
-#include <OSD_Directory.hxx>\r
-#include <OSD_Protection.hxx>\r
-#include <OSD_SingleProtection.hxx>\r
-#include <OSD_FileIterator.hxx>\r
-\r
-#ifdef WIN32\r
-#include <time.h>\r
-#endif\r
-\r
-/*! Constructor.*/\r
-LightApp_Driver::LightApp_Driver()\r
-{\r
-}\r
\r
-/*! Destructor.*/\r
-LightApp_Driver::~LightApp_Driver()\r
-{\r
-}\r
-\r
-using namespace std;\r
-\r
-//================================================================\r
-// Function : SaveDatasInFile\r
-/*! Purpose  : save in file 'theFileName' datas from this driver*/\r
-//================================================================\r
-bool LightApp_Driver::SaveDatasInFile( const char* theFileName, bool isMultiFile )\r
-{\r
-  int aNbModules = 0;\r
-  std::map<std::string, ListOfFiles>::const_iterator it;\r
-  for (it = myMap.begin(); it != myMap.end(); ++it)\r
-    aNbModules++;\r
-\r
-  unsigned char** aBuffer = new unsigned char*[aNbModules]; \r
-  long*           aBufferSize = new long[aNbModules];\r
-  char**          aModuleName = new char*[aNbModules];\r
-\r
-  if(aBuffer == NULL || aBufferSize == NULL || aModuleName == NULL)\r
-    return false;\r
-\r
-  int aFileBufferSize = 4;  //4 bytes for a number of the modules that will be written to the stream;\r
-  int i = 0;\r
-  for (it = myMap.begin(); it != myMap.end(); ++it) {\r
-    aModuleName[i] = const_cast<char*>(it->first.c_str());//(it->first);\r
-    aFileBufferSize += 4;                                //Add 4 bytes: a length of the module name\r
-    aFileBufferSize += strlen(aModuleName[i])+1;\r
-    std::string aName(aModuleName[i]);\r
-    PutFilesToStream(aName, aBuffer[i], aBufferSize[i], isMultiFile);\r
-    aFileBufferSize += 8;                                //Add 8 bytes: a length of the buffer\r
-    aFileBufferSize += aBufferSize[i];\r
-    // Remove the files and tmp directory, created by the component storage procedure\r
-    if (!isMultiFile)\r
-      RemoveTemporaryFiles(aModuleName[i], true);\r
-    i++;\r
-  }\r
-  int n = i;\r
-\r
-  unsigned char* aFileBuffer = new unsigned char[aFileBufferSize];\r
-  if(aFileBuffer == NULL)\r
-    return false;\r
-\r
-  int aCurrentPos = 0;\r
-\r
-  //Initialize 4 bytes of the buffer by 0\r
-  memset(aFileBuffer, 0, 4); \r
-  //Copy the number of modules that will be written to the stream\r
-  memcpy(aFileBuffer, &aNbModules, ((sizeof(int) > 4) ? 4 : sizeof(int)));\r
-  aCurrentPos += 4;\r
-\r
-  int aBufferNameSize = 0;\r
-  for (i = 0; i < n; i++) {\r
-    aBufferNameSize = strlen(aModuleName[i])+1;\r
-    //Initialize 4 bytes of the buffer by 0\r
-    memset((aFileBuffer + aCurrentPos), 0, 4); \r
-    //Copy the length of the module name to the buffer\r
-    memcpy((aFileBuffer + aCurrentPos), &aBufferNameSize, ((sizeof(int) > 4) ? 4 : sizeof(int))); \r
-    aCurrentPos += 4;\r
-    //Copy the module name to the buffer\r
-    memcpy((aFileBuffer + aCurrentPos), aModuleName[i], aBufferNameSize);\r
-    aCurrentPos += aBufferNameSize;\r
-\r
-    //Initialize 8 bytes of the buffer by 0\r
-    memset((aFileBuffer + aCurrentPos), 0, 8);\r
-    //Copy the length of the module buffer to the buffer\r
-    memcpy((aFileBuffer + aCurrentPos), (aBufferSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long)));\r
-    aCurrentPos += 8;\r
-    //Copy the module buffer to the buffer\r
-    memcpy((aFileBuffer + aCurrentPos), aBuffer[i], aBufferSize[i]);\r
-    aCurrentPos += aBufferSize[i];\r
-  }\r
-\r
-  ofstream aFile(theFileName);\r
-  aFile.write((char*)aFileBuffer, aFileBufferSize); \r
-  aFile.close();    \r
-\r
-  delete[] aBuffer;\r
-  delete[] aBufferSize;\r
-  delete[] aModuleName;\r
-  delete[] aFileBuffer;\r
-  return true;\r
-}\r
-\r
-//=======================================================================\r
-// name    : ReaDatasFromFile\r
-/*! Purpose : filling current driver from file 'theFileName'*/\r
-//=======================================================================\r
-bool LightApp_Driver::ReadDatasFromFile( const char* theFileName, bool isMultiFile )\r
-{\r
-#ifdef WNT\r
-  ifstream aFile(theFileName, ios::binary);\r
-#else\r
-  ifstream aFile(theFileName);\r
-#endif  \r
-\r
-  aFile.seekg(0, ios::end);\r
-  int aFileBufferSize = aFile.tellg();\r
-  unsigned char* aFileBuffer = new unsigned char[aFileBufferSize];\r
-  aFile.seekg(0, ios::beg);\r
-  aFile.read((char*)aFileBuffer, aFileBufferSize);\r
-  aFile.close();\r
-\r
-  int aNbModules = 0;\r
-  //Copy the number of files in the stream\r
-  memcpy(&aNbModules, aFileBuffer, sizeof(int));\r
-  long aCurrentPos = 4;\r
-  int aModuleNameSize;\r
-\r
-  for (int i = 0; i < aNbModules; i++) {\r
-    //Put a length of the module name to aModuleNameSize\r
-    memcpy(&aModuleNameSize, (aFileBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); \r
-    aCurrentPos += 4;\r
-\r
-    char *aModuleName = new char[aModuleNameSize];\r
-    //Put a module name to aModuleName\r
-    memcpy(aModuleName, (aFileBuffer + aCurrentPos), aModuleNameSize); \r
-    aCurrentPos += aModuleNameSize;\r
-\r
-    //Put a length of the file buffer to aBufferSize\r
-    long aBufferSize;\r
-    memcpy(&aBufferSize, (aFileBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); \r
-    aCurrentPos += 8;\r
-    unsigned char *aBuffer = new unsigned char[aBufferSize];\r
\r
-    //Put a buffer for current module to aBuffer\r
-    memcpy(aBuffer, (aFileBuffer + aCurrentPos), aBufferSize); \r
-    aCurrentPos += aBufferSize;\r
-\r
-    // Put buffer to aListOfFiles and set to myMap\r
-    ListOfFiles aListOfFiles = PutStreamToFiles(aBuffer, aBufferSize, isMultiFile);\r
-    SetListOfFiles(aModuleName, aListOfFiles);\r
-\r
-    delete[] aModuleName;\r
-    delete[] aBuffer;\r
-  }\r
-  delete[] aFileBuffer;\r
-  return true;\r
-}\r
-\r
-//================================================================\r
-// Function : GetTmpDir\r
-/*! Purpose  : returns temp directory for path 'theURL'*/\r
-//================================================================\r
-std::string LightApp_Driver::GetTmpDir (const char* theURL, const bool  isMultiFile)\r
-{\r
-  std::string anURLDir = GetDirFromPath(theURL);\r
-  std::string aTmpDir = isMultiFile ? anURLDir : GetTmpDir();\r
-\r
-  return aTmpDir;\r
-}\r
-\r
-//================================================================\r
-// Function : GetListOfFiles\r
-/*! Purpose  : returns list of files for module with name 'theModuleName'*/\r
-//================================================================\r
-LightApp_Driver::ListOfFiles LightApp_Driver::GetListOfFiles( const char* theModuleName )\r
-{\r
-  ListOfFiles aListOfFiles;\r
-\r
-  std::string aName(theModuleName);\r
-  if (myMap.count(aName))\r
-    aListOfFiles = myMap[aName];\r
-\r
-    return aListOfFiles;\r
-}\r
-\r
-//================================================================\r
-// Function : SetListOfFiles\r
-/*! Purpose  : sets list of files for module with name 'theModuleName'*/\r
-//================================================================\r
-void LightApp_Driver::SetListOfFiles( const char* theModuleName, const ListOfFiles theListOfFiles )\r
-{\r
-  std::string aName (theModuleName);\r
-  myMap[aName] = theListOfFiles;\r
-}\r
-\r
-//============================================================================\r
-// function : PutFilesToStream\r
-/*! Purpose  : converts files which was created from module <theModuleName> into a byte sequence unsigned char*/\r
-//============================================================================\r
-void LightApp_Driver::PutFilesToStream( const std::string& theModuleName, unsigned char*& theBuffer,\r
-                                        long& theBufferSize, bool theNamesOnly )\r
-{\r
-  ListOfFiles aFiles = myMap[theModuleName];\r
-  // aFiles must contain temporary directory name in its first item\r
-  // and names of files (relatively the temporary directory) in the others\r
-\r
-  int i, aLength = aFiles.size() - 1;\r
-  if(aLength <= 0) {\r
-    theBufferSize = 0;\r
-    theBuffer = new unsigned char[theBufferSize];\r
-    return;\r
-  }\r
-  //Get a temporary directory for saved a file\r
-  TCollection_AsciiString aTmpDir(const_cast<char*>(aFiles[0].c_str()));\r
-\r
-  long aBufferSize = 0;\r
-  long aCurrentPos;\r
-  int aNbFiles = 0;\r
-  int* aFileNameSize= new int[aLength];\r
-  long* aFileSize= new long[aLength];\r
-\r
-  //Determine the required size of the buffer\r
-  TCollection_AsciiString aFileName;\r
-  for (i = 0; i < aLength; i++) {\r
-    char* aFName = const_cast<char*>(aFiles[i+1].c_str());\r
-    aFileName = aFName;\r
-    //Check if the file exists\r
-    if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero\r
-      TCollection_AsciiString aFullPath = aTmpDir + aFileName;   \r
-      OSD_Path anOSDPath(aFullPath);\r
-      OSD_File anOSDFile(anOSDPath);\r
-      if(!anOSDFile.Exists()) continue;\r
-#ifdef WNT\r
-      ifstream aFile(aFullPath.ToCString(), ios::binary);\r
-#else\r
-      ifstream aFile(aFullPath.ToCString());\r
-#endif\r
-      aFile.seekg(0, ios::end);\r
-      aFileSize[i] = aFile.tellg();\r
-      aBufferSize += aFileSize[i];              //Add a space to store the file\r
-    }\r
-    aFileNameSize[i] = strlen(aFName) + 1;\r
-    aBufferSize += aFileNameSize[i];          //Add a space to store the file name\r
-    aBufferSize += (theNamesOnly)?4:12;       //Add 4 bytes: a length of the file name,\r
-                                              //    8 bytes: length of the file itself\r
-    aNbFiles++;\r
-    delete[] aFName;\r
-  }\r
-\r
-  aBufferSize += 4;      //4 bytes for a number of the files that will be written to the stream;\r
-  theBuffer = new unsigned char[aBufferSize];  \r
-  if(theBuffer == NULL) {\r
-    theBufferSize = 0;\r
-    theBuffer = 0;\r
-    return;\r
-  }\r
-  //Initialize 4 bytes of the buffer by 0\r
-  memset(theBuffer, 0, 4); \r
-  //Copy the number of files that will be written to the stream\r
-  memcpy(theBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); \r
-\r
-  aCurrentPos = 4;\r
-\r
-  for(i = 0; i < aLength; i++) {\r
-    ifstream *aFile;\r
-    if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true\r
-      TCollection_AsciiString aName(const_cast<char*>(aFiles[i+1].c_str()));\r
-      TCollection_AsciiString aFullPath = aTmpDir + aName;\r
-      OSD_Path anOSDPath(aFullPath);\r
-      OSD_File anOSDFile(anOSDPath);\r
-      if(!anOSDFile.Exists()) continue;\r
-#ifdef WNT\r
-      aFile = new ifstream(aFullPath.ToCString(), ios::binary);\r
-#else\r
-      aFile = new ifstream(aFullPath.ToCString());\r
-#endif\r
-    }\r
-    //Initialize 4 bytes of the buffer by 0\r
-    memset((theBuffer + aCurrentPos), 0, 4); \r
-    //Copy the length of the file name to the buffer\r
-    memcpy((theBuffer + aCurrentPos), (aFileNameSize + i), ((sizeof(int) > 4) ? 4 : sizeof(int))); \r
-    aCurrentPos += 4;\r
-\r
-    //Copy the file name to the buffer\r
-    char* aFName = const_cast<char*>(aFiles[i+1].c_str());\r
-    memcpy((theBuffer + aCurrentPos), aFName, aFileNameSize[i]);\r
-    aCurrentPos += aFileNameSize[i];\r
-    \r
-    if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly\r
-      //Initialize 8 bytes of the buffer by 0\r
-      memset((theBuffer + aCurrentPos), 0, 8); \r
-      //Copy the length of the file to the buffer\r
-      memcpy((theBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long)));\r
-      aCurrentPos += 8;\r
-      \r
-      aFile->seekg(0, ios::beg);\r
-      aFile->read((char *)(theBuffer + aCurrentPos), aFileSize[i]);\r
-      aFile->close();\r
-      delete(aFile);\r
-      aCurrentPos += aFileSize[i];\r
-    }\r
-  }\r
-  delete[] aFileNameSize;\r
-  delete[] aFileSize;\r
-\r
-  theBufferSize = aBufferSize;\r
-}\r
-\r
-//============================================================================\r
-// function : PutStreamToFile\r
-/*! Purpose  : converts a byte sequence <theBuffer> to files and return list of them*/\r
-//============================================================================\r
-LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned char* theBuffer,\r
-                                                                const long theBufferSize, bool theNamesOnly )\r
-{\r
-  if(theBufferSize == 0 || theBuffer == 0)\r
-    return   ListOfFiles();\r
-\r
-  // Create a temporary directory for the component's data files\r
-  std::string aDir = GetTmpDir();\r
-\r
-  //Get a temporary directory for saving a file\r
-  TCollection_AsciiString aTmpDir(const_cast<char*>(aDir.c_str()));\r
-\r
-  long aFileSize, aCurrentPos = 4;\r
-  int i, aFileNameSize, aNbFiles = 0;\r
-\r
-  //Copy the number of files in the stream\r
-  memcpy(&aNbFiles, theBuffer, sizeof(int)); \r
-\r
-  const int n = aNbFiles + 1;\r
-  ListOfFiles aFiles(n);\r
-  aFiles[0] = aDir;\r
-\r
-  for(i = 0; i < aNbFiles; i++) {\r
-    //Put a length of the file name to aFileNameSize\r
-    memcpy(&aFileNameSize, (theBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); \r
-    aCurrentPos += 4;\r
-\r
-    char *aFileName = new char[aFileNameSize];\r
-    //Put a file name to aFileName\r
-    memcpy(aFileName, (theBuffer + aCurrentPos), aFileNameSize); \r
-    aCurrentPos += aFileNameSize;\r
\r
-    //Put a length of the file to aFileSize\r
-    if (!theNamesOnly) {\r
-      memcpy(&aFileSize, (theBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long)));\r
-      aCurrentPos += 8;    \r
-      \r
-      TCollection_AsciiString aFullPath = aTmpDir + aFileName;\r
-      ofstream aFile(aFullPath.ToCString());\r
-      aFile.write((char *)(theBuffer+aCurrentPos), aFileSize); \r
-      aFile.close();  \r
-      aCurrentPos += aFileSize;\r
-    }\r
-    std::string aStrFileName(aFileName);\r
-    aFiles[i+1] = aStrFileName;\r
-    delete[] aFileName;\r
-  }\r
-  return aFiles;\r
-}\r
-\r
-//============================================================================\r
-// function : RemoveTemporaryFiles\r
-/*! Purpose  : removes files which was created from module theModuleName if <IsDirDeleted> is true tmp directory is also deleted if it is empty*/\r
-//============================================================================\r
-void LightApp_Driver::RemoveTemporaryFiles( const char* theModuleName, const bool IsDirDeleted )\r
-{\r
-  std::string aModuleName(theModuleName);\r
-  ListOfFiles aFiles = myMap[aModuleName];\r
-  // aFiles must contain temporary directory name in its first item\r
-  // and names of files (relatively the temporary directory) in the others\r
-\r
-  int i, aLength = aFiles.size() - 1;\r
-  if(aLength <= 0) {\r
-    return;\r
-  }\r
-  //Get a temporary directory for saved a file\r
-  TCollection_AsciiString aDirName(const_cast<char*>(aFiles[0].c_str()));\r
-\r
-  for(i = 0; i < aLength; i++) {\r
-    TCollection_AsciiString aFile(aDirName);\r
-    aFile += const_cast<char*>(aFiles[i+1].c_str());\r
-    OSD_Path anOSDPath(aFile);\r
-    OSD_File anOSDFile(anOSDPath);\r
-    if(!anOSDFile.Exists()) continue;\r
-\r
-    OSD_Protection aProtection = anOSDFile.Protection();\r
-    aProtection.SetUser(OSD_RW);\r
-    anOSDFile.SetProtection(aProtection);\r
-\r
-    anOSDFile.Remove();\r
-  }\r
-\r
-  if(IsDirDeleted) {\r
-    OSD_Path aPath(aDirName);\r
-    OSD_Directory aDir(aPath);\r
-    OSD_FileIterator anIterator(aPath, '*');\r
-\r
-    if(aDir.Exists() && !anIterator.More()) aDir.Remove();\r
-  }\r
-}\r
-\r
-//============================================================================\r
-// function : ClearDriverContents\r
-/*! Purpose  : clear map of list files*/ \r
-//============================================================================ \r
-void LightApp_Driver::ClearDriverContents()\r
-{\r
-  myMap.clear();\r
-}\r
-\r
-//============================================================================\r
-// function : GetTempDir\r
-/*! Purpose  : return a temp directory to store created files like "/tmp/sub_dir/" */\r
-//============================================================================ \r
-std::string LightApp_Driver::GetTmpDir()\r
-{\r
-  //Find a temporary directory to store a file\r
-  TCollection_AsciiString aTmpDir;\r
-\r
-  char *Tmp_dir = getenv("SALOME_TMP_DIR");\r
-  if(Tmp_dir != NULL) {\r
-    aTmpDir = TCollection_AsciiString(Tmp_dir);\r
-#ifdef WIN32\r
-    if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\';\r
-#else\r
-    if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/';\r
-#endif      \r
-  }\r
-  else {\r
-#ifdef WIN32\r
-    aTmpDir = TCollection_AsciiString("C:\\");\r
-#else\r
-    aTmpDir = TCollection_AsciiString("/tmp/");\r
-#endif\r
-  }\r
-\r
-  srand((unsigned int)time(NULL));\r
-  int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory\r
-  TCollection_AsciiString aSubDir(aRND);\r
-  if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876");\r
-\r
-  aTmpDir += aSubDir; //Get RND sub directory\r
-\r
-#ifdef WIN32\r
-  if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\';\r
-#else\r
-  if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/';\r
-#endif\r
-\r
-  OSD_Path aPath(aTmpDir);\r
-  OSD_Directory aDir(aPath);\r
-\r
-  for(aRND = 0; aDir.Exists(); aRND++) {\r
-    aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND));  //Build a unique directory name\r
-    aPath = OSD_Path(aTmpDir);\r
-    aDir = OSD_Directory(aPath);\r
-  }\r
-\r
-  OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX);\r
-  aDir.Build(aProtection);\r
-\r
-  return aTmpDir.ToCString();\r
-}\r
-\r
-//============================================================================\r
-// function : GetDirFromPath\r
-/*! Purpose  : returns the dir by the path*/\r
-//============================================================================\r
-std::string LightApp_Driver::GetDirFromPath( const std::string& thePath ) {\r
-  if(thePath == "")\r
-    return "";\r
-  OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast<char*>(thePath.c_str())));\r
-  TCollection_AsciiString aDirString(aPath.Trek());\r
-  aDirString.ChangeAll('|','/');\r
-  return aDirString.ToCString();\r
-}\r
-\r
+#include "LightApp_Driver.h"
+
+#include <TCollection_AsciiString.hxx> 
+
+#include <OSD_Path.hxx>
+#include <OSD_File.hxx>
+#include <OSD_Directory.hxx>
+#include <OSD_Process.hxx>
+#include <OSD_Directory.hxx>
+#include <OSD_Protection.hxx>
+#include <OSD_SingleProtection.hxx>
+#include <OSD_FileIterator.hxx>
+
+#include <qfileinfo.h>
+#include <qdir.h>
+
+#ifdef WIN32
+#include <time.h>
+#endif
+
+/*! Constructor.*/
+LightApp_Driver::LightApp_Driver()
+{
+}
+/*! Destructor.*/
+LightApp_Driver::~LightApp_Driver()
+{
+}
+
+using namespace std;
+
+//================================================================
+// Function : SaveDatasInFile
+/*! Purpose  : save in file 'theFileName' datas from this driver*/
+//================================================================
+bool LightApp_Driver::SaveDatasInFile( const char* theFileName, bool isMultiFile )
+{
+  int aNbModules = 0;
+  std::map<std::string, ListOfFiles>::const_iterator it;
+  for (it = myMap.begin(); it != myMap.end(); ++it)
+    aNbModules++;
+
+  unsigned char** aBuffer = new unsigned char*[aNbModules]; 
+  long*           aBufferSize = new long[aNbModules];
+  char**          aModuleName = new char*[aNbModules];
+
+  if(aBuffer == NULL || aBufferSize == NULL || aModuleName == NULL)
+    return false;
+
+  int aFileBufferSize = 4;  //4 bytes for a number of the modules that will be written to the stream;
+  int i = 0;
+  for (it = myMap.begin(); it != myMap.end(); ++it) {
+    aModuleName[i] = const_cast<char*>(it->first.c_str());//(it->first);
+    aFileBufferSize += 4;                                //Add 4 bytes: a length of the module name
+    aFileBufferSize += strlen(aModuleName[i])+1;
+    std::string aName(aModuleName[i]);
+    PutFilesToStream(aName, aBuffer[i], aBufferSize[i], isMultiFile);
+    aFileBufferSize += 8;                                //Add 8 bytes: a length of the buffer
+    aFileBufferSize += aBufferSize[i];
+    i++;
+  }
+  int n = i;
+
+  unsigned char* aFileBuffer = new unsigned char[aFileBufferSize];
+  if(aFileBuffer == NULL)
+    return false;
+
+  myTmpDir = QDir::convertSeparators( QFileInfo( theFileName ).dirPath( true ) + "/" ).latin1() ;
+
+  int aCurrentPos = 0;
+
+  //Initialize 4 bytes of the buffer by 0
+  memset(aFileBuffer, 0, 4); 
+  //Copy the number of modules that will be written to the stream
+  memcpy(aFileBuffer, &aNbModules, ((sizeof(int) > 4) ? 4 : sizeof(int)));
+  aCurrentPos += 4;
+
+  int aBufferNameSize = 0;
+  for (i = 0; i < n; i++) {
+    aBufferNameSize = strlen(aModuleName[i])+1;
+    //Initialize 4 bytes of the buffer by 0
+    memset((aFileBuffer + aCurrentPos), 0, 4); 
+    //Copy the length of the module name to the buffer
+    memcpy((aFileBuffer + aCurrentPos), &aBufferNameSize, ((sizeof(int) > 4) ? 4 : sizeof(int))); 
+    aCurrentPos += 4;
+    //Copy the module name to the buffer
+    memcpy((aFileBuffer + aCurrentPos), aModuleName[i], aBufferNameSize);
+    aCurrentPos += aBufferNameSize;
+
+    //Initialize 8 bytes of the buffer by 0
+    memset((aFileBuffer + aCurrentPos), 0, 8);
+    //Copy the length of the module buffer to the buffer
+    memcpy((aFileBuffer + aCurrentPos), (aBufferSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long)));
+    aCurrentPos += 8;
+    //Copy the module buffer to the buffer
+    memcpy((aFileBuffer + aCurrentPos), aBuffer[i], aBufferSize[i]);
+    aCurrentPos += aBufferSize[i];
+  }
+
+#ifdef WNT  
+  ofstream aFile(theFileName, ios::out | ios::binary);
+#else
+  ofstream aFile(theFileName);
+#endif
+  aFile.write((char*)aFileBuffer, aFileBufferSize); 
+  aFile.close();    
+
+  delete[] aBuffer;
+  delete[] aBufferSize;
+  delete[] aModuleName;
+  delete[] aFileBuffer;
+
+  return true;
+}
+
+//=======================================================================
+// name    : ReaDatasFromFile
+/*! Purpose : filling current driver from file 'theFileName'*/
+//=======================================================================
+bool LightApp_Driver::ReadDatasFromFile( const char* theFileName, bool isMultiFile )
+{
+#ifdef WNT
+  ifstream aFile(theFileName, ios::binary);
+#else
+  ifstream aFile(theFileName);
+#endif  
+
+  myTmpDir = QDir::convertSeparators( QFileInfo( theFileName ).dirPath( true ) + "/" ).latin1() ;
+
+  aFile.seekg(0, ios::end);
+  int aFileBufferSize = aFile.tellg();
+  unsigned char* aFileBuffer = new unsigned char[aFileBufferSize];
+  aFile.seekg(0, ios::beg);
+  aFile.read((char*)aFileBuffer, aFileBufferSize);
+  aFile.close();
+
+  int aNbModules = 0;
+  //Copy the number of files in the stream
+  memcpy(&aNbModules, aFileBuffer, sizeof(int));
+  long aCurrentPos = 4;
+  int aModuleNameSize;
+
+  for (int i = 0; i < aNbModules; i++) {
+    //Put a length of the module name to aModuleNameSize
+    memcpy(&aModuleNameSize, (aFileBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); 
+    aCurrentPos += 4;
+
+    char *aModuleName = new char[aModuleNameSize];
+    //Put a module name to aModuleName
+    memcpy(aModuleName, (aFileBuffer + aCurrentPos), aModuleNameSize); 
+    aCurrentPos += aModuleNameSize;
+
+    //Put a length of the file buffer to aBufferSize
+    long aBufferSize;
+    memcpy(&aBufferSize, (aFileBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); 
+    aCurrentPos += 8;
+    unsigned char *aBuffer = new unsigned char[aBufferSize];
+    //Put a buffer for current module to aBuffer
+    memcpy(aBuffer, (aFileBuffer + aCurrentPos), aBufferSize); 
+    aCurrentPos += aBufferSize;
+
+    // Put buffer to aListOfFiles and set to myMap
+    ListOfFiles aListOfFiles = PutStreamToFiles(aBuffer, aBufferSize, isMultiFile);
+    SetListOfFiles(aModuleName, aListOfFiles);
+
+    delete[] aModuleName;
+    delete[] aBuffer;
+  }
+
+  delete[] aFileBuffer;
+  
+  return true;
+}
+
+//================================================================
+// Function : GetTmpDir
+/*! Purpose  : returns temp directory for path 'theURL'*/
+//================================================================
+std::string LightApp_Driver::GetTmpDir (const char* theURL, const bool  isMultiFile)
+{
+  std::string anURLDir = GetDirFromPath(theURL);
+  std::string aTmpDir = isMultiFile ? anURLDir : GetTmpDir();
+
+  return aTmpDir;
+}
+
+//================================================================
+// Function : GetListOfFiles
+/*! Purpose  : returns list of files for module with name 'theModuleName'*/
+//================================================================
+LightApp_Driver::ListOfFiles LightApp_Driver::GetListOfFiles( const char* theModuleName )
+{
+  ListOfFiles aListOfFiles;
+
+  std::string aName(theModuleName);
+  if (myMap.count(aName))
+    aListOfFiles = myMap[aName];
+
+    return aListOfFiles;
+}
+
+//================================================================
+// Function : SetListOfFiles
+/*! Purpose  : sets list of files for module with name 'theModuleName'*/
+//================================================================
+void LightApp_Driver::SetListOfFiles( const char* theModuleName, const ListOfFiles theListOfFiles )
+{
+  std::string aName (theModuleName);
+  myMap[aName] = theListOfFiles;
+}
+
+//============================================================================
+// function : PutFilesToStream
+/*! Purpose  : converts files which was created from module <theModuleName> into a byte sequence unsigned char*/
+//============================================================================
+void LightApp_Driver::PutFilesToStream( const std::string& theModuleName, unsigned char*& theBuffer,
+                                        long& theBufferSize, bool theNamesOnly )
+{
+  ListOfFiles aFiles = myMap[theModuleName];
+  // aFiles must contain temporary directory name in its first item
+  // and names of files (relatively the temporary directory) in the others
+
+  int i, aLength = aFiles.size() - 1;
+  if(aLength <= 0) {
+    theBufferSize = 0;
+    theBuffer = new unsigned char[theBufferSize];
+    return;
+  }
+  //Get a temporary directory for saved a file
+  TCollection_AsciiString aTmpDir(const_cast<char*>(aFiles[0].c_str()));
+
+  long aBufferSize = 0;
+  long aCurrentPos;
+  int aNbFiles = 0;
+  int* aFileNameSize= new int[aLength];
+  long* aFileSize= new long[aLength];
+
+  //Determine the required size of the buffer
+  TCollection_AsciiString aFileName;
+  for (i = 0; i < aLength; i++) {
+    char* aFName = const_cast<char*>(aFiles[i+1].c_str());
+    aFileName = aFName;
+    //Check if the file exists
+    if (!theNamesOnly) { // mpv 15.01.2003: if only file names must be stroed, then size of files is zero
+      TCollection_AsciiString aFullPath = aTmpDir + aFileName;   
+      OSD_Path anOSDPath(aFullPath);
+      OSD_File anOSDFile(anOSDPath);
+      if(!anOSDFile.Exists()) continue;
+#ifdef WNT
+      ifstream aFile(aFullPath.ToCString(), ios::binary);
+#else
+      ifstream aFile(aFullPath.ToCString());
+#endif
+      aFile.seekg(0, ios::end);
+      aFileSize[i] = aFile.tellg();
+      aBufferSize += aFileSize[i];              //Add a space to store the file
+    }
+    aFileNameSize[i] = strlen(aFName) + 1;
+    aBufferSize += aFileNameSize[i];          //Add a space to store the file name
+    aBufferSize += (theNamesOnly)?4:12;       //Add 4 bytes: a length of the file name,
+                                              //    8 bytes: length of the file itself
+    aNbFiles++;
+  }
+
+  aBufferSize += 4;      //4 bytes for a number of the files that will be written to the stream;
+  theBuffer = new unsigned char[aBufferSize];  
+  if(theBuffer == NULL) {
+    theBufferSize = 0;
+    theBuffer = 0;
+    return;
+  }
+  //Initialize 4 bytes of the buffer by 0
+  memset(theBuffer, 0, 4); 
+  //Copy the number of files that will be written to the stream
+  memcpy(theBuffer, &aNbFiles, ((sizeof(int) > 4) ? 4 : sizeof(int))); 
+
+  aCurrentPos = 4;
+
+  for(i = 0; i < aLength; i++) {
+    ifstream *aFile;
+    if (!theNamesOnly) { // mpv 15.01.2003: we don't open any file if theNamesOnly = true
+      TCollection_AsciiString aName(const_cast<char*>(aFiles[i+1].c_str()));
+      TCollection_AsciiString aFullPath = aTmpDir + aName;
+      OSD_Path anOSDPath(aFullPath);
+      OSD_File anOSDFile(anOSDPath);
+      if(!anOSDFile.Exists()) continue;
+#ifdef WNT
+      aFile = new ifstream(aFullPath.ToCString(), ios::binary);
+#else
+      aFile = new ifstream(aFullPath.ToCString());
+#endif
+    }
+    //Initialize 4 bytes of the buffer by 0
+    memset((theBuffer + aCurrentPos), 0, 4); 
+    //Copy the length of the file name to the buffer
+    memcpy((theBuffer + aCurrentPos), (aFileNameSize + i), ((sizeof(int) > 4) ? 4 : sizeof(int))); 
+    aCurrentPos += 4;
+
+    //Copy the file name to the buffer
+    char* aFName = const_cast<char*>(aFiles[i+1].c_str());
+    memcpy((theBuffer + aCurrentPos), aFName, aFileNameSize[i]);
+    aCurrentPos += aFileNameSize[i];
+    
+    if (!theNamesOnly) { // mpv 15.01.2003: we don't copy file content to the buffer if !theNamesOnly
+      //Initialize 8 bytes of the buffer by 0
+      memset((theBuffer + aCurrentPos), 0, 8); 
+      //Copy the length of the file to the buffer
+      memcpy((theBuffer + aCurrentPos), (aFileSize + i), ((sizeof(long) > 8) ? 8 : sizeof(long)));
+      aCurrentPos += 8;
+      
+      aFile->seekg(0, ios::beg);
+      aFile->read((char *)(theBuffer + aCurrentPos), aFileSize[i]);
+      aFile->close();
+      delete(aFile);
+      aCurrentPos += aFileSize[i];
+    }
+  }
+  delete[] aFileNameSize;
+  delete[] aFileSize;
+
+  theBufferSize = aBufferSize;
+}
+
+//============================================================================
+// function : PutStreamToFile
+/*! Purpose  : converts a byte sequence <theBuffer> to files and return list of them*/
+//============================================================================
+LightApp_Driver::ListOfFiles LightApp_Driver::PutStreamToFiles( const unsigned char* theBuffer,
+                                                                const long theBufferSize, bool theNamesOnly )
+{
+  if(theBufferSize == 0 || theBuffer == 0)
+    return   ListOfFiles();
+
+  // Create a temporary directory for the component's data files
+  std::string aDir = GetTmpDir();
+
+  //Get a temporary directory for saving a file
+  TCollection_AsciiString aTmpDir(const_cast<char*>(aDir.c_str()));
+
+  long aFileSize, aCurrentPos = 4;
+  int i, aFileNameSize, aNbFiles = 0;
+
+  //Copy the number of files in the stream
+  memcpy(&aNbFiles, theBuffer, sizeof(int)); 
+
+  const int n = aNbFiles + 1;
+  ListOfFiles aFiles(n);
+  aFiles[0] = aDir;
+
+  for(i = 0; i < aNbFiles; i++) {
+    //Put a length of the file name to aFileNameSize
+    memcpy(&aFileNameSize, (theBuffer + aCurrentPos), ((sizeof(int) > 4) ? 4 : sizeof(int))); 
+    aCurrentPos += 4;
+
+    char *aFileName = new char[aFileNameSize];
+    //Put a file name to aFileName
+    memcpy(aFileName, (theBuffer + aCurrentPos), aFileNameSize); 
+    aCurrentPos += aFileNameSize;
+    //Put a length of the file to aFileSize
+    if (!theNamesOnly) {
+      memcpy(&aFileSize, (theBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long)));
+      aCurrentPos += 8;    
+      
+      TCollection_AsciiString aFullPath = aTmpDir + aFileName;
+      
+#ifdef WNT  
+  ofstream aFile(aFullPath.ToCString(), ios::out | ios::binary);
+#else
+  ofstream aFile(aFullPath.ToCString());
+#endif
+
+      aFile.write((char *)(theBuffer+aCurrentPos), aFileSize); 
+      aFile.close();  
+      aCurrentPos += aFileSize;
+    }
+    std::string aStrFileName(aFileName);
+    aFiles[i+1] = aStrFileName;
+    delete[] aFileName;
+  }
+  return aFiles;
+}
+
+//============================================================================
+// function : RemoveFiles
+/*! Purpose  : Remove files. First item in <theFiles> is a directory with slash at the end.
+               Other items are names of files. If <IsDirDeleted> is true,
+              then the directory is also deleted.
+*/
+//============================================================================
+void LightApp_Driver::RemoveFiles( const ListOfFiles& theFiles, const bool IsDirDeleted)
+{
+  int i, aLength = theFiles.size() - 1;
+  if(aLength <= 0) {
+    return;
+  }
+  //Get a temporary directory for saved a file
+  TCollection_AsciiString aDirName(const_cast<char*>(theFiles[0].c_str()));
+
+  for(i = 0; i < aLength; i++) {
+    TCollection_AsciiString aFile(aDirName);
+    aFile += const_cast<char*>(theFiles[i+1].c_str());
+    OSD_Path anOSDPath(aFile);
+    OSD_File anOSDFile(anOSDPath);
+    if(!anOSDFile.Exists()) continue;
+
+    anOSDFile.Remove();
+  }
+
+  if(IsDirDeleted) {
+    OSD_Path aPath(aDirName);
+    OSD_Directory aDir(aPath);
+    OSD_FileIterator anIterator(aPath, '*');
+
+    if(aDir.Exists() && !anIterator.More()) aDir.Remove();
+  }
+}
+
+//============================================================================
+// function : RemoveTemporaryFiles
+/*! Purpose  : removes files which was created from module theModuleName if 
+               <IsDirDeleted> is true tmp directory is also deleted if it is empty*/
+//============================================================================
+void LightApp_Driver::RemoveTemporaryFiles( const char* theModuleName, const bool IsDirDeleted )
+{
+  std::string aModuleName(theModuleName);
+  ListOfFiles aFiles = myMap[aModuleName];
+  // aFiles must contain temporary directory name in its first item
+  // and names of files (relatively the temporary directory) in the others
+  RemoveFiles( aFiles, IsDirDeleted );
+
+}
+
+//============================================================================
+// function : ClearDriverContents
+/*! Purpose  : clear map of list files*/ 
+//============================================================================ 
+void LightApp_Driver::ClearDriverContents()
+{
+  std::map<std::string, ListOfFiles>::iterator it;
+  for ( it = myMap.begin(); it != myMap.end(); ++it ) 
+  {
+    const char* aModuleName = const_cast<char*>(it->first.c_str());
+    RemoveTemporaryFiles( aModuleName, false );
+  }
+  myMap.clear();
+}
+
+//============================================================================
+// function : GetTempDir
+/*! Purpose  : return a temp directory to store created files like "/tmp/sub_dir/" */
+//============================================================================ 
+std::string LightApp_Driver::GetTmpDir()
+{
+  if ( myTmpDir.length() != 0 )
+    return myTmpDir;
+
+  //Find a temporary directory to store a file
+  TCollection_AsciiString aTmpDir;
+
+  char *Tmp_dir = getenv("SALOME_TMP_DIR");
+  if ( !Tmp_dir )
+    Tmp_dir = getenv ( "TEMP" );
+  if ( !Tmp_dir )
+    Tmp_dir = getenv ( "TMP" );
+  if ( Tmp_dir ) 
+  {
+    aTmpDir = TCollection_AsciiString(Tmp_dir);
+#ifdef WIN32
+    if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\';
+#else
+    if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/';
+#endif      
+  }
+  else 
+  {
+#ifdef WIN32
+    aTmpDir = TCollection_AsciiString("C:\\");
+#else
+    aTmpDir = TCollection_AsciiString("/tmp/");
+#endif
+  }
+
+  srand((unsigned int)time(NULL));
+  int aRND = 999 + (int)(100000.0*rand()/(RAND_MAX+1.0)); //Get a random number to present a name of a sub directory
+  TCollection_AsciiString aSubDir(aRND);
+  if(aSubDir.Length() <= 1) aSubDir = TCollection_AsciiString("123409876");
+
+  aTmpDir += aSubDir; //Get RND sub directory
+
+#ifdef WIN32
+  if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\';
+#else
+  if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/';
+#endif
+
+  OSD_Path aPath(aTmpDir);
+  OSD_Directory aDir(aPath);
+
+  for(aRND = 0; aDir.Exists(); aRND++) {
+    aTmpDir.Insert((aTmpDir.Length() - 1), TCollection_AsciiString(aRND));  //Build a unique directory name
+    aPath = OSD_Path(aTmpDir);
+    aDir = OSD_Directory(aPath);
+  }
+
+  myTmpDir = aTmpDir.ToCString();
+
+  return aTmpDir.ToCString();
+}
+
+//============================================================================
+// function : GetDirFromPath
+/*! Purpose  : returns the dir by the path*/
+//============================================================================
+std::string LightApp_Driver::GetDirFromPath( const std::string& thePath ) {
+  if(thePath == "")
+    return "";
+  OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast<char*>(thePath.c_str())));
+  TCollection_AsciiString aDirString(aPath.Trek());
+  aDirString.ChangeAll('|','/');
+  return aDirString.ToCString();
+}
+
index eb26e56331d6e657a8770b6a99732a99401289ea..1723a1a3d7c54a595ee90c6c905369b48770ebe5 100644 (file)
@@ -1,49 +1,51 @@
-#ifndef LIGHTAPP_DRIVER_H\r
-#define LIGHTAPP_DRIVER_H\r
-\r
-#include <LightApp.h>\r
-\r
-#include "string"\r
-#include "vector"\r
-#include "map"\r
-\r
-#ifdef WIN32\r
-#pragma warning( disable:4251 )\r
-#endif\r
-\r
-/*!Description : Driver can save to file and read from file list of files for light modules*/\r
-\r
-class LIGHTAPP_EXPORT LightApp_Driver\r
-{\r
-public:\r
-  LightApp_Driver();\r
-  virtual ~LightApp_Driver();\r
-\r
-\r
-  typedef std::vector<std::string> ListOfFiles;\r
-\r
-  bool                SaveDatasInFile   (const char* theFileName, bool isMultiFile );\r
-  bool                ReadDatasFromFile (const char* theFileName,  bool isMultiFile );\r
-  virtual std::string GetTmpDir      (const char* theURL, const bool  isMultiFile);\r
-\r
-  ListOfFiles         GetListOfFiles (const char* theModuleName);\r
-  virtual void        SetListOfFiles (const char* theModuleName, const ListOfFiles theListOfFiles);\r
-  virtual void        RemoveTemporaryFiles(const char* theModuleName, const bool IsDirDeleted);\r
-\r
-  virtual void        ClearDriverContents();\r
-\r
-private:\r
-  void                PutFilesToStream(const std::string& theModuleName, unsigned char*& theBuffer,\r
-                                       long& theBufferSize, bool theNamesOnly = false);\r
-  ListOfFiles         PutStreamToFiles(const unsigned char* theBuffer,\r
-                                       const long theBufferSize, bool theNamesOnly = false);\r
-\r
-  std::string GetTmpDir();\r
-  std::string GetDirFromPath(const std::string& thePath);\r
-\r
-private:\r
-  typedef std::map<std::string, ListOfFiles> MapOfListOfFiles;\r
-  MapOfListOfFiles                           myMap;\r
-};\r
-\r
-#endif \r
+#ifndef LIGHTAPP_DRIVER_H
+#define LIGHTAPP_DRIVER_H
+
+#include <LightApp.h>
+
+#include "string"
+#include "vector"
+#include "map"
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+/*!Description : Driver can save to file and read from file list of files for light modules*/
+
+class LIGHTAPP_EXPORT LightApp_Driver
+{
+public:
+  LightApp_Driver();
+  virtual ~LightApp_Driver();
+
+
+  typedef std::vector<std::string> ListOfFiles;
+
+  bool                SaveDatasInFile   (const char* theFileName, bool isMultiFile );
+  bool                ReadDatasFromFile (const char* theFileName,  bool isMultiFile );
+  virtual std::string GetTmpDir      (const char* theURL, const bool  isMultiFile);
+
+  ListOfFiles         GetListOfFiles (const char* theModuleName);
+  virtual void        SetListOfFiles (const char* theModuleName, const ListOfFiles theListOfFiles);
+  virtual void        RemoveTemporaryFiles(const char* theModuleName, const bool IsDirDeleted);
+  void                RemoveFiles( const ListOfFiles& theFiles, const bool IsDirDeleted);
+
+  virtual void        ClearDriverContents();
+
+private:
+  void                PutFilesToStream(const std::string& theModuleName, unsigned char*& theBuffer,
+                                       long& theBufferSize, bool theNamesOnly = false);
+  ListOfFiles         PutStreamToFiles(const unsigned char* theBuffer,
+                                       const long theBufferSize, bool theNamesOnly = false);
+
+  std::string GetTmpDir();
+  std::string GetDirFromPath(const std::string& thePath);
+
+private:
+  typedef std::map<std::string, ListOfFiles> MapOfListOfFiles;
+  MapOfListOfFiles                           myMap;
+  std::string                                myTmpDir;
+};
+
+#endif 
index e575e306d9f1c069b66c3c889e094810a6ad2e71..f4c99a0b4ea1661eb36a4611a8039ec8e3bc663b 100644 (file)
@@ -23,6 +23,7 @@
 #include <OSD_SingleProtection.hxx>
 #include <OSD_FileIterator.hxx>
 
+#include <set>
 #include <qstring.h>
 
 /*!
@@ -121,17 +122,52 @@ bool LightApp_Study::loadDocument( const QString& theStudyName )
 //=======================================================================
 bool LightApp_Study::saveDocumentAs( const QString& theFileName )
 {
-  ModelList list; dataModels( list );
+  SUIT_ResourceMgr* resMgr = application()->resourceMgr();
+  if( !resMgr )
+    return false;
+
+  ModelList list; 
+  dataModels( list );
 
   LightApp_DataModel* aModel = (LightApp_DataModel*)list.first();
 
-  myDriver->ClearDriverContents();
   QStringList listOfFiles;
-  for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) {
+  bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
+  for ( ; aModel; aModel = (LightApp_DataModel*)list.next() ) 
+  {
+    std::vector<std::string> anOldList = myDriver->GetListOfFiles( aModel->module()->name() );
     listOfFiles.clear();
     aModel->saveAs( theFileName, this, listOfFiles );
     if ( !listOfFiles.isEmpty() )
       saveModuleData(aModel->module()->name(), listOfFiles);
+
+    // Remove files if necessary. File is removed if it was in the list of files before
+    // saving and it is not contained in the list after saving. This provides correct 
+    // removing previous temporary files. These files are not removed before saving
+    // because they may be required for it.
+
+    std::vector<std::string> aNewList = myDriver->GetListOfFiles( aModel->module()->name() );
+    
+    std::set<std::string> aNewNames;
+    std::set<std::string> toRemove;
+    int i, n;
+    for( i = 0, n = aNewList.size(); i < n; i++ )
+      aNewNames.insert( aNewList[ i ] );
+    for( i = 0, n = anOldList.size(); i < n; i++ )
+    {
+      if ( i == 0 ) // directory is always inserted in list
+        toRemove.insert( anOldList[ i ] );
+      else if ( aNewNames.find( anOldList[ i ] ) == aNewNames.end() )
+        toRemove.insert( anOldList[ i ] );
+    }
+        
+    std::vector<std::string> toRemoveList( toRemove.size() );
+    std::set<std::string>::iterator anIter;
+    for( anIter = toRemove.begin(), i = 0; anIter != toRemove.end(); ++anIter, ++i )
+      toRemoveList[ i ] = *anIter;
+
+    
+    myDriver->RemoveFiles( toRemoveList, isMultiFile );
   }
 
   bool res = saveStudyData(theFileName);
@@ -175,6 +211,11 @@ bool LightApp_Study::saveDocument()
 //================================================================
 void LightApp_Study::closeDocument(bool permanently)
 {
+  // Remove temporary files
+  ModelList aList;
+  dataModels( aList );
+  myDriver->ClearDriverContents();
+
   // Inform everybody that this study is going to close when it's most safe to,
   // i.e. in the very beginning
   emit closed( this );
@@ -248,16 +289,7 @@ bool LightApp_Study::isModified() const
 //================================================================
 bool LightApp_Study::isSaved() const
 {
-  bool isAllSaved = CAM_Study::isSaved();
-  ModelList list; dataModels( list );
-
-  LightApp_DataModel* aModel = 0;
-  for ( QPtrListIterator<CAM_DataModel> it( list ); it.current() && isAllSaved; ++it ){
-    aModel = dynamic_cast<LightApp_DataModel*>( it.current() );
-    if ( aModel )
-      isAllSaved = aModel->isSaved();
-  }
-  return isAllSaved; 
+  return CAM_Study::isSaved();
 }
 
 //=======================================================================
@@ -319,11 +351,6 @@ bool LightApp_Study::saveStudyData( const QString& theFileName )
   bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
 
   bool aRes = myDriver->SaveDatasInFile(theFileName.latin1(), isMultiFile);
-  // clear map
-  std::vector<std::string> aList(0);
-  for ( ModelListIterator it( list ); it.current(); ++it )
-    myDriver->SetListOfFiles(it.current()->module()->name(), aList);
-
   return aRes;
 }
 
@@ -354,12 +381,7 @@ bool LightApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm
   QStringList listOfFiles;
   openModuleData(dm->module()->name(), listOfFiles);
   if (dm && dm->open(studyName, this, listOfFiles)) {
-    // Remove the files and temporary directory, created
-    // for this module by LightApp_Driver::OpenStudyData()
-    bool isMultiFile = false; // TODO: decide, how to access this parameter
-    RemoveTemporaryFiles( dm->module()->name(), isMultiFile );
-
-     // Something has been read -> create data model tree
+    // Something has been read -> create data model tree
     LightApp_DataModel* aDM = dynamic_cast<LightApp_DataModel*>( dm );
     if ( aDM )
       aDM->update(NULL, this);
@@ -425,3 +447,4 @@ void LightApp_Study::components( QStringList& comp ) const
       comp.append( obj->entry() );
   }
 }
+
index 2c0a57df87967b3e21971fc1b090ff3a0828357e..092b071f780a6b4e74d8708cbf2668685cd1d044 100755 (executable)
@@ -80,7 +80,6 @@ LIB_MOC = LightApp_AboutDlg.h \
          LightApp_Application.h \
          LightApp_DataModel.h \
          LightApp_Dialog.h \
-         LightApp_Driver.h \
          LightApp_GLSelector.h \
          LightApp_OBSelector.h \
          LightApp_OCCSelector.h \