Salome HOME
updated copyright message
[plugins/hybridplugin.git] / src / HYBRIDPlugin / MG_HYBRID_API.cxx
index 199a067b695b31130bf44fdb3fc2a1c84539f113..3288283bfe72ec32c432576f873da4d8595b7eb1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2004-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2004-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
 
 #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
 
@@ -340,7 +342,7 @@ struct MG_HYBRID_API::LibData
   }
 
   void ReadPrismNodes( int* node1, int* node2, int* node3, int* node4,
-                       int* node5, int* node6, int* domain )
+                       int* node5, int* node6, int* /*domain*/ )
   {
     integer vtx[6];
     status_t ret = mesh_get_prism_vertices( _hybrid_mesh, _count, vtx);
@@ -362,6 +364,27 @@ struct MG_HYBRID_API::LibData
     ++_count;
   }
 
+  void ReadPyramidNodes( int* node1, int* node2, int* node3, int* node4, int* node5, int* domain )
+  {
+    integer vtx[6];
+    status_t ret = mesh_get_pyramid_vertices( _hybrid_mesh, _count, vtx);
+    if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid" );
+
+    *node1 = vtx[0];
+    *node2 = vtx[1];
+    *node3 = vtx[2];
+    *node4 = vtx[3];
+    *node5 = vtx[4];
+
+    integer tag;
+    ret = mesh_get_pyramid_tag( _hybrid_mesh, _count, &tag );
+    if (ret != STATUS_OK) MG_Error( "unable to get resulting pyramid tag" );
+
+    *domain = tag;
+
+    ++_count;
+  }
+
   void ReadCorner( int* node )
   {
     if ( _count <= ReadNbCorners() )
@@ -407,7 +430,7 @@ struct MG_HYBRID_API::LibData
     _nbRequiredTria = nb;
   }
 
-  void AddNode( double x, double y, double z, int domain )
+  void AddNode( double x, double y, double z, int /*domain*/ )
   {
     _xyz.push_back( x );
     _xyz.push_back( y );
@@ -494,12 +517,12 @@ struct MG_HYBRID_API::LibData
 
   int IsVertexRequired( int iNode )
   {
-    return ! ( iNode < int( _xyz.size() - _nodeSize.size() ));
+    return ! ( iNode < int( NbNodes() - _nodeSize.size() ));
   }
 
   double GetSizeAtVertex( int iNode )
   {
-    return IsVertexRequired( iNode ) ? _nodeSize[ iNode - _xyz.size() + _nodeSize.size() ] : 0.;
+    return IsVertexRequired( iNode ) ? _nodeSize[ iNode - NbNodes() + _nodeSize.size() ] : 0.;
   }
 };
 
@@ -673,10 +696,21 @@ void MG_HYBRID_API::LibData::Init()
 
 bool MG_HYBRID_API::LibData::Compute()
 {
+  // MG license
+  std::string errorTxt;
+  status_t ret;
+
+  if ( !SMESHUtils_MGLicenseKeyGen::SignMesh( _surf_mesh, "hybrid", errorTxt ))
+  {
+    AddError( SMESH_Comment( "Problem with library SalomeMeshGemsKeyGenerator: ") << errorTxt );
+    return false;
+  }
+
   // Set surface mesh
-  status_t ret = hybrid_set_surface_mesh( _session, _surf_mesh );
+  ret = hybrid_set_surface_mesh( _session, _surf_mesh );
   if ( ret != STATUS_OK ) MG_Error( "unable to set surface mesh");
 
+#ifndef WIN32
   // Set a sizemap
   if ( !_nodeSize.empty() )
   {
@@ -687,6 +721,7 @@ bool MG_HYBRID_API::LibData::Compute()
     ret = hybrid_set_sizemap( _session, _sizemap );
     if ( ret != STATUS_OK ) MG_Error( "unable to set sizemap");
   }
+#endif
 
   //////////////////////////////////////////////////////////////////////////////////////////
   // const char* file  =  "/tmp/ghs3d_IN.mesh";
@@ -707,6 +742,14 @@ bool MG_HYBRID_API::LibData::Compute()
   return true;
 }
 
+#else // ifdef USE_MG_LIBS
+
+struct MG_HYBRID_API::LibData // to avoid compiler warnings
+{
+  volatile bool& _cancelled_flag;
+  double& _progress;
+  LibData(volatile bool& cancelled_flag, double& progress): _cancelled_flag{cancelled_flag}, _progress{progress} {}
+};
 
 #endif // ifdef USE_MG_LIBS
 
@@ -718,14 +761,16 @@ bool MG_HYBRID_API::LibData::Compute()
 //================================================================================
 
 MG_HYBRID_API::MG_HYBRID_API(volatile bool& cancelled_flag, double& progress)
+  :_nbNodes(0), _nbEdges(0), _nbFaces(0), _nbVolumes(0)
 {
+  _useLib = false;
+  _libData = new LibData( cancelled_flag, progress );
 #ifdef USE_MG_LIBS
   _useLib = true;
-  _libData = new LibData( cancelled_flag, progress );
   _libData->Init();
-#endif
   if ( getenv("MG_HYBRID_USE_EXE"))
     _useLib = false;
+#endif
 }
 
 //================================================================================
@@ -800,6 +845,8 @@ bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
       value = "";
       while ( i+1 < args.size() && args[i+1][0] != '-' )
       {
+        if ( strncmp( "1>", args[i+1].c_str(), 2 ) == 0 )
+          break;
         if ( !value.empty() ) value += " ";
         value += args[++i];
       }
@@ -808,19 +855,36 @@ bool MG_HYBRID_API::Compute( const std::string& cmdLine, std::string& errStr )
     }
 
     // compute
-    return _libData->Compute();
+    bool ok =  _libData->Compute();
+
+    GetLog(); // write a log file
+    _logFile = ""; // not to write it again
+
+    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;
+    }
+    if ( key != "0")
+      const_cast< std::string& >( cmdLine ) += " --key " + key;
+  }
+
   int err = system( cmdLine.c_str() ); // run
 
   if ( err )
     errStr = SMESH_Comment("system(mg-hybrid.exe ...) command failed with error: ")
       << strerror( errno );
 
-  GetLog(); // write a log file
-  _logFile = ""; // not to write it again
-
   return !err;
 
 }
@@ -903,7 +967,7 @@ void MG_HYBRID_API::GmfGotoKwd( int iMesh, GmfKwdCod what )
  */
 //================================================================================
 
-void MG_HYBRID_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int dummy )
+void MG_HYBRID_API::GmfGetLin( int iMesh, GmfKwdCod what, int* nbNodes, int* faceInd, int* ori, int* domain, int /*dummy*/ )
 {
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
@@ -1047,6 +1111,25 @@ void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
   ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, node6, node7, node8, domain );
 }
 
+//================================================================================
+/*!
+ * \brief Return node indices of a next pyramid
+ */
+//================================================================================
+
+void MG_HYBRID_API::GmfGetLin(int iMesh, GmfKwdCod what,
+                              int* node1, int* node2, int* node3, int* node4,
+                              int* node5, int* domain )
+{
+  if ( _useLib ) {
+#ifdef USE_MG_LIBS
+    _libData->ReadPyramidNodes( node1, node2, node3, node4, node5, domain );
+    return;
+#endif
+  }
+  ::GmfGetLin(iMesh, what, node1, node2, node3, node4, node5, domain );
+}
+
 //================================================================================
 /*!
  * \brief Return node indices of a next prism
@@ -1092,6 +1175,16 @@ int  MG_HYBRID_API::GmfOpenMesh(const char* theFile, int rdOrWr, int ver, int di
 
 void MG_HYBRID_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;
+    case GmfQuadrilaterals: _nbFaces += nb; break;
+    default:;
+    }
+  }
   if ( _useLib ) {
 #ifdef USE_MG_LIBS
     switch ( what ) {
@@ -1230,7 +1323,7 @@ void MG_HYBRID_API::GmfSetLin(int iMesh, GmfKwdCod what, int node1, int node2, i
     return;
 #endif
   }
-  ::GmfSetLin(iMesh, what, node1, node2, node3, domain );
+  ::GmfSetLin(iMesh, what, node1, node2, node3, node4, domain );
 }
 
 //================================================================================