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