mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Model: Minor change and add custom exception with message box.
This commit is contained in:
1 parent
81fdb9827b
commit
9944159d73
7 files changed
+88
-980
No files matched your search
@@ -73,7 +73,10 @@ class ProfileXYZ(Profile):
|
||||
Returns:
|
||||
Profile header.
|
||||
"""
|
||||
return np.array([self._num, self._code1, self._code2, self._nb_points, self._kp, self._name])
|
||||
return np.array(
|
||||
[self._num, self._code1, self._code2,
|
||||
self._nb_points, self._kp, self._name]
|
||||
)
|
||||
|
||||
def import_points(self, list_points: list):
|
||||
"""Import a list of points to profile
|
||||
@@ -100,7 +103,7 @@ class ProfileXYZ(Profile):
|
||||
try:
|
||||
return self._list_points[index]
|
||||
except IndexError:
|
||||
raise IndexError(f"Le profil a moins de {index} points !")
|
||||
raise IndexError(f"Invalid point index: {index}")
|
||||
|
||||
def add(self):
|
||||
"""Add a new PointXYZ to profile.
|
||||
@@ -123,7 +126,7 @@ class ProfileXYZ(Profile):
|
||||
try:
|
||||
self._list_points.pop(index)
|
||||
except IndexError:
|
||||
raise IndexError(f"Suppression échouée, l'indice {index} n'existe pas !")
|
||||
raise IndexError(f"Invalid point index: {index}")
|
||||
|
||||
def insert(self, index: int):
|
||||
"""Insert a new profile at index.
|
||||
@@ -154,10 +157,12 @@ class ProfileXYZ(Profile):
|
||||
try:
|
||||
self._list_points.pop(idx)
|
||||
except IndexError:
|
||||
print("Liste vide, rien à supprimer !")
|
||||
print("Empty list, nothing to delete")
|
||||
except TypeError:
|
||||
if isinstance(list_index, int):
|
||||
self._list_points.pop(list_index)
|
||||
print(f"\nSuppression --> attention !!!!\nL'argument {list_index} doit être une liste!\n")
|
||||
print(f"\n{list_index} is not a list\n")
|
||||
else:
|
||||
raise TypeError(f"L'argument {list_index} fourni est de type incorrect")
|
||||
raise TypeError(
|
||||
f"{list_index} is instance of unexpected type '{type(list_index)}'"
|
||||
)
|
||||
+59
-52
@@ -10,6 +10,8 @@ from operator import itemgetter
|
||||
from Model.Geometry.Profile import Profile
|
||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||
|
||||
from Model.Except import FileFormatError, exception_message_box
|
||||
|
||||
class Reach:
|
||||
def __init__(self, edge):
|
||||
self._edge = edge
|
||||
@@ -45,7 +47,7 @@ class Reach:
|
||||
try:
|
||||
return self._list_profiles[i]
|
||||
except IndexError:
|
||||
raise IndexError(f"Le bief a moins de {i} profil(s)")
|
||||
raise IndexError(f"Invalid profile index: {i}")
|
||||
|
||||
def add_XYZ(self):
|
||||
"""Add a new profile at the end of profiles list
|
||||
@@ -98,14 +100,13 @@ class Reach:
|
||||
self._list_profiles.pop(idx)
|
||||
self._update_profile_numbers()
|
||||
except IndexError:
|
||||
print("Liste vide, rien à supprimer !")
|
||||
print(f"Invalid profile index: {idx}")
|
||||
except TypeError:
|
||||
if isinstance(list_index, int):
|
||||
self._list_profiles.pop(list_index)
|
||||
self._update_profile_numbers()
|
||||
print(f"\nSuppression --> attention !!!!\nL'argument {list_index} doit être une liste!\n")
|
||||
else:
|
||||
raise TypeError(f"L'argument {list_index} fourni est de type incorrect")
|
||||
raise TypeError(f"{list_index} is instance of unexpected type '{type(list_index)}'")
|
||||
|
||||
def _sort(self, is_reversed: bool = False):
|
||||
self._list_profiles = sorted(
|
||||
@@ -137,13 +138,12 @@ class Reach:
|
||||
try:
|
||||
self.__list_copied_profiles.append(deepcopy(self.get_profile_i(index)))
|
||||
except IndexError:
|
||||
raise IndexError(f"Echec de la copie, l'indice {index} n'existe pas !")
|
||||
raise IndexError(f"Invalid profile index: {index}")
|
||||
|
||||
def paste(self):
|
||||
if self.__list_copied_profiles:
|
||||
for profile in self.__list_copied_profiles:
|
||||
self._list_profiles.append(profile)
|
||||
print("self.__list_copied_profiles", self.__list_copied_profiles, "\n *****")
|
||||
|
||||
def import_geometry(self, file_path_name: str):
|
||||
"""Import a geometry from file (.ST or .st)
|
||||
@@ -154,16 +154,21 @@ class Reach:
|
||||
Returns:
|
||||
Nothing.
|
||||
"""
|
||||
list_profile, list_header = self.read_file_st(str(file_path_name))
|
||||
try:
|
||||
list_profile, list_header = self.read_file_st(str(file_path_name))
|
||||
|
||||
if list_profile and list_header:
|
||||
for ind, profile in enumerate(list_profile):
|
||||
prof = ProfileXYZ(*list_header[ind])
|
||||
prof.import_points(profile)
|
||||
self._list_profiles.append(prof)
|
||||
self._update_profile_numbers()
|
||||
else:
|
||||
print("Fichier introuvable ou non conforme !")
|
||||
if list_profile and list_header:
|
||||
for ind, profile in enumerate(list_profile):
|
||||
prof = ProfileXYZ(*list_header[ind])
|
||||
prof.import_points(profile)
|
||||
self._list_profiles.append(prof)
|
||||
self._update_profile_numbers()
|
||||
except FileNotFoundError as e:
|
||||
print(e)
|
||||
exception_message_box(e)
|
||||
except FileFormatError as e:
|
||||
print(e)
|
||||
e.alert()
|
||||
|
||||
def read_file_st(self):
|
||||
"""Read the ST file
|
||||
@@ -177,43 +182,45 @@ class Reach:
|
||||
list_profile = []
|
||||
list_header = []
|
||||
stop_code = "999.999"
|
||||
try:
|
||||
with open(self.file_st, encoding="utf-8") as file_st:
|
||||
for line in file_st:
|
||||
if not (line.startswith("#") or line.startswith("*")):
|
||||
line = line.split()
|
||||
if line_is_header:
|
||||
if len(line) >= 6:
|
||||
list_header.append(line[:6])
|
||||
elif len(line) == 5:
|
||||
line.append("")
|
||||
list_header.append(line)
|
||||
else:
|
||||
print(f"Point {line} invalide ==> pas pris en compte")
|
||||
line_is_header = False
|
||||
else:
|
||||
# Read until "999.9990 999.9990" as found
|
||||
if len(line) == 3:
|
||||
x, y, z = line
|
||||
if stop_code in x and stop_code in y:
|
||||
line_is_header = True
|
||||
list_profile.append(list_point_profile)
|
||||
list_point_profile = []
|
||||
else:
|
||||
line.append("")
|
||||
list_point_profile.append(line)
|
||||
elif len(line) == 4:
|
||||
x, y, z, ld = line
|
||||
if stop_code in x and stop_code in y:
|
||||
list_profile.append(list_point_profile)
|
||||
list_point_profile = []
|
||||
line_is_header = True
|
||||
else:
|
||||
list_point_profile.append(line)
|
||||
else:
|
||||
pass
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"\n \n %%%%%% Fichier : {self.file_st} introuvable !! %%%%%%")
|
||||
with open(self.file_st, encoding="utf-8") as file_st:
|
||||
for line in file_st:
|
||||
if not (line.startswith("#") or line.startswith("*")):
|
||||
line = line.split()
|
||||
|
||||
if line_is_header:
|
||||
if len(line) >= 6:
|
||||
list_header.append(line[:6])
|
||||
elif len(line) == 5:
|
||||
line.append("")
|
||||
list_header.append(line)
|
||||
else:
|
||||
print(f"Point {line} invalide ==> pas pris en compte")
|
||||
line_is_header = False
|
||||
else:
|
||||
# Read until "999.9990 999.9990" as found
|
||||
if len(line) == 3:
|
||||
x, y, z = line
|
||||
if stop_code in x and stop_code in y:
|
||||
line_is_header = True
|
||||
list_profile.append(list_point_profile)
|
||||
list_point_profile = []
|
||||
else:
|
||||
line.append("")
|
||||
list_point_profile.append(line)
|
||||
elif len(line) == 4:
|
||||
x, y, z, ld = line
|
||||
if stop_code in x and stop_code in y:
|
||||
list_profile.append(list_point_profile)
|
||||
list_point_profile = []
|
||||
line_is_header = True
|
||||
else:
|
||||
list_point_profile.append(line)
|
||||
else:
|
||||
pass
|
||||
|
||||
if list_profile and list_header:
|
||||
raise FileFormatError(self.file_st, f"{list_profile}, {list_header}")
|
||||
|
||||
print("****** Fichier {} lu et traité en {} secondes *******".format(self.file_st, time() - t0))
|
||||
return list_profile, list_header
|
||||
Reference in new issue
Block a user