mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
load boundary conditions from file
This commit is contained in:
1 parent
7c4c772f43
commit
b582e133a1
6 files changed
+110
-16
No files matched your search
@@ -211,3 +211,23 @@ class TableModel(PamhyrTableModel):
|
||||
)
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.update()
|
||||
|
||||
def read_from_file(self, file_name, bctype):
|
||||
|
||||
logger.debug(f"Import initial conditions from {file_name}")
|
||||
data0 = []
|
||||
data1 = []
|
||||
if bctype == "ZD":
|
||||
mult = 1
|
||||
else:
|
||||
mult = 60
|
||||
with open(file_name, encoding="utf-8") as ini_file:
|
||||
for line in ini_file:
|
||||
if not (line.startswith("#") or
|
||||
line.startswith("*") or
|
||||
line.startswith("$")):
|
||||
line = line.split()
|
||||
data0.append(float(line[0]) * mult)
|
||||
data1.append(line[1])
|
||||
|
||||
self.replace_data(data0, data1)
|
||||
@@ -30,10 +30,10 @@ from PyQt5.QtGui import (
|
||||
QKeySequence,
|
||||
)
|
||||
|
||||
from PyQt5 import QtCore
|
||||
from PyQt5 import QtCore, QtWidgets
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel, QCoreApplication,
|
||||
pyqtSlot, pyqtSignal,
|
||||
pyqtSlot, pyqtSignal, QSettings,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
@@ -198,6 +198,8 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
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(QAction, "action_generate_uniform").triggered.connect(
|
||||
self.generate_uniform
|
||||
)
|
||||
@@ -293,6 +295,31 @@ class EditBoundaryConditionWindow(PamhyrWindow):
|
||||
self._table.sort(False)
|
||||
self.plot.update()
|
||||
|
||||
def import_from_file(self):
|
||||
options = QFileDialog.Options()
|
||||
settings = QSettings(QSettings.IniFormat,
|
||||
QSettings.UserScope, 'MyOrg', )
|
||||
options |= QFileDialog.DontUseNativeDialog
|
||||
|
||||
if self._data.bctype == "TD":
|
||||
file_types = [self._trad["file_hyd"]]
|
||||
if self._data.bctype == "TZ":
|
||||
file_types = [self._trad["file_lim"]]
|
||||
if self._data.bctype == "ZD":
|
||||
file_types = [self._trad["file_ava"]]
|
||||
file_types.append(self._trad["file_all"])
|
||||
|
||||
file_name, _ = QtWidgets.QFileDialog.getOpenFileName(
|
||||
self,
|
||||
self._trad["open_file"],
|
||||
"",
|
||||
";; ".join(file_types),
|
||||
options=options
|
||||
)
|
||||
|
||||
if file_name != "":
|
||||
self._table.read_from_file(file_name, self._data.bctype)
|
||||
|
||||
def move_up(self):
|
||||
row = self.index_selected_row()
|
||||
self._table.move_up(row)
|
||||
|
||||
@@ -35,6 +35,17 @@ class BCETranslate(BCTranslate):
|
||||
self._dict["Boundary Condition Options"] = _translate(
|
||||
"BoundaryCondition", "Boundary Condition Options")
|
||||
|
||||
self._dict["open_file"] = _translate(
|
||||
"BoundaryCondition", "Open a file")
|
||||
self._dict["file_hyd"] = _translate(
|
||||
"BoundaryCondition", "Mage hydrograph file (*.HYD)")
|
||||
self._dict["file_lim"] = _translate(
|
||||
"BoundaryCondition", "Mage limnigraph file (*.LIM)")
|
||||
self._dict["file_lim"] = _translate(
|
||||
"BoundaryCondition", "Mage rating curve file (*.AVA)")
|
||||
self._dict["file_all"] = _translate(
|
||||
"BoundaryCondition", "All files (*)")
|
||||
|
||||
self._sub_dict["table_headers"] = {
|
||||
"x": _translate("BoundaryCondition", "X"),
|
||||
"y": _translate("BoundaryCondition", "Y"),
|
||||
|
||||
Reference in new issue
Block a user