mirror of https://gitlab.com/pamhyr/pamhyr2
LateralContrib: split correctly reach and lateralContrib + display only enabled reach in tab
parent
e3fbe59585
commit
698e300690
|
|
@ -196,6 +196,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 LateralContribution(SQLSubModel):
|
class LateralContribution(SQLSubModel):
|
||||||
_sub_classes = [Data]
|
_sub_classes = [Data]
|
||||||
|
|
@ -511,6 +518,15 @@ class LateralContribution(SQLSubModel):
|
||||||
def has_reach(self):
|
def has_reach(self):
|
||||||
return self._reach is not None
|
return self._reach is not None
|
||||||
|
|
||||||
|
def cloned_for(self, reach, begin_section, end_section):
|
||||||
|
new = type(self)(name=self._name, status=self._status)
|
||||||
|
new._reach = reach
|
||||||
|
new._begin_section = begin_section
|
||||||
|
new._end_section = end_section
|
||||||
|
new._data = [data.cloned() for data in self.data]
|
||||||
|
new.modified()
|
||||||
|
return new
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def begin_rk(self):
|
def begin_rk(self):
|
||||||
if self._begin_section is None:
|
if self._begin_section is None:
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,89 @@ class LateralContributionList(PamhyrModelListWithTab):
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def split_reach(self, reach, profile, reach1, reach2):
|
||||||
|
profiles = reach.reach.profiles
|
||||||
|
split_index = profiles.index(profile)
|
||||||
|
|
||||||
|
parts = [
|
||||||
|
(
|
||||||
|
reach1,
|
||||||
|
0,
|
||||||
|
split_index,
|
||||||
|
dict(zip(
|
||||||
|
profiles[:split_index + 1],
|
||||||
|
reach1.reach.profiles
|
||||||
|
))
|
||||||
|
),
|
||||||
|
(
|
||||||
|
reach2,
|
||||||
|
split_index,
|
||||||
|
len(profiles) - 1,
|
||||||
|
dict(zip(
|
||||||
|
profiles[split_index:],
|
||||||
|
reach2.reach.profiles
|
||||||
|
))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
for tab in self._tabs:
|
||||||
|
contributions = [
|
||||||
|
contribution
|
||||||
|
for contribution in self.get_tab(tab)
|
||||||
|
if contribution.reach is reach
|
||||||
|
]
|
||||||
|
|
||||||
|
for contribution in contributions:
|
||||||
|
if (contribution.begin_section not in profiles or
|
||||||
|
contribution.end_section not in profiles):
|
||||||
|
continue
|
||||||
|
|
||||||
|
begin = profiles.index(contribution.begin_section)
|
||||||
|
end = profiles.index(contribution.end_section)
|
||||||
|
lower, upper = sorted((begin, end))
|
||||||
|
reverse = begin > end
|
||||||
|
clones = []
|
||||||
|
|
||||||
|
for new_reach, part_lower, part_upper, sections in parts:
|
||||||
|
clipped_lower = max(lower, part_lower)
|
||||||
|
clipped_upper = min(upper, part_upper)
|
||||||
|
if clipped_lower > clipped_upper:
|
||||||
|
continue
|
||||||
|
|
||||||
|
begin_index = (
|
||||||
|
clipped_upper if reverse else clipped_lower
|
||||||
|
)
|
||||||
|
end_index = (
|
||||||
|
clipped_lower if reverse else clipped_upper
|
||||||
|
)
|
||||||
|
clones.append(contribution.cloned_for(
|
||||||
|
new_reach,
|
||||||
|
sections[profiles[begin_index]],
|
||||||
|
sections[profiles[end_index]]
|
||||||
|
))
|
||||||
|
|
||||||
|
if len(clones) == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self._tabs[tab].extend(clones)
|
||||||
|
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
|
def get_tab_for_enabled_reaches(self, tab):
|
||||||
|
return [
|
||||||
|
contribution
|
||||||
|
for contribution in self.get_tab(tab)
|
||||||
|
if (contribution.reach is None or
|
||||||
|
(not contribution.reach.is_deleted() and
|
||||||
|
contribution.reach.is_enable()))
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_for_enabled_reaches(self, tab, index):
|
||||||
|
contributions = self.get_tab_for_enabled_reaches(tab)
|
||||||
|
if not 0 <= index < len(contributions):
|
||||||
|
return None
|
||||||
|
return contributions[index]
|
||||||
|
|
||||||
def __copy__(self):
|
def __copy__(self):
|
||||||
new = LateralContributionList()
|
new = LateralContributionList()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -982,5 +982,8 @@ Last export at: @date."""
|
||||||
self._initial_conditions.split_reach(
|
self._initial_conditions.split_reach(
|
||||||
reach, profile, r1, r2
|
reach, profile, r1, r2
|
||||||
)
|
)
|
||||||
|
self._lateral_contribution.split_reach(
|
||||||
|
reach, profile, r1, r2
|
||||||
|
)
|
||||||
|
|
||||||
return r1, r2
|
return r1, r2
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import tempfile
|
||||||
from Model.Status import StudyStatus
|
from Model.Status import StudyStatus
|
||||||
from Model.Study import Study
|
from Model.Study import Study
|
||||||
from Model.River import River
|
from Model.River import River
|
||||||
|
from Model.LateralContribution.LateralContributionTypes import LateralContrib
|
||||||
|
|
||||||
|
|
||||||
class StudyTestCase(unittest.TestCase):
|
class StudyTestCase(unittest.TestCase):
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,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))
|
||||||
|
|
@ -154,7 +157,9 @@ class TableModel(PamhyrTableModel):
|
||||||
self._long_types = self._trad.get_dict("long_types")
|
self._long_types = self._trad.get_dict("long_types")
|
||||||
|
|
||||||
def get_true_data_row(self, row):
|
def get_true_data_row(self, row):
|
||||||
lc = self._lst.get(self._tab, row)
|
lc = self._lst.get_for_enabled_reaches(self._tab, row)
|
||||||
|
if lc is None:
|
||||||
|
return len(self._lst.get_tab(self._tab))
|
||||||
|
|
||||||
return next(
|
return next(
|
||||||
map(
|
map(
|
||||||
|
|
@ -167,7 +172,7 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return self._lst.len(self._tab)
|
return len(self._lst.get_tab_for_enabled_reaches(self._tab))
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
|
|
@ -175,21 +180,22 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
row = index.row()
|
row = index.row()
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
contribution = self._lst.get_for_enabled_reaches(self._tab, row)
|
||||||
|
|
||||||
if self._headers[column] == "name":
|
if self._headers[column] == "name":
|
||||||
return self._lst.get(self._tab, row).name
|
return contribution.name
|
||||||
elif self._headers[column] == "type":
|
elif self._headers[column] == "type":
|
||||||
t = self._lst.get(self._tab, row).lctype
|
t = contribution.lctype
|
||||||
return self._long_types[t]
|
return self._long_types[t]
|
||||||
elif self._headers[column] == "edge":
|
elif self._headers[column] == "edge":
|
||||||
n = self._lst.get(self._tab, row).reach
|
n = contribution.reach
|
||||||
if n is None:
|
if n is None:
|
||||||
return self._trad['not_associated']
|
return self._trad['not_associated']
|
||||||
return n.name
|
return n.name
|
||||||
elif self._headers[column] == "begin_rk":
|
elif self._headers[column] == "begin_rk":
|
||||||
return str(self._lst.get(self._tab, row).begin_rk)
|
return str(contribution.begin_rk)
|
||||||
elif self._headers[column] == "end_rk":
|
elif self._headers[column] == "end_rk":
|
||||||
return str(self._lst.get(self._tab, row).end_rk)
|
return str(contribution.end_rk)
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
|
@ -202,6 +208,8 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
row = index.row()
|
row = index.row()
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
contribution = self._lst.get_for_enabled_reaches(self._tab, row)
|
||||||
|
row = self.get_true_data_row(row)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self._headers[column] == "name":
|
if self._headers[column] == "name":
|
||||||
|
|
@ -225,7 +233,7 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "begin_rk":
|
elif self._headers[column] == "begin_rk":
|
||||||
_edge = self._lst.get(self._tab, row).reach
|
_edge = contribution.reach
|
||||||
_begin_rk = next(
|
_begin_rk = next(
|
||||||
p for p in _edge.reach.profiles
|
p for p in _edge.reach.profiles
|
||||||
if p.pamhyr_id == value
|
if p.pamhyr_id == value
|
||||||
|
|
@ -236,7 +244,7 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "end_rk":
|
elif self._headers[column] == "end_rk":
|
||||||
_edge = self._lst.get(self._tab, row).reach
|
_edge = contribution.reach
|
||||||
_end_rk = next(
|
_end_rk = next(
|
||||||
p for p in _edge.reach.profiles
|
p for p in _edge.reach.profiles
|
||||||
if p.pamhyr_id == value
|
if p.pamhyr_id == value
|
||||||
|
|
|
||||||
|
|
@ -213,11 +213,11 @@ class LateralContributionWindow(PamhyrWindow):
|
||||||
if len(rows) > 0:
|
if len(rows) > 0:
|
||||||
edge = self._study.river\
|
edge = self._study.river\
|
||||||
.lateral_contribution\
|
.lateral_contribution\
|
||||||
.get(tab, rows[0])\
|
.get_for_enabled_reaches(tab, rows[0])\
|
||||||
.reach
|
.reach
|
||||||
if edge:
|
if edge:
|
||||||
data = edge.reach
|
data = edge.reach
|
||||||
lc = self._lcs.get(tab, rows[0])
|
lc = self._lcs.get_for_enabled_reaches(tab, rows[0])
|
||||||
highlight = (lc.begin_rk, lc.end_rk)
|
highlight = (lc.begin_rk, lc.end_rk)
|
||||||
|
|
||||||
for delegate in self._delegate_rk:
|
for delegate in self._delegate_rk:
|
||||||
|
|
@ -236,7 +236,8 @@ class LateralContributionWindow(PamhyrWindow):
|
||||||
def add(self):
|
def add(self):
|
||||||
tab = self.current_tab()
|
tab = self.current_tab()
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
if self._lcs.len(tab) == 0 or len(rows) == 0:
|
visible = self._lcs.get_tab_for_enabled_reaches(tab)
|
||||||
|
if len(visible) == 0 or len(rows) == 0:
|
||||||
self._table[tab].add(0)
|
self._table[tab].add(0)
|
||||||
else:
|
else:
|
||||||
self._table[tab].add(rows[0])
|
self._table[tab].add(rows[0])
|
||||||
|
|
@ -291,7 +292,7 @@ class LateralContributionWindow(PamhyrWindow):
|
||||||
tab = self.current_tab()
|
tab = self.current_tab()
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
data = self._lcs.get(tab, row)
|
data = self._lcs.get_for_enabled_reaches(tab, row)
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
EditLateralContributionWindow,
|
EditLateralContributionWindow,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue