bugfix [#25588] Not work fcurve.keyframe_points.add
authorCampbell Barton <ideasman42@gmail.com>
Thu, 13 Jan 2011 14:29:57 +0000 (14:29 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 13 Jan 2011 14:29:57 +0000 (14:29 +0000)
The problem was flag-enums were being treated as regular enums, a default value of 0 was using the first enum item, whereas with flag enums we want to be able to use 0 as a default value to specify all flags are off.

source/blender/makesrna/RNA_define.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_fcurve.c
source/blender/makesrna/intern/rna_wm_api.c

index 3a8e2e4f80e31711b26aa56061011ee11e4d4578..f4693ae941efd487b6a5d8bd1bebec26d1b92eba 100644 (file)
@@ -86,6 +86,7 @@ PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont, const char *iden
 PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont, const char *identifier, const char *default_value, int maxlen, const char *ui_name, const char *ui_description);
 
 PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description);
+PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description);
 void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc);
 
 PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax);
index cf1b14d5e620e70390bcae6c837098b25fb91cec..94b075c20c08379070a0a43079a92552b0b612d4 100644 (file)
@@ -2023,7 +2023,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
        switch(prop->type) {
                        case PROP_ENUM: {
                                EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
-                               int i, defaultfound= 0;
+                               int i, defaultfound= 0, totflag= 0;
 
                                if(eprop->item) {
                                        fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
@@ -2035,16 +2035,31 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                                                rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
                                                rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
 
-                                               if(eprop->item[i].identifier[0])
-                                                       if(eprop->defaultvalue == eprop->item[i].value)
-                                                               defaultfound= 1;
+                                               if(eprop->item[i].identifier[0]) {
+                                                       if(prop->flag & PROP_ENUM_FLAG) {
+                                                               totflag |= eprop->item[i].value;
+                                                       }
+                                                       else {
+                                                               if(eprop->defaultvalue == eprop->item[i].value) {
+                                                                       defaultfound= 1;
+                                                               }
+                                                       }
+                                               }
                                        }
 
                                        fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
 
-                                       if(!defaultfound) {
-                                               fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
-                                               DefRNA.error= 1;
+                                       if(prop->flag & PROP_ENUM_FLAG) {
+                                               if(eprop->defaultvalue & ~totflag) {
+                                                       fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default includes unused bits (%d).\n", srna->identifier, errnest, prop->identifier, eprop->defaultvalue & ~totflag);
+                                                       DefRNA.error= 1;
+                                               }
+                                       }
+                                       else {
+                                               if(!defaultfound) {
+                                                       fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
+                                                       DefRNA.error= 1;
+                                               }
                                        }
                                }
                                else {
index efef72913c9e4d2e47608bd6aea6416a2a94966e..a428c81106174274d360a3c4ea7ab90f5361ec5a 100644 (file)
@@ -481,8 +481,7 @@ static void rna_def_ID(BlenderRNA *brna)
        func= RNA_def_function(srna, "update", "rna_ID_update");
        RNA_def_function_flag(func, FUNC_USE_REPORTS);
        RNA_def_function_ui_description(func, "Tag the id to update its display data.");
-       parm= RNA_def_enum(func, "refresh", update_flag_items, 0, "", "Type of updates to perform.");
-       RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+       RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform.");
 }
 
 static void rna_def_library(BlenderRNA *brna)
index a72777726c2b1b3b74f72c9bac67f703fec98f46..b6b0bd3ae84a2163b005c87ed32007f519f89ff5 100644 (file)
@@ -1393,20 +1393,36 @@ void RNA_def_property_enum_default(PropertyRNA *prop, int value)
                        EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
                        eprop->defaultvalue= value;
 
-                       for(i=0; i<eprop->totitem; i++) {
-                               if(eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
-                                       defaultfound= 1;
-                       }
-
-                       if(!defaultfound && eprop->totitem) {
-                               if(value == 0) {
-                                       eprop->defaultvalue= eprop->item[0].value;
+                       if(prop->flag & PROP_ENUM_FLAG) {
+                               /* check all bits are accounted for */
+                               int totflag= 0;
+                               for(i=0; i<eprop->totitem; i++) {
+                                       if(eprop->item[i].identifier[0]) {
+                                               totflag |= eprop->item[i].value;
+                                       }
                                }
-                               else {
-                                       fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default is not in items.\n", srna->identifier, prop->identifier);
+
+                               if(eprop->defaultvalue & ~totflag) {
+                                       fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default includes unused bits (%d).\n", srna->identifier, prop->identifier, eprop->defaultvalue & ~totflag);
                                        DefRNA.error= 1;
                                }
                        }
+                       else {
+                               for(i=0; i<eprop->totitem; i++) {
+                                       if(eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
+                                               defaultfound= 1;
+                               }
+
+                               if(!defaultfound && eprop->totitem) {
+                                       if(value == 0) {
+                                               eprop->defaultvalue= eprop->item[0].value;
+                                       }
+                                       else {
+                                               fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default is not in items.\n", srna->identifier, prop->identifier);
+                                               DefRNA.error= 1;
+                                       }
+                               }
+                       }
 
                        break;
                }
@@ -2212,6 +2228,27 @@ PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, co
        return prop;
 }
 
+/* same as above but sets 'PROP_ENUM_FLAG' before setting the default value */
+PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value,
+       const char *ui_name, const char *ui_description)
+{
+       ContainerRNA *cont= cont_;
+       PropertyRNA *prop;
+
+       if(!items) {
+               printf("RNA_def_enum_flag: items not allowed to be NULL.\n");
+               return NULL;
+       }
+
+       prop= RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_ENUM_FLAG); /* important to run before default set */
+       if(items) RNA_def_property_enum_items(prop, items);
+       RNA_def_property_enum_default(prop, default_value);
+       RNA_def_property_ui_text(prop, ui_name, ui_description);
+
+       return prop;
+}
+
 void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
 {
        EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
index 12ecf15816a10b11130e3d0623d722df011c223f..5aa1e8e836f7aeefb849ce92ee9d2c39b7323083 100644 (file)
@@ -1333,8 +1333,7 @@ static void rna_def_fcurve_keyframe_points(BlenderRNA *brna, PropertyRNA *cprop)
        parm= RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "", "Y Value of this keyframe point", -FLT_MAX, FLT_MAX);
        RNA_def_property_flag(parm, PROP_REQUIRED);
 
-       parm= RNA_def_enum(func, "options", keyframe_flag_items, 0, "", "Keyframe options.");
-       RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+       RNA_def_enum_flag(func, "options", keyframe_flag_items, 0, "", "Keyframe options.");
 
        parm= RNA_def_pointer(func, "keyframe", "Keyframe", "", "Newly created keyframe");
        RNA_def_function_return(func, parm);
index e043db7d9d6f6f3689d64f1c20eba9f9b470cb48..b934bdfc979c97d02fa5aeb19b085a995ce5a011 100644 (file)
@@ -93,8 +93,7 @@ static void rna_generic_op_invoke(FunctionRNA *func, int flag)
        }
 
        if(flag & WM_GEN_INVOKE_RETURN) {
-               parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", "");
-               RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+               parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", "");
                RNA_def_function_return(func, parm);
        }
 }
@@ -146,8 +145,8 @@ void RNA_api_operator(StructRNA *srna)
 
        /* utility, not for registering */
        func= RNA_def_function(srna, "report", "rna_Operator_report");
-       parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
-       RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
+       parm= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
        parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
        RNA_def_property_flag(parm, PROP_REQUIRED);
 
@@ -167,8 +166,7 @@ void RNA_api_operator(StructRNA *srna)
        RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
        RNA_def_pointer(func, "context", "Context", "", "");
 
-       parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
-       RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+       parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
        RNA_def_function_return(func, parm);
 
        /* check */
@@ -187,8 +185,7 @@ void RNA_api_operator(StructRNA *srna)
        RNA_def_pointer(func, "context", "Context", "", "");
        RNA_def_pointer(func, "event", "Event", "", "");
 
-       parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
-       RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+       parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
        RNA_def_function_return(func, parm);
 
        func= RNA_def_function(srna, "modal", NULL); /* same as invoke */
@@ -197,8 +194,7 @@ void RNA_api_operator(StructRNA *srna)
        RNA_def_pointer(func, "context", "Context", "", "");
        RNA_def_pointer(func, "event", "Event", "", "");
 
-       parm= RNA_def_enum(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
-       RNA_def_property_flag(parm, PROP_ENUM_FLAG);
+       parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
        RNA_def_function_return(func, parm);
 
        /* draw */
@@ -215,8 +211,8 @@ void RNA_api_macro(StructRNA *srna)
 
        /* utility, not for registering */
        func= RNA_def_function(srna, "report", "rna_Operator_report");
-       parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
-       RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
+       parm= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
        parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
        RNA_def_property_flag(parm, PROP_REQUIRED);