diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 0d2242f2ff..32bb481bbc 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -104,7 +104,6 @@ SET(FemObjectsScripts_SRCS SET(FemCommand_SRCS femcommand/__init__.py femcommand/commands.py - femcommand/_CommandFemEquation.py femcommand/manager.py ) diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index f0df47f907..c441825286 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -57,7 +57,6 @@ INSTALL( FILES femcommand/__init__.py femcommand/commands.py - femcommand/_CommandFemEquation.py femcommand/manager.py DESTINATION Mod/Fem/femcommand diff --git a/src/Mod/Fem/InitGui.py b/src/Mod/Fem/InitGui.py index 0a560ba15b..20e96e46c7 100644 --- a/src/Mod/Fem/InitGui.py +++ b/src/Mod/Fem/InitGui.py @@ -45,7 +45,6 @@ class FemWorkbench (Workbench): import Fem import FemGui import femcommand.commands - import femcommand._CommandFemEquation def GetClassName(self): return "FemGui::Workbench" diff --git a/src/Mod/Fem/femcommand/_CommandFemEquation.py b/src/Mod/Fem/femcommand/_CommandFemEquation.py deleted file mode 100644 index 2f92165ac0..0000000000 --- a/src/Mod/Fem/femcommand/_CommandFemEquation.py +++ /dev/null @@ -1,130 +0,0 @@ -# *************************************************************************** -# * * -# * Copyright (c) 2017 - Markus Hovorka * -# * * -# * 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__ = "_CommandFemEquation" -__author__ = "Markus Hovorka" -__url__ = "http://www.freecadweb.org" - - -from PySide import QtCore - -import FreeCAD as App -import FreeCADGui as Gui -import FemUtils - - -class _Base(QtCore.QObject): - - def getSpecifier(self): - raise NotImplementedError() - - def Activated(self): - s = Gui.Selection.getSelection() - if len(s) == 1 and FemUtils.isDerivedFrom(s[0], "Fem::FemSolverObject"): - App.ActiveDocument.openTransaction( - "Add %s equation to %s" - % (self.getSpecifier(), s[0].Label)) - Gui.doCommand( - "App.ActiveDocument.%(obj)s.Proxy.addEquation(" - "App.ActiveDocument.%(obj)s, '%(name)s')" - % {"obj": s[0].Name, "name": self.getSpecifier()}) - App.ActiveDocument.commitTransaction() - App.ActiveDocument.recompute() - - def IsActive(self): - s = Gui.Selection.getSelection() - if len(s) == 1 and FemUtils.isDerivedFrom(s[0], "Fem::FemSolverObject"): - return s[0].Proxy.isSupported(self.getSpecifier()) - return False - - -class Heat(_Base): - - def getSpecifier(self): - return "Heat" - - def GetResources(self): - return { - 'Pixmap': 'fem-equation-heat', - 'MenuText': "Heat Equation", - 'ToolTip': "Creates a FEM constraint body heat flux" - } - - -class Elasticity(_Base): - - def getSpecifier(self): - return "Elasticity" - - def GetResources(self): - return { - 'Pixmap': 'fem-equation-elasticity', - 'MenuText': "Elasticity Equation", - 'ToolTip': "Creates a FEM constraint for elasticity" - } - - -class Electrostatic(_Base): - - def getSpecifier(self): - return "Electrostatic" - - def GetResources(self): - return { - 'Pixmap': 'fem-equation-electrostatic', - 'MenuText': "Electrostatic Equation", - 'ToolTip': "Creates a FEM equation for electrostatic" - } - - -class Fluxsolver(_Base): - - def getSpecifier(self): - return "Fluxsolver" - - def GetResources(self): - return { - 'Pixmap': 'fem-equation-fluxsolver', - 'MenuText': "Flux Solver Equation", - 'ToolTip': "Creates a FEM equation for solving the flux or gradient" - } - - -class Flow(_Base): - - def getSpecifier(self): - return "Flow" - - def GetResources(self): - return { - 'Pixmap': 'fem-equation-flow', - 'MenuText': "Flow Equation", - 'ToolTip': "Creates a FEM constraint body heat flux" - } - - -Gui.addCommand('FEM_EquationHeat', Heat()) -Gui.addCommand('FEM_EquationElasticity', Elasticity()) -Gui.addCommand('FEM_EquationElectrostatic', Electrostatic()) -Gui.addCommand('FEM_EquationFluxsolver', Fluxsolver()) -Gui.addCommand('FEM_EquationFlow', Flow()) diff --git a/src/Mod/Fem/femcommand/commands.py b/src/Mod/Fem/femcommand/commands.py index 003eadadfb..53793e658d 100644 --- a/src/Mod/Fem/femcommand/commands.py +++ b/src/Mod/Fem/femcommand/commands.py @@ -198,6 +198,86 @@ class _CommandFemElementGeometry2D(CommandManager): FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeElementGeometry2D(FreeCAD.ActiveDocument))") +class _CommandFemEquationElectrostatic(CommandManager): + "The FEM_EquationElectrostatic command definition" + def __init__(self): + super(_CommandFemEquationElectrostatic, self).__init__() + self.resources = {'Pixmap': 'fem-equation-electrostatic', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("FEM_EquationElectrostatic", "Electrostatic equation"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("FEM_EquationElectrostatic", "Creates a FEM equation for electrostatic")} + self.is_active = 'with_solver_elmer' + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create FemEquationElasticity") + FreeCADGui.addModule("ObjectsFem") + FreeCADGui.doCommand("ObjectsFem.makeEquationElectrostatic(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") + FreeCADGui.Selection.clearSelection() + + +class _CommandFemEquationElasticity(CommandManager): + "The FEM_EquationElasticity command definition" + def __init__(self): + super(_CommandFemEquationElasticity, self).__init__() + self.resources = {'Pixmap': 'fem-equation-elasticity', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("FEM_EquationElasticity", "Elasticity equation"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("FEM_EquationElasticity", "Creates a FEM equation for elasticity")} + self.is_active = 'with_solver_elmer' + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create FemEquationElasticity") + FreeCADGui.addModule("ObjectsFem") + FreeCADGui.doCommand("ObjectsFem.makeEquationElasticity(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") + FreeCADGui.Selection.clearSelection() + + +class _CommandFemEquationFlow(CommandManager): + "The FEM_EquationFlow command definition" + def __init__(self): + super(_CommandFemEquationFlow, self).__init__() + self.resources = {'Pixmap': 'fem-equation-flow', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("FEM_EquationFlow", "Flow equation"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("FEM_EquationFlow", "Creates a FEM equation for flow")} + self.is_active = 'with_solver_elmer' + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create FemEquationFlow") + FreeCADGui.addModule("ObjectsFem") + FreeCADGui.doCommand("ObjectsFem.makeEquationFlow(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") + FreeCADGui.Selection.clearSelection() + + +class _CommandFemEquationFluxsolver(CommandManager): + "The FEM_EquationFluxsolver command definition" + def __init__(self): + super(_CommandFemEquationFluxsolver, self).__init__() + self.resources = {'Pixmap': 'fem-equation-fluxsolver', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("FEM_EquationFluxsolver", "Fluxsolver equation"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("FEM_EquationFluxsolver", "Creates a FEM equation for fluxsolver")} + self.is_active = 'with_solver_elmer' + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create FemEquationFluxsolver") + FreeCADGui.addModule("ObjectsFem") + FreeCADGui.doCommand("ObjectsFem.makeEquationFluxsolver(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") + FreeCADGui.Selection.clearSelection() + + +class _CommandFemEquationHeat(CommandManager): + "The FEM_EquationHeat command definition" + def __init__(self): + super(_CommandFemEquationHeat, self).__init__() + self.resources = {'Pixmap': 'fem-equation-heat', + 'MenuText': QtCore.QT_TRANSLATE_NOOP("FEM_EquationHeat", "Fluxsolver heat"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("FEM_EquationHeat", "Creates a FEM equation for heat")} + self.is_active = 'with_solver_elmer' + + def Activated(self): + FreeCAD.ActiveDocument.openTransaction("Create FemEquationHeat") + FreeCADGui.addModule("ObjectsFem") + FreeCADGui.doCommand("ObjectsFem.makeEquationHeat(FreeCAD.ActiveDocument, FreeCAD.ActiveDocument." + self.selobj.Name + ")") + FreeCADGui.Selection.clearSelection() + + class _CommandFemMaterialFluid(CommandManager): "The FEM_MaterialFluid command definition" def __init__(self): @@ -652,6 +732,11 @@ FreeCADGui.addCommand('FEM_ConstraintSelfWeight', _CommandFemConstraintSelfWeigh FreeCADGui.addCommand('FEM_ElementFluid1D', _CommandFemElementFluid1D()) FreeCADGui.addCommand('FEM_ElementGeometry1D', _CommandFemElementGeometry1D()) FreeCADGui.addCommand('FEM_ElementGeometry2D', _CommandFemElementGeometry2D()) +FreeCADGui.addCommand('FEM_EquationElectrostatic', _CommandFemEquationElectrostatic()) +FreeCADGui.addCommand('FEM_EquationElasticity', _CommandFemEquationElasticity()) +FreeCADGui.addCommand('FEM_EquationFlow', _CommandFemEquationFlow()) +FreeCADGui.addCommand('FEM_EquationFluxsolver', _CommandFemEquationFluxsolver()) +FreeCADGui.addCommand('FEM_EquationHeat', _CommandFemEquationHeat()) FreeCADGui.addCommand('FEM_MaterialFluid', _CommandFemMaterialFluid()) FreeCADGui.addCommand('FEM_MaterialMechanicalNonlinear', _CommandFemMaterialMechanicalNonlinear()) FreeCADGui.addCommand('FEM_MaterialSolid', _CommandFemMaterialSolid()) diff --git a/src/Mod/Fem/femcommand/manager.py b/src/Mod/Fem/femcommand/manager.py index 08a2e0ba8b..fd86301c53 100644 --- a/src/Mod/Fem/femcommand/manager.py +++ b/src/Mod/Fem/femcommand/manager.py @@ -43,6 +43,7 @@ class CommandManager(object): 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_Command", "Default Fem Command ToolTip")} # FIXME add option description self.is_active = None + self.selobj = None def GetResources(self): return self.resources @@ -72,6 +73,8 @@ class CommandManager(object): active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and self.material_solid_selected() elif self.is_active == 'with_solver': active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and self.solver_selected() + elif self.is_active == 'with_solver_elmer': + active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and self.solver_elmer_selected() elif self.is_active == 'with_analysis_without_solver': active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and not self.analysis_has_solver() return active @@ -162,6 +165,14 @@ class CommandManager(object): else: return False + def solver_elmer_selected(self): + sel = FreeCADGui.Selection.getSelection() + if len(sel) == 1 and hasattr(sel[0], "Proxy") and sel[0].Proxy.Type == "Fem::FemSolverObjectElmer": + self.selobj = sel[0] + return True + else: + return False + def analysis_has_solver(self): solver = False analysis_members = FemGui.getActiveAnalysis().Group