[vtk-developers] undo / redo for widgets

Karthik Krishnan karthik.krishnan at kitware.com
Thu Nov 26 00:41:05 EST 2009


On Thu, Nov 26, 2009 at 12:34 AM, Karthik Krishnan
<karthik.krishnan at kitware.com> wrote:

> 4. At some point, I had the idea of adding XML IO to all the widgets.
> This is how we VolView creates session files. So every widget and
> representation used in VolView has a corresponding XML reader/writer
> for instance :
>
>  vtkXMLAngleWidgetReader,
>  vtkXMLAngleWidgetWriter,
>  vtkXMLAngleRepresentation2DReader,
>  vtkXMLAngleRepresentation2DWriter.
>
> At any point the application can ask the widget to serialize itself
> and restore it exactly to that state when needed. This framework could
> be useful for maintaining state in a stream, or serializing to a file.
>
> An class can maintain a queue of these stringstreams for any widget.
> Something like...
>
>  class vtkAbstractWidgetStates< class TAbstractWidget >
>    {
>    void SetWidget( TAbstractWidget * );
>
>    vtkTimeStamp Serialize( std::ostringstream &os );
>    bool UnSerialize( std::ostringstream &os );
>
>    void Undo() { --pos; UnSerialize( pos->second ); }
>    void Redo()..
>
>    void RecordState() { // Create new stringstream. Serialize, pushback }
>
>    std::map< vtkTimeStamp, std::ostringstream * > History;
>    HistoryIterator pos;
>    }
>
> This takes care of Issue (2), since serialization means that the
> widget should be entirely reproducible from the state...
> Also, all the undo / redo code is kept out of the widget /
> repesentation and done by the stateManager.


And to drive all this, so that the widget automatically supports
undo/redo, one could use an event mechanism.. The widget could
periodically invoke a RecordStateEvent, (this may be co-invoked with
EndInteractionEvent) and its stateManager would then record the event.
Disabling / Re-enabling Undo/Redo functionality is simply a question
of removing observers on the RecordStateEvent...

Thanks



More information about the vtk-developers mailing list