diff --git a/src/Model/Except.py b/src/Model/Except.py index b88eccd2f298fd435a63f12f076fb94ac7bedbfe..a468b037ce03819596469e7b10d95a6289cc1ac5 100644 --- a/src/Model/Except.py +++ b/src/Model/Except.py @@ -1,9 +1,16 @@ # -*- coding: utf-8 -*- +from PyQt5.QtCore import ( + QCoreApplication, +) + from PyQt5.QtWidgets import ( QApplication, QMessageBox, ) +_translate = QCoreApplication.translate + + #################################### # Message Box for python exception # #################################### @@ -27,13 +34,13 @@ class ExeceptionWithMessageBox(Exception): self.title = title def header(self): - return "Generic error message" + return _translate("Exception", "Generic error message") def short_message(self): - return "Undefined error message" + return _translate("Exception", "Undefined error message") def message(self): - return "Undefined error message" + return _translate("Exception", "Undefined error message") def alert(self): msg = QMessageBox() @@ -46,21 +53,66 @@ class ExeceptionWithMessageBox(Exception): msg.exec_() +class NotImplementedMethodeError(ExeceptionWithMessageBox): + def __init__(self, obj, func): + super(NotImplementedMethodeError, self).__init__( + title = _translate("Exception", "Method not implemented") + ) + + self.obj = obj + self.func = func + + self.alert() + + def __str__(self): + return ( + _translate("Exception", "Method") + + f" '{self.func.__name__}' " + + _translate("Exception", "not implemented") + + _translate("Exception", "for class") + + f" '{self.obj.__class__}'" + ) + + def header(self): + return _translate("Exception", "Not implemented method") + + def short_message(self): + return _translate("Exception", "Not implemented method") + + def message(self): + return ( + _translate("Exception", "Method") + + f" '{self.func.__name__}' " + + _translate("Exception", "not implemented") + + _translate("Exception", "for class") + + f" '{self.obj.__class__}'" + ) + class FileFormatError(ExeceptionWithMessageBox): def __init__(self, filename, reason): - super(FileFormatError, self).__init__(title = "FileFormatError") + super(FileFormatError, self).__init__( + title = _translate("Exception", "FileFormatError") + ) self.reason = reason self.filename = filename def __str__(self): - return f"Invalid file format: '{self.filename}'\n{self.message()}" + return ( + _translate("Exception", "Invalid file format:") + + f" '{self.filename}'\n{self.message()}" + ) def header(self): - return "File format error" + return _translate("Exception", "File format error") def short_message(self): - return "Invalid file format" + return _translate("Exception", "Invalid file format") def message(self): - return f"Invalid file '{self.filename}' format because of '{self.reason}'" + return ( + _translate("Exception", "Invalid file") + + f" '{self.filename}' " + + _translate("Exception", "format because of") + + f" '{self.reason}'" + ) diff --git a/src/Model/Geometry/Point.py b/src/Model/Geometry/Point.py index f83731f60dc6fb4eb536eae5602266f8844daa5c..699004416be61c5728b2c882f9476bc8418c8135 100644 --- a/src/Model/Geometry/Point.py +++ b/src/Model/Geometry/Point.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from Model.Except import NotImplementedMethodeError + class Point(object): def __init__(self, name:str = ""): super(Point, self).__init__() @@ -20,3 +22,9 @@ class Point(object): True if the point is named. """ return self._name.strip() != "" + + def is_nan(self): + raise NotImplementedMethodeError(self, self.is_nan) + + def dist(self, p2): + raise NotImplementedMethodeError(self, self.dist) diff --git a/src/Model/Geometry/PointXY.py b/src/Model/Geometry/PointXY.py index 65d7baf98c53f55cdc06cab342d74073e5ef5598..f118522a0a7d6016883611ea427a2e783afbe648 100644 --- a/src/Model/Geometry/PointXY.py +++ b/src/Model/Geometry/PointXY.py @@ -31,6 +31,9 @@ class PointAC(Point): def c(self, value): self._c = float(value) + def dist(self, p2): + return PointAC.distance(self, p2) + @staticmethod def distance(p1, p2): """Euclidean distance between p1 and p2. diff --git a/src/Model/Geometry/PointXYZ.py b/src/Model/Geometry/PointXYZ.py index 6939cadf57618271445518e3095c3e9d7dc8da52..e0c29860a26a0c819b9f178c9f4ce1d1becb2f83 100644 --- a/src/Model/Geometry/PointXYZ.py +++ b/src/Model/Geometry/PointXYZ.py @@ -50,6 +50,9 @@ class PointXYZ(Point): isna(self.y) or isna(self.z)) + def dist(self, p2): + return PointXYZ.distance(self, p2) + @staticmethod def distance(p1, p2): """Euclidean distance between p1 and p2. diff --git a/src/View/Geometry/GeometryWindow.py b/src/View/Geometry/GeometryWindow.py index 7a045b5ad56741f759bf61d3bccefae2077a35c0..ea3728433d909e26b2dfcf70bad6b9b451f058cd 100644 --- a/src/View/Geometry/GeometryWindow.py +++ b/src/View/Geometry/GeometryWindow.py @@ -20,6 +20,7 @@ from View.Geometry import qtableview_reach from View.Geometry import window_profileXYZ from View.ASubWindow import WindowToolKit + _translate = QCoreApplication.translate class GeometryWindow(QMainWindow, WindowToolKit):