FEM: move errors in own module

This commit is contained in:
Bernd Hahnebach
2020-02-25 16:54:50 +01:00
parent 43295895d6
commit e86ec2848e
5 changed files with 47 additions and 18 deletions

View File

@@ -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
)

View File

@@ -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

View File

@@ -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(

View File

@@ -0,0 +1,33 @@
# ***************************************************************************
# * Copyright (c) 2020 Markus Hovorka <m.hovorka@live.de> *
# * Copyright (c) 2020 Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * 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

View File

@@ -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):