All entities can embed an arbitrary number of generic attributes. These attributes can be accessed using the generic attributes API.
When a generic attribute is of type A3DFloat, the value can be associated to a complex unit system, such as
m²/sec. This unit system can be expressed using the A3DMiscAttributeUnit structure.
This example shows how a simple "kilometers per hour" (km/h) is expressed using unit attributes. The structures are explained in detail below.
The A3DMiscAttributeBasicUnitData structure
An instance of
A3DMiscAttributeBasicUnitData represents an element of a complex unit system (the
k or the
km/h) it's structure is:
m_eUnit represents the domain of the unit: meters, hours, kelvins, ... It can be any value from the A3DEBasicUnit enum. In our example with
km/h the two values we use are kA3DUnit_Metre and kA3DUnit_Hour.
m_iExponent is used to represent how the basic unit is used in the whole unit system. It's value must be non-zero. In
km/h the exponent for the kilometers is
1 and the value for
-1. An other common value is
3, such as when expression square meters.
m_dFactor is a multiplier on the base unit base. A common example is
km where the factor is
1000 for "ten times a meter".
The A3DMiscAttributeUnitData structure
The A3DMiscAttributeUnitData is a collection of A3DMiscAttributeBasicUnitData and combines them to form a complex unit. In our example,
km/h is expressed by combining two A3DMiscAttributeBasicUnitData instances: one for the kilometers and one for the hours.
The structure is:
This structure simply aggregates A3DMiscAttributeBasicUnitData instances in an ordered array. m_pcName is used to give a name to the unit.
Getting the unit from generic attributes
When reading generic attributes from
A3DRootBase instances, the A3DMiscSingleAttributeData instance represents a unit-qualified value if:
- m_eType is kA3DModellerAttributeTypeReal
- m_usUnit is not
m_usUnit is an index to the Global data. This index points to an A3DMiscAttributeUnit handle which can be used to retrieve the A3DMiscAttributeUnitData instance.
This example shows how to get the complex unit system from an A3DMiscSingleAttributeData instance:
If this is run with our
km/h example, we would get: