diff --git a/src/View/Sections/PlotStricklers.py b/src/View/Sections/PlotStricklers.py new file mode 100644 index 0000000000000000000000000000000000000000..5069087b17fa58d287a91fb640eb9677f3e2c9cb --- /dev/null +++ b/src/View/Sections/PlotStricklers.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- + +from tools import timer, flatten +from View.Plot.APlot import APlot + +from PyQt5.QtCore import ( + QCoreApplication +) + +_translate = QCoreApplication.translate + +class PlotStricklers(APlot): + def __init__(self, canvas=None, data=None, toolbar=None): + super(PlotStricklers, self).__init__( + canvas=canvas, + data=data, + toolbar=toolbar + ) + + def draw_sections(self, sections, color="r"): + lst = sections + lst.sort(key = lambda s: s.begin_kp) + + coef = flatten( + map( + lambda s: [s.begin_strickler, s.end_strickler], + lst + ) + ) + + kp = flatten( + map( + lambda s: [s.begin_kp, s.end_kp], + lst + ) + ) + + coef_minor = list(map(lambda s: s.minor, coef)) + coef_medium = list(map(lambda s: s.medium, coef)) + + self.line_kp_elevation = self.canvas.axes.plot( + kp, coef_minor, + color=color, lw=1. + ) + + self.line_kp_elevation = self.canvas.axes.plot( + kp, coef_medium, + color=color, lw=1. + ) + + + @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 + + self.canvas.axes.set_ylabel( + _translate("MainWindow_reach", "Stricklers (m)"), + color='green', fontsize=11 + ) + self.canvas.axes.set_xlabel( + _translate("MainWindow_reach", "KP (m)"), + color='green', fontsize=11 + ) + + kp = self.data.reach.get_kp() + self.canvas.axes.set_xlim( + left = min(kp), right = max(kp) + ) + + sections = self.data.sections + if len(sections) != 0: + lst = sections.sections + self.draw_sections(lst) + + # HightLight + + kp_min, kp_max = (-1, -1) + if highlight is not None: + kp_min, kp_max = highlight + + lst = list( + filter( + lambda s: (s.begin_kp == kp_min and + s.end_kp == kp_max), + sections.sections + ) + ) + self.draw_sections(lst, color="b") + + + 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 diff --git a/src/View/Sections/Table.py b/src/View/Sections/Table.py index 87461630cf0f60841109b2e35548c212520362d6..47aff38e1b5050f2054b722ade6c472ac5f1d719 100644 --- a/src/View/Sections/Table.py +++ b/src/View/Sections/Table.py @@ -159,7 +159,7 @@ class TableModel(QAbstractTableModel): elif self._headers[column] == "end_strickler": self._undo.push( SetEndStricklerCommand( - self._sections, row, self._data.strickler(value) + self._sections, row, self._study.river.strickler(value) ) ) diff --git a/src/View/Sections/Window.py b/src/View/Sections/Window.py index 979b3c1a932b653809a7ae0ae4c9bf5a33d2f44d..4176b8c37d8ad630481d924d3d52706f109bb081 100644 --- a/src/View/Sections/Window.py +++ b/src/View/Sections/Window.py @@ -32,6 +32,7 @@ from View.Sections.Table import ( from View.Plot.MplCanvas import MplCanvas from View.Geometry.PlotKPC import PlotKPC +from View.Sections.PlotStricklers import PlotStricklers from View.Sections.translate import * _translate = QCoreApplication.translate @@ -107,11 +108,23 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow): self.plot = PlotKPC( canvas = self.canvas, - data = None, + data = self._reach.reach, toolbar = None, display_current = False ) + 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_2 = PlotStricklers( + canvas = self.canvas_2, + data = self._reach, + toolbar = None + ) + + def setup_connections(self): self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_del").triggered.connect(self.delete) @@ -146,23 +159,30 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow): rows = self.index_selected_rows() data = None + reach = None highlight = None if len(rows) > 0: - edge = self._reach - if edge: - data = edge.reach - sec = self._sections.get(rows[0]) - highlight = (sec.begin_kp, sec.end_kp) + data = self._reach + reach = self._reach.reach + sec = self._sections.get(rows[0]) + highlight = (sec.begin_kp, sec.end_kp) self.plot = PlotKPC( canvas = self.canvas, - data = data, + data = reach, toolbar = None, display_current = False ) self.plot.draw(highlight=highlight) + self.plot = PlotStricklers( + canvas = self.canvas_2, + data = data, + toolbar = None + ) + self.plot.draw(highlight=highlight) + def add(self): rows = self.index_selected_rows() if len(self._sections) == 0 or len(rows) == 0: diff --git a/src/View/ui/Sections.ui b/src/View/ui/Sections.ui index cd6ea6ceea08a3882c02aecf4c7d37f0f2c347d6..558391970ec1edb436f3d233a691659948575c31 100644 --- a/src/View/ui/Sections.ui +++ b/src/View/ui/Sections.ui @@ -63,6 +63,7 @@ <addaction name="action_add"/> <addaction name="action_del"/> <addaction name="action_sort"/> + <addaction name="action_edit_stricklers"/> </widget> <action name="action_add"> <property name="icon"> @@ -91,6 +92,18 @@ <string>Sort</string> </property> </action> + <action name="action_edit_stricklers"> + <property name="icon"> + <iconset> + <normaloff>ressources/edit.png</normaloff>ressources/edit.png</iconset> + </property> + <property name="text"> + <string>Edit stricklers</string> + </property> + <property name="shortcut"> + <string>Ctrl+E</string> + </property> + </action> </widget> <resources/> <connections/>