Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am thinking about creating (developing, programming) "undo" action in 3D-Scene editor. Is there a standard solution?
Posted
Comments
Sergey Alexandrovich Kryukov 8-Dec-11 13:00pm    
It totally depends on what are you using for 3D.
--SA
VKarpov 8-Dec-11 13:17pm    
Plain C++ in Microsoft VisualStudio 6.0 + OpenGL. Do you know any smple code?
Sergey Alexandrovich Kryukov 8-Dec-11 19:00pm    
No, sorry.
--SA

1 solution

To implement undo, you need to be able to implement the concept of 'state' in your application.

The simplest mechanism might be to copy an object every time you change it, and put the old value on a save stack.

The save stack should have the following members in the records.
1. Action - What will be undone. Edit/Delete/Insert...
2. Old Object * - A pointer the object removed.
3. New Object * - A pointer to the new object that was added.

So every time there's a change, push the changed state on the stack.
And when you undo, pop the last action off and reverse it.

This is a basic way to start your implementation. How you implement it and what additional features you'll need will be up to how your application is structured and your coding style.
 
Share this answer
 
v2
Comments
VKarpov 8-Dec-11 13:19pm    
Do you know any sample (tutorial) code for C++?
JackDingler 8-Dec-11 13:36pm    
I've never looked for one. I've used existing code bases and rolled my own.

There can't really be a one size fits all solution, because every application's core functionality is different.

Start by creating a core class for your records and a class to contain the stack. You'll want to dynamically allocate record and save the pointers to them so you can use derived classes.

The std::deque is a good way to store your data as it supports fast push and pop operations. Your data member might look like std::deque<cundorecord *=""> RecordStack
Sergey Alexandrovich Kryukov 8-Dec-11 19:05pm    
Sounds reasonable, my 5. You can also add a stack of added/removed objects and keep them all to the certain required number. It's not expensive as the stack elements are just pointers, but keeping removed objects can be expensive. As to the support of all the edition steps (such as deformations, individual object zooms, motions) in the undo history -- this is much more difficult, will need a lot of though on architecture, in fact.
--SA
JackDingler 8-Dec-11 22:20pm    
The big CAD packages handle this by caching undo items to disk.

Some of those operations you describe may be too difficult to reverse the operation on. Saving the data set that is being manipulated may be the only option will be reliable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900