Commit 872ff0ef authored by Theophile Terraz's avatar Theophile Terraz
Browse files

PlotKPZ restructuration

Showing with 149 additions and 128 deletions
+149 -128
......@@ -21,7 +21,10 @@ import logging
from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtCore import(
Qt, QItemSelectionModel,
QItemSelection, QItemSelectionRange,
)
logger = logging.getLogger()
......@@ -29,7 +32,7 @@ logger = logging.getLogger()
class PlotKPZ(PamhyrPlot):
def __init__(self, canvas=None, trad=None,
study=None, data=None, toolbar=None,
parent=None):
table=None, parent=None):
self._study = study
super(PlotKPZ, self).__init__(
......@@ -37,6 +40,7 @@ class PlotKPZ(PamhyrPlot):
trad=trad,
data=data,
toolbar=toolbar,
table=table,
parent=parent
)
......@@ -55,6 +59,8 @@ class PlotKPZ(PamhyrPlot):
self.after_plot_selected = None
self._rect_select = None
self.parent=parent
self._table=table
self._colors = []
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
......@@ -69,7 +75,28 @@ class PlotKPZ(PamhyrPlot):
ind, point = self._closest_kp(event)
if self.parent._table is not None:
self.parent._table.blockSignals(True)
self.parent.select_row_profile_slider(ind)
if modifiers == Qt.ControlModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
self._select_in_table(rows+[ind])
elif modifiers == Qt.ShiftModifier:
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
if len(rows)>0:
i1 = min(rows[0], rows[-1], ind)
i2 = max(rows[0], rows[-1], ind)
else:
i1 = ind
i2 = ind
self._select_range_in_table(i1, i2)
else:
self.parent.select_row_profile_slider(ind)
self.parent._table.blockSignals(False)
self.update()
......@@ -96,6 +123,42 @@ class PlotKPZ(PamhyrPlot):
return closest
def _select_in_table(self, ind):
if self._table is not None:
self._table.blockSignals(True)
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection()
if len(ind) > 0:
for i in ind:
index.append(QItemSelectionRange(self._table.model().index(i, 0)))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
if len(ind) > 0:
self._table.scrollTo(self._table.model().index(ind[-1], 0))
self._table.blockSignals(False)
def _select_range_in_table(self, ind1, ind2):
if self._table is not None:
self._table.blockSignals(True)
self._table.setFocus()
selection = self._table.selectionModel()
index = QItemSelection(self._table.model().index(ind1, 0),
self._table.model().index(ind2, 0))
selection.select(
index,
QItemSelectionModel.Rows |
QItemSelectionModel.ClearAndSelect |
QItemSelectionModel.Select
)
self._table.scrollTo(self._table.model().index(ind2, 0))
self._table.blockSignals(False)
@timer
def draw(self):
self.init_axes()
......@@ -118,8 +181,7 @@ class PlotKPZ(PamhyrPlot):
return
self.draw_z_line()
self.draw_z_line_highlight()
self.draw_current()
self.draw_lr()
self.draw_gl()
self.draw_bottom()
self.draw_profiles_hs(self._data)
......@@ -132,77 +194,60 @@ class PlotKPZ(PamhyrPlot):
z_min = self.data.get_z_min()
z_max = self.data.get_z_max()
self._colors, self._style = self.color_hightlight()
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
x=kp, ymin=z_min, ymax=z_max,
color=self.color_plot,
color=self._colors,
linestyle = self._style,
lw=1.,
picker=10
picker=10,
)
def draw_z_line_highlight(self):
if self._highlight_data is not None:
kp = self.data.get_kp_complete_profiles()
z_min = self.data.get_z_min()
z_max = self.data.get_z_max()
kp_min, kp_max = self._highlight_data
indexes = list(
map(
lambda x: x[0],
filter(
lambda x: kp_min <= x[1] <= kp_max,
enumerate(kp)
)
)
)
def indexes_filter(data): return list(
map(
lambda x: x[1],
filter(
lambda x: x[0] in indexes,
enumerate(data)
)
)
)
ikp = indexes_filter(kp)
imin = indexes_filter(z_min)
imax = indexes_filter(z_max)
self.line_kp_zmin_zmax_highlight = self.canvas.axes.vlines(
x=ikp,
ymin=imin, ymax=imax,
color=self.color_plot_highlight,
lw=1.
def color_hightlight(self):
rows = list(
set(
(i.row() for i in self.parent.tableView.selectedIndexes())
)
def draw_current(self):
kp = self.data.get_kp_complete_profiles()
z_min = self.data.get_z_min()
z_max = self.data.get_z_max()
self.plot_selected, = self.canvas.axes.plot(
(kp[0], kp[0]),
(z_min[0], z_max[0]),
color=self.color_plot_current, lw=1.5
)
self.plot_selected.set_visible(False)
self.before_plot_selected, = self.canvas.axes.plot(
(kp[0], kp[0]),
(z_min[0], z_max[0]),
color=self.color_plot_previous, lw=1.5, linestyle='--'
colors = [self.color_plot for row in range(len(self._data))]
style = ["-" for row in range(len(self._data))]
if len(rows) >0:
for row in rows:
colors[row] = self.color_plot_current
if rows[0] > 0:
colors[rows[0]-1] = self.color_plot_previous
style[rows[0]-1] = "--"
if rows[-1] < len(self._data)-1:
colors[rows[-1]+1] = self.color_plot_next
style[rows[-1]+1] = "--"
return colors, style
def draw_lr(self):
kp = self.data.get_kp_complete_profiles()
lz = []
rz = []
self.line_lr = []
for z in self.data.get_z():
lz.append(z[0])
rz.append(z[-1])
line = self.canvas.axes.plot(
kp, lz,
color=self.color_plot_river_bottom,
linestyle="dotted",
lw=1.,
)
self.before_plot_selected.set_visible(False)
self.line_lr.append(line)
self.after_plot_selected, = self.canvas.axes.plot(
(kp[0], kp[0]),
(z_min[0], z_max[0]),
color=self.color_plot_next, lw=1.5, linestyle='--'
line = self.canvas.axes.plot(
kp, rz,
color=self.color_plot_river_bottom,
linestyle="dotted",
lw=1.,
)
self.after_plot_selected.set_visible(False)
self.line_lr.append(line)
def draw_gl(self):
kp = self.data.get_kp_complete_profiles()
......@@ -270,6 +315,7 @@ class PlotKPZ(PamhyrPlot):
self.draw()
return
self.update_lr()
self.update_gl()
self.update_current()
......@@ -277,52 +323,9 @@ class PlotKPZ(PamhyrPlot):
def update_current(self):
if self._current_data_update:
ind = self._current_data
before = ind - 1
after = ind + 1
self.before_plot_selected.set_visible(False)
self.plot_selected.set_visible(False)
self.after_plot_selected.set_visible(False)
if 0 <= before < self.data.number_profiles:
profile = self.data.profile(before)
if len(profile) > 0:
kp_i = profile.kp
z_min_i = profile.z_min()
z_max_i = profile.z_max()
self.before_plot_selected.set_data(
(kp_i, kp_i),
(z_min_i, z_max_i)
)
self.before_plot_selected.set_visible(True)
if 0 <= ind < self.data.number_profiles:
profile = self.data.profile(ind)
if len(profile) > 0:
kp_i = profile.kp
z_min_i = profile.z_min()
z_max_i = profile.z_max()
self.plot_selected.set_data(
(kp_i, kp_i),
(z_min_i, z_max_i)
)
self.plot_selected.set_visible(True)
if 0 <= after < self.data.number_profiles:
profile = self.data.profile(after)
if len(profile) > 0:
kp_i = profile.kp
z_min_i = profile.z_min()
z_max_i = profile.z_max()
self.after_plot_selected.set_data(
(kp_i, kp_i),
(z_min_i, z_max_i)
)
self.after_plot_selected.set_visible(True)
self._colors, self._style = self.color_hightlight()
self.line_kp_zmin_zmax.set_colors(self._colors)
self.line_kp_zmin_zmax.set_linestyle(self._style)
def update_gl(self):
if self._current_data_update:
......@@ -334,12 +337,19 @@ class PlotKPZ(PamhyrPlot):
self.line_kp_zmin.set_data(kp, z_min)
self.line_kp_zmin_zmax.remove()
self.line_kp_zmin_zmax = self.canvas.axes.vlines(
x=kp,
ymin=z_min, ymax=z_max,
color='r', lw=1.
)
# TODO comprendre à quoi sert ce bout de code
# ========>
#self.line_kp_zmin_zmax.remove()
#self._colors, self._style = self.color_hightlight()
#self.line_kp_zmin_zmax = self.canvas.axes.vlines(
#x=kp,
#ymin=z_min,
#ymax=z_max,
#color=self._colors,
#linestyle = self._style,
#lw=1.
#)
# <========
z_complete = self.data.get_guidelines_z()
try:
......@@ -349,3 +359,9 @@ class PlotKPZ(PamhyrPlot):
)
except Exception as e:
logger.warning(f"Failed to update graphic KPZ: {e}")
def update_lr(self):
for line in self.line_lr:
line[0].remove()
self.draw_lr()
......@@ -55,7 +55,8 @@ class PlotXY(PamhyrPlot):
self.parent=parent
self.line_xy_collection = None
self._table=table
self.colors = []
self._colors = []
self._style = []
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
......@@ -175,7 +176,6 @@ class PlotXY(PamhyrPlot):
self.draw_xy()
self.draw_lr()
self.draw_gl()
#self.draw_current()
self.idle()
self._init = True
......@@ -186,9 +186,10 @@ class PlotXY(PamhyrPlot):
for xy in zip(self.data.get_x(), self.data.get_y()):
self.line_xy.append(np.column_stack(xy))
self.colors = self.color_hightlight()
self._colors, self._style = self.color_hightlight()
self.line_xy_collection = collections.LineCollection(self.line_xy,
colors = self.colors,
colors = self._colors,
linestyle = self._style,
picker=10)
self.canvas.axes.add_collection(self.line_xy_collection)
......@@ -198,16 +199,18 @@ class PlotXY(PamhyrPlot):
(i.row() for i in self.parent.tableView.selectedIndexes())
)
)
colors = [self.color_plot for row in range(len(self.line_xy))]
colors = [self.color_plot for row in range(len(self._data))]
style = ["-" for row in range(len(self._data))]
if len(rows) >0:
for row in rows:
colors[row] = self.color_plot_current
if rows[0] > 0:
colors[rows[0]-1] = self.color_plot_previous
if rows[-1] < len(self.line_xy)-1:
style[rows[0]-1] = "--"
if rows[-1] < len(self._data)-1:
colors[rows[-1]+1] = self.color_plot_next
return colors
style[rows[-1]+1] = "--"
return colors, style
def draw_lr(self):
lx = []
......@@ -309,8 +312,9 @@ class PlotXY(PamhyrPlot):
def update_current(self):
if self._current_data_update:
self.colors = self.color_hightlight()
self.line_xy_collection.set_colors(self.colors)
self._colors, self._style = self.color_hightlight()
self.line_xy_collection.set_colors(self._colors)
self.line_xy_collection.set_linestyle(self._style)
def update_lr(self):
for line in self.line_lr:
......
......@@ -385,6 +385,7 @@ class GeometryWindow(PamhyrWindow):
data=self._reach,
trad=self._trad,
toolbar=self._toolbar_kpc,
table=self.find(QTableView, "tableView"),
parent=self
)
self._plot_kpc.draw()
......
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