Salome HOME
updated copyright message
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPlugin_HYBRID.cxx
index 7a432e97bae24a02984f6c37a74b0d62ada7c8d5..f9362f059c87232d2edcc8ae04909f29cfe1799f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -70,6 +70,9 @@
 #include <Basics_Utils.hxx>
 #include <utilities.h>
 
+#include <boost/filesystem.hpp>
+namespace boofs = boost::filesystem;
+
 #include <fstream>
 #include <algorithm>
 
@@ -96,6 +99,13 @@ static void removeFile( const std::string& fileName )
   }
 }
 
+// change results files permissions to user only (using boost to be used without C++17)
+static void chmodUserOnly(const char* filename)
+{
+  if (boofs::exists(filename))
+    boofs::permissions(filename, boofs::remove_perms | boofs::group_all | boofs::others_all );
+}
+
 //=============================================================================
 /*!
  *  
@@ -1383,11 +1393,17 @@ static bool writeGMFFile(MG_HYBRID_API*                                  MGInput
   }
 
   MGInput->GmfCloseMesh(idx);
+  chmodUserOnly(theMeshFileName);
   if (idxRequired)
-    MGInput->GmfCloseMesh(idxRequired);
+    {
+      MGInput->GmfCloseMesh(idxRequired);
+      chmodUserOnly(theRequiredFileName);
+    }
   if (idxSol)
-    MGInput->GmfCloseMesh(idxSol);
-  
+    {
+      MGInput->GmfCloseMesh(idxSol);
+      chmodUserOnly(theSolFileName);
+    }
   return true;
   
 }
@@ -1504,6 +1520,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh&         theMesh,
   }
 
   aIdsFile.close();
+  chmodUserOnly(aSmdsToHybridIdMapFileName.c_str());
 
   if ( ! Ok ) {
     if ( !_keepFiles ) {
@@ -1546,9 +1563,17 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh&         theMesh,
 
   if ( _logInStandardOutput && mgHybrid.IsLibrary() )
     std::cout << std::endl << mgHybrid.GetLog() << std::endl;
+  else
+    chmodUserOnly(aLogFileName.c_str());
   if ( Ok )
     std::cout << "End of Hybrid execution !" << std::endl;
 
+  if ( mgHybrid.IsExecutable() )
+    {
+      chmodUserOnly(aResultFileName.c_str());
+      chmodUserOnly(aResSolFileName.c_str());
+    }
+
   // --------------
   // read a result
   // --------------
@@ -1745,9 +1770,17 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh&         theMesh,
 
   if ( _logInStandardOutput && mgHybrid.IsLibrary() )
     std::cout << std::endl << mgHybrid.GetLog() << std::endl;
+  else
+    chmodUserOnly(aLogFileName.c_str());
   if ( Ok )
     std::cout << "End of Hybrid execution !" << std::endl;
 
+  if (mgHybrid.IsExecutable())
+    {
+      chmodUserOnly(aResultFileName.c_str());
+      chmodUserOnly(aResSolFileName.c_str());
+    }
+
   // --------------
   // read a result
   // --------------
@@ -2096,9 +2129,12 @@ bool HYBRIDPlugin_HYBRID::storeErrorDescription(const char*                logFi
   if ( errDescription.empty() ) { // no errors found
     char msgLic1[] = "connection to server failed";
     char msgLic2[] = " Dlim ";
+    char msgLic3[] = "license is not valid";
     if ( std::search( &buf[0], bufEnd, msgLic1, msgLic1 + strlen(msgLic1)) != bufEnd ||
          std::search( &buf[0], bufEnd, msgLic2, msgLic2 + strlen(msgLic2)) != bufEnd )
-      errDescription << "Licence problems.";
+      errDescription << "Network license problem.";
+    else if ( std::search( &buf[0], bufEnd, msgLic3, msgLic3 + strlen(msgLic3)) != bufEnd )
+      errDescription << "License is not valid.";
     else
     {
       char msg2[] = "SEGMENTATION FAULT";
@@ -2206,9 +2242,9 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh,
                                             "Submesh can not be evaluated",this));
       return false;
     }
-    std::vector<int> aVec = (*anIt).second;
-    nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
-    nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
+    std::vector<smIdType> aVec = (*anIt).second;
+    nbtri += std::max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]);
+    nbqua += std::max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]);
     GProp_GProps G;
     BRepGProp::SurfaceProperties(F,G);
     double anArea = G.Mass();
@@ -2227,9 +2263,9 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh,
     tmpMap.Add(E);
     SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current());
     MapShapeNbElemsItr anIt = aResMap.find(aSubMesh);
-    std::vector<int> aVec = (*anIt).second;
+    std::vector<smIdType> aVec = (*anIt).second;
     nb0d_e += aVec[SMDSEntity_Node];
-    nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
+    nb1d_e += std::max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]);
     if(IsFirst) {
       IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]);
       IsFirst = false;
@@ -2247,7 +2283,7 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh,
   int nbVols = int(aVolume/tetrVol/CoeffQuality);
   int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2;
   int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5;
-  std::vector<int> aVec(SMDSEntity_Last);
+  std::vector<smIdType> aVec(SMDSEntity_Last);
   for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i]=0;
   if( IsQuadratic ) {
     aVec[SMDSEntity_Node] = nb1d_in/6 + 1 + nb1d_in;