Commit 4b976d3b authored by Theophile Terraz's avatar Theophile Terraz
Browse files

add copy/paste in pollutant BC + debug

No related merge requests found
Showing with 98 additions and 2 deletions
+98 -2
......@@ -222,3 +222,33 @@ class BoundaryConditionAdisTS(SQLSubModel):
@property
def data(self):
return self._data.copy()
@property
def _default_0(self):
return self._types[0](0)
@property
def _default_1(self):
return self._types[1](0.0)
def new_from_data(self, header, data):
new_0 = self._default_0
new_1 = self._default_1
if len(header) != 0:
for i in [0, 1]:
for j in range(len(header)):
if self._header[i] == header[j]:
if i == 0:
new_0 = self._types[i](data[j].replace(",", "."))
else:
new_1 = self._types[i](data[j].replace(",", "."))
else:
new_0 = self._types[0](data[0].replace(",", "."))
new_1 = self._types[1](data[1].replace(",", "."))
return (new_0, new_1)
def insert(self, index: int, value):
self._data.insert(index, value)
self._status.modified()
......@@ -45,7 +45,10 @@ class Pollutants(SQLSubModel):
else:
self.id = id
self._name = str(name)
if name is None or name == "":
self.name = f"pol{self.id}"
else:
self._name = str(name)
self._enabled = True
self._data = []
......
......@@ -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]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment