mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
BC AdisTS Complete
This commit is contained in:
1 parent
b927aa81b3
commit
704130966e
13 files changed
+198
-478
No files matched your search
@@ -1,4 +1,4 @@
|
||||
# Window.py -- Pamhyr
|
||||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2023-2024 INRAE
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@@ -44,76 +44,23 @@ from PyQt5.QtWidgets import (
|
||||
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
||||
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
||||
|
||||
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
|
||||
from View.BoundaryConditionsAdisTS.Edit.translate import BCETranslate
|
||||
from View.BoundaryConditionsAdisTS.Edit.Table import TableModel
|
||||
from View.BoundaryConditionsAdisTS.Edit.Plot import Plot
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class WD50Sigma(PamhyrWidget):
|
||||
_pamhyr_ui = "d50sigma"
|
||||
|
||||
d50Changed = pyqtSignal(float)
|
||||
sigmaChanged = pyqtSignal(float)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(WD50Sigma, self).__init__(
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self.spinBox_d50 = self.find(QDoubleSpinBox, "doubleSpinBox_d50")
|
||||
self.spinBox_sigma = self.find(QDoubleSpinBox, "doubleSpinBox_sigma")
|
||||
|
||||
self.spinBox_d50.valueChanged.connect(self.valueChangedD50)
|
||||
self.spinBox_sigma.valueChanged.connect(self.valueChangedSigma)
|
||||
|
||||
def set_d50(self, d50):
|
||||
self.spinBox_d50.valueChanged.disconnect(self.valueChangedD50)
|
||||
self.spinBox_d50.setValue(float(d50))
|
||||
self.spinBox_d50.valueChanged.connect(self.valueChangedD50)
|
||||
|
||||
def get_d50(self):
|
||||
return float(self.spinBox_d50.value())
|
||||
|
||||
def set_sigma(self, sigma):
|
||||
self.spinBox_sigma.valueChanged.disconnect(self.valueChangedSigma)
|
||||
self.spinBox_sigma.setValue(float(sigma))
|
||||
self.spinBox_sigma.valueChanged.connect(self.valueChangedSigma)
|
||||
|
||||
def get_sigma(self):
|
||||
return float(self.spinBox_sigma.value())
|
||||
|
||||
@QtCore.pyqtSlot(float)
|
||||
def valueChangedD50(self, value):
|
||||
self.d50Changed.emit(value)
|
||||
|
||||
@QtCore.pyqtSlot(float)
|
||||
def valueChangedSigma(self, value):
|
||||
self.sigmaChanged.emit(value)
|
||||
|
||||
|
||||
class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "EditBoundaryConditions"
|
||||
_pamhyr_name = "Edit Boundary Conditions"
|
||||
_pamhyr_ui = "EditBoundaryConditionsAdisTS"
|
||||
_pamhyr_name = "Edit Boundary Conditions AdisTS"
|
||||
|
||||
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 = trad[self._pamhyr_name]
|
||||
if self._data is not None:
|
||||
node_name = (self._data.node.name if self._data.node is not None
|
||||
else trad['not_associated'])
|
||||
name += (
|
||||
f" - {study.name} " +
|
||||
f" - {self._data.name} ({self._data.id}) " +
|
||||
f"({self._long_types[self._data.bctype]} - {node_name})"
|
||||
)
|
||||
|
||||
super(EditBoundaryConditionWindow, self).__init__(
|
||||
title=name,
|
||||
@@ -123,25 +70,26 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
parent=parent
|
||||
)
|
||||
|
||||
if self._data is not None:
|
||||
n = self._data.node
|
||||
node_name = next(filter(lambda x: x.id == n, self._study.river._nodes)).name
|
||||
name += (
|
||||
f" - {study.name} " +
|
||||
f"({node_name})"
|
||||
)
|
||||
|
||||
self._hash_data.append(data)
|
||||
|
||||
self.setup_table()
|
||||
self.setup_plot()
|
||||
self.setup_data()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_data(self):
|
||||
self._is_solid = self._data.bctype == "SL"
|
||||
|
||||
if self._is_solid:
|
||||
layout = self.find(QVBoxLayout, "verticalLayout_table")
|
||||
self._d50sigma = WD50Sigma(parent=self)
|
||||
layout.addWidget(self._d50sigma)
|
||||
|
||||
self._d50sigma.set_d50(self._data.d50)
|
||||
self._d50sigma.set_sigma(self._data.sigma)
|
||||
|
||||
def setup_table(self):
|
||||
if self._data.type == "Concentration":
|
||||
self._data.header = ["time", "concentration"]
|
||||
else:
|
||||
self._data.header = ["time", "rate"]
|
||||
|
||||
headers = {}
|
||||
table_headers = self._trad.get_dict("table_headers")
|
||||
for h in self._data.header:
|
||||
@@ -192,35 +140,9 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
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._table.dataChanged.connect(self.update)
|
||||
|
||||
if self._is_solid:
|
||||
self._d50sigma.d50Changed.connect(self.d50_changed)
|
||||
self._d50sigma.sigmaChanged.connect(self.sigma_changed)
|
||||
|
||||
def d50_changed(self, value):
|
||||
self._undo_stack.push(
|
||||
SetMetaDataCommand(
|
||||
self._data,
|
||||
"d50", value
|
||||
)
|
||||
)
|
||||
|
||||
def sigma_changed(self, value):
|
||||
self._undo_stack.push(
|
||||
SetMetaDataCommand(
|
||||
self._data,
|
||||
"sigma", value
|
||||
)
|
||||
)
|
||||
|
||||
def widget_update(self):
|
||||
if self._is_solid:
|
||||
self._d50sigma.set_d50(self._data.d50)
|
||||
self._d50sigma.set_sigma(self._data.sigma)
|
||||
|
||||
def update(self):
|
||||
self.plot.update()
|
||||
|
||||
@@ -263,16 +185,6 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
self._table.sort(False)
|
||||
self.plot.update()
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_up(row)
|
||||
self.plot.update()
|
||||
|
||||
def move_down(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_down(row)
|
||||
self.plot.update()
|
||||
|
||||
def _copy(self):
|
||||
rows = self.index_selected_rows()
|
||||
|
||||
@@ -285,28 +197,10 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
|
||||
self.copyTableIntoClipboard(table)
|
||||
|
||||
def _paste(self):
|
||||
header, data = self.parseClipboardTable()
|
||||
|
||||
logger.debug(f"paste: h:{header}, d:{data}")
|
||||
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
row = 0
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) != 0:
|
||||
row = rows[0]
|
||||
|
||||
self._table.paste(row, header, data)
|
||||
self.plot.update()
|
||||
|
||||
def _undo(self):
|
||||
self._table.undo()
|
||||
self.plot.update()
|
||||
self.widget_update()
|
||||
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
self.plot.update()
|
||||
self.widget_update()
|
||||
Reference in new issue
Block a user