From: Konstantin Leontev Date: Tue, 14 May 2024 19:50:43 +0000 (+0100) Subject: [bos #40653][CEA] New mesh import export formats with meshio. X-Git-Tag: V9_13_0a1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e85c9d5b6b1c386840d0dca5d8c3c28ad562c6c1;p=modules%2Fsmesh.git [bos #40653][CEA] New mesh import export formats with meshio. Added using MESHIO_VERSION env variable to detect meshio version. Exodus format removed from a file filter on Windows. --- diff --git a/src/SMESHGUI/SMESHGUI_Meshio.cxx b/src/SMESHGUI/SMESHGUI_Meshio.cxx index 048dd4ac3..10fb582c2 100644 --- a/src/SMESHGUI/SMESHGUI_Meshio.cxx +++ b/src/SMESHGUI/SMESHGUI_Meshio.cxx @@ -137,7 +137,9 @@ const QStringList& SMESHGUI_Meshio::GetExportFileFilter() "AVS-UCD (*.avs)", "CGNS (*.cgns)", "DOLFIN XML (*.xml)", +#if !defined(WIN32) "Exodus (*.e *.exo)", +#endif "FLAC3D (*.f3grid)", "Gmsh 2.2 (*.msh)", "Gmsh 4.0, and 4.1 (*.msh)", @@ -241,19 +243,7 @@ QString SMESHGUI_Meshio::GetFileName(QString& selectedFilter, const bool isOpen/ */ bool SMESHGUI_Meshio::IsMeshioInstalled() { - auto IsAbleToCallMeshio = []() -> bool - { - // Try to call meshio to check if it's present - const std::string cmd = - SMESH_Meshio::IsModernPythonVersion() ? "meshio --version" : "meshio-info --version"; - - const int status = system(cmd.c_str()); - MESSAGE("status: " << status); - - return status == 0; - }; - - static const bool isInstalled = IsAbleToCallMeshio(); + const bool isInstalled = SMESH_Meshio::IsMeshioInstalled(); if (!isInstalled) { SUIT_MessageBox::warning( diff --git a/src/SMESH_I/SMESH_Meshio.cxx b/src/SMESH_I/SMESH_Meshio.cxx index d23d52c6c..6e744669f 100644 --- a/src/SMESH_I/SMESH_Meshio.cxx +++ b/src/SMESH_I/SMESH_Meshio.cxx @@ -71,7 +71,7 @@ SMESH_Meshio::~SMESH_Meshio() void SMESH_Meshio::Convert(const QString& sourceFileName, const QString& targetFileName) const { // Execute meshio convert command - const QString convert = IsModernPythonVersion() ? "meshio convert " : "meshio-convert "; + const QString convert = IsModernMeshioVersion() ? "meshio convert " : "meshio-convert "; const QString optArgs = GetConvertOptArgs(); const std::string cmd = @@ -128,6 +128,133 @@ void SMESH_Meshio::RemoveTempFile() } } +/*! + Returns meshio version string that has valid integer at least in the first position. +*/ +QString SMESH_Meshio::GetMeshioVersion() +{ + auto IsVersionStringValid = [](const QString& version) -> bool + { + if (version.isEmpty()) + { + return false; + } + + // Check if we have an integer at least at the first position + const QStringList curVersionNums = version.split('.'); + + bool ok; + const int firstNum = curVersionNums[0].toInt(&ok); + if (!ok) + { + ERROR_MESSAGE("meshio version value is not valid!"); + return false; + } + + MESSAGE("meshio version first number: " << firstNum); + return true; + }; + + auto GetMeshioVersionFromEnv = []() -> QString + { + const char *envVar = std::getenv("MESHIO_VERSION"); + if (envVar && (envVar[0] != '\0')) + { + MESSAGE("MESHIO_VERSION: " << envVar); + return envVar; + } + + MESSAGE("MESHIO_VERSION is not set!"); + return {}; + }; + + auto GetMeshioVersionHelper = [&]() -> QString + { + // Check if we can get a version from environment + const QString meshioVersionEnv = GetMeshioVersionFromEnv(); + if (IsVersionStringValid(meshioVersionEnv)) + { + return meshioVersionEnv; + } + + // Try to gess a version by installed Python version + const QString meshioVersionByPython = IsModernPythonVersion() ? "5" : "4"; + MESSAGE("meshio version was defined by Python version: " << meshioVersionByPython.toStdString()); + + return meshioVersionByPython; + }; + + static const QString meshioVersion = GetMeshioVersionHelper(); + return meshioVersion; +}; + +/*! + Returns true if we're going to use meshio version of 5.0 or greater. +*/ +bool SMESH_Meshio::IsModernMeshioVersion() +{ + // It's a version when meshio commands were changed from using + // many executables for each operation to one for everything (meshio 5.0). + // For example, from + // meshio-convert input.msh output.vtk + // to + // meshio convert input.msh output.vtk + + auto IsModernVersion = [&]() -> bool + { + const QString curVersion = GetMeshioVersion(); + + const int minReqVersion = 5; + const QStringList curVersionNums = curVersion.split('.'); + if (minReqVersion > curVersionNums[0].toInt()) + { + return false; + } + + return true; + }; + + static const bool isModern = IsModernVersion(); + return isModern; +} + +/*! + Returns true if meshio is installed +*/ +bool SMESH_Meshio::IsMeshioInstalled() +{ + auto IsAllowedFromEnvironment = []() -> bool + { + const QString curVersion = GetMeshioVersion(); + + // Check if we explicitly set off using of meshio from environment + const QStringList curVersionNums = curVersion.split('.'); + const int firstNum = curVersionNums[0].toInt(); + if (firstNum <= 0) + { + MESSAGE("meshio was set as not installed from an environment"); + return false; + } + + return true; + }; + + auto IsAbleToCallMeshio = []() -> bool + { + // Try to call meshio to check if it's present + const std::string cmd = + SMESH_Meshio::IsModernMeshioVersion() ? "meshio --version" : "meshio-info --version"; + + const int status = system(cmd.c_str()); + MESSAGE("status: " << status); + + return status == 0; + }; + + static const bool isInstalled = IsAllowedFromEnvironment() && IsAbleToCallMeshio(); + return isInstalled; +} + /*! Returns true if current Python equal or newer than required version for meshio release from 5.0 and greater. diff --git a/src/SMESH_I/SMESH_Meshio.h b/src/SMESH_I/SMESH_Meshio.h index efb41b0bf..2263f5c78 100644 --- a/src/SMESH_I/SMESH_Meshio.h +++ b/src/SMESH_I/SMESH_Meshio.h @@ -42,6 +42,9 @@ public: QString CreateTempFileName(const QString& targetFileName); void Convert(const QString& sourceFileName, const QString& targetFileName) const; + static QString GetMeshioVersion(); + static bool IsModernMeshioVersion(); + static bool IsMeshioInstalled(); static bool IsModernPythonVersion(); private: diff --git a/test/SMESH_MeshioShapes.py b/test/SMESH_MeshioShapes.py index f77d7a999..914c8b9b9 100644 --- a/test/SMESH_MeshioShapes.py +++ b/test/SMESH_MeshioShapes.py @@ -37,6 +37,8 @@ from salome.smesh import smeshBuilder import SALOME +import platform + # Constants EXPORT_TITLE = 'Export' IMPORT_TITLE = 'Import' @@ -92,7 +94,7 @@ def file_extensions(): Commented formats should be checked on next meshio release to see if the problem was fixed. """ - return [ + extensions = [ '.avs', '.bdf', # '.cgns', # meshio IndexError: index 2 is out of bounds for axis 1 with size 2 @@ -131,7 +133,10 @@ def file_extensions(): '.xmf', '.xml' ] + if platform.system() == 'Windows': + extensions = [ext for ext in extensions if not ext in ['.e', '.exo']] # needs to be digged out - presumably an issue about encoding. + return extensions def exception_handle(file_name, errors, operation_type, ex_text): """