]> SALOME platform Git repositories - plugins/hexoticplugin.git/commitdiff
Salome HOME
Merge branch 'occ/new_mg_licnese'
authorvsr <vsr@opencascade.com>
Fri, 24 Sep 2021 09:02:04 +0000 (12:02 +0300)
committervsr <vsr@opencascade.com>
Fri, 24 Sep 2021 09:02:04 +0000 (12:02 +0300)
src/HexoticPlugin/HexoticPlugin_Hexotic.cxx
src/HexoticPlugin/MG_Hexotic_API.cxx
src/HexoticPlugin/MG_Hexotic_API.hxx

index 37bd68508ee54dfe84380ce3c7ac8c422dafac55..2e87506228ec5bac09bf435d7df1b250a675e50a 100644 (file)
@@ -67,6 +67,7 @@
 #include <TopoDS_Vertex.hxx>
 #include <gp_Pnt.hxx>
 
+#include <Basics_DirUtils.hxx>
 #include <Basics_Utils.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOM_wrap.hxx>
@@ -788,7 +789,7 @@ HexoticPlugin_Hexotic::getHexoticCommand(const TCollection_AsciiString& Hexotic_
   TCollection_AsciiString minl         = " --min_level ", maxl = " --max_level ", angle = " --ridge_angle ";
   TCollection_AsciiString mins         = " --min_size ", maxs = " --max_size ";
   TCollection_AsciiString in           = " --in ",   out  = " --out ";
-  TCollection_AsciiString sizeMap      = " --read_sizemap ";
+  TCollection_AsciiString sizeMap      = " --sizemap ";
   TCollection_AsciiString ignoreRidges = " --compute_ridges no ", invalideElements = " --allow_invalid_elements yes ";
   TCollection_AsciiString subdom       = " --components ";
 #ifndef WIN32
@@ -870,7 +871,7 @@ HexoticPlugin_Hexotic::getHexoticCommand(const TCollection_AsciiString& Hexotic_
     run_Hexotic +=  angle + sharpAngle;
   
   if (_sizeMaps.begin() != _sizeMaps.end() && forExecutable )
-    run_Hexotic += sizeMap + Hexotic_SizeMap_Prefix;
+    run_Hexotic += sizeMap + Hexotic_SizeMap_Prefix + ".sol";
 
   if (_nbLayers       > 0 &&
       _firstLayerSize > 0 &&
@@ -1025,7 +1026,7 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh&          aMesh,
 
     SetParameters(_hypothesis);
 
-    TCollection_AsciiString aTmpDir = _hexoticWorkingDirectory.c_str();
+    TCollection_AsciiString aTmpDir = Kernel_Utils::GetTmpDirByPath(_hexoticWorkingDirectory).c_str();
     TCollection_AsciiString aQuote("");
 #ifdef WIN32
     aQuote = "\"";
@@ -1052,6 +1053,7 @@ bool HexoticPlugin_Hexotic::Compute(SMESH_Mesh&          aMesh,
       {
         MESSAGE("Use output file from blsurf as input file from hexotic: " << Hexotic_In);
         mgHexa.SetUseExecutable();
+        mgHexa.SetInputFile( _blsurfHypo->GetGMFFile() );
         defaultInputFile = false;
       }
     }
index ca19e8a11f34ce8bf64a71b3f78369c97129a039..5f88f1ce28c2ae3207bc6cbf24480c8051c3d1d9 100644 (file)
 #define NOMINMAX
 #endif
 
+#include <DriverGMF_Read.hxx>
 #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
 
@@ -667,6 +670,14 @@ void MG_Hexotic_API::LibData::Init()
 
 bool MG_Hexotic_API::LibData::Compute()
 {
+  // 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 = hexa_set_surface_mesh( _session, _tria_mesh );
   if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
@@ -719,7 +730,8 @@ struct MG_Hexotic_API::LibData // to avoid compiler warnings
  */
 //================================================================================
 
-MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress)
+MG_Hexotic_API::MG_Hexotic_API(volatile bool& cancelled_flag, double& progress):
+  _isMesh(true), _nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
 {
   _useLib = false;
   _libData = new LibData( cancelled_flag, progress );
@@ -813,7 +825,7 @@ bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
     }
 
     // compute
-    bool ok =  _libData->Compute();
+    bool ok = _libData->Compute();
 
     GetLog(); // write a log file
     _logFile = ""; // not to write it again
@@ -821,6 +833,20 @@ bool MG_Hexotic_API::Compute( const std::string& cmdLine, std::string& errStr )
     return ok;
 #endif
   }
+  // 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
 
@@ -927,7 +953,7 @@ void MG_Hexotic_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* fa
 //================================================================================
 
 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
-                             double* x, double* y, double *z, int* domain )
+                               double* x, double* y, double *z, int* domain )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -945,7 +971,7 @@ void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
 //================================================================================
 
 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
-                             float* x, float* y, float *z, int* domain )
+                               float* x, float* y, float *z, int* domain )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -1001,7 +1027,7 @@ void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what, int* node1, int* node2
 //================================================================================
 
 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
-                             int* node1, int* node2, int* node3, int* domain )
+                               int* node1, int* node2, int* node3, int* domain )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -1019,7 +1045,7 @@ void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
 //================================================================================
 
 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
-                             int* node1, int* node2, int* node3, int* node4, int* domain )
+                               int* node1, int* node2, int* node3, int* node4, int* domain )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -1040,9 +1066,9 @@ void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
 //================================================================================
 
 void MG_Hexotic_API::GmfGetLin(int iMesh, GmfKwdCod what,
-                             int* node1, int* node2, int* node3, int* node4,
-                             int* node5, int* node6, int* node7, int* node8,
-                             int* domain )
+                               int* node1, int* node2, int* node3, int* node4,
+                               int* node5, int* node6, int* node7, int* node8,
+                               int* domain )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -1080,6 +1106,16 @@ int  MG_Hexotic_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int d
 
 void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
 {
+  if ( iMesh == 1 && _isMesh )
+  {
+    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 ) {
@@ -1096,6 +1132,26 @@ void MG_Hexotic_API::GmfSetKwd(int iMesh, GmfKwdCod what, int nb )
   ::GmfSetKwd(iMesh, what, nb );
 }
 
+//================================================================================
+/*!
+ * \brief Set GMF file made by MG-CADSurf to get nb of mesh entities from it
+ */
+//================================================================================
+
+void MG_Hexotic_API::SetInputFile( const std::string mesh2DFile )
+{
+  DriverGMF_Read fileReader;
+  fileReader.SetFile( mesh2DFile );
+
+  smIdType nbVertex, nbEdge, nbFace, nbVol;
+  if ( fileReader.GetMeshInfo(nbVertex, nbEdge, nbFace, nbVol))
+  {
+    _nbNodes += nbVertex;
+    _nbEdges += nbEdge;
+    _nbFaces += nbFace;
+  }
+}
+
 //================================================================================
 /*!
  * \brief Add coordinates of a node
@@ -1212,6 +1268,9 @@ void MG_Hexotic_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2,
 
 void MG_Hexotic_API::GmfCloseMesh( int iMesh )
 {
+  if ( iMesh == 1 )
+    _isMesh = false;
+
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
     return;
@@ -1259,5 +1318,5 @@ std::string MG_Hexotic_API::GetLog()
 #endif
   }
   SMESH_File file( _logFile );
-  return file.getPos();
+  return file.exists() ? file.getPos() : "";
 }
index 1fd840173e4465837db13279b55a689541d6ccc7..e3d2cf4eb942a64e53f01b95d5fbf6a55d78727d 100644 (file)
@@ -41,6 +41,7 @@ public:
   bool IsLibrary();
   bool IsExecutable() { return !IsLibrary(); }
   void SetUseExecutable();
+  void SetInputFile( const std::string mesh2DFile );
 
   // IN to MESHGEMS
   int  GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int dim);
@@ -81,6 +82,13 @@ private:
   LibData*      _libData;
   std::set<int> _openFiles;
   std::string   _logFile;
+
+  // count mesh entities for MG license key generation
+  bool          _isMesh;
+  int           _nbNodes;
+  int           _nbEdges;
+  int           _nbFaces;
+  int           _nbVolumes;
 };
 
 #endif