From f35048b89f62c4ad2deab4c9ee84eb4cce58f746 Mon Sep 17 00:00:00 2001 From: Theophile Terraz Date: Mon, 23 Jun 2025 18:07:46 +0200 Subject: [PATCH] add reach selection in geometry --- src/Model/HydraulicStructures/Basic/Types.py | 4 +- src/View/Geometry/PlotAC.py | 5 ++ src/View/Geometry/PlotRKZ.py | 5 ++ src/View/Geometry/PlotXY.py | 5 ++ src/View/Geometry/Window.py | 28 +++++++- src/View/SelectReach/Window.py | 68 ++++++++++++++++++++ src/View/Translate.py | 1 + src/View/ui/GeometryReach.ui | 9 +++ src/View/ui/SelectReach.ui | 67 +++++++++++++++++++ 9 files changed, 187 insertions(+), 5 deletions(-) create mode 100644 src/View/SelectReach/Window.py create mode 100644 src/View/ui/SelectReach.ui diff --git a/src/Model/HydraulicStructures/Basic/Types.py b/src/Model/HydraulicStructures/Basic/Types.py index 0182409b..028d9f8c 100644 --- a/src/Model/HydraulicStructures/Basic/Types.py +++ b/src/Model/HydraulicStructures/Basic/Types.py @@ -83,8 +83,8 @@ class TriangularWeir(BasicHS): self._data = [ BHSValue("elevation", float, 1.0, status=status), BHSValue("loading_elevation", float, 9999.999, status=status), - BHSValue("discharge_coefficient", float, 0.4, status=status), - BHSValue("half-angle_tangent", float, 0.0, status=status), + BHSValue("discharge_coefficient", float, 0.31, status=status), + BHSValue("half-angle_tangent", float, 1.0, status=status), ] diff --git a/src/View/Geometry/PlotAC.py b/src/View/Geometry/PlotAC.py index 2be00355..03eba01a 100644 --- a/src/View/Geometry/PlotAC.py +++ b/src/View/Geometry/PlotAC.py @@ -51,6 +51,11 @@ class PlotAC(PamhyrPlot): self.plot_selected = None self.next_plot_selected = None + @timer + def redraw(self, data): + self._data = data + self.draw() + @timer def draw(self): self.init_axes() diff --git a/src/View/Geometry/PlotRKZ.py b/src/View/Geometry/PlotRKZ.py index f15e6826..0589ea22 100644 --- a/src/View/Geometry/PlotRKZ.py +++ b/src/View/Geometry/PlotRKZ.py @@ -163,6 +163,11 @@ class PlotRKZ(PamhyrPlot): ) self._table.scrollTo(self._table.model().index(ind2, 0)) + @timer + def redraw(self, data): + self._data = data + self.draw() + @timer def draw(self): self.init_axes() diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py index 548b7ee0..35afc749 100644 --- a/src/View/Geometry/PlotXY.py +++ b/src/View/Geometry/PlotXY.py @@ -162,6 +162,11 @@ class PlotXY(PamhyrPlot): ) self._table.scrollTo(self._table.model().index(ind2, 0)) + @timer + def redraw(self, data): + self._data = data + self.draw() + @timer def draw(self): self.init_axes() diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py index 6c24b22e..dbc1c1c7 100644 --- a/src/View/Geometry/Window.py +++ b/src/View/Geometry/Window.py @@ -47,6 +47,8 @@ from View.Tools.PamhyrWindow import PamhyrWindow from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar from View.Tools.Plot.PamhyrCanvas import MplCanvas +from View.SelectReach.Window import SelectReachWindow + from Meshing.Mage import ( MeshingWithMage, MeshingWithMageMailleurTT ) @@ -196,6 +198,7 @@ class GeometryWindow(PamhyrWindow): "action_update_rk": self.update_rk, "action_purge": self.purge, "action_shift": self.shift, + "action_select_reach": self.select_reach, } for action in actions: @@ -217,9 +220,9 @@ class GeometryWindow(PamhyrWindow): def _update(self, redraw=False, propagate=True): if redraw: - self._plot_xy.draw() - self._plot_rkc.draw() - self._plot_ac.draw() + self._plot_xy.redraw(data=self._reach) + self._plot_rkc.redraw(data=self._reach) + self._plot_ac.redraw(data=self._reach) self.select_current_profile() @@ -535,6 +538,25 @@ class GeometryWindow(PamhyrWindow): logger_exception(e) return + def select_reach(self): + try: + dlg = SelectReachWindow( + study=self._study, + trad=self._trad, + parent=self + ) + if dlg.exec(): + self._reach = self._study.river.current_reach().reach + self.setup_table() + self.update_redraw() # Profile selection when line change in table + self.find(QTableView, "tableView").selectionModel()\ + .selectionChanged\ + .connect(self.select_current_profile) + except Exception as e: + logger_exception(e) + return + + def duplicate(self): rows = [ row.row() for row in diff --git a/src/View/SelectReach/Window.py b/src/View/SelectReach/Window.py new file mode 100644 index 00000000..3d102ac7 --- /dev/null +++ b/src/View/SelectReach/Window.py @@ -0,0 +1,68 @@ +# Window.py -- Pamhyr +# Copyright (C) 2023-2025 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 View.Tools.PamhyrWindow import PamhyrDialog + + +class SelectReachWindow(PamhyrDialog): + _pamhyr_ui = "SelectReach" + _pamhyr_name = "Select reach" + + def __init__(self, study=None, config=None, trad=None, parent=None): + + super(SelectReachWindow, self).__init__( + title=trad[self._pamhyr_name], + study=study, + config=config, + options=[], + parent=parent + ) + + self.setup_combobox() + self.select_current_reach() + + def setup_combobox(self): + reaches = list(self._study.river.enable_edges()) + reaches_name = [r.name for r in reaches] + + self.combobox_add_items("comboBox", reaches_name) + + def select_current_reach(self): + if self._study.river.has_current_reach(): + reach = self._study.river.current_reach() + self.set_combobox_text( + "comboBox", + reach.name + ) + + def accept(self): + reach_name = self.get_combobox_text("comboBox") + + reach = next( + filter( + lambda s: s.name == reach_name, + self._study.river.enable_edges() + ) + ) + + self._study.river.set_current_reach(reach) + + super().accept() + + def reject(self): + self.close() diff --git a/src/View/Translate.py b/src/View/Translate.py index 25664fcf..8caa5f66 100644 --- a/src/View/Translate.py +++ b/src/View/Translate.py @@ -39,6 +39,7 @@ class CommonWordTranslate(PamhyrTranslate): self._dict["reach"] = _translate("CommonWord", "Reach") self._dict["reaches"] = _translate("CommonWord", "Reaches") + self._dict["Select reach"] = _translate("CommonWord", "Select reach") self._dict["cross_section"] = _translate("CommonWord", "Cross-section") self._dict["main_channel"] = _translate("CommonWord", "Main channel") self._dict["floodway"] = _translate("CommonWord", "Floodway") diff --git a/src/View/ui/GeometryReach.ui b/src/View/ui/GeometryReach.ui index 2d175bdc..8c80a7bf 100644 --- a/src/View/ui/GeometryReach.ui +++ b/src/View/ui/GeometryReach.ui @@ -93,6 +93,7 @@ + @@ -235,6 +236,14 @@ Shift selected sections coordinates + + + Select reach + + + Change current reach + + diff --git a/src/View/ui/SelectReach.ui b/src/View/ui/SelectReach.ui new file mode 100644 index 00000000..df3fd91f --- /dev/null +++ b/src/View/ui/SelectReach.ui @@ -0,0 +1,67 @@ + + + Dialog + + + + 0 + 0 + 400 + 76 + + + + Dialog + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + + + buttonBox + accepted() + Dialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Dialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +