mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Profile: Copy/Paste using system clipboard.
parent
012f7ce445
commit
e4c07e0e3e
|
|
@ -14,6 +14,29 @@ class PointXYZ(Point):
|
|||
self._y = float(y)
|
||||
self._z = float(z)
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, header, data):
|
||||
point = None
|
||||
try:
|
||||
if len(header) == 0:
|
||||
point = cls(
|
||||
*data
|
||||
)
|
||||
else:
|
||||
valid_header = {'name', 'x', 'y', 'z'}
|
||||
d = {}
|
||||
for i, v in enumerate(data):
|
||||
h = header[i].strip().lower().split(' ')[0]
|
||||
if h in valid_header:
|
||||
d[h] = v
|
||||
|
||||
point = cls(**d)
|
||||
except Exception as e:
|
||||
raise ClipboardFormatError(header, data)
|
||||
|
||||
return point
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ from typing import List
|
|||
|
||||
from tools import timer
|
||||
|
||||
from Model.Except import ClipboardFormatError
|
||||
from Model.Geometry.Profile import Profile
|
||||
from Model.Geometry.PointXYZ import PointXYZ
|
||||
from Model.Geometry.Vector_1d import Vector1d
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ from PyQt5.QtCore import (
|
|||
)
|
||||
from PyQt5.uic import loadUi
|
||||
|
||||
from Model.Except import ClipboardFormatError
|
||||
|
||||
class WindowToolKit(object):
|
||||
def __init__(self, parent=None):
|
||||
super(WindowToolKit, self).__init__()
|
||||
|
|
|
|||
|
|
@ -386,6 +386,9 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
def paste(self):
|
||||
header, data = self.parseClipboardTable()
|
||||
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
if len(header) != 0:
|
||||
header.append("reach")
|
||||
for row in data:
|
||||
|
|
|
|||
|
|
@ -141,8 +141,8 @@ class PasteCommand(QUndoCommand):
|
|||
self._points.reverse()
|
||||
|
||||
def undo(self):
|
||||
for ind in range(len(self._profiles)):
|
||||
self._profile.delete(self._row)
|
||||
for ind in range(len(self._points)):
|
||||
self._profile.delete([self._row])
|
||||
|
||||
def redo(self):
|
||||
for point in self._points:
|
||||
|
|
|
|||
|
|
@ -18,18 +18,17 @@ from PyQt5.QtWidgets import (
|
|||
QUndoStack, QShortcut,
|
||||
)
|
||||
|
||||
from View.ASubWindow import WindowToolKit
|
||||
from View.Geometry.Profile.mainwindow_ui_profile import Ui_MainWindow
|
||||
|
||||
from View.Geometry.Profile.Plot import Plot
|
||||
|
||||
from View.Geometry.Profile.qtableview_profile import *
|
||||
from Model.Geometry.Reach import Reach
|
||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||
from View.Geometry.Profile.qtableview_profile import *
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class ProfileWindow(QMainWindow):
|
||||
class ProfileWindow(QMainWindow, WindowToolKit):
|
||||
def __init__(self, profile=None, parent=None):
|
||||
self.parent = parent
|
||||
super(ProfileWindow, self).__init__(self.parent)
|
||||
|
|
@ -132,6 +131,12 @@ class ProfileWindow(QMainWindow):
|
|||
self.ui.tableView.model().blockSignals(False)
|
||||
|
||||
def index_selected_row(self):
|
||||
rows = self.ui.tableView\
|
||||
.selectionModel()\
|
||||
.selectedRows()
|
||||
if len(rows) == 0:
|
||||
return 0
|
||||
|
||||
return self.ui.tableView\
|
||||
.selectionModel()\
|
||||
.selectedRows()[0]\
|
||||
|
|
@ -201,23 +206,36 @@ class ProfileWindow(QMainWindow):
|
|||
self.update_plot()
|
||||
|
||||
def copy(self):
|
||||
rows = self.tableView\
|
||||
.selectionModel()\
|
||||
.selectedRows()
|
||||
|
||||
self._clipboard = []
|
||||
rows = self.ui.tableView\
|
||||
.selectionModel()\
|
||||
.selectedRows()
|
||||
table = []
|
||||
table.append(["x", "y", "z", "name"])
|
||||
|
||||
for row in rows:
|
||||
self._clipboard.append(
|
||||
deepcopy(
|
||||
self._reach.profile(row.row())
|
||||
)
|
||||
point = self._profile.point(row.row())
|
||||
table.append(
|
||||
[
|
||||
point.x, point.y, point.z, point.name
|
||||
]
|
||||
)
|
||||
|
||||
self.copyTableIntoClipboard(table)
|
||||
|
||||
def paste(self):
|
||||
header, data = self.parseClipboardTable()
|
||||
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
if len(header) != 0:
|
||||
header.append("profile")
|
||||
for row in data:
|
||||
row.append(self._profile)
|
||||
|
||||
row = self.index_selected_row()
|
||||
self._model.paste(row, self._clipboard)
|
||||
self.select_current_profile()
|
||||
self._model.paste(row, header, data)
|
||||
self.update_plot()
|
||||
|
||||
def undo(self):
|
||||
self._model.undo()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import numpy as np
|
||||
|
||||
from tools import timer, trace
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
QFont, QColor
|
||||
)
|
||||
|
|
@ -12,6 +15,7 @@ from PyQt5.QtCore import (
|
|||
QVariant, QCoreApplication
|
||||
)
|
||||
|
||||
from Model.Geometry.PointXYZ import PointXYZ
|
||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||
|
||||
from View.Geometry.Profile.ProfileUndoCommand import *
|
||||
|
|
@ -259,18 +263,24 @@ class TableEditableModel(QAbstractTableModel):
|
|||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def paste(self, row, points):
|
||||
def paste(self, row, header, data):
|
||||
if row > self._profile.number_points:
|
||||
return
|
||||
|
||||
if len(points) == 0:
|
||||
if len(data) == 0:
|
||||
return
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo_stack.push(
|
||||
PasteCommand(
|
||||
self._profile, row, points
|
||||
self._profile, row,
|
||||
list(
|
||||
map(
|
||||
lambda d: PointXYZ.from_data(header, d),
|
||||
data
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -212,7 +212,6 @@ class TableEditableModel(QAbstractTableModel):
|
|||
self.endMoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
@trace
|
||||
def paste(self, row, header, data):
|
||||
if row > self._reach.number_profiles:
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue