LC: Change graph to reach plot.

mesh
Pierre-Antoine Rouby 2023-05-17 15:31:32 +02:00
parent bcaca20f28
commit 55cd309188
2 changed files with 88 additions and 38 deletions

View File

@ -10,13 +10,15 @@ from PyQt5.QtCore import (
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class PlotXY(APlot): 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__( super(PlotXY, self).__init__(
canvas=canvas, canvas=canvas,
data=data, data=data,
toolbar=toolbar toolbar=toolbar
) )
self.display_current = display_current
self.line_xy = [] self.line_xy = []
self.line_gl = [] self.line_gl = []
@ -25,14 +27,21 @@ class PlotXY(APlot):
self.after_plot_selected = None self.after_plot_selected = None
@timer @timer
def draw(self): def draw(self, highlight=None):
self.canvas.axes.cla() self.canvas.axes.cla()
self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5) self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5)
if self.data is None:
return
if self.data.number_profiles == 0: if self.data.number_profiles == 0:
self._init = False self._init = False
return return
kp_min, kp_max = (-1, -1)
if highlight is not None:
kp_min, kp_max = highlight
# Axes # Axes
self.canvas.axes.set_xlabel( self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "X (m)"), _translate("MainWindow_reach", "X (m)"),
@ -46,11 +55,14 @@ class PlotXY(APlot):
# Draw line for each profile # Draw line for each profile
self.line_xy = [ self.line_xy = [
self.canvas.axes.plot( self.canvas.axes.plot(
x, y, x, y, lw=1.,
color='r', lw=1., color='b' if kp_min <= kp <= kp_max else 'r',
markersize=3, marker='+' 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 # Guide lines
@ -64,6 +76,7 @@ class PlotXY(APlot):
for x, y in zip(x_complete, y_complete) for x, y in zip(x_complete, y_complete)
] ]
if self.display_current:
# Previous profile # Previous profile
self.before_plot_selected, = self.canvas.axes.plot( self.before_plot_selected, = self.canvas.axes.plot(
self.data.profile(0).x(), self.data.profile(0).x(),
@ -103,7 +116,10 @@ class PlotXY(APlot):
self.draw() self.draw()
return return
if ind is not None: if self.data is None:
return
if ind is not None and self.display_current:
before = ind - 1 before = ind - 1
after = ind + 1 after = ind + 1

View File

@ -36,7 +36,8 @@ from View.LateralContribution.Table import (
TableModel, ComboBoxDelegate 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.translate import *
from View.LateralContribution.Edit.Window import EditLateralContributionWindow from View.LateralContribution.Edit.Window import EditLateralContributionWindow
@ -106,14 +107,16 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
table.setAlternatingRowColors(True) table.setAlternatingRowColors(True)
def setup_graph(self): def setup_graph(self):
self.graph_widget = GraphWidget( self.canvas = MplCanvas(width=5, height=4, dpi=100)
self._study.river, self.canvas.setObjectName("canvas")
min_size=None, size=(200,200), self.plot_layout = self.find(QVBoxLayout, "verticalLayout")
only_display=True, self.plot_layout.addWidget(self.canvas)
parent=self
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): def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add) 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.copy_sc.activated.connect(self.copy)
self.paste_sc.activated.connect(self.paste) 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): def current_tab(self):
return self.find(QTabWidget, "tabWidget")\ return self.find(QTabWidget, "tabWidget")\
.currentWidget()\ .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): def add(self):
tab = self.current_tab() tab = self.current_tab()
rows = self.index_selected_rows() rows = self.index_selected_rows()