mirror of https://gitlab.com/pamhyr/pamhyr2
add copy/paste in pollutant BC + debug
parent
e3315c8f81
commit
4b976d3b5f
|
|
@ -222,3 +222,33 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
return self._data.copy()
|
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:
|
else:
|
||||||
self.id = id
|
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._enabled = True
|
||||||
|
|
||||||
self._data = []
|
self._data = []
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ from PyQt5.QtWidgets import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.BoundaryConditionsAdisTS.Edit.UndoCommand import (
|
from View.BoundaryConditionsAdisTS.Edit.UndoCommand import (
|
||||||
AddCommand, DelCommand, SetDataCommand,
|
AddCommand, DelCommand, SetDataCommand, PasteCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
_translate = QCoreApplication.translate
|
_translate = QCoreApplication.translate
|
||||||
|
|
@ -118,3 +118,28 @@ class TableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
self.endRemoveRows()
|
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):
|
def redo(self):
|
||||||
for row in self._rows:
|
for row in self._rows:
|
||||||
del self._data._data[row]
|
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)
|
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):
|
def _undo(self):
|
||||||
self._table.undo()
|
self._table.undo()
|
||||||
self.plot.update()
|
self.plot.update()
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,9 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow):
|
||||||
for row in rows:
|
for row in rows:
|
||||||
data = self._bcs.lst[row]
|
data = self._bcs.lst[row]
|
||||||
|
|
||||||
|
if data.node is None:
|
||||||
|
continue
|
||||||
|
|
||||||
if self.sub_window_exists(
|
if self.sub_window_exists(
|
||||||
EditBoundaryConditionWindow,
|
EditBoundaryConditionWindow,
|
||||||
data=[self._study, None, data]
|
data=[self._study, None, data]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue