Geometry: Fix profile copy/paste.

scenarios
Pierre-Antoine 2025-09-04 16:41:07 +02:00
parent 2a1c8c1e57
commit f4d3f2b28f
6 changed files with 50 additions and 13 deletions

View File

@ -273,6 +273,22 @@ class PointXYZ(Point):
return point
def copy(self):
new_p = PointXYZ(
id=-1,
name=self.name,
x=self.x, y=self.y, z=self.z,
profile=self.profile,
status=self._status
)
if self.is_deleted():
new_p.set_as_deleted()
new_p._sl = self.sl
new_p.modified()
return new_p
def __repr__(self):
return f"({self._x}, {self._y}, {self._z}, {self._name})"

View File

@ -202,7 +202,7 @@ class Profile(object):
if point in self._points:
point.set_as_not_deleted()
else:
self.points.insert(index, point)
self._points.insert(index, point)
self.modified()

View File

@ -369,6 +369,27 @@ class ProfileXYZ(Profile, SQLSubModel):
return profile
def copy(self):
new_p = ProfileXYZ(
id=-1,
name=self.name,
rk=self.rk,
reach=self.reach,
status=self._status
)
if self.is_deleted():
new_p.set_as_deleted()
new_p._sl = self.sl
for point in self._points:
p = point.copy()
print(p)
new_p._points.append(p)
new_p.modified()
return new_p
def point_from_data(self, header, data):
def float_format(s: str):
return float(

View File

@ -241,7 +241,6 @@ class GeometryProfileTableModel(PamhyrTableModel):
self.layoutChanged.emit()
def reverse(self):
self._undo.push(
ReverseCommand(
self._data
@ -259,15 +258,16 @@ class GeometryProfileTableModel(PamhyrTableModel):
self.layoutAboutToBeChanged.emit()
points = list(
map(
lambda d: self._data.point_from_data(header, d),
data
)
)
self._undo.push(
PasteCommand(
self._data, row,
list(
map(
lambda d: self._data.point_from_data(header, d),
data
)
)
self._data, row, points
)
)

View File

@ -294,13 +294,13 @@ class ProfileWindow(PamhyrWindow):
rows = table.selectionModel().selectedRows()
data = []
data.append(["x", "y", "z", "name"])
data.append(["name", "x", "y", "z"])
for row in rows:
point = self._profile.point(row.row())
data.append(
[
point.x, point.y, point.z, point.name
point.name, point.x, point.y, point.z
]
)

View File

@ -158,7 +158,7 @@ class PasteCommand(QUndoCommand):
self._row = row
self._profiles = list(
map(
lambda p: deepcopy(p),
lambda p: p.copy(),
profiles
)
)
@ -180,7 +180,7 @@ class DuplicateCommand(QUndoCommand):
self._rows = rows
self._profiles = list(
map(
lambda p: deepcopy(p),
lambda p: p.copy(),
profiles
)
)