IC: Add custom plots.

mesh
Pierre-Antoine Rouby 2023-05-31 16:24:07 +02:00
parent a6e18aa7c9
commit 79857cc8f9
4 changed files with 167 additions and 6 deletions

View File

@ -157,3 +157,21 @@ class InitialConditions(object):
def sort(self, reverse=False, key=None):
self._data.sort(reverse=reverse, key=key)
self._status.modified()
def _data_get(self, key):
return list(
map(
lambda d: d[key],
self._data
)
)
def get_kp(self):
return self._data_get("kp")
def get_elevation(self):
return self._data_get("elevation")
def get_flow(self):
return self._data_get("flow")

View File

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
from tools import timer
from View.Plot.APlot import APlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotDKP(APlot):
def __init__(self, canvas=None, data=None, toolbar=None):
super(PlotDKP, self).__init__(
canvas=canvas,
data=data,
toolbar=toolbar
)
@timer
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 len(self.data) == 0:
return
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Draft (m)"),
color='green', fontsize=12
)
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "KP (m)"),
color='green', fontsize=12
)
kp = self.data.reach.reach.get_kp()
z_min = self.data.reach.reach.get_z_min()
self.line_kp_zmin = self.canvas.axes.plot(
kp, z_min,
color='grey', lw=1.
)
kp = self.data.get_kp()
elevation = self.data.get_elevation()
self.line_kp_elevation = self.canvas.axes.plot(
kp, elevation,
color='b', marker='+', lw=1.
)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
if self.toolbar is not None:
self.toolbar.update()
# self._init = True
@timer
def update(self, ind=None):
if self._init == False:
self.draw()
return

View File

@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
from tools import timer
from View.Plot.APlot import APlot
from PyQt5.QtCore import (
QCoreApplication
)
_translate = QCoreApplication.translate
class PlotFlow(APlot):
def __init__(self, canvas=None, data=None, toolbar=None):
super(PlotFlow, self).__init__(
canvas=canvas,
data=data,
toolbar=toolbar
)
@timer
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 len(self.data) == 0:
return
self.canvas.axes.set_ylabel(
_translate("MainWindow_reach", "Flow (m³/s)"),
color='green', fontsize=12
)
self.canvas.axes.set_xlabel(
_translate("MainWindow_reach", "KP (m)"),
color='green', fontsize=12
)
kp = self.data.get_kp()
flow = self.data.get_flow()
self.line_kp_zmin = self.canvas.axes.plot(
kp, flow,
color='r', lw=1.
)
self.canvas.figure.tight_layout()
self.canvas.figure.canvas.draw_idle()
if self.toolbar is not None:
self.toolbar.update()
# self._init = True
@timer
def update(self, ind=None):
if self._init == False:
self.draw()
return

View File

@ -31,7 +31,8 @@ from View.InitialConditions.UndoCommand import (
from View.InitialConditions.Table import TableModel, ComboBoxDelegate
from View.Plot.MplCanvas import MplCanvas
from View.Geometry.PlotXY import PlotXY
from View.InitialConditions.PlotDKP import PlotDKP
from View.InitialConditions.PlotFlow import PlotFlow
from View.InitialConditions.translate import *
_translate = QCoreApplication.translate
@ -96,29 +97,31 @@ class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
table.setAlternatingRowColors(True)
def setup_graph(self):
print("TODO")
self.canvas_1 = MplCanvas(width=5, height=4, dpi=100)
self.canvas_1.setObjectName("canvas_1")
self.plot_layout_1 = self.find(QVBoxLayout, "verticalLayout_1")
self.plot_layout_1.addWidget(self.canvas_1)
self.plot = PlotXY(
self.plot_1 = PlotDKP(
canvas = self.canvas_1,
data = None,
data = self._ics,
toolbar = None,
)
self.plot_1.draw()
self.canvas_2 = MplCanvas(width=5, height=4, dpi=100)
self.canvas_2.setObjectName("canvas_2")
self.plot_layout_2 = self.find(QVBoxLayout, "verticalLayout_2")
self.plot_layout_2.addWidget(self.canvas_2)
self.plot = PlotXY(
self.plot_2 = PlotFlow(
canvas = self.canvas_2,
data = None,
data = self._ics,
toolbar = None,
)
self.plot_2.draw()
def setup_connections(self):
self.find(QAction, "action_add").triggered.connect(self.add)
self.find(QAction, "action_del").triggered.connect(self.delete)
@ -135,6 +138,10 @@ class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
.selectedRows()[0]\
.row()
def _update_plot(self):
self.plot_1.draw()
self.plot_2.draw()
def index_selected_rows(self):
table = self.find(QTableView, f"tableView")
return list(
@ -154,32 +161,42 @@ class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
else:
self._table.add(rows[0])
self._update_plot()
def delete(self):
rows = self.index_selected_rows()
if len(rows) == 0:
return
self._table.delete(rows)
self._update_plot()
def sort(self):
self._table.sort(False)
self._update_plot()
def move_up(self):
row = self.index_selected_row()
self._table.move_up(row)
self._update_plot()
def move_down(self):
row = self.index_selected_row()
self._table.move_down(row)
self._update_plot()
def copy(self):
print("TODO")
self._update_plot()
def paste(self):
print("TODO")
self._update_plot()
def undo(self):
self._table.undo()
self._update_plot()
def redo(self):
self._table.redo()
self._update_plot()