Assume you have a a2dDrawing 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 parameter to the objects to iterate. The object iterates itself, but at important points calls 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 drawing. But wxArt2D its native format CVG, uses the a2dObject its Save and Load members to do this. The class for that is a2dIOHandlerXmlSerOut.

wxArt2D: WalkerTraversion (last edited 2016-05-03 09:33:01 by KlaasHolwerda)