Salome HOME
bos #24596 [CEA] New MeshGems license occ/new_MG_licnese
authoreap <eap@opencascade.com>
Thu, 5 Aug 2021 12:33:26 +0000 (15:33 +0300)
committereap <eap@opencascade.com>
Thu, 5 Aug 2021 12:33:26 +0000 (15:33 +0300)
src/GHS3DPRLPlugin/CMakeLists.txt
src/GHS3DPRLPlugin/GHS3DPRLPlugin_GHS3DPRL.cxx
src/GHS3DPRLPlugin/MG_TetraHPC_API.cxx
src/GHS3DPRLPlugin/MG_TetraHPC_API.hxx

index 0bc8aac3086b8310db122b22d15510b5ea26921f..febf8776325c0fc4fd70042a8d9cb4ebf4a82579 100644 (file)
@@ -54,6 +54,7 @@ SET(_link_LIBRARIES
   ${SMESH_SMDS}
   ${SMESH_StdMeshers}
   ${SMESH_MeshDriverGMF}
+  ${SMESH_SMESHUtils}
   ${KERNEL_SalomeGenericObj}
   ${KERNEL_SALOMELocalTrace}
   ${KERNEL_SALOMEBasics}
index 71ff80573c7d3ec08d5b542c04de75a3b004aefa..eb92f305a1ed48d3831a05c7024d524546c548b8 100644 (file)
@@ -321,7 +321,7 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
 
   exportGMF( &mgTetraHPC, fileskinmesh.ToCString(), meshDS );
 
-  if ( useLib )
+  if ( true /*useLib*/ )
   {
     TCollection_AsciiString cmd = TCollection_AsciiString("mg-tetra_hpc.exe") + 
       " --number_of_subdomains=" + NbPart +
@@ -337,9 +337,11 @@ bool GHS3DPRLPlugin_GHS3DPRL::Compute(SMESH_Mesh&         theMesh,
          << "  Creating a log file : " << logFileName << endl << endl;
     mgTetraHPC.SetLogFile( logFileName.ToCString() );
 
-    mgTetraHPC.Compute( cmd.ToCString() );
+    std::string log;
+    mgTetraHPC.Compute( cmd.ToCString(), log );
 
-    std::string log = mgTetraHPC.GetLog();
+    if ( log.empty() )
+      log = mgTetraHPC.GetLog();
     if ( log.find(" Dlim "   ) != std::string::npos ||
          log.find(" license ") != std::string::npos )
       return error("License problem");
index b8b59d55e86848b685977c67a30e96d45f188f3a..0edfd15c09792699f8a4f4cf6643f6991a2b0496 100644 (file)
 
 #include <SMESH_Comment.hxx>
 #include <SMESH_File.hxx>
+#include <SMESH_MGLicenseKeyGen.hxx>
 #include <Utils_SALOME_Exception.hxx>
 
-#include <vector>
-#include <iterator>
 #include <cstring>
+#include <iostream>
+#include <iterator>
+#include <vector>
 
 #ifdef USE_MG_LIBS
 
@@ -584,6 +586,14 @@ void MG_TetraHPC_API::LibData::Init()
 
 bool MG_TetraHPC_API::LibData::Compute( const std::string& outFile )
 {
+  // MG license
+  std::string errorTxt;
+  if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _tria_mesh, errorTxt ))
+  {
+    AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
+    return false;
+  }
+
   // Set surface mesh
   status_t ret = tetra_hpc_set_input_mesh( _session, _tria_mesh );
   if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
@@ -635,7 +645,8 @@ struct MG_TetraHPC_API::LibData // to avoid compiler warnings
  */
 //================================================================================
 
-MG_TetraHPC_API::MG_TetraHPC_API(volatile bool& cancelled_flag, double& progress)
+MG_TetraHPC_API::MG_TetraHPC_API(volatile bool& cancelled_flag, double& progress):
+  _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
 {
   _useLib = false;
   _libData = new LibData( cancelled_flag, progress );
@@ -695,7 +706,7 @@ void MG_TetraHPC_API::SetUseExecutable()
  */
 //================================================================================
 
-bool MG_TetraHPC_API::Compute( const std::string& cmdLine )
+bool MG_TetraHPC_API::Compute( const std::string& cmdLine, std::string& errStr )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -744,7 +755,7 @@ bool MG_TetraHPC_API::Compute( const std::string& cmdLine )
     }
 
     // compute
-    bool ok =  _libData->Compute( outFile );
+    bool ok = _libData->Compute( outFile );
 
     GetLog(); // write a log file
     _logFile = ""; // not to write it again
@@ -753,14 +764,26 @@ bool MG_TetraHPC_API::Compute( const std::string& cmdLine )
 #endif
   }
 
-  (void)cmdLine; // unused
-  // Run library ONLY
+  // add MG license key
+  {
+    std::string errorTxt, meshIn;
+    std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( meshIn,
+                                                          _nbNodes, _nbEdges, _nbFaces, _nbVolumes,
+                                                          errorTxt );
+    if ( key.empty() )
+    {
+      errStr = "Problem with library SalomeMeshGemsKeyGenerator: " + errorTxt;
+      return false;
+    }
+
+    const_cast< std::string& >( cmdLine ) += " --key " + key;
+  }
 
-  // int err = system( cmdLine.c_str() ); // run
+  int err = system( cmdLine.c_str() ); // run
 
-  // if ( err )
-  //   errStr = SMESH_Comment("system(mg-tetra.exe ...) command failed with error: ")
-  //     << strerror( errno );
+  if ( err )
+    errStr = SMESH_Comment("system(mg-tetra.exe ...) command failed with error: ")
+      << strerror( errno );
 
   return false;
 }
@@ -1012,6 +1035,16 @@ int  MG_TetraHPC_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int
 
 void MG_TetraHPC_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
 {
+  if ( iMesh == 1 )
+  {
+    switch ( what ) {
+    case GmfVertices:  _nbNodes = nb; break;
+    case GmfEdges:     _nbEdges = nb; break;
+    case GmfTriangles: _nbFaces = nb; break;
+    default:;
+    }
+  }
+
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
     switch ( what ) {
index b4f9153c498b2a38ce5f30fe42f9de49414d2074..d1aed510c4d6f18b208863c8f6b6db547cf6c257 100644 (file)
@@ -52,7 +52,7 @@ public:
   void GmfSetLin(int iMesh, GmfKwdCod what, int id ); // required
   void GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, int node3, int domain ); // tria
 
-  bool Compute( const std::string& cmdLine );
+  bool Compute( const std::string& cmdLine, std::string& errStr );
 
   // OUT from MESHGEMS
   int  GmfOpenMesh(const char* theFile, int rdOrWr, int * ver, int * dim);
@@ -81,6 +81,13 @@ private:
   LibData*      _libData;
   std::set<int> _openFiles;
   std::string   _logFile;
+
+
+  // count mesh entities for MG license key generation
+  int           _nbNodes;
+  int           _nbEdges;
+  int           _nbFaces;
+  int           _nbVolumes;
 };
 
 #endif