Skip to content

Commit

Permalink
Renumber grains when one is deleted
Browse files Browse the repository at this point in the history
This is a great fix for the fact that hexrd expects the
grains to be sequentially numbered. We might be able to skip this in
the future if the requirement is removed from hexrd, but this works
fine for now.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Aug 25, 2022
1 parent b659f52 commit a9ef8b9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hexrd/ui/indexing/grains_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ def delete_grains(self, grain_ids):
any_modified = True

if any_modified:
self.renumber_grains()
self.grains_table_modified.emit()

def renumber_grains(self):
sorted_indices = np.argsort(self.full_grains_table[:, 0])
print(f'Renumbering grains from 0 to {len(sorted_indices) - 1}...')

for i, ind in enumerate(sorted_indices):
self.full_grains_table[ind, 0] = i

self.regenerate_grains_table()

def remove_rows(self, rows):
for row in rows:
self.beginRemoveRows(QModelIndex(), row, row)
Expand Down

0 comments on commit a9ef8b9

Please sign in to comment.