Page 1 of 1

Undo function

Posted: Tue Oct 25, 2011 10:17 pm
by bjcam
Hi
How do I apply 'Undo' and 'Redo' to annotations?
For example if a user changes the size of an annotation by mistake?
Also - is the only way to have an 'eraser' to use a white AnnotationTypeFreeHand?
Thanks

Re: Undo function

Posted: Wed Oct 26, 2011 11:32 am
by SamiKharma
Hi,
There are multiple ways in programming to do Undo-Redo, you can use stacks, object tracking, your own history class loaded with arrays for each structure.
Simplest way for the annotations would be to have a current annotation state for each annotation added.
The rest, would be basically saving annotations to the Temp Folder, loading from the Temp Folder and deleting the annotation.

To explain further, say you have a user who made a FilledRectangle annotation, you shall then make an instance of a class you made called AnnotationHistory, each annotation added will have an instance of this class.
This class will have the following data:
1. Number of Annotation changed
2. Current Annotation state.

When a change is made, the current annotation is saved to Tmp, deleted from the picture, and a the new change is made, then the Number of annotation is increased by one, and so is the current Annotation
When an Undo is made, a save of the current is made to TMP, deleted from the image, and then the Current Annotation -1 is loaded, and the Current Annotation is decreased by 1;
When a Redo is made, save of the current is made to TMP, deleted from the image, and then the Current Annotation +1 is loaded, and the Current Annotation is increased by 1.

It is very simple logic, we have implemented such a method in our upcoming Image Processing Demo which will be released very soon, and a similar logic should be added to our annotations demo, but a release time is not yet scheduled.
Hope this helps,
Sami Kharma,
GdPicture Support Team Member

Re: Undo function

Posted: Wed Oct 26, 2011 12:28 pm
by bjcam
Hi Sami
Thanks for the reply.
I thought the only way to save annotations was use SaveAnnotationsToXMP, which saves all annotations at once. Does this not mean constant saving and deleting of all annotations, and saving all annotations each time a change is made? Or is there another way to save/reload a single annotation?

Re: Undo function

Posted: Thu Oct 27, 2011 9:51 am
by SamiKharma
Hi,
I am sorry, you are correct, the saving applies to all annotations but the logic is the same. The only thing that would change is there would only be one instance of the History class per Image. And the loading and the saving of annotations would happen all at once.
As to another way to save and load would be to save the image using functions like SaveDocumentToJPEG, and loading them normally as if loading an image, with keeping the same logic.

Now to do undo and redo in case of saving XMPfiles using stacks probably would be easier. If you use images saving and loading, then definitely use saving onto TMP file and do not forget to delete all of them in the end. The reason for that is that you do not want to have many images in the memory while the program is running, and one image per annotation change, you will end up with a lot of memory consumed and definitely a lot of crashes on inferior computers.

Best Regards,
Sami Kharma
GdPicture Support Team Member

Re: Undo function

Posted: Wed Nov 21, 2012 3:15 pm
by hardikv
Can u please give me a sample code to undo newly added annotation?