"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)",
*/
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(
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 =
}
}
+/*!
+ 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.