[PythonCAD] Working on undo/redo stuff

Art Haas ahaas at airmail.net
Tue Jan 13 13:48:42 EST 2004


Not much mail moving through the list these days, so I thought I'd post
a message. I'm working on adding undo/redo stuff, and things are going
along slowly. I've spent time seeing how this sort of stuff is
implemented in other programs like Gnumeric and Kspread (spreadsheets),
Gimp (Graphics), and an old version of qcad. In a nutshell here's how
undo/redo works ...

1) Save the relevant info in your program that you are going to change.
2) Make the changes
3) Append the pre-change info on an 'undo' list.

No-duh, huh? To undo something, just pop the last thing off the list and
use that info to restore the program to the previous state, then append
the info on a 'redo' list. To redo an action, just pop the last item off
the 'redo' list, execute it, then push the info onto the 'undo' list.

Adding an undo/redo ability for things like changing an entities color
or linetype is straightforward, but things get more complex when
entities are deleted, and that is where I am getting bogged down. I
haven't figured a good way to store the undo/redo stuff so that it is
not tied to the existance of a particular object. By this I mean the
id() of the object, as the entities may/will get deleted during some
action, and then new entities will be created in the undo operation, so
the undo history of the old entity is now lost. One solution to this
problem is to not delete the entity so the history of that object is
still useable, but this could lead to significant increases of memory
usage. If a better solution does not present itself than this may be the
approach taken. Time will tell.

Comments and suggestions welcomed for other approaches welcomed.

Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822

More information about the PythonCAD mailing list