Revision: 26566
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26566
Author:   campbellbarton
Date:     2010-02-03 00:03:56 +0100 (Wed, 03 Feb 2010)

Log Message:
-----------
patch [#20889] Support "unit"s for FloatProperty
from Martin B?\195?\188rbaum (pontiac)
(with own minor changes)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/RNA_enum_types.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_rna.c
    trunk/blender/source/blender/python/intern/bpy_props.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c  2010-02-02 
21:43:26 UTC (rev 26565)
+++ trunk/blender/source/blender/editors/interface/interface.c  2010-02-02 
23:03:56 UTC (rev 26566)
@@ -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);
        }

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h  2010-02-02 21:43:26 UTC 
(rev 26565)
+++ trunk/blender/source/blender/makesrna/RNA_access.h  2010-02-02 23:03:56 UTC 
(rev 26566)
@@ -649,7 +649,6 @@
 int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char 
**identifier);
 int RNA_enum_bitflag_identifiers(EnumPropertyItem *item, const int value, 
const char **identifier);
 int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name);
-int RNA_enum_value(EnumPropertyItem *item, const char *name, int *r_value);
 
 void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA 
*prop, EnumPropertyItem **item, int *totitem, int *free);
 int RNA_property_enum_value(struct bContext *C, PointerRNA *ptr, PropertyRNA 
*prop, const char *identifier, int *value);

Modified: trunk/blender/source/blender/makesrna/RNA_enum_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_enum_types.h      2010-02-02 
21:43:26 UTC (rev 26565)
+++ trunk/blender/source/blender/makesrna/RNA_enum_types.h      2010-02-02 
23:03:56 UTC (rev 26566)
@@ -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);

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c   2010-02-02 
21:43:26 UTC (rev 26565)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c   2010-02-02 
23:03:56 UTC (rev 26566)
@@ -1034,17 +1034,6 @@
        return 0;
 }
 
-int RNA_enum_value(EnumPropertyItem *item, const char *name, int *r_value)
-{
-       for (; item->identifier; item++) {
-               if(item->identifier[0] && strcmp(item->identifier, name)==0) {
-                       *r_value= item->value;
-                       return 1;
-               }
-       }
-       return 0;
-}
-
 int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA 
*prop, const int value, const char **identifier)
 {      
        EnumPropertyItem *item= NULL;

Modified: trunk/blender/source/blender/makesrna/intern/rna_rna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_rna.c      2010-02-02 
21:43:26 UTC (rev 26565)
+++ trunk/blender/source/blender/makesrna/intern/rna_rna.c      2010-02-02 
23:03:56 UTC (rev 26566)
@@ -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.");
 

Modified: trunk/blender/source/blender/python/intern/bpy_props.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_props.c      2010-02-02 
21:43:26 UTC (rev 26565)
+++ trunk/blender/source/blender/python/intern/bpy_props.c      2010-02-02 
23:03:56 UTC (rev 26566)
@@ -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"
 
@@ -127,7 +128,7 @@
                if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, 
pyopts, &opts, "BoolProperty(options={...}):"))
                        return NULL;
 
-               if(pysubtype && RNA_enum_value(property_subtype_number_items, 
pysubtype, &subtype)==0) {
+               if(pysubtype && 
RNA_enum_value_from_id(property_subtype_number_items, pysubtype, &subtype)==0) {
                        PyErr_Format(PyExc_TypeError, 
"BoolProperty(subtype='%s'): invalid subtype.");
                        return NULL;
                }
@@ -189,7 +190,7 @@
                if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, 
pyopts, &opts, "BoolVectorProperty(options={...}):"))
                        return NULL;
 
-               if(pysubtype && RNA_enum_value(property_subtype_array_items, 
pysubtype, &subtype)==0) {
+               if(pysubtype && 
RNA_enum_value_from_id(property_subtype_array_items, pysubtype, &subtype)==0) {
                        PyErr_Format(PyExc_TypeError, 
"BoolVectorProperty(subtype='%s'): invalid subtype.");
                        return NULL;
                }
@@ -258,7 +259,7 @@
                if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, 
pyopts, &opts, "IntProperty(options={...}):"))
                        return NULL;
 
-               if(pysubtype && RNA_enum_value(property_subtype_number_items, 
pysubtype, &subtype)==0) {
+               if(pysubtype && 
RNA_enum_value_from_id(property_subtype_number_items, pysubtype, &subtype)==0) {
                        PyErr_Format(PyExc_TypeError, 
"IntProperty(subtype='%s'): invalid subtype.");
                        return NULL;
                }
@@ -321,7 +322,7 @@
                if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, 
pyopts, &opts, "IntVectorProperty(options={...}):"))
                        return NULL;
 
-               if(pysubtype && RNA_enum_value(property_subtype_array_items, 
pysubtype, &subtype)==0) {
+               if(pysubtype && 
RNA_enum_value_from_id(property_subtype_array_items, pysubtype, &subtype)==0) {
                        PyErr_Format(PyExc_TypeError, 
"IntVectorProperty(subtype='%s'): invalid subtype.");
                        return NULL;
                }
@@ -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\n"
+"   :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,19 +389,26 @@
                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={...}):"))
                        return NULL;
 
-               if(pysubtype && RNA_enum_value(property_subtype_number_items, 
pysubtype, &subtype)==0) {
+               if(pysubtype && 
RNA_enum_value_from_id(property_subtype_number_items, pysubtype, &subtype)==0) {
                        PyErr_Format(PyExc_TypeError, 
"FloatProperty(subtype='%s'): invalid subtype.");
                        return NULL;
                }
 
-               prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
+               if(pyunit && RNA_enum_value_from_id(property_unit_items, 
pyunit, &unit)==0) {
+                       PyErr_Format(PyExc_TypeError, 
"FloatProperty(unit='%s'): invalid unit.");
+                       return NULL;
+               }
+

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to