Commit 11a94d77 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Sections: Add stricklers plots.

Showing with 147 additions and 8 deletions
+147 -8
# -*- 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
......@@ -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)
)
)
......
......@@ -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:
......
......@@ -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/>
......
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