interactive profile selection in structures + debug

0.0.9
Theophile Terraz 2024-06-11 14:17:38 +02:00
parent c6b28ba3a0
commit ea146cbe87
7 changed files with 80 additions and 34 deletions

View File

@ -50,7 +50,6 @@ class PlotAC(PamhyrPlot):
self.previous_plot_selected = None
self.plot_selected = None
self.next_plot_selected = None
self._rect_select = None
@timer
def draw(self):

View File

@ -57,7 +57,6 @@ class PlotKPZ(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self._rect_select = None
self.parent=parent
self._table=table
self._colors = []
@ -286,6 +285,7 @@ class PlotKPZ(PamhyrPlot):
for hs in lhs:
x = hs.input_kp
if x is not None:
z_min = reach.get_z_min()
z_max = reach.get_z_max()

View File

@ -51,7 +51,6 @@ class PlotXY(PamhyrPlot):
self.before_plot_selected = None
self.plot_selected = None
self.after_plot_selected = None
self._rect_select = None
self.parent=parent
self.line_xy_collection = None
self._table=table

View File

@ -29,6 +29,7 @@ from PyQt5.QtCore import (
)
from PyQt5.QtWidgets import QApplication
from matplotlib.widgets import RectangleSelector
_translate = QCoreApplication.translate
@ -71,6 +72,14 @@ class Plot(PamhyrPlot):
# wet_preimeter, water_width)
)
self._onpickevent = None
self._rect_select = RectangleSelector(ax=self.canvas.axes,
onselect=self.rect_select_callback,
useblit=True,
button=[1], # don't use middle nor right button
minspanx=2.0,
minspany=2.0,
spancoords='pixels',
interactive=False)
def onrelease(self, event):
# we need to do that to prevent conflicst between onpick and rect_select_callback

View File

@ -20,8 +20,9 @@ from tools import timer
from View.Tools.PamhyrPlot import PamhyrPlot
from PyQt5.QtCore import (
QCoreApplication
QCoreApplication, Qt,
)
from PyQt5.QtWidgets import QApplication
from matplotlib.collections import LineCollection
@ -50,6 +51,7 @@ class PlotKPC(PamhyrPlot):
self._auto_relim_update = True
self._autoscale_update = True
self.parent = parent
@property
def river(self):
@ -91,7 +93,14 @@ class PlotKPC(PamhyrPlot):
self.line_kp_zmin, = self.canvas.axes.plot(
kp, z_min,
color=self.color_plot_river_bottom,
lw=1.
lw=1.,
)
self.line_kp_zmax, = self.canvas.axes.plot(
kp, z_max,
color=self.color_plot_river_bottom,
lw=1.,
alpha=0.0
)
if len(kp) != 0:
@ -99,7 +108,8 @@ class PlotKPC(PamhyrPlot):
x=kp,
ymin=z_min, ymax=z_max,
color=self.color_plot,
lw=1.
lw=1.,
picker=10
)
def draw_current(self):
@ -163,3 +173,40 @@ class PlotKPC(PamhyrPlot):
self.profile.set_data([], [])
self.canvas.figure.canvas.draw_idle()
def onpick(self, event):
if event.mouseevent.inaxes != self.canvas.axes:
return
if event.mouseevent.button.value != 1:
return
modifiers = QApplication.keyboardModifiers()
if modifiers not in [Qt.ControlModifier, Qt.NoModifier, Qt.ShiftModifier]:
return
closest = self._closest_profile(event)
index = self.parent.tableView.selectedIndexes()
print(index)
if self.parent._table is not None:
self.parent._table.setData(index[2], closest)
return
def _closest_profile(self, event):
s = event.artist.get_segments()
x = [i[0,0] for i in s]
mx = event.mouseevent.xdata
points = enumerate(x)
def dist_mouse(point):
x = point[1]
d = abs(mx - x)
return d
closest = min(
points, key=dist_mouse
)
return closest[1]

View File

@ -141,7 +141,8 @@ class HydraulicStructuresWindow(PamhyrWindow):
reach=None,
profile=None,
trad=self._trad,
toolbar=self.toolbar
toolbar=self.toolbar,
parent=self
)
self.plot_kpc.draw()

View File

@ -19,7 +19,6 @@
import logging
import matplotlib.colors as mplcolors
from matplotlib.widgets import RectangleSelector
from matplotlib import ticker
from tools import timestamp_to_old_pamhyr_date
@ -43,7 +42,6 @@ class PamhyrPlot(APlot):
color_plot_river_bottom = "grey"
color_plot_river_water = "blue"
color_plot_river_water_zone = "skyblue"
colors = list(mplcolors.TABLEAU_COLORS)
linestyle = ['solid', 'dashed', 'dashdot', 'dotted']
@ -106,14 +104,7 @@ class PamhyrPlot(APlot):
self._highlight_data_update = False
self._current_data = None #: Current data identifier
self._current_data_update = False
self._rect_select = RectangleSelector(ax=self.canvas.axes,
onselect=self.rect_select_callback,
useblit=True,
button=[1], # don't use middle nor right button
minspanx=2.0,
minspany=2.0,
spancoords='pixels',
interactive=False)
self._rect_select = None
@property
def canvas(self):