Undo/Redo Callback or synchronization?

Hello everyone:

The undo/redo mechanism of OCAF works well as long as all the necessary information is in data framework. But for those information outside the data framework?

For example, suppose we have a tree-pane to show the structure of model, when we call Undo() method, the viewer updated. but what tree-pane does? It belongs to the GUI, it beyond the scope of OCAF.

Maybe we should synchronize calling our own Undo/Redo implementation about GUI elements together with the Undo invocation of TDocStd_Document? But if this is true, we must implement our own undo/redo mechanism. If there a callback or notification mechanism in OCAF?

Lugi.C's picture

Hi, fhchina:
I'm thinking the same problem these days,
the Undo/Redo mechanism is a complexity question in software design, I think the OCC will not provide such structure for the user, its goal is to make geometry object not the GUI, so this is out of its abilities.

So, I want to implement the Undo/Redo structure for other parts by myself, the "command" pattern has a such good idea for doing so.

best regards
Lugi.C

fhchina's picture

Yeah. I found one article on some MFC site to discuss a general Undo/Redo structure, but I have no time to read it.:-)

I have dived into some internal of the implemenation of OCAF Undo/Redo, it seems to require TDF_Attribute derived class to implement some Copy/Restore interface/virtual function.

If we must implement by ourself, the life is truely unhappy.

Umar Said's picture

Does anyone has solution for this? I have the same problem recently. Thanks.

Bearloga's picture

As fhchina said, we should implement our own TDF_Attribute derived class. It need no to be persistent, i.e. we need no to implement a persistent driver for it, it can be totally transient, creating it anew after each document retrieval. The virtual method AfterUndo should be used as a callback during undo/redo. The attribute must implement some counter that application must increment on modification of any model data. This attribute must create a proper delta using Backup mechanism. Under these conditions, the OCAF will call AfterUndo just after undo/redo has been done on this attribute.
Hint: place the attribute on the label with the most big tag number, so that this attribute treated the most last.