# PlotKPC.py -- Pamhyr # Copyright (C) 2023-2024 INRAE # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -*- coding: utf-8 -*- from tools import timer from View.Tools.PamhyrPlot import PamhyrPlot from PyQt5.QtCore import ( QCoreApplication ) from matplotlib.collections import LineCollection _translate = QCoreApplication.translate class PlotKPC(PamhyrPlot): def __init__(self, canvas=None, trad=None, toolbar=None, river=None, reach=None, profile=None, parent=None): super(PlotKPC, self).__init__( canvas=canvas, trad=trad, data=river, toolbar=toolbar, parent=parent ) self._current_reach = reach self._current_profile = profile self.label_x = self._trad["unit_kp"] self.label_y = self._trad["unit_elevation"] self._isometric_axis = False self._auto_relim_update = True self._autoscale_update = True @property def river(self): return self.data @river.setter def river(self, river): self.data = river @timer def draw(self, highlight=None): self.init_axes() if self.data is None: self.profile = None self.line_kp_zmin_zmax = None self.line_kp_zmin = None return if self._current_reach is None: self.profile = None self.line_kp_zmin_zmax = None self.line_kp_zmin = None return self.draw_data() self.draw_current() self.idle() self._init = True def draw_data(self): reach = self._current_reach kp = reach.reach.get_kp() z_min = reach.reach.get_z_min() z_max = reach.reach.get_z_max() self.line_kp_zmin, = self.canvas.axes.plot( kp, z_min, color=self.color_plot_river_bottom, lw=1. ) if len(kp) != 0: self.line_kp_zmin_zmax = self.canvas.axes.vlines( x=kp, ymin=z_min, ymax=z_max, color=self.color_plot, lw=1. ) def draw_current(self): if self._current_profile is None: self.profile = None else: kp = [self._current_profile.kp, self._current_profile.kp] min_max = [self._current_profile.z_min(), self._current_profile.z_max()] self.profile = self.canvas.axes.plot( kp, min_max, color=self.color_plot_current, lw=1. ) def set_reach(self, reach): self._current_reach = reach self._current_profile = None self.update() def set_profile(self, profile): self._current_profile = profile self.update_current_profile() def update(self): self.draw() def update_current_profile(self): reach = self._current_reach kp = reach.reach.get_kp() z_min = reach.reach.get_z_min() z_max = reach.reach.get_z_max() if self.profile is None: self.draw() else: self.profile.set_data( [self._current_profile.kp, self._current_profile.kp], [self._current_profile.z_min(), self._current_profile.z_max()], ) self.update_idle() def clear(self): if self.profile is not None: self.profile[0].set_data([], []) if self.line_kp_zmin_zmax is not None: self.line_kp_zmin_zmax.remove() self.line_kp_zmin_zmax = None if self.line_kp_zmin is not None: self.line_kp_zmin.set_data([], []) self.canvas.figure.canvas.draw_idle() def clear_profile(self): if self.profile is not None: self.profile.set_data([], []) self.canvas.figure.canvas.draw_idle()