geometry: Add scheme undo/redo feature.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-04-20 10:51:20 +02:00
1 parent 6fcd0b83af
commit 51b9b3e1e4
4 files changed
+159 -24

No files matched your search

+34 -22
View File
@@ -8,7 +8,7 @@ from copy import deepcopy
from operator import itemgetter
from functools import reduce
from tools import flatten, timer
from tools import flatten, timer, trace
from Model.Geometry.Profile import Profile
from Model.Geometry.ProfileXYZ import ProfileXYZ
@@ -99,6 +99,19 @@ class Reach:
self._profiles.insert(index, profile)
self._update_profile_numbers()
def insert_profile(self, index: int, profile: Profile):
"""Insert new profile in list
Args:
index: The position of the new profile.
Returns:
Nothing.
"""
self._profiles.insert(index, profile)
self._update_profile_numbers()
def delete(self, list_index: list):
"""Delete some elements in profile list
@@ -124,13 +137,6 @@ class Reach:
else:
raise TypeError(f"{list_index} is instance of unexpected type '{type(list_index)}'")
def sort(self, is_reversed: bool = False):
self._profiles = sorted(
self._profiles,
key=lambda profile: profile.kp,
reverse=is_reversed
)
def get_x(self):
return [profile.x() for profile in self.profiles]
@@ -270,22 +276,28 @@ class Reach:
# Sort
def sort_ascending(self):
"""Sort profiles by increasing KP
@timer
def sort(self, is_reversed: bool = False):
self._profiles = sorted(
self._profiles,
key=lambda profile: profile.kp,
reverse=is_reversed
)
Returns:
Nothing.
"""
self._sort(is_reversed=False)
def sort_descending(self):
"""Sort profiles by decreasing KP
Returns:
Nothing.
"""
self._sort(is_reversed=True)
@timer
def sort_with_indexes(self, indexes: list):
if len(self._profiles) != len(indexes):
print("TODO: CRITICAL ERROR!")
self._profiles = list(
map(
lambda x: x[1],
sorted(
enumerate(self.profiles),
key=lambda x: indexes[x[0]]
)
)
)
# Copy/Paste