From d13c279d5abb5c27784f655ed890a5ba07518d52 Mon Sep 17 00:00:00 2001 From: Przemo Firszt Date: Tue, 31 Mar 2015 16:31:10 +0100 Subject: [PATCH] FEM: Add preferences dialog This patch add FEM preferrences dialog. There is currently only one option to define if internal or external editor should be used to open CalculiX input .inp files. Disabling internal editor allows to define path to external editor. Signed-off-by: Przemo Firszt --- src/Mod/Fem/Gui/AppFemGui.cpp | 4 + src/Mod/Fem/Gui/CMakeLists.txt | 5 + src/Mod/Fem/Gui/DlgSettingsFem.ui | 200 ++ src/Mod/Fem/Gui/DlgSettingsFemImp.cpp | 69 + src/Mod/Fem/Gui/DlgSettingsFemImp.h | 50 + src/Mod/Fem/Gui/Resources/Fem.qrc | 1 + .../Gui/Resources/icons/preferences-fem.svg | 1692 +++++++++++++++++ src/Mod/Fem/MechanicalAnalysis.py | 29 +- 8 files changed, 2035 insertions(+), 15 deletions(-) create mode 100644 src/Mod/Fem/Gui/DlgSettingsFem.ui create mode 100644 src/Mod/Fem/Gui/DlgSettingsFemImp.cpp create mode 100644 src/Mod/Fem/Gui/DlgSettingsFemImp.h create mode 100755 src/Mod/Fem/Gui/Resources/icons/preferences-fem.svg diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index 45518d124..3417a5787 100755 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -30,7 +30,9 @@ #include #include #include +#include #include +#include "DlgSettingsFemImp.h" #include "ViewProviderFemMesh.h" #include "ViewProviderFemMeshShape.h" #include "ViewProviderFemMeshShapeNetgen.h" @@ -103,6 +105,8 @@ void FemGuiExport initFemGui() Base::Interpreter().loadModule("FemLib"); + // register preferences pages + new Gui::PrefPageProducer ("FEM"); // add resources and reloads the translators loadFemResource(); diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index fefd63fd5..3c2f0c047 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -41,6 +41,7 @@ SOURCE_GROUP("Python" FILES ${Python_SRCS}) set(FemGui_MOC_HDRS + DlgSettingsFemImp.h Hypothesis.h TaskObjectName.h TaskCreateNodeSet.h @@ -61,6 +62,7 @@ fc_wrap_cpp(FemGui_MOC_SRCS ${FemGui_MOC_HDRS}) SOURCE_GROUP("Moc" FILES ${FemGui_MOC_SRCS}) set(FemGui_UIC_SRCS + DlgSettingsFem.ui Hypothesis.ui TaskCreateNodeSet.ui TaskObjectName.ui @@ -76,6 +78,9 @@ qt4_wrap_ui(FemGui_UIC_HDRS ${FemGui_UIC_SRCS}) SET(FemGui_DLG_SRCS ${FemGui_UIC_HDRS} + DlgSettingsFem.ui + DlgSettingsFemImp.cpp + DlgSettingsFemImp.h Hypothesis.ui Hypothesis.cpp Hypothesis.h diff --git a/src/Mod/Fem/Gui/DlgSettingsFem.ui b/src/Mod/Fem/Gui/DlgSettingsFem.ui new file mode 100644 index 000000000..5b02f2283 --- /dev/null +++ b/src/Mod/Fem/Gui/DlgSettingsFem.ui @@ -0,0 +1,200 @@ + + + FemGui::DlgSettingsFemImp + + + + 0 + 0 + 555 + 429 + + + + FEM + + + + 9 + + + 6 + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + CalculiX + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + QLayout::SetNoConstraint + + + + + + + + + Use internal editor for .inp files + + + true + + + UseInternalEditor + + + Mod/Fem + + + + + + + + + false + + + External editor: + + + + + + + false + + + ExternalEditorPath + + + Mod/Fem + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+ + Gui::PrefFileChooser + Gui::FileChooser +
Gui/PrefWidgets.h
+
+ + Gui::PrefCheckBox + QCheckBox +
Gui/PrefWidgets.h
+
+
+ + + + + + cb_int_editor + toggled(bool) + l_ext_editor + setEnabled(bool) + + + 100 + 47 + + + 99 + 76 + + + + + cb_int_editor + toggled(bool) + l_ext_editor + setDisabled(bool) + + + 125 + 49 + + + 120 + 74 + + + + + cb_int_editor + toggled(bool) + fc_ext_editor + setEnabled(bool) + + + 327 + 54 + + + 323 + 79 + + + + + cb_int_editor + toggled(bool) + fc_ext_editor + setDisabled(bool) + + + 409 + 50 + + + 406 + 78 + + + + +
diff --git a/src/Mod/Fem/Gui/DlgSettingsFemImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemImp.cpp new file mode 100644 index 000000000..18bd799ca --- /dev/null +++ b/src/Mod/Fem/Gui/DlgSettingsFemImp.cpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * Based on src/Mod/Raytracing/Gui/DlgSettingsRayImp.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 "DlgSettingsFemImp.h" +#include + +using namespace FemGui; + +DlgSettingsFemImp::DlgSettingsFemImp( QWidget* parent ) + : PreferencePage( parent ) +{ + this->setupUi(this); +} + +DlgSettingsFemImp::~DlgSettingsFemImp() +{ + // no need to delete child widgets, Qt does it all for us +} + +void DlgSettingsFemImp::saveSettings() +{ + cb_int_editor->onSave(); + fc_ext_editor->onSave(); +} + +void DlgSettingsFemImp::loadSettings() +{ + cb_int_editor->onRestore(); + fc_ext_editor->onRestore(); +} + +/** + * Sets the strings of the subwidgets using the current language. + */ +void DlgSettingsFemImp::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + +#include "moc_DlgSettingsFemImp.cpp" diff --git a/src/Mod/Fem/Gui/DlgSettingsFemImp.h b/src/Mod/Fem/Gui/DlgSettingsFemImp.h new file mode 100644 index 000000000..1a57e338d --- /dev/null +++ b/src/Mod/Fem/Gui/DlgSettingsFemImp.h @@ -0,0 +1,50 @@ + /************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * Based on src/Mod/Raytracing/Gui/DlgSettingsRayImp.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_DLGSETTINGSFEMIMP_H +#define FEMGUI_DLGSETTINGSFEMIMP_H + +#include "ui_DlgSettingsFem.h" +#include + +namespace FemGui { + +class DlgSettingsFemImp : public Gui::Dialog::PreferencePage, public Ui_DlgSettingsFemImp +{ + Q_OBJECT + +public: + DlgSettingsFemImp( QWidget* parent = 0 ); + ~DlgSettingsFemImp(); + +protected: + void saveSettings(); + void loadSettings(); + void changeEvent(QEvent *e); +}; + +} // namespace FemGui + +#endif // FEMGUI_DLGSETTINGSFEMIMP_H diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index c094fd3b3..3b3d193d6 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -17,6 +17,7 @@ icons/Fem_Result.svg icons/Fem_ResultDisplacement.svg icons/Fem_ResultStress.svg + icons/preferences-fem.svg translations/Fem_af.qm translations/Fem_de.qm translations/Fem_fi.qm diff --git a/src/Mod/Fem/Gui/Resources/icons/preferences-fem.svg b/src/Mod/Fem/Gui/Resources/icons/preferences-fem.svg new file mode 100755 index 000000000..7b98dcaa7 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/preferences-fem.svg @@ -0,0 +1,1692 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Fem/MechanicalAnalysis.py b/src/Mod/Fem/MechanicalAnalysis.py index 27c1e1afc..498fc0f89 100644 --- a/src/Mod/Fem/MechanicalAnalysis.py +++ b/src/Mod/Fem/MechanicalAnalysis.py @@ -226,6 +226,7 @@ class _JobControlTaskPanel: self.obj = object #self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem") + self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem") self.Calculix = QtCore.QProcess() self.Timer = QtCore.QTimer() self.Timer.start(300) @@ -543,24 +544,22 @@ class _JobControlTaskPanel: QApplication.restoreOverrideCursor() + def start_ext_editor(self, ext_editor_path, filename): + self.ext_editor_process = QtCore.QProcess() + self.ext_editor_process.execute(ext_editor_path, [filename]) + def editCalculixInputFile(self): filename = self.Basename + '.inp' print 'editCalculixInputFile {}'.format(filename) - - # FIXME: That code should be removed as soon as there is "Preferred editor" option - # added to Preferences, to allow existing SciTE users override built-in editor - # - #import webbrowser - # If inp-file extension is assigned the os will use the appropriate binary - # (normally an Editor) to open the file. Works perfectly on Windows if SciTE is installed. - # However using webbrower.open is not portable and not supported - # https://docs.python.org/3.4/library/webbrowser.html - #webbrowser.open(filename) - - # The Abaqus syntax highlighter works similarly to that one of SciTE so that our - # own editor can be used now - import FemGui - FemGui.open(filename) + if self.fem_prefs.GetBool("UseInternalEditor",True): + FemGui.open(filename) + else: + ext_editor_path = self.fem_prefs.GetString("ExternalEditorPath","") + if ext_editor_path: + self.start_ext_editor(ext_editor_path, filename) + else: + print "External editor is not defined in FEM preferences. Falling back to internal editor" + FemGui.open(filename) def runCalculix(self): print 'runCalculix'