Skip to content

Commit

Permalink
FEM: Migrate _CommandFemFromShape to FemCommands and add new is_activ…
Browse files Browse the repository at this point in the history
…e type

Signed-off-by: Przemo Firszt <przemo@firszt.eu>
  • Loading branch information
PrzemoF authored and wwmayer committed Oct 13, 2015
1 parent 217103a commit 1ad481b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/Mod/Fem/FemCommands.py
Expand Up @@ -54,6 +54,8 @@ def IsActive(self):
active = FreeCADGui.ActiveDocument is not None and FemGui.getActiveAnalysis() is not None
elif self.is_active == 'with_results':
active = FreeCADGui.ActiveDocument is not None and FemGui.getActiveAnalysis() is not None and self.results_present()
elif self.is_active == 'with_part_feature':
active = FreeCADGui.ActiveDocument is not None and FemGui.getActiveAnalysis() is not None and self.part_feature_selected()
return active

def results_present(self):
Expand All @@ -63,3 +65,10 @@ def results_present(self):
if o.isDerivedFrom('Fem::FemResultObject'):
results = True
return results

def part_feature_selected(self):
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 1 and sel[0].isDerivedFrom("Part::Feature"):
return True
else:
return False
18 changes: 8 additions & 10 deletions src/Mod/Fem/_CommandFemFromShape.py
Expand Up @@ -25,17 +25,20 @@
__url__ = "http://www.freecadweb.org"

import FreeCAD
from FemCommands import FemCommands

if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore


class _CommandFemFromShape:
def GetResources(self):
return {'Pixmap': 'fem-fem-mesh-from-shape',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_CreateFromShape", "Create FEM mesh"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_CreateFromShape", "Create FEM mesh from shape")}
class _CommandFemFromShape(FemCommands):
def __init__(self):
super(_CommandFemFromShape, self).__init__()
self.resources = {'Pixmap': 'fem-fem-mesh-from-shape',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_CreateFromShape", "Create FEM mesh"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_CreateFromShape", "Create FEM mesh from shape")}
self.is_active = 'with_part_feature'

def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create FEM mesh")
Expand All @@ -50,11 +53,6 @@ def Activated(self):

FreeCADGui.Selection.clearSelection()

def IsActive(self):
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 1:
return sel[0].isDerivedFrom("Part::Feature")
return False

if FreeCAD.GuiUp:
FreeCADGui.addCommand('Fem_CreateFromShape', _CommandFemFromShape())

0 comments on commit 1ad481b

Please sign in to comment.