Interpolated profiles: fix undo/redo misconnection of undo_stack between geometry and profile window, adding a new data in the profile model, common to both window

dev_dylan
Dylan Jeannin 2026-09-11 18:48:45 +02:00
parent 0dbea26a2e
commit 5ce5478bf4
3 changed files with 156 additions and 29 deletions

View File

@ -47,6 +47,8 @@ class Profile(object):
self._sl = None
self._points: List[Point] = []
self._modification_count = 0
self._old_interpolated = ""
self._profile_type = _type
@ -227,8 +229,34 @@ class Profile(object):
return [point for point in self.points
if point.is_named()]
@property
def modification_count(self):
"""Content revision for this session; not stored in the database."""
return self._modification_count
def increase_modification_count(self):
"""Increase content revision for this session;
not stored in the database."""
self._modification_count += 1
def decrease_modification_count(self):
"""Decrease content revision for this session;
not stored in the database."""
self._modification_count -= 1
@property
def old_interpolated(self):
"""Old interpolated value for this session;
not stored in the database."""
return self._old_interpolated
@old_interpolated.setter
def old_interpolated(self, value):
self._old_interpolated = value
def content_modified(self):
"""An edited profile is no longer an interpolation result."""
# self._modification_count += 1
if hasattr(self, "_interpolated"):
self._interpolated = False
self.modified()

View File

@ -37,7 +37,11 @@ class SetDataCommand(QUndoCommand):
self._index = index
self._old = old_value
self._new = self.type(new_value)
self._old_interpolated = self._profile.interpolated
if self._profile.old_interpolated == "":
if self._profile.interpolated:
self._profile.old_interpolated = "interpolated"
else:
self._profile.old_interpolated = "not_interpolated"
class SetXCommand(SetDataCommand):
@ -47,11 +51,19 @@ class SetXCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).x = self._old
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).x = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -62,11 +74,19 @@ class SetYCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).y = self._old
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).y = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -77,11 +97,19 @@ class SetZCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).z = self._old
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).z = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -93,11 +121,19 @@ class SetNameCommand(SetDataCommand):
def undo(self):
self._profile.point(self._index).name = self._old
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.point(self._index).name = self._new
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -108,11 +144,16 @@ class AddCommand(QUndoCommand):
self._profile = profile
self._index = index
self._point = None
self._old_interpolated = self._profile.interpolated
def undo(self):
self._profile.delete_i([self._index])
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
@ -121,7 +162,7 @@ class AddCommand(QUndoCommand):
else:
self._profile.insert_point(self._index, self._point)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -131,17 +172,23 @@ class DelCommand(QUndoCommand):
self._profile = profile
self._points = points
self._old_interpolated = self._profile.interpolated
def undo(self):
for point in self._points:
point.set_as_not_deleted()
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.delete_points(self._points)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -152,7 +199,6 @@ class SortCommand(QUndoCommand):
self._profile = profile
self._column = column
self._reverse = _reverse
self._old_interpolated = self._profile.interpolated
old = self._profile._points
self._profile.sort(self._column, self._reverse)
@ -167,12 +213,19 @@ class SortCommand(QUndoCommand):
def undo(self):
self._profile.sort_with_indexes(self._indexes)
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.sort(self._column, self._reverse)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -184,14 +237,18 @@ class MoveCommand(QUndoCommand):
self._up = up == "up"
self._i = i
self._old_interpolated = self._profile.interpolated
def undo(self):
if self._up:
self._profile.move_up_point(self._i)
else:
self._profile.move_down_point(self._i)
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
@ -199,6 +256,7 @@ class MoveCommand(QUndoCommand):
self._profile.move_up_point(self._i)
else:
self._profile.move_down_point(self._i)
self._profile.increase_modification_count()
self._profile.interpolated = False
self._profile.modified()
@ -208,16 +266,22 @@ class ReverseCommand(QUndoCommand):
QUndoCommand.__init__(self)
self._profile = profile
self._old_interpolated = self._profile.interpolated
def undo(self):
self._profile.reverse()
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._profile.reverse()
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -228,17 +292,23 @@ class PurgeCommand(QUndoCommand):
self._deleted = []
self._profile = profile
self._np_purge = np_purge
self._old_interpolated = self._profile.interpolated
def undo(self):
for point in self._deleted:
point.set_as_not_deleted()
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
self._deleted = self._profile.purge(self._np_purge)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()
@ -249,17 +319,23 @@ class PasteCommand(QUndoCommand):
self._profile = profile
self._row = row
self._points = points
self._old_interpolated = self._profile.interpolated
self._points.reverse()
def undo(self):
self._profile.delete_points(self._points)
self._profile.interpolated = self._old_interpolated
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
self._profile.modified()
def redo(self):
for point in self._points:
self._profile.insert_point(self._row, point)
self._profile.interpolated = False
self._profile.increase_modification_count()
self._profile.modified()

View File

@ -41,6 +41,7 @@ class SetDataCommand(QUndoCommand):
self._index = index
self._old = old_value
self._new = self.type(new_value)
self._profile = self._reach.profile(self._index)
class SetNameCommand(SetDataCommand):
@ -48,30 +49,52 @@ class SetNameCommand(SetDataCommand):
self.type = str
super(SetNameCommand, self).__init__(
reach, index, old_value, new_value)
self._old_interpolated = self._reach.profile(self._index).interpolated
if self._profile.old_interpolated == "":
if self._profile.interpolated:
self._profile.old_interpolated = "interpolated"
else:
self._profile.old_interpolated = "not_interpolated"
def undo(self):
self._reach.profile(self._index).name = self._old
self._reach.profile(self._index).interpolated = self._old_interpolated
self._profile.name = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
def redo(self):
# Name setter will automatically update the interpolated attribute
self._reach.profile(self._index).name = self._new
self._profile.name = self._new
self._profile.increase_modification_count()
class SetRKCommand(SetDataCommand):
def __init__(self, reach, index, old_value, new_value):
self.type = float
super(SetRKCommand, self).__init__(reach, index, old_value, new_value)
self._old_interpolated = self._reach.profile(self._index).interpolated
if self._profile.old_interpolated == "":
if self._profile.interpolated:
self._profile.old_interpolated = "interpolated"
else:
self._profile.old_interpolated = "not_interpolated"
def undo(self):
self._reach.profile(self._index).rk = self._old
self._reach.profile(self._index).interpolated = self._old_interpolated
self._profile.rk = self._old
self._profile.decrease_modification_count()
if self._profile.modification_count == 0:
if self._profile.old_interpolated == "interpolated":
self._profile.interpolated = True
else:
self._profile.interpolated = False
self._profile.old_interpolated = ""
def redo(self):
# RK setter will automatically update the interpolated attribute
self._reach.profile(self._index).rk = self._new
self._profile.rk = self._new
self._profile.increase_modification_count()
class SetEnabledCommand(QUndoCommand):