mirror of https://gitlab.com/pamhyr/pamhyr2
IC: Add import action (for BIN file).
parent
459722610a
commit
9d343a42ce
|
|
@ -126,3 +126,11 @@ class River(object):
|
|||
|
||||
self._reachs.append(new)
|
||||
return new
|
||||
|
||||
def get_reach_by_geometry(self, geometry_reach):
|
||||
return next(
|
||||
filter(
|
||||
lambda r: r.geometry is geometry_reach,
|
||||
self._reachs
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
|
|||
|
||||
from View.InitialConditions.UndoCommand import (
|
||||
SetCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, PasteCommand,
|
||||
SortCommand, MoveCommand, InsertCommand,
|
||||
DuplicateCommand, GenerateCommand,
|
||||
)
|
||||
|
||||
|
|
@ -230,7 +230,44 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
PasteCommand(
|
||||
InsertCommand(
|
||||
self._lst, index,
|
||||
list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def import_from_results(self, index, results):
|
||||
if results is None:
|
||||
logger.error("No results data")
|
||||
return
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
ts = max(results.get("timestamps"))
|
||||
res_reach = results.river.get_reach_by_geometry(
|
||||
self._reach.reach
|
||||
)
|
||||
data = list(
|
||||
map(
|
||||
lambda p: [
|
||||
p.geometry.kp,
|
||||
p.get_ts_key(ts, "Q"),
|
||||
p.get_ts_key(ts, "Z"),
|
||||
],
|
||||
res_reach.profiles
|
||||
)
|
||||
)
|
||||
|
||||
self._undo.push(
|
||||
InsertCommand(
|
||||
self._lst, index,
|
||||
list(
|
||||
map(
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ class MoveCommand(QUndoCommand):
|
|||
self._ics.move_down(self._i)
|
||||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
class InsertCommand(QUndoCommand):
|
||||
def __init__(self, ics, row, ic):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import logging
|
||||
|
||||
from tools import trace, timer, logger_exception
|
||||
|
|
@ -43,7 +44,7 @@ from Modules import Modules
|
|||
|
||||
from View.InitialConditions.UndoCommand import (
|
||||
SetCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, PasteCommand,
|
||||
SortCommand, MoveCommand, InsertCommand,
|
||||
DuplicateCommand,
|
||||
)
|
||||
|
||||
|
|
@ -59,6 +60,9 @@ from View.InitialConditions.PlotDischarge import PlotDischarge
|
|||
from View.InitialConditions.translate import ICTranslate
|
||||
from View.InitialConditions.DialogHeight import HeightDialog
|
||||
from View.InitialConditions.DialogDischarge import DischargeDialog
|
||||
from View.Results.ReadingResultsDialog import ReadingResultsDialog
|
||||
|
||||
from Solver.Mage import Mage8
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
|
@ -166,6 +170,7 @@ class InitialConditionsWindow(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(QPushButton, "pushButton_generate_1").clicked.connect(
|
||||
self.generate_growing_constante_height
|
||||
|
|
@ -179,9 +184,14 @@ class InitialConditionsWindow(PamhyrWindow):
|
|||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, f"tableView")
|
||||
return table.selectionModel()\
|
||||
.selectedRows()[0]\
|
||||
.row()
|
||||
rows = table.selectionModel()\
|
||||
.selectedRows()
|
||||
|
||||
if len(rows) == 0:
|
||||
return 0
|
||||
|
||||
return rows[0].row()
|
||||
|
||||
|
||||
def update(self):
|
||||
self._update_plot()
|
||||
|
|
@ -230,6 +240,42 @@ class InitialConditionsWindow(PamhyrWindow):
|
|||
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)
|
||||
|
|
@ -278,7 +324,7 @@ class InitialConditionsWindow(PamhyrWindow):
|
|||
)
|
||||
|
||||
try:
|
||||
row = 0 if len(self._ics.lst()) == 0 else self.index_selected_row()
|
||||
row = self.index_selected_row()
|
||||
# self._table.paste(row, header, data)
|
||||
self._table.paste(row, [], data)
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ class WindowToolKit(object):
|
|||
|
||||
def file_dialog(self, select_file=True,
|
||||
callback=lambda x: None,
|
||||
directory=None):
|
||||
directory=None,
|
||||
default_suffix=None,
|
||||
file_filter=None):
|
||||
"""Open a new file dialog and send result to callback function
|
||||
|
||||
Args:
|
||||
|
|
@ -95,7 +97,8 @@ class WindowToolKit(object):
|
|||
callback: The callback function with one arguments, files
|
||||
selection list
|
||||
directory: Defaut directory
|
||||
|
||||
default_suffix: Default file suffix
|
||||
file_filter: List of file filter
|
||||
Returns:
|
||||
The returns of callback
|
||||
"""
|
||||
|
|
@ -110,6 +113,13 @@ class WindowToolKit(object):
|
|||
if directory is not None:
|
||||
dialog.setDirectory(directory)
|
||||
|
||||
if select_file:
|
||||
if default_suffix is not None:
|
||||
dialog.setDefaultSuffix(default_suffix)
|
||||
|
||||
if file_filter is not None:
|
||||
dialog.setNameFilters(file_filter)
|
||||
|
||||
if dialog.exec_():
|
||||
file_names = dialog.selectedFiles()
|
||||
return callback(file_names)
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@
|
|||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="action_import"/>
|
||||
<addaction name="action_add"/>
|
||||
<addaction name="action_del"/>
|
||||
<addaction name="action_sort"/>
|
||||
|
|
@ -121,6 +122,18 @@
|
|||
<string>Sort inital condition</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_import">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>ressources/import.png</normaloff>ressources/import.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Import from file</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue