FEM: result view provider, implement checks for open result task panel

This commit is contained in:
Bernd Hahnebach 2017-02-16 08:07:05 +01:00
parent e4bd9054a6
commit 18dafb469c
3 changed files with 55 additions and 33 deletions

View File

@ -48,9 +48,10 @@ class _CommandShowResult(FemCommands):
if (len(sel) == 1):
if sel[0].isDerivedFrom("Fem::FemResultObject"):
self.result_object = sel[0]
import _TaskPanelShowResult
taskd = _TaskPanelShowResult._TaskPanelShowResult(self.result_object)
FreeCADGui.Control.showDialog(taskd)
import _ViewProviderFemMechanicalResult
if _ViewProviderFemMechanicalResult.is_result_obj_valid(self.result_object):
self.result_object.ViewObject.startEditing()
FreeCADGui.addCommand('Fem_ShowResult', _CommandShowResult())

View File

@ -43,7 +43,7 @@ class _TaskPanelShowResult:
self.result_object = obj
self.MeshObject = self.result_object.Mesh
# task panel should be started by use of setEdit of view provider
# in setEdit check for, Mesh, active analysis and if Mesh and result are in active analysis
# in view provider checks: Mesh, active analysis and if Mesh and result are in active analysis
self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/TaskPanelShowResult.ui")
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
@ -311,35 +311,23 @@ class _TaskPanelShowResult:
self.form.hsb_displacement_factor.setValue(value)
def update(self):
self.MeshObject = None
self.suitable_results = False
if self.result_object:
if len(self.result_object.Temperature) == 0: # Disable temperature radio button if it does ot exist in results
self.form.rb_temperature.setEnabled(0)
if len(self.result_object.Temperature) == 0: # Disable temperature radio button if it does ot exist in results
self.form.rb_temperature.setEnabled(0)
if hasattr(self.result_object, "Mesh") and self.result_object.Mesh:
self.MeshObject = self.result_object.Mesh
if (self.MeshObject.FemMesh.NodeCount == len(self.result_object.NodeNumbers)):
self.suitable_results = True
self.MeshObject.ViewObject.Visibility = True
hide_parts_constraints()
else:
if not self.MeshObject.FemMesh.VolumeCount:
error_message = 'FEM: Graphical bending stress output for beam or shell FEM Meshes not yet supported.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No result object', error_message)
else:
error_message = 'FEM: Result node numbers are not equal to FEM Mesh NodeCount.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No result object', error_message)
else:
error_message = 'FEM: Result object has no appropriate FEM mesh.\n'
if (self.MeshObject.FemMesh.NodeCount == len(self.result_object.NodeNumbers)):
self.suitable_results = True
self.MeshObject.ViewObject.Visibility = True
hide_parts_constraints()
else:
if not self.MeshObject.FemMesh.VolumeCount:
error_message = 'FEM: Graphical bending stress output for beam or shell FEM Meshes not yet supported.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No result object', error_message)
else:
error_message = 'FEM: Result node numbers are not equal to FEM Mesh NodeCount.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No result object', error_message)
else:
error_message = 'FEM: Result task panel, no result object to display results for.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No result object', error_message)
def reset_mesh_deformation(self):
self.MeshObject.ViewObject.applyDisplacement(0.0)

View File

@ -30,6 +30,7 @@ __url__ = "http://www.freecadweb.org"
import FreeCAD
import FreeCADGui
import FemGui
class _ViewProviderFemMechanicalResult:
@ -58,20 +59,20 @@ class _ViewProviderFemMechanicalResult:
FreeCADGui.activateWorkbench("FemWorkbench")
doc = FreeCADGui.getDocument(vobj.Object.Document)
if not doc.getInEdit():
doc.setEdit(vobj.Object.Name)
if is_result_obj_valid(self.Object):
doc.setEdit(vobj.Object.Name)
else:
FreeCAD.Console.PrintError('Active Task Dialog found! Please close this one first!\n')
return True
def setEdit(self, vobj, mode):
#if FemGui.getActiveAnalysis():
def setEdit(self, vobj, mode=0):
import _TaskPanelShowResult
taskd = _TaskPanelShowResult._TaskPanelShowResult(self.Object)
taskd.obj = vobj.Object
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self, vobj, mode):
def unsetEdit(self, vobj, mode=0):
FreeCADGui.Control.closeDialog()
return
@ -80,3 +81,35 @@ class _ViewProviderFemMechanicalResult:
def __setstate__(self, state):
return None
# helper
# I tried to do this inside the setEdit def but I was not able to unset the edit mode from within the setEdit def
def is_result_obj_valid(result_obj):
from PySide import QtGui
if FemGui.getActiveAnalysis() is not None:
if hasattr(result_obj, "Mesh") and result_obj.Mesh:
mem = FemGui.getActiveAnalysis().Member
if result_obj in mem:
if result_obj.Mesh in mem:
return True
else:
error_message = 'FEM: Result mesh object is not in active analysis.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'Not in activate analysis', error_message)
return False
else:
error_message = 'FEM: Result object is not in active analysis.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'Not in activate analysis', error_message)
return False
else:
error_message = 'FEM: Result object has no appropriate FEM mesh.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No result object', error_message)
return False
else:
error_message = 'FEM: No active analysis found! Please activate the analysis you would like to view results for.\n'
FreeCAD.Console.PrintError(error_message)
QtGui.QMessageBox.critical(None, 'No activate analysis', error_message)
return False