diff --git a/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py b/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py index ee1d88b0ed..b5cf9527c4 100644 --- a/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py +++ b/src/Mod/Fem/femguiobjects/_ViewProviderFemResultMechanical.py @@ -30,7 +30,7 @@ __url__ = "http://www.freecadweb.org" import FreeCAD import FreeCADGui -import FemGui # needed to display the icons in TreeView +from . import ViewProviderFemConstraint # for the panel import femresult.resulttools as resulttools @@ -42,70 +42,28 @@ import numpy as np import matplotlib.pyplot as plt -False if FemGui.__name__ else True # flake8, dummy FemGui usage - - -class _ViewProviderFemResultMechanical: +class _ViewProviderFemResultMechanical(ViewProviderFemConstraint.ViewProxy): "A View Provider for the FemResultObject Python derived FemResult class" - def __init__(self, vobj): - vobj.Proxy = self - def getIcon(self): """after load from FCStd file, self.icon does not exist, return constant path instead""" return ":/icons/fem-post-result-show.svg" - def attach(self, vobj): - self.ViewObject = vobj - self.Object = vobj.Object - - def updateData(self, obj, prop): - return - - def onChanged(self, vobj, prop): - return - - def doubleClicked(self, vobj): - guidoc = FreeCADGui.getDocument(vobj.Object.Document) - # check if another VP is in edit mode - # https://forum.freecadweb.org/viewtopic.php?t=13077#p104702 - if not guidoc.getInEdit(): - guidoc.setEdit(vobj.Object.Name) - else: - from PySide.QtGui import QMessageBox - message = "Active Task Dialog found! Please close this one before opening a new one!" - QMessageBox.critical(None, "Error in tree view", message) - FreeCAD.Console.PrintError(message + "\n") - return True - def setEdit(self, vobj, mode=0): - if hasattr(self.Object, "Mesh") and self.Object.Mesh: - hide_femmeshes_postpiplines() - # only show the FEM result mesh - self.Object.Mesh.ViewObject.show() - taskd = _TaskPanelFemResultShow(self.Object) - taskd.obj = vobj.Object - FreeCADGui.Control.showDialog(taskd) - return True - else: - error_message = "FEM: Result object has no appropriate FEM mesh.\n" - FreeCAD.Console.PrintError(error_message) - from PySide import QtGui - QtGui.QMessageBox.critical(None, "No result object", error_message) - return False + ViewProviderFemConstraint.ViewProxy.setEdit( + self, + vobj, + mode, + _TaskPanelFemResultShow, + ) + # overwrite unsetEdit, because the mesh result obj needs to be hided on task panel exit def unsetEdit(self, vobj, mode=0): FreeCADGui.Control.closeDialog() # hide the mesh after result viewing is finished, but do not reset the coloring self.Object.Mesh.ViewObject.hide() return True - def __getstate__(self): - return None - - def __setstate__(self, state): - return None - def claimChildren(self): return [self.Object.Mesh] # claimChildren needs to return a list ! diff --git a/src/Mod/Fem/femobjects/_FemResultMechanical.py b/src/Mod/Fem/femobjects/_FemResultMechanical.py index ddfbc3b36d..d42e7b34a5 100644 --- a/src/Mod/Fem/femobjects/_FemResultMechanical.py +++ b/src/Mod/Fem/femobjects/_FemResultMechanical.py @@ -27,14 +27,17 @@ __url__ = "http://www.freecadweb.org" # \ingroup FEM # \brief FreeCAD DocumentObject class to hold mechanical results in FEM workbench +from . import FemConstraint -class _FemResultMechanical(): + +class _FemResultMechanical(FemConstraint.Proxy): """The Fem::_FemResultMechanical's Proxy python type, add result specific properties """ + + Type = "Fem::FemResultMechanical" + def __init__(self, obj): - self.Type = "Fem::FemResultMechanical" - self.Object = obj # keep a ref to the DocObj for nonGui usage - obj.Proxy = self # link between App::DocumentObject to this object + super(_FemResultMechanical, self).__init__(obj) obj.addProperty( "App::PropertyString",