mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
INI Default
This commit is contained in:
1 parent
bcf825a4f7
commit
7df0750c58
17 files changed
+325
-497
No files matched your search
@@ -48,19 +48,11 @@ from View.InitialConditionsAdisTS.UndoCommand import (
|
||||
DuplicateCommand,
|
||||
)
|
||||
|
||||
from View.InitialConditionsAdisTS.Table import (
|
||||
InitialConditionTableModel, ComboBoxDelegate,
|
||||
from View.InitialConditionsAdisTS.TableDefault import (
|
||||
InitialConditionTableDefaultModel,
|
||||
)
|
||||
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
from View.InitialConditionsAdisTS.PlotDKP import PlotDKP
|
||||
from View.InitialConditionsAdisTS.PlotDischarge import PlotDischarge
|
||||
from View.InitialConditionsAdisTS.translate import ICTranslate
|
||||
from View.InitialConditionsAdisTS.DialogHeight import HeightDialog
|
||||
from View.InitialConditionsAdisTS.DialogDischarge import DischargeDialog
|
||||
from View.Results.ReadingResultsDialog import ReadingResultsDialog
|
||||
from View.InitialConditionsAdisTS.translate import IcAdisTSTranslate
|
||||
|
||||
from Solver.Mage import Mage8
|
||||
|
||||
@@ -69,25 +61,23 @@ _translate = QCoreApplication.translate
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class InitialConditionsWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "InitialConditions"
|
||||
_pamhyr_name = "Initial condition"
|
||||
class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "InitialConditionsAdisTS"
|
||||
_pamhyr_name = "Initial condition AdisTS"
|
||||
|
||||
def __init__(self, study=None, config=None, reach=None, parent=None):
|
||||
trad = ICTranslate()
|
||||
|
||||
if reach is not None:
|
||||
self._reach = reach
|
||||
else:
|
||||
self._reach = study.river.current_reach()
|
||||
def __init__(self, data=None, study=None, config=None, parent=None):
|
||||
self._data = []
|
||||
self._data.append(data)
|
||||
#print(self._data.name, self._data.concentration, self._data.eg, self._data.em, self._data.ed)
|
||||
trad = IcAdisTSTranslate()
|
||||
|
||||
name = (
|
||||
trad[self._pamhyr_name] +
|
||||
" - " + study.name +
|
||||
" - " + self._reach.name
|
||||
" - " + self._data[0].name
|
||||
)
|
||||
|
||||
super(InitialConditionsWindow, self).__init__(
|
||||
super(InitialConditionsAdisTSWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
@@ -95,31 +85,22 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
parent=parent
|
||||
)
|
||||
|
||||
# Add reach to hash computation data
|
||||
self._hash_data.append(self._reach)
|
||||
self._hash_data.append(data)
|
||||
|
||||
self._ics = study.river.initial_conditions.get(self._reach)
|
||||
self._ics_adists_lst = study.river.initial_conditions_adists
|
||||
|
||||
self.setup_table()
|
||||
self.setup_plot()
|
||||
self.setup_connections()
|
||||
|
||||
self.ui.setWindowTitle(self._title)
|
||||
|
||||
def setup_table(self):
|
||||
table = self.find(QTableView, f"tableView")
|
||||
self._delegate_kp = ComboBoxDelegate(
|
||||
reach=self._reach,
|
||||
parent=self
|
||||
)
|
||||
|
||||
self._table = InitialConditionTableModel(
|
||||
reach=self._reach,
|
||||
self._table = InitialConditionTableDefaultModel(
|
||||
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,
|
||||
editable_headers=["name", "concentration", "eg", "em", "ed"],
|
||||
delegates={},
|
||||
data=self._data,
|
||||
undo=self._undo_stack,
|
||||
trad=self._trad
|
||||
)
|
||||
@@ -127,62 +108,9 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
table.setModel(self._table)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
#table.verticalHeader()
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def setup_plot(self):
|
||||
self.canvas_1 = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_1.setObjectName("canvas_1")
|
||||
self.toolbar_1 = PamhyrPlotToolbar(
|
||||
self.canvas_1, self
|
||||
)
|
||||
self.plot_layout_1 = self.find(QVBoxLayout, "verticalLayout_1")
|
||||
self.plot_layout_1.addWidget(self.toolbar_1)
|
||||
self.plot_layout_1.addWidget(self.canvas_1)
|
||||
|
||||
self.plot_1 = PlotDKP(
|
||||
canvas=self.canvas_1,
|
||||
data=self._ics,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_1,
|
||||
parent=self
|
||||
)
|
||||
self.plot_1.draw()
|
||||
|
||||
self.canvas_2 = MplCanvas(width=5, height=4, dpi=100)
|
||||
self.canvas_2.setObjectName("canvas_2")
|
||||
self.toolbar_2 = PamhyrPlotToolbar(
|
||||
self.canvas_2, self
|
||||
)
|
||||
self.plot_layout_2 = self.find(QVBoxLayout, "verticalLayout_2")
|
||||
self.plot_layout_2.addWidget(self.toolbar_2)
|
||||
self.plot_layout_2.addWidget(self.canvas_2)
|
||||
|
||||
self.plot_2 = PlotDischarge(
|
||||
canvas=self.canvas_2,
|
||||
data=self._ics,
|
||||
trad=self._trad,
|
||||
toolbar=self.toolbar_2,
|
||||
parent=self
|
||||
)
|
||||
self.plot_2.draw()
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
||||
self.find(QAction, "action_import").triggered\
|
||||
.connect(self.import_from_file)
|
||||
|
||||
self.find(QPushButton, "pushButton_generate_1").clicked.connect(
|
||||
self.generate_growing_constante_height
|
||||
)
|
||||
|
||||
self.find(QPushButton, "pushButton_generate_2").clicked.connect(
|
||||
self.generate_discharge
|
||||
)
|
||||
|
||||
self._table.dataChanged.connect(self._update_plot)
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, f"tableView")
|
||||
rows = table.selectionModel()\
|
||||
@@ -193,20 +121,6 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
|
||||
return rows[0].row()
|
||||
|
||||
def update(self):
|
||||
self._update_plot()
|
||||
self._propagate_update(key=Modules.INITIAL_CONDITION)
|
||||
|
||||
def _update_plot(self):
|
||||
self.plot_1.draw()
|
||||
self.plot_2.draw()
|
||||
|
||||
def _propagated_update(self, key=Modules(0)):
|
||||
if Modules.GEOMETRY not in key:
|
||||
return
|
||||
|
||||
self.update()
|
||||
|
||||
def index_selected_rows(self):
|
||||
table = self.find(QTableView, f"tableView")
|
||||
return list(
|
||||
@@ -219,63 +133,6 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
)
|
||||
)
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(self._ics) == 0 or len(rows) == 0:
|
||||
self._table.add(0)
|
||||
else:
|
||||
self._table.add(rows[0])
|
||||
|
||||
self._update()
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._table.delete(rows)
|
||||
self._update()
|
||||
|
||||
def sort(self):
|
||||
self._table.sort(False)
|
||||
self._update()
|
||||
|
||||
def import_from_file(self):
|
||||
workdir = os.path.dirname(self._study.filename)
|
||||
|
||||
return self.file_dialog(
|
||||
callback=lambda d: self._import_from_file(d[0]),
|
||||
directory=workdir,
|
||||
default_suffix=".BIN",
|
||||
file_filter=["Mage (*.BIN)"],
|
||||
)
|
||||
|
||||
def _import_from_file(self, file_name):
|
||||
solver = Mage8("dummy")
|
||||
name = os.path.basename(file_name)\
|
||||
.replace(".BIN", "")
|
||||
|
||||
def reading():
|
||||
self._tmp_results = solver.results(
|
||||
self._study,
|
||||
os.path.dirname(file_name),
|
||||
name=name
|
||||
)
|
||||
|
||||
dlg = ReadingResultsDialog(
|
||||
reading_fn=reading,
|
||||
parent=self
|
||||
)
|
||||
dlg.exec_()
|
||||
results = self._tmp_results
|
||||
self._import_from_results(results)
|
||||
|
||||
def _import_from_results(self, results):
|
||||
logger.debug(f"import from results: {results}")
|
||||
row = self.index_selected_row()
|
||||
|
||||
self._table.import_from_results(row, results)
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_up(row)
|
||||
@@ -339,17 +196,3 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
self._update()
|
||||
|
||||
def generate_growing_constante_height(self):
|
||||
dlg = HeightDialog(trad=self._trad, parent=self)
|
||||
if dlg.exec():
|
||||
value = dlg.value
|
||||
self._table.generate("growing", value)
|
||||
self._update()
|
||||
|
||||
def generate_discharge(self):
|
||||
dlg = DischargeDialog(trad=self._trad, parent=self)
|
||||
if dlg.exec():
|
||||
value = dlg.value
|
||||
self._table.generate("discharge", value)
|
||||
self._update()
|
||||
Reference in new issue
Block a user