Undo / Redo

On Feb 2, 2007, at 7:55 PM, Donald Ephraim Curtis wrote:

How are you thinking about doing the Undo/Redo? Copies of the
molecule?

Qt 4.2 and later has a great feature for keeping an undo/redo stack.

http://doc.trolltech.com/4.2/qundo.html#undo-framework

Basically, any action we want to have undo/redo support for needs an
“action” as a subclass of QUndoCommand:

http://doc.trolltech.com/4.2/qundocommand.html

The subclass would have code for doing the action (redo) as well as
undo. For example, let’s say we have a draw action, which would
create an atom and a bond. We’d need to create DrawCommand which gets
passed the next atom id and bond id and appropriate parameters
(element, bond order, etc.).

virtual void redo() {
// create atom as we do now
// create bond as we do now
}

virtual void undo() {
DeleteAtom(m_atom_idx);
DeleteBond(m_bond_idx);
}

The minor disadvantage is that it requires a bit more coding and
classes to handle. The BIG advantage is memory savings, since you
can have a huge history (unlimited undo?) rather than keeping copies
of the molecule.

Granted, undo on something like a geometry optimization probably
requires at least storing all the previous coordinates.

Cheers,
-Geoff

We also need to consider Undo actions for Plugins. Right now the plugin
interface is kinda BETA. Don’t know how to get it where we want it.

(Fri, Feb 02, 2007 at 08:22:00PM -0500) Geoffrey Hutchison geoff.hutchison@gmail.com:

On Feb 2, 2007, at 7:55 PM, Donald Ephraim Curtis wrote:

How are you thinking about doing the Undo/Redo? Copies of the
molecule?

Qt 4.2 and later has a great feature for keeping an undo/redo stack.

http://doc.trolltech.com/4.2/qundo.html#undo-framework

Basically, any action we want to have undo/redo support for needs an
“action” as a subclass of QUndoCommand:

http://doc.trolltech.com/4.2/qundocommand.html

The subclass would have code for doing the action (redo) as well as
undo. For example, let’s say we have a draw action, which would
create an atom and a bond. We’d need to create DrawCommand which gets
passed the next atom id and bond id and appropriate parameters
(element, bond order, etc.).

virtual void redo() {
// create atom as we do now
// create bond as we do now
}

virtual void undo() {
DeleteAtom(m_atom_idx);
DeleteBond(m_bond_idx);
}

The minor disadvantage is that it requires a bit more coding and
classes to handle. The BIG advantage is memory savings, since you
can have a huge history (unlimited undo?) rather than keeping copies
of the molecule.

Granted, undo on something like a geometry optimization probably
requires at least storing all the previous coordinates.

Cheers,
-Geoff