mirror of https://gitlab.com/pamhyr/pamhyr2
InitialConditionsAdisTS: split correctly reach and InitialConditionsAdisTS + display only enabled reach in tab
parent
6175e8a03e
commit
5e95c286a9
|
|
@ -359,3 +359,60 @@ class InitialConditionsAdisTS(SQLSubModel):
|
||||||
x.set_as_not_deleted()
|
x.set_as_not_deleted()
|
||||||
|
|
||||||
self.modified()
|
self.modified()
|
||||||
|
|
||||||
|
def split_reach(self, reach, profile, reach1, reach2):
|
||||||
|
split_rk = profile.rk
|
||||||
|
reach_rks = reach.reach.get_rk()
|
||||||
|
if len(reach_rks) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
lower_reach_rk = min(reach_rks)
|
||||||
|
upper_reach_rk = max(reach_rks)
|
||||||
|
parts = [
|
||||||
|
(reach1.id, lower_reach_rk, split_rk),
|
||||||
|
(reach2.id, split_rk, upper_reach_rk),
|
||||||
|
]
|
||||||
|
specifications = [
|
||||||
|
specification
|
||||||
|
for specification in self._data
|
||||||
|
if (not specification.is_deleted() and
|
||||||
|
specification.reach == reach.id)
|
||||||
|
]
|
||||||
|
|
||||||
|
for specification in specifications:
|
||||||
|
begin = specification.start_rk
|
||||||
|
end = specification.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
|
||||||
|
|
||||||
|
start_rk = clipped_upper if reverse else clipped_lower
|
||||||
|
end_rk = clipped_lower if reverse else clipped_upper
|
||||||
|
self._data.append(specification.cloned_for(
|
||||||
|
new_reach, start_rk, end_rk
|
||||||
|
))
|
||||||
|
|
||||||
|
if len(specifications) != 0:
|
||||||
|
self.modified()
|
||||||
|
|
||||||
|
def get_specs_for_enabled_reaches(self, reaches):
|
||||||
|
enabled_reaches = {
|
||||||
|
reach.id
|
||||||
|
for reach in reaches
|
||||||
|
if not reach.is_deleted() and reach.is_enable()
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
specification
|
||||||
|
for specification in self._data
|
||||||
|
if (not specification.is_deleted() and
|
||||||
|
(specification.reach in (None, -1) or
|
||||||
|
specification.reach in enabled_reaches))
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,12 @@ class InitialConditionsAdisTSList(PamhyrModelList):
|
||||||
self._status.modified()
|
self._status.modified()
|
||||||
return n
|
return n
|
||||||
|
|
||||||
|
def split_reach(self, reach, profile, reach1, reach2):
|
||||||
|
for initial_condition in self.lst:
|
||||||
|
initial_condition.split_reach(
|
||||||
|
reach, profile, reach1, reach2
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def Initial_Conditions_List(self):
|
def Initial_Conditions_List(self):
|
||||||
return self.lst
|
return self.lst
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,12 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = []
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
status=None, owner_scenario=None):
|
status=None, owner_scenario=-1):
|
||||||
super(ICAdisTSSpec, self).__init__()
|
super(ICAdisTSSpec, self).__init__(
|
||||||
|
id=id,
|
||||||
self._status = status
|
status=status,
|
||||||
|
owner_scenario=owner_scenario
|
||||||
|
)
|
||||||
|
|
||||||
self._name_section = name
|
self._name_section = name
|
||||||
self._reach = None
|
self._reach = None
|
||||||
|
|
@ -234,7 +236,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@name.setter
|
@name.setter
|
||||||
def name(self, name):
|
def name(self, name):
|
||||||
self._name_section = name
|
self._name_section = name
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def reach(self):
|
def reach(self):
|
||||||
|
|
@ -243,7 +245,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@reach.setter
|
@reach.setter
|
||||||
def reach(self, reach):
|
def reach(self, reach):
|
||||||
self._reach = reach
|
self._reach = reach
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def start_rk(self):
|
def start_rk(self):
|
||||||
|
|
@ -252,7 +254,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@start_rk.setter
|
@start_rk.setter
|
||||||
def start_rk(self, start_rk):
|
def start_rk(self, start_rk):
|
||||||
self._start_rk = start_rk
|
self._start_rk = start_rk
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def end_rk(self):
|
def end_rk(self):
|
||||||
|
|
@ -261,7 +263,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@end_rk.setter
|
@end_rk.setter
|
||||||
def end_rk(self, end_rk):
|
def end_rk(self, end_rk):
|
||||||
self._end_rk = end_rk
|
self._end_rk = end_rk
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def concentration(self):
|
def concentration(self):
|
||||||
|
|
@ -270,7 +272,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@concentration.setter
|
@concentration.setter
|
||||||
def concentration(self, concentration):
|
def concentration(self, concentration):
|
||||||
self._concentration = concentration
|
self._concentration = concentration
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def eg(self):
|
def eg(self):
|
||||||
|
|
@ -279,7 +281,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@eg.setter
|
@eg.setter
|
||||||
def eg(self, eg):
|
def eg(self, eg):
|
||||||
self._eg = eg
|
self._eg = eg
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def em(self):
|
def em(self):
|
||||||
|
|
@ -288,7 +290,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@em.setter
|
@em.setter
|
||||||
def em(self, em):
|
def em(self, em):
|
||||||
self._em = em
|
self._em = em
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ed(self):
|
def ed(self):
|
||||||
|
|
@ -297,7 +299,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@ed.setter
|
@ed.setter
|
||||||
def ed(self, ed):
|
def ed(self, ed):
|
||||||
self._ed = ed
|
self._ed = ed
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rate(self):
|
def rate(self):
|
||||||
|
|
@ -306,7 +308,7 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@rate.setter
|
@rate.setter
|
||||||
def rate(self, rate):
|
def rate(self, rate):
|
||||||
self._rate = rate
|
self._rate = rate
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self):
|
def enabled(self):
|
||||||
|
|
@ -315,4 +317,18 @@ class ICAdisTSSpec(SQLSubModel):
|
||||||
@enabled.setter
|
@enabled.setter
|
||||||
def enabled(self, enabled):
|
def enabled(self, enabled):
|
||||||
self._enabled = enabled
|
self._enabled = enabled
|
||||||
self._status.modified()
|
self.modified()
|
||||||
|
|
||||||
|
def cloned_for(self, reach, start_rk, end_rk):
|
||||||
|
new = ICAdisTSSpec(name=self._name_section, status=self._status)
|
||||||
|
new._reach = reach
|
||||||
|
new._start_rk = start_rk
|
||||||
|
new._end_rk = end_rk
|
||||||
|
new._concentration = self._concentration
|
||||||
|
new._eg = self._eg
|
||||||
|
new._em = self._em
|
||||||
|
new._ed = self._ed
|
||||||
|
new._rate = self._rate
|
||||||
|
new._enabled = self._enabled
|
||||||
|
new.modified()
|
||||||
|
return new
|
||||||
|
|
|
||||||
|
|
@ -988,5 +988,8 @@ Last export at: @date."""
|
||||||
self._hydraulic_structures.split_reach(
|
self._hydraulic_structures.split_reach(
|
||||||
reach, profile, r1, r2
|
reach, profile, r1, r2
|
||||||
)
|
)
|
||||||
|
self._InitialConditionsAdisTS.split_reach(
|
||||||
|
reach, profile, r1, r2
|
||||||
|
)
|
||||||
|
|
||||||
return r1, r2
|
return r1, r2
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,27 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
self._trad = trad
|
self._trad = trad
|
||||||
self._ic_spec_lst = ic_spec_lst
|
self._ic_spec_lst = ic_spec_lst
|
||||||
|
|
||||||
|
def _specifications(self):
|
||||||
|
if hasattr(
|
||||||
|
self._ic_spec_lst,
|
||||||
|
"get_specs_for_enabled_reaches"
|
||||||
|
):
|
||||||
|
return self._ic_spec_lst.get_specs_for_enabled_reaches(
|
||||||
|
self._data.edges()
|
||||||
|
)
|
||||||
|
return self._ic_spec_lst
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
self.editor = QComboBox(parent)
|
self.editor = QComboBox(parent)
|
||||||
|
|
||||||
val = []
|
val = []
|
||||||
if self._mode == "rk":
|
if self._mode == "rk":
|
||||||
reach_id = self._ic_spec_lst[index.row()].reach
|
reach_id = self._specifications()[index.row()].reach
|
||||||
|
|
||||||
reach = next(filter(lambda edge: edge.id == reach_id,
|
reach = next(filter(lambda edge: edge.id == reach_id,
|
||||||
self._data.edges()), None)
|
self._data.edges()), None)
|
||||||
|
|
||||||
if reach_id is not None:
|
if reach is not None:
|
||||||
val = list(
|
val = list(
|
||||||
map(
|
map(
|
||||||
lambda rk: str(rk), reach.reach.get_rk()
|
lambda rk: str(rk), reach.reach.get_rk()
|
||||||
|
|
@ -74,7 +84,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()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -117,11 +127,8 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = list(
|
self._lst = self._data.get_specs_for_enabled_reaches(
|
||||||
filter(
|
self._river.edges()
|
||||||
lambda ica: ica._deleted is False,
|
|
||||||
self._data._data
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
|
|
|
||||||
|
|
@ -152,14 +152,14 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||||
self._delegate_reach = ComboBoxDelegate(
|
self._delegate_reach = ComboBoxDelegate(
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
ic_spec_lst=self._data[0]._data,
|
ic_spec_lst=self._data[0],
|
||||||
parent=self,
|
parent=self,
|
||||||
mode="reaches"
|
mode="reaches"
|
||||||
)
|
)
|
||||||
self._delegate_rk = ComboBoxDelegate(
|
self._delegate_rk = ComboBoxDelegate(
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
ic_spec_lst=self._data[0]._data,
|
ic_spec_lst=self._data[0],
|
||||||
parent=self,
|
parent=self,
|
||||||
mode="rk"
|
mode="rk"
|
||||||
)
|
)
|
||||||
|
|
@ -308,7 +308,10 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
if len(self._data[0]._data) == 0 or len(rows) == 0:
|
visible = self._data[0].get_specs_for_enabled_reaches(
|
||||||
|
self._study.river.edges()
|
||||||
|
)
|
||||||
|
if len(visible) == 0 or len(rows) == 0:
|
||||||
self._table_spec.add(0)
|
self._table_spec.add(0)
|
||||||
else:
|
else:
|
||||||
self._table_spec.add(rows[0])
|
self._table_spec.add(rows[0])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue