From b5ed48f56497242b14f495cc29a0b3e3eeca5fc9 Mon Sep 17 00:00:00 2001 From: hyx0329 Date: Tue, 11 Jun 2024 23:35:16 +0800 Subject: [PATCH 1/3] Fem: fix and improve searching 3rd-party binaries --- src/Mod/Fem/App/FemTools.cpp | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Mod/Fem/App/FemTools.cpp b/src/Mod/Fem/App/FemTools.cpp index 3739f2c42e..fedbe2fe8f 100644 --- a/src/Mod/Fem/App/FemTools.cpp +++ b/src/Mod/Fem/App/FemTools.cpp @@ -23,7 +23,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include +#include +#include #include #include @@ -300,29 +301,33 @@ std::string Fem::Tools::checkIfBinaryExists(std::string prefSection, bool knownDirectories = hGrp->GetBool(knownDirectoriesString.c_str(), true); if (knownDirectories) { -#if defined(FC_OS_WIN32) - binaryName = binaryName + ".exe"; -#endif - // first check the environment paths by QFileInfo - if (QFileInfo::exists(QString::fromLatin1(binaryName.c_str()))) { - return binaryName; + // first check the environment paths, normally determined by the PATH environment variable + // On Windows, the executable extensions(".exe" etc.) should be automatically appended + QString executablePath = + QStandardPaths::findExecutable(QString::fromLatin1(binaryName.c_str())); + if (!executablePath.isEmpty()) { + return executablePath.toStdString(); } // check the folder of the FreeCAD binary else { - auto homePathBinary = App::Application::getHomePath() + "bin/" + binaryName; - if (QFileInfo::exists(QString::fromLatin1(homePathBinary.c_str()))) { - return binaryName; + auto appBinaryPath = App::Application::getHomePath() + "bin/"; + QStringList pathCandidates = {QString::fromLatin1(appBinaryPath.c_str())}; + QString executablePath = + QStandardPaths::findExecutable(QString::fromLatin1(binaryName.c_str()), + pathCandidates); + if (!executablePath.isEmpty()) { + return executablePath.toStdString(); } } } else { auto binaryPathString = prefBinaryName + "BinaryPath"; - ParameterGrp::handle hGrp = - App::GetApplication().GetParameterGroupByPath(paramPath.c_str()); - auto binaryPath = hGrp->GetASCII(binaryPathString.c_str(), ""); - QFileInfo::exists(QString::fromLatin1(binaryPath.c_str())); - if (QFileInfo::exists(QString::fromLatin1(binaryPath.c_str()))) { - return binaryPath; + // use binary path from settings, fall back to system path if not defined + auto binaryPath = hGrp->GetASCII(binaryPathString.c_str(), binaryName.c_str()); + QString executablePath = + QStandardPaths::findExecutable(QString::fromLatin1(binaryPath.c_str())); + if (!executablePath.isEmpty()) { + return executablePath.toStdString(); } } return ""; From 3caabad54dec70673304be75f5e580bd4066214b Mon Sep 17 00:00:00 2001 From: hyx0329 Date: Tue, 11 Jun 2024 23:14:31 +0800 Subject: [PATCH 2/3] Fem: fix ccx config section string used in UI code --- src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp | 2 +- src/Mod/Fem/Gui/Workbench.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp index 1cf03d90bf..1d6182261d 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp +++ b/src/Mod/Fem/Gui/DlgSettingsFemGeneralImp.cpp @@ -43,7 +43,7 @@ DlgSettingsFemGeneralImp::DlgSettingsFemGeneralImp(QWidget* parent) ui->cmb_def_solver->clear(); std::vector Solvers = {"None"}; - if (!Fem::Tools::checkIfBinaryExists("CCX", "ccx", "ccx").empty()) { + if (!Fem::Tools::checkIfBinaryExists("Ccx", "ccx", "ccx").empty()) { Solvers.emplace_back("CalculiX"); } if (!Fem::Tools::checkIfBinaryExists("Elmer", "elmer", "ElmerSolver").empty()) { diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 2f2600013d..e2ea74f046 100644 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -167,7 +167,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* solve = new Gui::ToolBarItem(root); solve->setCommand("Solve"); - if (!Fem::Tools::checkIfBinaryExists("CCX", "ccx", "ccx").empty()) { + if (!Fem::Tools::checkIfBinaryExists("Ccx", "ccx", "ccx").empty()) { *solve << "FEM_SolverCalculiXCcxTools"; } if (!Fem::Tools::checkIfBinaryExists("Elmer", "elmer", "ElmerSolver").empty()) { From 635131355417c8b5b6423f5069e5ff6c6fd0685d Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Wed, 10 Jul 2024 08:57:25 -0500 Subject: [PATCH 3/3] FEM: Add QStandardPaths to PreCompiled.h --- src/Mod/Fem/App/PreCompiled.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Mod/Fem/App/PreCompiled.h b/src/Mod/Fem/App/PreCompiled.h index 1adfb01bb4..5d0cc033eb 100644 --- a/src/Mod/Fem/App/PreCompiled.h +++ b/src/Mod/Fem/App/PreCompiled.h @@ -54,6 +54,7 @@ #include #include +#include // Salomesh #include