mirror of https://gitlab.com/pamhyr/pamhyr2
LateralContributions: propagate LAT when splitting reach + display only enabled reach in combobox
parent
87d31c134e
commit
bbdd18e8ef
|
|
@ -192,6 +192,13 @@ class Data(SQLSubModel):
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
self._data[key] = self._types[key](value)
|
self._data[key] = self._types[key](value)
|
||||||
|
|
||||||
|
def cloned(self):
|
||||||
|
return Data(
|
||||||
|
self[0], self[1],
|
||||||
|
types=self._types,
|
||||||
|
status=self._status
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LateralContributionAdisTS(SQLSubModel):
|
class LateralContributionAdisTS(SQLSubModel):
|
||||||
_sub_classes = [Data]
|
_sub_classes = [Data]
|
||||||
|
|
@ -477,6 +484,18 @@ class LateralContributionAdisTS(SQLSubModel):
|
||||||
self._end_rk = end_rk
|
self._end_rk = end_rk
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
def cloned_for(self, reach, begin_rk, end_rk):
|
||||||
|
new = LateralContributionAdisTS(
|
||||||
|
pollutant=self._pollutant,
|
||||||
|
status=self._status
|
||||||
|
)
|
||||||
|
new._reach = reach
|
||||||
|
new._begin_rk = begin_rk
|
||||||
|
new._end_rk = end_rk
|
||||||
|
new._data = [data.cloned() for data in self.data]
|
||||||
|
new.modified()
|
||||||
|
return new
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _default_0(self):
|
def _default_0(self):
|
||||||
return self._types[0](0)
|
return self._types[0](0)
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,46 @@ class LateralContributionsAdisTSList(PamhyrModelList):
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def split_reach(self, reach, profile, reach1, reach2):
|
||||||
|
parts = []
|
||||||
|
for new_reach in (reach1, reach2):
|
||||||
|
rks = new_reach.reach.get_rk()
|
||||||
|
if len(rks) == 0:
|
||||||
|
continue
|
||||||
|
parts.append((new_reach.id, min(rks), max(rks)))
|
||||||
|
|
||||||
|
contributions = [
|
||||||
|
contribution
|
||||||
|
for contribution in self.lst
|
||||||
|
if contribution.reach == reach.id
|
||||||
|
]
|
||||||
|
clones = []
|
||||||
|
|
||||||
|
for contribution in contributions:
|
||||||
|
begin = contribution.begin_rk
|
||||||
|
end = contribution.end_rk
|
||||||
|
if begin is None or end is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
lower, upper = sorted((begin, end))
|
||||||
|
reverse = begin > end
|
||||||
|
|
||||||
|
for new_reach, part_lower, part_upper in parts:
|
||||||
|
clipped_lower = max(lower, part_lower)
|
||||||
|
clipped_upper = min(upper, part_upper)
|
||||||
|
if clipped_lower > clipped_upper:
|
||||||
|
continue
|
||||||
|
|
||||||
|
begin_rk = clipped_upper if reverse else clipped_lower
|
||||||
|
end_rk = clipped_lower if reverse else clipped_upper
|
||||||
|
clones.append(contribution.cloned_for(
|
||||||
|
new_reach, begin_rk, end_rk
|
||||||
|
))
|
||||||
|
|
||||||
|
if len(clones) != 0:
|
||||||
|
self._lst.extend(clones)
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def Lat_Cont_List(self):
|
def Lat_Cont_List(self):
|
||||||
return self.lst
|
return self.lst
|
||||||
|
|
|
||||||
|
|
@ -991,5 +991,8 @@ Last export at: @date."""
|
||||||
self._InitialConditionsAdisTS.split_reach(
|
self._InitialConditionsAdisTS.split_reach(
|
||||||
reach, profile, r1, r2
|
reach, profile, r1, r2
|
||||||
)
|
)
|
||||||
|
self._LateralContributionsAdisTS.split_reach(
|
||||||
|
reach, profile, r1, r2
|
||||||
|
)
|
||||||
|
|
||||||
return r1, r2
|
return r1, r2
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ class AdisTSwc(AdisTS):
|
||||||
for LC in POL_LC:
|
for LC in POL_LC:
|
||||||
reach = next((
|
reach = next((
|
||||||
edge for edge in study.river.enable_edges()
|
edge for edge in study.river.enable_edges()
|
||||||
if edge.id == LC.edge
|
if edge.id == LC.reach
|
||||||
), None)
|
), None)
|
||||||
if reach is None:
|
if reach is None:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
else:
|
else:
|
||||||
val = list(
|
val = list(
|
||||||
map(
|
map(
|
||||||
lambda n: n.name, self._data.edges()
|
lambda n: n.name, self._data.enable_edges()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
else:
|
else:
|
||||||
val = list(
|
val = list(
|
||||||
map(
|
map(
|
||||||
lambda n: n.name, self._data.edges()
|
lambda n: n.name, self._data.enable_edges()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
else:
|
else:
|
||||||
val = list(
|
val = list(
|
||||||
map(
|
map(
|
||||||
lambda n: n.name, self._data.edges()
|
lambda n: n.name, self._data.enable_edges()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,10 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
else:
|
else:
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
[self._trad['not_associated']] +
|
[self._trad['not_associated']] +
|
||||||
self._data.edges_names()
|
[
|
||||||
|
reach.name
|
||||||
|
for reach in self._data.enable_edges()
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||||
|
|
@ -119,6 +122,11 @@ class TableModel(PamhyrTableModel):
|
||||||
self._setup_lst()
|
self._setup_lst()
|
||||||
|
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
|
enabled_reach_ids = {
|
||||||
|
reach.id
|
||||||
|
for reach in self._data.enable_edges()
|
||||||
|
}
|
||||||
|
|
||||||
if self._lcs_list is not None:
|
if self._lcs_list is not None:
|
||||||
self._lcs_pol_list = [
|
self._lcs_pol_list = [
|
||||||
lcs for lcs in self._lcs_list._lst
|
lcs for lcs in self._lcs_list._lst
|
||||||
|
|
@ -127,7 +135,13 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
self._lst = list(
|
self._lst = list(
|
||||||
filter(
|
filter(
|
||||||
lambda x: x._deleted is False,
|
lambda x: (
|
||||||
|
x._deleted is False and
|
||||||
|
(
|
||||||
|
x.reach in (None, -1) or
|
||||||
|
x.reach in enabled_reach_ids
|
||||||
|
)
|
||||||
|
),
|
||||||
self._lcs_pol_list
|
self._lcs_pol_list
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -137,6 +151,18 @@ class TableModel(PamhyrTableModel):
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self._lst)
|
return len(self._lst)
|
||||||
|
|
||||||
|
def get(self, row):
|
||||||
|
if 0 <= row < len(self._lst):
|
||||||
|
return self._lst[row]
|
||||||
|
return None
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.beginResetModel()
|
||||||
|
try:
|
||||||
|
self._setup_lst()
|
||||||
|
finally:
|
||||||
|
self.endResetModel()
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
@ -170,11 +196,18 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self._headers[column] == "reach":
|
if self._headers[column] == "reach":
|
||||||
|
reach = self._data.reach(value)
|
||||||
|
rks = reach.reach.get_rk()
|
||||||
|
if len(rks) == 0:
|
||||||
|
return False
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetReachCommand(
|
SetReachCommand(
|
||||||
self._lcs_list, self._lst,
|
self._lcs_list, self._lst,
|
||||||
row,
|
row,
|
||||||
self._data.reach(value).id
|
reach.id,
|
||||||
|
min(rks),
|
||||||
|
max(rks)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "begin_rk":
|
elif self._headers[column] == "begin_rk":
|
||||||
|
|
@ -193,6 +226,12 @@ class TableModel(PamhyrTableModel):
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
|
|
||||||
|
if self._headers[column] == "reach":
|
||||||
|
end_index = self.index(
|
||||||
|
row, self._headers.index("end_rk")
|
||||||
|
)
|
||||||
|
self.dataChanged.emit(index, end_index)
|
||||||
|
else:
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,20 +64,30 @@ class SetEndCommand(QUndoCommand):
|
||||||
|
|
||||||
|
|
||||||
class SetReachCommand(QUndoCommand):
|
class SetReachCommand(QUndoCommand):
|
||||||
def __init__(self, lcs, lcs_lst, index, reach):
|
def __init__(self, lcs, lcs_lst, index, reach, begin_rk, end_rk):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._lcs = lcs
|
self._lcs = lcs
|
||||||
self._lcs_lst = lcs_lst
|
self._lcs_lst = lcs_lst
|
||||||
self._index = index
|
self._index = index
|
||||||
self._old = self._lcs_lst[self._index].reach
|
self._old = self._lcs_lst[self._index].reach
|
||||||
|
self._old_begin_rk = self._lcs_lst[self._index].begin_rk
|
||||||
|
self._old_end_rk = self._lcs_lst[self._index].end_rk
|
||||||
self._new = reach
|
self._new = reach
|
||||||
|
self._new_begin_rk = begin_rk
|
||||||
|
self._new_end_rk = end_rk
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._lcs_lst[self._index].reach = self._old
|
contribution = self._lcs_lst[self._index]
|
||||||
|
contribution.reach = self._old
|
||||||
|
contribution.begin_rk = self._old_begin_rk
|
||||||
|
contribution.end_rk = self._old_end_rk
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._lcs_lst[self._index].reach = self._new
|
contribution = self._lcs_lst[self._index]
|
||||||
|
contribution.reach = self._new
|
||||||
|
contribution.begin_rk = self._new_begin_rk
|
||||||
|
contribution.end_rk = self._new_end_rk
|
||||||
|
|
||||||
|
|
||||||
class AddCommand(QUndoCommand):
|
class AddCommand(QUndoCommand):
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import logging
|
||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Modules import Modules
|
||||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||||
|
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
|
|
@ -187,12 +188,13 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
data = None
|
data = None
|
||||||
highlight = None
|
highlight = None
|
||||||
|
|
||||||
tab = "liquid"
|
|
||||||
|
|
||||||
if len(rows) > 0:
|
if len(rows) > 0:
|
||||||
reach_id = self._study.river\
|
contribution = self._table.get(rows[0])
|
||||||
.lateral_contributions_adists.lst[rows[0]]\
|
reach_id = (
|
||||||
.reach
|
contribution.reach
|
||||||
|
if contribution is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
if reach_id:
|
if reach_id:
|
||||||
reach = next(
|
reach = next(
|
||||||
|
|
@ -201,8 +203,10 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
self._study.river.reachs()))
|
self._study.river.reachs()))
|
||||||
|
|
||||||
data = reach.reach
|
data = reach.reach
|
||||||
lc = self._lcs.lst[rows[0]]
|
highlight = (
|
||||||
highlight = (lc.begin_rk, lc.end_rk)
|
contribution.begin_rk,
|
||||||
|
contribution.end_rk
|
||||||
|
)
|
||||||
|
|
||||||
for delegate in self._delegate_rk:
|
for delegate in self._delegate_rk:
|
||||||
delegate.data = reach
|
delegate.data = reach
|
||||||
|
|
@ -254,13 +258,23 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
|
||||||
self._table.redo()
|
self._table.redo()
|
||||||
self._set_current_reach()
|
self._set_current_reach()
|
||||||
|
|
||||||
|
def _propagated_update(self, key=Modules(0)):
|
||||||
|
if Modules.NETWORK not in key:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._table.refresh()
|
||||||
|
self.find(QTableView, "tableView").clearSelection()
|
||||||
|
self._set_current_reach()
|
||||||
|
|
||||||
def edit(self):
|
def edit(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
if not rows:
|
if not rows:
|
||||||
return
|
return
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
data = self._lcs.lst[row]
|
data = self._table.get(row)
|
||||||
|
if data is None:
|
||||||
|
continue
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
EditLateralContributionAdisTSWindow,
|
EditLateralContributionAdisTSWindow,
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,10 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
else:
|
else:
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
[self._trad['not_associated']] +
|
[self._trad['not_associated']] +
|
||||||
self._data.edges_names()
|
[
|
||||||
|
reach.name
|
||||||
|
for reach in self._data.enable_edges()
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
self.editor.setCurrentText(str(index.data(Qt.DisplayRole)))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue