Property Metadata

From K-3D

Jump to: navigation, search

Overview

Starting in K-3D 0.7.6.0, properties can advertise "metadata", an arbitrary collection of name-value string pairs property details that can't be inferred from the property type. The interpretation of specific names and values is left to other parts of the system, such as the UI layer. By definition, metadata name-value pairs are modeled on XML attributes, including the use of namespaces.

Working With Metadata

Any part of the system can read/write metadata on an existing property, provided the property implements the k3d::imetadata interface. Currently, all user properties implement k3d::imetadata, along with a handful of builtin properties. Currently there is access via C++ and Python:

C++:

if(k3d::imetadata* const metadata = dynamic_cast<k3d::imetadata*>(property))
{
  metadata->set_metadata("my_name", "my_value");
  k3d::string_t value = metadata->get_metadata()["my_name"];
  metadata->erase_metadata("my_name");
}

Python:

m = k3d.dynamic_cast(property, "imetadata")
m.set_metadata("my_name", "my_value")
m.get_metadata()["my_name"]
m.erase_metadata("my_name")

Currently Defined Namespaces/Names

k3d

The k3d namespace is reserved for use by the K-3D application:

  • k3d:domain - Specifies the domain over which a value or collection of values is defined. An example would be specifying that an integer must be non-negative.
  • k3d:role - Identifies the purpose of a value or collection of values beyond that which can be inferred from their type:
    • k3d:multi-line-text - The property is a k3d::string_t that stores multiple lines of text.
    • k3d:nurbs-knot-vector - The property is a std::vector<k3d::double_t> that represents a NURBS knot-vector.
Personal tools