mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Overlapping intervals: we cannot select rk if the interval overlaps anohter one, to avoid the confusion of multiple definitions over the same interval for WeatherParameters
This commit is contained in:
1 parent
9309aa9d2d
commit
50fa4f7bd8
2 files changed
+65
-2
No files matched your search
@@ -30,7 +30,7 @@ from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QComboBox,
|
||||
QComboBox, QMessageBox,
|
||||
)
|
||||
|
||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
@@ -222,6 +222,10 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||
p for p in _edge.reach.profiles
|
||||
if p.pamhyr_id == value
|
||||
)
|
||||
if self._overlaps_existing_interval(
|
||||
row, begin_section=_begin_rk):
|
||||
self._show_overlap_warning()
|
||||
return False
|
||||
self._undo.push(
|
||||
SetBeginCommand(
|
||||
self._data, global_row, _begin_rk
|
||||
@@ -233,15 +237,24 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||
p for p in _edge.reach.profiles
|
||||
if p.pamhyr_id == value
|
||||
)
|
||||
if self._overlaps_existing_interval(
|
||||
row, end_section=_end_rk):
|
||||
self._show_overlap_warning()
|
||||
return False
|
||||
self._undo.push(
|
||||
SetEndCommand(
|
||||
self._data, global_row, _end_rk
|
||||
)
|
||||
)
|
||||
elif self._headers[column] == "reach":
|
||||
new_reach = self._river.edge(value)
|
||||
if self._overlaps_existing_interval(
|
||||
row, reach=new_reach):
|
||||
self._show_overlap_warning()
|
||||
return False
|
||||
self._undo.push(
|
||||
SetEdgeCommand(
|
||||
self._data, global_row, self._river.edge(value)
|
||||
self._data, global_row, new_reach
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
@@ -251,6 +264,48 @@ class WeatherParametersTableModel(PamhyrTableModel):
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def _overlaps_existing_interval(self, row, reach=None,
|
||||
begin_section=None, end_section=None):
|
||||
current = self._lst[row]
|
||||
reach = current.reach if reach is None else reach
|
||||
if reach is None:
|
||||
return False
|
||||
|
||||
if begin_section is None:
|
||||
begin_section = (
|
||||
reach.reach.profiles[0]
|
||||
if reach is not current.reach and reach.reach.profiles
|
||||
else current.begin_section
|
||||
)
|
||||
if end_section is None:
|
||||
end_section = (
|
||||
reach.reach.profiles[-1]
|
||||
if reach is not current.reach and reach.reach.profiles
|
||||
else current.end_section
|
||||
)
|
||||
if begin_section is None or end_section is None:
|
||||
return False
|
||||
|
||||
lower, upper = sorted((begin_section.rk, end_section.rk))
|
||||
return any(
|
||||
other is not current
|
||||
and not other.is_deleted()
|
||||
and other.type == current.type
|
||||
and other.reach is reach
|
||||
and other.begin_section is not None
|
||||
and other.end_section is not None
|
||||
and max(lower, min(other.begin_rk, other.end_rk))
|
||||
< min(upper, max(other.begin_rk, other.end_rk))
|
||||
for other in self._data.lst
|
||||
)
|
||||
|
||||
def _show_overlap_warning(self):
|
||||
QMessageBox.warning(
|
||||
self._table_view,
|
||||
self._trad["msg_rk_overlap_title"],
|
||||
self._trad["msg_rk_overlap_text"]
|
||||
)
|
||||
|
||||
def add(self, row, parent=QModelIndex()):
|
||||
self.beginInsertRows(parent, row, row)
|
||||
|
||||
|
||||
@@ -41,6 +41,14 @@ class WeatherParametersTranslate(MainTranslate):
|
||||
"These values are applied to sections that have not been "
|
||||
"defined using time series."
|
||||
)
|
||||
self._dict["msg_rk_overlap_title"] = _translate(
|
||||
"WeatherParameters", "Overlapping interval"
|
||||
)
|
||||
self._dict["msg_rk_overlap_text"] = _translate(
|
||||
"WeatherParameters",
|
||||
"Two weather-parameter intervals of the same type cannot "
|
||||
"overlap on the same reach."
|
||||
)
|
||||
|
||||
self._dict["rk"] = self._dict["unit_rk"]
|
||||
|
||||
|
||||
Reference in new issue
Block a user