mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Continue to adapt to new model scheme.
parent
af4832a134
commit
2708e81ebb
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from math import dist
|
from math import dist
|
||||||
from pandas import isna as pd_is_na
|
from pandas import isna
|
||||||
|
|
||||||
from Model.Geometry.Point import Point
|
from Model.Geometry.Point import Point
|
||||||
|
|
||||||
|
|
@ -41,13 +41,14 @@ class PointXYZ(Point):
|
||||||
def z(self, value):
|
def z(self, value):
|
||||||
self._z = float(value)
|
self._z = float(value)
|
||||||
|
|
||||||
@property
|
|
||||||
def is_nan(self):
|
def is_nan(self):
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
True if at least one coordinate is as np.nan
|
True if at least one coordinate is as np.nan
|
||||||
"""
|
"""
|
||||||
return pd_is_na(self.x) or pd_is_na(self.y) or pd_is_na(self.z)
|
return (isna(self.x) or
|
||||||
|
isna(self.y) or
|
||||||
|
isna(self.z))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def distance(p1, p2):
|
def distance(p1, p2):
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,36 @@ class ProfileXYZ(Profile):
|
||||||
self.nb_points(), self._kp, self._name]
|
self.nb_points(), self._kp, self._name]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def x(self):
|
||||||
|
return [point.x for point in self._points]
|
||||||
|
|
||||||
|
def y(self):
|
||||||
|
return [point.y for point in self._points]
|
||||||
|
|
||||||
|
def z(self):
|
||||||
|
return [point.z for point in self._points]
|
||||||
|
|
||||||
|
def names(self):
|
||||||
|
return [point.name for point in self._points]
|
||||||
|
|
||||||
|
def x_max(self):
|
||||||
|
return max(self.filter_isnan(self.x))
|
||||||
|
|
||||||
|
def x_min(self):
|
||||||
|
return min(self.filter_isnan(self.x))
|
||||||
|
|
||||||
|
def y_max(self):
|
||||||
|
return max(self.filter_isnan(self.y))
|
||||||
|
|
||||||
|
def y_min(self):
|
||||||
|
return min(self.filter_isnan(self.y))
|
||||||
|
|
||||||
|
def z_max(self):
|
||||||
|
return max(self.filter_isnan(self.z))
|
||||||
|
|
||||||
|
def z_min(self):
|
||||||
|
return min(self.filter_isnan(self.z))
|
||||||
|
|
||||||
def import_points(self, list_points: list):
|
def import_points(self, list_points: list):
|
||||||
"""Import a list of points to profile
|
"""Import a list of points to profile
|
||||||
|
|
||||||
|
|
@ -148,32 +178,91 @@ class ProfileXYZ(Profile):
|
||||||
"""
|
"""
|
||||||
return [x for x in lst if not np.isnan(x)]
|
return [x for x in lst if not np.isnan(x)]
|
||||||
|
|
||||||
def x(self):
|
def get_station(self) -> np.ndarray:
|
||||||
return [point.x for point in self._points]
|
"""Projection of the points of the profile on a plane.
|
||||||
|
|
||||||
def y(self):
|
Args:
|
||||||
return [point.y for point in self._points]
|
profile: The profile
|
||||||
|
|
||||||
def z(self):
|
Returns:
|
||||||
return [point.z for point in self._points]
|
Projection of the points of the profile on a plane.
|
||||||
|
"""
|
||||||
|
if self.nb_points >= 3:
|
||||||
|
first_named_point = None
|
||||||
|
index_first_named_point = None
|
||||||
|
last_named_point = None
|
||||||
|
|
||||||
def names(self):
|
for index, point in enumerate(self.points):
|
||||||
return [point.name for point in self._points]
|
if point.point_is_named():
|
||||||
|
index_first_named_point = index
|
||||||
|
first_named_point = point
|
||||||
|
break
|
||||||
|
|
||||||
def x_max(self):
|
for point in self._points[::-1]:
|
||||||
return max(self.filter_isnan(self.x))
|
if point.point_is_named():
|
||||||
|
last_named_point = point
|
||||||
|
break
|
||||||
|
|
||||||
def x_min(self):
|
station = []
|
||||||
return min(self.filter_isnan(self.x))
|
constant = 0.0
|
||||||
|
|
||||||
def y_max(self):
|
if ((first_named_point is not None) and
|
||||||
return max(self.filter_isnan(self.y))
|
(last_named_point is not None)):
|
||||||
|
if (first_named_point != last_named_point and
|
||||||
|
first_named_point.x != last_named_point.x):
|
||||||
|
vector = Vector1d(first_named_point, last_named_point)
|
||||||
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
else:
|
||||||
|
vector = Vector1d(_first_point_not_nan(profile),
|
||||||
|
_last_point_not_nan(profile))
|
||||||
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
def y_min(self):
|
for point in self._points:
|
||||||
return min(self.filter_isnan(self.y))
|
xi = point.x - first_named_point.x
|
||||||
|
yi = point.y - first_named_point.y
|
||||||
|
station_i = (normalized_direction_vec[0] * xi +
|
||||||
|
normalized_direction_vec[1] * yi)
|
||||||
|
station.append(station_i)
|
||||||
|
|
||||||
def z_max(self):
|
station = np.array(station)
|
||||||
return max(self.filter_isnan(self.z))
|
|
||||||
|
|
||||||
def z_min(self):
|
constant = station[index_first_named_point]
|
||||||
return min(self.filter_isnan(self.z))
|
elif first_named_point is None:
|
||||||
|
vector = Vector1d(_first_point_not_nan(profile),
|
||||||
|
_last_point_not_nan(profile))
|
||||||
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
|
for point in self._points:
|
||||||
|
xi = point.x - _first_point_not_nan(profile).x
|
||||||
|
yi = point.y - _first_point_not_nan(profile).y
|
||||||
|
station_i = (normalized_direction_vec[0] * xi +
|
||||||
|
normalized_direction_vec[1] * yi)
|
||||||
|
station.append(station_i)
|
||||||
|
|
||||||
|
station = np.array(station)
|
||||||
|
index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0]
|
||||||
|
constant = station[index_profile_z_min]
|
||||||
|
|
||||||
|
return (station - constant)
|
||||||
|
else:
|
||||||
|
return np.array(np.nan)
|
||||||
|
|
||||||
|
def _first_point_not_nan(self):
|
||||||
|
first_point = self._points[0]
|
||||||
|
|
||||||
|
for point in self.points:
|
||||||
|
if not point.is_nan():
|
||||||
|
first_point = point
|
||||||
|
break
|
||||||
|
|
||||||
|
return first_point_not_nan
|
||||||
|
|
||||||
|
def _last_point_not_nan(self):
|
||||||
|
last_point = self._points[-1]
|
||||||
|
|
||||||
|
for point in self._points[::-1]:
|
||||||
|
if not point.is_nan():
|
||||||
|
last_point = point
|
||||||
|
break
|
||||||
|
|
||||||
|
return last_point
|
||||||
|
|
|
||||||
|
|
@ -123,10 +123,10 @@ class Reach:
|
||||||
else:
|
else:
|
||||||
raise TypeError(f"{list_index} is instance of unexpected type '{type(list_index)}'")
|
raise TypeError(f"{list_index} is instance of unexpected type '{type(list_index)}'")
|
||||||
|
|
||||||
def _sort(self, is_reversed: bool = False):
|
def sort(self, is_reversed: bool = False):
|
||||||
self._profiles = sorted(
|
self._profiles = sorted(
|
||||||
self._profiles,
|
self._profiles,
|
||||||
key=lambda profile: profile.kp(),
|
key=lambda profile: profile.kp,
|
||||||
reverse=is_reversed
|
reverse=is_reversed
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,54 +44,55 @@ def get_station(profile: ProfileXYZ) -> np.ndarray:
|
||||||
last_named_point = point
|
last_named_point = point
|
||||||
break
|
break
|
||||||
|
|
||||||
station = [] # abscisse en travers
|
station = []
|
||||||
constant = 0.0 # constante pour décaler l'origine de l'ascisse en travers caluculée.
|
constant = 0.0
|
||||||
|
|
||||||
if (first_named_point is not None) and (last_named_point is not None):
|
if ((first_named_point is not None) and
|
||||||
if first_named_point != last_named_point and first_named_point.x != last_named_point.x:
|
(last_named_point is not None)):
|
||||||
|
if (first_named_point != last_named_point and
|
||||||
|
first_named_point.x != last_named_point.x):
|
||||||
vector = Vector1d(first_named_point, last_named_point)
|
vector = Vector1d(first_named_point, last_named_point)
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
else:
|
else:
|
||||||
vector = Vector1d(_first_point_not_nan(profile), _last_point_not_nan(profile))
|
vector = Vector1d(_first_point_not_nan(profile),
|
||||||
|
_last_point_not_nan(profile))
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
for point in profile.points:
|
for point in profile.points:
|
||||||
xi = point.x - first_named_point.x
|
xi = point.x - first_named_point.x
|
||||||
yi = point.y - first_named_point.y
|
yi = point.y - first_named_point.y
|
||||||
station_i = normalized_direction_vec[0] * xi + normalized_direction_vec[1] * yi
|
station_i = (normalized_direction_vec[0] * xi +
|
||||||
|
normalized_direction_vec[1] * yi)
|
||||||
station.append(station_i)
|
station.append(station_i)
|
||||||
|
|
||||||
station = np.array(station)
|
station = np.array(station)
|
||||||
|
|
||||||
constant = station[index_first_named_point] # pour placer l'origine au premier point nomme.
|
constant = station[index_first_named_point]
|
||||||
elif first_named_point is None:
|
elif first_named_point is None:
|
||||||
vector = Vector1d(_first_point_not_nan(profile), _last_point_not_nan(profile))
|
vector = Vector1d(_first_point_not_nan(profile),
|
||||||
|
_last_point_not_nan(profile))
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
for point in profile.points:
|
for point in profile.points:
|
||||||
xi = point.x - _first_point_not_nan(profile).x
|
xi = point.x - _first_point_not_nan(profile).x
|
||||||
yi = point.y - _first_point_not_nan(profile).y
|
yi = point.y - _first_point_not_nan(profile).y
|
||||||
station_i = normalized_direction_vec[0] * xi + normalized_direction_vec[1] * yi
|
station_i = (normalized_direction_vec[0] * xi +
|
||||||
|
normalized_direction_vec[1] * yi)
|
||||||
station.append(station_i)
|
station.append(station_i)
|
||||||
|
|
||||||
station = np.array(station)
|
station = np.array(station)
|
||||||
index_profile_z_min = np.where(np.array(profile.z) == profile.z_min)[0][0]
|
index_profile_z_min = np.where(np.array(profile.z) == profile.z_min)[0][0]
|
||||||
constant = station[index_profile_z_min] # pour placer l'origine au fond ie à la cote minimale
|
constant = station[index_profile_z_min]
|
||||||
# z_min du profil.
|
|
||||||
station = station - constant
|
|
||||||
|
|
||||||
return station
|
return (station - constant)
|
||||||
else:
|
else:
|
||||||
return np.array(np.nan)
|
return np.array(np.nan)
|
||||||
|
|
||||||
def _point_is_nan(point: PointXYZ):
|
|
||||||
return pd.isna(point.x) or pd.isna(point.y) or pd.isna(point.z)
|
|
||||||
|
|
||||||
def _first_point_not_nan(profile: ProfileXYZ):
|
def _first_point_not_nan(profile: ProfileXYZ):
|
||||||
first_point_not_nan = profile.points[0]
|
first_point_not_nan = profile.points[0]
|
||||||
|
|
||||||
for point in profile.points:
|
for point in profile.points:
|
||||||
if not _point_is_nan(point):
|
if not point.is_nan():
|
||||||
first_point_not_nan = point
|
first_point_not_nan = point
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -101,7 +102,7 @@ def _last_point_not_nan(profile: ProfileXYZ):
|
||||||
last_point = profile.points[-1]
|
last_point = profile.points[-1]
|
||||||
|
|
||||||
for point in profile.points[::-1]:
|
for point in profile.points[::-1]:
|
||||||
if not _point_is_nan(point):
|
if not point.is_nan():
|
||||||
last_point = point
|
last_point = point
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,15 +89,9 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
)
|
)
|
||||||
|
|
||||||
current_dir = os.path.split(filename)[0] or DEFAULT_DIRECTORY
|
current_dir = os.path.split(filename)[0] or DEFAULT_DIRECTORY
|
||||||
#settings.setValue('current_directory', current_dir)
|
|
||||||
if filename != "":
|
if filename != "":
|
||||||
size = os.stat(filename).st_size
|
size = os.stat(filename).st_size
|
||||||
self._reach.import_geometry(filename)
|
self._reach.import_geometry(filename)
|
||||||
# self.model = qtableview_reach.PandasModelEditable(
|
|
||||||
# ,
|
|
||||||
# self.tableView_header
|
|
||||||
# )
|
|
||||||
# self.tableView.setModel(self.model)
|
|
||||||
self.model.layoutChanged.emit()
|
self.model.layoutChanged.emit()
|
||||||
|
|
||||||
self.update_profile_windows()
|
self.update_profile_windows()
|
||||||
|
|
@ -149,7 +143,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
for selected_row in list_selected_row[:5]:
|
for selected_row in list_selected_row[:5]:
|
||||||
selected_row = int(selected_row)
|
selected_row = int(selected_row)
|
||||||
profile_identifier = self._reach.get_profile_selected_identifier(selected_row)
|
profile_identifier = self._reach.get_profile_selected_identifier(selected_row)
|
||||||
Kp = self._reach.get_kp_i(selected_row)
|
Kp = self._reach.profile(selected_row).kp
|
||||||
profile_name = self._reach.get_profile_name(selected_row)
|
profile_name = self._reach.get_profile_name(selected_row)
|
||||||
|
|
||||||
if len(self.list_second_window) == 0:
|
if len(self.list_second_window) == 0:
|
||||||
|
|
@ -220,9 +214,6 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
self.update_graphic_1()
|
self.update_graphic_1()
|
||||||
print("update_graphic_1_profile")
|
print("update_graphic_1_profile")
|
||||||
|
|
||||||
def print_data(self):
|
|
||||||
print(self.model_data.profile)
|
|
||||||
|
|
||||||
def update_profile_windows(self):
|
def update_profile_windows(self):
|
||||||
self.list_second_window = []
|
self.list_second_window = []
|
||||||
self.list_row = []
|
self.list_row = []
|
||||||
|
|
@ -290,33 +281,33 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
_translate("MainWindow_reach", "Cote (m)"), color='green', fontsize=12
|
_translate("MainWindow_reach", "Cote (m)"), color='green', fontsize=12
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_kp = self._reach.get_kp()
|
kp = self._reach.get_kp()
|
||||||
self.get_z_min = self._reach.get_z_min()
|
z_min = self._reach.get_z_min()
|
||||||
self.get_z_max = self._reach.get_z_max()
|
z_max = self._reach.get_z_max()
|
||||||
|
|
||||||
self.line_kp_zmin_zmax = self.ui.canvas_2.axes.vlines(
|
self.line_kp_zmin_zmax = self.ui.canvas_2.axes.vlines(
|
||||||
x=self.get_kp,
|
x=kp,
|
||||||
ymin=self.get_z_min, ymax=self.get_z_max,
|
ymin=z_min, ymax=z_max,
|
||||||
color='r', lw=1.
|
color='r', lw=1.
|
||||||
)
|
)
|
||||||
|
|
||||||
self.plot_selected_2, = self.ui.canvas_2.axes.plot(
|
self.plot_selected_2, = self.ui.canvas_2.axes.plot(
|
||||||
(self.get_kp[0], self.get_kp[0]),
|
(kp[0], kp[0]),
|
||||||
(self.get_z_min[0], self.get_z_max[0]),
|
(z_min[0], z_max[0]),
|
||||||
color='b', lw=1.8
|
color='b', lw=1.8
|
||||||
)
|
)
|
||||||
self.plot_selected_2.set_visible(False)
|
self.plot_selected_2.set_visible(False)
|
||||||
|
|
||||||
self.before_plot_selected_2, = self.ui.canvas_2.axes.plot(
|
self.before_plot_selected_2, = self.ui.canvas_2.axes.plot(
|
||||||
(self.get_kp[0], self.get_kp[0]),
|
(kp[0], kp[0]),
|
||||||
(self.get_z_min[0], self.get_z_max[0]),
|
(z_min[0], z_max[0]),
|
||||||
color='k', lw=1.6, linestyle='--'
|
color='k', lw=1.6, linestyle='--'
|
||||||
)
|
)
|
||||||
self.before_plot_selected_2.set_visible(False)
|
self.before_plot_selected_2.set_visible(False)
|
||||||
|
|
||||||
self.after_plot_selected_2, = self.ui.canvas_2.axes.plot(
|
self.after_plot_selected_2, = self.ui.canvas_2.axes.plot(
|
||||||
(self.get_kp[0], self.get_kp[0]),
|
(kp[0], kp[0]),
|
||||||
(self.get_z_min[0], self.get_z_max[0]),
|
(z_min[0], z_max[0]),
|
||||||
color='m', lw=1.6, linestyle='--'
|
color='m', lw=1.6, linestyle='--'
|
||||||
)
|
)
|
||||||
self.after_plot_selected_2.set_visible(False)
|
self.after_plot_selected_2.set_visible(False)
|
||||||
|
|
@ -331,7 +322,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
print("TODO")
|
print("TODO")
|
||||||
|
|
||||||
self.line_kp_zmin, = self.ui.canvas_2.axes.plot(
|
self.line_kp_zmin, = self.ui.canvas_2.axes.plot(
|
||||||
self.get_kp, self.get_z_min,
|
kp, z_min,
|
||||||
linestyle=":", lw=1.8,
|
linestyle=":", lw=1.8,
|
||||||
color='lightgrey'
|
color='lightgrey'
|
||||||
)
|
)
|
||||||
|
|
@ -347,8 +338,8 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
|
|
||||||
for ind in range(self.model.rowCount()):
|
for ind in range(self.model.rowCount()):
|
||||||
self.line_xy[ind][0].set_data(
|
self.line_xy[ind][0].set_data(
|
||||||
self._reach.get_x_profile_i(ind),
|
self._reach.profile(ind).x,
|
||||||
self._reach.get_y_profile_i(ind)
|
self._reach.profile(ind).y
|
||||||
)
|
)
|
||||||
|
|
||||||
for i in range(len(self.line_ld_1)):
|
for i in range(len(self.line_ld_1)):
|
||||||
|
|
@ -363,23 +354,23 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
def update_graphic_2(self):
|
def update_graphic_2(self):
|
||||||
self.tableView.model().blockSignals(True)
|
self.tableView.model().blockSignals(True)
|
||||||
|
|
||||||
get_kp = self._reach.get_kp()
|
kp = self._reach.get_kp()
|
||||||
get_z_min = self._reach.get_z_min()
|
z_min = self._reach.get_z_min()
|
||||||
get_z_max = self._reach.get_z_max()
|
z_max = self._reach.get_z_max()
|
||||||
|
|
||||||
self.line_kp_zmin.set_data(get_kp, get_z_min)
|
self.line_kp_zmin.set_data(kp, z_min)
|
||||||
|
|
||||||
self.line_kp_zmin_zmax.remove()
|
self.line_kp_zmin_zmax.remove()
|
||||||
self.line_kp_zmin_zmax = self.ui.canvas_2.axes.vlines(
|
self.line_kp_zmin_zmax = self.ui.canvas_2.axes.vlines(
|
||||||
x=get_kp,
|
x=kp,
|
||||||
ymin=get_z_min, ymax=get_z_max,
|
ymin=z_min, ymax=z_max,
|
||||||
color='r', lw=1.
|
color='r', lw=1.
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for i in range(len(self.line_kp_zld)):
|
for i in range(len(self.line_kp_zld)):
|
||||||
self.line_kp_zld[i][0].set_data(
|
self.line_kp_zld[i][0].set_data(
|
||||||
get_kp, self.model.z_complete_guideline()[i]
|
kp, self.model.z_complete_guideline()[i]
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
print("TODO")
|
print("TODO")
|
||||||
|
|
@ -394,9 +385,9 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
selected_profile = 0
|
selected_profile = 0
|
||||||
station = self._reach.get_station(selected_profile) # L'abscisse en travers
|
station = self._reach.get_station(selected_profile) # L'abscisse en travers
|
||||||
station_plus_1 = self._reach.get_station(selected_profile + 1)
|
station_plus_1 = self._reach.get_station(selected_profile + 1)
|
||||||
elevation = self._reach.get_z_profile_i(selected_profile)
|
elevation = self._reach.profile(selected_profile).z
|
||||||
elevation_i_plus_1 = self._reach.get_z_profile_i(selected_profile + 1)
|
elevation_i_plus_1 = self._reach.profile(selected_profile + 1).z
|
||||||
ld = self._reach.get_ld_profile_i(selected_profile)
|
ld = self._reach.profile(selected_profile).name
|
||||||
|
|
||||||
self.ui.canvas_3.axes.cla()
|
self.ui.canvas_3.axes.cla()
|
||||||
self.ui.canvas_3.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
self.ui.canvas_3.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
@ -500,7 +491,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
|
|
||||||
x = self.get_station(ind)
|
x = self.get_station(ind)
|
||||||
y = self.get_elevation(ind)
|
y = self.get_elevation(ind)
|
||||||
ld = self._reach.get_ld_profile_i(ind)
|
ld = self._reach.profile(ind).name
|
||||||
get_complete_list_ld = self._reach.get_complete_list_ld()
|
get_complete_list_ld = self._reach.get_complete_list_ld()
|
||||||
get_incomplete_list_ld = self._reach.get_incomplete_list_ld()
|
get_incomplete_list_ld = self._reach.get_incomplete_list_ld()
|
||||||
|
|
||||||
|
|
@ -558,51 +549,47 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
return self._reach.get_station(ind)
|
return self._reach.get_station(ind)
|
||||||
|
|
||||||
def get_elevation(self, ind: int):
|
def get_elevation(self, ind: int):
|
||||||
return self._reach.get_z_profile_i(ind)
|
return self._reach.profile(ind).z
|
||||||
|
|
||||||
def update_graphic_3(self, ind: int):
|
def update_graphic_3(self, ind: int):
|
||||||
self.tableView.model().blockSignals(True)
|
self.tableView.model().blockSignals(True)
|
||||||
|
|
||||||
selected_profile = ind
|
if ind == 0:
|
||||||
print(selected_profile)
|
|
||||||
|
|
||||||
if selected_profile == 0:
|
|
||||||
self.profile_i_minus_1.set_data([], [])
|
self.profile_i_minus_1.set_data([], [])
|
||||||
self.profile_i.set_data(
|
self.profile_i.set_data(
|
||||||
self.get_station(selected_profile),
|
self.get_station(ind),
|
||||||
self.get_elevation(selected_profile)
|
self.get_elevation(ind)
|
||||||
)
|
)
|
||||||
self.profile_i_plus_1.set_data(
|
self.profile_i_plus_1.set_data(
|
||||||
self.get_station(selected_profile + 1),
|
self.get_station(ind + 1),
|
||||||
self.get_elevation(selected_profile + 1)
|
self.get_elevation(ind + 1)
|
||||||
)
|
)
|
||||||
elif selected_profile == self.model.rowCount() - 1:
|
elif ind == self.model.rowCount() - 1:
|
||||||
self.profile_i_minus_1.set_data(
|
self.profile_i_minus_1.set_data(
|
||||||
self.get_station(selected_profile - 1),
|
self.get_station(ind - 1),
|
||||||
self.get_elevation(selected_profile - 1)
|
self.get_elevation(ind - 1)
|
||||||
)
|
)
|
||||||
self.profile_i.set_data(
|
self.profile_i.set_data(
|
||||||
self.get_station(selected_profile),
|
self.get_station(ind),
|
||||||
self.get_elevation(selected_profile)
|
self.get_elevation(ind)
|
||||||
)
|
)
|
||||||
self.profile_i_plus_1.set_data([], [])
|
self.profile_i_plus_1.set_data([], [])
|
||||||
elif 0 < selected_profile < self.model.rowCount() - 1:
|
elif 0 < ind < self.model.rowCount() - 1:
|
||||||
self.profile_i_minus_1.set_data(
|
self.profile_i_minus_1.set_data(
|
||||||
self.get_station(selected_profile - 1),
|
self.get_station(ind - 1),
|
||||||
self.get_elevation(selected_profile - 1)
|
self.get_elevation(ind - 1)
|
||||||
)
|
)
|
||||||
self.profile_i.set_data(
|
self.profile_i.set_data(
|
||||||
self.get_station(selected_profile),
|
self.get_station(ind),
|
||||||
self.get_elevation(selected_profile)
|
self.get_elevation(ind)
|
||||||
)
|
)
|
||||||
self.profile_i_plus_1.set_data(
|
self.profile_i_plus_1.set_data(
|
||||||
self.get_station(selected_profile + 1),
|
self.get_station(ind + 1),
|
||||||
self.get_elevation(selected_profile + 1)
|
self.get_elevation(ind + 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.tableView.model().blockSignals(False)
|
self.tableView.model().blockSignals(False)
|
||||||
|
self.update_annotate_3(ind)
|
||||||
self.update_annotate_3(selected_profile)
|
|
||||||
|
|
||||||
self.ui.canvas_3.axes.relim()
|
self.ui.canvas_3.axes.relim()
|
||||||
self.ui.canvas_3.axes.autoscale_view()
|
self.ui.canvas_3.axes.autoscale_view()
|
||||||
|
|
@ -612,28 +599,27 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
self.tableView.model().blockSignals(True)
|
self.tableView.model().blockSignals(True)
|
||||||
|
|
||||||
if 0 <= ind < self.model.rowCount():
|
if 0 <= ind < self.model.rowCount():
|
||||||
self.plot_selected_1.set_data(self._reach.get_x_profile_i(ind),
|
self.plot_selected_1.set_data(self._reach.profile(ind).x,
|
||||||
self._reach.get_y_profile_i(ind))
|
self._reach.profile(ind).y)
|
||||||
self.plot_selected_1.set_visible(True)
|
self.plot_selected_1.set_visible(True)
|
||||||
|
|
||||||
self.tableView.model().blockSignals(False)
|
self.tableView.model().blockSignals(False)
|
||||||
|
|
||||||
def select_plot_graphic_2(self, ind: int):
|
def select_plot_graphic_2(self, ind: int):
|
||||||
get_kp_i = self.get_kp_i(ind)
|
kp_i = self._reach.profile(ind).kp
|
||||||
get_z_min_i = self.get_z_min_i(ind)
|
z_min_i = self._reach.profile(ind).z_min
|
||||||
get_z_max_i = self.get_z_max_i(ind)
|
z_max_i = self._reach.profile(ind).z_max
|
||||||
|
|
||||||
if 0 <= ind < self.model.rowCount():
|
if 0 <= ind < self.model.rowCount():
|
||||||
self.plot_selected_2.set_data((get_kp_i, get_kp_i),
|
self.plot_selected_2.set_data((kp_i, kp_i),
|
||||||
(get_z_min_i, get_z_max_i))
|
(z_min_i, z_max_i))
|
||||||
self.plot_selected_2.set_visible(True)
|
self.plot_selected_2.set_visible(True)
|
||||||
|
|
||||||
def select_before_plot_selected_1(self, ind: int):
|
def select_before_plot_selected_1(self, ind: int):
|
||||||
if 0 <= ind < self.model.rowCount():
|
if 0 <= ind < self.model.rowCount():
|
||||||
t0 = time.time()
|
|
||||||
|
|
||||||
self.before_plot_selected_1.set_data(
|
self.before_plot_selected_1.set_data(
|
||||||
self._reach.get_x_profile_i(ind),
|
self._reach.profile(ind).x,
|
||||||
self._reach.get_y_profile_i(ind)
|
self._reach.profile(ind).y
|
||||||
)
|
)
|
||||||
|
|
||||||
self.before_plot_selected_1.set_visible(True)
|
self.before_plot_selected_1.set_visible(True)
|
||||||
|
|
@ -642,22 +628,21 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
def select_after_plot_selected_1(self, ind: int):
|
def select_after_plot_selected_1(self, ind: int):
|
||||||
if 0 <= ind < self.model.rowCount():
|
if 0 <= ind < self.model.rowCount():
|
||||||
self.after_plot_selected_1.set_data(
|
self.after_plot_selected_1.set_data(
|
||||||
self._reach.get_x_profile_i(ind),
|
self._reach.profile(ind).x,
|
||||||
self._reach.get_y_profile_i(ind)
|
self._reach.profile(ind).y
|
||||||
)
|
)
|
||||||
self.after_plot_selected_1.set_visible(True)
|
self.after_plot_selected_1.set_visible(True)
|
||||||
self.ui.canvas_1.figure.canvas.draw_idle()
|
self.ui.canvas_1.figure.canvas.draw_idle()
|
||||||
|
|
||||||
def select_before_plot_selected_2(self, ind: int):
|
def select_before_plot_selected_2(self, ind: int):
|
||||||
if 0 <= ind < self.model.rowCount():
|
if 0 <= ind < self.model.rowCount():
|
||||||
t0 = time.time()
|
kp_i = self._reach.profile(ind).kp
|
||||||
get_kp_i = self.get_kp_i(ind)
|
z_min_i = self._reach.profile(ind).z_min
|
||||||
get_z_min_i = self.get_z_min_i(ind)
|
z_max_i = self._reach.profile(ind).z_max
|
||||||
get_z_max_i = self.get_z_max_i(ind)
|
|
||||||
|
|
||||||
self.before_plot_selected_2.set_data(
|
self.before_plot_selected_2.set_data(
|
||||||
(get_kp_i, get_kp_i),
|
(kp_i, kp_i),
|
||||||
(get_z_min_i, get_z_max_i)
|
(z_min_i, z_max_i)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.before_plot_selected_2.set_visible(True)
|
self.before_plot_selected_2.set_visible(True)
|
||||||
|
|
@ -665,14 +650,13 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
|
|
||||||
def select_after_plot_selected_2(self, ind: int):
|
def select_after_plot_selected_2(self, ind: int):
|
||||||
if 0 <= ind < self.model.rowCount():
|
if 0 <= ind < self.model.rowCount():
|
||||||
t0 = time.time()
|
kp_i = self._reach.profile(ind).kp
|
||||||
get_kp_i = self.get_kp_i(ind)
|
z_min_i = self._reach.profile(ind).z_min
|
||||||
get_z_min_i = self.get_z_min_i(ind)
|
z_max_i = self._reach.profile(ind).z_max
|
||||||
get_z_max_i = self.get_z_max_i(ind)
|
|
||||||
|
|
||||||
self.after_plot_selected_2.set_data(
|
self.after_plot_selected_2.set_data(
|
||||||
(get_kp_i, get_kp_i),
|
(kp_i, kp_i),
|
||||||
(get_z_min_i, get_z_max_i)
|
(z_min_i, z_max_i)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.after_plot_selected_2.set_visible(True)
|
self.after_plot_selected_2.set_visible(True)
|
||||||
|
|
@ -726,11 +710,11 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
def changed_slider_value(self):
|
def changed_slider_value(self):
|
||||||
self.tableView.model().blockSignals(True)
|
self.tableView.model().blockSignals(True)
|
||||||
|
|
||||||
if self.filename is not None:
|
if self.model.rowCount() != 0:
|
||||||
self.ui.verticalSlider.setMaximum(self.model.rowCount() - 1)
|
self.ui.verticalSlider.setMaximum(self.model.rowCount() - 1)
|
||||||
|
|
||||||
slider_value = self.ui.verticalSlider.value()
|
slider_value = self.ui.verticalSlider.value()
|
||||||
kp = self._reach.get_kp_profile_i(slider_value)
|
kp = self._reach.profile(slider_value).kp
|
||||||
|
|
||||||
self.ui.vertical_slider_label.setText(
|
self.ui.vertical_slider_label.setText(
|
||||||
_translate("MainWindow_reach", "Kp : ") +
|
_translate("MainWindow_reach", "Kp : ") +
|
||||||
|
|
@ -784,7 +768,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
return [index.row() for index in self.tableView.selectedIndexes()][0]
|
return [index.row() for index in self.tableView.selectedIndexes()][0]
|
||||||
|
|
||||||
def sort_ascending(self):
|
def sort_ascending(self):
|
||||||
self.model.sort_data(True)
|
self.model.sort_profiles(True)
|
||||||
self.select_current_profile()
|
self.select_current_profile()
|
||||||
self.changed_slider_value()
|
self.changed_slider_value()
|
||||||
|
|
||||||
|
|
@ -792,7 +776,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
self.update_graphic_3(self.index_selected_row)
|
self.update_graphic_3(self.index_selected_row)
|
||||||
|
|
||||||
def sort_descending(self):
|
def sort_descending(self):
|
||||||
self.model.sort_data(False)
|
self.model.sort_profiles(False)
|
||||||
|
|
||||||
self.select_current_profile()
|
self.select_current_profile()
|
||||||
self.changed_slider_value()
|
self.changed_slider_value()
|
||||||
|
|
@ -859,7 +843,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
current_dir = settings.value('current_directory', DEFAULT_DIRECTORY, type=str)
|
current_dir = settings.value('current_directory', DEFAULT_DIRECTORY, type=str)
|
||||||
options |= QFileDialog.DontUseNativeDialog
|
options |= QFileDialog.DontUseNativeDialog
|
||||||
|
|
||||||
filename, self.filters = QFileDialog.getSaveFileName(
|
filename, filters = QFileDialog.getSaveFileName(
|
||||||
self,
|
self,
|
||||||
filter=_translate("MainWindow_reach",
|
filter=_translate("MainWindow_reach",
|
||||||
"Fichiers .ST(*.ST ou *.st)")
|
"Fichiers .ST(*.ST ou *.st)")
|
||||||
|
|
@ -875,10 +859,10 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
self.model.export_reach(filename)
|
self.model.export_reach(filename)
|
||||||
|
|
||||||
def handleOpen(self):
|
def handleOpen(self):
|
||||||
self.filename, self.filterName = QFileDialog.getOpenFileName(self)
|
filename, filterName = QFileDialog.getOpenFileName(self)
|
||||||
|
|
||||||
if self.filename != '':
|
if filename != '':
|
||||||
with open(self.filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
reader = csv.reader(f, delimiter='\t')
|
reader = csv.reader(f, delimiter='\t')
|
||||||
header = next(reader)
|
header = next(reader)
|
||||||
buf = []
|
buf = []
|
||||||
|
|
@ -889,7 +873,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
self.model = None
|
self.model = None
|
||||||
self.model = qtableview_reach.PandasModelEditable(buf)
|
self.model = qtableview_reach.PandasModelEditable(buf)
|
||||||
self.tableView.setModel(self.model)
|
self.tableView.setModel(self.model)
|
||||||
self.filename = ''
|
filename = ''
|
||||||
|
|
||||||
def get_lignes_directrices(self):
|
def get_lignes_directrices(self):
|
||||||
liste_lignes_directrices = [
|
liste_lignes_directrices = [
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ from PyQt5 import (
|
||||||
QtGui, QtWidgets
|
QtGui, QtWidgets
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
Qt, QAbstractTableModel, QModelIndex, QVariant, pyqtSlot, QCoreApplication
|
Qt, QAbstractTableModel, QModelIndex,
|
||||||
|
QVariant, pyqtSlot, QCoreApplication
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QMessageBox
|
QMessageBox
|
||||||
|
|
@ -27,7 +28,7 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
QAbstractTableModel.__init__(self)
|
QAbstractTableModel.__init__(self)
|
||||||
data_list = []
|
data_list = []
|
||||||
|
|
||||||
self._data = reach
|
self._reach = reach
|
||||||
|
|
||||||
if headers is None:
|
if headers is None:
|
||||||
self.headers = [
|
self.headers = [
|
||||||
|
|
@ -39,7 +40,7 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
|
|
||||||
def rowCount(self, parent=QModelIndex()):
|
def rowCount(self, parent=QModelIndex()):
|
||||||
return self._data.number_profiles
|
return self._reach.number_profiles
|
||||||
|
|
||||||
def columnCount(self, parent=QModelIndex()):
|
def columnCount(self, parent=QModelIndex()):
|
||||||
return len(self.headers)
|
return len(self.headers)
|
||||||
|
|
@ -47,21 +48,21 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
def data(self, index, role=Qt.DisplayRole):
|
def data(self, index, role=Qt.DisplayRole):
|
||||||
if index.isValid():
|
if index.isValid():
|
||||||
if role == Qt.DisplayRole and index.column() == 0:
|
if role == Qt.DisplayRole and index.column() == 0:
|
||||||
return self._data.profile(index.row()).name
|
return self._reach.profile(index.row()).name
|
||||||
|
|
||||||
if role == Qt.DisplayRole and index.column() == 1:
|
if role == Qt.DisplayRole and index.column() == 1:
|
||||||
kp = self._data.profile(index.row()).kp
|
kp = self._reach.profile(index.row()).kp
|
||||||
return f"{kp:.4f}"
|
return f"{kp:.4f}"
|
||||||
|
|
||||||
if role == Qt.DisplayRole and index.column() == 2:
|
if role == Qt.DisplayRole and index.column() == 2:
|
||||||
return self._data.profile(index.row()).profile_type
|
return self._reach.profile(index.row()).profile_type
|
||||||
|
|
||||||
for column in range(0, self.columnCount()):
|
for column in range(0, self.columnCount()):
|
||||||
if index.column() == column and role == Qt.TextAlignmentRole:
|
if index.column() == column and role == Qt.TextAlignmentRole:
|
||||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||||
|
|
||||||
if role == Qt.ForegroundRole and index.column() == 0:
|
if role == Qt.ForegroundRole and index.column() == 0:
|
||||||
name = self._data.profile(index.row()).name\
|
name = self._reach.profile(index.row()).name\
|
||||||
.strip()\
|
.strip()\
|
||||||
.lower()
|
.lower()
|
||||||
if (name == "upstream" or name == "up" or
|
if (name == "upstream" or name == "up" or
|
||||||
|
|
@ -89,10 +90,10 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
|
|
||||||
if role == Qt.EditRole and index.column() != 2:
|
if role == Qt.EditRole and index.column() != 2:
|
||||||
if role == Qt.EditRole and index.column() == 0:
|
if role == Qt.EditRole and index.column() == 0:
|
||||||
self._data.profile(index.row()).name = value
|
self._reach.profile(index.row()).name = value
|
||||||
|
|
||||||
if role == Qt.EditRole and index.column() == 1:
|
if role == Qt.EditRole and index.column() == 1:
|
||||||
self._data.profile(index.row()).pk = float(value)
|
self._reach.profile(index.row()).pk = float(value)
|
||||||
|
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
@ -122,7 +123,7 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
def insertRows(self, row, count, parent=QModelIndex()):
|
def insertRows(self, row, count, parent=QModelIndex()):
|
||||||
self.beginInsertRows(parent, row, row + count - 1)
|
self.beginInsertRows(parent, row, row + count - 1)
|
||||||
|
|
||||||
self._data.add_profile(row)
|
self._reach.add_profile(row)
|
||||||
|
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
@ -132,17 +133,17 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
|
|
||||||
if len(list_row_selected) >= 1:
|
if len(list_row_selected) >= 1:
|
||||||
if len(list_row_selected) == 1:
|
if len(list_row_selected) == 1:
|
||||||
self._data.delete_profile(list_row_selected[0])
|
self._reach.delete_profile(list_row_selected[0])
|
||||||
elif len(list_row_selected) > 1:
|
elif len(list_row_selected) > 1:
|
||||||
self._data.delete_profile_rows(list_row_selected)
|
self._reach.delete_profile_rows(list_row_selected)
|
||||||
|
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def sort_data(self, _reverse):
|
def sort_profiles(self, _reverse):
|
||||||
self.layoutAboutToBeChanged.emit()
|
self.layoutAboutToBeChanged.emit()
|
||||||
|
|
||||||
self._data.sort(_reverse)
|
self._reach.sort(_reverse)
|
||||||
|
|
||||||
self.layoutAboutToBeChanged.emit()
|
self.layoutAboutToBeChanged.emit()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
@ -151,7 +152,7 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
target = row_to_move + 2
|
target = row_to_move + 2
|
||||||
self.beginMoveRows(parent, row_to_move, row_to_move, parent, target)
|
self.beginMoveRows(parent, row_to_move, row_to_move, parent, target)
|
||||||
|
|
||||||
self._data.move_down_profile(row_to_move)
|
self._reach.move_down_profile(row_to_move)
|
||||||
|
|
||||||
self.endMoveRows()
|
self.endMoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
@ -160,7 +161,7 @@ class PandasModelEditable(QAbstractTableModel):
|
||||||
target = row_to_move + 1
|
target = row_to_move + 1
|
||||||
self.beginMoveRows(parent, row_to_move - 1, row_to_move - 1, parent, target)
|
self.beginMoveRows(parent, row_to_move - 1, row_to_move - 1, parent, target)
|
||||||
|
|
||||||
self._data.move_up_profile(row_to_move)
|
self._reach.move_up_profile(row_to_move)
|
||||||
|
|
||||||
self.endMoveRows()
|
self.endMoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ def main():
|
||||||
|
|
||||||
application = ApplicationWindow(conf=conf)
|
application = ApplicationWindow(conf=conf)
|
||||||
application.show()
|
application.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(int(app.exec_()))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue