Merge pull request #14495 from hyx0329/bugfix/fem-binary-detection-in-PATH
Fem: fix searching 3rd-party binaries in system path
This commit is contained in:
@@ -23,7 +23,8 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
#include <QStringList>
|
||||
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
@@ -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 "";
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
|
||||
#include <Python.h>
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
|
||||
// Salomesh
|
||||
#include <SMDSAbs_ElementType.hxx>
|
||||
|
||||
@@ -43,7 +43,7 @@ DlgSettingsFemGeneralImp::DlgSettingsFemGeneralImp(QWidget* parent)
|
||||
ui->cmb_def_solver->clear();
|
||||
std::vector<std::string> 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()) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user