FEM: result task panel, changes in the way the task panel is called be the commands in Gui

This commit is contained in:
Bernd Hahnebach 2017-02-16 08:06:48 +01:00
parent 91bd0fc536
commit 28d0d737e5
4 changed files with 47 additions and 63 deletions

View File

@ -56,6 +56,8 @@ class FemCommands(object):
active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc()
elif self.is_active == 'with_results':
active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and self.results_present()
elif self.is_active == 'with_selresult':
active = FemGui.getActiveAnalysis() is not None and self.active_analysis_in_active_doc() and self.result_selected()
elif self.is_active == 'with_part_feature':
active = FreeCADGui.ActiveDocument is not None and self.part_feature_selected()
elif self.is_active == 'with_femmesh':
@ -80,6 +82,19 @@ class FemCommands(object):
results = True
return results
def result_selected(self):
result_is_in_active_analysis = False
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 1 and sel[0].isDerivedFrom("Fem::FemResultObject"):
for o in FemGui.getActiveAnalysis().Member:
if o == sel[0]:
result_is_in_active_analysis = True
break
if result_is_in_active_analysis:
return True
else:
return False
def part_feature_selected(self):
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 1 and sel[0].isDerivedFrom("Part::Feature"):

View File

@ -46,8 +46,6 @@ class _CommandRunSolver(FemCommands):
def load_results(ret_code):
if ret_code == 0:
self.fea.load_results()
self.show_results_on_mesh()
self.hide_parts_constraints_show_meshes()
else:
print ("CalculiX failed ccx finished with error {}".format(ret_code))
@ -78,13 +76,5 @@ class _CommandRunSolver(FemCommands):
else:
QtGui.QMessageBox.critical(None, "Not known solver type", message)
def show_results_on_mesh(self):
# FIXME proprer mesh refreshing as per FreeCAD.FEM_dialog settings required
# or confirmation that it's safe to call restore_result_dialog
# FIXME if an analysis has multiple results (frequence) the first result object found is restored
import _TaskPanelShowResult
tp = _TaskPanelShowResult._TaskPanelShowResult()
tp.restore_result_dialog()
FreeCADGui.addCommand('Fem_RunSolver', _CommandRunSolver())

View File

@ -21,7 +21,7 @@
# ***************************************************************************
__title__ = "Command Show Result"
__author__ = "Juergen Riegel"
__author__ = "Juergen Riegel, Bernd Hahnebach"
__url__ = "http://www.freecadweb.org"
## @package CommandShowResult
@ -30,7 +30,7 @@ __url__ = "http://www.freecadweb.org"
from FemCommands import FemCommands
import FreeCADGui
from PySide import QtCore, QtGui
from PySide import QtCore
class _CommandShowResult(FemCommands):
@ -41,33 +41,19 @@ class _CommandShowResult(FemCommands):
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_ShowResult", "Show result"),
'Accel': "S, R",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_ShowResult", "Shows and visualizes selected result data")}
self.is_active = 'with_results'
self.is_active = 'with_selresult'
def Activated(self):
self.result_object = get_results_object(FreeCADGui.Selection.getSelection())
if not self.result_object:
QtGui.QMessageBox.critical(None, "Missing prerequisite", "No result found in active Analysis")
return
sel = FreeCADGui.Selection.getSelection()
if (len(sel) == 1):
if sel[0].isDerivedFrom("Fem::FemResultObject"):
self.result_object = sel[0]
self.hide_parts_constraints_show_meshes()
import _TaskPanelShowResult
taskd = _TaskPanelShowResult._TaskPanelShowResult()
taskd = _TaskPanelShowResult._TaskPanelShowResult(self.result_object)
FreeCADGui.Control.showDialog(taskd)
# Code duplidation - to be removed after migration to FemTools
def get_results_object(sel):
import FemGui
if (len(sel) == 1):
if sel[0].isDerivedFrom("Fem::FemResultObject"):
return sel[0]
for i in FemGui.getActiveAnalysis().Member:
if(i.isDerivedFrom("Fem::FemResultObject")):
return i
return None
FreeCADGui.addCommand('Fem_ShowResult', _CommandShowResult())

View File

@ -40,7 +40,8 @@ from PySide.QtGui import QApplication
class _TaskPanelShowResult:
'''The task panel for the post-processing'''
def __init__(self):
def __init__(self, obj):
self.result_object = obj
self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/TaskPanelShowResult.ui")
self.fem_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem/General")
self.restore_result_settings_in_dialog = self.fem_prefs.GetBool("RestoreResultDialog", True)
@ -66,6 +67,8 @@ class _TaskPanelShowResult:
QtCore.QObject.connect(self.form.sb_displacement_factor_max, QtCore.SIGNAL("valueChanged(int)"), self.sb_disp_factor_max_changed)
self.update()
if not FemGui.getActiveAnalysis():
FreeCAD.Console.PrintError('FEM Result task panel, no active analysis. This will cause problems later ...\n')
if self.restore_result_settings_in_dialog:
self.restore_result_dialog()
else:
@ -310,44 +313,34 @@ class _TaskPanelShowResult:
def update(self):
self.MeshObject = None
self.result_object = get_results_object(FreeCADGui.Selection.getSelection())
for i in FemGui.getActiveAnalysis().Member:
if i.isDerivedFrom("Fem::FemMeshObject"):
self.MeshObject = i
break
self.suitable_results = False
if self.result_object:
# Disable temperature radio button if it does ot exist in results
if len(self.result_object.Temperature) == 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 (self.MeshObject.FemMesh.NodeCount == len(self.result_object.NodeNumbers)):
self.suitable_results = True
else:
if not self.MeshObject.FemMesh.VolumeCount:
FreeCAD.Console.PrintError('FEM: Graphical bending stress output for beam or shell FEM Meshes not yet supported.\n')
if hasattr(self.result_object, "Mesh") and self.result_object.Mesh:
self.MeshObject = self.result_object.Mesh
self.MeshObject.ViewObject.Visibility = True
if (self.MeshObject.FemMesh.NodeCount == len(self.result_object.NodeNumbers)):
self.suitable_results = True
else:
FreeCAD.Console.PrintError('FEM: Result node numbers are not equal to FEM Mesh NodeCount.\n')
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'
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 accept(self):
FreeCADGui.Control.closeDialog()
def reject(self):
FreeCADGui.Control.closeDialog()
# It's code duplication that should be removes wher we migrate to FemTools.py
def get_results_object(sel):
if (len(sel) == 1):
if sel[0].isDerivedFrom("Fem::FemResultObject"):
return sel[0]
for i in FemGui.getActiveAnalysis().Member:
if(i.isDerivedFrom("Fem::FemResultObject")):
return i
return None
FreeCADGui.Control.closeDialog() # if the taks panell is called from Command obj is not in edit mode thus reset edit does not cleses the dialog, may be do not call but set in edit instead
FreeCADGui.ActiveDocument.resetEdit()