|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Wed Apr 06, 2016 8:14 pm Post subject: UNDO & REDO - Stacks of things to learn ? |
|
|
I've been pondering about how best to organise a program to perform what is one of the most taken for granted operations in any program.
I've quickly come to realise that it's maybe not as easy as it would appear to be trivial.
There seem to be 2 fundamental strategies:-
a) memorising previous states (e.g. by saving an image, or a list of parameters used to create it and then simply re-running the appropriate routine
b) recording a 'stack' (I believe that's the correct word) or rather 'stacks' of operations which may or may not be 'undo'-able and/or 'redo'-abl on an individual basis (a 'shorter' but maybe more complicated option it would seem at first glance)
It sounds simple, but probably isn't for anything but the simplest of cases.
All very well in theory, but , baffled by the terminologies bandied about I need hard and fast examples (not necessarily FTN95 nor indeed FORTRAN) to demonstrate the theories, and maybe even more importantly the pitfalls likely to be encountered.
As expected, sadly lacking in the netosphere.
I've seen fleeting glimpses of mention of UNDO/REDO on the forums here, but a search (the search facility still befuddles and confounds me) only dumps me a list of potential posts (containing the words UNDO-REDO), in which the titles give no real indication as to their applicability.
I found one, but it only briefly mentions the subject matter.
Are there any 'big posts' which discuss it in depth.
(PS - as an aside, why do some posts which the search pops up have the 'flashing' icon on left hand side ansėd others not ?)
More importantly, what experiences have users had in trying to (successfully or otherwise) applying any UNDO-REDO strategy.
Any practical links to interesting reads on the subject elsewhere in cyberspace would also be appreciated. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Wed Apr 06, 2016 9:52 pm Post subject: |
|
|
John,
I share your perplexity, and although I dabbled, I've never fully implemented undo/redo. The two approaches you suggest are not the full set of possibilities, as I will discuss below.
Your model 1, of remembering several states of your datafile depends on how large that datafile is. Some problems have small data structures, a number of which could be held in RAM, other problems have data structures that need to be held on disk. FTN95 has had a routine for generating unique file names now in the depths of the FTN77 library documentation, so you could use that to create a series of state files. You would also need to save some hints as to what the changes were, because otherwise you will find yourself not being able to explain what they are undoing!
Your model 2 is probably more compact, as all you need is for each change to remember the nature of the change via a code along with the requisite parameters that changed. But, you will find yourself writing a lot of code to add things back that were removed, or to remove things that were added.
In both cases, you have to decide how many steps back you need to go.
The model I ended up adopting was to make the dataset visible pictorially, and to make replacing something deleted or removing something added at least as simple as selecting 'undo': in other words, an implied depth of only 1. It can be enough, if it is obvious you made a mistake immediately after you did it.
It is helpful to ask for confirmation of any significant delete operation. I learnt after a while to add a 'Do not notify me of this again' tick box to the 'Are you sure?' popup. The corresponding strategy on insertion is to ask the user if they wish to save the current state of the dataset. |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Thu Apr 07, 2016 12:15 pm Post subject: |
|
|
John and Eddie,
Yes this is usually more difficult that the program itself. I have a few programs which when on save the file renames the previous file by modifying the extension and using the rename function available in FTN95. I go back only 10 saves. My normal files have the extension ".fbi" and I rename the previous .fbi to .fb1, and the previous .fb1 to .fb2.
I only go back 10 steps because my mind is stuck in a three character extension time warp.
I've used a similar technique when entering a dialogue box where I save the entire data file with some arbitrary file extension and re-read it if the user hits the "Cancel" button. I could have extended it to the multiple save and used the undo function. Redo would be similar an maintain a pointer to the current file so one can move in either direction. Of course files that were created after the undo step you have returned to need to be deleted if a new edit is performed.
If the data files are large, then you might consider only storing the section you are modifying.
In days gone by when commands were typed, I simply recorded these to a journal file for replaying after the inevitable crash, but these files had to be opened and closed as each item was output as if the program crashed, they could be lost as well. These were text files so you could simply edit out the last command that had caused the crash.
Regards
Ian |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sat Apr 09, 2016 11:15 pm Post subject: |
|
|
Ian,
Writing a file and immediately re-reading it is much faster that one would think, because it stays in the disk cache unless there is a heck of a lot of other stuff going on.
You may well be stuck with 10 digits, but then there's a whole alphabet and a bunch of other characters you could use ...
Eddie |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Mon Apr 11, 2016 12:13 pm Post subject: |
|
|
Eddie,
Thanks. I may move out of the time warp at some stage and move to four character file extensions, but the current file plus 9 backups- is enough for now.
For the program which I used as an example, it can currently run up to 1000 loadcases and I use .000 to .999 as the file extensions for each case.
Regards
Ian |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Mon Apr 11, 2016 12:14 pm Post subject: |
|
|
Eddie,
Thanks. I may move out of the time warp at some stage and move to four character file extensions, but the current file plus 9 backups- is enough for now.
For the program which I used as an example, it can currently run up to 1000 loadcases and I use .000 to .999 as the file extensions for each case.
Regards
Ian |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|