From e86ec2848e948cada33369c8dc8451dc1784ffd7 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Tue, 25 Feb 2020 16:54:50 +0100 Subject: [PATCH] FEM: move errors in own module --- src/Mod/Fem/CMakeLists.txt | 1 + src/Mod/Fem/femsolver/run.py | 9 ++++---- src/Mod/Fem/femsolver/solverbase.py | 6 +++--- src/Mod/Fem/femtools/errors.py | 33 +++++++++++++++++++++++++++++ src/Mod/Fem/femtools/femutils.py | 16 +++++--------- 5 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 src/Mod/Fem/femtools/errors.py diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index d47719512d..77a341b59a 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -221,6 +221,7 @@ SET(FemTools_SRCS femtools/__init__.py femtools/membertools.py femtools/ccxtools.py + femtools/errors.py femtools/femutils.py femtools/tokrules.py ) diff --git a/src/Mod/Fem/femsolver/run.py b/src/Mod/Fem/femsolver/run.py index 6511b10b71..7b22ba2936 100644 --- a/src/Mod/Fem/femsolver/run.py +++ b/src/Mod/Fem/femsolver/run.py @@ -45,6 +45,7 @@ import femtools.membertools as membertools from . import settings from . import signal from . import task +from femtools.errors import MustSaveError, DirectoryDoesNotExistError if App.GuiUp: import FreeCADGui @@ -118,7 +119,7 @@ def run_fem_solver(solver, working_dir=None): machine = getMachine(solver, working_dir) else: machine = getMachine(solver) - except femutils.MustSaveError: + except MustSaveError: error_message = ( "Please save the file before executing the solver. " "This must be done because the location of the working " @@ -132,7 +133,7 @@ def run_fem_solver(solver, working_dir=None): error_message ) return - except femutils.DirectoryDoesNotExistError: + except DirectoryDoesNotExistError: error_message = "Selected working directory doesn't exist." App.Console.PrintError(error_message + "\n") if App.GuiUp: @@ -251,7 +252,7 @@ def _getBesideBase(solver): "Can't start Solver", error_message ) - raise femutils.MustSaveError() + raise MustSaveError() return path @@ -276,7 +277,7 @@ def _getCustomBase(solver): "Can't start Solver", error_message ) - raise femutils.DirectoryDoesNotExistError("Invalid path") + raise DirectoryDoesNotExistError("Invalid path") return path diff --git a/src/Mod/Fem/femsolver/solverbase.py b/src/Mod/Fem/femsolver/solverbase.py index e7156ea3f8..85b0a3eb85 100644 --- a/src/Mod/Fem/femsolver/solverbase.py +++ b/src/Mod/Fem/femsolver/solverbase.py @@ -29,7 +29,7 @@ __url__ = "http://www.freecadweb.org" from PySide import QtGui import FreeCAD as App -import femtools.femutils as femutils +from femtools.errors import MustSaveError, DirectoryDoesNotExistError from . import run if App.GuiUp: @@ -78,7 +78,7 @@ class ViewProxy(object): def setEdit(self, vobj, mode=0): try: machine = run.getMachine(vobj.Object) - except femutils.MustSaveError: + except MustSaveError: error_message = ( "Please save the file before opening the task panel. " "This must be done because the location of the working " @@ -91,7 +91,7 @@ class ViewProxy(object): error_message ) return False - except femutils.DirectoryDoesNotExistError: + except DirectoryDoesNotExistError: error_message = "Selected working directory doesn't exist." App.Console.PrintError(error_message + "\n") QtGui.QMessageBox.critical( diff --git a/src/Mod/Fem/femtools/errors.py b/src/Mod/Fem/femtools/errors.py new file mode 100644 index 0000000000..2c0dc4d70e --- /dev/null +++ b/src/Mod/Fem/femtools/errors.py @@ -0,0 +1,33 @@ +# *************************************************************************** +# * Copyright (c) 2020 Markus Hovorka * +# * Copyright (c) 2020 Bernd Hahnebach * +# * * +# * 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__ = "FEM Errors" +__author__ = "Markus Hovorka, Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +class MustSaveError(Exception): + pass + + +class DirectoryDoesNotExistError(Exception): + pass diff --git a/src/Mod/Fem/femtools/femutils.py b/src/Mod/Fem/femtools/femutils.py index 7cb03fba55..3cc620d052 100644 --- a/src/Mod/Fem/femtools/femutils.py +++ b/src/Mod/Fem/femtools/femutils.py @@ -118,7 +118,7 @@ def is_derived_from(obj, t): def get_pref_working_dir(solver_obj): """ Return working directory for solver honoring user settings. - :throws femsolver.run.MustSaveError: + :throws femtools.erros.MustSaveError: If user setting is set to BESIDE and the document isn't saved. :note: @@ -179,6 +179,7 @@ def get_beside_base(obj): "Can't start Solver or Mesh creation besides FC file.", error_message ) + # from .errors import MustSaveError # raise MustSaveError() return get_temp_dir() else: @@ -197,7 +198,9 @@ def get_custom_base(solver): "Can't start Solver or Mesh creation.", error_message ) - raise DirectoryDoesNotExistError("Invalid path") + # from .errors import DirectoryDoesNotExistError + # raise DirectoryDoesNotExistError("Invalid path") + return get_temp_dir() return path @@ -211,15 +214,6 @@ def check_working_dir(wdir): return False -# TODO: move in own error module -class MustSaveError(Exception): - pass - - -class DirectoryDoesNotExistError(Exception): - pass - - # ************************************************************************************************ # other def get_part_to_mesh(mesh_obj):