fix for using subtype units that are not defined as a part of types. eg.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Aug 2009 11:50:40 +0000 (11:50 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Aug 2009 11:50:40 +0000 (11:50 +0000)
 prop= RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ|PROP_UNIT_LENGTH);

source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/makesrna.c

index 0a641ecebe94a0ad112bc6dcecb75df44375dae6..4833640a04b94a134d77e19ff647594acdee7aa3 100644 (file)
@@ -66,6 +66,7 @@ typedef enum PropertyType {
        PROP_COLLECTION = 6
 } PropertyType;
 
+/* also update rna_property_subtype_unit when you change this */
 typedef enum PropertyUnit {
        PROP_UNIT_NONE = (0<<16),
        PROP_UNIT_LENGTH = (1<<16),                     /* m */
index 8b9ce879b8aa4ba2299f12e601bfa03ec90ed59f..05eac06de7ffeceac29bbc2251f0be2ec1bea802 100644 (file)
@@ -1388,6 +1388,30 @@ static const char *rna_property_subtypename(PropertyType type)
                case PROP_XYZ: return "PROP_XYZ";
                case PROP_RGB: return "PROP_RGB";
                case PROP_NEVER_NULL: return "PROP_NEVER_NULL";
+               default: {
+                       /* incase we dont have a type preset that includes the subtype */
+                       if(RNA_SUBTYPE_UNIT(type)) {
+                               return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
+                       }
+                       else {
+                               return "PROP_SUBTYPE_UNKNOWN";
+                       }
+               }
+       }
+}
+
+static const char *rna_property_subtype_unit(PropertyType type)
+{
+       switch(RNA_SUBTYPE_UNIT(type)) {
+               case PROP_UNIT_NONE:            return "PROP_UNIT_NONE";
+               case PROP_UNIT_LENGTH:          return "PROP_UNIT_LENGTH";
+               case PROP_UNIT_AREA:            return "PROP_UNIT_AREA";
+               case PROP_UNIT_VOLUME:          return "PROP_UNIT_VOLUME";
+               case PROP_UNIT_MASS:            return "PROP_UNIT_MASS";
+               case PROP_UNIT_ROTATION:        return "PROP_UNIT_ROTATION";
+               case PROP_UNIT_TIME:            return "PROP_UNIT_TIME";
+               case PROP_UNIT_VELOCITY:        return "PROP_UNIT_VELOCITY";
+               case PROP_UNIT_ACCELERATION:return "PROP_UNIT_ACCELERATION";
                default: return "PROP_UNKNOWN";
        }
 }
@@ -1693,7 +1717,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
        rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
        rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
        fprintf(f, "%d,\n", prop->icon);
-       fprintf(f, "\t%s, %s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), prop->arraylength);
+       fprintf(f, "\t%s, %s|%s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), prop->arraylength);
        fprintf(f, "\t%s, %d, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable));
 
        if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);