diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 6d64ae9c6..309c1b29c 100755 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -82,6 +82,7 @@ SET(FemScripts_SRCS MechanicalMaterial.ui MechanicalMaterial.py ShowDisplacement.ui + FemCommands.py _ResultControlTaskPanel.py _JobControlTaskPanel.py _ViewProviderFemAnalysis.py diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 607b0d180..73de859b0 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -24,6 +24,7 @@ INSTALL( MechanicalMaterial.ui MechanicalAnalysis.ui ShowDisplacement.ui + FemCommands.py _ResultControlTaskPanel.py _JobControlTaskPanel.py _ViewProviderFemAnalysis.py diff --git a/src/Mod/Fem/FemCommands.py b/src/Mod/Fem/FemCommands.py new file mode 100644 index 000000000..a3a7e6c80 --- /dev/null +++ b/src/Mod/Fem/FemCommands.py @@ -0,0 +1,55 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2015 - FreeCAD Developers * +#* Author (c) 2015 - Przemo Fiszt < przemo@firszt.eu> * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* This program 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 program; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#*************************************************************************** + +__title__ = "Fem Commands" +__author__ = "Przemo Firszt" +__url__ = "http://www.freecadweb.org" + +import FreeCAD + +if FreeCAD.GuiUp: + import FreeCADGui + import FemGui + from PySide import QtCore + + +class FemCommands(object): + def __init__(self): + self.resources = {'Pixmap': 'fem-frequency-analysis', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_Command", "Default Fem Command MenuText"), + 'Accel': "", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Command", "Default Fem Command ToolTip")} + #FIXME add option description + self.is_active = None + + def GetResources(self): + return self.resources + + def IsActive(self): + if not self.is_active: + active = False + elif self.is_active == 'with_document': + active = FreeCADGui.ActiveDocument is not None + elif self.is_active == 'with_analysis': + active = FreeCADGui.ActiveDocument is not None and FemGui.getActiveAnalysis() is not None + return active diff --git a/src/Mod/Fem/Gui/AppFemGui.cpp b/src/Mod/Fem/Gui/AppFemGui.cpp index dc427f658..c8e621f3d 100644 --- a/src/Mod/Fem/Gui/AppFemGui.cpp +++ b/src/Mod/Fem/Gui/AppFemGui.cpp @@ -102,6 +102,8 @@ void FemGuiExport initFemGui() FemGui::ViewProviderResult ::init(); FemGui::ViewProviderResultPython ::init(); + Base::Interpreter().loadModule("FemCommands"); + Base::Interpreter().loadModule("_CommandMechanicalShowResult"); Base::Interpreter().loadModule("_CommandFrequencyAnalysis"); Base::Interpreter().loadModule("_CommandQuickAnalysis"); diff --git a/src/Mod/Fem/_CommandFrequencyAnalysis.py b/src/Mod/Fem/_CommandFrequencyAnalysis.py index aa3a29165..0f2ebb88c 100644 --- a/src/Mod/Fem/_CommandFrequencyAnalysis.py +++ b/src/Mod/Fem/_CommandFrequencyAnalysis.py @@ -1,18 +1,46 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2013-2015 - Juergen Riegel * +#* * +#* This program is free software; you can redistribute it and/or modify * +#* it under the terms of the GNU Lesser General Public License (LGPL) * +#* as published by the Free Software Foundation; either version 2 of * +#* the License, or (at your option) any later version. * +#* for detail see the LICENCE text file. * +#* * +#* This program 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 program; if not, write to the Free Software * +#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +#* USA * +#* * +#*************************************************************************** + +__title__ = "Command Frequency Analysis" +__author__ = "Juergen Riegel" +__url__ = "http://www.freecadweb.org" + import FreeCAD +from FemCommands import FemCommands from FemTools import FemTools if FreeCAD.GuiUp: import FreeCADGui - import FemGui from PySide import QtCore, QtGui -class _CommandFrequencyAnalysis: - def GetResources(self): - return {'Pixmap': 'fem-frequency-analysis', - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_Frequency_Analysis", "Run frequency analysis with CalculiX ccx"), - 'Accel': "R, F", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Frequency_Analysis", "Write .inp file and run frequency analysis with CalculiX ccx")} +class _CommandFrequencyAnalysis(FemCommands): + def __init__(self): + super(_CommandFrequencyAnalysis, self).__init__() + self.resources = {'Pixmap': 'fem-frequency-analysis', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_Frequency_Analysis", "Run frequency analysis with CalculiX ccx"), + 'Accel': "R, F", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Frequency_Analysis", "Write .inp file and run frequency analysis with CalculiX ccx")} + self.is_active = 'with_analysis' def Activated(self): def load_results(ret_code): @@ -31,9 +59,6 @@ class _CommandFrequencyAnalysis: self.fea.finished.connect(load_results) QtCore.QThreadPool.globalInstance().start(self.fea) - def IsActive(self): - return FreeCADGui.ActiveDocument is not None and FemGui.getActiveAnalysis() is not None - if FreeCAD.GuiUp: FreeCADGui.addCommand('Fem_Frequency_Analysis', _CommandFrequencyAnalysis())