mirror of https://gitlab.com/pamhyr/pamhyr2
refactoring: Update BC.
parent
dbc256be1a
commit
245a5057c3
|
|
@ -27,7 +27,7 @@ from PyQt5.QtCore import (
|
|||
QCoreApplication
|
||||
)
|
||||
|
||||
from View.BoundaryCondition.Edit.translate import *
|
||||
from View.BoundaryCondition.Edit.translate import BCETranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
|
@ -42,6 +42,8 @@ class Plot(APlot):
|
|||
toolbar=toolbar
|
||||
)
|
||||
|
||||
self._trad = BCETranslate()
|
||||
self._table_headers = self._trad.get_dict("table_headers")
|
||||
self._mode = mode
|
||||
|
||||
def custom_ticks(self):
|
||||
|
|
@ -109,10 +111,10 @@ class Plot(APlot):
|
|||
# Plot label
|
||||
header = self.data.header
|
||||
self.canvas.axes.set_xlabel(
|
||||
table_headers[header[0]], color='black', fontsize=10
|
||||
self._table_headers[header[0]], color='black', fontsize=10
|
||||
)
|
||||
self.canvas.axes.set_ylabel(
|
||||
table_headers[header[1]], color='black', fontsize=10
|
||||
self._table_headers[header[1]], color='black', fontsize=10
|
||||
)
|
||||
|
||||
self.canvas.axes.autoscale_view(True, True, True)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ from View.BoundaryCondition.Edit.UndoCommand import (
|
|||
SortCommand, MoveCommand, PasteCommand,
|
||||
DuplicateCommand,
|
||||
)
|
||||
from View.BoundaryCondition.Edit.translate import *
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ from PyQt5.QtWidgets import (
|
|||
from View.Plot.MplCanvas import MplCanvas
|
||||
from View.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
from View.BoundaryCondition.translate import long_types
|
||||
from View.BoundaryCondition.Edit.translate import table_headers, retranslate
|
||||
from View.BoundaryCondition.Edit.translate import BCETranslate
|
||||
from View.BoundaryCondition.Edit.UndoCommand import SetMetaDataCommand
|
||||
from View.BoundaryCondition.Edit.Table import TableModel
|
||||
from View.BoundaryCondition.Edit.Plot import Plot
|
||||
|
|
@ -101,6 +100,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
|||
|
||||
def __init__(self, data=None, study=None, config=None, parent=None):
|
||||
self._data = data
|
||||
trad = BCETranslate()
|
||||
self._long_types = trad.get_dict("long_types")
|
||||
|
||||
name = self._pamhyr_name
|
||||
if self._data is not None:
|
||||
|
|
@ -110,13 +111,14 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
|||
_translate("Edit boundary condition", self._pamhyr_name) +
|
||||
f" - {study.name} " +
|
||||
f" - {self._data.name} ({self._data.id}) " +
|
||||
f"({long_types[self._data.bctype]} - {node_name})"
|
||||
f"({self._long_types[self._data.bctype]} - {node_name})"
|
||||
)
|
||||
|
||||
super(EditBoundaryConditionWindow, self).__init__(
|
||||
title = name,
|
||||
study = study,
|
||||
config = config,
|
||||
trad = trad,
|
||||
parent = parent
|
||||
)
|
||||
|
||||
|
|
@ -139,8 +141,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
|||
self._d50sigma.set_sigma(self._data.sigma)
|
||||
|
||||
def setup_table(self):
|
||||
retranslate()
|
||||
headers = {}
|
||||
table_headers = self._trad.get_dict("table_headers")
|
||||
for h in self._data.header:
|
||||
headers[h] = table_headers[h]
|
||||
|
||||
|
|
|
|||
|
|
@ -18,23 +18,22 @@
|
|||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Tools.PamhyrTranslate import PamhyrTranslate
|
||||
|
||||
from View.BoundaryCondition.translate import BCTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
table_headers = {
|
||||
"x": _translate("BoundaryCondition", "X"),
|
||||
"y": _translate("BoundaryCondition", "Y"),
|
||||
"time": _translate("BoundaryCondition", "Time"),
|
||||
"date": _translate("BoundaryCondition", "Date"),
|
||||
"discharge": _translate("BoundaryCondition", "Discharge (m³/s)"),
|
||||
"z": _translate("BoundaryCondition", "Z (m)"),
|
||||
"solid": _translate("BoundaryCondition", "Solid (kg/s)"),
|
||||
}
|
||||
class BCETranslate(BCTranslate):
|
||||
def __init__(self):
|
||||
super(BCETranslate, self).__init__()
|
||||
|
||||
def retranslate():
|
||||
table_headers["x"] = _translate("BoundaryCondition", "X")
|
||||
table_headers["y"] = _translate("BoundaryCondition", "Y")
|
||||
table_headers["time"] = _translate("BoundaryCondition", "Time")
|
||||
table_headers["date"] = _translate("BoundaryCondition", "Date")
|
||||
table_headers["discharge"] = _translate("BoundaryCondition", "Discharge (m³/s)")
|
||||
table_headers["z"] = _translate("BoundaryCondition", "Z (m)")
|
||||
table_headers["solid"] = _translate("BoundaryCondition", "Solid (kg/s)")
|
||||
self._sub_dict["table_headers"] = {
|
||||
"x": _translate("BoundaryCondition", "X"),
|
||||
"y": _translate("BoundaryCondition", "Y"),
|
||||
"time": _translate("BoundaryCondition", "Time"),
|
||||
"date": _translate("BoundaryCondition", "Date"),
|
||||
"discharge": _translate("BoundaryCondition", "Discharge (m³/s)"),
|
||||
"z": _translate("BoundaryCondition", "Z (m)"),
|
||||
"solid": _translate("BoundaryCondition", "Solid (kg/s)"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,19 +46,24 @@ from View.BoundaryCondition.UndoCommand import (
|
|||
AddCommand, DelCommand, SortCommand,
|
||||
MoveCommand, PasteCommand, DuplicateCommand,
|
||||
)
|
||||
from View.BoundaryCondition.translate import *
|
||||
from View.BoundaryCondition.translate import BC_types
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
class ComboBoxDelegate(QItemDelegate):
|
||||
def __init__(self, data=None, mode="type", tab="", parent=None):
|
||||
def __init__(self, data=None, mode="type", tab="", trad=None, parent=None):
|
||||
super(ComboBoxDelegate, self).__init__(parent)
|
||||
|
||||
self._data = data
|
||||
self._mode = mode
|
||||
self._tab = tab
|
||||
self._trad = trad
|
||||
|
||||
self._long_types = {}
|
||||
if self._trad is not None:
|
||||
self._long_types = self._trad.get_dict("long_types")
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
self.editor = QComboBox(parent)
|
||||
|
|
@ -66,7 +71,7 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
if self._mode == "type":
|
||||
lst = list(
|
||||
map(
|
||||
lambda k: long_types[k],
|
||||
lambda k: self._long_types[k],
|
||||
filter(
|
||||
lambda k: self._tab in BC_types[k].compatibility(),
|
||||
BC_types.keys()
|
||||
|
|
@ -107,6 +112,13 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def __init__(self, **kwargs):
|
||||
super(TableModel, self).__init__(**kwargs)
|
||||
|
||||
self._long_types = {}
|
||||
if self._trad is not None:
|
||||
self._long_types = self._trad.get_dict("long_types")
|
||||
|
||||
def _setup_lst(self):
|
||||
self._lst = self._data.boundary_condition
|
||||
self._tab = self._opt_data
|
||||
|
|
@ -125,7 +137,7 @@ class TableModel(PamhyrTableModel):
|
|||
return self._lst.get(self._tab, row).name
|
||||
elif self._headers[column] == "type":
|
||||
t = self._lst.get(self._tab, row).bctype
|
||||
return long_types[t]
|
||||
return self._long_types[t]
|
||||
elif self._headers[column] == "node":
|
||||
n = self._lst.get(self._tab, row).node
|
||||
if n is None:
|
||||
|
|
@ -149,7 +161,7 @@ class TableModel(PamhyrTableModel):
|
|||
)
|
||||
)
|
||||
elif self._headers[column] == "type":
|
||||
key = next(k for k, v in long_types.items() if v == value)
|
||||
key = next(k for k, v in self._long_types.items() if v == value)
|
||||
self._undo.push(
|
||||
SetTypeCommand(
|
||||
self._lst, self._tab,row, BC_types[key]
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ from View.BoundaryCondition.Table import (
|
|||
)
|
||||
|
||||
from View.Network.GraphWidget import GraphWidget
|
||||
from View.BoundaryCondition.translate import table_headers, retranslate
|
||||
from View.BoundaryCondition.translate import BCTranslate
|
||||
from View.BoundaryCondition.Edit.Window import EditBoundaryConditionWindow
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
|
@ -73,6 +73,7 @@ class BoundaryConditionWindow(PamhyrWindow):
|
|||
title = name,
|
||||
study = study,
|
||||
config = config,
|
||||
trad = BCTranslate(),
|
||||
parent=parent
|
||||
)
|
||||
|
||||
|
|
@ -85,17 +86,18 @@ class BoundaryConditionWindow(PamhyrWindow):
|
|||
self.ui.setWindowTitle(self._title)
|
||||
|
||||
def setup_table(self):
|
||||
retranslate()
|
||||
self._table = {}
|
||||
|
||||
for t in ["liquid", "solid", "suspenssion"]:
|
||||
self._delegate_type = ComboBoxDelegate(
|
||||
trad = self._trad,
|
||||
data = self._study.river,
|
||||
mode = "type",
|
||||
tab = t,
|
||||
parent=self
|
||||
)
|
||||
self._delegate_node = ComboBoxDelegate(
|
||||
trad = self._trad,
|
||||
data = self._study.river,
|
||||
mode = "node",
|
||||
tab = t,
|
||||
|
|
@ -105,12 +107,13 @@ class BoundaryConditionWindow(PamhyrWindow):
|
|||
table = self.find(QTableView, f"tableView_{t}")
|
||||
self._table[t] = TableModel(
|
||||
table_view = table,
|
||||
table_headers = table_headers,
|
||||
table_headers = self._trad.get_dict("table_headers"),
|
||||
editable_headers = ["name", "type", "node"],
|
||||
delegates = {
|
||||
"type": self._delegate_type,
|
||||
"node": self._delegate_node,
|
||||
},
|
||||
trad = self._trad,
|
||||
data = self._study.river,
|
||||
undo = self._undo_stack,
|
||||
opt_data = t,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
from PyQt5.QtCore import QCoreApplication
|
||||
|
||||
from View.Tools.PamhyrTranslate import PamhyrTranslate
|
||||
|
||||
from Model.BoundaryCondition.BoundaryConditionTypes import (
|
||||
NotDefined, PonctualContribution,
|
||||
TimeOverZ, TimeOverDischarge, ZOverDischarge,
|
||||
|
|
@ -26,21 +28,6 @@ from Model.BoundaryCondition.BoundaryConditionTypes import (
|
|||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
long_types = {
|
||||
"ND": _translate("BoundaryCondition", "Not defined"),
|
||||
"PC": _translate("BoundaryCondition", "Ponctual contribution"),
|
||||
"TZ": _translate("BoundaryCondition", "TimeZ"),
|
||||
"TD": _translate("BoundaryCondition", "TimeDischarge"),
|
||||
"ZD": _translate("BoundaryCondition", "ZDischarge"),
|
||||
"SL": _translate("BoundaryCondition", "Solid"),
|
||||
}
|
||||
|
||||
table_headers = {
|
||||
"name": _translate("BoundaryCondition", "Name"),
|
||||
"type": _translate("BoundaryCondition", "Type"),
|
||||
"node": _translate("BoundaryCondition", "Node")
|
||||
}
|
||||
|
||||
BC_types = {
|
||||
"ND": NotDefined,
|
||||
"PC": PonctualContribution,
|
||||
|
|
@ -50,7 +37,21 @@ BC_types = {
|
|||
"SL": Solid,
|
||||
}
|
||||
|
||||
def retranslate():
|
||||
table_headers["name"] = _translate("BoundaryCondition", "Name")
|
||||
table_headers["type"] = _translate("BoundaryCondition", "Type")
|
||||
table_headers["node"] = _translate("BoundaryCondition", "Node")
|
||||
class BCTranslate(PamhyrTranslate):
|
||||
def __init__(self):
|
||||
super(BCTranslate, self).__init__()
|
||||
|
||||
self._sub_dict["long_types"] = {
|
||||
"ND": _translate("BoundaryCondition", "Not defined"),
|
||||
"PC": _translate("BoundaryCondition", "Ponctual contribution"),
|
||||
"TZ": _translate("BoundaryCondition", "TimeZ"),
|
||||
"TD": _translate("BoundaryCondition", "TimeDischarge"),
|
||||
"ZD": _translate("BoundaryCondition", "ZDischarge"),
|
||||
"SL": _translate("BoundaryCondition", "Solid"),
|
||||
}
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"name": _translate("BoundaryCondition", "Name"),
|
||||
"type": _translate("BoundaryCondition", "Type"),
|
||||
"node": _translate("BoundaryCondition", "Node")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,13 +75,14 @@ class PamhyrTableModel(QAbstractTableModel):
|
|||
)
|
||||
|
||||
def __init__(self,
|
||||
table_view=None,
|
||||
table_headers={},
|
||||
editable_headers=[],
|
||||
table_view = None,
|
||||
table_headers = {},
|
||||
editable_headers = [],
|
||||
delegates = {},
|
||||
data=None,
|
||||
undo=None,
|
||||
opt_data=None):
|
||||
trad = None,
|
||||
data = None,
|
||||
undo = None,
|
||||
opt_data = None):
|
||||
super(PamhyrTableModel, self).__init__()
|
||||
|
||||
self._table_view = table_view
|
||||
|
|
@ -90,6 +91,7 @@ class PamhyrTableModel(QAbstractTableModel):
|
|||
self._headers = list(table_headers.keys())
|
||||
self._editable_headers = editable_headers
|
||||
self._delegates = delegates
|
||||
self._trad = trad
|
||||
|
||||
self._data = data
|
||||
self._opt_data = opt_data
|
||||
|
|
|
|||
Loading…
Reference in New Issue