Commit 9944159d authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Model: Minor change and add custom exception with message box.

Showing with 86 additions and 978 deletions
+86 -978
......@@ -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)}'"
)
......@@ -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))
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 !")
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()
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:
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_header.append(line)
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:
print(f"Point {line} invalide ==> pas pris en compte")
line_is_header = False
list_point_profile.append(line)
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
pass
if list_profile and list_header:
raise FileFormatError(self.file_st, f"{list_profile}, {list_header}")
except FileNotFoundError:
print(f"\n \n %%%%%% Fichier : {self.file_st} introuvable !! %%%%%%")
print("****** Fichier {} lu et traité en {} secondes *******".format(self.file_st, time() - t0))
return list_profile, list_header
......@@ -60,7 +60,11 @@ class ASubWindow(QDialog):
Returns:
Nothing
"""
self.find(QLineEdit, name).setText(text)
try:
self.find(QLineEdit, name).setText(text)
except AttributeError as e:
print(e)
print(f"{name}")
def get_line_edit_text(self, name:str):
"""Get text of line edit component
......@@ -283,7 +287,7 @@ class ASubWindow(QDialog):
msg.setInformativeText(f"{informative_text}")
msg.setWindowTitle(f"{window_title}")
# msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
_width = len(f"{text} : {value}")
msg.setStyleSheet("QLabel{min-width:200 px; font-size: 13px;} QPushButton{width:10px; font-size: 12px};"
"background-color: Ligthgray; color : gray; font-size: 8pt; color: #888a80;")
# _width = len(f"{text} : {value}")
# msg.setStyleSheet("QLabel{min-width:200 px; font-size: 13px;} QPushButton{width:10px; font-size: 12px};"
# "background-color: Ligthgray; color : gray; font-size: 8pt; color: #888a80;")
msg.exec_()
......@@ -75,8 +75,8 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
self.find(QTableView, "tableView_solver")\
.setSelectionBehavior(QAbstractItemView.SelectRows)
# Mailleur
self.set_line_edit_text("lineEdit_mailleur", self.conf.mailleur)
# Meshing_Tool
self.set_line_edit_text("lineEdit_meshing_tool", self.conf.meshing_tool)
# Const
self.set_line_edit_text("lineEdit_segment", str(self.conf.segment))
......@@ -109,10 +109,10 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
"lineEdit_backup_path", f[0]
)
),
"pushButton_mailleur" : lambda: self.file_dialog(
"pushButton_meshing_tool" : lambda: self.file_dialog(
select_file = True,
callback = lambda f: self.set_line_edit_text(
"lineEdit_mailleur", f[0]
"lineEdit_meshing_tool", f[0]
)
),
}
......@@ -124,8 +124,8 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
# Solvers
self.conf.solvers = self.solver_table_model.rows.copy()
# Mailleur
self.conf.mailleur = self.get_line_edit_text("lineEdit_mailleur")
# Meshing_Tool
self.conf.meshing_tool = self.get_line_edit_text("lineEdit_meshing_tool")
# Const
self.conf.segment = self.get_line_edit_text("lineEdit_segment")
......
......@@ -127,10 +127,10 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_mailleur_2"/>
<widget class="QLineEdit" name="lineEdit_meshing_tool"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_mailleur_2">
<widget class="QPushButton" name="pushButton_meshing_tool">
<property name="text">
<string/>
</property>
......
This diff is collapsed.
......@@ -17,8 +17,8 @@ class Config(object):
# Solvers
self.solvers = []
# Mailleur
self.mailleur = ""
# Meshing tool
self.meshing_tool = ""
# Const
self.segment = 1000
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment