From 7760181baaa3d3beb4243b75542d7f9cf7acf46f Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 16 Feb 2024 14:32:18 +0100 Subject: [PATCH] Friction: Apply new PamhyrPlot features. --- src/View/Frictions/PlotStricklers.py | 115 +++++++++++++++------------ src/View/Frictions/Window.py | 11 ++- src/View/Frictions/translate.py | 8 ++ src/View/Geometry/PlotKPZ.py | 7 +- 4 files changed, 80 insertions(+), 61 deletions(-) diff --git a/src/View/Frictions/PlotStricklers.py b/src/View/Frictions/PlotStricklers.py index 062d0bfe..c7f0abc3 100644 --- a/src/View/Frictions/PlotStricklers.py +++ b/src/View/Frictions/PlotStricklers.py @@ -31,59 +31,40 @@ _translate = QCoreApplication.translate class PlotStricklers(PamhyrPlot): - def draw_frictions(self, frictions, color="r"): - lst = sorted( - filter( - lambda f: f.is_full_defined(), - frictions - ), - key=lambda s: s.begin_kp - ) - - coef = flatten( - map( - lambda s: [s.begin_strickler, s.end_strickler], - lst - ) + def __init__(self, data=None, canvas=None, trad=None, + toolbar=None, parent=None): + super(PlotStricklers, self).__init__( + canvas=canvas, + trad=trad, + data=data, + toolbar=toolbar, + parent=parent ) - kp = flatten( - map( - lambda s: [s.begin_kp, s.end_kp], - lst - ) - ) + self.label_x = self._trad["kp"] + self.label_y = self._trad["stricklers"] - coef_minor = list(map(lambda s: s.minor, coef)) - coef_medium = list(map(lambda s: s.medium, coef)) + self.line_kp_elevation = [None, None] - self.line_kp_elevation = self.canvas.axes.plot( - kp, coef_minor, - color=color, lw=1. - ) + self._isometric_axis = False - self.line_kp_elevation = self.canvas.axes.plot( - kp, coef_medium, - color=color, lw=1. - ) + self._auto_relim = False + self._auto_relim_update = False + self._autoscale_update = True @timer def draw(self, highlight=None): - self.canvas.axes.cla() - self.canvas.axes.grid(color='grey', linestyle='--', linewidth=0.5) + self.init_axes() if self.data is None: return - self.canvas.axes.set_ylabel( - _translate("MainWindow_reach", "Stricklers"), - color='black', fontsize=11 - ) - self.canvas.axes.set_xlabel( - _translate("MainWindow_reach", "Kp (m)"), - color='black', fontsize=11 - ) + self.draw_data() + + self.idle() + self._init = True + def draw_data(self): kp = self.data.reach.get_kp() self.canvas.axes.set_xlim( left=min(kp), right=max(kp) @@ -92,12 +73,12 @@ class PlotStricklers(PamhyrPlot): frictions = self.data.frictions if len(frictions) != 0: lst = frictions.frictions - self.draw_frictions(lst) + self.draw_frictions(lst, self.color_plot) # HightLight kp_min, kp_max = (-1, -1) - if highlight is not None: - kp_min, kp_max = highlight + if self._highlight_data is not None: + kp_min, kp_max = self._highlight_data lst = list( filter( @@ -106,17 +87,45 @@ class PlotStricklers(PamhyrPlot): frictions.frictions ) ) - self.draw_frictions(lst, color="b") - self.canvas.figure.tight_layout() - self.canvas.figure.canvas.draw_idle() - if self.toolbar is not None: - self.toolbar.update() + self.draw_frictions(lst, self.color_plot_highlight) - # self._init = True + def draw_frictions(self, frictions, color): + lst = sorted( + filter( + lambda f: f.is_full_defined(), + frictions + ), + 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[0] = self.canvas.axes.plot( + kp, coef_minor, + color=color, lw=1. + ) + + self.line_kp_elevation[1] = self.canvas.axes.plot( + kp, coef_medium, + color=color, lw=1. + ) @timer - def update(self, ind=None): - if not self._init: - self.draw() - return + def update(self): + self.draw() diff --git a/src/View/Frictions/Window.py b/src/View/Frictions/Window.py index cfb31027..e920244c 100644 --- a/src/View/Frictions/Window.py +++ b/src/View/Frictions/Window.py @@ -132,8 +132,8 @@ class FrictionsWindow(PamhyrWindow): self.plot = PlotKPZ( canvas=self.canvas, data=self._reach.reach, + trad=self._trad, toolbar=None, - display_current=False ) self.plot.draw() @@ -145,6 +145,7 @@ class FrictionsWindow(PamhyrWindow): self.plot_2 = PlotStricklers( canvas=self.canvas_2, data=self._reach, + trad=self._trad, toolbar=None ) self.plot_2.draw() @@ -193,16 +194,18 @@ class FrictionsWindow(PamhyrWindow): canvas=self.canvas, data=reach, toolbar=None, - display_current=False ) - self.plot.draw(highlight=highlight) + self.plot.highlight = highlight + self.plot.draw() self.plot = PlotStricklers( canvas=self.canvas_2, data=data, + trad=self._trad, toolbar=None ) - self.plot.draw(highlight=highlight) + self.plot.highlight = highlight + self.plot.draw() def add(self): rows = self.index_selected_rows() diff --git a/src/View/Frictions/translate.py b/src/View/Frictions/translate.py index 5ead3e1c..3cade05a 100644 --- a/src/View/Frictions/translate.py +++ b/src/View/Frictions/translate.py @@ -27,6 +27,14 @@ class FrictionsTranslate(PamhyrTranslate): def __init__(self): super(FrictionsTranslate, self).__init__() + self._dict["kp"] = _translate( + "Frictions", "Kp (m)" + ) + self._dict["stricklers"] = _translate( + "Frictions", "Stricklers" + ) + + self._dict["Edit frictions"] = _translate( "Frictions", "Edit frictions" ) diff --git a/src/View/Geometry/PlotKPZ.py b/src/View/Geometry/PlotKPZ.py index 0209b0aa..c3ca9653 100644 --- a/src/View/Geometry/PlotKPZ.py +++ b/src/View/Geometry/PlotKPZ.py @@ -56,7 +56,7 @@ class PlotKPZ(PamhyrPlot): self.after_plot_selected = None @timer - def draw(self, highlight=None): + def draw(self): self.init_axes() if self.data is None: @@ -91,8 +91,7 @@ class PlotKPZ(PamhyrPlot): z_max = self.data.get_z_max() self.line_kp_zmin_zmax = self.canvas.axes.vlines( - x=kp, - ymin=z_min, ymax=z_max, + x=kp, ymin=z_min, ymax=z_max, color=self.color_plot, lw=1. ) @@ -103,7 +102,7 @@ class PlotKPZ(PamhyrPlot): z_min = self.data.get_z_min() z_max = self.data.get_z_max() - kp_min, kp_max = highlight + kp_min, kp_max = self._highlight_data indexes = list( map( -- GitLab