FreeCAD/src/Mod/Fem/_CommandRunSolver.py
2016-11-25 22:59:03 +01:00

91 lines
4.4 KiB
Python

# ***************************************************************************
# * *
# * Copyright (c) 2013-2015 - Juergen Riegel <FreeCAD@juergen-riegel.net> *
# * *
# * 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__ = "Command Run Solver"
__author__ = "Juergen Riegel"
__url__ = "http://www.freecadweb.org"
## @package CommandRunSolver
# \ingroup FEM
from FemCommands import FemCommands
import FreeCADGui
from PySide import QtCore, QtGui
class _CommandRunSolver(FemCommands):
# the Fem_RunSolver command definition
def __init__(self):
super(_CommandRunSolver, self).__init__()
self.resources = {'Pixmap': 'fem-run-solver',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Fem_RunAnalysis", "Run solver calculations"),
'Accel': "R, C",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Fem_RunAnalysis", "Runs the calculations for the selected solver")}
self.is_active = 'with_solver'
def Activated(self):
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))
sel = FreeCADGui.Selection.getSelection()
if len(sel) == 1 and sel[0].isDerivedFrom("Fem::FemSolverObjectPython"):
self.solver = sel[0]
if self.solver.SolverType == "FemSolverCalculix":
import FemToolsCcx
self.fea = FemToolsCcx.FemToolsCcx(None, self.solver)
self.fea.reset_mesh_purge_results_checked()
message = self.fea.check_prerequisites()
if message:
QtGui.QMessageBox.critical(None, "Missing prerequisite", message)
return
self.fea.finished.connect(load_results)
QtCore.QThreadPool.globalInstance().start(self.fea)
elif self.solver.SolverType == "FemSolverZ88":
import FemToolsZ88
self.fea = FemToolsZ88.FemToolsZ88(None, self.solver)
self.fea.reset_mesh_purge_results_checked()
message = self.fea.check_prerequisites()
if message:
QtGui.QMessageBox.critical(None, "Missing prerequisite", message)
return
self.fea.run() # test z88
# self.fea.finished.connect(load_results)
# QtCore.QThreadPool.globalInstance().start(self.fea)
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())