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 ""; 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 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()) {