geometry: Fix some minor bugs.

mesh
Pierre-Antoine Rouby 2023-04-26 11:29:52 +02:00
parent 9efa43ebd4
commit b3a6d0713d
11 changed files with 148 additions and 101 deletions

View File

@ -3,6 +3,8 @@
import numpy as np
from typing import List
from tools import timer
from Model.Geometry.Profile import Profile
from Model.Geometry.PointXYZ import PointXYZ
from Model.Geometry.Vector_1d import Vector1d
@ -143,6 +145,7 @@ class ProfileXYZ(Profile):
return last_point
@timer
def get_station(self) -> np.ndarray:
"""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.
"""
if self.nb_points < 3:
return np.array(np.nan)
return None
else:
first_named_point = None
index_first_named_point = None
@ -168,7 +171,7 @@ class ProfileXYZ(Profile):
first_named_point = point
break
for point in self._points[::-1]:
for point in reversed(self._points):
if point.point_is_named():
last_named_point = point
break
@ -183,8 +186,7 @@ class ProfileXYZ(Profile):
vector = Vector1d(first_named_point, last_named_point)
normalized_direction_vec = vector.normalized_direction_vector()
else:
vector = Vector1d(first_point_not_nan,
last_point_not_nan)
vector = Vector1d(first_point_not_nan, last_point_not_nan)
normalized_direction_vec = vector.normalized_direction_vector()
for point in self._points:
@ -194,11 +196,9 @@ class ProfileXYZ(Profile):
normalized_direction_vec[1] * yi)
station.append(station_i)
ret = np.array(station)
constant = ret[index_first_named_point]
constant = station[index_first_named_point]
elif first_named_point is None:
vector = Vector1d(first_point_not_nan,
last_point_not_nan)
vector = Vector1d(first_point_not_nan, last_point_not_nan)
normalized_direction_vec = vector.normalized_direction_vector()
for point in self._points:
@ -208,8 +208,13 @@ class ProfileXYZ(Profile):
normalized_direction_vec[1] * yi)
station.append(station_i)
ret = np.array(station)
index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0]
constant = ret[index_profile_z_min]
z_min = self.z_min()
index_profile_z_min = list(
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))

View File

@ -80,10 +80,9 @@ class GeometryWindow(QMainWindow, WindowToolKit):
self.tableView.setItemDelegate(Delegate())
def setup_plots(self):
if self._reach.number_profiles != 0:
self.plot_xy()
self.plot_kpc()
self.plot_ac()
self.plot_xy()
self.plot_kpc()
self.plot_ac()
def setup_connections(self):
self.ui.btn_open.clicked.connect(self.open_file_dialog)

View File

@ -33,6 +33,12 @@ class PlotAC(APlot):
@timer
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
station = self.data.profile(selected_profile).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()
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(
_translate("MainWindow_reach", "Abscisse en travers (m)"),
color='green', fontsize=12
@ -130,6 +134,8 @@ class PlotAC(APlot):
self.canvas.figure.canvas.draw_idle()
self.toolbar.update()
self._init = True
def update_full(self):
selected_profile = 0
station = self.data.profile(selected_profile).get_station()
@ -285,6 +291,10 @@ class PlotAC(APlot):
@timer
def update(self, ind=None):
if self._init == False:
self.draw()
return
if ind is not None:
before = ind - 1
after = ind + 1

View File

@ -29,6 +29,10 @@ class PlotKPC(APlot):
def draw(self):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.data.number_profiles == 0:
return
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "Kp (m)"),
color='green', fontsize=12
@ -92,8 +96,14 @@ class PlotKPC(APlot):
self.canvas.figure.canvas.draw_idle()
self.toolbar.update()
self._init = True
@timer
def update(self, ind=None):
if self._init == False:
self.draw()
return
if ind is not None:
before = ind - 1
after = ind + 1

View File

@ -29,6 +29,10 @@ class PlotXY(APlot):
self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.data.number_profiles == 0:
self._init = False
return
# Axes
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "X (m)"),
@ -91,8 +95,14 @@ class PlotXY(APlot):
self.canvas.figure.canvas.draw_idle()
self.toolbar.update()
self._init = True
@timer
def update(self, ind=None):
if self._init == False:
self.draw()
return
if ind is not None:
before = ind - 1
after = ind + 1

View File

@ -29,94 +29,97 @@ class Plot(APlot):
@timer
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.grid(
color='grey', linestyle='--', linewidth=0.5
)
if (len(x_carto) >= 3 and
len(y_carto) >= 3 and
len(x) >= 3):
self.profile_line2D, = self.canvas.axes.plot(
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
)
x = self.data.get_station()
y = self.data.z()
x_carto = self.data.x()
y_carto = self.data.y()
# Add label on graph
self.annotation = []
for i, txt in enumerate(list(gl)):
annotation = self.canvas.axes.annotate(
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)
if (len(x_carto) < 3 or len(y_carto) < 3 or
len(x) < 3):
# Noting to do in this case
return
al = 8.
arrowprops = dict(
clip_on=True,
headwidth=5.,
facecolor='k'
)
kwargs = dict(
xycoords='axes fraction',
textcoords='offset points',
arrowprops=arrowprops,
gl = map(lambda p: p.name, self.data.points)
self.profile_line2D, = self.canvas.axes.plot(
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
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)
self.canvas.axes.annotate("", (0, 1), xytext=(0, -al), **kwargs)
al = 8.
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.yaxis.tick_left()
self.canvas.axes.xaxis.tick_bottom()
self.canvas.axes.set_facecolor('#F9F9F9')
self.canvas.figure.patch.set_facecolor('white')
self.canvas.axes.annotate("", (1, 0), xytext=(-al, 0), **kwargs)
self.canvas.axes.annotate("", (0, 1), xytext=(0, -al), **kwargs)
self.onpick_event = OnpickEvent(
self.canvas.axes,
x, y, x_carto, y_carto,
self._table
)
self.canvas.figure.canvas\
.mpl_connect(
'pick_event',
self.onpick_event.onpick
)
self.canvas.axes.spines[['top', 'right']].set_color('none')
self.canvas.axes.yaxis.tick_left()
self.canvas.axes.xaxis.tick_bottom()
self.canvas.axes.set_facecolor('#F9F9F9')
self.canvas.figure.patch.set_facecolor('white')
self.onclick_event = OnpickEvent(
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.onpick_event = OnpickEvent(
self.canvas.axes,
x, y, x_carto, y_carto,
self._table
)
self.canvas.figure.canvas\
.mpl_connect(
'pick_event',
self.onpick_event.onpick
)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
self.onclick_event = OnpickEvent(
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
def update(self, ind=None):

View File

@ -131,6 +131,11 @@ class ProfileWindow(QMainWindow):
self.ui.tableView.model().blockSignals(False)
def index_selected_row(self):
return self.ui.tableView\
.selectionModel()\
.selectedRows()[0]\
.row()
def insert_row(self):
if len(self.ui.tableView.selectedIndexes()) == 0:

View File

@ -55,14 +55,15 @@ class TableEditableModel(QAbstractTableModel):
elif index.column() == 3:
value = self._profile.point(index.row()).name
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:
return f"{value:.4f}"
elif index.column() == 4:
if np.isnan(value):
return "-"
return f"{value:.3f}"
return f"{value}"

View File

@ -68,10 +68,10 @@ class TableEditableModel(QAbstractTableModel):
.lower()
if (name == "upstream" or name == "up" or
name == _translate("Geometry", "upstream")):
return QtGui.QColor("Green")
return QColor("Green")
elif (name == "downstream" or name == "down" or
name == _translate("Geometry", "downstream")):
return QtGui.QColor("Red")
return QColor("Red")
return QVariant()

View File

@ -4,6 +4,8 @@ class APlot(object):
def __init__(self, canvas=None, data=None, toolbar=None):
super(APlot, self).__init__()
self._init = False
self._canvas = canvas
self._data = data
self._toolbar = toolbar

View File

@ -56,7 +56,9 @@ def timer(func):
try:
value = func(*args, **kwargs)
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()
run_time = end_time - start_time