a2dWalkerIOHandler

Assume you have a a2dCanvasDocument filled with a2dCanvasObject, and now you want to perform some action on all your objects, but that can not be achieved with the standard functionality available in wxArt2D. You/we can not add virtual functions to the base class a2dCanvasObject for each and every action a user needs. So there should be a way to iterate through the objects of a document, but without adding new functions to classes. You could yourself program a class which iterates the document starting at its root objects, and recursive go into childs objects etc., but this is also limited. For instance it would be hard to iterate in exactly the same way as wxArt2D does it when it comes to events and rendering order. Therefore the way to do it is using a2dWalkerIOHandler. It is given as a context paramter to the objects to iterate. The object iterated itself, but at important point call the context with a specific id. Based on that id, you know where the iteration is at that moment, and if at the right spot, take action.

With this in place you can write advanced algorithms to work on canvas document, without the need to extend wxArt2D its fundamental classes first. To get an idea of what can be achieved, take a look at classes like:

The class a2dWalkerIOHandler is derived from a2dIOHandler. This last is the baseclass for implementing Saving and Loading the contents of your document to a file or string. Those implementations still implement there own iteration through a document. But wxArt2D its native format CVG, uses the a2dObject its Save and Load members to do this. The class for that is a2dIOHandlerXmlSerOut.

WalkerTraversion (last edited 2009-07-02 15:06:01 by KlaasHolwerda)