Index: blender/source/blender/python/intern/bpy_props.c =================================================================== --- blender/source/blender/python/intern/bpy_props.c (Revision 26563) +++ blender/source/blender/python/intern/bpy_props.c (Arbeitskopie) @@ -28,6 +28,7 @@ #include "RNA_access.h" #include "RNA_define.h" /* for defining our own rna */ +#include "RNA_enum_types.h" #include "MEM_guardedalloc.h" @@ -355,14 +356,16 @@ static char BPy_FloatProperty_doc[] = -".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE')\n" +".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE', unit='NONE')\n" "\n" " Returns a new float property definition.\n" "\n" " :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n" " :type options: set\n" " :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n" -" :type subtype: string"; +" :type subtype: string" +" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n" +" :type unit: string\n"; PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw) { StructRNA *srna; @@ -377,7 +380,7 @@ return NULL; /* self's type was compatible but error getting the srna */ } else if(srna) { - static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", NULL}; + static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "unit", NULL}; char *id=NULL, *name="", *description=""; float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f; int precision= 2; @@ -386,8 +389,10 @@ int opts=0; char *pysubtype= NULL; int subtype= PROP_NONE; + char *pyunit= NULL; + int unit= PROP_UNIT_NONE; - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssffffffiO!s:FloatProperty", kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, &pyopts, &pysubtype)) + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssffffffiO!ss:FloatProperty", kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, &pyopts, &pysubtype, &pyunit)) return NULL; if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "FloatProperty(options={...}):")) @@ -398,7 +403,14 @@ return NULL; } + if(pyunit && RNA_enum_value(property_unit_items, pyunit, &unit)==0) { + PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit."); + return NULL; + } + printf("BPy_FloatProperty: %i %s\n", unit, pyunit); + prop= RNA_def_property(srna, id, PROP_FLOAT, subtype); + RNA_def_property_unit(prop, unit); RNA_def_property_float_default(prop, def); RNA_def_property_range(prop, min, max); RNA_def_property_ui_text(prop, name, description); Index: blender/source/blender/makesrna/intern/rna_rna.c =================================================================== --- blender/source/blender/makesrna/intern/rna_rna.c (Revision 26563) +++ blender/source/blender/makesrna/intern/rna_rna.c (Arbeitskopie) @@ -32,6 +32,17 @@ #include "rna_internal.h" +EnumPropertyItem property_unit_items[] = { + {PROP_UNIT_NONE, "NONE", 0, "None", ""}, + {PROP_UNIT_LENGTH, "LENGTH", 0, "Length", ""}, + {PROP_UNIT_AREA, "AREA", 0, "Area", ""}, + {PROP_UNIT_VOLUME, "VOLUME", 0, "Volume", ""}, + {PROP_UNIT_ROTATION, "ROTATION", 0, "Rotation", ""}, + {PROP_UNIT_TIME, "TIME", 0, "Time", ""}, + {PROP_UNIT_VELOCITY, "VELOCITY", 0, "Velocity", ""}, + {PROP_UNIT_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""}, + {0, NULL, 0, NULL, NULL}}; + #ifdef RNA_RUNTIME #include "BLI_ghash.h" @@ -926,16 +937,6 @@ {PROP_LAYER, "LAYER", 0, "Layer", ""}, {PROP_LAYER_MEMBER, "LAYER_MEMBERSHIP", 0, "Layer Membership", ""}, {0, NULL, 0, NULL, NULL}}; - static EnumPropertyItem unit_items[] = { - {PROP_UNIT_NONE, "NONE", 0, "None", ""}, - {PROP_UNIT_LENGTH, "LENGTH", 0, "Length", ""}, - {PROP_UNIT_AREA, "AREA", 0, "Area", ""}, - {PROP_UNIT_VOLUME, "VOLUME", 0, "Volume", ""}, - {PROP_UNIT_ROTATION, "ROTATION", 0, "Rotation", ""}, - {PROP_UNIT_TIME, "TIME", 0, "Time", ""}, - {PROP_UNIT_VELOCITY, "VELOCITY", 0, "Velocity", ""}, - {PROP_UNIT_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""}, - {0, NULL, 0, NULL, NULL}}; srna= RNA_def_struct(brna, "Property", NULL); RNA_def_struct_ui_text(srna, "Property Definition", "RNA property definition."); @@ -978,7 +979,7 @@ prop= RNA_def_property(srna, "unit", PROP_ENUM, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_enum_items(prop, unit_items); + RNA_def_property_enum_items(prop, property_unit_items); RNA_def_property_enum_funcs(prop, "rna_Property_unit_get", NULL, NULL); RNA_def_property_ui_text(prop, "Unit", "Type of units for this property."); Index: blender/source/blender/makesrna/intern/rna_define.c =================================================================== --- blender/source/blender/makesrna/intern/rna_define.c (Revision 26563) +++ blender/source/blender/makesrna/intern/rna_define.c (Arbeitskopie) @@ -1006,6 +1006,11 @@ prop->flag &= ~flag; } +void RNA_def_property_unit(PropertyRNA *prop, int unit) +{ + prop->subtype |= unit; +} + void RNA_def_property_array(PropertyRNA *prop, int length) { StructRNA *srna= DefRNA.laststruct; Index: blender/source/blender/makesrna/RNA_define.h =================================================================== --- blender/source/blender/makesrna/RNA_define.h (Revision 26563) +++ blender/source/blender/makesrna/RNA_define.h (Arbeitskopie) @@ -131,6 +131,7 @@ void RNA_def_property_flag(PropertyRNA *prop, int flag); void RNA_def_property_clear_flag(PropertyRNA *prop, int flag); +void RNA_def_property_unit(PropertyRNA *prop, int unit); void RNA_def_property_array(PropertyRNA *prop, int length); void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, int length[]); void RNA_def_property_range(PropertyRNA *prop, double min, double max); Index: blender/source/blender/makesrna/RNA_enum_types.h =================================================================== --- blender/source/blender/makesrna/RNA_enum_types.h (Revision 26563) +++ blender/source/blender/makesrna/RNA_enum_types.h (Arbeitskopie) @@ -77,6 +77,8 @@ extern EnumPropertyItem wm_report_items[]; +extern EnumPropertyItem property_unit_items[]; + struct bContext; struct PointerRNA; EnumPropertyItem *rna_TransformOrientation_itemf(struct bContext *C, struct PointerRNA *ptr, int *free); Index: blender/source/blender/editors/interface/interface.c =================================================================== --- blender/source/blender/editors/interface/interface.c (Revision 26563) +++ blender/source/blender/editors/interface/interface.c (Arbeitskopie) @@ -1429,6 +1429,12 @@ if(subtype == PROP_UNIT_LENGTH) { return value * scene->unit.scale_length; } + else if(subtype == PROP_UNIT_AREA) { + return value * pow(scene->unit.scale_length, 2); + } + else if(subtype == PROP_UNIT_VOLUME) { + return value * pow(scene->unit.scale_length, 3); + } else if(subtype == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */ return FRA2TIME(value); }