Undo and Redo

There are two basic ways of recording the state for an undo operation. The automatic undo mechanism, the default, lets the system copy the object's complete state by calling the object's dwgOutFields() function with the undo filer. An alternative mechanism, referred to as the partial undo mechanism, requires more programming effort but enables you to write out and read in only the specific information regarding the particular modifications that were made to the object.

Every modification function for your new class (for example, any set() function) is required to call the assertWriteEnabled() function, which checks that the object is write-enabled. If the value of the autoUndo parameter for this function is kTrue, the object is recorded for undo. When the object modification is complete and the object is closed, the contents of the filer are saved into an undo file. For a given class, some modification functions can use the auto undo mechanism and others can implement a partial undo mechanism. The partial undo mechanism is useful if the modification involves a small amount of data.

When an UNDO command is invoked and an auto undo operation was performed, AutoCAD invokes dwgInFields() on the object, thus reading in the contents of the undo file.