diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index d9ea8f2180ab80229498c2b2ae26192eccf7d053..cfb33fca723e66286ef12dfe596b36b07de1f4fd 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 f1e4150eb14263c094095c26578d9e4cdc5a090a..096dc7b80bee24f09ddb2daeb3b38f61b0df7881 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 1c8c95aa53e0fcb485f96aabe6f77cab6001847f..f96cfe59f732384dae0b0e706682a7befe277020 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 47f0650bb9300749434f992a1693f63a34b97d85..b6e16998343c62d14d18a3a45c2ca9afc6b24211 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 f0947493b92295d2e4e36355eea4bdaba08360a0..c14d6f634664b6b79b2eff7be3de7d76882165d7 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 11d0987f4a9c27ecfe761aa649eb1f7642a14812..d00de347774ba41d862c70c69628b3b97b1428c3 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 24c2022f72bb1e2279bd5ea98f71d75d48c16740..818605cf917c59212002a97e5fe356babbf290b3 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 5140a9d929ff00b5e490d12660045f60a8171601..f7e680b36b4e8c5aa55c821afece4006d3d875bf 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 88577bc13fcdfd8038d4eec3f69e29681f4d9729..c2b9e7893c5da5e3a551e617855b5e3f3cb53cf5 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 = {