From: srn Date: Wed, 31 Oct 2007 09:06:39 +0000 (+0000) Subject: New implementation of TOOLSDS package based on DF data structure instead of OCAF X-Git-Tag: V4_1_0a3~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f24a57c5807c91b1829d6310e9d2908537a294d0;p=modules%2Fkernel.git New implementation of TOOLSDS package based on DF data structure instead of OCAF --- diff --git a/src/TOOLSDS/Makefile.am b/src/TOOLSDS/Makefile.am index e015ae928..a041e283f 100644 --- a/src/TOOLSDS/Makefile.am +++ b/src/TOOLSDS/Makefile.am @@ -40,15 +40,13 @@ COMMON_CPPFLAGS=\ -I$(top_builddir)/salome_adm/unix \ -I$(top_builddir)/idl \ @CORBA_CXXFLAGS@ @CORBA_INCLUDES@ \ - @CAS_CPPFLAGS@ @CAS_CXXFLAGS@ \ @HDF5_INCLUDES@ \ @BOOST_CPPFLAGS@ # This local variable defines the list of dependant libraries common to all target in this package. COMMON_LIBS =\ ../Utils/libOpUtil.la \ - $(top_builddir)/idl/libSalomeIDLKernel.la\ - @CAS_KERNEL@ + $(top_builddir)/idl/libSalomeIDLKernel.la # # =============================================================== diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index e67c96a5e..bbb4192d3 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -28,24 +28,18 @@ #include "utilities.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include - #ifndef WNT -#include +#include +#include +#include #include #include -#include +#include #else +#include +#include #endif + #include #include @@ -53,6 +47,22 @@ using namespace std; +bool Exists(const string thePath) +{ +#ifdef WNT + if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { + if ( GetLastError () != ERROR_FILE_NOT_FOUND ) { + return false; + } + } +#else + int status = access ( thePath.c_str() , F_OK ); + if (status != 0) return false; +#endif + return true; +} + + //============================================================================ // function : GetTempDir // purpose : Return a temp directory to store created files like "/tmp/sub_dir/" @@ -61,54 +71,57 @@ std::string SALOMEDS_Tool::GetTmpDir() { //Find a temporary directory to store a file - TCollection_AsciiString aTmpDir; + string aTmpDir = ""; char *Tmp_dir = getenv("SALOME_TMP_DIR"); if(Tmp_dir != NULL) { - aTmpDir = TCollection_AsciiString(Tmp_dir); + aTmpDir = string(Tmp_dir); #ifdef WIN32 - if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; + if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\'; #else - if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; + if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/'; #endif } else { #ifdef WIN32 - aTmpDir = TCollection_AsciiString("C:\\"); + aTmpDir = string("C:\\"); #else - aTmpDir = TCollection_AsciiString("/tmp/"); + aTmpDir = string("/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"); + char buffer[127]; + sprintf(buffer, "%d", aRND); + string aSubDir(buffer); + if(aSubDir.size() <= 1) aSubDir = string("123409876"); aTmpDir += aSubDir; //Get RND sub directory + string aDir = aTmpDir; + + if(Exists(aDir)) { + for(aRND = 0; Exists(aDir); aRND++) { + sprintf(buffer, "%d", aRND); + aDir = aTmpDir+buffer; //Build a unique directory name + } + } + #ifdef WIN32 - if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; + if(aDir[aDir.size()-1] != '\\') aDir+='\\'; #else - if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; + if(aDir[aTmpDir.size()-1] != '/') aDir+='/'; #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); - } - MESSAGE("#### TMP" << aTmpDir.ToCString()); - - //OSD_Protection aProtection(OSD_RW, OSD_RWX, OSD_RX, OSD_RX); - OSD_Protection aProtection(OSD_RWXD, OSD_RWX, OSD_RX, OSD_RX ); - aDir.Build(aProtection); +#ifdef WNT + CreateDirectory(aDir.c_str(), NULL); +#else + mkdir(aDir.c_str(), 0x1ff); +#endif - return aTmpDir.ToCString(); + return aDir; } //============================================================================ @@ -119,35 +132,29 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory, const SALOMEDS::ListOfFileNames& theFiles, const bool IsDirDeleted) { - TCollection_AsciiString aDirName(const_cast(theDirectory.c_str())); + string aDirName = theDirectory; int i, aLength = theFiles.length(); - for(i=0; iMore()) - { - delete anIterator; - aDir.Remove(); - } + if(Exists(aDirName)) { +#ifdef WNT + RemoveDirectory(aDireName.c_str()); +#else + rmdir(aDirName.c_str()); +#endif + } } } @@ -169,7 +176,7 @@ namespace return (new SALOMEDS::TMPFile); //Get a temporary directory for saved a file - TCollection_AsciiString aTmpDir(const_cast(theFromDirectory.c_str())); + string aTmpDir = theFromDirectory; long aBufferSize = 0; long aCurrentPos; @@ -185,14 +192,12 @@ namespace //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 + const_cast(theFiles[i].in()); - OSD_Path anOSDPath(aFullPath); - OSD_File anOSDFile(anOSDPath); - if(!anOSDFile.Exists()) continue; + string aFullPath = aTmpDir + const_cast(theFiles[i].in()); + if(!Exists(aFullPath)) continue; #ifdef WNT - ifstream aFile(aFullPath.ToCString(), ios::binary); + ifstream aFile(aFullPath.c_str(), ios::binary); #else - ifstream aFile(aFullPath.ToCString()); + ifstream aFile(aFullPath.c_str()); #endif aFile.seekg(0, ios::end); aFileSize[i] = aFile.tellg(); @@ -221,14 +226,12 @@ namespace for(i=0; i(theFiles[i].in()); - OSD_Path anOSDPath(aFullPath); - OSD_File anOSDFile(anOSDPath); - if(!anOSDFile.Exists()) continue; + string aFullPath = aTmpDir + const_cast(theFiles[i].in()); + if(!Exists(aFullPath)) continue; #ifdef WNT - aFile = new ifstream(aFullPath.ToCString(), ios::binary); + aFile = new ifstream(aFullPath.c_str(), ios::binary); #else - aFile = new ifstream(aFullPath.ToCString()); + aFile = new ifstream(aFullPath.c_str()); #endif } //Initialize 4 bytes of the buffer by 0 @@ -300,7 +303,7 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, return aFiles; //Get a temporary directory for saving a file - TCollection_AsciiString aTmpDir(const_cast(theToDirectory.c_str())); + string aTmpDir = theToDirectory; unsigned char *aBuffer = (unsigned char*)theStream.NP_data(); @@ -331,11 +334,11 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, memcpy(&aFileSize, (aBuffer + aCurrentPos), ((sizeof(long) > 8) ? 8 : sizeof(long))); aCurrentPos += 8; - TCollection_AsciiString aFullPath = aTmpDir + aFileName; + string aFullPath = aTmpDir + aFileName; #ifdef WNT - ofstream aFile(aFullPath.ToCString(), ios::binary); + ofstream aFile(aFullPath.c_str(), ios::binary); #else - ofstream aFile(aFullPath.ToCString()); + ofstream aFile(aFullPath.c_str()); #endif aFile.write((char *)(aBuffer+aCurrentPos), aFileSize); aFile.close(); @@ -353,11 +356,30 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, // purpose : Returns the name by the path //============================================================================ std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) { - if(thePath == "") - return ""; - OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast(thePath.c_str()))); - TCollection_AsciiString aNameString(aPath.Name()); - return aNameString.ToCString(); + if (thePath.empty()) return ""; + string aPath = thePath; + bool isFound = false; + int pos = aPath.rfind('/'); + if(pos > 0) { + aPath = aPath.substr(pos+1, aPath.size()); + isFound = true; + } + if(!isFound) { + pos = aPath.rfind('\\'); + if(pos > 0) { + aPath = aPath.substr(pos+1, aPath.size()); + isFound = true; + } + } + if(!isFound) { + pos = aPath.rfind('|'); + if(pos > 0) aPath = aPath.substr(pos+1, aPath.size()); + } + + pos = aPath.rfind('.'); + if(pos > 0) aPath = aPath.substr(0, pos); //Remove extension + + return aPath; } //============================================================================ @@ -365,12 +387,32 @@ std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) { // purpose : Returns the dir by the path //============================================================================ std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) { - if(thePath == "") - return ""; - OSD_Path aPath = OSD_Path(TCollection_AsciiString(const_cast(thePath.c_str()))); - TCollection_AsciiString aDirString(aPath.Trek()); - aDirString.ChangeAll('|','/'); - return aDirString.ToCString(); + if (thePath.empty()) return ""; + + int pos = thePath.rfind('/'); + string path; + if(pos > 0) { + path = thePath.substr(0, pos+1); + } + if(path.empty()) { + pos = thePath.rfind('\\'); + if(pos > 0) path = thePath.substr(0, pos+1); + } + if(path.empty()) { + pos = thePath.rfind('|'); + if(pos > 0) path = thePath.substr(0, pos+1); + } + if(path.empty()) { + path = thePath+"/"; + } + +#ifdef WNT //Check if the only disk letter is given as path + if(path.size() == 2 && path[1] == ":") path +='\\'; +#endif + + for(int i = 0, len = path.size(); i