Undo step...

I am displaying edge and immediately undo it. But its failing.

TCollection_ExtendedString str1("UndoStep");
Handle (TDocStd_Document) theDocument = new TDocStd_Document(str1);
TPrsStd_AISViewer::New(theDocument->Main(),myContext->CurrentViewer());
theDocument->SetUndoLimit(10);
theDocument->NewCommand();

TDF_Label aMainLabel = theDocument->Main();
Handle(Geom_TrimmedCurve) aPoleSegment1 = GC_MakeSegment(gp_Pnt(100, 100, 0.0), gp_Pnt(200, 300, 0.0));
TopoDS_Edge PoleEdge1 = BRepBuilderAPI_MakeEdge(aPoleSegment1);
DisplayShapes(myContext, PoleEdge1);

TDF_Label AnnotLabel= TDF_TagSource::NewChild(aMainLabel);

theDocument->CommitCommand();
int i = theDocument->GetAvailableUndos(); //getting count 1

Standard_Boolean flg = theDocument->Undo(); //returns true and should undo the edge displayed on screen.
myView->Redraw();
myContext->UpdateCurrentViewer();

Plz, help on this?

-Komal Patil

ciplogic's picture

Hi Komal,

You make a small mistake here. OCAF stores as your code shows a document that internally stores a tree of nodes and attributes.
The OpenCascade context mostly stores the scene (the scene contained as topological shapes stored as AIS_Shapes).

You will have to add a "Function" to your label. A function is a custom-made attribute that can be attached to your node. And this function can be undo-ed.

So resuming you have this configuration in your document/tree: aMainLabel>AnnotLabel and for your undo/redo to work, you have to:
aMainLabel>AnnotLabel>TFunction that stores the shape creation code (your code with MakeSegment... and such). And when you will do the Undo, the tree will remove your aMainLabel and AnnotLabel and your TFunction and automatically will remove (using a PresentationManager class) your contained shape from context.
At the end you will have to see OCAF as a persistence layer on top of OpenCascade context. You can work with OCC context if you want, but after you use OCAF, you will have to store everything that creates the shape as attributes.
This code is only an overview because I'm not an expert of OCAF, but I've tried that everything I've wrote you down to be accurate.
Hope it helps,
Ciprian