Unit Converter
Realsoft 3D uses SI unit system internally (meters, radians, etc.). The user interface shows the units with the desired user selected units (cm, degrees etc.). Unit conversion class impelements functionality for converting SI units to desired user selected units for the user interface.
If you implement new gadgets, you should also implement support for unit converter. Your gadget should attach to the unit converter through model-view system. For example, the vector gadget is simply a string gadget. Whenever the user enters a value through it, the gadget calls R3UNITCONVM_STRINGTOVECTOR to convert the entered value to internal units. Also, when the model's attribute has changed, the gadget convert the model's SI units to user preferred format by calling R3UNITCONVM_VECTORTOSTRING.
Most user interface objects dealing with numeric data define attribute for unit converter. For example, to create a vector gadget with unit conversion support:
#include <real/gadget/r3vectg.h>
gad = R3New(R3CLID_VECTORGADGET,
R3T(R3VCGA_UnitConverter, unitconverter),
R3T(R3VCGA_UnitType, R3UNIU_DISTANCE),
...
If you use vector gadget to show polar coordinates, you should use R3UNIU_ANGLE rather than R3UNIU_DISTANCE.
To fetch the unit converter from the current project and to convert a string representing a vector value to a vector type:
R3OBJ *unitcv;
R3VECTOR v;
R3GetAttrs(currentlayer,
R3T(R3LAYLA_UnitConverter, &unitcv),
R3TAG_END);
R3DoA3(unitcv, R3UNITCONVM_STRINGTOVECTOR, R3UNIU_DISTANCE, "1.2 0.2 0.5", &v);