Merge branch 'occ/new_mg_licnese' of https://codev-tuleap.cea.fr/plugins/git/salome/smesh into occ/new_mg_licnese

This commit is contained in:
Anthony Geay 2021-09-10 15:24:05 +02:00
commit abc53b03ca
12 changed files with 86 additions and 73 deletions

View File

@ -152,12 +152,16 @@ namespace
0, 0,
NULL NULL
); );
if ( msgLen > 0 ) if ( msgLen > 0 ) {
# if defined( UNICODE )
error = Kernel_Utils::encode_s((wchar_t*)cstr);
# else
error = (char*)cstr; error = (char*)cstr;
# endif
LocalFree(cstr); LocalFree(cstr);
}
return msgLen; return (bool)msgLen;
#endif #endif
} }
@ -259,11 +263,11 @@ namespace
#ifdef WIN32 #ifdef WIN32
std::string outFile = tmpDir + "libMeshGemsKeyGenerator.dll"; std::string outFile = tmpDir + "MeshGemsKeyGenerator.dll";
// use wget (== Invoke-WebRequest) PowerShell command available since Windows 7 // use wget (== Invoke-WebRequest) PowerShell command available since Windows 7
std::string psCmd = "wget -Uri " + url + " -OutFile " + outFile; std::string psCmd = "wget -Uri " + url + " -OutFile " + outFile;
std::string cmd = "start powershell.exe " + psCmd; std::string cmd = "powershell.exe " + psCmd;
#else #else
@ -290,6 +294,8 @@ namespace
if ( ok ) if ( ok )
libraryFile._name = outFile; libraryFile._name = outFile;
else
error = "Can't download file " + url;
return ok; return ok;
} }
@ -372,6 +378,7 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
if ( !loadLibrary( error, libraryFile )) if ( !loadLibrary( error, libraryFile ))
return false; return false;
bool ok = false;
typedef bool (*SignFun)(void* ); typedef bool (*SignFun)(void* );
SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignCAD" ); SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignCAD" );
if ( !signFun ) if ( !signFun )
@ -379,9 +386,8 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
if ( ! getLastError( error )) if ( ! getLastError( error ))
error = SMESH_Comment( "Can't find symbol 'SignCAD' in '") << getenv( theEnvVar ) << "'"; error = SMESH_Comment( "Can't find symbol 'SignCAD' in '") << getenv( theEnvVar ) << "'";
} }
else
bool ok; {
SMESH_TRY; SMESH_TRY;
ok = signFun( meshgems_cad ); ok = signFun( meshgems_cad );
@ -392,7 +398,7 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
ok = false; ok = false;
else if ( !ok ) else if ( !ok )
error = "SignCAD() failed (located in '" + libraryFile._name + "')"; error = "SignCAD() failed (located in '" + libraryFile._name + "')";
}
return ok; return ok;
} }
@ -411,6 +417,7 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
if ( !loadLibrary( error, libraryFile )) if ( !loadLibrary( error, libraryFile ))
return false; return false;
bool ok = false;
typedef bool (*SignFun)(void* ); typedef bool (*SignFun)(void* );
SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignMesh" ); SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignMesh" );
if ( !signFun ) if ( !signFun )
@ -418,8 +425,8 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
if ( ! getLastError( error )) if ( ! getLastError( error ))
error = SMESH_Comment( "Can't find symbol 'SignMesh' in '") << getenv( theEnvVar ) << "'"; 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 );
@ -430,7 +437,7 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
ok = false; ok = false;
else if ( !ok ) else if ( !ok )
error = "SignMesh() failed (located in '" + libraryFile._name + "')"; error = "SignMesh() failed (located in '" + libraryFile._name + "')";
}
return ok; return ok;
} }
@ -463,8 +470,10 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
if ( ! getLastError( error )) if ( ! getLastError( error ))
error = SMESH_Comment( "Can't find symbol 'GetKey' in '") << getenv( theEnvVar ) << "'"; error = SMESH_Comment( "Can't find symbol 'GetKey' in '") << getenv( theEnvVar ) << "'";
} }
else
{
key = keyFun( gmfFile, nbVertex, nbEdge, nbFace, nbVol ); key = keyFun( gmfFile, nbVertex, nbEdge, nbFace, nbVol );
}
if ( key.empty() ) if ( key.empty() )
error = "GetKey() failed (located in '" + libraryFile._name + "')"; error = "GetKey() failed (located in '" + libraryFile._name + "')";

View File

@ -44,7 +44,7 @@ namespace SMESHUtils_MGLicenseKeyGen
int nbVol, int nbVol,
std::string& error); std::string& error);
SMESHUtils_EXPORT bool CheckKeyGeLibrary( std::string& error ); SMESHUtils_EXPORT bool CheckKeyGenLibrary( std::string& error );
SMESHUtils_EXPORT std::string GetLibraryName(); SMESHUtils_EXPORT std::string GetLibraryName();
} }

View File

@ -25,6 +25,8 @@ include_directories(
${PROJECT_SOURCE_DIR}/src/SMDS ${PROJECT_SOURCE_DIR}/src/SMDS
${PROJECT_SOURCE_DIR}/src/SMESH ${PROJECT_SOURCE_DIR}/src/SMESH
${PROJECT_SOURCE_DIR}/src/SMESH_I ${PROJECT_SOURCE_DIR}/src/SMESH_I
${PROJECT_SOURCE_DIR}/src/Driver
${PROJECT_SOURCE_DIR}/src/DriverGMF
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}/idl ${PROJECT_BINARY_DIR}/idl
) )
@ -123,7 +125,7 @@ IF(${CMAKE_VERSION} VERSION_LESS "3.8.0")
ELSE() ELSE()
SWIG_ADD_LIBRARY(SMeshHelper LANGUAGE python SOURCES ${SMeshHelper_SOURCES}) SWIG_ADD_LIBRARY(SMeshHelper LANGUAGE python SOURCES ${SMeshHelper_SOURCES})
ENDIF() ENDIF()
SWIG_LINK_LIBRARIES(SMeshHelper ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SMESHEngine ) SWIG_LINK_LIBRARIES(SMeshHelper ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} SMESHEngine MeshDriverGMF )
SWIG_CHECK_GENERATION(SMeshHelper) SWIG_CHECK_GENERATION(SMeshHelper)
IF(WIN32) IF(WIN32)
SET_TARGET_PROPERTIES(_SMeshHelper PROPERTIES DEBUG_OUTPUT_NAME _SMeshHelper_d) SET_TARGET_PROPERTIES(_SMeshHelper PROPERTIES DEBUG_OUTPUT_NAME _SMeshHelper_d)

View File

@ -25,9 +25,35 @@
#include <cstring> #include <cstring>
#include <DriverGMF_Read.hxx>
#include <SMESH_MGLicenseKeyGen.hxx>
std::string BuildSMESHInstanceInternal() std::string BuildSMESHInstanceInternal()
{ {
Engines::EngineComponent_var zeRef = RetrieveSMESHInstance(); Engines::EngineComponent_var zeRef = RetrieveSMESHInstance();
CORBA::String_var ior = KERNEL::getORB()->object_to_string(zeRef); CORBA::String_var ior = KERNEL::getORB()->object_to_string(zeRef);
return std::string(ior.in()); 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<int>( nbVertex ),
FromSmIdType<int>( nbEdge ),
FromSmIdType<int>( nbFace ),
FromSmIdType<int>( nbVol ),
errorTxt );
if ( !errorTxt.empty() )
{
std::cerr << "Error: Pb with MeshGems license: " << errorTxt << std::endl;
key = "<" + errorTxt + ">";
}
return key;
}

View File

@ -22,3 +22,5 @@
#include <string> #include <string>
std::string BuildSMESHInstanceInternal(); std::string BuildSMESHInstanceInternal();
std::string GetMGLicenseKeyImpl(const char* gmfFile);

View File

@ -31,4 +31,9 @@
{ {
return BuildSMESHInstanceInternal(); return BuildSMESHInstanceInternal();
} }
std::string GetMGLicenseKey(const char* gmfFile)
{
return GetMGLicenseKeyImpl( gmfFile );
}
} }

View File

@ -525,18 +525,6 @@ class MGCleanerMonPlugDialog(Ui_MGCleanerPlugDialog,QWidget):
def PrepareLigneCommande(self): 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" #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 if not self.CB_ComputedOverlapDistance.isChecked(): #computed default
self.commande+=" --overlap_distance " + self.SP_toStr(self.SP_OverlapDistance) self.commande+=" --overlap_distance " + self.SP_toStr(self.SP_OverlapDistance)
self.commande+=" --overlap_angle " + str(self.SP_OverlapAngle.value()) 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)) if verbose: print(("INFO: MGCCleaner command:\n %s" % self.commande))
return True return True

View File

@ -35,11 +35,6 @@ from MGCleanerViewText_ui import Ui_ViewExe
verbose = True 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): class MGCleanerMonViewText(Ui_ViewExe, QDialog):
""" """
Classe permettant la visualisation de texte Classe permettant la visualisation de texte

View File

@ -31,15 +31,6 @@ def MGCleanerLct(context):
import tempfile import tempfile
from qtsalome import QFileDialog, QMessageBox 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 import MGCleanerMonPlugDialog
window = MGCleanerMonPlugDialog.getDialog() window = MGCleanerMonPlugDialog.getDialog()
window.show() window.show()

View File

@ -34,11 +34,6 @@ from ViewText_ui import Ui_ViewExe
verbose = True 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): class MonViewText(Ui_ViewExe, QDialog):
""" """
Classe permettant la visualisation de texte Classe permettant la visualisation de texte

View File

@ -546,6 +546,10 @@ class MonYamsPlugDialog(Ui_YamsPlugDialog,QWidget):
self.commande+=' --in "' + self.fichierIn +'"' self.commande+=' --in "' + self.fichierIn +'"'
self.commande+=' --out "' + self.fichierOut +'"' self.commande+=' --out "' + self.fichierOut +'"'
import SMeshHelper
key = SMeshHelper.GetMGLicenseKey( self.fichierIn )
self.commande+=' --key ' + key
print(self.commande) print(self.commande)
return True return True

View File

@ -31,15 +31,6 @@ def YamsLct(context):
import tempfile import tempfile
from qtsalome import QFileDialog, QMessageBox 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 import monYamsPlugDialog
window = monYamsPlugDialog.getDialog() window = monYamsPlugDialog.getDialog()
window.show() window.show()