work on interactive profil plot

0.0.9
Theophile Terraz 2024-06-06 16:29:26 +02:00
parent 601ef73b5d
commit 89d5b2d576
3 changed files with 57 additions and 23 deletions

View File

@ -24,7 +24,8 @@ from tools import timer, trace
from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtCore import (
Qt, QCoreApplication, QItemSelectionModel, QItemSelection, QItemSelectionRange
Qt, QCoreApplication, QItemSelectionModel,
QItemSelection, QItemSelectionRange,
)
from PyQt5.QtWidgets import QApplication
@ -46,6 +47,7 @@ class Plot(PamhyrPlot):
)
self._table = table
self._parent = parent
self._z_note = None
self._z_line = None
self._z_fill_between = None
@ -72,17 +74,24 @@ class Plot(PamhyrPlot):
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
return
modifiers = QApplication.keyboardModifiers()
if modifiers != Qt.ControlModifier:
if event.mouseevent.button.value != 1:
return
_, hyd = self.highlight
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier]:
return
points, hyd = self.highlight
ind, point = self._closer_point(event)
self.highlight = ([point], hyd)
self._select_in_table([ind])
if modifiers == Qt.ControlModifier:
rows = self._parent.index_selected_rows()
self.highlight = (points+[point], hyd)
self._select_in_table(rows+[ind])
else:
self.highlight = ([point], hyd)
self._select_in_table([ind])
self.update()
return
@ -90,18 +99,22 @@ class Plot(PamhyrPlot):
def onclick(self, event):
if event.inaxes != self.canvas.axes:
return
modifiers = QApplication.keyboardModifiers()
if modifiers != Qt.ShiftModifier:
if event.button.value == 1:
return
#modifiers = QApplication.keyboardModifiers()
#if modifiers not in [Qt.ShiftModifier]:
#return
points, _ = self.highlight
z = self._get_z_from_click(event)
if z < self.data.z_min():
if z < self.data.z_min() or event.button.value == 2:
self.highlight = (points, None)
self.update()
return
a, p, w = self._compute_hydrolics(z)
a, p, w = self._compute_hydraulics(z)
logger.debug(f"{z, a, p, w}")
@ -110,7 +123,7 @@ class Plot(PamhyrPlot):
self.update()
return
def select_points_from_indexes(self, indexes):
def select_points_from_indices(self, indexes):
data = self.data
_, hyd = self.highlight
@ -187,16 +200,27 @@ class Plot(PamhyrPlot):
def rect_select_callback(self, eclick, erelease):
_, hyd = self.highlight
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
if(max(abs(x1-x2), abs(y1-y2))<0.001):
return
modifiers = QApplication.keyboardModifiers()
points, hyd = self.highlight
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
inds, points = self._points_in_rectangle(x1, y1, x2, y2)
inds, points2 = self._points_in_rectangle(x1, y1, x2, y2)
self.highlight = (points, hyd)
self._select_in_table(inds)
if modifiers == Qt.ControlModifier:
rows = self._parent.index_selected_rows()
self.highlight = (points+points2, hyd)
self._select_in_table(rows+inds)
else:
self.highlight = (points2, hyd)
self._select_in_table(inds)
self.update()
return
@ -213,7 +237,7 @@ class Plot(PamhyrPlot):
return listi, listp
def _compute_hydrolics(self, z):
def _compute_hydraulics(self, z):
profile = self.data
points = profile.wet_points(z)
@ -242,7 +266,7 @@ class Plot(PamhyrPlot):
self.profile_line2D, = self.canvas.axes.plot(
x, y, color=self.color_plot,
lw=1.5, markersize=7, marker='+',
picker=30
picker=10
)
self.draw_annotation(x, y)
@ -307,6 +331,11 @@ class Plot(PamhyrPlot):
if hyd is not None:
self.draw_highligth_z_line(*hyd)
else:
if self._z_note is not None:
self._z_note.set_visible(False)
self._z_line[0].set_visible(False)
self._z_fill_between.set_visible(False)
def draw_highligth_z_line(self, z, a, p, w):
text = (
@ -331,6 +360,7 @@ class Plot(PamhyrPlot):
xlim, [z, z],
color=self.color_plot_river_water
)
self._z_line[0].set_visible(True)
self._z_note = self.canvas.axes.annotate(
text, pos,
@ -342,12 +372,15 @@ class Plot(PamhyrPlot):
fontweight='bold',
alpha=0.7
)
self._z_note.set_visible(True)
else:
self.draw_highligth_z_line_fill(x, y, z)
self._z_line[0].set_data(xlim, [z, z])
self._z_note.set_position(pos)
self._z_note.set_text(text)
self._z_line[0].set_visible(True)
self._z_note.set_visible(True)
def draw_highligth_z_line_fill(self, x, y, z):
if self._z_fill_between is not None:

View File

@ -115,7 +115,8 @@ class ProfileWindow(PamhyrWindow):
data=self._profile,
trad=self._trad,
toolbar=self._toolbar,
table=self.find(QTableView, "tableView")
table=self.find(QTableView, "tableView"),
parent=self
)
self._plot.draw()
@ -146,7 +147,7 @@ class ProfileWindow(PamhyrWindow):
def update_points_selection(self):
rows = self.index_selected_rows()
self._plot.select_points_from_indexes(rows)
self._plot.select_points_from_indices(rows)
def update(self):
self.update_plot()

View File

@ -104,7 +104,7 @@ class PamhyrPlot(APlot):
self._rect_select = RectangleSelector(ax=self.canvas.axes,
onselect=self.rect_select_callback,
useblit=True,
button=[1, 3], # don't use middle button
button=[1], # don't use middle nor right button
minspanx=1.0,
minspany=1.0,
spancoords='pixels',