Note that there are some explanatory texts on larger screens.

plurals
  1. POundo/redo with cascading deletions
    primarykey
    data
    text
    <p>I'm trying to implement an undo/redo feature into my application, using the <a href="http://en.wikipedia.org/wiki/Command_pattern" rel="noreferrer">Command Pattern</a>. I'm facing a problem.</p> <p>To illustrate it, let's imagine you can create with my application 2D profiles (as many as you want).</p> <p>From these 2D profiles, you can then create a 3D part with different attributes (name, colour, scale, etc.).</p> <pre><code>+--------------+ +--------------+ +--------------+ | 2D profile A | | 2D profile B | | 2D profile C | +--------------+ +--------------+ +--------------+ | | | | +---------------+ +---------------+ | | 3D Part B | | 3D Part C | | | Colour : blue | | Colour : grey | | | Name : bibi | | Name : foo | | | Scale : 33% | | Scale : 100% | | +---------------+ +---------------+ +--------------+ | 3D Part A | | Colour : red | | Name : aaa | | Scale : 50% | +--------------* </code></pre> <p>When a profile is deleted, all 3D parts which a built on this profile are automaticaly deleted too (when a profile is about to be deleted, a 3D part manager is notified and will delete the obsolete 3D parts. Views are also notified to update the GUI).</p> <p>This is where I'm facing a problem : I'm writing the undo/redo command for deleting a 2D profile, which looks something like this (pseudo-code) :</p> <pre><code>virtual void redo() { m_pProfileList.remove(m_pProfile); // This will automatically delete all 3D parts relying on the deleted 2D profile } virtual void undo() { m_pProfileList.add(m_pProfile); // This will add the 2D profile, but the 3D Parts are lost } </code></pre> <p>As you can see in the code above, removing the 2D profile will automatically delete all 3D parts relying on the removed profile.</p> <p>But when doing undo, re-adding the 2D profile to the list is not enough : the 3D parts are lost.</p> <p>What should I do ? Should the undo/redo command be responsible of taking care of the deletion of the 3D parts (which is something actually done by the 3d part manager) ? This would mean the undo/redo command would also be responsible to notify the views to update the GUI.</p> <p>Or should the undo/redo command create an internal copy of all 3d parts which will be deleted and let the 3d part manager delete the 3D parts ?</p> <p>Or is there another better solution ?</p> <p>Thanks for your help !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload