From 704130966e6f21e1d606f8a8ce4c9de2fbbfdfd3 Mon Sep 17 00:00:00 2001
From: Youcef AOUAD <youcef.aouad@inrae.fr>
Date: Tue, 18 Jun 2024 15:40:06 +0200
Subject: [PATCH] BC AdisTS Complete

---
 .../BoundaryConditionAdisTS.py                |  16 +-
 .../BoundaryConditionsAdisTSList.py           |   1 +
 .../BoundaryConditionsAdisTS/Edit/Plot.py     |   1 +
 .../BoundaryConditionsAdisTS/Edit/Table.py    |  80 +---------
 .../Edit/UndoCommand.py                       | 122 +++------------
 .../BoundaryConditionsAdisTS/Edit/Window.py   | 144 +++---------------
 .../Edit/translate.py                         |  11 +-
 src/View/BoundaryConditionsAdisTS/Table.py    |   9 +-
 .../BoundaryConditionsAdisTS/UndoCommand.py   |  90 +----------
 src/View/BoundaryConditionsAdisTS/Window.py   |  35 +----
 src/View/ui/BoundaryConditionsAdisTS.ui       |  55 +++----
 src/View/ui/EditBoundaryConditionsAdisTS.ui   | 112 ++++++++++++++
 tests_cases/Enlargement/Enlargement.pamhyr    | Bin 192512 -> 200704 bytes
 13 files changed, 198 insertions(+), 478 deletions(-)
 create mode 100644 src/View/ui/EditBoundaryConditionsAdisTS.ui

diff --git a/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py b/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py
index 4176350c..68a91ae7 100644
--- a/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py
+++ b/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py
@@ -105,7 +105,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
 
                 bc.node = None
                 if row[3] != -1:
-                    bc.node = next(filter(lambda n: n.id == row[3], data["nodes"]))
+                    bc.node = next(filter(lambda n: n.id == row[3], data["nodes"])).id
 
                 values = execute(
                     "SELECT data0, data1 FROM boundary_condition_data_adists " +
@@ -114,8 +114,8 @@ class BoundaryConditionAdisTS(SQLSubModel):
 
                 # Write data
                 for v in values:
-                    data0 = bc._types[0](v[1])
-                    data1 = bc._types[1](v[2])
+                    data0 = bc._types[0](v[0])
+                    data1 = bc._types[1](v[1])
                     # Replace data at pos ind
                     bc._data.append((data0, data1))
 
@@ -124,20 +124,19 @@ class BoundaryConditionAdisTS(SQLSubModel):
         return new
 
     def _db_save(self, execute, data=None):
-        pollutant_id = data["pollutant_id"]
 
         execute(f"DELETE FROM boundary_condition_adists WHERE id = {self.id}")
         execute(f"DELETE FROM boundary_condition_data_adists WHERE bc = {self.id}")
 
         node = -1
         if self._node is not None:
-            node = self._node.id
+            node = self._node
 
         sql = (
             "INSERT INTO " +
             "boundary_condition_adists(id, pollutant, type, node) " +
             "VALUES (" +
-            f"{self.id}, {pollutant_id}, " +
+            f"{self.id}, {self._pollutant}, " +
             f"'{self._db_format(self._type)}', {node}" +
             ")"
         )
@@ -188,6 +187,11 @@ class BoundaryConditionAdisTS(SQLSubModel):
     def header(self):
         return self._header.copy()
 
+    @header.setter
+    def header(self, header):
+        self._header = header
+        self._status.modified()
+
     @property
     def pollutant(self):
         return self._pollutant
diff --git a/src/Model/BoundaryConditionsAdisTS/BoundaryConditionsAdisTSList.py b/src/Model/BoundaryConditionsAdisTS/BoundaryConditionsAdisTSList.py
index 4246905f..613b70e6 100644
--- a/src/Model/BoundaryConditionsAdisTS/BoundaryConditionsAdisTSList.py
+++ b/src/Model/BoundaryConditionsAdisTS/BoundaryConditionsAdisTSList.py
@@ -44,6 +44,7 @@ class BoundaryConditionsAdisTSList(PamhyrModelList):
 
     def _db_save(self, execute, data=None):
         execute("DELETE FROM boundary_condition_adists")
+        execute("DELETE FROM boundary_condition_data_adists")
 
         if data is None:
             data = {}
diff --git a/src/View/BoundaryConditionsAdisTS/Edit/Plot.py b/src/View/BoundaryConditionsAdisTS/Edit/Plot.py
index 5405a501..8ecc288d 100644
--- a/src/View/BoundaryConditionsAdisTS/Edit/Plot.py
+++ b/src/View/BoundaryConditionsAdisTS/Edit/Plot.py
@@ -47,6 +47,7 @@ class Plot(PamhyrPlot):
         self._table_headers = self._trad.get_dict("table_headers")
 
         header = self.data.header
+
         self.label_x = self._table_headers[header[0]]
         self.label_y = self._table_headers[header[1]]
 
diff --git a/src/View/BoundaryConditionsAdisTS/Edit/Table.py b/src/View/BoundaryConditionsAdisTS/Edit/Table.py
index 287a8fe4..729f8420 100644
--- a/src/View/BoundaryConditionsAdisTS/Edit/Table.py
+++ b/src/View/BoundaryConditionsAdisTS/Edit/Table.py
@@ -40,14 +40,8 @@ from PyQt5.QtWidgets import (
     QTimeEdit, QDateTimeEdit, QItemDelegate,
 )
 
-from Model.BoundaryCondition.BoundaryConditionTypes import (
-    NotDefined, PonctualContribution,
-    TimeOverZ, TimeOverDischarge, ZOverDischarge
-)
-
-from View.BoundaryCondition.Edit.UndoCommand import (
-    SetDataCommand, AddCommand, DelCommand,
-    SortCommand, MoveCommand, PasteCommand,
+from View.BoundaryConditionsAdisTS.Edit.UndoCommand import (
+    AddCommand, DelCommand, SetDataCommand,
 )
 
 _translate = QCoreApplication.translate
@@ -69,8 +63,8 @@ class TableModel(PamhyrTableModel):
         value = QVariant()
 
         if 0 <= column < 2:
-            v = self._data.get_i(row)[column]
-            if self._data.get_type_column(column) == float:
+            v = self._data._data[row][column]
+            if self._data._types[column] == float:
                 value = f"{v:.4f}"
             elif self._data.header[column] == "time":
                 if self._opt_data == "time":
@@ -125,69 +119,3 @@ class TableModel(PamhyrTableModel):
 
         self.endRemoveRows()
 
-    def sort(self, _reverse, parent=QModelIndex()):
-        self.layoutAboutToBeChanged.emit()
-
-        self._undo.push(
-            SortCommand(
-                self._data, _reverse
-            )
-        )
-
-        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._data, "up", row
-            )
-        )
-
-        self.endMoveRows()
-        self.layoutChanged.emit()
-
-    def move_down(self, index, parent=QModelIndex()):
-        if row > len(self._data):
-            return
-
-        target = row
-
-        self.beginMoveRows(parent, row + 1, row + 1, parent, target)
-
-        self._undo_stack.push(
-            MoveCommand(
-                self._data, "down", row
-            )
-        )
-
-        self.endMoveRows()
-        self.layoutChanged.emit()
-
-    def paste(self, row, header, data):
-        if len(data) == 0:
-            return
-
-        self.layoutAboutToBeChanged.emit()
-
-        self._undo.push(
-            PasteCommand(
-                self._data, row,
-                list(
-                    map(
-                        lambda d: self._data.new_from_data(header, d),
-                        data
-                    )
-                )
-            )
-        )
-
-        self.layoutAboutToBeChanged.emit()
-        self.layoutChanged.emit()
diff --git a/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py b/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py
index 02e0a48e..dbca067e 100644
--- a/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py
+++ b/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py
@@ -25,7 +25,7 @@ from PyQt5.QtWidgets import (
     QMessageBox, QUndoCommand, QUndoStack,
 )
 
-from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
+from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
 
 logger = logging.getLogger()
 
@@ -37,42 +37,21 @@ class SetDataCommand(QUndoCommand):
         self._data = data
         self._index = index
         self._column = column
-        self._old = self._data.get_i(self._index)[self._column]
-        _type = self._data.get_type_column(self._column)
+        self._old = self._data._data[self._index][self._column]
+        _type = self._data._types[self._column]
         self._new = _type(new_value)
 
     def undo(self):
-        self._data._set_i_c_v(self._index, self._column, self._old)
-
-    def redo(self):
-        self._data._set_i_c_v(self._index, self._column, self._new)
-
-
-class SetMetaDataCommand(QUndoCommand):
-    def __init__(self, data, column, new_value):
-        QUndoCommand.__init__(self)
-
-        self._data = data
-        self._column = column
-        if self._column == "d50":
-            self._old = self._data.d50
-        elif self._column == "sigma":
-            self._old = self._data.sigma
-
-        self._new = float(new_value)
-
-    def undo(self):
-        if self._column == "d50":
-            self._data.d50 = self._old
-        elif self._column == "sigma":
-            self._data.sigma = self._old
+        if self._column == 0:
+            self._data._data[self._index] = (self._old,self._data._data[self._index][1])
+        else:
+            self._data._data[self._index] = (self._data._data[self._index][1], self._old)
 
     def redo(self):
-        if self._column == "d50":
-            self._data.d50 = self._new
-        elif self._column == "sigma":
-            self._data.sigma = self._new
-
+        if self._column == 0:
+            self._data._data[self._index] = (self._new,self._data._data[self._index][1])
+        else:
+            self._data._data[self._index] = (self._data._data[self._index][1], self._new)
 
 class AddCommand(QUndoCommand):
     def __init__(self, data, index):
@@ -83,14 +62,13 @@ class AddCommand(QUndoCommand):
         self._new = None
 
     def undo(self):
-        self._data.delete_i([self._index])
+        del self._data._data[self._index]
 
     def redo(self):
         if self._new is None:
-            self._new = self._data.add(self._index)
+            self._new = self._data._data.insert(self._index, (self._data._types[0](0), self._data._types[1](0.0)))
         else:
-            self._data.insert(self._index, self._new)
-
+            self._data._data.insert(self._index, self._new)
 
 class DelCommand(QUndoCommand):
     def __init__(self, data, rows):
@@ -101,7 +79,7 @@ class DelCommand(QUndoCommand):
 
         self._bc = []
         for row in rows:
-            self._bc.append((row, self._data.get_i(row)))
+            self._bc.append((row, self._data._data[row]))
         self._bc.sort()
 
     def undo(self):
@@ -109,75 +87,9 @@ class DelCommand(QUndoCommand):
             self._data.insert(row, el)
 
     def redo(self):
-        self._data.delete_i(self._rows)
+        for row in self._rows:
+            del self._data._data[row]
 
 
-class SortCommand(QUndoCommand):
-    def __init__(self, data, _reverse):
-        QUndoCommand.__init__(self)
-
-        self._data = data
-        self._reverse = _reverse
 
-        self._old = self._data.data
-        self._indexes = None
-
-    def undo(self):
-        ll = self._data.data
-        self._data.sort(
-            key=lambda x: self._indexes[ll.index(x)]
-        )
 
-    def redo(self):
-        self._data.sort(
-            _reverse=self._reverse,
-            key=lambda x: x[0]
-        )
-        if self._indexes is None:
-            self._indexes = list(
-                map(
-                    lambda p: self._old.index(p),
-                    self._data.data
-                )
-            )
-            self._old = None
-
-
-class MoveCommand(QUndoCommand):
-    def __init__(self, data, up, i):
-        QUndoCommand.__init__(self)
-
-        self._data = data
-        self._up = up == "up"
-        self._i = i
-
-    def undo(self):
-        if self._up:
-            self._data.move_up(self._i)
-        else:
-            self._data.move_down(self._i)
-
-    def redo(self):
-        if self._up:
-            self._data.move_up(self._i)
-        else:
-            self._data.move_down(self._i)
-
-
-class PasteCommand(QUndoCommand):
-    def __init__(self, data, row, bcs):
-        QUndoCommand.__init__(self)
-
-        self._data = data
-        self._row = row
-        self._bcs = bcs
-        self._bcs.reverse()
-
-    def undo(self):
-        self._data.delete_i(
-            range(self._row, self._row + len(self._bcs))
-        )
-
-    def redo(self):
-        for bc in self._bcs:
-            self._data.insert(self._row, bc)
diff --git a/src/View/BoundaryConditionsAdisTS/Edit/Window.py b/src/View/BoundaryConditionsAdisTS/Edit/Window.py
index faf41896..43223b84 100644
--- a/src/View/BoundaryConditionsAdisTS/Edit/Window.py
+++ b/src/View/BoundaryConditionsAdisTS/Edit/Window.py
@@ -1,4 +1,4 @@
-# Window.py -- Pamhyr
+ # Window.py -- Pamhyr
 # Copyright (C) 2023-2024  INRAE
 #
 # This program is free software: you can redistribute it and/or modify
@@ -44,76 +44,23 @@ from PyQt5.QtWidgets import (
 from View.Tools.Plot.PamhyrCanvas import MplCanvas
 from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
 
-from View.BoundaryCondition.Edit.translate import BCETranslate
-from View.BoundaryCondition.Edit.UndoCommand import SetMetaDataCommand
-from View.BoundaryCondition.Edit.Table import TableModel
-from View.BoundaryCondition.Edit.Plot import Plot
+from View.BoundaryConditionsAdisTS.Edit.translate import BCETranslate
+from View.BoundaryConditionsAdisTS.Edit.Table import TableModel
+from View.BoundaryConditionsAdisTS.Edit.Plot import Plot
 
 _translate = QCoreApplication.translate
 
 logger = logging.getLogger()
 
-
-class WD50Sigma(PamhyrWidget):
-    _pamhyr_ui = "d50sigma"
-
-    d50Changed = pyqtSignal(float)
-    sigmaChanged = pyqtSignal(float)
-
-    def __init__(self, parent=None):
-        super(WD50Sigma, self).__init__(
-            parent=parent
-        )
-
-        self.spinBox_d50 = self.find(QDoubleSpinBox, "doubleSpinBox_d50")
-        self.spinBox_sigma = self.find(QDoubleSpinBox, "doubleSpinBox_sigma")
-
-        self.spinBox_d50.valueChanged.connect(self.valueChangedD50)
-        self.spinBox_sigma.valueChanged.connect(self.valueChangedSigma)
-
-    def set_d50(self, d50):
-        self.spinBox_d50.valueChanged.disconnect(self.valueChangedD50)
-        self.spinBox_d50.setValue(float(d50))
-        self.spinBox_d50.valueChanged.connect(self.valueChangedD50)
-
-    def get_d50(self):
-        return float(self.spinBox_d50.value())
-
-    def set_sigma(self, sigma):
-        self.spinBox_sigma.valueChanged.disconnect(self.valueChangedSigma)
-        self.spinBox_sigma.setValue(float(sigma))
-        self.spinBox_sigma.valueChanged.connect(self.valueChangedSigma)
-
-    def get_sigma(self):
-        return float(self.spinBox_sigma.value())
-
-    @QtCore.pyqtSlot(float)
-    def valueChangedD50(self, value):
-        self.d50Changed.emit(value)
-
-    @QtCore.pyqtSlot(float)
-    def valueChangedSigma(self, value):
-        self.sigmaChanged.emit(value)
-
-
 class EditBoundaryConditionWindow(PamhyrWindow):
-    _pamhyr_ui = "EditBoundaryConditions"
-    _pamhyr_name = "Edit Boundary Conditions"
+    _pamhyr_ui = "EditBoundaryConditionsAdisTS"
+    _pamhyr_name = "Edit Boundary Conditions AdisTS"
 
     def __init__(self, data=None, study=None, config=None, parent=None):
         self._data = data
         trad = BCETranslate()
-        self._long_types = trad.get_dict("long_types")
 
         name = trad[self._pamhyr_name]
-        if self._data is not None:
-            node_name = (self._data.node.name if self._data.node is not None
-                         else trad['not_associated'])
-            name += (
-                f" - {study.name} " +
-                f" - {self._data.name} ({self._data.id}) " +
-                f"({self._long_types[self._data.bctype]} - {node_name})"
-            )
 
         super(EditBoundaryConditionWindow, self).__init__(
             title=name,
@@ -123,25 +70,26 @@ class EditBoundaryConditionWindow(PamhyrWindow):
             parent=parent
         )
 
+        if self._data is not None:
+            n = self._data.node
+            node_name = next(filter(lambda x: x.id == n, self._study.river._nodes)).name
+            name += (
+                f" - {study.name} " +
+                f"({node_name})"
+            )
+
         self._hash_data.append(data)
 
         self.setup_table()
         self.setup_plot()
-        self.setup_data()
         self.setup_connections()
 
-    def setup_data(self):
-        self._is_solid = self._data.bctype == "SL"
-
-        if self._is_solid:
-            layout = self.find(QVBoxLayout, "verticalLayout_table")
-            self._d50sigma = WD50Sigma(parent=self)
-            layout.addWidget(self._d50sigma)
-
-            self._d50sigma.set_d50(self._data.d50)
-            self._d50sigma.set_sigma(self._data.sigma)
-
     def setup_table(self):
+        if self._data.type == "Concentration":
+            self._data.header = ["time", "concentration"]
+        else:
+            self._data.header = ["time", "rate"]
+
         headers = {}
         table_headers = self._trad.get_dict("table_headers")
         for h in self._data.header:
@@ -192,35 +140,9 @@ class EditBoundaryConditionWindow(PamhyrWindow):
     def setup_connections(self):
         self.find(QAction, "action_add").triggered.connect(self.add)
         self.find(QAction, "action_del").triggered.connect(self.delete)
-        self.find(QAction, "action_sort").triggered.connect(self.sort)
 
         self._table.dataChanged.connect(self.update)
 
-        if self._is_solid:
-            self._d50sigma.d50Changed.connect(self.d50_changed)
-            self._d50sigma.sigmaChanged.connect(self.sigma_changed)
-
-    def d50_changed(self, value):
-        self._undo_stack.push(
-            SetMetaDataCommand(
-                self._data,
-                "d50", value
-            )
-        )
-
-    def sigma_changed(self, value):
-        self._undo_stack.push(
-            SetMetaDataCommand(
-                self._data,
-                "sigma", value
-            )
-        )
-
-    def widget_update(self):
-        if self._is_solid:
-            self._d50sigma.set_d50(self._data.d50)
-            self._d50sigma.set_sigma(self._data.sigma)
-
     def update(self):
         self.plot.update()
 
@@ -263,16 +185,6 @@ class EditBoundaryConditionWindow(PamhyrWindow):
         self._table.sort(False)
         self.plot.update()
 
-    def move_up(self):
-        row = self.index_selected_row()
-        self._table.move_up(row)
-        self.plot.update()
-
-    def move_down(self):
-        row = self.index_selected_row()
-        self._table.move_down(row)
-        self.plot.update()
-
     def _copy(self):
         rows = self.index_selected_rows()
 
@@ -285,28 +197,10 @@ class EditBoundaryConditionWindow(PamhyrWindow):
 
         self.copyTableIntoClipboard(table)
 
-    def _paste(self):
-        header, data = self.parseClipboardTable()
-
-        logger.debug(f"paste: h:{header}, d:{data}")
-
-        if len(data) == 0:
-            return
-
-        row = 0
-        rows = self.index_selected_rows()
-        if len(rows) != 0:
-            row = rows[0]
-
-        self._table.paste(row, header, data)
-        self.plot.update()
-
     def _undo(self):
         self._table.undo()
         self.plot.update()
-        self.widget_update()
 
     def _redo(self):
         self._table.redo()
         self.plot.update()
-        self.widget_update()
diff --git a/src/View/BoundaryConditionsAdisTS/Edit/translate.py b/src/View/BoundaryConditionsAdisTS/Edit/translate.py
index 9d835550..0375adbb 100644
--- a/src/View/BoundaryConditionsAdisTS/Edit/translate.py
+++ b/src/View/BoundaryConditionsAdisTS/Edit/translate.py
@@ -29,16 +29,13 @@ class BCETranslate(BCTranslate):
     def __init__(self):
         super(BCETranslate, self).__init__()
 
-        self._dict["Edit Boundary Conditions"] = _translate(
-            "BoundaryCondition", "Edit boundary conditions"
+        self._dict["Edit Boundary Conditions AdisTS"] = _translate(
+            "BoundaryConditionAdisTS", "Edit boundary conditions AdisTS"
         )
 
         self._sub_dict["table_headers"] = {
-            "x": _translate("BoundaryCondition", "X"),
-            "y": _translate("BoundaryCondition", "Y"),
             "time": self._dict["time"],
             "date": self._dict["date"],
-            "discharge": self._dict["unit_discharge"],
-            "z": self._dict["unit_elevation"],
-            "solid": _translate("BoundaryCondition", "Solid (kg/s)"),
+            "rate": _translate("BoundaryConditionAdisTS", "Rate"),
+            "concentration": _translate("BoundaryConditionAdisTS", "Concentration"),
         }
diff --git a/src/View/BoundaryConditionsAdisTS/Table.py b/src/View/BoundaryConditionsAdisTS/Table.py
index d2b08caf..4a71d3cf 100644
--- a/src/View/BoundaryConditionsAdisTS/Table.py
+++ b/src/View/BoundaryConditionsAdisTS/Table.py
@@ -43,8 +43,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
 
 from View.BoundaryConditionsAdisTS.UndoCommand import (
     SetNodeCommand, SetTypeCommand,
-    AddCommand, DelCommand, SortCommand,
-    MoveCommand, PasteCommand,
+    AddCommand, DelCommand,
 )
 from View.BoundaryCondition.translate import BC_types
 
@@ -111,7 +110,6 @@ class TableModel(PamhyrTableModel):
         self._trad = trad
         self._bc_list = bc_list
         self._pollutant = pollutant
-        print("pollutant : ", self._pollutant)
 
         super(TableModel, self).__init__(trad=trad, **kwargs)
 
@@ -135,17 +133,15 @@ class TableModel(PamhyrTableModel):
         column = index.column()
 
         if self._headers[column] == "type":
-            #n = self._lst[row].type
             n = data[row].type
             if n is None or n == "":
                 return self._trad["not_associated"]
             return n
         elif self._headers[column] == "node":
-            #n = self._lst[row].node
             n = data[row].node
             if n is None:
                 return self._trad["not_associated"]
-            return n
+            return next(filter(lambda x: x.id == n, self._data._nodes)).name
 
         return QVariant()
 
@@ -169,6 +165,7 @@ class TableModel(PamhyrTableModel):
                         self._lst, row, self._data.node(value)
                     )
                 )
+                print(value, self._data.node(value).id)
         except Exception as e:
             logger.info(e)
             logger.debug(traceback.format_exc())
diff --git a/src/View/BoundaryConditionsAdisTS/UndoCommand.py b/src/View/BoundaryConditionsAdisTS/UndoCommand.py
index 98fff994..dd39d42a 100644
--- a/src/View/BoundaryConditionsAdisTS/UndoCommand.py
+++ b/src/View/BoundaryConditionsAdisTS/UndoCommand.py
@@ -56,7 +56,6 @@ class SetTypeCommand(QUndoCommand):
 
     def redo(self):
         self._bcs[self._index].type = self._new
-        print("type : ", self._old, self._new, self._bcs[self._index].type)
 
 class AddCommand(QUndoCommand):
     def __init__(self, pollutant, bcs_list, bcs, index):
@@ -74,106 +73,27 @@ class AddCommand(QUndoCommand):
     def redo(self):
         if self._new is None:
             self._new = self._bc_list.new(self._index, self._pollutant)
-            print(self._new.pollutant)
-            print(len(self._bc_list))
-            print(len(self._bcs))
         else:
             self._bcs.insert(self._index, self._new)
 
 
 class DelCommand(QUndoCommand):
-    def __init__(self, bcs, tab, rows):
+    def __init__(self, bcs, rows):
         QUndoCommand.__init__(self)
 
         self._bcs = bcs
-        self._tab = tab
         self._rows = rows
 
         self._bc = []
         for row in rows:
-            self._bc.append((row, self._bcs.get(self._tab, row)))
+            self._bc.append((row, self._bcs[row]))
         self._bc.sort()
 
     def undo(self):
         for row, el in self._bc:
-            self._bcs.insert(self._tab, row, el)
+            self._bcs.insert(row, el)
 
     def redo(self):
-        self._bcs.delete_i(self._tab, self._rows)
+        for row in self._rows:
+            del self._bcs[row]
 
-
-class SortCommand(QUndoCommand):
-    def __init__(self, bcs, tab, _reverse):
-        QUndoCommand.__init__(self)
-
-        self._bcs = bcs
-        self._tab = tab
-        self._reverse = _reverse
-
-        self._old = self._bcs.get_tab(self._tab)
-        self._indexes = None
-
-    def undo(self):
-        ll = self._bcs.get_tab(self._tab)
-        self._bcs.sort(
-            self._tab,
-            key=lambda x: self._indexes[ll.index(x)]
-        )
-
-    def redo(self):
-        self._bcs.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._bcs.get_tab(self._tab)
-                )
-            )
-            self._old = None
-
-
-class MoveCommand(QUndoCommand):
-    def __init__(self, bcs, tab, up, i):
-        QUndoCommand.__init__(self)
-
-        self._bcs = bcs
-        self._tab = tab
-        self._up = up == "up"
-        self._i = i
-
-    def undo(self):
-        if self._up:
-            self._bcs.move_up(self._tab, self._i)
-        else:
-            self._bcs.move_down(self._tab, self._i)
-
-    def redo(self):
-        if self._up:
-            self._bcs.move_up(self._tab, self._i)
-        else:
-            self._bcs.move_down(self._tab, self._i)
-
-
-class PasteCommand(QUndoCommand):
-    def __init__(self, bcs, tab, row, bc):
-        QUndoCommand.__init__(self)
-
-        self._bcs = bcs
-        self._tab = tab
-        self._row = row
-        self._bc = deepcopy(bc)
-        self._bc.reverse()
-
-    def undo(self):
-        self._bcs.delete_i(
-            self._tab,
-            range(self._row, self._row + len(self._bc))
-        )
-
-    def redo(self):
-        for bc in self._bc:
-            self._bcs.insert(self._tab, self._row, bc)
diff --git a/src/View/BoundaryConditionsAdisTS/Window.py b/src/View/BoundaryConditionsAdisTS/Window.py
index 8b825080..e055c58b 100644
--- a/src/View/BoundaryConditionsAdisTS/Window.py
+++ b/src/View/BoundaryConditionsAdisTS/Window.py
@@ -40,17 +40,6 @@ from PyQt5.QtWidgets import (
     QWidget,
 )
 
-from Model.BoundaryCondition.BoundaryConditionTypes import (
-    NotDefined, PonctualContribution,
-    TimeOverZ, TimeOverDischarge, ZOverDischarge
-)
-
-from View.BoundaryCondition.UndoCommand import (
-    SetNameCommand, SetNodeCommand, SetTypeCommand,
-    AddCommand, DelCommand, SortCommand,
-    MoveCommand, PasteCommand,
-)
-
 from View.BoundaryConditionsAdisTS.Table import (
     TableModel, ComboBoxDelegate
 )
@@ -119,7 +108,8 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
             trad=self._trad,
             bc_list = self._study.river.boundary_conditions_adists,
             undo=self._undo_stack,
-            pollutant=self._pollutant
+            pollutant=self._pollutant,
+            data=self._study.river
         )
         table.setModel(self._table)
         table.setSelectionBehavior(QAbstractItemView.SelectRows)
@@ -140,7 +130,6 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
         self.find(QAction, "action_add").triggered.connect(self.add)
         self.find(QAction, "action_del").triggered.connect(self.delete)
         self.find(QAction, "action_edit").triggered.connect(self.edit)
-        self.find(QAction, "action_sort").triggered.connect(self.sort)
 
     def index_selected_row(self):
         tab = "liquid"
@@ -169,27 +158,12 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
             self._table.add(rows[0])
 
     def delete(self):
-        tab = "liquid"
         rows = self.index_selected_rows()
         if len(rows) == 0:
             return
 
         self._table.delete(rows)
 
-    def sort(self):
-        tab = "liquid"
-        self._table.sort(False)
-
-    def move_up(self):
-        tab = "liquid"
-        row = self.index_selected_row()
-        self._table.move_up(row)
-
-    def move_down(self):
-        tab = "liquid"
-        row = self.index_selected_row()
-        self._table.move_down(row)
-
     def _copy(self):
         logger.info("TODO: copy")
 
@@ -197,18 +171,15 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
         logger.info("TODO: paste")
 
     def _undo(self):
-        tab = "liquid"
         self._table.undo()
 
     def _redo(self):
-        tab = "liquid"
         self._table.redo()
 
     def edit(self):
-        tab = "liquid"
         rows = self.index_selected_rows()
         for row in rows:
-            data = self._bcs.get(tab, row)
+            data = self._bcs.lst[row]
 
             if self.sub_window_exists(
                 EditBoundaryConditionWindow,
diff --git a/src/View/ui/BoundaryConditionsAdisTS.ui b/src/View/ui/BoundaryConditionsAdisTS.ui
index e9ceb0f3..e9fce33d 100644
--- a/src/View/ui/BoundaryConditionsAdisTS.ui
+++ b/src/View/ui/BoundaryConditionsAdisTS.ui
@@ -23,29 +23,25 @@
    <locale language="English" country="Europe"/>
   </property>
   <widget class="QWidget" name="centralwidget">
-   <widget class="QSplitter" name="splitter">
-    <property name="geometry">
-     <rect>
-      <x>20</x>
-      <y>10</y>
-      <width>811</width>
-      <height>421</height>
-     </rect>
-    </property>
-    <property name="orientation">
-     <enum>Qt::Horizontal</enum>
-    </property>
-    <widget class="QWidget" name="verticalLayoutWidget_2">
-     <layout class="QVBoxLayout" name="verticalLayout_2">
-      <item>
-       <widget class="QTableView" name="tableView"/>
-      </item>
-     </layout>
-    </widget>
-    <widget class="QWidget" name="verticalLayoutWidget">
-     <layout class="QVBoxLayout" name="verticalLayout"/>
-    </widget>
-   </widget>
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QSplitter" name="splitter">
+      <property name="orientation">
+       <enum>Qt::Horizontal</enum>
+      </property>
+      <widget class="QWidget" name="verticalLayoutWidget_2">
+       <layout class="QVBoxLayout" name="verticalLayout_2">
+        <item>
+         <widget class="QTableView" name="tableView"/>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QWidget" name="verticalLayoutWidget">
+       <layout class="QVBoxLayout" name="verticalLayout"/>
+      </widget>
+     </widget>
+    </item>
+   </layout>
   </widget>
   <widget class="QMenuBar" name="menubar">
    <property name="geometry">
@@ -70,7 +66,6 @@
    <addaction name="action_add"/>
    <addaction name="action_del"/>
    <addaction name="action_edit"/>
-   <addaction name="action_sort"/>
   </widget>
   <action name="action_add">
    <property name="checkable">
@@ -120,18 +115,6 @@
     <string>Ctrl+E</string>
    </property>
   </action>
-  <action name="action_sort">
-   <property name="icon">
-    <iconset>
-     <normaloff>ressources/sort_A-Z.png</normaloff>ressources/sort_A-Z.png</iconset>
-   </property>
-   <property name="text">
-    <string>Sort</string>
-   </property>
-   <property name="toolTip">
-    <string>Sort boundary condition by name</string>
-   </property>
-  </action>
  </widget>
  <resources/>
  <connections/>
diff --git a/src/View/ui/EditBoundaryConditionsAdisTS.ui b/src/View/ui/EditBoundaryConditionsAdisTS.ui
new file mode 100644
index 00000000..bd55a027
--- /dev/null
+++ b/src/View/ui/EditBoundaryConditionsAdisTS.ui
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>450</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <property name="locale">
+   <locale language="English" country="Europe"/>
+  </property>
+  <widget class="QWidget" name="centralwidget">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
+     <widget class="QSplitter" name="splitter">
+      <property name="orientation">
+       <enum>Qt::Horizontal</enum>
+      </property>
+      <widget class="QWidget" name="verticalLayoutWidget_2">
+       <layout class="QVBoxLayout" name="verticalLayout_table">
+        <item>
+         <widget class="QTableView" name="tableView">
+          <property name="minimumSize">
+           <size>
+            <width>0</width>
+            <height>200</height>
+           </size>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QWidget" name="verticalLayoutWidget">
+       <layout class="QVBoxLayout" name="verticalLayout"/>
+      </widget>
+     </widget>
+    </item>
+   </layout>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>22</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="toolBar">
+   <property name="windowTitle">
+    <string>toolBar</string>
+   </property>
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+   <addaction name="action_add"/>
+   <addaction name="action_del"/>
+  </widget>
+  <action name="action_add">
+   <property name="checkable">
+    <bool>false</bool>
+   </property>
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/add.png</normaloff>ressources/add.png</iconset>
+   </property>
+   <property name="text">
+    <string>Add</string>
+   </property>
+   <property name="toolTip">
+    <string>Add a new point in boundary condition or punctual contribution</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+N</string>
+   </property>
+  </action>
+  <action name="action_del">
+   <property name="icon">
+    <iconset>
+     <normaloff>ressources/del.png</normaloff>ressources/del.png</iconset>
+   </property>
+   <property name="text">
+    <string>Delete</string>
+   </property>
+   <property name="toolTip">
+    <string>Delete current selected rows</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+D</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests_cases/Enlargement/Enlargement.pamhyr b/tests_cases/Enlargement/Enlargement.pamhyr
index d4b08c0bbb44d05b387edac1981b388fb6fc37fb..98658da7f9e9fecc5edd2bd0b851a201b9e5f636 100644
GIT binary patch
delta 568
zcmZp8z}>KbXM#MhAp-))Zqzx)&n5;G;OE&S(8kYeZfI_4Zlq^qVrXn;vU#$6g#)AE
zW}bu%{2>ON#Xx2HoqRx2uR|F~>bBbgNu9PJAgSG&4kWc&8G)o`i!_kbXx0Lf>P;>{
zQmru(NU9d|0!bGBi46QN_)qh1<)64&(4di@MTv#kbMpCm36A*0l+5CiVy4Yo>-`g$
zc^LgRvp;ZW+|2p+JJV*@C;Pc2xEPNxaI9rN%C?5}0rMYb3C1IQl04hE4K~Ys@a1A+
zI61NL=yrqCjMrGUvN8VKFT=$U#K5J(sl^e(Uc({I>dvgr5X9HUtHHp);WM$(XnW8B
z#$W7A+y>kIPB1=VVrF1q+^qOOmvQ2R6I@Nv3hd&Zo{TMqll`B_utQxo`9i%o%#|vW
z?>?31j!#J}NrcEw-*}W!Z}PmqGL!H8b($RV)Kw9xOCvKylS=^(G@Huh*~RVc8Cz<B
zW=kkQJe`zZnwOGTR2iR~pO=zZl9`_e)vXM&hYewc&GcJ`88xQYoMlv)y!x}+bpE4^
zDwDsylA65dnfA5|j4T0cjQnpH_}^?6ba=$CAjH7Rz^TsZoS&DRnpaYk2r?KH3rzek
p82G>PzW}Pb!!N<j#L6Hn%weEsV611r$;isU599!O%M_R{002K8soMYm

delta 307
zcmZozz|-)6dxAW#J_7<sZ`3)*&n65M;OE*T(8kYeWM*z|YN=;pWNc(?v3at5g#)Ah
zW}bu%{6Tu1#Xx1coqRx2r$ZS?YPZ`0Nv*aZAgS4!4kR^N8G)pFi!_i_Yt{mis!c9H
zQl&8xNGcce0!e26tqlAx_)qh1-7ILZoPYDydjAAwE*96#><`=-nfZS(O~3eoNp0hV
zb4*-KiCpaB*4B(Ik<%xfW0csO{$wt<1SjJW2EI~WPL8$gN7>e}K4AXCECCd<+br|J
zmy3yM(Z<GkOq=~4erMXk$Z|l6n<0pSPm*UFw*i+5rxr&Ddku#;t2?tgL(s%VlkGtV
j7=N)dF)(cRJHhyfX|uuaYb@K@E-?P{-_GK|^yfSPyoyn`

-- 
GitLab