mirror of https://gitlab.com/pamhyr/pamhyr2
refactoring: refacto IC.
parent
500885ec4d
commit
b430cbb62b
|
|
@ -37,7 +37,7 @@ class DischargeDialog(PamhyrDialog):
|
||||||
|
|
||||||
def __init__(self, title="Discharge", parent=None):
|
def __init__(self, title="Discharge", parent=None):
|
||||||
super(DischargeDialog, self).__init__(
|
super(DischargeDialog, self).__init__(
|
||||||
title = _pamhyr_name,
|
title = self._pamhyr_name,
|
||||||
options = [],
|
options = [],
|
||||||
parent = parent
|
parent = parent
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class HeightDialog(PamhyrDialog):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(HeightDialog, self).__init__(
|
super(HeightDialog, self).__init__(
|
||||||
title = name,
|
title = self._pamhyr_name,
|
||||||
options = [],
|
options = [],
|
||||||
parent = parent
|
parent = parent
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from tools import timer
|
from tools import timer
|
||||||
from View.Plot.APlot import APlot
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
QCoreApplication
|
QCoreApplication
|
||||||
|
|
@ -25,14 +25,7 @@ from PyQt5.QtCore import (
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
class PlotDKP(APlot):
|
class PlotDKP(PamhyrPlot):
|
||||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
|
||||||
super(PlotDKP, self).__init__(
|
|
||||||
canvas=canvas,
|
|
||||||
data=data,
|
|
||||||
toolbar=toolbar
|
|
||||||
)
|
|
||||||
|
|
||||||
@timer
|
@timer
|
||||||
def draw(self, highlight=None):
|
def draw(self, highlight=None):
|
||||||
self.canvas.axes.cla()
|
self.canvas.axes.cla()
|
||||||
|
|
@ -42,11 +35,11 @@ class PlotDKP(APlot):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.canvas.axes.set_ylabel(
|
self.canvas.axes.set_ylabel(
|
||||||
_translate("MainWindow_reach", "Elevation (m)"),
|
self._trad["elevation"],
|
||||||
color='green', fontsize=11
|
color='green', fontsize=11
|
||||||
)
|
)
|
||||||
self.canvas.axes.set_xlabel(
|
self.canvas.axes.set_xlabel(
|
||||||
_translate("MainWindow_reach", "KP (m)"),
|
self._trad["kp"],
|
||||||
color='green', fontsize=11
|
color='green', fontsize=11
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,22 +17,9 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from tools import timer
|
from tools import timer
|
||||||
from View.Plot.APlot import APlot
|
from View.Tools.PamhyrPlot import PamhyrPlot
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
|
||||||
QCoreApplication
|
|
||||||
)
|
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
|
||||||
|
|
||||||
class PlotDischarge(APlot):
|
|
||||||
def __init__(self, canvas=None, data=None, toolbar=None):
|
|
||||||
super(PlotDischarge, self).__init__(
|
|
||||||
canvas=canvas,
|
|
||||||
data=data,
|
|
||||||
toolbar=toolbar
|
|
||||||
)
|
|
||||||
|
|
||||||
|
class PlotDischarge(PamhyrPlot):
|
||||||
@timer
|
@timer
|
||||||
def draw(self, highlight=None):
|
def draw(self, highlight=None):
|
||||||
self.canvas.axes.cla()
|
self.canvas.axes.cla()
|
||||||
|
|
@ -42,11 +29,11 @@ class PlotDischarge(APlot):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.canvas.axes.set_ylabel(
|
self.canvas.axes.set_ylabel(
|
||||||
_translate("MainWindow_reach", "Discharge (m^3/s)"),
|
self._trad["discharge"],
|
||||||
color='green', fontsize=11
|
color='green', fontsize=11
|
||||||
)
|
)
|
||||||
self.canvas.axes.set_xlabel(
|
self.canvas.axes.set_xlabel(
|
||||||
_translate("MainWindow_reach", "KP (m)"),
|
self._trad["kp"],
|
||||||
color='green', fontsize=11
|
color='green', fontsize=11
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,14 @@ from PyQt5.QtWidgets import (
|
||||||
QComboBox,
|
QComboBox,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||||
|
|
||||||
from View.InitialConditions.UndoCommand import (
|
from View.InitialConditions.UndoCommand import (
|
||||||
SetCommand, AddCommand, DelCommand,
|
SetCommand, AddCommand, DelCommand,
|
||||||
SortCommand, MoveCommand, PasteCommand,
|
SortCommand, MoveCommand, PasteCommand,
|
||||||
DuplicateCommand, GenerateCommand,
|
DuplicateCommand, GenerateCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.InitialConditions.translate import *
|
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
@ -87,29 +87,13 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
self.commitData.emit(self.sender())
|
self.commitData.emit(self.sender())
|
||||||
|
|
||||||
|
|
||||||
class TableModel(QAbstractTableModel):
|
class InitialConditionTableModel(PamhyrTableModel):
|
||||||
def __init__(self, river=None, reach=None, undo=None):
|
def __init__(self, reach=None, **kwargs):
|
||||||
super(QAbstractTableModel, self).__init__()
|
|
||||||
self._headers = list(table_headers.keys())
|
|
||||||
self._river = river
|
|
||||||
self._reach = reach
|
self._reach = reach
|
||||||
self._undo = undo
|
super(InitialConditionTableModel, self).__init__(**kwargs)
|
||||||
self._ics = self._river.initial_conditions.get(reach)
|
|
||||||
|
|
||||||
def flags(self, index):
|
def _setup_lst(self):
|
||||||
column = index.column()
|
self._lst = self._data.river.initial_conditions.get(self._reach)
|
||||||
|
|
||||||
options = Qt.ItemIsSelectable
|
|
||||||
if self._headers[column] != "speed":
|
|
||||||
options |= Qt.ItemIsEnabled | Qt.ItemIsEditable
|
|
||||||
|
|
||||||
return options
|
|
||||||
|
|
||||||
def rowCount(self, parent):
|
|
||||||
return len(self._ics)
|
|
||||||
|
|
||||||
def columnCount(self, parent):
|
|
||||||
return len(self._headers)
|
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role != Qt.ItemDataRole.DisplayRole:
|
if role != Qt.ItemDataRole.DisplayRole:
|
||||||
|
|
@ -119,16 +103,10 @@ class TableModel(QAbstractTableModel):
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
||||||
if self._headers[column] not in ["name", "comment"]:
|
if self._headers[column] not in ["name", "comment"]:
|
||||||
v = self._ics.get(row)[self._headers[column]]
|
v = self._lst.get(row)[self._headers[column]]
|
||||||
return f"{v:.4f}"
|
return f"{v:.4f}"
|
||||||
else:
|
else:
|
||||||
return self._ics.get(row)[self._headers[column]]
|
return self._lst.get(row)[self._headers[column]]
|
||||||
|
|
||||||
return QVariant()
|
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
|
||||||
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
|
|
||||||
return table_headers[self._headers[section]]
|
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
|
@ -143,7 +121,7 @@ class TableModel(QAbstractTableModel):
|
||||||
if self._headers[column] is not None:
|
if self._headers[column] is not None:
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetCommand(
|
SetCommand(
|
||||||
self._ics, row, self._headers[column], value
|
self._lst, row, self._headers[column], value
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -158,7 +136,7 @@ class TableModel(QAbstractTableModel):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
AddCommand(
|
AddCommand(
|
||||||
self._ics, row
|
self._lst, row
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -170,7 +148,7 @@ class TableModel(QAbstractTableModel):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._ics, rows
|
self._lst, rows
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -182,7 +160,7 @@ class TableModel(QAbstractTableModel):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SortCommand(
|
SortCommand(
|
||||||
self._ics, False
|
self._lst, False
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -199,7 +177,7 @@ class TableModel(QAbstractTableModel):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
MoveCommand(
|
MoveCommand(
|
||||||
self._ics, "up", row
|
self._lst, "up", row
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -207,7 +185,7 @@ class TableModel(QAbstractTableModel):
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def move_down(self, index, parent=QModelIndex()):
|
def move_down(self, index, parent=QModelIndex()):
|
||||||
if row > len(self._ics):
|
if row > len(self._lst):
|
||||||
return
|
return
|
||||||
|
|
||||||
target = row
|
target = row
|
||||||
|
|
@ -216,7 +194,7 @@ class TableModel(QAbstractTableModel):
|
||||||
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
MoveCommand(
|
MoveCommand(
|
||||||
self._ics, "down", row
|
self._lst, "down", row
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -234,7 +212,7 @@ class TableModel(QAbstractTableModel):
|
||||||
def generate(self, generator, param):
|
def generate(self, generator, param):
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
GenerateCommand(
|
GenerateCommand(
|
||||||
self._ics, generator, param
|
self._lst, generator, param
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,14 @@ from View.InitialConditions.UndoCommand import (
|
||||||
DuplicateCommand,
|
DuplicateCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.InitialConditions.Table import TableModel, ComboBoxDelegate
|
from View.InitialConditions.Table import InitialConditionTableModel, ComboBoxDelegate
|
||||||
|
|
||||||
from View.Plot.MplCanvas import MplCanvas
|
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||||
from View.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||||
|
|
||||||
from View.InitialConditions.PlotDKP import PlotDKP
|
from View.InitialConditions.PlotDKP import PlotDKP
|
||||||
from View.InitialConditions.PlotDischarge import PlotDischarge
|
from View.InitialConditions.PlotDischarge import PlotDischarge
|
||||||
from View.InitialConditions.translate import table_headers, retranslate
|
from View.InitialConditions.translate import ICTranslate
|
||||||
from View.InitialConditions.DialogHeight import HeightDialog
|
from View.InitialConditions.DialogHeight import HeightDialog
|
||||||
from View.InitialConditions.DialogDischarge import DischargeDialog
|
from View.InitialConditions.DialogDischarge import DischargeDialog
|
||||||
|
|
||||||
|
|
@ -80,43 +80,42 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
title = name,
|
title = name,
|
||||||
study = study,
|
study = study,
|
||||||
config = config,
|
config = config,
|
||||||
|
trad = ICTranslate(),
|
||||||
parent = parent
|
parent = parent
|
||||||
)
|
)
|
||||||
|
|
||||||
self._ics = study.river.initial_conditions.get(self._reach)
|
self._ics = study.river.initial_conditions.get(self._reach)
|
||||||
|
|
||||||
self.setup_table()
|
self.setup_table()
|
||||||
self.setup_graph()
|
self.setup_plot()
|
||||||
self.setup_connections()
|
self.setup_connections()
|
||||||
|
|
||||||
self.ui.setWindowTitle(self._title)
|
self.ui.setWindowTitle(self._title)
|
||||||
|
|
||||||
def setup_table(self):
|
def setup_table(self):
|
||||||
retranslate()
|
|
||||||
|
|
||||||
table = self.find(QTableView, f"tableView")
|
table = self.find(QTableView, f"tableView")
|
||||||
self._table = TableModel(
|
|
||||||
river = self._study.river,
|
|
||||||
reach = self._reach,
|
|
||||||
undo = self._undo_stack,
|
|
||||||
)
|
|
||||||
table.setModel(self._table)
|
|
||||||
|
|
||||||
self._delegate_kp = ComboBoxDelegate(
|
self._delegate_kp = ComboBoxDelegate(
|
||||||
reach = self._reach,
|
reach = self._reach,
|
||||||
parent = self
|
parent = self
|
||||||
)
|
)
|
||||||
|
|
||||||
table.setItemDelegateForColumn(
|
self._table = InitialConditionTableModel(
|
||||||
list(table_headers).index("kp"),
|
reach = self._reach,
|
||||||
self._delegate_kp
|
table_view = table,
|
||||||
|
table_headers = self._trad.get_dict("table_headers"),
|
||||||
|
editable_headers = ["kp", "discharge", "elevation", "height"],
|
||||||
|
delegates = {"kp": self._delegate_kp},
|
||||||
|
data = self._study,
|
||||||
|
undo = self._undo_stack,
|
||||||
|
trad = self._trad
|
||||||
)
|
)
|
||||||
|
|
||||||
|
table.setModel(self._table)
|
||||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||||
table.setAlternatingRowColors(True)
|
table.setAlternatingRowColors(True)
|
||||||
|
|
||||||
def setup_graph(self):
|
def setup_plot(self):
|
||||||
self.canvas_1 = MplCanvas(width=5, height=4, dpi=100)
|
self.canvas_1 = MplCanvas(width=5, height=4, dpi=100)
|
||||||
self.canvas_1.setObjectName("canvas_1")
|
self.canvas_1.setObjectName("canvas_1")
|
||||||
self.toolbar_1 = PamhyrPlotToolbar(
|
self.toolbar_1 = PamhyrPlotToolbar(
|
||||||
|
|
@ -129,7 +128,9 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
self.plot_1 = PlotDKP(
|
self.plot_1 = PlotDKP(
|
||||||
canvas = self.canvas_1,
|
canvas = self.canvas_1,
|
||||||
data = self._ics,
|
data = self._ics,
|
||||||
|
trad = self._trad,
|
||||||
toolbar = self.toolbar_1,
|
toolbar = self.toolbar_1,
|
||||||
|
parent = self
|
||||||
)
|
)
|
||||||
self.plot_1.draw()
|
self.plot_1.draw()
|
||||||
|
|
||||||
|
|
@ -145,7 +146,9 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
self.plot_2 = PlotDischarge(
|
self.plot_2 = PlotDischarge(
|
||||||
canvas = self.canvas_2,
|
canvas = self.canvas_2,
|
||||||
data = self._ics,
|
data = self._ics,
|
||||||
|
trad = self._trad,
|
||||||
toolbar = self.toolbar_2,
|
toolbar = self.toolbar_2,
|
||||||
|
parent = self
|
||||||
)
|
)
|
||||||
self.plot_2.draw()
|
self.plot_2.draw()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,23 +18,24 @@
|
||||||
|
|
||||||
from PyQt5.QtCore import QCoreApplication
|
from PyQt5.QtCore import QCoreApplication
|
||||||
|
|
||||||
|
from View.Tools.PamhyrTranslate import PamhyrTranslate
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
table_headers = {
|
class ICTranslate(PamhyrTranslate):
|
||||||
# "name": _translate("LateralContribution", "Name"),
|
def __init__(self):
|
||||||
"kp": _translate("LateralContribution", "KP (m)"),
|
super(ICTranslate, self).__init__()
|
||||||
# "speed": _translate("LateralContribution", "Speed (m/s)"),
|
|
||||||
"discharge": _translate("LateralContribution", "Discharge (m³/s)"),
|
|
||||||
"elevation": _translate("LateralContribution", "Elevation (m)"),
|
|
||||||
"height": _translate("LateralContribution", "Height (m)"),
|
|
||||||
# "comment": _translate("LateralContribution", "Comment"),
|
|
||||||
}
|
|
||||||
|
|
||||||
def retranslate():
|
self._dict["elevation"] = _translate("InitialCondition", "Elevation (m)")
|
||||||
# table_headers["name"] = _translate("LateralContribution", "Name")
|
self._dict["discharge"] = _translate("InitialCondition", "Discharge (m³/s)")
|
||||||
table_headers["kp"] = _translate("LateralContribution", "KP (m)")
|
self._dict["kp"] = _translate("InitialCondition", "KP (m)")
|
||||||
# table_headers["speed"] = _translate("LateralContribution", "Speed (m/s)")
|
|
||||||
table_headers["discharge"] = _translate("LateralContribution", "Discharge (m³/s)")
|
self._sub_dict["table_headers"] = {
|
||||||
table_headers["elevation"] = _translate("LateralContribution", "Elevation (m)")
|
# "name": _translate("InitialCondition", "Name"),
|
||||||
table_headers["height"] = _translate("LateralContribution", "Height (m)")
|
"kp": _translate("InitialCondition", "KP (m)"),
|
||||||
# table_headers["comment"] = _translate("LateralContribution", "Comment")
|
# "speed": _translate("InitialCondition", "Speed (m/s)"),
|
||||||
|
"discharge": _translate("InitialCondition", "Discharge (m³/s)"),
|
||||||
|
"elevation": _translate("InitialCondition", "Elevation (m)"),
|
||||||
|
"height": _translate("InitialCondition", "Height (m)"),
|
||||||
|
# "comment": _translate("InitialCondition", "Comment"),
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ from View.Network.Window import NetworkWindow
|
||||||
from View.Geometry.Window import GeometryWindow
|
from View.Geometry.Window import GeometryWindow
|
||||||
from View.BoundaryCondition.Window import BoundaryConditionWindow
|
from View.BoundaryCondition.Window import BoundaryConditionWindow
|
||||||
from View.LateralContribution.Window import LateralContributionWindow
|
from View.LateralContribution.Window import LateralContributionWindow
|
||||||
# from View.InitialConditions.Window import InitialConditionsWindow
|
from View.InitialConditions.Window import InitialConditionsWindow
|
||||||
# from View.Stricklers.Window import StricklersWindow
|
# from View.Stricklers.Window import StricklersWindow
|
||||||
# from View.Frictions.Window import FrictionsWindow
|
# from View.Frictions.Window import FrictionsWindow
|
||||||
# from View.SedimentLayers.Window import SedimentLayersWindow
|
# from View.SedimentLayers.Window import SedimentLayersWindow
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ class PamhyrTranslate(object):
|
||||||
# Module sub dictionnary
|
# Module sub dictionnary
|
||||||
self._sub_dict = {}
|
self._sub_dict = {}
|
||||||
|
|
||||||
|
self._dict["pamhyr"] = _translate("Pamhyr", "Pamhyr2")
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
if index not in self._dict:
|
if index not in self._dict:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue