mirror of https://gitlab.com/pamhyr/pamhyr2
debug adis BC
parent
b72ffe03c3
commit
0b051ad3c6
|
|
@ -200,6 +200,11 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
def pollutant(self):
|
def pollutant(self):
|
||||||
return self._pollutant
|
return self._pollutant
|
||||||
|
|
||||||
|
@pollutant.setter
|
||||||
|
def pollutant(self, pollutant):
|
||||||
|
self._pollutant = pollutant
|
||||||
|
self._status.modified()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
return self._type
|
return self._type
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
||||||
from View.BoundaryConditionsAdisTS.UndoCommand import (
|
from View.BoundaryConditionsAdisTS.UndoCommand import (
|
||||||
SetNodeCommand, SetTypeCommand,
|
SetNodeCommand, SetTypeCommand,
|
||||||
AddCommand, DelCommand,
|
AddCommand, DelCommand, SetPolCommand
|
||||||
)
|
)
|
||||||
from View.BoundaryCondition.translate import BC_types
|
from View.BoundaryCondition.translate import BC_types
|
||||||
|
|
||||||
|
|
@ -74,11 +74,17 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
lst
|
lst
|
||||||
)
|
)
|
||||||
else:
|
elif self._mode == "node":
|
||||||
self.editor.addItems(
|
self.editor.addItems(
|
||||||
[self._trad["not_associated"]] +
|
[self._trad["not_associated"]] +
|
||||||
self._data.nodes_names()
|
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))
|
self.editor.setCurrentText(index.data(Qt.DisplayRole))
|
||||||
return self.editor
|
return self.editor
|
||||||
|
|
@ -121,8 +127,7 @@ class TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if len(self._lst) != 0:
|
if len(self._lst) != 0:
|
||||||
data = list(filter(lambda x: x.pollutant == self._pollutant,
|
data = self._lst
|
||||||
self._lst))
|
|
||||||
else:
|
else:
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
|
|
@ -142,6 +147,11 @@ class TableModel(PamhyrTableModel):
|
||||||
if n is None:
|
if n is None:
|
||||||
return self._trad["not_associated"]
|
return self._trad["not_associated"]
|
||||||
return next(filter(lambda x: x.id == n, self._data._nodes)).name
|
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()
|
return QVariant()
|
||||||
|
|
||||||
|
|
@ -165,7 +175,13 @@ class TableModel(PamhyrTableModel):
|
||||||
self._lst, row, self._data.node(value)
|
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:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,23 @@ class SetTypeCommand(QUndoCommand):
|
||||||
self._bcs[self._index].type = self._new
|
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):
|
class AddCommand(QUndoCommand):
|
||||||
def __init__(self, pollutant, bcs_list, bcs, index):
|
def __init__(self, pollutant, bcs_list, bcs, index):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
|
||||||
|
|
@ -58,15 +58,13 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
||||||
_pamhyr_name = "Boundary conditions AdisTS"
|
_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()
|
trad = BCAdisTSTranslate()
|
||||||
name = (
|
name = (
|
||||||
trad[self._pamhyr_name] +
|
trad[self._pamhyr_name] +
|
||||||
" - " + study.name
|
" - " + study.name
|
||||||
)
|
)
|
||||||
|
|
||||||
self._pollutant = pollutant
|
|
||||||
|
|
||||||
super(BoundaryConditionAdisTSWindow, self).__init__(
|
super(BoundaryConditionAdisTSWindow, self).__init__(
|
||||||
title=name,
|
title=name,
|
||||||
study=study,
|
study=study,
|
||||||
|
|
@ -75,10 +73,12 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
parent=parent
|
parent=parent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._pollutants_lst = self._study._river._Pollutants
|
||||||
|
|
||||||
self._bcs = self._study.river.boundary_conditions_adists
|
self._bcs = self._study.river.boundary_conditions_adists
|
||||||
|
|
||||||
self.setup_table()
|
|
||||||
self.setup_graph()
|
self.setup_graph()
|
||||||
|
self.setup_table()
|
||||||
self.setup_connections()
|
self.setup_connections()
|
||||||
|
|
||||||
self.ui.setWindowTitle(self._title)
|
self.ui.setWindowTitle(self._title)
|
||||||
|
|
@ -96,20 +96,26 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
mode="node",
|
mode="node",
|
||||||
parent=self
|
parent=self
|
||||||
)
|
)
|
||||||
|
self._delegate_pol = ComboBoxDelegate(
|
||||||
|
trad=self._trad,
|
||||||
|
data=self._study.river,
|
||||||
|
mode="pol",
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
|
|
||||||
table = self.find(QTableView, f"tableView")
|
table = self.find(QTableView, f"tableView")
|
||||||
self._table = TableModel(
|
self._table = TableModel(
|
||||||
table_view=table,
|
table_view=table,
|
||||||
table_headers=self._trad.get_dict("table_headers"),
|
table_headers=self._trad.get_dict("table_headers"),
|
||||||
editable_headers=["type", "node"],
|
editable_headers=["type", "node", "pol"],
|
||||||
delegates={
|
delegates={
|
||||||
"type": self._delegate_type,
|
"type": self._delegate_type,
|
||||||
"node": self._delegate_node,
|
"node": self._delegate_node,
|
||||||
|
"pol": self._delegate_pol,
|
||||||
},
|
},
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
bc_list=self._study.river.boundary_conditions_adists,
|
bc_list=self._study.river.boundary_conditions_adists,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
pollutant=self._pollutant,
|
|
||||||
data=self._study.river
|
data=self._study.river
|
||||||
)
|
)
|
||||||
table.setModel(self._table)
|
table.setModel(self._table)
|
||||||
|
|
@ -120,7 +126,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
def setup_graph(self):
|
def setup_graph(self):
|
||||||
self.graph_widget = GraphWidget(
|
self.graph_widget = GraphWidget(
|
||||||
self._study.river,
|
self._study.river,
|
||||||
min_size=None, size=(200, 200),
|
min_size=None, size=(150, 200),
|
||||||
only_display=True,
|
only_display=True,
|
||||||
parent=self
|
parent=self
|
||||||
)
|
)
|
||||||
|
|
@ -133,8 +139,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||||
|
|
||||||
def index_selected_row(self):
|
def index_selected_row(self):
|
||||||
tab = "liquid"
|
table = self.find(QTableView, f"tableView")
|
||||||
table = self.find(QTableView, f"tableView_{tab}")
|
|
||||||
return table.selectionModel()\
|
return table.selectionModel()\
|
||||||
.selectedRows()[0]\
|
.selectedRows()[0]\
|
||||||
.row()
|
.row()
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,6 @@ class BCAdisTSTranslate(MainTranslate):
|
||||||
|
|
||||||
self._sub_dict["table_headers"] = {
|
self._sub_dict["table_headers"] = {
|
||||||
"type": self._dict["type"],
|
"type": self._dict["type"],
|
||||||
"node": _translate("BoundaryCondition", "Node")
|
"node": _translate("BoundaryCondition", "Node"),
|
||||||
|
"pol": _translate("BoundaryCondition", "Pollutant")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
if len(self._pollutants_lst) == 0 or len(rows) == 0:
|
if len(self._pollutants_lst) == 0 or len(rows) == 0:
|
||||||
self._table.add(0)
|
self._table.add(0)
|
||||||
else:
|
else:
|
||||||
self._table.add(rows[0])
|
self._table.add(rows[-1])
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
|
|
@ -227,16 +227,16 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
BoundaryConditionAdisTSWindow,
|
BoundaryConditionAdisTSWindow,
|
||||||
data=[self._study, None, pollutant_id]
|
data=[self._study, None]
|
||||||
):
|
):
|
||||||
bound = self.get_sub_window(
|
bound = self.get_sub_window(
|
||||||
BoundaryConditionAdisTSWindow,
|
BoundaryConditionAdisTSWindow,
|
||||||
data=[self._study, None, pollutant_id]
|
data=[self._study, None]
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
bound = BoundaryConditionAdisTSWindow(
|
bound = BoundaryConditionAdisTSWindow(
|
||||||
study=self._study, pollutant=pollutant_id, parent=self
|
study=self._study, parent=self
|
||||||
)
|
)
|
||||||
bound.show()
|
bound.show()
|
||||||
|
|
||||||
|
|
@ -248,14 +248,14 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
LateralContributionAdisTSWindow,
|
LateralContributionAdisTSWindow,
|
||||||
data=[self._study, None, pollutant_id]
|
data=[self._study, pollutant_id, None]
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
lateral = LateralContributionAdisTSWindow(
|
lateral = LateralContributionAdisTSWindow(
|
||||||
study=self._study,
|
study=self._study,
|
||||||
parent=self,
|
pollutant=pollutant_id,
|
||||||
pollutant=pollutant_id
|
parent=self
|
||||||
)
|
)
|
||||||
lateral.show()
|
lateral.show()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,14 @@
|
||||||
<widget class="QWidget" name="verticalLayoutWidget_2">
|
<widget class="QWidget" name="verticalLayoutWidget_2">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue