diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index 6978ca98602e0fe6882069f9f2b3e9f2ffefc1e8..d5486eaa354a3cc67d6174dcf0bf1870f7606269 100644 --- a/src/Model/BoundaryCondition/BoundaryCondition.py +++ b/src/Model/BoundaryCondition/BoundaryCondition.py @@ -65,6 +65,24 @@ class BoundaryCondition(object): def is_define(self): return self._data is not None + 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]) + else: + new_1 = self._types[i](data[j]) + else: + new_0 = self._types[0](data[0]) + new_1 = self._types[1](data[1]) + + return (new_0, new_1) + def add(self, index:int): value = (self._default_0, self._default_1) self._data.insert(index, value) diff --git a/src/View/BoundaryCondition/Edit/Table.py b/src/View/BoundaryCondition/Edit/Table.py index 16670fe5c55eae3866ff7814d48e23b83684835b..c6fa672288e931d0a1de5233b6e1247bb12215b9 100644 --- a/src/View/BoundaryCondition/Edit/Table.py +++ b/src/View/BoundaryCondition/Edit/Table.py @@ -162,6 +162,28 @@ class TableModel(QAbstractTableModel): self.endMoveRows() self.layoutChanged.emit() + 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.layoutChanged.emit() + + def undo(self): self._undo.undo() self.layoutChanged.emit() diff --git a/src/View/BoundaryCondition/Edit/UndoCommand.py b/src/View/BoundaryCondition/Edit/UndoCommand.py index ba8fe77c3537e96db81cde1a48b295e7fb225aab..b2eb09acfd3648a34e752cc243dc3a5466090820 100644 --- a/src/View/BoundaryCondition/Edit/UndoCommand.py +++ b/src/View/BoundaryCondition/Edit/UndoCommand.py @@ -114,19 +114,19 @@ class MoveCommand(QUndoCommand): class PasteCommand(QUndoCommand): - def __init__(self, data, row, bc): + def __init__(self, data, row, bcs): QUndoCommand.__init__(self) self._data = data self._row = row - self._bc = deepcopy(bc) - self._bc.reverse() + self._bcs = bcs + self._bcs.reverse() def undo(self): - self._data.delete(self._bc) + self._data.delete(self._bcs) def redo(self): - for bc in self._bc: + for bc in self._bcs: self._data.insert(self._row, bc) diff --git a/src/View/BoundaryCondition/Edit/Window.py b/src/View/BoundaryCondition/Edit/Window.py index 1b2e554cd5d07b625b22e8d25d371acbd5d11eb8..5f0b38e40544c3b88b55d59a6d4c394bc9289e31 100644 --- a/src/View/BoundaryCondition/Edit/Window.py +++ b/src/View/BoundaryCondition/Edit/Window.py @@ -152,11 +152,29 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): def copy(self): - print("TODO") - self.plot.update() + rows = self.index_selected_rows() + + table = [] + table.append(self._data.header) + + data = self._data.data + for row in rows: + table.append(list(data[row])) + + self.copyTableIntoClipboard(table) def paste(self): - print("TODO") + header, data = self.parseClipboardTable() + + 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):