Operating system: window 11
Slicer version: slicer 5.2.1
Q1. After searching various materials, it was said that the undo/redo function for all nodes drawn in the scene is difficult to implement. Is this true?
Q2. If so, I want to create a redo and undo function for a specific node (markupFiducial, Closedcurved).
# Enable undo for the scene
slicer.mrmlScene.SetUndoOn()
# Enable undo for markups fiducial nodes
defaultMarkupsNode = slicer.mrmlScene.GetDefaultNodeByClass("vtkMRMLMarkupsFiducialNode")
if not defaultMarkupsNode:
defaultMarkupsNode = slicer.vtkMRMLMarkupsFiducialNode()
slicer.mrmlScene.AddDefaultNode(defaultMarkupsNode)
defaultMarkupsNode.UndoEnabledOn()
# Add standard keyboard shortcuts for scene undo/redo
redoKeyBindings = qt.QKeySequence.keyBindings(qt.QKeySequence.Redo)
for redoBinding in redoKeyBindings:
redoShortcut = qt.QShortcut(slicer.util.mainWindow())
redoShortcut.setKey(redoBinding)
redoShortcut.connect("activated()", slicer.mrmlScene.Redo)
undoKeyBindings = qt.QKeySequence.keyBindings(qt.QKeySequence.Undo)
for undoBinding in undoKeyBindings:
undoShortcut = qt.QShortcut(slicer.util.mainWindow())
undoShortcut.setKey(undoBinding)
undoShortcut.connect("activated()", slicer.mrmlScene.Undo)
This @lassoan 's code not working in python interactor
After posting this question, I’ll add more detailed questions as I continue to investigate.
What I want to know is how to implement redo/undo for a specific node.