From 70a26d003629311c4d40a5eb369e666c77a68813 Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Wed, 21 Oct 2026 17:04:30 +0200 Subject: [PATCH] Mage: warn with a non-blocking checker about solid lateral contributions, and rerun lateral contribution checkers when they are modified --- src/Checker/Mage.py | 43 +++++++++++++++++++++ src/Solver/Mage.py | 2 + src/View/LateralContribution/Edit/Window.py | 8 ++++ src/View/LateralContribution/Window.py | 9 +++++ 4 files changed, 62 insertions(+) diff --git a/src/Checker/Mage.py b/src/Checker/Mage.py index f7d4d747..9041cc8d 100644 --- a/src/Checker/Mage.py +++ b/src/Checker/Mage.py @@ -254,3 +254,46 @@ for each reach" return False return ok + + +class MageLateralSolidChecker(AbstractModelChecker): + """Mage has no solid lateral contribution (notice: only upstream + solid discharges, QSO): the solid ones are not exported (LAT holds + liquid discharges only). Non blocking warning""" + + def __init__(self, version="mage8"): + super(MageLateralSolidChecker, self).__init__() + + self._name = _translate( + "Checker", "Mage solid lateral contributions checker") + self._description = _translate( + "Checker", + "Check if the study has solid lateral contributions, which " + "Mage does not take into account" + ) + self._solver = version + self._modules = Modules.LATERAL_CONTRIBUTION + + def run(self, study): + if not self.basic_check(study): + return False + + edges = study.river.enable_edges() + names = [ + lc.name + for lc in study.river.lateral_contribution.get_tab("solid") + if not lc.is_deleted() and lc.reach in edges and len(lc) > 0 + ] + + if len(names) == 0: + self._status = STATUS.OK + self._summary = "ok" + return True + + self._status = STATUS.WARNING + self._summary = _translate( + "Checker", + "Solid lateral contributions not taken into account by Mage: " + "{names}" + ).format(names=", ".join(names)) + return False diff --git a/src/Solver/Mage.py b/src/Solver/Mage.py index 498a8ea9..f77f69bf 100644 --- a/src/Solver/Mage.py +++ b/src/Solver/Mage.py @@ -28,6 +28,7 @@ from tools import timer, trace, logger_exception from Solver.CommandLine import CommandLineSolver from Checker.Mage import ( MageNetworkGraphChecker, MageGeometryGuideLineChecker, + MageLateralSolidChecker, ) from Model.Results.Results import Results @@ -106,6 +107,7 @@ class Mage(CommandLineSolver): MageNetworkGraphChecker(connectivity=True, version=cls._type), MageNetworkGraphChecker(connectivity=False, version=cls._type), MageGeometryGuideLineChecker(version=cls._type), + MageLateralSolidChecker(version=cls._type), ] return lst diff --git a/src/View/LateralContribution/Edit/Window.py b/src/View/LateralContribution/Edit/Window.py index 772be51b..f0448947 100644 --- a/src/View/LateralContribution/Edit/Window.py +++ b/src/View/LateralContribution/Edit/Window.py @@ -157,6 +157,8 @@ class EditLateralContributionWindow(PamhyrWindow): self.widget_update() def setup_connections(self): + self._undo_stack.indexChanged.connect(self._propagate_lateral_update) + if self._study.is_editable(): self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_del").triggered.connect(self.delete) @@ -172,6 +174,12 @@ class EditLateralContributionWindow(PamhyrWindow): else: self._d50sigma.setEnabled(False) + def _propagate_lateral_update(self, index=None): + # Every change of the lateral contributions goes through the undo + # stack (push, undo, redo): the main window then reruns their + # checkers + self._propagate_update(key=Modules.LATERAL_CONTRIBUTION) + def d50_changed(self, value): self._undo_stack.push(SetMetaDataCommand(self._data, "d50", value)) diff --git a/src/View/LateralContribution/Window.py b/src/View/LateralContribution/Window.py index 62047596..b5e464c3 100644 --- a/src/View/LateralContribution/Window.py +++ b/src/View/LateralContribution/Window.py @@ -20,6 +20,7 @@ import logging from tools import trace, timer +from Modules import Modules from View.Tools.PamhyrWindow import PamhyrWindow from PyQt5 import QtWidgets @@ -159,6 +160,8 @@ class LateralContributionWindow(PamhyrWindow): ) def setup_connections(self): + self._undo_stack.indexChanged.connect(self._propagate_lateral_update) + if self._study.is_editable(): self.find(QAction, "action_import").triggered.connect( self.import_from_file) @@ -178,6 +181,12 @@ class LateralContributionWindow(PamhyrWindow): self._table[t].dataChanged\ .connect(self._set_current_reach) + def _propagate_lateral_update(self, index=None): + # Every change of the lateral contributions goes through the undo + # stack (push, undo, redo): the main window then reruns their + # checkers + self._propagate_update(key=Modules.LATERAL_CONTRIBUTION) + def current_tab(self): return self.find(QTabWidget, "tabWidget")\ .currentWidget()\