From 1179dd0b927aa8db203f918f7646526b217a54af Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 15 May 2023 16:01:11 +0200 Subject: [PATCH] LC: Add begin and end kp and fix the convertion bug. --- .../BoundaryCondition/BoundaryCondition.py | 5 ++- .../BoundaryConditionList.py | 2 +- src/Model/Geometry/Reach.py | 6 +++ .../LateralContribution.py | 45 ++++++++++++++++++- .../LateralContributionList.py | 2 +- src/Model/River.py | 1 - src/View/LateralContribution/Table.py | 24 ++++++++-- src/View/LateralContribution/UndoCommand.py | 33 ++++++++++++++ src/View/LateralContribution/translate.py | 4 +- 9 files changed, 112 insertions(+), 10 deletions(-) diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index d9ea8f21..cfb33fca 100644 --- a/src/Model/BoundaryCondition/BoundaryCondition.py +++ b/src/Model/BoundaryCondition/BoundaryCondition.py @@ -161,7 +161,9 @@ class BoundaryCondition(object): @timer def convert(self, cls): - new = cls(name = self.name) + new = cls(name = self.name, status = self._status) + new.node = self.node + for i, _ in self.data: new.add(i) @@ -171,7 +173,6 @@ class BoundaryCondition(object): for ind, v in self.data: new._set_i_c_v(ind, j, v[i]) - self._status.modified() return new def move_up(self, index): diff --git a/src/Model/BoundaryCondition/BoundaryConditionList.py b/src/Model/BoundaryCondition/BoundaryConditionList.py index f1e4150e..096dc7b8 100644 --- a/src/Model/BoundaryCondition/BoundaryConditionList.py +++ b/src/Model/BoundaryCondition/BoundaryConditionList.py @@ -37,7 +37,7 @@ class BoundaryConditionList(object): self._status.modified() def new(self, lst, index): - n = NotDefined() + n = NotDefined(status=self._status) self._tabs[lst].insert(index, n) self._status.modified() return n diff --git a/src/Model/Geometry/Reach.py b/src/Model/Geometry/Reach.py index 1c8c95aa..f96cfe59 100644 --- a/src/Model/Geometry/Reach.py +++ b/src/Model/Geometry/Reach.py @@ -201,6 +201,12 @@ class Reach: """ return [profile.kp for profile in self.profiles] + def get_kp_min(self): + return min([profile.kp for profile in self.profiles]) + + def get_kp_max(self): + return max([profile.kp for profile in self.profiles]) + # Guidelines diff --git a/src/Model/LateralContribution/LateralContribution.py b/src/Model/LateralContribution/LateralContribution.py index 47f0650b..b6e16998 100644 --- a/src/Model/LateralContribution/LateralContribution.py +++ b/src/Model/LateralContribution/LateralContribution.py @@ -13,6 +13,8 @@ class LateralContribution(object): self._name = name self._type = "" self._edge = None + self._begin_kp = 0.0 + self._end_kp = 0.0 self._data = [] self._header = [] self._types = [float, float] @@ -51,11 +53,48 @@ class LateralContribution(object): @edge.setter def edge(self, edge): self._edge = edge + if edge is not None: + self._begin_kp = self._edge.reach.get_kp_min() + self._end_kp = self._edge.reach.get_kp_max() self._status.modified() def has_edge(self): return self._edge is not None + @property + def begin_kp(self): + return self._begin_kp + + @begin_kp.setter + def begin_kp(self, begin_kp): + if self._edge is None: + self._begin_kp = begin_kp + else: + _min = self._edge.reach.get_kp_min() + _max = self._edge.reach.get_kp_max() + + if _min <= begin_kp <= _max: + self._begin_kp = begin_kp + + self._status.modified() + + @property + def end_kp(self): + return self._end_kp + + @end_kp.setter + def end_kp(self, end_kp): + if self._edge is None: + self._end_kp = end_kp + else: + _min = self._edge.reach.get_kp_min() + _max = self._edge.reach.get_kp_max() + + if _min <= end_kp <= _max: + self._end_kp = end_kp + + self._status.modified() + @property def header(self): return self._header.copy() @@ -160,7 +199,11 @@ class LateralContribution(object): @timer def convert(self, cls): - new = cls(name = self.name) + new = cls(name = self.name, status = self._status) + new.edge = self.edge + new.begin_kp = self.begin_kp + new.end_kp = self.end_kp + for i, _ in self.data: new.add(i) diff --git a/src/Model/LateralContribution/LateralContributionList.py b/src/Model/LateralContribution/LateralContributionList.py index f0947493..c14d6f63 100644 --- a/src/Model/LateralContribution/LateralContributionList.py +++ b/src/Model/LateralContribution/LateralContributionList.py @@ -35,7 +35,7 @@ class LateralContributionList(object): self._status.modified() def new(self, lst, index): - n = NotDefined() + n = NotDefined(status=self._status) self._tabs[lst].insert(index, n) self._status.modified() return n diff --git a/src/Model/River.py b/src/Model/River.py index 11d0987f..d00de347 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -52,7 +52,6 @@ class RiverReach(Edge): class River(Graph): def __init__(self, status=None): - print(status) super(River, self).__init__(status=status) # Replace Node and Edge ctor by custom ctor diff --git a/src/View/LateralContribution/Table.py b/src/View/LateralContribution/Table.py index 24c2022f..818605cf 100644 --- a/src/View/LateralContribution/Table.py +++ b/src/View/LateralContribution/Table.py @@ -17,6 +17,7 @@ from PyQt5.QtWidgets import ( from View.LateralContribution.UndoCommand import ( SetNameCommand, SetEdgeCommand, SetTypeCommand, + SetBeginCommand, SetEndCommand, AddCommand, DelCommand, SortCommand, MoveCommand, PasteCommand, DuplicateCommand, ) @@ -120,6 +121,11 @@ class TableModel(QAbstractTableModel): if n is None: return _translate("LateralContribution", "Not associate") return n.name + elif self._headers[column] == "begin_kp": + return self._lcs.get(self._tab, row).begin_kp + elif self._headers[column] == "end_kp": + return self._lcs.get(self._tab, row).end_kp + return QVariant() @@ -139,20 +145,32 @@ class TableModel(QAbstractTableModel): if self._headers[column] == "name": self._undo.push( SetNameCommand( - self._lcs, self._tab,row, value + self._lcs, self._tab, row, value ) ) elif self._headers[column] == "type": key = next(k for k, v in long_types.items() if v == value) self._undo.push( SetTypeCommand( - self._lcs, self._tab,row, LC_types[key] + self._lcs, self._tab, row, LC_types[key] ) ) elif self._headers[column] == "edge": self._undo.push( SetEdgeCommand( - self._lcs, self._tab,row, self._data.edge(value) + self._lcs, self._tab, row, self._data.edge(value) + ) + ) + elif self._headers[column] == "begin_kp": + self._undo.push( + SetBeginCommand( + self._lcs, self._tab, row, value + ) + ) + elif self._headers[column] == "end_kp": + self._undo.push( + SetEndCommand( + self._lcs, self._tab, row, value ) ) diff --git a/src/View/LateralContribution/UndoCommand.py b/src/View/LateralContribution/UndoCommand.py index 5140a9d9..f7e680b3 100644 --- a/src/View/LateralContribution/UndoCommand.py +++ b/src/View/LateralContribution/UndoCommand.py @@ -26,6 +26,39 @@ class SetNameCommand(QUndoCommand): def redo(self): self._lcs.get(self._tab, self._index).name = self._new +class SetBeginCommand(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).begin_kp + self._new = new_value + + def undo(self): + self._lcs.get(self._tab, self._index).begin_kp = float(self._old) + + def redo(self): + self._lcs.get(self._tab, self._index).begin_kp = float(self._new) + +class SetEndCommand(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).end_kp + self._new = new_value + + def undo(self): + self._lcs.get(self._tab, self._index).end_kp = float(self._old) + + def redo(self): + self._lcs.get(self._tab, self._index).end_kp = float(self._new) + + class SetEdgeCommand(QUndoCommand): def __init__(self, lcs, tab, index, edge): QUndoCommand.__init__(self) diff --git a/src/View/LateralContribution/translate.py b/src/View/LateralContribution/translate.py index 88577bc1..c2b9e789 100644 --- a/src/View/LateralContribution/translate.py +++ b/src/View/LateralContribution/translate.py @@ -18,7 +18,9 @@ long_types = { table_headers = { "name": _translate("LateralContribution", "Name"), "type": _translate("LateralContribution", "Type"), - "edge": _translate("LateralContribution", "Edge") + "edge": _translate("LateralContribution", "Reach"), + "begin_kp": _translate("LateralContribution", "Begin kp (m)"), + "end_kp": _translate("LateralContribution", "End kp (m)") } LC_types = { -- GitLab