Differences between revisions 3 and 5 (spanning 2 versions)
Revision 3 as of 2008-08-04 18:32:41
Size: 6374
Comment:
Revision 5 as of 2008-08-08 22:38:38
Size: 6411
Comment:
Deletions are marked like this. Additions are marked like this.
Line 15: Line 15:
PropertySystem
Line 18: Line 20:

/PropertySystem

General Module

Abstract

The module general is used by all other modules. It contains classes etc. that can be used in all other modules. a2dObject and its derived dynamic property classes are in this module. While the class a2dPropObject can hold dynamic properties in a property list. Another one is a2dSmrtPtr, which is a smart pointer template class. It works for classes with a Release and Own mechanism, which are all a2dObject derived classes. The Special a2dEvtHandler is defined here. It is almost equal to wxWidget its wxEvtHandler, only this one is derived from a2dObject instead. This makes it possible to serialize event handling classes. Serialization is done via wxDocviewIOHandlerXmlSer, which is in principle an XML parser, which uses wxWidget RTTI for creation of objects from classname strings. All in and output to and from objects can be implemented using a2dIOHandler. A special one is using the visitor design pattern a2dWalkerIOHandler, which can be used to iterate through hierarchies of a2dObject's.

a2dObject

This class implements reference counting and serialization. In many wxArt2D classes, pointer reference counting is used, it uses an Own and Release principle. The last objectX which owns an objectY will really delete the objectY when it releases that object. All the other Objects owning objectY will just lower the reference count when they release it. The class a2dSmrtPtr, which is a smart pointer template class, makes it very easy to use pointer reference counting. All Own and Release calls will be done automatically. For serialization of a2dObject hierarchies, there are Save and Load methods. This uses Serialisation for parsing and writing XML class data. In order to give classes serialization, you derive them from a2dObject.

a2dNamedProperty

PropertySystem

The dynamic properties are very important in wxArt2D, they are used to store data into classes which is not always there. And as such a prefect way to add data to classes without extending its memory usage permanently. For instance when editing a graphical object, all data that is needed temporarely to edit such an object, is stored as dynamic properties. Finishing the editing will free all dynamic properties, and brings back the object to its low memory usage. Another use is adding data to existing objects by user a program, without extending the class ( which is inside the library ). The last use is for storing undo data. The data that is modified inside a class is wrapped inside a property. So for class members it is wrapped into a a2dNamedProperty derived class. But when it is already a dynamic property on the object, its is simply refcounted once more. The data collected like a property is stored inside a property command. The command is containing the data before the change and after the change of the class. This command is placed on the undo stack. By storing changed data into a property class, and using this as an interface towards objects, it is sufficient to have only one command class. If not using such a system, one would need to define a specific command class for all different types of data changes to an object. In order to cope with many types of data, there is a range of a2dNamedProperty derived classes, each used for a different type of data. You can also define your own types, using complex internal data structure if needed. When setting a property to a class, the class itself is responsible for translating the property contents back to its internal data.

a2dPropObject

/PropertySystem

All classes with the ability to have dynamic properties attached to it, are derived from this class. Dynamic properties are a2dObject's derived, which are added to a a2dObjectList within the a2dPropObject. Serialization to or from a file for those properties is automatic. The properties can be used to stored almost any kind of data. In wxArt2D stroke and fill properties are stored as dynamic properties in a drawable canvas object. But also for user data or temporary data the properties can be used. The a2dPropObject has a range of functions to add, remove, modify, find etc. a property.

a2dEvtHandler

For event handling object, which or not wxWindow derived, this is used as a base class. This class is almost a direct copy of the wxWidget wxEvtHandler. This last is directly derived from wxObject, while a2dEvtHandler is derived from a2dObject. Therefore all those event handling classes in wxArt2D can be reference counted and serialized. The defenitions of an event table, is equal to the wxWidget normal event table, but instead of EVT_ you need to use !A2D_EVT_ like this:

   1 BEGIN_EVENT_TABLE( a2dDocument, a2dEvtHandler )
   2     EVTREF_CLOSE_VIEW( a2dDocument::OnCloseView )
   3 END_EVENT_TABLE()

a2dIOHandlerXmlSerIn and a2dIOHandlerXmlSerOut

Class a2dIOHandlerXmlSerIn and a2dIOHandlerXmlSerOut are used by a2dObject and derived classes to load and save class data to an XML serialization format. Since these classes input and output to a a2dDocument, the classes are derived from a2dIOHandlerStrIn and a2dIOHandlerStrOut at the bottom. The class a2dIOHandlerXmlSerIn internal uses expat for parsing XML data, and a2dIOHandlerXmlSerOut has functionality to easily write XML data to a file. The serialization format is using wxWidget RTTI to create classes based on the classname string. Your own classes can easily be serialized in the same form. An important feature is that it supports hierarchies of class data, including reference counted objects. So one object can be used by several parent objects. When reading from a file those references are resolved automatically. Parsing of the XML data is directly from a stream, and no DOM structure is used in between, this way of parsing XML data is called Pull parsing. The functions to save and load data are integrated with the classes itself. Hierarchies of classes via child objects, are easily reconstructed from a file, also multiple child branches ( one in the base class, one in a derived class ), are reloaded properly.

wxArt2D: GeneralModule (last edited 2011-03-05 17:10:40 by dslb-084-058-165-011)