mirror of https://gitlab.com/pamhyr/pamhyr2
LC: Change graph to reach plot.
parent
bcaca20f28
commit
55cd309188
|
|
@ -10,13 +10,15 @@ from PyQt5.QtCore import (
|
|||
_translate = QCoreApplication.translate
|
||||
|
||||
class PlotXY(APlot):
|
||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
||||
def __init__(self, canvas=None, data=None, toolbar=None, display_current=True):
|
||||
super(PlotXY, self).__init__(
|
||||
canvas=canvas,
|
||||
data=data,
|
||||
toolbar=toolbar
|
||||
)
|
||||
|
||||
self.display_current = display_current
|
||||
|
||||
self.line_xy = []
|
||||
self.line_gl = []
|
||||
|
||||
|
|
@ -25,14 +27,21 @@ class PlotXY(APlot):
|
|||
self.after_plot_selected = None
|
||||
|
||||
@timer
|
||||
def draw(self):
|
||||
def draw(self, highlight=None):
|
||||
self.canvas.axes.cla()
|
||||
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
|
||||
if self.data is None:
|
||||
return
|
||||
|
||||
if self.data.number_profiles == 0:
|
||||
self._init = False
|
||||
return
|
||||
|
||||
kp_min, kp_max = (-1, -1)
|
||||
if highlight is not None:
|
||||
kp_min, kp_max = highlight
|
||||
|
||||
# Axes
|
||||
self.canvas.axes.set_xlabel(
|
||||
_translate("MainWindow_reach", "X (m)"),
|
||||
|
|
@ -46,11 +55,14 @@ class PlotXY(APlot):
|
|||
# Draw line for each profile
|
||||
self.line_xy = [
|
||||
self.canvas.axes.plot(
|
||||
x, y,
|
||||
color='r', lw=1.,
|
||||
x, y, lw=1.,
|
||||
color='b' if kp_min <= kp <= kp_max else 'r',
|
||||
markersize=3, marker='+'
|
||||
)
|
||||
for x, y in zip(self.data.get_x(), self.data.get_y())
|
||||
for x, y, kp in zip(
|
||||
self.data.get_x(), self.data.get_y(),
|
||||
self.data.get_kp()
|
||||
)
|
||||
]
|
||||
|
||||
# Guide lines
|
||||
|
|
@ -64,32 +76,33 @@ class PlotXY(APlot):
|
|||
for x, y in zip(x_complete, y_complete)
|
||||
]
|
||||
|
||||
# Previous profile
|
||||
self.before_plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="k", linestyle="--"
|
||||
)
|
||||
self.before_plot_selected.set_visible(False)
|
||||
if self.display_current:
|
||||
# Previous profile
|
||||
self.before_plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="k", linestyle="--"
|
||||
)
|
||||
self.before_plot_selected.set_visible(False)
|
||||
|
||||
# Current profile
|
||||
self.plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="b"
|
||||
)
|
||||
self.plot_selected.set_visible(False)
|
||||
# Current profile
|
||||
self.plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="b"
|
||||
)
|
||||
self.plot_selected.set_visible(False)
|
||||
|
||||
# Next profile
|
||||
self.after_plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="m", linestyle='--'
|
||||
)
|
||||
self.after_plot_selected.set_visible(False)
|
||||
# Next profile
|
||||
self.after_plot_selected, = self.canvas.axes.plot(
|
||||
self.data.profile(0).x(),
|
||||
self.data.profile(0).y(),
|
||||
lw=1., markersize=3,
|
||||
marker='+', color="m", linestyle='--'
|
||||
)
|
||||
self.after_plot_selected.set_visible(False)
|
||||
|
||||
self.canvas.figure.tight_layout()
|
||||
self.canvas.figure.canvas.draw_idle()
|
||||
|
|
@ -103,7 +116,10 @@ class PlotXY(APlot):
|
|||
self.draw()
|
||||
return
|
||||
|
||||
if ind is not None:
|
||||
if self.data is None:
|
||||
return
|
||||
|
||||
if ind is not None and self.display_current:
|
||||
before = ind - 1
|
||||
after = ind + 1
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ from View.LateralContribution.Table import (
|
|||
TableModel, ComboBoxDelegate
|
||||
)
|
||||
|
||||
from View.Network.GraphWidget import GraphWidget
|
||||
from View.Plot.MplCanvas import MplCanvas
|
||||
from View.Geometry.PlotXY import PlotXY
|
||||
from View.LateralContribution.translate import *
|
||||
from View.LateralContribution.Edit.Window import EditLateralContributionWindow
|
||||
|
||||
|
|
@ -106,14 +107,16 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_graph(self):
|
||||
self.graph_widget = GraphWidget(
|
||||
self._study.river,
|
||||
min_size=None, size=(200,200),
|
||||
only_display=True,
|
||||
parent=self
|
||||
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas.setObjectName("canvas")
|
||||
self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
|
||||
self.plot_layout.addWidget(self.canvas)
|
||||
|
||||
self.plot = PlotXY(
|
||||
canvas = self.canvas,
|
||||
data = None,
|
||||
toolbar = None,
|
||||
)
|
||||
self.graph_layout = self.find(QVBoxLayout, "verticalLayout")
|
||||
self.graph_layout.addWidget(self.graph_widget)
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
|
|
@ -126,6 +129,12 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
self.copy_sc.activated.connect(self.copy)
|
||||
self.paste_sc.activated.connect(self.paste)
|
||||
|
||||
for t in ["liquid", "solid", "suspenssion"]:
|
||||
table = self.find(QTableView, f"tableView_{t}")
|
||||
table.selectionModel()\
|
||||
.selectionChanged\
|
||||
.connect(self._set_current_reach)
|
||||
|
||||
def current_tab(self):
|
||||
return self.find(QTabWidget, "tabWidget")\
|
||||
.currentWidget()\
|
||||
|
|
@ -152,6 +161,31 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
|
|||
)
|
||||
)
|
||||
|
||||
def _set_current_reach(self):
|
||||
tab = self.current_tab()
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
data = None
|
||||
highlight = None
|
||||
|
||||
if len(rows) > 0:
|
||||
edge = self._study\
|
||||
.river\
|
||||
.lateral_contribution\
|
||||
.get(tab, rows[0])\
|
||||
.edge
|
||||
if edge:
|
||||
data = edge.reach
|
||||
lc = self._lcs.get(tab, rows[0])
|
||||
highlight = (lc.begin_kp, lc.end_kp)
|
||||
|
||||
self.plot = PlotXY(
|
||||
canvas = self.canvas,
|
||||
data = data,
|
||||
toolbar = None,
|
||||
)
|
||||
self.plot.draw(highlight=highlight)
|
||||
|
||||
def add(self):
|
||||
tab = self.current_tab()
|
||||
rows = self.index_selected_rows()
|
||||
|
|
|
|||
Loading…
Reference in New Issue