From 510bee115bf3a48ce79c826ad42b04bffa8a18a1 Mon Sep 17 00:00:00 2001 From: Youcef AOUAD <youcef.aouad@inrae.fr> Date: Thu, 20 Jun 2024 11:12:14 +0200 Subject: [PATCH] LCS -data --- .../LateralContributionAdisTS.py | 6 +- src/View/LateralContributionsAdisTS/Table.py | 55 +----- .../LateralContributionsAdisTS/UndoCommand.py | 169 +++--------------- src/View/LateralContributionsAdisTS/Window.py | 18 +- tests_cases/Enlargement/Enlargement.pamhyr | Bin 200704 -> 208896 bytes 5 files changed, 34 insertions(+), 214 deletions(-) diff --git a/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py b/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py index 6f5bb570..0088fe8b 100644 --- a/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py +++ b/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py @@ -127,15 +127,11 @@ class LateralContributionAdisTS(SQLSubModel): execute(f"DELETE FROM lateral_contribution_adists WHERE id = {self.id}") execute(f"DELETE FROM lateral_contribution_data_adists WHERE lc = {self.id}") - node = -1 - if self._node is not None: - node = self._node - sql = ( "INSERT INTO " + "lateral_contribution_adists(id, pollutant, edge, begin_kp, end_kp) " + "VALUES (" + - f"{self.id}, {self._pollutant}, " + + f"{self.id}, {self._pollutant}, {self.edge}, " + f"{self._begin_kp}, {self._end_kp}" + ")" ) diff --git a/src/View/LateralContributionsAdisTS/Table.py b/src/View/LateralContributionsAdisTS/Table.py index 5b7fbd31..3375cf5f 100644 --- a/src/View/LateralContributionsAdisTS/Table.py +++ b/src/View/LateralContributionsAdisTS/Table.py @@ -35,10 +35,9 @@ from PyQt5.QtWidgets import ( ) from View.LateralContributionsAdisTS.UndoCommand import ( - SetNameCommand, SetEdgeCommand, SetTypeCommand, + SetEdgeCommand, SetBeginCommand, SetEndCommand, - AddCommand, DelCommand, SortCommand, - MoveCommand, PasteCommand, DuplicateCommand, + AddCommand, DelCommand, ) from View.Tools.PamhyrTable import PamhyrTableModel @@ -156,19 +155,19 @@ class TableModel(PamhyrTableModel): if self._headers[column] == "edge": self._undo.push( SetEdgeCommand( - self._lst, self._tab, row, self._data.edge(value) + self._lcs_list, self._lst, row, self._data.edge(value).id ) ) elif self._headers[column] == "begin_kp": self._undo.push( SetBeginCommand( - self._lst, self._tab, row, value + self._lcs_list, self._lst, row, value ) ) elif self._headers[column] == "end_kp": self._undo.push( SetEndCommand( - self._lst, self._tab, row, value + self._lcs_list, self._lst, row, value ) ) except Exception as e: @@ -195,55 +194,13 @@ class TableModel(PamhyrTableModel): self._undo.push( DelCommand( - self._lst, self._tab, rows + self._lst, rows ) ) self.endRemoveRows() self.layoutChanged.emit() - def sort(self, _reverse, parent=QModelIndex()): - self.layoutAboutToBeChanged.emit() - self._undo.push( - SortCommand( - self._lst, self._tab, False - ) - ) - - self.layoutAboutToBeChanged.emit() - self.layoutChanged.emit() - def move_up(self, row, parent=QModelIndex()): - if row <= 0: - return - - target = row + 2 - - self.beginMoveRows(parent, row - 1, row - 1, parent, target) - - self._undo_stack.push( - MoveCommand( - self._lst, self._tab, "up", row - ) - ) - self.endMoveRows() - self.layoutChanged.emit() - - def move_down(self, index, parent=QModelIndex()): - if row > len(self._lst): - return - - target = row - - self.beginMoveRows(parent, row + 1, row + 1, parent, target) - - self._undo_stack.push( - MoveCommand( - self._lst, self._tab, "down", row - ) - ) - - self.endMoveRows() - self.layoutChanged.emit() diff --git a/src/View/LateralContributionsAdisTS/UndoCommand.py b/src/View/LateralContributionsAdisTS/UndoCommand.py index 707d61a1..3b4340ef 100644 --- a/src/View/LateralContributionsAdisTS/UndoCommand.py +++ b/src/View/LateralContributionsAdisTS/UndoCommand.py @@ -28,93 +28,55 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList import ( LateralContributionsAdisTSList ) - -class SetNameCommand(QUndoCommand): - def __init__(self, lcs, tab, index, new_value): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._index = index - self._old = self._lcs.get(self._tab, self._index).name - self._new = str(new_value) - - def undo(self): - self._lcs.get(self._tab, self._index).name = self._old - - def redo(self): - self._lcs.get(self._tab, self._index).name = self._new - - class SetBeginCommand(QUndoCommand): - def __init__(self, lcs, tab, index, new_value): + def __init__(self, lcs, lcs_lst, index, new_value): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab + self._lcs_lst = lcs_lst self._index = index - self._old = self._lcs.get(self._tab, self._index).begin_kp + self._old = self._lcs_lst[self._index].begin_kp self._new = float(new_value) def undo(self): - self._lcs.get(self._tab, self._index).begin_kp = float(self._old) + self._lcs_lst[self._index].begin_kp = float(self._old) def redo(self): - self._lcs.get(self._tab, self._index).begin_kp = float(self._new) + self._lcs_lst[self._index].begin_kp = float(self._new) class SetEndCommand(QUndoCommand): - def __init__(self, lcs, tab, index, new_value): + def __init__(self, lcs, lcs_lst, index, new_value): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab + self._lcs_lst = lcs_lst self._index = index - self._old = self._lcs.get(self._tab, self._index).end_kp + self._old = self._lcs_lst[self._index].end_kp self._new = float(new_value) def undo(self): - self._lcs.get(self._tab, self._index).end_kp = float(self._old) + self._lcs_lst[self._index].end_kp = float(self._old) def redo(self): - self._lcs.get(self._tab, self._index).end_kp = float(self._new) + self._lcs_lst[self._index].end_kp = float(self._new) class SetEdgeCommand(QUndoCommand): - def __init__(self, lcs, tab, index, edge): + def __init__(self, lcs, lcs_lst, index, edge): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab + self._lcs_lst = lcs_lst self._index = index - self._old = self._lcs.get(self._tab, self._index).edge + self._old = self._lcs_lst[self._index].edge self._new = edge def undo(self): - self._lcs.get(self._tab, self._index).edge = self._old + self._lcs_lst[self._index].edge = self._old def redo(self): - self._lcs.get(self._tab, self._index).edge = self._new - - -class SetTypeCommand(QUndoCommand): - def __init__(self, lcs, tab, index, _type): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._index = index - self._type = _type - self._old = self._lcs.get(self._tab, self._index) - self._new = self._lcs.get(self._tab, self._index)\ - .convert(self._type) - - def undo(self): - self._lcs.set(self._tab, self._index, self._old) - - def redo(self): - self._lcs.set(self._tab, self._index, self._new) - + self._lcs_lst[self._index].edge = self._new class AddCommand(QUndoCommand): def __init__(self, pollutant, lcs, lcs_lst, index): @@ -137,113 +99,22 @@ class AddCommand(QUndoCommand): class DelCommand(QUndoCommand): - def __init__(self, lcs, tab, rows): + def __init__(self, lcs, rows): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab self._rows = rows self._bc = [] for row in rows: - self._bc.append((row, self._lcs.get(self._tab, row))) + self._bc.append((row, self._lcs[row])) self._bc.sort() def undo(self): for row, el in self._bc: - self._lcs.insert(self._tab, row, el) - - def redo(self): - self._lcs.delete_i(self._tab, self._rows) - - -class SortCommand(QUndoCommand): - def __init__(self, lcs, tab, _reverse): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._reverse = _reverse - - self._old = self._lcs.get_tab(self._tab) - self._indexes = None - - def undo(self): - ll = self._lcs.get_tab(self._tab) - self._lcs.sort( - self._tab, - key=lambda x: self._indexes[ll.index(x)] - ) - - def redo(self): - self._lcs.sort( - self._tab, - reverse=self._reverse, - key=lambda x: x.name - ) - if self._indexes is None: - self._indexes = list( - map( - lambda p: self._old.index(p), - self._lcs.get_tab(self._tab) - ) - ) - self._old = None - - -class MoveCommand(QUndoCommand): - def __init__(self, lcs, tab, up, i): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._up = up == "up" - self._i = i - - def undo(self): - if self._up: - self._lcs.move_up(self._tab, self._i) - else: - self._lcs.move_down(self._tab, self._i) + self._lcs.insert(row, el) def redo(self): - if self._up: - self._lcs.move_up(self._tab, self._i) - else: - self._lcs.move_down(self._tab, self._i) - - -class PasteCommand(QUndoCommand): - def __init__(self, lcs, tab, row, bc): - QUndoCommand.__init__(self) + for row in self._rows: + del self._lcs[row] - self._lcs = lcs - self._tab = tab - self._row = row - self._bc = deepcopy(bc) - self._bc.reverse() - - def undo(self): - self._lcs.delete(self._tab, self._bc) - - def redo(self): - for bc in self._bc: - self._lcs.insert(self._tab, self._row, bc) - - -class DuplicateCommand(QUndoCommand): - def __init__(self, lcs, tab, rows, bc): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._rows = rows - self._bc = deepcopy(bc) - self._bc.reverse() - - def undo(self): - self._lcs.delete(self._tab, self._bc) - - def redo(self): - for bc in self._lcs: - self._lcs.insert(self._tab, self._rows[0], bc) diff --git a/src/View/LateralContributionsAdisTS/Window.py b/src/View/LateralContributionsAdisTS/Window.py index 69c3e0ca..3f6a9988 100644 --- a/src/View/LateralContributionsAdisTS/Window.py +++ b/src/View/LateralContributionsAdisTS/Window.py @@ -39,12 +39,6 @@ from PyQt5.QtWidgets import ( QComboBox, QVBoxLayout, QHeaderView, QTabWidget, ) -from View.LateralContributionsAdisTS.UndoCommand import ( - SetNameCommand, SetEdgeCommand, SetTypeCommand, - AddCommand, DelCommand, SortCommand, - MoveCommand, PasteCommand, DuplicateCommand, -) - from View.LateralContributionsAdisTS.Table import ( TableModel, ComboBoxDelegate ) @@ -179,16 +173,18 @@ class LateralContributionAdisTSWindow(PamhyrWindow): tab = "liquid" if len(rows) > 0: - edge = self._study.river\ + edge_id = self._study.river\ .lateral_contributions_adists.lst[rows[0]]\ .edge - if edge: + + if edge_id: + edge = next(filter(lambda e: e.id == edge_id, self._study.river.edges())) data = edge.reach - lc = self._lcs.get(tab, rows[0]) + lc = self._lcs.lst[rows[0]] highlight = (lc.begin_kp, lc.end_kp) - for delegate in self._delegate_kp: - delegate.data = edge + for delegate in self._delegate_kp: + delegate.data = edge self.plot = PlotXY( canvas=self.canvas, diff --git a/tests_cases/Enlargement/Enlargement.pamhyr b/tests_cases/Enlargement/Enlargement.pamhyr index 98658da7f9e9fecc5edd2bd0b851a201b9e5f636..6dc4a66a947b1dc12e17f996a08f4142ebdcc3bc 100644 GIT binary patch delta 480 zcmZozz|-)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