Geometry: Fix section modification command.

scenarios
Pierre-Antoine 2025-09-05 16:57:12 +02:00
parent a6341dedd2
commit c58620fdc2
4 changed files with 34 additions and 14 deletions

View File

@ -239,10 +239,10 @@ class Profile(object):
# Move # Move
def move_up_point(self, index: int): def move_up_point(self, index: int):
if index < len(self.points): if index < len(self._points):
next = index - 1 next = index - 1
p = self.points p = self._points
p[index], p[next] = p[next], p[index] p[index], p[next] = p[next], p[index]
self.modified() self.modified()
@ -250,7 +250,7 @@ class Profile(object):
if index >= 0: if index >= 0:
prev = index + 1 prev = index + 1
p = self.points p = self._points
p[index], p[prev] = p[prev], p[index] p[index], p[prev] = p[prev], p[index]
self.modified() self.modified()
@ -265,7 +265,7 @@ class Profile(object):
def predicate(p): return p.z def predicate(p): return p.z
self._points = sorted( self._points = sorted(
self.points, self._points,
key=predicate, key=predicate,
reverse=is_reversed reverse=is_reversed
) )
@ -273,14 +273,14 @@ class Profile(object):
@timer @timer
def sort_with_indexes(self, indexes: list): def sort_with_indexes(self, indexes: list):
if len(self.points) != len(indexes): if len(self._points) != len(indexes):
logger.critical("Indexes list do not correspond to point list") logger.critical("Indexes list do not correspond to point list")
self._points = list( self._points = list(
map( map(
lambda x: x[1], lambda x: x[1],
sorted( sorted(
enumerate(self.points), enumerate(self._points),
key=lambda x: indexes[x[0]] key=lambda x: indexes[x[0]]
) )
) )

View File

@ -45,6 +45,19 @@ _translate = QCoreApplication.translate
class GeometryProfileTableModel(PamhyrTableModel): class GeometryProfileTableModel(PamhyrTableModel):
def get_true_data_row(self, row):
profile = self._data.point(row)
return next(
map(
lambda e: e[0],
filter(
lambda e: e[1] == profile,
enumerate(self._data._points)
)
), 0
)
def data(self, index, role=Qt.DisplayRole): def data(self, index, role=Qt.DisplayRole):
if index.isValid(): if index.isValid():
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
@ -162,6 +175,8 @@ class GeometryProfileTableModel(PamhyrTableModel):
def insert_row(self, row, parent=QModelIndex()): def insert_row(self, row, parent=QModelIndex()):
self.beginInsertRows(parent, row, row - 1) self.beginInsertRows(parent, row, row - 1)
row = self.get_true_data_row(row)
self._undo.push( self._undo.push(
AddCommand( AddCommand(
self._data, row self._data, row
@ -176,7 +191,12 @@ class GeometryProfileTableModel(PamhyrTableModel):
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._data, rows self._data, list(
map(
lambda r: self.get_true_data_row(r),
rows
)
)
) )
) )
@ -200,10 +220,10 @@ class GeometryProfileTableModel(PamhyrTableModel):
if row <= 0: if row <= 0:
return return
target = row + 2 target = row + 1
self.beginMoveRows(parent, row - 1, row - 1, parent, target) self.beginMoveRows(parent, row - 1, row - 1, parent, target)
row = self.get_true_data_row(row)
self._undo.push( self._undo.push(
MoveCommand( MoveCommand(
self._data, "up", row self._data, "up", row
@ -218,9 +238,9 @@ class GeometryProfileTableModel(PamhyrTableModel):
return return
target = row target = row
self.beginMoveRows(parent, row + 1, row + 1, parent, target) self.beginMoveRows(parent, row + 1, row + 1, parent, target)
row = self.get_true_data_row(row)
self._undo.push( self._undo.push(
MoveCommand( MoveCommand(
self._data, "down", row self._data, "down", row

View File

@ -144,9 +144,9 @@ class SortCommand(QUndoCommand):
self._column = column self._column = column
self._reverse = _reverse self._reverse = _reverse
old = self._profile.points old = self._profile._points
self._profile.sort(self._column, self._reverse) self._profile.sort(self._column, self._reverse)
new = self._profile.points new = self._profile._points
self._indexes = list( self._indexes = list(
map( map(

View File

@ -132,8 +132,8 @@ class ProfileWindow(PamhyrWindow):
actions = {} actions = {}
else: else:
actions = { actions = {
"action_sort_asc": self.sort_X_ascending, "action_sort_asc": self.sort_Y_ascending,
"action_sort_des": self.sort_X_descending, "action_sort_des": self.sort_Y_descending,
"action_up": self.move_up, "action_up": self.move_up,
"action_down": self.move_down, "action_down": self.move_down,
"action_add": self.add, "action_add": self.add,