add copy/paste in pollutant BC + debug

This commit is contained in:
Theophile Terraz committed 2025-02-17 09:43:02 +01:00
1 parent e3315c8f81
commit 4b976d3b5f
6 files changed
+98 -2

No files matched your search

@@ -41,7 +41,7 @@ from PyQt5.QtWidgets import (
)
from View.BoundaryConditionsAdisTS.Edit.UndoCommand import (
AddCommand, DelCommand, SetDataCommand,
AddCommand, DelCommand, SetDataCommand, PasteCommand,
)
_translate = QCoreApplication.translate
@@ -118,3 +118,28 @@ class TableModel(PamhyrTableModel):
)
self.endRemoveRows()
def paste(self, row, header, data):
if len(data) == 0:
return
self.layoutAboutToBeChanged.emit()
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.new_from_data(header, d),
data
)
)
)
)
self.layoutAboutToBeChanged.emit()
self.update()
def update(self):
# self.auto_sort()
self.layoutChanged.emit()
@@ -102,3 +102,22 @@ class DelCommand(QUndoCommand):
def redo(self):
for row in self._rows:
del self._data._data[row]
class PasteCommand(QUndoCommand):
def __init__(self, data, row, bcs):
QUndoCommand.__init__(self)
self._data = data
self._row = row
self._bcs = bcs
self._bcs.reverse()
def undo(self):
self._data.delete_i(
range(self._row, self._row + len(self._bcs))
)
def redo(self):
for bc in self._bcs:
self._data.insert(self._row, bc)
@@ -200,6 +200,22 @@ 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()
@@ -182,6 +182,9 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
for row in rows:
data = self._bcs.lst[row]
if data.node is None:
continue
if self.sub_window_exists(
EditBoundaryConditionWindow,
data=[self._study, None, data]