mirror of https://gitlab.com/pamhyr/pamhyr2
Overlapping intervals: we cannot select rk that is already selected, to avoid the confusion of multiple definitions over the same interval
parent
c0000bb332
commit
9309aa9d2d
|
|
@ -30,7 +30,7 @@ from PyQt5.QtWidgets import (
|
||||||
QDialogButtonBox, QPushButton, QLineEdit,
|
QDialogButtonBox, QPushButton, QLineEdit,
|
||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||||
QComboBox,
|
QComboBox, QMessageBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.Tools.PamhyrTable import PamhyrTableModel
|
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
@ -212,15 +212,28 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||||
|
|
||||||
row = index.row()
|
row = index.row()
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
column_name = self._headers[column]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
new_value = (
|
||||||
|
self._river.edge(value).id
|
||||||
|
if column_name == "reach"
|
||||||
|
else value
|
||||||
|
)
|
||||||
|
if (column_name in ("reach", "rk")
|
||||||
|
and self._overlaps_existing_rk(
|
||||||
|
row, column_name, new_value
|
||||||
|
)):
|
||||||
|
QMessageBox.warning(
|
||||||
|
self._table_view,
|
||||||
|
self._trad["msg_rk_overlap_title"],
|
||||||
|
self._trad["msg_rk_overlap_text"]
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetCommandSpec(
|
SetCommandSpec(
|
||||||
self._data, self._lst, row, self._headers[column],
|
self._data, self._lst, row, column_name, new_value
|
||||||
(self._river.edge(value).id
|
|
||||||
if self._headers[column] == "reach"
|
|
||||||
else value
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -230,6 +243,25 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _overlaps_existing_rk(self, row, column, value):
|
||||||
|
current = self._lst[row]
|
||||||
|
reach = value if column == "reach" else current.reach
|
||||||
|
rk = value if column == "rk" else current.start_rk
|
||||||
|
if reach in (None, -1) or rk is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
rk = float(rk)
|
||||||
|
return any(
|
||||||
|
other is not current
|
||||||
|
and not other.is_deleted()
|
||||||
|
and other.reach == reach
|
||||||
|
and other.start_rk is not None
|
||||||
|
and other.end_rk is not None
|
||||||
|
and min(other.start_rk, other.end_rk) <= rk
|
||||||
|
<= max(other.start_rk, other.end_rk)
|
||||||
|
for other in self._data._data
|
||||||
|
)
|
||||||
|
|
||||||
def add(self, row, parent=QModelIndex()):
|
def add(self, row, parent=QModelIndex()):
|
||||||
self.beginInsertRows(parent, row, row - 1)
|
self.beginInsertRows(parent, row, row - 1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,16 @@ class IcTemperatureTranslate(MainTranslate):
|
||||||
|
|
||||||
self._dict["rk"] = self._dict["unit_rk"]
|
self._dict["rk"] = self._dict["unit_rk"]
|
||||||
|
|
||||||
|
self._dict["msg_rk_overlap_title"] = _translate(
|
||||||
|
"InitialConditionTemperature",
|
||||||
|
"Chainage already used"
|
||||||
|
)
|
||||||
|
self._dict["msg_rk_overlap_text"] = _translate(
|
||||||
|
"InitialConditionTemperature",
|
||||||
|
"An initial temperature condition is already defined at this "
|
||||||
|
"chainage on the selected reach."
|
||||||
|
)
|
||||||
|
|
||||||
self._sub_dict["table_headers"] = {
|
self._sub_dict["table_headers"] = {
|
||||||
"name": self._dict["name"],
|
"name": self._dict["name"],
|
||||||
"temperature": self._dict["unit_temperature"],
|
"temperature": self._dict["unit_temperature"],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue