FEM: GMSH mesh tool, add a pref page for gmsh binary path

This commit is contained in:
Bernd Hahnebach 2016-11-22 19:48:05 +01:00
parent ae90dd0522
commit b2827a21e8
6 changed files with 384 additions and 15 deletions

View File

@ -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:

View File

@ -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<FemGui::DlgSettingsFemGeneralImp> (QT_TRANSLATE_NOOP("QObject","FEM"));
new Gui::PrefPageProducer<FemGui::DlgSettingsFemCcxImp> (QT_TRANSLATE_NOOP("QObject","FEM"));
new Gui::PrefPageProducer<FemGui::DlgSettingsFemGmshImp> (QT_TRANSLATE_NOOP("QObject","FEM"));
new Gui::PrefPageProducer<FemGui::DlgSettingsFemZ88Imp> (QT_TRANSLATE_NOOP("QObject","FEM"));
// add resources and reloads the translators

View File

@ -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

View File

@ -0,0 +1,230 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FemGui::DlgSettingsFemGmshImp</class>
<widget class="QWidget" name="FemGui::DlgSettingsFemGmshImp">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>372</width>
<height>144</height>
</rect>
</property>
<property name="windowTitle">
<string>GMSH</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="gb_gmsh_param">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="title">
<string>GMSH</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item>
<layout class="QGridLayout" name="gl_01">
<item row="0" column="2">
<widget class="Gui::PrefCheckBox" name="cb_gmsh_binary_std">
<property name="text">
<string>Use standard gmsh binary path</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>UseStandardGmshLocation</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Fem/Gmsh</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="l_gmsh_binary_std">
<property name="text">
<string>GMSH binary</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="l_gmsh_binary_path">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>gmsh binary path</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="Gui::PrefFileChooser" name="fc_gmsh_binary_path" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Leave blank to use default gmsh binary file</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>gmshBinaryPath</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Fem/Gmsh</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::FileChooser</class>
<extends>QWidget</extends>
<header>Gui/FileDialog.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefFileChooser</class>
<extends>Gui::FileChooser</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Resources/Fem.qrc"/>
</resources>
<connections>
<connection>
<sender>cb_gmsh_binary_std</sender>
<signal>toggled(bool)</signal>
<receiver>l_gmsh_binary_path</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>406</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>148</x>
<y>68</y>
</hint>
</hints>
</connection>
<connection>
<sender>cb_gmsh_binary_std</sender>
<signal>toggled(bool)</signal>
<receiver>fc_gmsh_binary_path</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>406</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>406</x>
<y>68</y>
</hint>
</hints>
</connection>
<connection>
<sender>cb_gmsh_binary_std</sender>
<signal>toggled(bool)</signal>
<receiver>l_gmsh_binary_path</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>406</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>148</x>
<y>68</y>
</hint>
</hints>
</connection>
<connection>
<sender>cb_gmsh_binary_std</sender>
<signal>toggled(bool)</signal>
<receiver>fc_gmsh_binary_path</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>406</x>
<y>45</y>
</hint>
<hint type="destinationlabel">
<x>406</x>
<y>68</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (c) 2016 FreeCAD Developers *
* Author: Bernd Hahnebach <bernd@bimstatik.ch> *
* 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 <Gui/PrefWidgets.h>
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"

View File

@ -0,0 +1,50 @@
/**************************************************************************
* Copyright (c) 2016 FreeCAD Developers *
* Author: Bernd Hahnebach <bernd@bimstatik.ch> *
* 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 <Gui/PropertyPage.h>
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