RADF:How to Add an Attribute to a Document Node
This article discusses how to add a new attribute to a SceneNode.
NodeAttributes and Their Role in the RADF Document
NodeAttributes can be considered properties of a DocumentNode. They are used to append data to a DocumentNode. Typically, the data represented by a NodeAttribute includes information on how to display a DocumentNode, but they can also be used to attach application-specific data. For example, an existing NodeAttributeTransform class represents the transform associated with a DocumentNode. An application might have the need to store custom data associated with a DocumentNode. Adding a custom NodeAttribute class is a good way to do this. The NodeAttributes attached to a DocumentNode are stored in a NodeAttributeCollection that is a member of the DocumentNode.
Deriving a New Class from NodeAttribute
Application-specific NodeAttributes need to derive from the NodeAttribute abstract base class. The derived class needs to implement virtual methods that enable it to work within the attribute framework.
Methods to Override in the Derived Class
The derived class needs to override the clone method in NodeAttribute. The clone method is responsible for making a clone of the attribute. Because the derived class contains custom data, it needs to take the responsibility to clone itself.
Another method that the derived class needs to override is the DeserializedEquals method. This method is used to check if this object is equal to another, after deserialization.
public abstract NodeAttribute Clone(); public abstract bool DeserializedEquals(object obj);
A few virtual methods in NodeAttribute can be overridden by the derived class. These methods let the derived class specify custom behavior when a NodeAttribute is attached to a DocumentNode or combined with another NodeAttribute.
- The attach method is called when an attribute is attached to a DocumentNode.
- The skip method is called when the attachment of a NodeAttribute to a DocumentNode is skipped.
- The combine method is called when a NodeAttribute is combined with an existing NodeAttribute on the owner.
protected virtual bool skip(SceneNode owner); protected virtual bool attach(NodeAttribute attr, DocumentNode owner); protected virtual bool combine(NodeAttribute attr, DocumentNode owner);
Sample Classes Derived from NodeAttribute
RADF already implements classes derived from NodeAttribute. You can review the implementation of these classes to gain insight into their working. Some classes include NodeAttributeTransform and NodeAttributeTransparency.