debug adis BC

adists_release
Theophile Terraz 2024-12-05 13:38:22 +01:00
parent b72ffe03c3
commit 0b051ad3c6
7 changed files with 74 additions and 23 deletions

View File

@ -200,6 +200,11 @@ class BoundaryConditionAdisTS(SQLSubModel):
def pollutant(self):
return self._pollutant
@pollutant.setter
def pollutant(self, pollutant):
self._pollutant = pollutant
self._status.modified()
@property
def type(self):
return self._type

View File

@ -43,7 +43,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
from View.BoundaryConditionsAdisTS.UndoCommand import (
SetNodeCommand, SetTypeCommand,
AddCommand, DelCommand,
AddCommand, DelCommand, SetPolCommand
)
from View.BoundaryCondition.translate import BC_types
@ -74,11 +74,17 @@ class ComboBoxDelegate(QItemDelegate):
self.editor.addItems(
lst
)
else:
elif self._mode == "node":
self.editor.addItems(
[self._trad["not_associated"]] +
self._data.nodes_names()
)
elif self._mode == "pol":
lst = [p.name for p in self._data._Pollutants.Pollutants_List]
self.editor.addItems(
[self._trad["not_associated"]] +
lst
)
self.editor.setCurrentText(index.data(Qt.DisplayRole))
return self.editor
@ -121,8 +127,7 @@ class TableModel(PamhyrTableModel):
def data(self, index, role):
if len(self._lst) != 0:
data = list(filter(lambda x: x.pollutant == self._pollutant,
self._lst))
data = self._lst
else:
data = []
@ -142,6 +147,11 @@ class TableModel(PamhyrTableModel):
if n is None:
return self._trad["not_associated"]
return next(filter(lambda x: x.id == n, self._data._nodes)).name
elif self._headers[column] == "pol":
n = data[row].pollutant
if n is None or n == "not_associated" or n == "":
return self._trad["not_associated"]
return self._data._Pollutants.Pollutants_List[n].name
return QVariant()
@ -165,7 +175,13 @@ class TableModel(PamhyrTableModel):
self._lst, row, self._data.node(value)
)
)
print(value, self._data.node(value).id)
elif self._headers[column] == "pol":
pol = next(filter(lambda x: x.name == value, self._data._Pollutants.Pollutants_List))
self._undo.push(
SetPolCommand(
self._lst, row, pol.id
)
)
except Exception as e:
logger.info(e)
logger.debug(traceback.format_exc())

View File

@ -62,6 +62,23 @@ class SetTypeCommand(QUndoCommand):
self._bcs[self._index].type = self._new
class SetPolCommand(QUndoCommand):
def __init__(self, bcs, index, pollutant):
QUndoCommand.__init__(self)
self._bcs = bcs
self._index = index
self._pollutant = pollutant
self._old = self._bcs[self._index].pollutant
self._new = self._pollutant
def undo(self):
self._bcs[self._index].pollutant = self._old
def redo(self):
self._bcs[self._index].pollutant = self._new
class AddCommand(QUndoCommand):
def __init__(self, pollutant, bcs_list, bcs, index):
QUndoCommand.__init__(self)

View File

@ -58,15 +58,13 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
_pamhyr_ui = "BoundaryConditionsAdisTS"
_pamhyr_name = "Boundary conditions AdisTS"
def __init__(self, pollutant=None, study=None, config=None, parent=None):
def __init__(self, study=None, config=None, parent=None):
trad = BCAdisTSTranslate()
name = (
trad[self._pamhyr_name] +
" - " + study.name
)
self._pollutant = pollutant
super(BoundaryConditionAdisTSWindow, self).__init__(
title=name,
study=study,
@ -75,10 +73,12 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
parent=parent
)
self._pollutants_lst = self._study._river._Pollutants
self._bcs = self._study.river.boundary_conditions_adists
self.setup_table()
self.setup_graph()
self.setup_table()
self.setup_connections()
self.ui.setWindowTitle(self._title)
@ -96,20 +96,26 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
mode="node",
parent=self
)
self._delegate_pol = ComboBoxDelegate(
trad=self._trad,
data=self._study.river,
mode="pol",
parent=self
)
table = self.find(QTableView, f"tableView")
self._table = TableModel(
table_view=table,
table_headers=self._trad.get_dict("table_headers"),
editable_headers=["type", "node"],
editable_headers=["type", "node", "pol"],
delegates={
"type": self._delegate_type,
"node": self._delegate_node,
"pol": self._delegate_pol,
},
trad=self._trad,
bc_list=self._study.river.boundary_conditions_adists,
undo=self._undo_stack,
pollutant=self._pollutant,
data=self._study.river
)
table.setModel(self._table)
@ -120,7 +126,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
def setup_graph(self):
self.graph_widget = GraphWidget(
self._study.river,
min_size=None, size=(200, 200),
min_size=None, size=(150, 200),
only_display=True,
parent=self
)
@ -133,8 +139,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
self.find(QAction, "action_edit").triggered.connect(self.edit)
def index_selected_row(self):
tab = "liquid"
table = self.find(QTableView, f"tableView_{tab}")
table = self.find(QTableView, f"tableView")
return table.selectionModel()\
.selectedRows()[0]\
.row()

View File

@ -33,5 +33,6 @@ class BCAdisTSTranslate(MainTranslate):
self._sub_dict["table_headers"] = {
"type": self._dict["type"],
"node": _translate("BoundaryCondition", "Node")
"node": _translate("BoundaryCondition", "Node"),
"pol": _translate("BoundaryCondition", "Pollutant")
}

View File

@ -158,7 +158,7 @@ class PollutantsWindow(PamhyrWindow):
if len(self._pollutants_lst) == 0 or len(rows) == 0:
self._table.add(0)
else:
self._table.add(rows[0])
self._table.add(rows[-1])
def delete(self):
rows = self.index_selected_rows()
@ -227,16 +227,16 @@ class PollutantsWindow(PamhyrWindow):
if self.sub_window_exists(
BoundaryConditionAdisTSWindow,
data=[self._study, None, pollutant_id]
data=[self._study, None]
):
bound = self.get_sub_window(
BoundaryConditionAdisTSWindow,
data=[self._study, None, pollutant_id]
data=[self._study, None]
)
return
bound = BoundaryConditionAdisTSWindow(
study=self._study, pollutant=pollutant_id, parent=self
study=self._study, parent=self
)
bound.show()
@ -248,14 +248,14 @@ class PollutantsWindow(PamhyrWindow):
if self.sub_window_exists(
LateralContributionAdisTSWindow,
data=[self._study, None, pollutant_id]
data=[self._study, pollutant_id, None]
):
return
lateral = LateralContributionAdisTSWindow(
study=self._study,
parent=self,
pollutant=pollutant_id
pollutant=pollutant_id,
parent=self
)
lateral.show()

View File

@ -32,7 +32,14 @@
<widget class="QWidget" name="verticalLayoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTableView" name="tableView"/>
<widget class="QTableView" name="tableView">
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>