diff --git a/src/SMESHUtils/SMESH_MGLicenseKeyGen.cxx b/src/SMESHUtils/SMESH_MGLicenseKeyGen.cxx index 99336c6a3..ec06d9885 100644 --- a/src/SMESHUtils/SMESH_MGLicenseKeyGen.cxx +++ b/src/SMESHUtils/SMESH_MGLicenseKeyGen.cxx @@ -152,12 +152,16 @@ namespace 0, NULL ); - if ( msgLen > 0 ) - error = (char*) cstr; + if ( msgLen > 0 ) { +# if defined( UNICODE ) + error = Kernel_Utils::encode_s((wchar_t*)cstr); +# else + error = (char*)cstr; +# endif + LocalFree(cstr); + } - LocalFree(cstr); - - return msgLen; + return (bool)msgLen; #endif } @@ -259,11 +263,11 @@ namespace #ifdef WIN32 - std::string outFile = tmpDir + "libMeshGemsKeyGenerator.dll"; + std::string outFile = tmpDir + "MeshGemsKeyGenerator.dll"; // use wget (== Invoke-WebRequest) PowerShell command available since Windows 7 std::string psCmd = "wget -Uri " + url + " -OutFile " + outFile; - std::string cmd = "start powershell.exe " + psCmd; + std::string cmd = "powershell.exe " + psCmd; #else @@ -290,6 +294,8 @@ namespace if ( ok ) libraryFile._name = outFile; + else + error = "Can't download file " + url; return ok; } @@ -372,27 +378,27 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation if ( !loadLibrary( error, libraryFile )) return false; + bool ok = false; typedef bool (*SignFun)(void* ); - SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignCAD" ); + SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignCAD" ); if ( !signFun ) { if ( ! getLastError( error )) error = SMESH_Comment( "Can't find symbol 'SignCAD' in '") << getenv( theEnvVar ) << "'"; } + else + { + SMESH_TRY; - bool ok; + ok = signFun( meshgems_cad ); - SMESH_TRY; - - ok = signFun( meshgems_cad ); - - SMESH_CATCH( SMESH::returnError ); - - if ( !error.empty() ) - ok = false; - else if ( !ok ) - error = "SignCAD() failed (located in '" + libraryFile._name + "')"; + SMESH_CATCH( SMESH::returnError ); + if ( !error.empty() ) + ok = false; + else if ( !ok ) + error = "SignCAD() failed (located in '" + libraryFile._name + "')"; + } return ok; } @@ -411,6 +417,7 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation if ( !loadLibrary( error, libraryFile )) return false; + bool ok = false; typedef bool (*SignFun)(void* ); SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignMesh" ); if ( !signFun ) @@ -418,19 +425,19 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation if ( ! getLastError( error )) error = SMESH_Comment( "Can't find symbol 'SignMesh' in '") << getenv( theEnvVar ) << "'"; } - bool ok; + else + { + SMESH_TRY; - SMESH_TRY; + ok = signFun( meshgems_mesh ); - ok = signFun( meshgems_mesh ); - - SMESH_CATCH( SMESH::returnError ); - - if ( !error.empty() ) - ok = false; - else if ( !ok ) - error = "SignMesh() failed (located in '" + libraryFile._name + "')"; + SMESH_CATCH( SMESH::returnError ); + if ( !error.empty() ) + ok = false; + else if ( !ok ) + error = "SignMesh() failed (located in '" + libraryFile._name + "')"; + } return ok; } @@ -463,8 +470,10 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation if ( ! getLastError( error )) error = SMESH_Comment( "Can't find symbol 'GetKey' in '") << getenv( theEnvVar ) << "'"; } - key = keyFun( gmfFile, nbVertex, nbEdge, nbFace, nbVol ); - + else + { + key = keyFun( gmfFile, nbVertex, nbEdge, nbFace, nbVol ); + } if ( key.empty() ) error = "GetKey() failed (located in '" + libraryFile._name + "')"; diff --git a/src/SMESHUtils/SMESH_MGLicenseKeyGen.hxx b/src/SMESHUtils/SMESH_MGLicenseKeyGen.hxx index c81fa3090..796cde4b5 100644 --- a/src/SMESHUtils/SMESH_MGLicenseKeyGen.hxx +++ b/src/SMESHUtils/SMESH_MGLicenseKeyGen.hxx @@ -44,7 +44,7 @@ namespace SMESHUtils_MGLicenseKeyGen int nbVol, std::string& error); - SMESHUtils_EXPORT bool CheckKeyGeLibrary( std::string& error ); + SMESHUtils_EXPORT bool CheckKeyGenLibrary( std::string& error ); SMESHUtils_EXPORT std::string GetLibraryName(); } diff --git a/src/SMESH_SWIG/CMakeLists.txt b/src/SMESH_SWIG/CMakeLists.txt index 53b87e321..bd3a578d4 100644 --- a/src/SMESH_SWIG/CMakeLists.txt +++ b/src/SMESH_SWIG/CMakeLists.txt @@ -25,6 +25,8 @@ include_directories( ${PROJECT_SOURCE_DIR}/src/SMDS ${PROJECT_SOURCE_DIR}/src/SMESH ${PROJECT_SOURCE_DIR}/src/SMESH_I + ${PROJECT_SOURCE_DIR}/src/Driver + ${PROJECT_SOURCE_DIR}/src/DriverGMF ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BINARY_DIR}/idl ) @@ -123,7 +125,7 @@ IF(${CMAKE_VERSION} VERSION_LESS "3.8.0") ELSE() SWIG_ADD_LIBRARY(SMeshHelper LANGUAGE python SOURCES ${SMeshHelper_SOURCES}) ENDIF() -SWIG_LINK_LIBRARIES(SMeshHelper ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SMESHEngine ) +SWIG_LINK_LIBRARIES(SMeshHelper ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SMESHEngine MeshDriverGMF ) SWIG_CHECK_GENERATION(SMeshHelper) IF(WIN32) SET_TARGET_PROPERTIES(_SMeshHelper PROPERTIES DEBUG_OUTPUT_NAME _SMeshHelper_d) diff --git a/src/SMESH_SWIG/SMeshHelper.cxx b/src/SMESH_SWIG/SMeshHelper.cxx index ee2d54b05..92991e20c 100644 --- a/src/SMESH_SWIG/SMeshHelper.cxx +++ b/src/SMESH_SWIG/SMeshHelper.cxx @@ -25,9 +25,35 @@ #include +#include +#include + + std::string BuildSMESHInstanceInternal() { Engines::EngineComponent_var zeRef = RetrieveSMESHInstance(); CORBA::String_var ior = KERNEL::getORB()->object_to_string(zeRef); return std::string(ior.in()); } + +std::string GetMGLicenseKeyImpl(const char* gmfFile) +{ + smIdType nbVertex, nbEdge, nbFace, nbVol; + DriverGMF_Read gmfReader; + gmfReader.SetFile( gmfFile ); + gmfReader.GetMeshInfo( nbVertex, nbEdge, nbFace, nbVol ); + + std::string errorTxt; + std::string key = SMESHUtils_MGLicenseKeyGen::GetKey( gmfFile, + FromSmIdType( nbVertex ), + FromSmIdType( nbEdge ), + FromSmIdType( nbFace ), + FromSmIdType( nbVol ), + errorTxt ); + if ( !errorTxt.empty() ) + { + std::cerr << "Error: Pb with MeshGems license: " << errorTxt << std::endl; + key = "<" + errorTxt + ">"; + } + return key; +} diff --git a/src/SMESH_SWIG/SMeshHelper.h b/src/SMESH_SWIG/SMeshHelper.h index 58b2c5321..9c912869e 100644 --- a/src/SMESH_SWIG/SMeshHelper.h +++ b/src/SMESH_SWIG/SMeshHelper.h @@ -22,3 +22,5 @@ #include std::string BuildSMESHInstanceInternal(); + +std::string GetMGLicenseKeyImpl(const char* gmfFile); diff --git a/src/SMESH_SWIG/SMeshHelper.i b/src/SMESH_SWIG/SMeshHelper.i index b73a87db9..d1220cb90 100644 --- a/src/SMESH_SWIG/SMeshHelper.i +++ b/src/SMESH_SWIG/SMeshHelper.i @@ -31,4 +31,9 @@ { return BuildSMESHInstanceInternal(); } + + std::string GetMGLicenseKey(const char* gmfFile) + { + return GetMGLicenseKeyImpl( gmfFile ); + } } diff --git a/src/Tools/MGCleanerPlug/MGCleanerMonPlugDialog.py b/src/Tools/MGCleanerPlug/MGCleanerMonPlugDialog.py index c701b3449..f5c226b87 100644 --- a/src/Tools/MGCleanerPlug/MGCleanerMonPlugDialog.py +++ b/src/Tools/MGCleanerPlug/MGCleanerMonPlugDialog.py @@ -525,18 +525,6 @@ class MGCleanerMonPlugDialog(Ui_MGCleanerPlugDialog,QWidget): def PrepareLigneCommande(self): """ - #use doc examples of mg-cleaner: - ls -al /data/tmplgls/salome/prerequis/install/COMMON_64/MeshGems-1.0/bin - source /data/tmplgls/salome/prerequis/install/LICENSE/dlim8.var.sh - export PATH=/data/tmplgls/salome/prerequis/install/COMMON_64/MeshGems-1.0/bin/Linux_64:$PATH - cp -r /data/tmplgls/salome/prerequis/install/COMMON_64/MeshGems-1.0/examples . - cd examples - mg-cleaner.exe --help - mg-cleaner.exe --in case7.mesh --out case7-test.mesh --check - mg-cleaner.exe case7.mesh case7-fix.mesh --fix - mg-cleaner.exe --in Porsche.mesh --out Porsche-test.mesh --check - mg-cleaner.exe --in Porsche.mesh --out Porschefix.mesh --fix - mg-cleaner.exe --in Porsche.mesh --out PorscheNewfix.mesh --fix --resolution_length 0.03 """ #self.commande="mg-cleaner.exe --in " + self.fichierIn + " --out " + self.fichierOut + " --fix2pass" @@ -577,6 +565,11 @@ class MGCleanerMonPlugDialog(Ui_MGCleanerPlugDialog,QWidget): if not self.CB_ComputedOverlapDistance.isChecked(): #computed default self.commande+=" --overlap_distance " + self.SP_toStr(self.SP_OverlapDistance) self.commande+=" --overlap_angle " + str(self.SP_OverlapAngle.value()) + + import SMeshHelper + key = SMeshHelper.GetMGLicenseKey( self.fichierIn ) + self.commande+=' --key ' + key + if verbose: print(("INFO: MGCCleaner command:\n %s" % self.commande)) return True diff --git a/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py b/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py index 5df87ad6a..a117ed2e9 100644 --- a/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py +++ b/src/Tools/MGCleanerPlug/MGCleanerMonViewText.py @@ -35,11 +35,6 @@ from MGCleanerViewText_ui import Ui_ViewExe verbose = True -force = os.getenv("FORCE_DISTENE_LICENSE_FILE") -if force != None: - os.environ["DISTENE_LICENSE_FILE"] = force - os.environ["DLIM8VAR"] = "NOTHING" - class MGCleanerMonViewText(Ui_ViewExe, QDialog): """ Classe permettant la visualisation de texte diff --git a/src/Tools/MGCleanerPlug/MGCleanerplug_plugin.py b/src/Tools/MGCleanerPlug/MGCleanerplug_plugin.py index 1058e658c..7bc19e021 100644 --- a/src/Tools/MGCleanerPlug/MGCleanerplug_plugin.py +++ b/src/Tools/MGCleanerPlug/MGCleanerplug_plugin.py @@ -31,15 +31,6 @@ def MGCleanerLct(context): import tempfile from qtsalome import QFileDialog, QMessageBox - #prior test to avoid unnecessary user GUI work with ending crash - try : - os.environ['DISTENE_LICENSE_FILE'] - except: - QMessageBox.warning(None, "Products", """\ -Distene's product MeshGem Cleaner is not installed. -required environment variable: -DISTENE_LICENSE_FILE='.../dlim8.var.sh'""") - return import MGCleanerMonPlugDialog window = MGCleanerMonPlugDialog.getDialog() window.show() diff --git a/src/Tools/YamsPlug/monViewText.py b/src/Tools/YamsPlug/monViewText.py index eb371b0f1..082c9fa01 100644 --- a/src/Tools/YamsPlug/monViewText.py +++ b/src/Tools/YamsPlug/monViewText.py @@ -34,11 +34,6 @@ from ViewText_ui import Ui_ViewExe verbose = True -force = os.getenv("FORCE_DISTENE_LICENSE_FILE") -if force != None: - os.environ["DISTENE_LICENSE_FILE"] = force - os.environ["DLIM8VAR"] = "NOTHING" - class MonViewText(Ui_ViewExe, QDialog): """ Classe permettant la visualisation de texte diff --git a/src/Tools/YamsPlug/monYamsPlugDialog.py b/src/Tools/YamsPlug/monYamsPlugDialog.py index 63efd6c2d..477a2b4e4 100644 --- a/src/Tools/YamsPlug/monYamsPlugDialog.py +++ b/src/Tools/YamsPlug/monYamsPlugDialog.py @@ -545,6 +545,10 @@ class MonYamsPlugDialog(Ui_YamsPlugDialog,QWidget): self.commande+=' --in "' + self.fichierIn +'"' self.commande+=' --out "' + self.fichierOut +'"' + + import SMeshHelper + key = SMeshHelper.GetMGLicenseKey( self.fichierIn ) + self.commande+=' --key ' + key print(self.commande) return True diff --git a/src/Tools/YamsPlug/yamsplug_plugin.py b/src/Tools/YamsPlug/yamsplug_plugin.py index 278406503..4a0b005fb 100644 --- a/src/Tools/YamsPlug/yamsplug_plugin.py +++ b/src/Tools/YamsPlug/yamsplug_plugin.py @@ -31,15 +31,6 @@ def YamsLct(context): import tempfile from qtsalome import QFileDialog, QMessageBox - #prior test to avoid unnecessary user GUI work with ending crash - try : - os.environ['DISTENE_LICENSE_FILE'] - except: - QMessageBox.warning(None,"Products","""\ -Distene's product MeshGem SurfOpt is not installed. -required environment variable: -DISTENE_LICENSE_FILE='.../dlim8.var.sh'""") - return import monYamsPlugDialog window = monYamsPlugDialog.getDialog() window.show()