Commit 55cd3091 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

LC: Change graph to reach plot.

Showing with 90 additions and 40 deletions
+90 -40
...@@ -10,13 +10,15 @@ from PyQt5.QtCore import ( ...@@ -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): ...@@ -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): ...@@ -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,32 +76,33 @@ class PlotXY(APlot): ...@@ -64,32 +76,33 @@ class PlotXY(APlot):
for x, y in zip(x_complete, y_complete) for x, y in zip(x_complete, y_complete)
] ]
# Previous profile if self.display_current:
self.before_plot_selected, = self.canvas.axes.plot( # Previous profile
self.data.profile(0).x(), self.before_plot_selected, = self.canvas.axes.plot(
self.data.profile(0).y(), self.data.profile(0).x(),
lw=1., markersize=3, self.data.profile(0).y(),
marker='+', color="k", linestyle="--" lw=1., markersize=3,
) marker='+', color="k", linestyle="--"
self.before_plot_selected.set_visible(False) )
self.before_plot_selected.set_visible(False)
# Current profile
self.plot_selected, = self.canvas.axes.plot( # Current profile
self.data.profile(0).x(), self.plot_selected, = self.canvas.axes.plot(
self.data.profile(0).y(), self.data.profile(0).x(),
lw=1., markersize=3, self.data.profile(0).y(),
marker='+', color="b" lw=1., markersize=3,
) marker='+', color="b"
self.plot_selected.set_visible(False) )
self.plot_selected.set_visible(False)
# Next profile
self.after_plot_selected, = self.canvas.axes.plot( # Next profile
self.data.profile(0).x(), self.after_plot_selected, = self.canvas.axes.plot(
self.data.profile(0).y(), self.data.profile(0).x(),
lw=1., markersize=3, self.data.profile(0).y(),
marker='+', color="m", linestyle='--' lw=1., markersize=3,
) marker='+', color="m", linestyle='--'
self.after_plot_selected.set_visible(False) )
self.after_plot_selected.set_visible(False)
self.canvas.figure.tight_layout() self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle() self.canvas.figure.canvas.draw_idle()
...@@ -103,7 +116,10 @@ class PlotXY(APlot): ...@@ -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
......
...@@ -36,7 +36,8 @@ from View.LateralContribution.Table import ( ...@@ -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): ...@@ -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): ...@@ -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): ...@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment