From: akl Date: Thu, 6 Jun 2013 12:54:32 +0000 (+0000) Subject: Fix of 0022223: [CEA 821] Management of temporary files created by Hexotic. X-Git-Tag: V7_3_0a1~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9bd3ca8a2ca1392f9878792733ace39c7486195b;p=plugins%2Fhexoticplugin.git Fix of 0022223: [CEA 821] Management of temporary files created by Hexotic. 1) '___' suffix was added to the names of temporary Hexotic files; 2) these files are removed if Compute finished successfully and kept otherwise. --- diff --git a/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx b/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx index 03d93b3..357364e 100644 --- a/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx +++ b/src/HexoticPlugin/HexoticPlugin_Hexotic.cxx @@ -64,6 +64,8 @@ #include #include +#include + static void removeFile( const TCollection_AsciiString& fileName ) { try { @@ -847,9 +849,16 @@ static TCollection_AsciiString getTmpDir() TCollection_AsciiString aTmpDir; char *Tmp_dir = getenv("SALOME_TMP_DIR"); +#ifdef WIN32 + if(Tmp_dir == NULL) { + Tmp_dir = getenv("TEMP"); + if( Tmp_dir== NULL ) + Tmp_dir = getenv("TMP"); +#endif + if(Tmp_dir != NULL) { aTmpDir = Tmp_dir; - #ifdef WIN32 +#ifdef WIN32 if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; #else if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; @@ -865,6 +874,24 @@ static TCollection_AsciiString getTmpDir() return aTmpDir; } +//======================================================================= +//function : getSuffix +//purpose : Returns a suffix that will be unique for the current process +//======================================================================= + +static TCollection_AsciiString getSuffix() +{ + TCollection_AsciiString aSuffix = ""; + aSuffix += "_"; + aSuffix += getenv("USER"); + aSuffix += "_"; + aSuffix += Kernel_Utils::GetHostname().c_str(); + aSuffix += "_"; + aSuffix += getpid(); + + return aSuffix; +} + //================================================================================ /*! * \brief Returns a command to run Hexotic mesher @@ -1020,12 +1047,12 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, #endif TCollection_AsciiString Hexotic_In(""), Hexotic_Out; TCollection_AsciiString modeFile_In( "chmod 666 " ), modeFile_Out( "chmod 666 " ); - TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic.log"; // log + TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic"+getSuffix()+".log"; // log std::map aSmdsToHexoticIdMap; std::map aHexoticIdToNodeMap; - Hexotic_Out = aTmpDir + "Hexotic_Out.mesh"; + Hexotic_Out = aTmpDir + "Hexotic"+getSuffix()+"_Out.mesh"; #ifdef WITH_BLSURFPLUGIN bool defaultInputFile = true; if (_blsurfHypo && !_blsurfHypo->GetQuadAllowed()) { @@ -1035,7 +1062,7 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, } if (defaultInputFile) { #endif - Hexotic_In = aTmpDir + "Hexotic_In.mesh"; + Hexotic_In = aTmpDir + "Hexotic"+getSuffix()+"_In.mesh"; removeHexoticFiles(Hexotic_In, Hexotic_Out); cout << std::endl; cout << "Creating Hexotic input mesh file : " << Hexotic_In << std::endl; @@ -1076,7 +1103,7 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, this, #endif meshDS, _nbShape, tabShape, tabBox ); - if(Ok) + if(Ok) { /********************* // TODO: Detect and remove elements in holes in case of sd mode = 4 // Remove previous nodes and elements @@ -1092,9 +1119,14 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh& aMesh, if (myError) */ hexahedraMessage = "success"; - else + removeFile(Hexotic_Out); + removeFile(Hexotic_In); + removeFile(aLogFileName); + } + else { hexahedraMessage = "failed"; } + } else { hexahedraMessage = "failed"; cout << "Problem with Hexotic output file " << Hexotic_Out.ToCString() << std::endl; @@ -1159,13 +1191,13 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHel TCollection_AsciiString aTmpDir = getTmpDir(); TCollection_AsciiString Hexotic_In, Hexotic_Out; TCollection_AsciiString modeFile_In( "chmod 666 " ), modeFile_Out( "chmod 666 " ); - TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic.log"; // log + TCollection_AsciiString aLogFileName = aTmpDir + "Hexotic"+getSuffix()+".log"; // log std::map aSmdsToHexoticIdMap; std::map aHexoticIdToNodeMap; - Hexotic_In = aTmpDir + "Hexotic_In.mesh"; - Hexotic_Out = aTmpDir + "Hexotic_Out.mesh"; + Hexotic_In = aTmpDir + "Hexotic"+getSuffix()+"_In.mesh"; + Hexotic_Out = aTmpDir + "Hexotic"+getSuffix()+"_Out.mesh"; std::string run_Hexotic = getHexoticCommand(Hexotic_In, Hexotic_Out); run_Hexotic += std::string(" 1 > ") + aLogFileName.ToCString(); // dump into file @@ -1252,6 +1284,9 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHel if(_compute_canceled) return error(SMESH_Comment("interruption initiated by user")); #endif + removeFile(Hexotic_Out); + removeFile(Hexotic_In); + removeFile(aLogFileName); return Ok; /* return myError->IsOK(); diff --git a/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx b/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx index cc67ce4..13c5dcd 100644 --- a/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx +++ b/src/HexoticPlugin/HexoticPlugin_Hypothesis.cxx @@ -304,20 +304,32 @@ int HexoticPlugin_Hypothesis::GetDefaultHexoticNbProc() std::string HexoticPlugin_Hypothesis::GetDefaultHexoticWorkingDirectory() { - TCollection_AsciiString aTmpDir; + std::string aTmpDir; char *Tmp_dir = getenv("SALOME_TMP_DIR"); - if(Tmp_dir != NULL) { - aTmpDir = Tmp_dir; +#ifdef WIN32 + if(Tmp_dir == NULL) { + Tmp_dir = getenv("TEMP"); + if( Tmp_dir== NULL ) + Tmp_dir = getenv("TMP"); + } +#endif + if( Tmp_dir != NULL ) { + aTmpDir = std::string(Tmp_dir); +#ifdef WIN32 + if(aTmpDir[aTmpDir.size()-1] != '\\') aTmpDir+='\\'; +#else + if(aTmpDir[aTmpDir.size()-1] != '/') aTmpDir+='/'; +#endif } else { #ifdef WIN32 - aTmpDir = TCollection_AsciiString("C:\\"); + aTmpDir = "C:\\"; #else - aTmpDir = TCollection_AsciiString("/tmp/"); + aTmpDir = "/tmp/"; #endif } - return aTmpDir.ToCString(); + return aTmpDir; } int HexoticPlugin_Hypothesis::GetDefaultHexoticSdMode()