Salome HOME
Fix bos #26435 MG-Tetra_HPC failed with new licence mechanism:
[plugins/ghs3dprlplugin.git] / src / GHS3DPRLPlugin / GHS3DPRLPlugin_Hypothesis.cxx
index 16505ffd67834e194d7d448b8e0bff7e3175306b..635fe2e7b2ae126338d453e9cf84320c9c47baa7 100644 (file)
 // ---
 //
 #include "GHS3DPRLPlugin_Hypothesis.hxx"
+#include <Basics_DirUtils.hxx>
+#include <SMESH_File.hxx>
 #include <utilities.h>
+#include <unistd.h>
+
+#ifdef WIN32
+#include <process.h>
+#define getpid _getpid
+#endif
 
 //=============================================================================
 /*!
@@ -47,6 +55,56 @@ GHS3DPRLPlugin_Hypothesis::GHS3DPRLPlugin_Hypothesis (int hypId, SMESH_Gen * gen
   _param_algo_dim = 3;
 }
 
+//=======================================================================
+//function : DefaultWorkingDirectory
+//=======================================================================
+
+std::string GHS3DPRLPlugin_Hypothesis::DefaultWorkingDirectory()
+{
+  TCollection_AsciiString aTmpDir;
+
+  char *Tmp_dir = getenv("SALOME_TMP_DIR");
+  if(Tmp_dir != NULL) {
+    aTmpDir = Tmp_dir;
+  }
+  else {
+#ifdef WIN32
+    aTmpDir = TCollection_AsciiString("C:\\");
+#else
+    aTmpDir = TCollection_AsciiString("/tmp/");
+#endif
+  }
+  return aTmpDir.ToCString();
+}
+
+//================================================================================
+/*!
+ * \brief Return a unique file name
+ */
+//================================================================================
+
+std::string GHS3DPRLPlugin_Hypothesis::GetFileName(const GHS3DPRLPlugin_Hypothesis* hyp)
+{
+  std::string aTmpDir = DefaultWorkingDirectory();
+  if ( !SMESH_File( aTmpDir ).exists() )
+    aTmpDir = Kernel_Utils::GetTmpDirByPath( aTmpDir );
+
+  const char lastChar = *aTmpDir.rbegin();
+#ifdef WIN32
+    if(lastChar != '\\') aTmpDir+='\\';
+#else
+    if(lastChar != '/') aTmpDir+='/';
+#endif
+
+  TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
+  aGenericName += "MGTETRAHPC_";
+  aGenericName += getpid();
+  aGenericName += "_";
+  aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());
+
+  return aGenericName.ToCString();
+}
+
 //=============================================================================
 /*!
  *
@@ -290,7 +348,7 @@ std::string GHS3DPRLPlugin_Hypothesis::GetDefaultMEDName()
 //=============================================================================
 int GHS3DPRLPlugin_Hypothesis::GetDefaultNbPart()
 {
-  return 16;
+  return 8;
 }
 
 //=============================================================================