【转】How do I use MDGModifier so I can get reliable Undo/Redo?

来源:互联网 发布:台湾购物数据 编辑:程序博客网 时间:2024/06/05 09:12

 

I've had several logistical problems with MDGModifiers, exclusively with its ::undo() and ::redo() mechanism. After much trial and error on the topic I've come to the following conclusions:

There are times when you may have to perform a ::doIt() in the middle of your MDGModifier modification so the scene state is valid for further operations. For example, if you use MDGModifier::create(), you will need to ::doIt() so this node exists if you wish to perform any edits using a class other than MDGModifier (finding an MPlug on your new node, for instance).

Do not continue to use a MDGModifier object after you have called its ::doIt() method!

My "Golden Rule" for MDGModifier is now the following:

"Execute ::doIt() as soon as I need to update the state of the scene, then immediately allocate another MDGModifier for further edits. Continue, rinse, repeat."

All allocated MDGModifier nodes go onto a stack. The stack in undone in FILO order, and redone in FIFO order.