From d027946fb29908ca89e01a84d5b6da4cfb345f8b Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Wed, 22 Jul 2026 12:54:50 +0200 Subject: [PATCH] OutputRK: delete all references to this useless feature --- src/Checker/Adists.py | 52 ---- src/Model/OutputRKAdists/OutputRKAdists.py | 208 ---------------- .../OutputRKAdists/OutputRKListAdists.py | 59 ----- src/Model/River.py | 13 - src/Model/Scenario.py | 1 - src/Modules.py | 2 - src/Solver/AdisTS.py | 35 +-- src/View/MainWindow.py | 17 +- src/View/OutputRKAdisTS/Table.py | 229 ------------------ src/View/OutputRKAdisTS/Translate.py | 40 --- src/View/OutputRKAdisTS/UndoCommand.py | 155 ------------ src/View/OutputRKAdisTS/Window.py | 209 ---------------- src/View/ui/MainWindow.ui | 6 - src/View/ui/OutputRKAdisTS.ui | 126 ---------- src/lang/fr.ts | 44 ---- 15 files changed, 2 insertions(+), 1194 deletions(-) delete mode 100644 src/Checker/Adists.py delete mode 100644 src/Model/OutputRKAdists/OutputRKAdists.py delete mode 100644 src/Model/OutputRKAdists/OutputRKListAdists.py delete mode 100644 src/View/OutputRKAdisTS/Table.py delete mode 100644 src/View/OutputRKAdisTS/Translate.py delete mode 100644 src/View/OutputRKAdisTS/UndoCommand.py delete mode 100644 src/View/OutputRKAdisTS/Window.py delete mode 100644 src/View/ui/OutputRKAdisTS.ui diff --git a/src/Checker/Adists.py b/src/Checker/Adists.py deleted file mode 100644 index 68e37824..00000000 --- a/src/Checker/Adists.py +++ /dev/null @@ -1,52 +0,0 @@ -# Adists.py -- Pamhyr study checkers -# Copyright (C) 2023-2026 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 -*- - -import time -import logging -from functools import reduce - -from PyQt5.QtCore import QCoreApplication - -from Modules import Modules -from Checker.Checker import AbstractModelChecker, STATUS - -_translate = QCoreApplication.translate - -logger = logging.getLogger() - - -class AdistsOutputRKChecker(AbstractModelChecker): - def __init__(self): - super(AdistsOutputRKChecker, self).__init__() - - self._name = _translate("Checker", "AdisTS output RK checker") - self._description = _translate( - "Checker", "Check output RK" - ) - self._modules = Modules.OUTPUT_RK - - def run(self, study): - ok = True - nerror = 0 - self._summary = "ok" - self._status = STATUS.OK - - if not self.basic_check(study): - return False - - return ok diff --git a/src/Model/OutputRKAdists/OutputRKAdists.py b/src/Model/OutputRKAdists/OutputRKAdists.py deleted file mode 100644 index e428b8f7..00000000 --- a/src/Model/OutputRKAdists/OutputRKAdists.py +++ /dev/null @@ -1,208 +0,0 @@ -# OutputRKAdists.py -- Pamhyr -# Copyright (C) 2023-2026 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 -*- - -import logging - -from tools import ( - trace, timer, - old_pamhyr_date_to_timestamp, - date_iso_to_timestamp, - date_dmy_to_timestamp, -) - -from Model.Tools.PamhyrDB import SQLSubModel -from Model.Except import NotImplementedMethodeError -from Model.Scenario import Scenario - -logger = logging.getLogger() - - -class OutputRKAdists(SQLSubModel): - _sub_classes = [] - - def __init__(self, id: int = -1, reach=None, - rk=None, title: str = "", status=None, - owner_scenario=-1): - super(OutputRKAdists, self).__init__( - id=id, status=status, - owner_scenario=owner_scenario - ) - - self._reach = reach - self._rk = rk - self._title = str(title) - self._enabled = True - - @property - def reach(self): - return self._reach - - @reach.setter - def reach(self, reach_id): - self._reach = reach_id - self._status.modified() - - @property - def rk(self): - return self._rk - - @rk.setter - def rk(self, profile_id): - self._rk = profile_id - self._status.modified() - - @property - def title(self): - return self._title - - @title.setter - def title(self, title): - self._title = title - self._status.modified() - - @classmethod - def _db_create(cls, execute, ext=""): - execute(f""" - CREATE TABLE output_rk_adists{ext}( - {cls.create_db_add_pamhyr_id()}, - deleted BOOLEAN NOT NULL DEFAULT FALSE, - reach INTEGER NOT NULL, - rk REAL NOT NULL, - title TEXT NOT NULL, - {Scenario.create_db_add_scenario()}, - {Scenario.create_db_add_scenario_fk()}, - FOREIGN KEY(reach) REFERENCES river_reach(id) - ) - """) - - return cls._create_submodel(execute) - - @classmethod - def _db_update(cls, execute, version, data=None): - major, minor, release = version.strip().split(".") - - if major == "0" and int(minor) < 2: - if cls.is_table_exists(execute, "OutputRKAdists"): - cls._db_update_to_0_2_0(execute, data) - else: - cls._db_create(execute) - - return True - - @classmethod - def _db_update_to_0_2_0(cls, execute, data): - table = "OutputRKAdists" - table_new = "output_rk_adists" - reachs = data['id2pid']['river_reach'] - - cls.update_db_add_pamhyr_id(execute, table, data) - Scenario.update_db_add_scenario(execute, table) - - cls._db_create(execute, ext="_tmp") - - execute( - f"INSERT INTO {table_new}_tmp " + - "(pamhyr_id, reach, rk, title, scenario) " + - "SELECT pamhyr_id, reach, rk, title, scenario " + - f"FROM {table}" - ) - - execute(f"DROP TABLE {table}") - execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}") - - cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs) - - @classmethod - def _db_load(cls, execute, data=None): - new = [] - status = data['status'] - scenario = data["scenario"] - loaded = data['loaded_pid'] - - # reach = data["reach"] - # profile = data["profile"] - - if scenario is None: - return new - - table = execute( - "SELECT pamhyr_id, deleted, reach, rk, title, scenario " + - f"FROM output_rk_adists" - ) - - if table is not None: - for row in table: - it = iter(row) - - pid = next(it) - deleted = (next(it) == 1) - id_reach = next(it) - id_rk = next(it) - title = next(it) - owner_scenario = next(it) - - new_output = cls( - id=pid, reach=id_reach, - rk=id_rk, title=title, - status=status, - owner_scenario=owner_scenario, - ) - if deleted: - new_output.set_as_deleted() - - loaded.add(pid) - new.append(new_output) - - data["scenario"] = scenario.parent - new += cls._db_load(execute, data) - data["scenario"] = scenario - - return new - - def _db_save(self, execute, data=None): - if not self.must_be_saved(): - return True - - execute( - "DELETE FROM output_rk_adists " + - f"WHERE pamhyr_id = {self.id} " + - f"AND scenario = {self._status.scenario_id} " - ) - - execute( - "INSERT INTO " + - "output_rk_adists(pamhyr_id, deleted, " + - "reach, rk, title, scenario) " + - "VALUES (" + - f"{self.id}, {self._db_format(self.is_deleted())}, " + - f"{self._reach}, {self._rk}, " + - f"'{self._db_format(self._title)}', " + - f"{self._status.scenario_id}" + - ")" - ) - - return True - - @property - def enabled(self): - return self._enabled - - @enabled.setter - def enabled(self, enabled): - self._enabled = enabled - self._status.modified() diff --git a/src/Model/OutputRKAdists/OutputRKListAdists.py b/src/Model/OutputRKAdists/OutputRKListAdists.py deleted file mode 100644 index f4f11f82..00000000 --- a/src/Model/OutputRKAdists/OutputRKListAdists.py +++ /dev/null @@ -1,59 +0,0 @@ -# OutputRKListAdists.py -- Pamhyr -# Copyright (C) 2024-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 tools import trace, timer - -from Model.Except import NotImplementedMethodeError -from Model.Tools.PamhyrListExt import PamhyrModelList -from Model.OutputRKAdists.OutputRKAdists import OutputRKAdists - - -class OutputRKAdistsList(PamhyrModelList): - _sub_classes = [OutputRKAdists] - - @classmethod - def _db_load(cls, execute, data=None): - new = cls(status=data["status"]) - - new._lst = OutputRKAdists._db_load(execute, data) - - return new - - def _db_save(self, execute, data=None): - ok = True - - # Delete previous data - execute( - "DELETE FROM output_rk_adists " + - f"WHERE scenario = {self._status.scenario_id}" - ) - - for sl in self._lst: - ok &= sl._db_save(execute, data) - - return ok - - @property - def OutputRK_List(self): - return self.lst - - def new(self, lst, index): - n = OutputRKAdists(status=self._status) - self._lst.insert(index, n) - self._status.modified() - return n diff --git a/src/Model/River.py b/src/Model/River.py index becc5e7c..882a844f 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -49,7 +49,6 @@ from Model.REPLine.REPLineList import REPLineList from Solver.Solvers import solver_type_list -from Model.OutputRKAdists.OutputRKListAdists import OutputRKAdistsList from Model.Pollutants.PollutantsList import PollutantsList from Model.InitialConditionsAdisTS.InitialConditionsAdisTSList \ import InitialConditionsAdisTSList @@ -478,7 +477,6 @@ class River(Graph): HydraulicStructureList, AddFileList, REPLineList, - OutputRKAdistsList, PollutantsList, InitialConditionsAdisTSList, BoundaryConditionsAdisTSList, @@ -515,7 +513,6 @@ class River(Graph): ) self._additional_files = AddFileList(status=self._status) self._rep_lines = REPLineList(status=self._status) - self._Output_rk_adists = OutputRKAdistsList(status=self._status) self._Pollutants = PollutantsList(status=self._status) self._InitialConditionsAdisTS = InitialConditionsAdisTSList( status=self._status) @@ -630,10 +627,6 @@ class River(Graph): new._Pollutants = PollutantsList._db_load(execute, data) - new._Output_rk_adists = OutputRKAdistsList._db_load( - execute, data - ) - new._InitialConditionsAdisTS = InitialConditionsAdisTSList._db_load( execute, data) @@ -682,7 +675,6 @@ class River(Graph): for solver in self._parameters: objs.append(self._parameters[solver]) - objs.append(self._Output_rk_adists) objs.append(self._Pollutants) objs.append(self._InitialConditionsAdisTS) objs.append(self._BoundaryConditionsAdisTS) @@ -766,7 +758,6 @@ class River(Graph): self._hydraulic_structures, self._additional_files, self._rep_lines, - self._Output_rk_adists, self._Pollutants, self._InitialConditionsAdisTS, self._BoundaryConditionsAdisTS, @@ -880,10 +871,6 @@ Last export at: @date.""" def parameters(self): return self._parameters - @property - def Output_rk_adists(self): - return self._Output_rk_adists - @property def Pollutants(self): return self._Pollutants diff --git a/src/Model/Scenario.py b/src/Model/Scenario.py index b3a3aa57..f6d66887 100644 --- a/src/Model/Scenario.py +++ b/src/Model/Scenario.py @@ -32,7 +32,6 @@ class Scenario(SQLSubModel): tables_with_deleted_column = [ # Adists - "output_rk_adists", "boundary_condition_adists", "boundary_condition_data_adists", "lateral_contribution_adists", "lateral_contribution_data_adists", "initial_conditions_adists", "initial_conditions_adists_spec", diff --git a/src/Modules.py b/src/Modules.py index 860bc0cf..725c65c5 100644 --- a/src/Modules.py +++ b/src/Modules.py @@ -55,7 +55,6 @@ class Modules(IterableFlag): RESERVOIR = auto() SEDIMENT_LAYER = auto() ADDITIONAL_FILES = auto() - OUTPUT_RK = auto() GEOTIFF = auto() # Results @@ -81,7 +80,6 @@ class Modules(IterableFlag): cls.ADDITIONAL_FILES, cls.RESULTS, cls.WINDOW_LIST, - cls.OUTPUT_RK, cls.GEOTIFF ] diff --git a/src/Solver/AdisTS.py b/src/Solver/AdisTS.py index 55e18edf..2ab237dc 100644 --- a/src/Solver/AdisTS.py +++ b/src/Solver/AdisTS.py @@ -35,10 +35,6 @@ from Solver.CommandLine import CommandLineSolver from Model.Results.ResultsAdisTS import Results from Model.Results.River.River import River, Reach, Profile -from Checker.Adists import ( - AdistsOutputRKChecker, -) - from itertools import chain logger = logging.getLogger() @@ -90,11 +86,7 @@ class AdisTS(CommandLineSolver): @classmethod def checkers(cls): - lst = [ - AdistsOutputRKChecker(), - ] - - return lst + return [] ########## # Export # @@ -821,33 +813,8 @@ class AdisTSwc(AdisTS): if name != "command_line_arguments": f.write(f"{dict_names[name]} = {value}\n") - outputrks = study.river.Output_rk_adists.OutputRK_List - - for outputrk in outputrks: - self._export_outputrk(study, outputrk, f, qlog) - return files - def _export_outputrk(self, study, outputrk, f, qlog, name="0"): - if (outputrk.reach is None - or outputrk.rk is None - or outputrk.title is None): - return - - edges = study.river.enable_edges() - - id_edges = list(map(lambda x: x.id, edges)) - - id_reach = outputrk.reach - reach = next((x for x in edges if x.id == id_reach), None) - rk = outputrk.rk - title = outputrk.title - - if reach is None: - return - - f.write(f"output = {study.river.get_edge_id(reach)+1} {rk} {title}\n") - @timer def read_bin(self, study, repertory, results, qlog=None, name="0"): diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 1af3930d..38ca8770 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -107,7 +107,6 @@ from View.Results.WindowAdisTT import ResultsWindowAdisTT from View.Results.ReadingResultsDialog import ReadingResultsDialog from View.Debug.Window import ReplWindow, TimerWindow -from View.OutputRKAdisTS.Window import OutputRKAdisTSWindow from View.Pollutants.Window import PollutantsWindow from View.D90AdisTS.Window import D90AdisTSWindow from View.DIFAdisTS.Window import DIFAdisTSWindow @@ -173,7 +172,7 @@ define_model_action = [ "action_menu_results_last", "action_menu_open_results_from_file", "action_menu_compare_scenarios_results", "action_menu_boundary_conditions_sediment", - "action_menu_rep_additional_lines", "action_menu_output_rk", + "action_menu_rep_additional_lines", "action_menu_run_adists", "action_menu_pollutants", "action_menu_d90", "action_menu_dif", "action_menu_edit_geotiff", "action_menu_boundary_conditions_temperature", @@ -301,7 +300,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self.select_run_solver_adists, "action_menu_run_adistt": self.select_run_solver_adistt, - "action_menu_output_rk": self.open_output_rk_adists, "action_menu_config": self.open_configure, "action_menu_new": self.open_new_study, "action_menu_edit": self.open_edit_study, @@ -1166,19 +1164,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ) Pollutants.show() - def open_output_rk_adists(self): - if self.sub_window_exists( - OutputRKAdisTSWindow, - data=[self._study, None] - ): - return - - Output_RK_AdisTS = OutputRKAdisTSWindow( - study=self._study, - parent=self - ) - Output_RK_AdisTS.show() - def open_configure(self): """Open configure window diff --git a/src/View/OutputRKAdisTS/Table.py b/src/View/OutputRKAdisTS/Table.py deleted file mode 100644 index 0768ed4b..00000000 --- a/src/View/OutputRKAdisTS/Table.py +++ /dev/null @@ -1,229 +0,0 @@ -# Table.py -- Pamhyr -# Copyright (C) 2023-2026 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 -*- - -import logging -import traceback - -from tools import trace, timer - -from PyQt5.QtCore import ( - Qt, QVariant, QAbstractTableModel, - QCoreApplication, QModelIndex, pyqtSlot, - QRect, -) - -from PyQt5.QtWidgets import ( - QDialogButtonBox, QPushButton, QLineEdit, - QFileDialog, QTableView, QAbstractItemView, - QUndoStack, QShortcut, QAction, QItemDelegate, - QComboBox, -) - -from View.Tools.PamhyrTable import PamhyrTableModel - -from View.OutputRKAdisTS.UndoCommand import ( - SetTitleCommand, SetReachCommand, SetRKCommand, - SetEnabledCommand, AddCommand, DelCommand, -) - -from functools import reduce - -logger = logging.getLogger() - -_translate = QCoreApplication.translate - - -class ComboBoxDelegate(QItemDelegate): - def __init__(self, data=None, trad=None, parent=None, mode="reaches"): - super(ComboBoxDelegate, self).__init__(parent) - - self._data = data - self._trad = trad - self._mode = mode - - def createEditor(self, parent, option, index): - self.editor = QComboBox(parent) - - val = [] - if self._mode == "rk": - reach_id = self._data.Output_rk_adists \ - .get(index.row()) \ - .reach - - if reach_id is not None: - reach = next( - filter( - lambda edge: edge.id == reach_id, self._data.edges() - ) - ) - - val = list( - map( - lambda rk: str(rk), reach.reach.get_rk() - ) - ) - else: - val = list( - map( - lambda n: n.name, self._data.edges() - ) - ) - - self.editor.addItems( - [self._trad['not_associated']] + - val - ) - - self.editor.setCurrentText(str(index.data(Qt.DisplayRole))) - return self.editor - - def setEditorData(self, editor, index): - value = index.data(Qt.DisplayRole) - self.editor.currentTextChanged.connect(self.currentItemChanged) - - def setModelData(self, editor, model, index): - text = str(editor.currentText()) - model.setData(index, text) - editor.close() - editor.deleteLater() - - def updateEditorGeometry(self, editor, option, index): - r = QRect(option.rect) - if self.editor.windowFlags() & Qt.Popup: - if editor.parent() is not None: - r.setTopLeft(self.editor.parent().mapToGlobal(r.topLeft())) - editor.setGeometry(r) - - @pyqtSlot() - def currentItemChanged(self): - self.commitData.emit(self.sender()) - - -class TableModel(PamhyrTableModel): - def _setup_lst(self): - self._lst = self._data._Output_rk_adists - - def rowCount(self, parent): - return len(self._lst) - - def data(self, index, role): - if role != Qt.ItemDataRole.DisplayRole: - return QVariant() - - row = index.row() - column = index.column() - - if self._headers[column] == "title": - return self._lst.get(row).title - elif self._headers[column] == "reach": - n = self._lst.get(row).reach - if n is None: - return self._trad['not_associated'] - return next(filter( - lambda edge: edge.id == n, self._data.edges()) - ).name - elif self._headers[column] == "rk": - n = self._lst.get(row).rk - if n is None: - return self._trad['not_associated'] - return n - - return QVariant() - - def setData(self, index, value, role=Qt.EditRole): - if not index.isValid() or role != Qt.EditRole: - return False - - if self.is_same_data(index, value): - return False - - row = index.row() - column = index.column() - na = self._trad['not_associated'] - - try: - if self._headers[column] == "title": - self._undo.push( - SetTitleCommand( - self._lst, row, value - ) - ) - elif self._headers[column] == "reach": - if value == na: - value = None - - self._undo.push( - SetReachCommand( - self._lst, row, self._data.edge(value) - ) - ) - elif self._headers[column] == "rk": - if value == na: - value = None - - self._undo.push( - SetRKCommand( - self._lst, row, value - ) - ) - except Exception as e: - logger.info(e) - logger.debug(traceback.format_exc()) - - self.dataChanged.emit(index, index) - return True - - def add(self, row, parent=QModelIndex()): - self.beginInsertRows(parent, row, row - 1) - - self._undo.push( - AddCommand( - self._lst, row - ) - ) - - self.endInsertRows() - self.layoutChanged.emit() - - def delete(self, rows, parent=QModelIndex()): - self.beginRemoveRows(parent, rows[0], rows[-1]) - - self._undo.push( - DelCommand( - self._lst, rows - ) - ) - - self.endRemoveRows() - self.layoutChanged.emit() - - def enabled(self, row, enabled, parent=QModelIndex()): - self._undo.push( - SetEnabledCommand( - self._lst, row, enabled - ) - ) - self.layoutChanged.emit() - - def undo(self): - self._undo.undo() - self.layoutChanged.emit() - - def redo(self): - self._undo.redo() - self.layoutChanged.emit() diff --git a/src/View/OutputRKAdisTS/Translate.py b/src/View/OutputRKAdisTS/Translate.py deleted file mode 100644 index a5b7bfbb..00000000 --- a/src/View/OutputRKAdisTS/Translate.py +++ /dev/null @@ -1,40 +0,0 @@ -# translate.py -- Pamhyr -# Copyright (C) 2023-2026 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 PyQt5.QtCore import QCoreApplication - -from View.Translate import MainTranslate - -_translate = QCoreApplication.translate - - -class OutputRKAdisTSTranslate(MainTranslate): - def __init__(self): - super(OutputRKAdisTSTranslate, self).__init__() - - self._dict["Output RK"] = _translate( - "OutputRKAdisTS", "Output RK" - ) - - self._dict["x"] = _translate("OutputRKAdisTS", "X (m)") - - self._sub_dict["table_headers"] = { - "title": self._dict["title"], - "reach": self._dict["reach"], - "rk": self._dict["unit_rk"], - } diff --git a/src/View/OutputRKAdisTS/UndoCommand.py b/src/View/OutputRKAdisTS/UndoCommand.py deleted file mode 100644 index b6833bfb..00000000 --- a/src/View/OutputRKAdisTS/UndoCommand.py +++ /dev/null @@ -1,155 +0,0 @@ -# UndoCommand.py -- Pamhyr -# Copyright (C) 2023-2026 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 -*- - -import logging - -from copy import deepcopy -from tools import trace, timer - -from PyQt5.QtWidgets import ( - QMessageBox, QUndoCommand, QUndoStack, -) - -logger = logging.getLogger() - - -class SetTitleCommand(QUndoCommand): - def __init__(self, outputrk_lst, index, new_value): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - self._index = index - self._old = self._outputrk_lst.get(self._index).title - self._new = str(new_value) - - def undo(self): - self._outputrk_lst.get(self._index).title = self._old - - def redo(self): - self._outputrk_lst.get(self._index).title = self._new - - -class SetReachCommand(QUndoCommand): - def __init__(self, outputrk_lst, index, reach): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - self._index = index - self._old = self._outputrk_lst.get(self._index).reach - self._new = reach.id - - def undo(self): - i = self._outputrk_lst.get(self._index) - i.reach = self._old - - def redo(self): - i = self._outputrk_lst.get(self._index) - i.reach = self._new - - -class SetRKCommand(QUndoCommand): - def __init__(self, outputrk_lst, index, rk): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - self._index = index - self._old = self._outputrk_lst.get(self._index).rk - self._new = rk - - def undo(self): - self._outputrk_lst.get(self._index).rk = self._old - - def redo(self): - self._outputrk_lst.get(self._index).rk = self._new - - -class SetEnabledCommand(QUndoCommand): - def __init__(self, outputrk_lst, index, enabled): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - self._index = index - self._old = not enabled - self._new = enabled - - def undo(self): - self._outputrk_lst.get(self._index).enabled = self._old - - def redo(self): - self._outputrk_lst.get(self._index).enabled = self._new - - -class AddCommand(QUndoCommand): - def __init__(self, outputrk_lst, index): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - - self._index = index - self._new = None - - def undo(self): - self._outputrk_lst.delete_i([self._index]) - - def redo(self): - if self._new is None: - self._new = self._outputrk_lst.new(self._outputrk_lst, self._index) - else: - self._outputrk_lst.insert(self._index, self._new) - - -class DelCommand(QUndoCommand): - def __init__(self, outputrk_lst, rows): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - - self._rows = rows - - self._outputrk = [] - for row in rows: - self._outputrk.append((row, self._outputrk_lst.get(row))) - self._outputrk.sort() - - def undo(self): - for row, el in self._outputrk: - self._outputrk_lst.insert(row, el) - - def redo(self): - self._outputrk_lst.delete_i(self._rows) - - -class PasteCommand(QUndoCommand): - def __init__(self, outputrk_lst, row, outputrk): - QUndoCommand.__init__(self) - - self._outputrk_lst = outputrk_lst - - self._row = row - self._outputrk = deepcopy(outputrk) - self._outputrk.reverse() - - def undo(self): - self._outputrk_lst.delete_i( - self._tab, - range(self._row, self._row + len(self._outputrk)) - ) - - def redo(self): - for r in self._outputrk: - self._outputrk_lst.insert(self._row, r) diff --git a/src/View/OutputRKAdisTS/Window.py b/src/View/OutputRKAdisTS/Window.py deleted file mode 100644 index 54e79692..00000000 --- a/src/View/OutputRKAdisTS/Window.py +++ /dev/null @@ -1,209 +0,0 @@ -# Window.py -- Pamhyr -# Copyright (C) 2023-2026 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 -*- - -import logging - -from tools import timer, trace - -from View.Tools.PamhyrWindow import PamhyrWindow - -from PyQt5 import QtCore -from PyQt5.QtCore import ( - Qt, QVariant, QAbstractTableModel, QCoreApplication, - pyqtSlot, pyqtSignal, QItemSelectionModel, -) - -from PyQt5.QtWidgets import ( - QDialogButtonBox, QPushButton, QLineEdit, - QFileDialog, QTableView, QAbstractItemView, - QUndoStack, QShortcut, QAction, QItemDelegate, - QHeaderView, QDoubleSpinBox, QVBoxLayout, QCheckBox -) - -from View.Tools.Plot.PamhyrCanvas import MplCanvas -from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar - -from View.OutputRKAdisTS.Table import ( - TableModel, ComboBoxDelegate, -) - -from View.Network.GraphWidget import GraphWidget -from View.OutputRKAdisTS.Translate import OutputRKAdisTSTranslate - -logger = logging.getLogger() - - -class OutputRKAdisTSWindow(PamhyrWindow): - _pamhyr_ui = "OutputRKAdisTS" - _pamhyr_name = "Output RK" - - def __init__(self, study=None, config=None, parent=None): - trad = OutputRKAdisTSTranslate() - name = trad[self._pamhyr_name] + " - " + study.name - - super(OutputRKAdisTSWindow, self).__init__( - title=name, - study=study, - config=config, - trad=trad, - parent=parent - ) - - self._outputrk_lst = self._study.river._Output_rk_adists - - self.setup_table() - self.setup_checkbox() - self.setup_connections() - - self.update() - - def setup_table(self): - self._table = None - - self._delegate_reach = ComboBoxDelegate( - trad=self._trad, - data=self._study.river, - parent=self, - mode="reaches" - ) - self._delegate_rk = ComboBoxDelegate( - trad=self._trad, - data=self._study.river, - parent=self, - mode="rk" - ) - - table = self.find(QTableView, f"tableView") - self._table = TableModel( - table_view=table, - table_headers=self._trad.get_dict("table_headers"), - editable_headers=["title", "reach", "rk"], - delegates={ - "reach": self._delegate_reach, - "rk": self._delegate_rk, - }, - trad=self._trad, - data=self._study.river, - undo=self._undo_stack, - ) - - selectionModel = table.selectionModel() - index = table.model().index(0, 0) - - selectionModel.select( - index, - QItemSelectionModel.Rows | - QItemSelectionModel.ClearAndSelect | - QItemSelectionModel.Select - ) - table.scrollTo(index) - - def setup_checkbox(self): - self._checkbox = self.find(QCheckBox, f"checkBox") - self._set_checkbox_state() - - def setup_connections(self): - self.find(QAction, "action_add").triggered.connect(self.add) - self.find(QAction, "action_delete").triggered.connect(self.delete) - self._checkbox.clicked.connect(self._set_outputrk_state) - - table = self.find(QTableView, "tableView") - table.selectionModel()\ - .selectionChanged\ - .connect(self.update) - - self._table.dataChanged.connect(self.update) - self._table.layoutChanged.connect(self.update) - - def index_selected(self): - table = self.find(QTableView, "tableView") - r = table.selectionModel().selectedRows() - - if len(r) > 0: - return r[0] - else: - return None - - def index_selected_row(self): - table = self.find(QTableView, "tableView") - r = table.selectionModel().selectedRows() - - if len(r) > 0: - return r[0].row() - else: - return None - - def index_selected_rows(self): - table = self.find(QTableView, "tableView") - return list( - # Delete duplicate - set( - map( - lambda i: i.row(), - table.selectedIndexes() - ) - ) - ) - - def add(self): - rows = self.index_selected_rows() - if len(self._outputrk_lst) == 0 or len(rows) == 0: - self._table.add(0) - else: - self._table.add(rows[0]) - - def delete(self): - rows = self.index_selected_rows() - if len(rows) == 0: - return - - self._table.delete(rows) - - def _copy(self): - logger.info("TODO: copy") - - def _paste(self): - logger.info("TODO: paste") - - def _undo(self): - self._table.undo() - - def _redo(self): - self._table.redo() - - def _set_checkbox_state(self): - row = self.index_selected_row() - if row is None: - self._checkbox.setEnabled(False) - self._checkbox.setChecked(True) - else: - self._checkbox.setEnabled(True) - self._checkbox.setChecked(self._outputrk_lst.get(row).enabled) - - def _set_outputrk_state(self): - rows = self.index_selected_rows() - if len(rows) != 0: - for row in rows: - if row is not None: - self._table.enabled( - row, - self._checkbox.isChecked() - ) - - def update(self): - self._set_checkbox_state() diff --git a/src/View/ui/MainWindow.ui b/src/View/ui/MainWindow.ui index a97d2e8a..b5951ed8 100644 --- a/src/View/ui/MainWindow.ui +++ b/src/View/ui/MainWindow.ui @@ -225,7 +225,6 @@ AdisTS - @@ -766,11 +765,6 @@ Edit scenarios tree - - - Output RK - - diff --git a/src/View/ui/OutputRKAdisTS.ui b/src/View/ui/OutputRKAdisTS.ui deleted file mode 100644 index cb84fb2a..00000000 --- a/src/View/ui/OutputRKAdisTS.ui +++ /dev/null @@ -1,126 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 450 - - - - Hydraulic structures - - - - - - - Qt::Horizontal - - - - - - - - 300 - 0 - - - - - 0 - 0 - - - - - - - - 5 - - - - - Enable / Disable Output RK AdisTS - - - true - - - - - - - - - - Qt::Vertical - - - - - - - - - - - - - - - - 0 - 0 - 800 - 22 - - - - - - - toolBar - - - TopToolBarArea - - - false - - - - - - - - ressources/add.pngressources/add.png - - - Add - - - Add a new point - - - - - - ressources/del.pngressources/del.png - - - Delete - - - Delete points - - - - - - diff --git a/src/lang/fr.ts b/src/lang/fr.ts index 735ed188..9c6fa990 100644 --- a/src/lang/fr.ts +++ b/src/lang/fr.ts @@ -406,16 +406,6 @@ Cette fonctionnalité nécessite un bief muni d'une géométrie. Check if exists at least one reach exists Vérificateur si il exists au moins un bief - - - AdisTS output RK checker - Vérifie les PK de sortie AdisTS - - - - Check output RK - Vérifie les PK de sortie - Checklist @@ -2167,7 +2157,6 @@ Some profiles don't contain any point. Éditer les casiers - Hydraulic structures Ouvrages hydrauliques @@ -2386,16 +2375,6 @@ Some profiles don't contain any point. Enable / Disable basic hydraulic structure Activer/Désactiver l'ouvrage hydraulique élémentaire - - - Add a new point - Ajouter un nouveau point - - - - Delete points - Supprimer les points - Edit selected hydraulic structure @@ -2906,11 +2885,6 @@ Some profiles don't contain any point. AdisTS AdisTS - - - Output RK - Pk de sortie - Run AdisTS @@ -2936,11 +2910,6 @@ Some profiles don't contain any point. Open results AdisTS Ouvrir des résultats AdisTS - - - Enable / Disable Output RK AdisTS - Activer / Désactiver la sortie AdisTS - Add a new point in boundary condition or punctual contribution @@ -3388,19 +3357,6 @@ Some profiles don't contain any point. Sélectionner le profile - - OutputRKAdisTS - - - Output RK - Pk de sortie - - - - X (m) - X (m) - - Pamhyr