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)
|
self._reachs.append(new)
|
||||||
return 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 (
|
from View.InitialConditions.UndoCommand import (
|
||||||
SetCommand, AddCommand, DelCommand,
|
SetCommand, AddCommand, DelCommand,
|
||||||
SortCommand, MoveCommand, PasteCommand,
|
SortCommand, MoveCommand, InsertCommand,
|
||||||
DuplicateCommand, GenerateCommand,
|
DuplicateCommand, GenerateCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -230,7 +230,44 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||||
self.layoutAboutToBeChanged.emit()
|
self.layoutAboutToBeChanged.emit()
|
||||||
|
|
||||||
self._undo.push(
|
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,
|
self._lst, index,
|
||||||
list(
|
list(
|
||||||
map(
|
map(
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ class MoveCommand(QUndoCommand):
|
||||||
self._ics.move_down(self._i)
|
self._ics.move_down(self._i)
|
||||||
|
|
||||||
|
|
||||||
class PasteCommand(QUndoCommand):
|
class InsertCommand(QUndoCommand):
|
||||||
def __init__(self, ics, row, ic):
|
def __init__(self, ics, row, ic):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tools import trace, timer, logger_exception
|
from tools import trace, timer, logger_exception
|
||||||
|
|
@ -43,7 +44,7 @@ from Modules import Modules
|
||||||
|
|
||||||
from View.InitialConditions.UndoCommand import (
|
from View.InitialConditions.UndoCommand import (
|
||||||
SetCommand, AddCommand, DelCommand,
|
SetCommand, AddCommand, DelCommand,
|
||||||
SortCommand, MoveCommand, PasteCommand,
|
SortCommand, MoveCommand, InsertCommand,
|
||||||
DuplicateCommand,
|
DuplicateCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -59,6 +60,9 @@ from View.InitialConditions.PlotDischarge import PlotDischarge
|
||||||
from View.InitialConditions.translate import ICTranslate
|
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
|
||||||
|
from View.Results.ReadingResultsDialog import ReadingResultsDialog
|
||||||
|
|
||||||
|
from Solver.Mage import Mage8
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
@ -166,6 +170,7 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||||
self.find(QAction, "action_del").triggered.connect(self.delete)
|
self.find(QAction, "action_del").triggered.connect(self.delete)
|
||||||
self.find(QAction, "action_sort").triggered.connect(self.sort)
|
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.find(QPushButton, "pushButton_generate_1").clicked.connect(
|
||||||
self.generate_growing_constante_height
|
self.generate_growing_constante_height
|
||||||
|
|
@ -179,9 +184,14 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
|
|
||||||
def index_selected_row(self):
|
def index_selected_row(self):
|
||||||
table = self.find(QTableView, f"tableView")
|
table = self.find(QTableView, f"tableView")
|
||||||
return table.selectionModel()\
|
rows = table.selectionModel()\
|
||||||
.selectedRows()[0]\
|
.selectedRows()
|
||||||
.row()
|
|
||||||
|
if len(rows) == 0:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return rows[0].row()
|
||||||
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self._update_plot()
|
self._update_plot()
|
||||||
|
|
@ -230,6 +240,42 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
self._table.sort(False)
|
self._table.sort(False)
|
||||||
self._update()
|
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):
|
def move_up(self):
|
||||||
row = self.index_selected_row()
|
row = self.index_selected_row()
|
||||||
self._table.move_up(row)
|
self._table.move_up(row)
|
||||||
|
|
@ -278,7 +324,7 @@ class InitialConditionsWindow(PamhyrWindow):
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
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, header, data)
|
||||||
self._table.paste(row, [], data)
|
self._table.paste(row, [], data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,9 @@ class WindowToolKit(object):
|
||||||
|
|
||||||
def file_dialog(self, select_file=True,
|
def file_dialog(self, select_file=True,
|
||||||
callback=lambda x: None,
|
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
|
"""Open a new file dialog and send result to callback function
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
@ -95,7 +97,8 @@ class WindowToolKit(object):
|
||||||
callback: The callback function with one arguments, files
|
callback: The callback function with one arguments, files
|
||||||
selection list
|
selection list
|
||||||
directory: Defaut directory
|
directory: Defaut directory
|
||||||
|
default_suffix: Default file suffix
|
||||||
|
file_filter: List of file filter
|
||||||
Returns:
|
Returns:
|
||||||
The returns of callback
|
The returns of callback
|
||||||
"""
|
"""
|
||||||
|
|
@ -110,6 +113,13 @@ class WindowToolKit(object):
|
||||||
if directory is not None:
|
if directory is not None:
|
||||||
dialog.setDirectory(directory)
|
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_():
|
if dialog.exec_():
|
||||||
file_names = dialog.selectedFiles()
|
file_names = dialog.selectedFiles()
|
||||||
return callback(file_names)
|
return callback(file_names)
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@
|
||||||
<attribute name="toolBarBreak">
|
<attribute name="toolBarBreak">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<addaction name="action_import"/>
|
||||||
<addaction name="action_add"/>
|
<addaction name="action_add"/>
|
||||||
<addaction name="action_del"/>
|
<addaction name="action_del"/>
|
||||||
<addaction name="action_sort"/>
|
<addaction name="action_sort"/>
|
||||||
|
|
@ -121,6 +122,18 @@
|
||||||
<string>Sort inital condition</string>
|
<string>Sort inital condition</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</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>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue