Nevron Open Vision Documentation
Schemas

 
Schemas Overview

You can think of node schemas as the DOM equivalent of each CLR object Type. This is because schemas primary serve for node reflection purposes. A singleton instance of the NSchema class is associated with each type of node instance. The respective NSchema instance can be accessed in two ways:

  1. Via the Schema property of each NNode instance.
  2. Via the public static readonly field that is assigned by the specific node type static constructor.

The schema created for each type of node, holds a reference to a base schema - the schema associated with the base node type. The base schema is accessible from BaseSchema property of each NSchema. In this way schemas are hierarchically organized to follow the type inheritance of each node type.

Schemas are used to define the self-properties that each specific node type declares.

Schemas are used to define the way in which a certain type of node aggregates other nodes. In case of container nodes, the schemas are also used to define the available child slots.

Creating Schemas

It is mandatory to create a schema instance for each type of node subclass that you want to create. The schema instance needs to be created in the static constructor and assigned to a public static readonly field, that follows the TypeName + "Schema" naming convention as shown in the following example:

My First Node
Copy Code
public class MyNode : NNode
{
 public MyNode()
 {
 }
 static MyNode()
 {
   MyNodeSchema = NSchema.Create(typeof(MyNode), NNode.NNodeSchema);
   // TODO: Declare Node Children Aggregation method
   // TODO: For container nodes - Create Node Child Slots
   // TODO: Create Node Self-Properties
   // TODO: Associate Custom Metadata
 }
 public static readonly NSchema MyNodeSchema;
}

As you can see, the first thing to do in the static constructor of a certain node type is to create a singleton schema instance for it, by passing the respective node type and base schema to the NSchema.Create method, and store the returned instance in a public static readonly field, that follows the mentioned naming convention. Once you do that you can perform the following optional schema building steps:

As mentioned in the Nodes topic, each type of node can aggregate other child nodes in its children dimension in two ways - as a collection or as a container.

If you want to make a collection node, you need to call the MakeCollection(NSchema childrenBaseSchema) method of the newly created schema (see Nodes for an example). If the base schema is already defined as a collection, the childrenBaseSchema argument can only be a schema that is equal or derived from the childrenBaseSchema of the base schema. If the base schema is already defined as container the method will throw an exception.

If you want to make a container node, you need to call the MakeContainer() method of the newly created schema. If the base schema is already defined as collection the method will throw an exception.

If you have declared the node as container you can define the node child slots by calling the AddChild method of the newly created schema (see Nodes for an example).

You can define the self-properties of the node type by calling the AddSlot and AddMember methods of the newly created schema (see Properties for an example).

You can associate custom metadata to the schema - see Schemas and Meta Units below.

Schemas and Properties
Because self-properties are created by the schema itself, schemas naturally know about them. The NSchema class has several methods that help you query and iterate the self-properties declared with it or with any of its base schemas:
Method Description

int GetPropertiesCount()

Gets the count of properties declared in this and base schemas.

NProperty GetPropertyByName(string name)

Tries to gets a property declared by this or base schemas that has the specified name. Returns null if such property does not exist.

NProperty GetPropertyById(int id)

Tries to gets a property declared by this or base schemas that has the specified id. Returns null if such property does not exist.

INIterator<NProperty> GetPropertyIterator()

Gets an iterator that iterates through the properties declared by this and base schemas.

INIterator<NProperty> GetPropertyIterator(INFilter<NProperty> filter)

Gets an iterator that iterates through the properties declared by this and base schemas, that pass the specified property filter.

See Properties topic more info.

Schemas and Children

We have already discussed that schemas defines the way in which a specific type of node aggregates other nodes. The schema ChildrenAggregation property returns the currently defined aggregation method (None, Collection or Container). In case of collection and container nodes, the ChildrenBaseSchema property returns the base schema of the possible node children.

In case the schema is defined for a container node, the following methods help you query and iterate the child slots declared with it or with any of its base schemas:

Method Description

int GetChildrenCount()

Gets the count of child slots declared in this and base schemas.

NChild GetChildByName(string name)

Tries to gets a child slot declared by this or base schemas that has the specified name. Returns null if such child slot does not exist.

NChild GetChildById(int id)

Tries to gets a child slot declared by this or base schemas that has the specified id. Returns null if such child slot does not exist.

INIterator<NChild> GetChildIterator()

Gets an iterator that iterates through the child slots declared by this and base schemas.

INIterator<NChild> GetChildIterator(INFilter<NChild> filter)

Gets an iterator that iterates through the child slots declared by this and base schemas, that pass the specified child slot filter.

See Child Slots for more info.

Schema Metadata

The metadata available for each schema includes flags and meta units. The following table summarizes the metadata API of NSchema.

Getter and Setter Description

Flags applicable to NElement derivates

bool GetFormulaSheet(NSchema schema)
void SetFormulaSheet(NSchema schema, bool value)

Gets or sets whether element instances of the schema must be considered as formula sheets. By default false. See Expressions for info about formula expressions and formula sheets).

bool GetChildrenAffectsParentMeasure(NSchema schema)
void SetChildrenAffectsParentMeasure(NSchema schema, bool value)

Gets or sets whether children changes of elements that are instances of the schema affect the measure of the parent measure element. By default false. The parent measure element is by default the first ancestor that implements the INMeasureElementParent interface. (see Measure and Arrange for more info).

bool GetChildrenAffectsParentArrange(NSchema schema)
void SetChildrenAffectsParentArrange(NSchema schema, bool value)

Gets or sets whether children changes of elements that are instances of the schema affect the measure of the parent arrange element. By default false. The parent arrange element is by default the first ancestor that implements the INArrangeElementParent interface. (see Measure and Arrange for more info).

bool GetChildrenAffectsParentDisplay(NSchema schema)
void SetChildrenAffectsParentDisplay(NSchema schema, bool value)

Gets or sets whether children changes of elements that are instances of the schema affect the parent display element. By default false.The parent display element is by default the first ancestor that is derived from NVisual (see The Visual Tree for more info). 

Flags applicable to NElement derivates that implement specific interfaces.

bool GetChildrenAffectsMeasure(NSchema schema)

void SetChildrenAffectsMeasure(NSchema schema, bool value)

Gets or sets whether children changes of elements that are instances of the schema affect the element measure. By default false. The element must implement the INMeasureElement interface (see Measure and Arrange for more info).

bool GetChildrenAffectsArrange(NSchema schema)
void SetChildrenAffectsArrange(NSchema schema, bool value)

Gets or sets whether children changes of elements that are instances of the schema affect the element arrange. By default false. The element must implement the INArrangeElement interface (see Measure and Arrange for more info).

Custom Flags - not used by NOV

bool GetCustomX(NSchema schema)
void SetCustomX(NSchema schema, bool value)
where X in [1: 5
] range

A set of 5 custom flags you can use as you wish.

Meta units are the DOM equivalent of CLR attributes. You can associate meta units with each schema instance via the SetMetaUnit(NMetaUnit unit) method. Several GetMetaUnit method overrides of NSchema help you query for meta units associated with the schema and its base schemas. See Meta Units for more info.
See Also
Send Feedback