From b2827a21e8c8acea23303fba047be66ae57701cb Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Tue, 22 Nov 2016 19:48:05 +0100 Subject: [PATCH] FEM: GMSH mesh tool, add a pref page for gmsh binary path --- src/Mod/Fem/FemGmshTools.py | 43 ++-- src/Mod/Fem/Gui/AppFemGui.cpp | 2 + src/Mod/Fem/Gui/CMakeLists.txt | 5 + src/Mod/Fem/Gui/DlgSettingsFemGmsh.ui | 230 ++++++++++++++++++++++ src/Mod/Fem/Gui/DlgSettingsFemGmshImp.cpp | 69 +++++++ src/Mod/Fem/Gui/DlgSettingsFemGmshImp.h | 50 +++++ 6 files changed, 384 insertions(+), 15 deletions(-) create mode 100644 src/Mod/Fem/Gui/DlgSettingsFemGmsh.ui create mode 100644 src/Mod/Fem/Gui/DlgSettingsFemGmshImp.cpp create mode 100644 src/Mod/Fem/Gui/DlgSettingsFemGmshImp.h diff --git a/src/Mod/Fem/FemGmshTools.py b/src/Mod/Fem/FemGmshTools.py index f55999a05..a93c37365 100644 --- a/src/Mod/Fem/FemGmshTools.py +++ b/src/Mod/Fem/FemGmshTools.py @@ -34,14 +34,6 @@ import tempfile from platform import system -# CONFIGURATION - EDIT THE FOLLOWING LINE TO MATCH YOUR GMSH BINARY -# gmsh_bin_linux = "/usr/bin/gmsh" -gmsh_bin_linux = "/usr/local/bin/gmsh" -gmsh_bin_windwos = "C:\\Daten\\gmsh-2.13.2-Windows\\gmsh.exe" -gmsh_bin_other = "/usr/bin/gmsh" -# END CONFIGURATION - - class FemGmshTools(): def __init__(self, gmsh_mesh_obj, analysis=None): self.mesh_obj = gmsh_mesh_obj @@ -150,14 +142,35 @@ class FemGmshTools(): print(' ' + self.temp_file_geo) def get_gmsh_command(self): - if system() == "Linux": - self.gmsh_bin = gmsh_bin_linux - elif system() == "Windows": - self.gmsh_bin = gmsh_bin_windwos + self.gmsh_bin = None + gmsh_std_location = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Gmsh").GetBool("UseStandardGmshLocation") + if gmsh_std_location: + if system() == "Windows": + gmsh_path = FreeCAD.getHomePath() + "bin/gmsh.exe" + FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Gmsh").SetString("gmshBinaryPath", gmsh_path) + self.gmsh_bin = gmsh_path + elif system() == "Linux": + p1 = subprocess.Popen(['which', 'gmsh'], stdout=subprocess.PIPE) + if p1.wait() == 0: + gmsh_path = p1.stdout.read().split('\n')[0] + elif p1.wait() == 1: + error_message = "GMSH binary gmsh not found in standard system binary path. Please install gmsh or set path to binary in FEM preferences tab GMSH.\n" + # if FreeCAD.GuiUp: + # QtGui.QMessageBox.critical(None, "No GMSH binary ccx", error_message) + raise Exception(error_message) + self.gmsh_bin = gmsh_path else: - self.gmsh_bin = gmsh_bin_other - self.gmsh_command = self.gmsh_bin + ' - ' + self.temp_file_geo # gmsh - /tmp/shape2mesh.geo - print(' ' + self.gmsh_command) + if not self.gmsh_bin: + self.gmsh_bin = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/Gmsh").GetString("gmshBinaryPath", "") + if not self.gmsh_bin: # in prefs not set, we will try to use something reasonable + if system() == "Linux": + self.gmsh_bin = "gmsh" + elif system() == "Windows": + self.gmsh_bin = FreeCAD.getHomePath() + "bin/gmsh.exe" + else: + self.gmsh_bin = "gmsh" + self.gmsh_bin = self.gmsh_bin + print(' ' + self.gmsh_bin) def get_group_data(self): if self.analysis: diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 840f98aba..e8bb5266d 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -35,6 +35,7 @@ #include "PropertyFemMeshItem.h" #include "DlgSettingsFemGeneralImp.h" #include "DlgSettingsFemCcxImp.h" +#include "DlgSettingsFemGmshImp.h" #include "DlgSettingsFemZ88Imp.h" #include "ViewProviderFemMesh.h" #include "ViewProviderFemMeshShape.h" @@ -154,6 +155,7 @@ PyMODINIT_FUNC initFemGui() // register preferences pages new Gui::PrefPageProducer (QT_TRANSLATE_NOOP("QObject","FEM")); new Gui::PrefPageProducer (QT_TRANSLATE_NOOP("QObject","FEM")); + new Gui::PrefPageProducer (QT_TRANSLATE_NOOP("QObject","FEM")); new Gui::PrefPageProducer (QT_TRANSLATE_NOOP("QObject","FEM")); // add resources and reloads the translators diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 661b7835b..6c4dc2641 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -44,6 +44,7 @@ SOURCE_GROUP("Python" FILES ${Python_SRCS}) set(FemGui_MOC_HDRS DlgSettingsFemCcxImp.h DlgSettingsFemGeneralImp.h + DlgSettingsFemGmshImp.h DlgSettingsFemZ88Imp.h PropertyFemMeshItem.h TaskObjectName.h @@ -83,6 +84,7 @@ SOURCE_GROUP("Moc" FILES ${FemGui_MOC_SRCS}) set(FemGui_UIC_SRCS DlgSettingsFemCcx.ui DlgSettingsFemGeneral.ui + DlgSettingsFemGmsh.ui DlgSettingsFemZ88.ui TaskCreateNodeSet.ui TaskObjectName.ui @@ -125,6 +127,9 @@ SET(FemGui_DLG_SRCS DlgSettingsFemGeneral.ui DlgSettingsFemGeneralImp.cpp DlgSettingsFemGeneralImp.h + DlgSettingsFemGmsh.ui + DlgSettingsFemGmshImp.cpp + DlgSettingsFemGmshImp.h DlgSettingsFemZ88.ui DlgSettingsFemZ88Imp.cpp DlgSettingsFemZ88Imp.h diff --git a/src/Mod/Fem/Gui/DlgSettingsFemGmsh.ui b/src/Mod/Fem/Gui/DlgSettingsFemGmsh.ui new file mode 100644 index 000000000..3be9f8bff --- /dev/null +++ b/src/Mod/Fem/Gui/DlgSettingsFemGmsh.ui @@ -0,0 +1,230 @@ + + + FemGui::DlgSettingsFemGmshImp + + + + 0 + 0 + 372 + 144 + + + + GMSH + + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + GMSH + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + QLayout::SetNoConstraint + + + + + + + Use standard gmsh binary path + + + true + + + UseStandardGmshLocation + + + Mod/Fem/Gmsh + + + + + + + GMSH binary + + + + + + + false + + + + 100 + 0 + + + + gmsh binary path + + + + + + + false + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Leave blank to use default gmsh binary file + + + gmshBinaryPath + + + Mod/Fem/Gmsh + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+ + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+ + Gui::PrefFileChooser + Gui::FileChooser +
Gui/PrefWidgets.h
+
+
+ + + + + + cb_gmsh_binary_std + toggled(bool) + l_gmsh_binary_path + setEnabled(bool) + + + 406 + 45 + + + 148 + 68 + + + + + cb_gmsh_binary_std + toggled(bool) + fc_gmsh_binary_path + setEnabled(bool) + + + 406 + 45 + + + 406 + 68 + + + + + cb_gmsh_binary_std + toggled(bool) + l_gmsh_binary_path + setDisabled(bool) + + + 406 + 45 + + + 148 + 68 + + + + + cb_gmsh_binary_std + toggled(bool) + fc_gmsh_binary_path + setDisabled(bool) + + + 406 + 45 + + + 406 + 68 + + + + +
diff --git a/src/Mod/Fem/Gui/DlgSettingsFemGmshImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemGmshImp.cpp new file mode 100644 index 000000000..adbd5fb9a --- /dev/null +++ b/src/Mod/Fem/Gui/DlgSettingsFemGmshImp.cpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (c) 2016 FreeCAD Developers * + * Author: Bernd Hahnebach * + * Based on src/Mod/Fem/Gui/DlgSettingsFemCcxImp.cpp * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#include "Gui/Application.h" +#include "DlgSettingsFemGmshImp.h" +#include + +using namespace FemGui; + +DlgSettingsFemGmshImp::DlgSettingsFemGmshImp( QWidget* parent ) + : PreferencePage( parent ) +{ + this->setupUi(this); +} + +DlgSettingsFemGmshImp::~DlgSettingsFemGmshImp() +{ + // no need to delete child widgets, Qt does it all for us +} + +void DlgSettingsFemGmshImp::saveSettings() +{ + cb_gmsh_binary_std->onSave(); + fc_gmsh_binary_path->onSave(); +} + +void DlgSettingsFemGmshImp::loadSettings() +{ + cb_gmsh_binary_std->onRestore(); + fc_gmsh_binary_path->onRestore(); +} + +/** + * Sets the strings of the subwidgets using the current language. + */ +void DlgSettingsFemGmshImp::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + } + else { + QWidget::changeEvent(e); + } +} + +#include "moc_DlgSettingsFemGmshImp.cpp" diff --git a/src/Mod/Fem/Gui/DlgSettingsFemGmshImp.h b/src/Mod/Fem/Gui/DlgSettingsFemGmshImp.h new file mode 100644 index 000000000..33596da73 --- /dev/null +++ b/src/Mod/Fem/Gui/DlgSettingsFemGmshImp.h @@ -0,0 +1,50 @@ + /************************************************************************** + * Copyright (c) 2016 FreeCAD Developers * + * Author: Bernd Hahnebach * + * Based on src/Mod/Fem/Gui/DlgSettingsFemCcx.h * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef FEMGUI_DLGSETTINGSFEMGMSHIMP_H +#define FEMGUI_DLGSETTINGSFEMGMSHIMP_H + +#include "ui_DlgSettingsFemGmsh.h" +#include + +namespace FemGui { + +class DlgSettingsFemGmshImp : public Gui::Dialog::PreferencePage, public Ui_DlgSettingsFemGmshImp +{ + Q_OBJECT + +public: + DlgSettingsFemGmshImp( QWidget* parent = 0 ); + ~DlgSettingsFemGmshImp(); + +protected: + void saveSettings(); + void loadSettings(); + void changeEvent(QEvent *e); +}; + +} // namespace FemGui + +#endif // FEMGUI_DLGSETTINGSFEMGMSHIMP_H