mirror of https://gitlab.com/pamhyr/pamhyr2
update model + view to display only BCAdisTS related to pollutant, and not the global list, todo: reconnect add/del buttons
parent
63836527c7
commit
23361d142e
|
|
@ -312,6 +312,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
status = data['status']
|
status = data['status']
|
||||||
nodes = data['nodes']
|
nodes = data['nodes']
|
||||||
scenario = data["scenario"]
|
scenario = data["scenario"]
|
||||||
|
pollutant = data["pollutant"]
|
||||||
loaded = data['loaded_pid']
|
loaded = data['loaded_pid']
|
||||||
|
|
||||||
if scenario is None:
|
if scenario is None:
|
||||||
|
|
@ -321,7 +322,8 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario " +
|
"SELECT pamhyr_id, deleted, pollutant, type, node, scenario " +
|
||||||
"FROM boundary_condition_adists " +
|
"FROM boundary_condition_adists " +
|
||||||
f"WHERE scenario = {scenario.id} " +
|
f"WHERE scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) "
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
|
||||||
|
f"AND pollutant = {pollutant.id} "
|
||||||
)
|
)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ from tools import (
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
from Model.Scenario import Scenario
|
from Model.Scenario import Scenario
|
||||||
|
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
@ -275,7 +276,8 @@ class PollutantCharacteristics(SQLSubModel):
|
||||||
|
|
||||||
|
|
||||||
class Pollutants(SQLSubModel):
|
class Pollutants(SQLSubModel):
|
||||||
_sub_classes = [PollutantCharacteristics]
|
_sub_classes = [PollutantCharacteristics,
|
||||||
|
BoundaryConditionAdisTS]
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "",
|
def __init__(self, id: int = -1, name: str = "",
|
||||||
status=None, owner_scenario=-1):
|
status=None, owner_scenario=-1):
|
||||||
|
|
@ -293,6 +295,11 @@ class Pollutants(SQLSubModel):
|
||||||
self._enabled = True
|
self._enabled = True
|
||||||
|
|
||||||
self._data = []
|
self._data = []
|
||||||
|
self._boundary_conditions_adists = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def boundary_conditions_adists(self):
|
||||||
|
return self._boundary_conditions_adists
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|
@ -416,6 +423,10 @@ class Pollutants(SQLSubModel):
|
||||||
execute, data=data
|
execute, data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
new_pollutant._boundary_conditions_adists = BoundaryConditionAdisTS._db_load(
|
||||||
|
execute, data=data
|
||||||
|
)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(new_pollutant)
|
new.append(new_pollutant)
|
||||||
|
|
||||||
|
|
@ -455,6 +466,9 @@ class Pollutants(SQLSubModel):
|
||||||
for d in self._data:
|
for d in self._data:
|
||||||
ok &= d._db_save(execute, data)
|
ok &= d._db_save(execute, data)
|
||||||
|
|
||||||
|
for bc in self._boundary_conditions_adists:
|
||||||
|
ok &= bc._db_save(execute, data)
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
def _data_traversal(self,
|
def _data_traversal(self,
|
||||||
|
|
|
||||||
|
|
@ -112,18 +112,21 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
|
|
||||||
|
|
||||||
class TableModel(PamhyrTableModel):
|
class TableModel(PamhyrTableModel):
|
||||||
def __init__(self, pollutant=None, bc_list=None, trad=None, **kwargs):
|
def __init__(self, bc_list=None, pollutant_bc_list=None, trad=None, **kwargs):
|
||||||
self._trad = trad
|
self._trad = trad
|
||||||
self._bc_list = bc_list
|
self._bc_list = bc_list
|
||||||
self._pollutant = pollutant
|
self._pollutant = pollutant_bc_list.id
|
||||||
|
self._pollutant_bc_list = pollutant_bc_list
|
||||||
|
|
||||||
super(TableModel, self).__init__(trad=trad, **kwargs)
|
super(TableModel, self).__init__(trad=trad, **kwargs)
|
||||||
|
|
||||||
|
def _setup_lst(self):
|
||||||
|
self._lst = self._pollutant_bc_list.boundary_conditions_adists
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self._bc_list)
|
return len(self._lst)
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
|
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
|
@ -131,12 +134,12 @@ class TableModel(PamhyrTableModel):
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
||||||
if self._headers[column] == "type":
|
if self._headers[column] == "type":
|
||||||
n = self._bc_list.get(row).type
|
n = self._lst[row].type
|
||||||
if n is None or n == "":
|
if n is None or n == "":
|
||||||
return self._trad["not_associated"]
|
return self._trad["not_associated"]
|
||||||
return n
|
return n
|
||||||
elif self._headers[column] == "node":
|
elif self._headers[column] == "node":
|
||||||
n = self._bc_list.get(row).node
|
n = self._lst[row].node
|
||||||
if n is None:
|
if n is None:
|
||||||
return self._trad["not_associated"]
|
return self._trad["not_associated"]
|
||||||
tmp = next(filter(lambda x: x.id == n, self._data._nodes), None)
|
tmp = next(filter(lambda x: x.id == n, self._data._nodes), None)
|
||||||
|
|
@ -144,18 +147,6 @@ class TableModel(PamhyrTableModel):
|
||||||
return tmp.name
|
return tmp.name
|
||||||
else:
|
else:
|
||||||
return self._trad["not_associated"]
|
return self._trad["not_associated"]
|
||||||
elif self._headers[column] == "pol":
|
|
||||||
n = self._bc_list.get(row).pollutant
|
|
||||||
if n is None or n == "not_associated" or n == "":
|
|
||||||
return self._trad["not_associated"]
|
|
||||||
tmp = next(filter(lambda x: x.id == n,
|
|
||||||
self._data._Pollutants.Pollutants_List
|
|
||||||
),
|
|
||||||
None)
|
|
||||||
if tmp is not None:
|
|
||||||
return tmp.name
|
|
||||||
else:
|
|
||||||
return self._trad["not_associated"]
|
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
|
@ -179,22 +170,7 @@ class TableModel(PamhyrTableModel):
|
||||||
self._bc_list, row, self._data.node(value)
|
self._bc_list, row, self._data.node(value)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "pol":
|
|
||||||
if value == self._trad["not_associated"]:
|
|
||||||
self._undo.push(
|
|
||||||
SetPolCommand(
|
|
||||||
self._bc_list, row, None
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
pol = next(filter(lambda x: x.name == value,
|
|
||||||
self._data._Pollutants.Pollutants_List)
|
|
||||||
)
|
|
||||||
self._undo.push(
|
|
||||||
SetPolCommand(
|
|
||||||
self._bc_list, 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())
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,21 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
_pamhyr_ui = "BoundaryConditionsAdisTS"
|
||||||
_pamhyr_name = "Boundary conditions AdisTS"
|
_pamhyr_name = "Boundary conditions AdisTS"
|
||||||
|
|
||||||
def __init__(self, study=None, config=None, parent=None):
|
def __init__(self, data=None, pollutant_id=None, study=None, config=None, parent=None):
|
||||||
|
self._data = data
|
||||||
|
self._pollutant_id = pollutant_id
|
||||||
|
|
||||||
|
_pollutants_lst = study._river._Pollutants.Pollutants_List
|
||||||
|
self._pollutant_name = next(
|
||||||
|
(x.name for x in _pollutants_lst if x.id == self._pollutant_id),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
trad = BCAdisTSTranslate()
|
trad = BCAdisTSTranslate()
|
||||||
name = (
|
name = (
|
||||||
trad[self._pamhyr_name] +
|
trad[self._pamhyr_name] +
|
||||||
" - " + study.name
|
" - " + study.name +
|
||||||
|
" - " + self._pollutant_name
|
||||||
)
|
)
|
||||||
|
|
||||||
super(BoundaryConditionAdisTSWindow, self).__init__(
|
super(BoundaryConditionAdisTSWindow, self).__init__(
|
||||||
|
|
@ -73,7 +83,6 @@ 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_graph()
|
self.setup_graph()
|
||||||
|
|
@ -95,12 +104,6 @@ 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(
|
||||||
|
|
@ -110,10 +113,10 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
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,
|
||||||
|
pollutant_bc_list=self._data,
|
||||||
undo=self._undo_stack,
|
undo=self._undo_stack,
|
||||||
data=self._study.river
|
data=self._study.river
|
||||||
)
|
)
|
||||||
|
|
@ -156,7 +159,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
)
|
)
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
self._table.add(len(self._bcs))
|
self._table.add(len(self._data.boundary_conditions_adists))
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
rows = self.index_selected_rows()
|
rows = self.index_selected_rows()
|
||||||
|
|
|
||||||
|
|
@ -34,5 +34,4 @@ 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")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -222,19 +222,30 @@ class PollutantsWindow(PamhyrWindow):
|
||||||
initial.show()
|
initial.show()
|
||||||
|
|
||||||
def boundary_conditions(self):
|
def boundary_conditions(self):
|
||||||
|
rows = self.index_selected_rows()
|
||||||
|
if len(rows) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
for row in rows:
|
||||||
|
pollutant_id = self._pollutants_lst.get(row).id
|
||||||
|
|
||||||
|
bclist = self._study.river.boundary_conditions_adists.BCs_AdisTS_List
|
||||||
|
bcs_adists = [
|
||||||
|
x for x in bclist
|
||||||
|
if x.pollutant == pollutant_id
|
||||||
|
]
|
||||||
|
self._data = self._study.river.Pollutants.get(row)
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
BoundaryConditionAdisTSWindow,
|
BoundaryConditionAdisTSWindow,
|
||||||
data=[self._study, None]
|
data=[self._study, None, bcs_adists]
|
||||||
):
|
):
|
||||||
bound = self.get_sub_window(
|
|
||||||
BoundaryConditionAdisTSWindow,
|
|
||||||
data=[self._study, None]
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
bound = BoundaryConditionAdisTSWindow(
|
bound = BoundaryConditionAdisTSWindow(
|
||||||
study=self._study, parent=self
|
study=self._study,
|
||||||
|
parent=self,
|
||||||
|
data=self._data,
|
||||||
|
pollutant_id=pollutant_id
|
||||||
)
|
)
|
||||||
bound.show()
|
bound.show()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue