Undo and redo operations are applied in many software applications, and 3DS MAX is no exception. So what does 3DS MAX use to implement undo and redo?
After reading deriving from restoreobj of Max SDK 2010, you will suddenly realize that Max uses restoreobj to implement undo and redo.
First, you need to implement a class that inherits restoreobj (deriverestoreobj). In this class, you need to implement the restore and redo functions in restoreobj, which are used
Implement the Undo and redo operations of Max.
In addition, you need to implement other methods, such as size (), endhold (), description () and other functions. The size function indicates the number of bytes of your restoreobj.
Endhold () is the end of setting a restore.
Next, we will use thehold to implement undo and redo operations. Here you use thehold as a stack bucket, and thehold. Begin () indicates starting
Put it into the operation, and thehold. Put (New deriverestoreobj (...) next to it indicates that the stack bucket must use the restore function and
The redo function is used to perform undo and redo operations.
After a code operation, thehold. Accept () indicates that the Code operation is pressed into the stack bucket, and thehold. Cancel () indicates that the operation is revoked from the stack bucket.
The Code operation is not pushed into the stack bucket, and thehold stack bucket is revoked.
Finally, let's take a look at the example of the Max SDK:
Class noderest: Public restoreobj {
Public:
Orient offs;
Orient redooffs;
Node * cur;
Noderest () {cur = NULL ;}
Noderest (node * node ){
Cur = node;
Offs = node-> modoffset;
}
~ Noderest (){}
Void restore (INT isundo );
Void Redo ();
Int size () {return 2 * sizeof (Orient) + sizeof (inode *);}
Void endhold () {cur-> clearaflag (a_held );}
Virtual tstr description () {return tstr (_ T ("node state "));}
};
Void node: holdstate (){
If (thehold. Holding ()&&! Testaflag (a_held ))
{
Thehold. Put (New noderest (this ));
Setaflag (a_held );
}
}