mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Fix some minor bugs.
parent
9efa43ebd4
commit
b3a6d0713d
|
|
@ -3,6 +3,8 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
from tools import timer
|
||||||
|
|
||||||
from Model.Geometry.Profile import Profile
|
from Model.Geometry.Profile import Profile
|
||||||
from Model.Geometry.PointXYZ import PointXYZ
|
from Model.Geometry.PointXYZ import PointXYZ
|
||||||
from Model.Geometry.Vector_1d import Vector1d
|
from Model.Geometry.Vector_1d import Vector1d
|
||||||
|
|
@ -143,6 +145,7 @@ class ProfileXYZ(Profile):
|
||||||
|
|
||||||
return last_point
|
return last_point
|
||||||
|
|
||||||
|
@timer
|
||||||
def get_station(self) -> np.ndarray:
|
def get_station(self) -> np.ndarray:
|
||||||
"""Projection of the points of the profile on a plane.
|
"""Projection of the points of the profile on a plane.
|
||||||
|
|
||||||
|
|
@ -153,7 +156,7 @@ class ProfileXYZ(Profile):
|
||||||
Projection of the points of the profile on a plane.
|
Projection of the points of the profile on a plane.
|
||||||
"""
|
"""
|
||||||
if self.nb_points < 3:
|
if self.nb_points < 3:
|
||||||
return np.array(np.nan)
|
return None
|
||||||
else:
|
else:
|
||||||
first_named_point = None
|
first_named_point = None
|
||||||
index_first_named_point = None
|
index_first_named_point = None
|
||||||
|
|
@ -168,7 +171,7 @@ class ProfileXYZ(Profile):
|
||||||
first_named_point = point
|
first_named_point = point
|
||||||
break
|
break
|
||||||
|
|
||||||
for point in self._points[::-1]:
|
for point in reversed(self._points):
|
||||||
if point.point_is_named():
|
if point.point_is_named():
|
||||||
last_named_point = point
|
last_named_point = point
|
||||||
break
|
break
|
||||||
|
|
@ -183,8 +186,7 @@ class ProfileXYZ(Profile):
|
||||||
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,
|
vector = Vector1d(first_point_not_nan, last_point_not_nan)
|
||||||
last_point_not_nan)
|
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
|
|
@ -194,11 +196,9 @@ class ProfileXYZ(Profile):
|
||||||
normalized_direction_vec[1] * yi)
|
normalized_direction_vec[1] * yi)
|
||||||
station.append(station_i)
|
station.append(station_i)
|
||||||
|
|
||||||
ret = np.array(station)
|
constant = station[index_first_named_point]
|
||||||
constant = ret[index_first_named_point]
|
|
||||||
elif first_named_point is None:
|
elif first_named_point is None:
|
||||||
vector = Vector1d(first_point_not_nan,
|
vector = Vector1d(first_point_not_nan, last_point_not_nan)
|
||||||
last_point_not_nan)
|
|
||||||
normalized_direction_vec = vector.normalized_direction_vector()
|
normalized_direction_vec = vector.normalized_direction_vector()
|
||||||
|
|
||||||
for point in self._points:
|
for point in self._points:
|
||||||
|
|
@ -208,8 +208,13 @@ class ProfileXYZ(Profile):
|
||||||
normalized_direction_vec[1] * yi)
|
normalized_direction_vec[1] * yi)
|
||||||
station.append(station_i)
|
station.append(station_i)
|
||||||
|
|
||||||
ret = np.array(station)
|
z_min = self.z_min()
|
||||||
index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0]
|
index_profile_z_min = list(
|
||||||
constant = ret[index_profile_z_min]
|
filter(
|
||||||
|
lambda z: z[1] == z_min,
|
||||||
|
enumerate(self.z())
|
||||||
|
)
|
||||||
|
)[0]
|
||||||
|
constant = station[index_profile_z_min[0]]
|
||||||
|
|
||||||
return (ret - constant)
|
return list(map(lambda s: s - constant, station))
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,9 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
||||||
self.tableView.setItemDelegate(Delegate())
|
self.tableView.setItemDelegate(Delegate())
|
||||||
|
|
||||||
def setup_plots(self):
|
def setup_plots(self):
|
||||||
if self._reach.number_profiles != 0:
|
self.plot_xy()
|
||||||
self.plot_xy()
|
self.plot_kpc()
|
||||||
self.plot_kpc()
|
self.plot_ac()
|
||||||
self.plot_ac()
|
|
||||||
|
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
self.ui.btn_open.clicked.connect(self.open_file_dialog)
|
self.ui.btn_open.clicked.connect(self.open_file_dialog)
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,12 @@ class PlotAC(APlot):
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
self.canvas.axes.cla()
|
||||||
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data.number_profiles == 0:
|
||||||
|
return
|
||||||
|
|
||||||
selected_profile = 0
|
selected_profile = 0
|
||||||
station = self.data.profile(selected_profile).get_station()
|
station = self.data.profile(selected_profile).get_station()
|
||||||
station_plus_1 = self.data.profile(selected_profile + 1).get_station()
|
station_plus_1 = self.data.profile(selected_profile + 1).get_station()
|
||||||
|
|
@ -40,8 +46,6 @@ class PlotAC(APlot):
|
||||||
elevation_i_plus_1 = self.data.profile(selected_profile + 1).z()
|
elevation_i_plus_1 = self.data.profile(selected_profile + 1).z()
|
||||||
gl = self.data.profile(selected_profile).names()
|
gl = self.data.profile(selected_profile).names()
|
||||||
|
|
||||||
self.canvas.axes.cla()
|
|
||||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
|
||||||
self.canvas.axes.set_xlabel(
|
self.canvas.axes.set_xlabel(
|
||||||
_translate("MainWindow_reach", "Abscisse en travers (m)"),
|
_translate("MainWindow_reach", "Abscisse en travers (m)"),
|
||||||
color='green', fontsize=12
|
color='green', fontsize=12
|
||||||
|
|
@ -130,6 +134,8 @@ class PlotAC(APlot):
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
self.toolbar.update()
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = True
|
||||||
|
|
||||||
def update_full(self):
|
def update_full(self):
|
||||||
selected_profile = 0
|
selected_profile = 0
|
||||||
station = self.data.profile(selected_profile).get_station()
|
station = self.data.profile(selected_profile).get_station()
|
||||||
|
|
@ -285,6 +291,10 @@ class PlotAC(APlot):
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def update(self, ind=None):
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
if ind is not None:
|
if ind is not None:
|
||||||
before = ind - 1
|
before = ind - 1
|
||||||
after = ind + 1
|
after = ind + 1
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ class PlotKPC(APlot):
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.canvas.axes.cla()
|
self.canvas.axes.cla()
|
||||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data.number_profiles == 0:
|
||||||
|
return
|
||||||
|
|
||||||
self.canvas.axes.set_xlabel(
|
self.canvas.axes.set_xlabel(
|
||||||
_translate("MainWindow_reach", "Kp (m)"),
|
_translate("MainWindow_reach", "Kp (m)"),
|
||||||
color='green', fontsize=12
|
color='green', fontsize=12
|
||||||
|
|
@ -92,8 +96,14 @@ class PlotKPC(APlot):
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
self.toolbar.update()
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = True
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def update(self, ind=None):
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
if ind is not None:
|
if ind is not None:
|
||||||
before = ind - 1
|
before = ind - 1
|
||||||
after = ind + 1
|
after = ind + 1
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ class PlotXY(APlot):
|
||||||
self.canvas.axes.cla()
|
self.canvas.axes.cla()
|
||||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||||
|
|
||||||
|
if self.data.number_profiles == 0:
|
||||||
|
self._init = False
|
||||||
|
return
|
||||||
|
|
||||||
# Axes
|
# Axes
|
||||||
self.canvas.axes.set_xlabel(
|
self.canvas.axes.set_xlabel(
|
||||||
_translate("MainWindow_reach", "X (m)"),
|
_translate("MainWindow_reach", "X (m)"),
|
||||||
|
|
@ -91,8 +95,14 @@ class PlotXY(APlot):
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.figure.canvas.draw_idle()
|
||||||
self.toolbar.update()
|
self.toolbar.update()
|
||||||
|
|
||||||
|
self._init = True
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def update(self, ind=None):
|
def update(self, ind=None):
|
||||||
|
if self._init == False:
|
||||||
|
self.draw()
|
||||||
|
return
|
||||||
|
|
||||||
if ind is not None:
|
if ind is not None:
|
||||||
before = ind - 1
|
before = ind - 1
|
||||||
after = ind + 1
|
after = ind + 1
|
||||||
|
|
|
||||||
|
|
@ -29,94 +29,97 @@ class Plot(APlot):
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self):
|
def draw(self):
|
||||||
x = self.data.get_station()
|
|
||||||
y = self.data.z()
|
|
||||||
gl = self.data.name
|
|
||||||
x_carto = self.data.x()
|
|
||||||
y_carto = self.data.y()
|
|
||||||
|
|
||||||
self.canvas.axes.cla()
|
self.canvas.axes.cla()
|
||||||
self.canvas.axes.grid(
|
self.canvas.axes.grid(
|
||||||
color='grey', linestyle='--', linewidth=0.5
|
color='grey', linestyle='--', linewidth=0.5
|
||||||
)
|
)
|
||||||
|
|
||||||
if (len(x_carto) >= 3 and
|
x = self.data.get_station()
|
||||||
len(y_carto) >= 3 and
|
y = self.data.z()
|
||||||
len(x) >= 3):
|
x_carto = self.data.x()
|
||||||
self.profile_line2D, = self.canvas.axes.plot(
|
y_carto = self.data.y()
|
||||||
x, y, color='r', lw=1.5,
|
|
||||||
markersize=7, marker='+',
|
|
||||||
picker=30
|
|
||||||
)
|
|
||||||
self.canvas.axes.set_xlabel(
|
|
||||||
_translate("MainWindowProfile",
|
|
||||||
"Abscisse en travers (m)"),
|
|
||||||
color='black', fontsize=10
|
|
||||||
)
|
|
||||||
self.canvas.axes.set_ylabel(
|
|
||||||
_translate("MainWindowProfile", "Cote (m)"),
|
|
||||||
color='black', fontsize=10
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add label on graph
|
if (len(x_carto) < 3 or len(y_carto) < 3 or
|
||||||
self.annotation = []
|
len(x) < 3):
|
||||||
for i, txt in enumerate(list(gl)):
|
# Noting to do in this case
|
||||||
annotation = self.canvas.axes.annotate(
|
return
|
||||||
txt, (x[i], y[i]),
|
|
||||||
horizontalalignment='left',
|
|
||||||
verticalalignment='top',
|
|
||||||
annotation_clip=True,
|
|
||||||
fontsize=10, color='black'
|
|
||||||
)
|
|
||||||
annotation.set_position((x[i], y[i]))
|
|
||||||
annotation.set_color("black")
|
|
||||||
self.annotation.append(annotation)
|
|
||||||
|
|
||||||
al = 8.
|
gl = map(lambda p: p.name, self.data.points)
|
||||||
arrowprops = dict(
|
|
||||||
clip_on=True,
|
self.profile_line2D, = self.canvas.axes.plot(
|
||||||
headwidth=5.,
|
x, y, color='r', lw=1.5,
|
||||||
facecolor='k'
|
markersize=7, marker='+',
|
||||||
)
|
picker=30
|
||||||
kwargs = dict(
|
)
|
||||||
xycoords='axes fraction',
|
self.canvas.axes.set_xlabel(
|
||||||
textcoords='offset points',
|
_translate("MainWindowProfile",
|
||||||
arrowprops=arrowprops,
|
"Abscisse en travers (m)"),
|
||||||
|
color='black', fontsize=10
|
||||||
|
)
|
||||||
|
self.canvas.axes.set_ylabel(
|
||||||
|
_translate("MainWindowProfile", "Cote (m)"),
|
||||||
|
color='black', fontsize=10
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add label on graph
|
||||||
|
self.annotation = []
|
||||||
|
for i, name in enumerate(list(gl)):
|
||||||
|
annotation = self.canvas.axes.annotate(
|
||||||
|
name, (x[i], y[i]),
|
||||||
|
horizontalalignment='left',
|
||||||
|
verticalalignment='top',
|
||||||
|
annotation_clip=True,
|
||||||
|
fontsize=10, color='black'
|
||||||
)
|
)
|
||||||
|
annotation.set_position((x[i], y[i]))
|
||||||
|
annotation.set_color("black")
|
||||||
|
self.annotation.append(annotation)
|
||||||
|
|
||||||
self.canvas.axes.annotate("", (1, 0), xytext=(-al, 0), **kwargs)
|
al = 8.
|
||||||
self.canvas.axes.annotate("", (0, 1), xytext=(0, -al), **kwargs)
|
arrowprops = dict(
|
||||||
|
clip_on=True,
|
||||||
|
headwidth=5.,
|
||||||
|
facecolor='k'
|
||||||
|
)
|
||||||
|
kwargs = dict(
|
||||||
|
xycoords='axes fraction',
|
||||||
|
textcoords='offset points',
|
||||||
|
arrowprops=arrowprops,
|
||||||
|
)
|
||||||
|
|
||||||
self.canvas.axes.spines[['top', 'right']].set_color('none')
|
self.canvas.axes.annotate("", (1, 0), xytext=(-al, 0), **kwargs)
|
||||||
self.canvas.axes.yaxis.tick_left()
|
self.canvas.axes.annotate("", (0, 1), xytext=(0, -al), **kwargs)
|
||||||
self.canvas.axes.xaxis.tick_bottom()
|
|
||||||
self.canvas.axes.set_facecolor('#F9F9F9')
|
|
||||||
self.canvas.figure.patch.set_facecolor('white')
|
|
||||||
|
|
||||||
self.onpick_event = OnpickEvent(
|
self.canvas.axes.spines[['top', 'right']].set_color('none')
|
||||||
self.canvas.axes,
|
self.canvas.axes.yaxis.tick_left()
|
||||||
x, y, x_carto, y_carto,
|
self.canvas.axes.xaxis.tick_bottom()
|
||||||
self._table
|
self.canvas.axes.set_facecolor('#F9F9F9')
|
||||||
)
|
self.canvas.figure.patch.set_facecolor('white')
|
||||||
self.canvas.figure.canvas\
|
|
||||||
.mpl_connect(
|
|
||||||
'pick_event',
|
|
||||||
self.onpick_event.onpick
|
|
||||||
)
|
|
||||||
|
|
||||||
self.onclick_event = OnpickEvent(
|
self.onpick_event = OnpickEvent(
|
||||||
self.canvas.axes,
|
self.canvas.axes,
|
||||||
x, y, x_carto, y_carto,
|
x, y, x_carto, y_carto,
|
||||||
self._table
|
self._table
|
||||||
)
|
)
|
||||||
self.canvas.figure.canvas\
|
self.canvas.figure.canvas\
|
||||||
.mpl_connect(
|
.mpl_connect(
|
||||||
'button_press_event',
|
'pick_event',
|
||||||
self.onclick_event.onclick
|
self.onpick_event.onpick
|
||||||
)
|
)
|
||||||
|
|
||||||
self.canvas.figure.tight_layout()
|
self.onclick_event = OnpickEvent(
|
||||||
self.canvas.figure.canvas.draw_idle()
|
self.canvas.axes,
|
||||||
|
x, y, x_carto, y_carto,
|
||||||
|
self._table
|
||||||
|
)
|
||||||
|
self.canvas.figure.canvas\
|
||||||
|
.mpl_connect(
|
||||||
|
'button_press_event',
|
||||||
|
self.onclick_event.onclick
|
||||||
|
)
|
||||||
|
|
||||||
|
self.canvas.figure.tight_layout()
|
||||||
|
self.canvas.figure.canvas.draw_idle()
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def update(self, ind=None):
|
def update(self, ind=None):
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,11 @@ class ProfileWindow(QMainWindow):
|
||||||
|
|
||||||
self.ui.tableView.model().blockSignals(False)
|
self.ui.tableView.model().blockSignals(False)
|
||||||
|
|
||||||
|
def index_selected_row(self):
|
||||||
|
return self.ui.tableView\
|
||||||
|
.selectionModel()\
|
||||||
|
.selectedRows()[0]\
|
||||||
|
.row()
|
||||||
|
|
||||||
def insert_row(self):
|
def insert_row(self):
|
||||||
if len(self.ui.tableView.selectedIndexes()) == 0:
|
if len(self.ui.tableView.selectedIndexes()) == 0:
|
||||||
|
|
|
||||||
|
|
@ -55,14 +55,15 @@ class TableEditableModel(QAbstractTableModel):
|
||||||
elif index.column() == 3:
|
elif index.column() == 3:
|
||||||
value = self._profile.point(index.row()).name
|
value = self._profile.point(index.row()).name
|
||||||
elif index.column() == 4:
|
elif index.column() == 4:
|
||||||
value = self._profile.get_station()[index.row()]
|
station = self._profile.get_station()
|
||||||
|
if station is None:
|
||||||
|
return "-"
|
||||||
|
else:
|
||||||
|
value = station[index.row()]
|
||||||
|
return f"{value:.3f}"
|
||||||
|
|
||||||
if 0 <= index.column() < 3:
|
if 0 <= index.column() < 3:
|
||||||
return f"{value:.4f}"
|
return f"{value:.4f}"
|
||||||
elif index.column() == 4:
|
|
||||||
if np.isnan(value):
|
|
||||||
return "-"
|
|
||||||
return f"{value:.3f}"
|
|
||||||
|
|
||||||
return f"{value}"
|
return f"{value}"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,10 +68,10 @@ class TableEditableModel(QAbstractTableModel):
|
||||||
.lower()
|
.lower()
|
||||||
if (name == "upstream" or name == "up" or
|
if (name == "upstream" or name == "up" or
|
||||||
name == _translate("Geometry", "upstream")):
|
name == _translate("Geometry", "upstream")):
|
||||||
return QtGui.QColor("Green")
|
return QColor("Green")
|
||||||
elif (name == "downstream" or name == "down" or
|
elif (name == "downstream" or name == "down" or
|
||||||
name == _translate("Geometry", "downstream")):
|
name == _translate("Geometry", "downstream")):
|
||||||
return QtGui.QColor("Red")
|
return QColor("Red")
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ class APlot(object):
|
||||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
def __init__(self, canvas=None, data=None, toolbar=None):
|
||||||
super(APlot, self).__init__()
|
super(APlot, self).__init__()
|
||||||
|
|
||||||
|
self._init = False
|
||||||
|
|
||||||
self._canvas = canvas
|
self._canvas = canvas
|
||||||
self._data = data
|
self._data = data
|
||||||
self._toolbar = toolbar
|
self._toolbar = toolbar
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,9 @@ def timer(func):
|
||||||
try:
|
try:
|
||||||
value = func(*args, **kwargs)
|
value = func(*args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"{e}")
|
print(f"[{Fore.RED}ERROR{Style.RESET_ALL}]" +
|
||||||
|
f"[{func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}]: " +
|
||||||
|
f"{Fore.RED}{e}{Style.RESET_ALL}")
|
||||||
|
|
||||||
end_time = time.perf_counter()
|
end_time = time.perf_counter()
|
||||||
run_time = end_time - start_time
|
run_time = end_time - start_time
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue