mirror of https://gitlab.com/pamhyr/pamhyr2
interactive profile selection in structures + debug
parent
c6b28ba3a0
commit
ea146cbe87
|
|
@ -50,7 +50,6 @@ class PlotAC(PamhyrPlot):
|
||||||
self.previous_plot_selected = None
|
self.previous_plot_selected = None
|
||||||
self.plot_selected = None
|
self.plot_selected = None
|
||||||
self.next_plot_selected = None
|
self.next_plot_selected = None
|
||||||
self._rect_select = None
|
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,6 @@ class PlotKPZ(PamhyrPlot):
|
||||||
self.before_plot_selected = None
|
self.before_plot_selected = None
|
||||||
self.plot_selected = None
|
self.plot_selected = None
|
||||||
self.after_plot_selected = None
|
self.after_plot_selected = None
|
||||||
self._rect_select = None
|
|
||||||
self.parent=parent
|
self.parent=parent
|
||||||
self._table=table
|
self._table=table
|
||||||
self._colors = []
|
self._colors = []
|
||||||
|
|
@ -286,25 +285,26 @@ class PlotKPZ(PamhyrPlot):
|
||||||
|
|
||||||
for hs in lhs:
|
for hs in lhs:
|
||||||
x = hs.input_kp
|
x = hs.input_kp
|
||||||
z_min = reach.get_z_min()
|
if x is not None:
|
||||||
z_max = reach.get_z_max()
|
z_min = reach.get_z_min()
|
||||||
|
z_max = reach.get_z_max()
|
||||||
|
|
||||||
self.canvas.axes.plot(
|
self.canvas.axes.plot(
|
||||||
[x, x],
|
[x, x],
|
||||||
[min(z_min), max(z_max)],
|
[min(z_min), max(z_max)],
|
||||||
linestyle="--",
|
linestyle="--",
|
||||||
lw=1.,
|
lw=1.,
|
||||||
color=self.color_plot_previous,
|
color=self.color_plot_previous,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.canvas.axes.annotate(
|
self.canvas.axes.annotate(
|
||||||
" > " + hs.name,
|
" > " + hs.name,
|
||||||
(x, max(z_max)),
|
(x, max(z_max)),
|
||||||
horizontalalignment='left',
|
horizontalalignment='left',
|
||||||
verticalalignment='top',
|
verticalalignment='top',
|
||||||
annotation_clip=True,
|
annotation_clip=True,
|
||||||
fontsize=9, color=self.color_plot_previous,
|
fontsize=9, color=self.color_plot_previous,
|
||||||
)
|
)
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def update(self):
|
def update(self):
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,6 @@ class PlotXY(PamhyrPlot):
|
||||||
self.before_plot_selected = None
|
self.before_plot_selected = None
|
||||||
self.plot_selected = None
|
self.plot_selected = None
|
||||||
self.after_plot_selected = None
|
self.after_plot_selected = None
|
||||||
self._rect_select = None
|
|
||||||
self.parent=parent
|
self.parent=parent
|
||||||
self.line_xy_collection = None
|
self.line_xy_collection = None
|
||||||
self._table=table
|
self._table=table
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ from PyQt5.QtCore import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
from matplotlib.widgets import RectangleSelector
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
@ -71,6 +72,14 @@ class Plot(PamhyrPlot):
|
||||||
# wet_preimeter, water_width)
|
# wet_preimeter, water_width)
|
||||||
)
|
)
|
||||||
self._onpickevent = None
|
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):
|
def onrelease(self, event):
|
||||||
# we need to do that to prevent conflicst between onpick and rect_select_callback
|
# we need to do that to prevent conflicst between onpick and rect_select_callback
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@ from tools import timer
|
||||||
from View.Tools.PamhyrPlot import PamhyrPlot
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
QCoreApplication
|
QCoreApplication, Qt,
|
||||||
)
|
)
|
||||||
|
from PyQt5.QtWidgets import QApplication
|
||||||
|
|
||||||
from matplotlib.collections import LineCollection
|
from matplotlib.collections import LineCollection
|
||||||
|
|
||||||
|
|
@ -50,6 +51,7 @@ class PlotKPC(PamhyrPlot):
|
||||||
|
|
||||||
self._auto_relim_update = True
|
self._auto_relim_update = True
|
||||||
self._autoscale_update = True
|
self._autoscale_update = True
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def river(self):
|
def river(self):
|
||||||
|
|
@ -91,7 +93,14 @@ class PlotKPC(PamhyrPlot):
|
||||||
self.line_kp_zmin, = self.canvas.axes.plot(
|
self.line_kp_zmin, = self.canvas.axes.plot(
|
||||||
kp, z_min,
|
kp, z_min,
|
||||||
color=self.color_plot_river_bottom,
|
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:
|
if len(kp) != 0:
|
||||||
|
|
@ -99,7 +108,8 @@ class PlotKPC(PamhyrPlot):
|
||||||
x=kp,
|
x=kp,
|
||||||
ymin=z_min, ymax=z_max,
|
ymin=z_min, ymax=z_max,
|
||||||
color=self.color_plot,
|
color=self.color_plot,
|
||||||
lw=1.
|
lw=1.,
|
||||||
|
picker=10
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_current(self):
|
def draw_current(self):
|
||||||
|
|
@ -163,3 +173,40 @@ class PlotKPC(PamhyrPlot):
|
||||||
self.profile.set_data([], [])
|
self.profile.set_data([], [])
|
||||||
|
|
||||||
self.canvas.figure.canvas.draw_idle()
|
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]
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,8 @@ class HydraulicStructuresWindow(PamhyrWindow):
|
||||||
reach=None,
|
reach=None,
|
||||||
profile=None,
|
profile=None,
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
toolbar=self.toolbar
|
toolbar=self.toolbar,
|
||||||
|
parent=self
|
||||||
)
|
)
|
||||||
self.plot_kpc.draw()
|
self.plot_kpc.draw()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import matplotlib.colors as mplcolors
|
import matplotlib.colors as mplcolors
|
||||||
from matplotlib.widgets import RectangleSelector
|
|
||||||
from matplotlib import ticker
|
from matplotlib import ticker
|
||||||
|
|
||||||
from tools import timestamp_to_old_pamhyr_date
|
from tools import timestamp_to_old_pamhyr_date
|
||||||
|
|
@ -43,7 +42,6 @@ class PamhyrPlot(APlot):
|
||||||
color_plot_river_bottom = "grey"
|
color_plot_river_bottom = "grey"
|
||||||
color_plot_river_water = "blue"
|
color_plot_river_water = "blue"
|
||||||
color_plot_river_water_zone = "skyblue"
|
color_plot_river_water_zone = "skyblue"
|
||||||
|
|
||||||
colors = list(mplcolors.TABLEAU_COLORS)
|
colors = list(mplcolors.TABLEAU_COLORS)
|
||||||
linestyle = ['solid', 'dashed', 'dashdot', 'dotted']
|
linestyle = ['solid', 'dashed', 'dashdot', 'dotted']
|
||||||
|
|
||||||
|
|
@ -106,14 +104,7 @@ class PamhyrPlot(APlot):
|
||||||
self._highlight_data_update = False
|
self._highlight_data_update = False
|
||||||
self._current_data = None #: Current data identifier
|
self._current_data = None #: Current data identifier
|
||||||
self._current_data_update = False
|
self._current_data_update = False
|
||||||
self._rect_select = RectangleSelector(ax=self.canvas.axes,
|
self._rect_select = None
|
||||||
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)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def canvas(self):
|
def canvas(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue