mirror of https://gitlab.com/pamhyr/pamhyr2
work on interactive profil plot
parent
601ef73b5d
commit
89d5b2d576
|
|
@ -24,7 +24,8 @@ from tools import timer, trace
|
||||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
Qt, QCoreApplication, QItemSelectionModel, QItemSelection, QItemSelectionRange
|
Qt, QCoreApplication, QItemSelectionModel,
|
||||||
|
QItemSelection, QItemSelectionRange,
|
||||||
)
|
)
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
@ -46,6 +47,7 @@ class Plot(PamhyrPlot):
|
||||||
)
|
)
|
||||||
|
|
||||||
self._table = table
|
self._table = table
|
||||||
|
self._parent = parent
|
||||||
self._z_note = None
|
self._z_note = None
|
||||||
self._z_line = None
|
self._z_line = None
|
||||||
self._z_fill_between = None
|
self._z_fill_between = None
|
||||||
|
|
@ -72,17 +74,24 @@ class Plot(PamhyrPlot):
|
||||||
def onpick(self, event):
|
def onpick(self, event):
|
||||||
if event.mouseevent.inaxes != self.canvas.axes:
|
if event.mouseevent.inaxes != self.canvas.axes:
|
||||||
return
|
return
|
||||||
|
if event.mouseevent.button.value != 1:
|
||||||
modifiers = QApplication.keyboardModifiers()
|
|
||||||
if modifiers != Qt.ControlModifier:
|
|
||||||
return
|
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)
|
ind, point = self._closer_point(event)
|
||||||
|
|
||||||
self.highlight = ([point], hyd)
|
if modifiers == Qt.ControlModifier:
|
||||||
self._select_in_table([ind])
|
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()
|
self.update()
|
||||||
return
|
return
|
||||||
|
|
@ -90,18 +99,22 @@ class Plot(PamhyrPlot):
|
||||||
def onclick(self, event):
|
def onclick(self, event):
|
||||||
if event.inaxes != self.canvas.axes:
|
if event.inaxes != self.canvas.axes:
|
||||||
return
|
return
|
||||||
|
if event.button.value == 1:
|
||||||
modifiers = QApplication.keyboardModifiers()
|
|
||||||
if modifiers != Qt.ShiftModifier:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
#modifiers = QApplication.keyboardModifiers()
|
||||||
|
#if modifiers not in [Qt.ShiftModifier]:
|
||||||
|
#return
|
||||||
|
|
||||||
points, _ = self.highlight
|
points, _ = self.highlight
|
||||||
|
|
||||||
z = self._get_z_from_click(event)
|
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
|
return
|
||||||
|
|
||||||
a, p, w = self._compute_hydrolics(z)
|
a, p, w = self._compute_hydraulics(z)
|
||||||
|
|
||||||
logger.debug(f"{z, a, p, w}")
|
logger.debug(f"{z, a, p, w}")
|
||||||
|
|
||||||
|
|
@ -110,7 +123,7 @@ class Plot(PamhyrPlot):
|
||||||
self.update()
|
self.update()
|
||||||
return
|
return
|
||||||
|
|
||||||
def select_points_from_indexes(self, indexes):
|
def select_points_from_indices(self, indexes):
|
||||||
data = self.data
|
data = self.data
|
||||||
_, hyd = self.highlight
|
_, hyd = self.highlight
|
||||||
|
|
||||||
|
|
@ -187,16 +200,27 @@ class Plot(PamhyrPlot):
|
||||||
|
|
||||||
def rect_select_callback(self, eclick, erelease):
|
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
|
x1, y1 = eclick.xdata, eclick.ydata
|
||||||
x2, y2 = erelease.xdata, erelease.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)
|
if modifiers == Qt.ControlModifier:
|
||||||
|
rows = self._parent.index_selected_rows()
|
||||||
self._select_in_table(inds)
|
self.highlight = (points+points2, hyd)
|
||||||
|
self._select_in_table(rows+inds)
|
||||||
|
else:
|
||||||
|
self.highlight = (points2, hyd)
|
||||||
|
self._select_in_table(inds)
|
||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
return
|
return
|
||||||
|
|
@ -213,7 +237,7 @@ class Plot(PamhyrPlot):
|
||||||
return listi, listp
|
return listi, listp
|
||||||
|
|
||||||
|
|
||||||
def _compute_hydrolics(self, z):
|
def _compute_hydraulics(self, z):
|
||||||
profile = self.data
|
profile = self.data
|
||||||
|
|
||||||
points = profile.wet_points(z)
|
points = profile.wet_points(z)
|
||||||
|
|
@ -242,7 +266,7 @@ class Plot(PamhyrPlot):
|
||||||
self.profile_line2D, = self.canvas.axes.plot(
|
self.profile_line2D, = self.canvas.axes.plot(
|
||||||
x, y, color=self.color_plot,
|
x, y, color=self.color_plot,
|
||||||
lw=1.5, markersize=7, marker='+',
|
lw=1.5, markersize=7, marker='+',
|
||||||
picker=30
|
picker=10
|
||||||
)
|
)
|
||||||
|
|
||||||
self.draw_annotation(x, y)
|
self.draw_annotation(x, y)
|
||||||
|
|
@ -307,6 +331,11 @@ class Plot(PamhyrPlot):
|
||||||
|
|
||||||
if hyd is not None:
|
if hyd is not None:
|
||||||
self.draw_highligth_z_line(*hyd)
|
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):
|
def draw_highligth_z_line(self, z, a, p, w):
|
||||||
text = (
|
text = (
|
||||||
|
|
@ -331,6 +360,7 @@ class Plot(PamhyrPlot):
|
||||||
xlim, [z, z],
|
xlim, [z, z],
|
||||||
color=self.color_plot_river_water
|
color=self.color_plot_river_water
|
||||||
)
|
)
|
||||||
|
self._z_line[0].set_visible(True)
|
||||||
|
|
||||||
self._z_note = self.canvas.axes.annotate(
|
self._z_note = self.canvas.axes.annotate(
|
||||||
text, pos,
|
text, pos,
|
||||||
|
|
@ -342,12 +372,15 @@ class Plot(PamhyrPlot):
|
||||||
fontweight='bold',
|
fontweight='bold',
|
||||||
alpha=0.7
|
alpha=0.7
|
||||||
)
|
)
|
||||||
|
self._z_note.set_visible(True)
|
||||||
else:
|
else:
|
||||||
self.draw_highligth_z_line_fill(x, y, z)
|
self.draw_highligth_z_line_fill(x, y, z)
|
||||||
|
|
||||||
self._z_line[0].set_data(xlim, [z, z])
|
self._z_line[0].set_data(xlim, [z, z])
|
||||||
self._z_note.set_position(pos)
|
self._z_note.set_position(pos)
|
||||||
self._z_note.set_text(text)
|
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):
|
def draw_highligth_z_line_fill(self, x, y, z):
|
||||||
if self._z_fill_between is not None:
|
if self._z_fill_between is not None:
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,8 @@ class ProfileWindow(PamhyrWindow):
|
||||||
data=self._profile,
|
data=self._profile,
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
toolbar=self._toolbar,
|
toolbar=self._toolbar,
|
||||||
table=self.find(QTableView, "tableView")
|
table=self.find(QTableView, "tableView"),
|
||||||
|
parent=self
|
||||||
)
|
)
|
||||||
self._plot.draw()
|
self._plot.draw()
|
||||||
|
|
||||||
|
|
@ -146,7 +147,7 @@ class ProfileWindow(PamhyrWindow):
|
||||||
|
|
||||||
def update_points_selection(self):
|
def update_points_selection(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
self._plot.select_points_from_indexes(rows)
|
self._plot.select_points_from_indices(rows)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.update_plot()
|
self.update_plot()
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class PamhyrPlot(APlot):
|
||||||
self._rect_select = RectangleSelector(ax=self.canvas.axes,
|
self._rect_select = RectangleSelector(ax=self.canvas.axes,
|
||||||
onselect=self.rect_select_callback,
|
onselect=self.rect_select_callback,
|
||||||
useblit=True,
|
useblit=True,
|
||||||
button=[1, 3], # don't use middle button
|
button=[1], # don't use middle nor right button
|
||||||
minspanx=1.0,
|
minspanx=1.0,
|
||||||
minspany=1.0,
|
minspany=1.0,
|
||||||
spancoords='pixels',
|
spancoords='pixels',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue