diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 15e387d33ee..9fe252090e9 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -30,6 +30,8 @@ struct bContext; struct Main; +extern BlenderRNA BLENDER_RNA; + /* Pointer * * Currently only an RNA pointer to Main can be obtained, this @@ -45,6 +47,8 @@ const char *RNA_struct_ui_name(PointerRNA *ptr); PropertyRNA *RNA_struct_name_property(PointerRNA *ptr); PropertyRNA *RNA_struct_iterator_property(PointerRNA *ptr); +PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier); + /* Properties * * Access to struct properties. All this works with RNA pointers rather than @@ -103,7 +107,6 @@ void RNA_property_enum_set(PropertyRNA *prop, PointerRNA *ptr, int value); void RNA_property_pointer_get(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_ptr); void RNA_property_pointer_set(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *ptr_value); -StructRNA *RNA_property_pointer_type(PropertyRNA *prop, PointerRNA *ptr); void RNA_property_collection_begin(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *ptr); void RNA_property_collection_next(PropertyRNA *prop, CollectionPropertyIterator *iter); @@ -142,5 +145,54 @@ void RNA_test_dependencies_cb(void *udata, PointerRNA *from, PointerRNA *to); void RNA_generate_dependencies(PointerRNA *mainptr, void *udata, PropDependencyCallback cb); #endif +/* Quick name based property access + * + * These are just an easier way to access property values without having to + * call RNA_struct_find_property. The names have to exist as RNA properties + * for the type in the pointer, if they do not exist an error will be printed. + * + * The get and set functions work like the corresponding functions above, the + * default functions are intended to be used for runtime / id properties + * specifically. They will set the value only if the id property does not yet + * exist, and return the current value. This is useful to set inputs in an + * operator, avoiding to overwrite them if they were specified by the caller. + * + * There is no support for pointers and collections here yet, these can be + * added when ID properties support them. */ + +int RNA_boolean_get(PointerRNA *ptr, const char *name); +void RNA_boolean_set(PointerRNA *ptr, const char *name, int value); +int RNA_boolean_default(PointerRNA *ptr, const char *name, int value); +void RNA_boolean_get_array(PointerRNA *ptr, const char *name, int *values); +void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const int *values); +void RNA_boolean_default_array(PointerRNA *ptr, const char *name, int *values); + +int RNA_int_get(PointerRNA *ptr, const char *name); +void RNA_int_set(PointerRNA *ptr, const char *name, int value); +int RNA_int_default(PointerRNA *ptr, const char *name, int value); +void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values); +void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values); +void RNA_int_default_array(PointerRNA *ptr, const char *name, int *values); + +float RNA_float_get(PointerRNA *ptr, const char *name); +void RNA_float_set(PointerRNA *ptr, const char *name, float value); +float RNA_float_default(PointerRNA *ptr, const char *name, float value); +void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values); +void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values); +void RNA_float_default_array(PointerRNA *ptr, const char *name, float *values); + +int RNA_enum_get(PointerRNA *ptr, const char *name); +void RNA_enum_set(PointerRNA *ptr, const char *name, int value); +int RNA_enum_default(PointerRNA *ptr, const char *name, int value); + +void RNA_string_get(PointerRNA *ptr, const char *name, char *value); +char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen); +int RNA_string_length(PointerRNA *ptr, const char *name); +void RNA_string_set(PointerRNA *ptr, const char *name, const char *value); +void RNA_string_default(PointerRNA *ptr, const char *name, const char *value); + +/* check if the idproperty exists, for operators */ +int RNA_property_is_set(PointerRNA *ptr, const char *name); + #endif /* RNA_ACCESS */ diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 1425bbb3c47..df66613a94b 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -25,12 +25,7 @@ #ifndef RNA_DEFINE_H #define RNA_DEFINE_H -/* Functions used during preprocess, for defining the RNA. - * - * This is currently only used internally in the module, but should eventually - * also become available outside of that, at runtime for python and plugins. - * Where the result of such runtime RNA is stored and how it integrates needs - * to be figured out still. */ +/* Functions used during preprocess and runtime, for defining the RNA. */ #include "DNA_listBase.h" #include "RNA_types.h" @@ -40,13 +35,16 @@ BlenderRNA *RNA_create(void); void RNA_define_free(BlenderRNA *brna); void RNA_free(BlenderRNA *brna); +void RNA_exit(void); /* Struct */ -StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *name); +StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from, const char *name); void RNA_def_struct_sdna(StructRNA *srna, const char *structname); void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop); void RNA_def_struct_flag(StructRNA *srna, int flag); +void RNA_def_struct_funcs(StructRNA *srna, const char *notify, const char *refine); +void RNA_def_struct_identifier(StructRNA *srna, const char *identifier, const char *name); /* Property */ @@ -80,7 +78,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value); void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description); void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision); -void RNA_def_property_funcs(PropertyRNA *prop, const char *notify, const char *readonly); +void RNA_def_property_funcs(PropertyRNA *prop, const char *notify); void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set); void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set); void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 33b720f9c0c..bee3e6610f3 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -96,7 +96,9 @@ typedef enum PropertyFlag { /* internal flags */ PROP_BUILTIN = 128, - PROP_EXPORT = 256 + PROP_EXPORT = 256, + PROP_RUNTIME = 512, + PROP_IDPROPERTY = 1024 } PropertyFlag; typedef struct CollectionPropertyIterator { @@ -120,7 +122,10 @@ typedef struct PropertyRNA PropertyRNA; typedef enum StructFlag { /* indicates that this struct is an ID struct */ - STRUCT_ID = 1 + STRUCT_ID = 1, + + /* internal flags */ + STRUCT_RUNTIME = 2 } StructFlag; struct StructRNA; diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 509b95027e1..c281bfb4c74 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -100,6 +100,9 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr { char *func; + if(prop->flag & PROP_IDPROPERTY) + return NULL; + if(!dp->dnastructname || !dp->dnaname) { fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier); DefRNA.error= 1; @@ -195,6 +198,9 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr { char *func; + if(prop->flag & PROP_IDPROPERTY) + return NULL; + if(!dp->dnastructname || !dp->dnaname) { if(!(prop->flag & PROP_NOT_EDITABLE)) { fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier); @@ -266,6 +272,9 @@ static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA { char *func= NULL; + if(prop->flag & PROP_IDPROPERTY) + return NULL; + if(prop->type == PROP_STRING) { if(!dp->dnastructname || !dp->dnaname) { fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier); @@ -304,6 +313,9 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA * { char *func; + if(prop->flag & PROP_IDPROPERTY) + return NULL; + if(!dp->dnastructname || !dp->dnaname) { fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier); DefRNA.error= 1; @@ -741,7 +753,12 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) if(prop) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier); else fprintf(f, "\tNULL, "); - fprintf(f, "\t(PropertyRNA*)&rna_%s_rna_properties,\n", srna->identifier); + fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", srna->identifier); + + if(srna->from) fprintf(f, "\t&RNA_%s,\n", (char*)srna->from); + else fprintf(f, "\tNULL,\n"); + + fprintf(f, "\t%s, %s,\n", rna_function_string(srna->notify), rna_function_string(srna->refine)); prop= srna->properties.first; if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier); @@ -762,13 +779,14 @@ typedef struct RNAProcessItem { } RNAProcessItem; RNAProcessItem PROCESS_ITEMS[]= { - {"rna_ID.c", RNA_def_ID_types}, + {"rna_ID.c", RNA_def_ID}, {"rna_main.c", RNA_def_main}, {"rna_mesh.c", RNA_def_mesh}, {"rna_object.c", RNA_def_object}, {"rna_rna.c", RNA_def_rna}, {"rna_scene.c", RNA_def_scene}, {"rna_lamp.c", RNA_def_lamp}, + {"rna_wm.c", RNA_def_wm}, {NULL, NULL}}; static int rna_preprocess(char *basedirectory, FILE *f) @@ -795,6 +813,10 @@ static int rna_preprocess(char *basedirectory, FILE *f) fprintf(f, "#include \"RNA_types.h\"\n"); fprintf(f, "#include \"rna_internal.h\"\n\n"); + /* this is ugly, but we cannot have c files compiled for both + * makesrna and blender with some build systems at the moment */ + fprintf(f, "#include \"rna_define.c\"\n\n"); + for(i=0; PROCESS_ITEMS[i].filename; i++) if(PROCESS_ITEMS[i].define) PROCESS_ITEMS[i].define(brna); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 77d273816ae..d61a1f6ddb7 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -53,180 +53,96 @@ static void rna_ID_name_set(PointerRNA *ptr, const char *value) BLI_strncpy(id->name+2, value, sizeof(id->name)-2); } -/* ID properties */ - -static void rna_IDProperty_string_get(PointerRNA *ptr, char *value) +static StructRNA *rna_ID_refine(PointerRNA *ptr) { - IDProperty *prop= (IDProperty*)ptr->data; - strcpy(value, IDP_String(prop)); -} + ID *id= (ID*)ptr->data; -static int rna_IDProperty_string_length(PointerRNA *ptr) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return strlen(IDP_String(prop)); -} - -static void rna_IDProperty_string_set(PointerRNA *ptr, const char *value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - IDP_AssignString(prop, (char*)value); -} - -static int rna_IDProperty_int_get(PointerRNA *ptr) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return IDP_Int(prop); -} - -static void rna_IDProperty_int_set(PointerRNA *ptr, int value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - IDP_Int(prop)= value; -} - -static int rna_IDProperty_intarray_get(PointerRNA *ptr, int index) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return ((int*)IDP_Array(prop))[index]; -} - -static void rna_IDProperty_intarray_set(PointerRNA *ptr, int index, int value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - ((int*)IDP_Array(prop))[index]= value; -} - -static float rna_IDProperty_float_get(PointerRNA *ptr) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return IDP_Float(prop); -} - -static void rna_IDProperty_float_set(PointerRNA *ptr, float value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - IDP_Float(prop)= value; -} - -static float rna_IDProperty_floatarray_get(PointerRNA *ptr, int index) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return ((float*)IDP_Array(prop))[index]; -} - -static void rna_IDProperty_floatarray_set(PointerRNA *ptr, int index, float value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - ((float*)IDP_Array(prop))[index]= value; -} - -static float rna_IDProperty_double_get(PointerRNA *ptr) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return (float)IDP_Double(prop); -} - -static void rna_IDProperty_double_set(PointerRNA *ptr, float value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - IDP_Double(prop)= value; -} - -static float rna_IDProperty_doublearray_get(PointerRNA *ptr, int index) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return (float)(((double*)IDP_Array(prop))[index]); -} - -static void rna_IDProperty_doublearray_set(PointerRNA *ptr, int index, float value) -{ - IDProperty *prop= (IDProperty*)ptr->data; - ((double*)IDP_Array(prop))[index]= value; -} - -static void* rna_IDProperty_group_get(PointerRNA *ptr) -{ - IDProperty *prop= (IDProperty*)ptr->data; - return prop; + switch(GS(id->name)) { + case ID_LA: return &RNA_Lamp; + case ID_ME: return &RNA_Mesh; + case ID_OB: return &RNA_Object; + case ID_SCE: return &RNA_Scene; + case ID_WM: return &RNA_WindowManager; + default: return &RNA_ID; + } } #else -static void RNA_def_ID_property(BlenderRNA *brna) +static void rna_def_ID_properties(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; /* this is struct is used for holding the virtual * PropertyRNA's for ID properties */ - srna= RNA_def_struct(brna, "IDProperty", "ID Property"); + srna= RNA_def_struct(brna, "IDProperty", NULL, "ID Property"); /* IDP_STRING */ prop= RNA_def_property(srna, "string", PROP_STRING, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); - RNA_def_property_string_funcs(prop, "rna_IDProperty_string_get", "rna_IDProperty_string_length", "rna_IDProperty_string_set"); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); /* IDP_INT */ prop= RNA_def_property(srna, "int", PROP_INT, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); - RNA_def_property_int_funcs(prop, "rna_IDProperty_int_get", "rna_IDProperty_int_set"); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); prop= RNA_def_property(srna, "intarray", PROP_INT, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); RNA_def_property_array(prop, 1); - RNA_def_property_int_funcs(prop, "rna_IDProperty_intarray_get", "rna_IDProperty_intarray_set"); /* IDP_FLOAT */ prop= RNA_def_property(srna, "float", PROP_FLOAT, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); - RNA_def_property_float_funcs(prop, "rna_IDProperty_float_get", "rna_IDProperty_float_set"); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); prop= RNA_def_property(srna, "floatarray", PROP_FLOAT, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); RNA_def_property_array(prop, 1); - RNA_def_property_float_funcs(prop, "rna_IDProperty_floatarray_get", "rna_IDProperty_floatarray_set"); /* IDP_DOUBLE */ prop= RNA_def_property(srna, "double", PROP_FLOAT, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); - RNA_def_property_float_funcs(prop, "rna_IDProperty_double_get", "rna_IDProperty_double_set"); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); prop= RNA_def_property(srna, "doublearray", PROP_FLOAT, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_IDPROPERTY); RNA_def_property_array(prop, 1); - RNA_def_property_float_funcs(prop, "rna_IDProperty_doublearray_get", "rna_IDProperty_doublearray_set"); /* IDP_GROUP */ prop= RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE); - RNA_def_property_flag(prop, PROP_EXPORT|PROP_NOT_EDITABLE); + RNA_def_property_flag(prop, PROP_EXPORT|PROP_NOT_EDITABLE|PROP_IDPROPERTY); RNA_def_property_struct_type(prop, "IDPropertyGroup"); - RNA_def_property_pointer_funcs(prop, "rna_IDProperty_group_get", 0, 0); /* IDP_ID -- not implemented yet in id properties */ /* ID property groups > level 0, since level 0 group is merged * with native RNA properties. the builtin_properties will take * care of the properties here */ - srna= RNA_def_struct(brna, "IDPropertyGroup", "ID Property Group"); + srna= RNA_def_struct(brna, "IDPropertyGroup", NULL, "ID Property Group"); } -void RNA_def_ID(StructRNA *srna) +void rna_def_ID(BlenderRNA *brna) { + StructRNA *srna; PropertyRNA *prop; + srna= RNA_def_struct(brna, "ID", NULL, "ID"); RNA_def_struct_flag(srna, STRUCT_ID); + RNA_def_struct_funcs(srna, NULL, "rna_ID_refine"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, "ID", "name"); RNA_def_property_ui_text(prop, "Name", "Object ID name."); RNA_def_property_string_funcs(prop, "rna_ID_name_get", "rna_ID_name_length", "rna_ID_name_set"); + RNA_def_property_string_maxlength(prop, 22); RNA_def_struct_name_property(srna, prop); } -void RNA_def_ID_types(BlenderRNA *brna) +void RNA_def_ID(BlenderRNA *brna) { - RNA_def_ID_property(brna); + /* ID */ + rna_def_ID(brna); + + /* ID Properties */ + rna_def_ID_properties(brna); } #endif diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 029e3a27e78..d16a085b0be 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -30,13 +30,24 @@ #include "BLI_blenlib.h" #include "BLI_dynstr.h" +#include "BKE_idprop.h" + #include "DNA_ID.h" +#include "DNA_windowmanager_types.h" #include "RNA_access.h" +#include "RNA_define.h" #include "RNA_types.h" #include "rna_internal.h" +/* Exit */ + +void RNA_exit() +{ + RNA_free(&BLENDER_RNA); +} + /* Pointer */ void RNA_pointer_main_get(struct Main *main, struct PointerRNA *r_ptr) @@ -61,6 +72,41 @@ static void rna_pointer_inherit_id(PointerRNA *parent, PointerRNA *ptr) /* ID Properties */ +IDProperty *rna_idproperties_get(StructRNA *type, void *data, int create) +{ + if(type->flag & STRUCT_ID) + return IDP_GetProperties(data, create); + else if(type == &RNA_IDPropertyGroup) + return data; + else if(type->from == &RNA_Operator) { + wmOperator *op= (wmOperator*)data; + + if(create && !op->properties) { + IDPropertyTemplate val; + val.i = 0; /* silence MSVC warning about uninitialized var when debugging */ + op->properties= IDP_New(IDP_GROUP, val, "property"); + } + + return op->properties; + } + else + return NULL; +} + +static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name) +{ + IDProperty *group= rna_idproperties_get(ptr->type, ptr->data, 0); + IDProperty *idprop; + + if(group) { + for(idprop=group->data.group.first; idprop; idprop=idprop->next) + if(strcmp(idprop->name, name) == 0) + return idprop; + } + + return NULL; +} + IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) { /* This is quite a hack, but avoids some complexity in the API. we @@ -70,11 +116,14 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) * we look up an IDP PropertyRNA based on the type, and set the data * pointer to the IDProperty. */ - /* these bytes have */ if((*prop)->magic == RNA_MAGIC) { - return 0; + if((*prop)->flag & PROP_IDPROPERTY) + return rna_idproperty_find(ptr, (*prop)->identifier); + else + return NULL; } - else { + + { static PropertyRNA *typemap[IDP_NUMTYPES] = {(PropertyRNA*)&rna_IDProperty_string, (PropertyRNA*)&rna_IDProperty_int, @@ -89,17 +138,13 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) NULL, NULL, NULL, NULL, NULL, (PropertyRNA*)&rna_IDProperty_doublearray}; - IDProperty *idprop; + IDProperty *idprop= (IDProperty*)(*prop); - idprop= (IDProperty*)*prop; if(idprop->type == IDP_ARRAY) *prop= arraytypemap[(int)(idprop->subtype)]; else *prop= typemap[(int)(idprop->type)]; - if(ptr) - ptr->data= idprop; - return idprop; } } @@ -126,13 +171,35 @@ PropertyRNA *RNA_struct_iterator_property(PointerRNA *ptr) return ptr->type->iteratorproperty; } +PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier) +{ + CollectionPropertyIterator iter; + PropertyRNA *iterprop, *prop; + int i = 0; + + iterprop= RNA_struct_iterator_property(ptr); + RNA_property_collection_begin(iterprop, &iter, ptr); + prop= NULL; + + for(; iter.valid; RNA_property_collection_next(iterprop, &iter), i++) { + if(strcmp(identifier, RNA_property_identifier(iter.ptr.data, &iter.ptr)) == 0) { + prop= iter.ptr.data; + break; + } + } + + RNA_property_collection_end(iterprop, &iter); + + return prop; +} + /* Property Information */ const char *RNA_property_identifier(PropertyRNA *prop, PointerRNA *ptr) { IDProperty *idprop; - if((idprop=rna_idproperty_check(&prop, NULL))) + if((idprop=rna_idproperty_check(&prop, ptr))) return idprop->name; else return prop->identifier; @@ -140,14 +207,14 @@ const char *RNA_property_identifier(PropertyRNA *prop, PointerRNA *ptr) PropertyType RNA_property_type(PropertyRNA *prop, PointerRNA *ptr) { - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return prop->type; } PropertySubType RNA_property_subtype(PropertyRNA *prop, PointerRNA *ptr) { - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return prop->subtype; } @@ -156,7 +223,7 @@ int RNA_property_array_length(PropertyRNA *prop, PointerRNA *ptr) { IDProperty *idprop; - if((idprop=rna_idproperty_check(&prop, NULL)) && idprop->type==IDP_ARRAY) + if((idprop=rna_idproperty_check(&prop, ptr)) && idprop->type==IDP_ARRAY) return idprop->len; else return prop->arraylength; @@ -166,7 +233,7 @@ void RNA_property_int_range(PropertyRNA *prop, PointerRNA *ptr, int *hardmin, in { IntPropertyRNA *iprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); iprop= (IntPropertyRNA*)prop; *hardmin= iprop->hardmin; @@ -177,7 +244,7 @@ void RNA_property_int_ui_range(PropertyRNA *prop, PointerRNA *ptr, int *softmin, { IntPropertyRNA *iprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); iprop= (IntPropertyRNA*)prop; *softmin= iprop->softmin; @@ -189,7 +256,7 @@ void RNA_property_float_range(PropertyRNA *prop, PointerRNA *ptr, float *hardmin { FloatPropertyRNA *fprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); fprop= (FloatPropertyRNA*)prop; *hardmin= fprop->hardmin; @@ -200,7 +267,7 @@ void RNA_property_float_ui_range(PropertyRNA *prop, PointerRNA *ptr, float *soft { FloatPropertyRNA *fprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); fprop= (FloatPropertyRNA*)prop; *softmin= fprop->softmin; @@ -213,7 +280,7 @@ int RNA_property_string_maxlength(PropertyRNA *prop, PointerRNA *ptr) { StringPropertyRNA *sprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); sprop= (StringPropertyRNA*)prop; return sprop->maxlength; @@ -223,7 +290,7 @@ void RNA_property_enum_items(PropertyRNA *prop, PointerRNA *ptr, const EnumPrope { EnumPropertyRNA *eprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); eprop= (EnumPropertyRNA*)prop; *item= eprop->item; @@ -232,9 +299,10 @@ void RNA_property_enum_items(PropertyRNA *prop, PointerRNA *ptr, const EnumPrope const char *RNA_property_ui_name(PropertyRNA *prop, PointerRNA *ptr) { + PropertyRNA *oldprop= prop; IDProperty *idprop; - if((idprop=rna_idproperty_check(&prop, NULL))) + if((idprop=rna_idproperty_check(&prop, ptr)) && oldprop!=prop) return idprop->name; else return prop->name; @@ -242,7 +310,9 @@ const char *RNA_property_ui_name(PropertyRNA *prop, PointerRNA *ptr) const char *RNA_property_ui_description(PropertyRNA *prop, PointerRNA *ptr) { - if(rna_idproperty_check(&prop, NULL)) + PropertyRNA *oldprop= prop; + + if(rna_idproperty_check(&prop, ptr) && oldprop!=prop) return ""; else return prop->description; @@ -250,21 +320,21 @@ const char *RNA_property_ui_description(PropertyRNA *prop, PointerRNA *ptr) int RNA_property_editable(PropertyRNA *prop, PointerRNA *ptr) { - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return !(prop->flag & PROP_NOT_EDITABLE); } int RNA_property_evaluated(PropertyRNA *prop, PointerRNA *ptr) { - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return (prop->flag & PROP_EVALUATED); } void RNA_property_notify(PropertyRNA *prop, struct bContext *C, PointerRNA *ptr) { - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); if(prop->notify) prop->notify(C, ptr); @@ -274,138 +344,252 @@ void RNA_property_notify(PropertyRNA *prop, struct bContext *C, PointerRNA *ptr) int RNA_property_boolean_get(PropertyRNA *prop, PointerRNA *ptr) { - BooleanPropertyRNA *bprop; + BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - bprop= (BooleanPropertyRNA*)prop; - - return bprop->get(ptr); + if((idprop=rna_idproperty_check(&prop, ptr))) + return IDP_Int(idprop); + else if(bprop->get) + return bprop->get(ptr); + else + return bprop->defaultvalue; } void RNA_property_boolean_set(PropertyRNA *prop, PointerRNA *ptr, int value) { - BooleanPropertyRNA *bprop; + BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - bprop= (BooleanPropertyRNA*)prop; - - if(bprop->set) + if((idprop=rna_idproperty_check(&prop, ptr))) + IDP_Int(idprop)= value; + else if(bprop->set) bprop->set(ptr, value); + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.i= value; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) + IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); + } } int RNA_property_boolean_get_array(PropertyRNA *prop, PointerRNA *ptr, int index) { - BooleanPropertyRNA *bprop; + BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - bprop= (BooleanPropertyRNA*)prop; - - return bprop->getarray(ptr, index); + if((idprop=rna_idproperty_check(&prop, ptr))) + return ((int*)IDP_Array(idprop))[index]; + else if(bprop->getarray) + return bprop->getarray(ptr, index); + else + return bprop->defaultarray[index]; } void RNA_property_boolean_set_array(PropertyRNA *prop, PointerRNA *ptr, int index, int value) { - BooleanPropertyRNA *bprop; + BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - bprop= (BooleanPropertyRNA*)prop; - - if(bprop->setarray) + if((idprop=rna_idproperty_check(&prop, ptr))) + ((int*)IDP_Array(idprop))[index]= value; + else if(bprop->setarray) bprop->setarray(ptr, index, value); + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.array.len= prop->arraylength; + val.array.type= IDP_INT; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) { + idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); + IDP_AddToGroup(group, idprop); + memcpy(idprop->data.pointer, bprop->defaultarray, sizeof(int)*prop->arraylength); + ((int*)idprop->data.pointer)[index]= value; + } + } } int RNA_property_int_get(PropertyRNA *prop, PointerRNA *ptr) { - IntPropertyRNA *iprop; + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - iprop= (IntPropertyRNA*)prop; - - return iprop->get(ptr); + if((idprop=rna_idproperty_check(&prop, ptr))) + return IDP_Int(idprop); + else if(iprop->get) + return iprop->get(ptr); + else + return iprop->defaultvalue; } void RNA_property_int_set(PropertyRNA *prop, PointerRNA *ptr, int value) { - IntPropertyRNA *iprop; + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - iprop= (IntPropertyRNA*)prop; - - if(iprop->set) + if((idprop=rna_idproperty_check(&prop, ptr))) + IDP_Int(idprop)= value; + else if(iprop->set) iprop->set(ptr, value); + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.i= value; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) + IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); + } } int RNA_property_int_get_array(PropertyRNA *prop, PointerRNA *ptr, int index) { - IntPropertyRNA *iprop; + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - iprop= (IntPropertyRNA*)prop; - - return iprop->getarray(ptr, index); + if((idprop=rna_idproperty_check(&prop, ptr))) + return ((int*)IDP_Array(idprop))[index]; + else if(iprop->getarray) + return iprop->getarray(ptr, index); + else + return iprop->defaultarray[index]; } void RNA_property_int_set_array(PropertyRNA *prop, PointerRNA *ptr, int index, int value) { - IntPropertyRNA *iprop; + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - iprop= (IntPropertyRNA*)prop; - - if(iprop->setarray) + if((idprop=rna_idproperty_check(&prop, ptr))) + ((int*)IDP_Array(idprop))[index]= value; + else if(iprop->setarray) iprop->setarray(ptr, index, value); + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.array.len= prop->arraylength; + val.array.type= IDP_INT; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) { + idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); + IDP_AddToGroup(group, idprop); + memcpy(idprop->data.pointer, iprop->defaultarray, sizeof(int)*prop->arraylength); + ((int*)idprop->data.pointer)[index]= value; + } + } } float RNA_property_float_get(PropertyRNA *prop, PointerRNA *ptr) { - FloatPropertyRNA *fprop; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - fprop= (FloatPropertyRNA*)prop; - - return fprop->get(ptr); + if((idprop=rna_idproperty_check(&prop, ptr))) { + if(idprop->type == IDP_FLOAT) + return IDP_Float(idprop); + else + return (float)IDP_Double(idprop); + } + else if(fprop->get) + return fprop->get(ptr); + else + return fprop->defaultvalue; } void RNA_property_float_set(PropertyRNA *prop, PointerRNA *ptr, float value) { - FloatPropertyRNA *fprop; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - fprop= (FloatPropertyRNA*)prop; - - if(fprop->set) + if((idprop=rna_idproperty_check(&prop, ptr))) { + if(idprop->type == IDP_FLOAT) + IDP_Float(idprop)= value; + else + IDP_Double(idprop)= value; + } + else if(fprop->set) { fprop->set(ptr, value); + } + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.f= value; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) + IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, (char*)prop->identifier)); + } } float RNA_property_float_get_array(PropertyRNA *prop, PointerRNA *ptr, int index) { - FloatPropertyRNA *fprop; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - fprop= (FloatPropertyRNA*)prop; - - return fprop->getarray(ptr, index); + if((idprop=rna_idproperty_check(&prop, ptr))) { + if(idprop->type == IDP_FLOAT) + return ((float*)IDP_Array(idprop))[index]; + else + return (float)(((double*)IDP_Array(idprop))[index]); + } + else if(fprop->getarray) + return fprop->getarray(ptr, index); + else + return fprop->defaultarray[index]; } void RNA_property_float_set_array(PropertyRNA *prop, PointerRNA *ptr, int index, float value) { - FloatPropertyRNA *fprop; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - fprop= (FloatPropertyRNA*)prop; - - if(fprop->setarray) + if((idprop=rna_idproperty_check(&prop, ptr))) { + if(idprop->type == IDP_FLOAT) + ((float*)IDP_Array(idprop))[index]= value; + else + ((double*)IDP_Array(idprop))[index]= value; + } + else if(fprop->setarray) { fprop->setarray(ptr, index, value); + } + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.array.len= prop->arraylength; + val.array.type= IDP_FLOAT; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) { + idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); + IDP_AddToGroup(group, idprop); + memcpy(idprop->data.pointer, fprop->defaultarray, sizeof(float)*prop->arraylength); + ((float*)idprop->data.pointer)[index]= value; + } + } } void RNA_property_string_get(PropertyRNA *prop, PointerRNA *ptr, char *value) { - StringPropertyRNA *sprop; + StringPropertyRNA *sprop= (StringPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - sprop= (StringPropertyRNA*)prop; - - sprop->get(ptr, value); + if((idprop=rna_idproperty_check(&prop, ptr))) + strcpy(value, IDP_String(idprop)); + else if(sprop->get) + sprop->get(ptr, value); + else + strcpy(value, sprop->defaultvalue); } char *RNA_property_string_get_alloc(PropertyRNA *prop, PointerRNA *ptr, char *fixedbuf, int fixedlen) @@ -413,8 +597,6 @@ char *RNA_property_string_get_alloc(PropertyRNA *prop, PointerRNA *ptr, char *fi char *buf; int length; - rna_idproperty_check(&prop, ptr); - length= RNA_property_string_length(prop, ptr); if(length+1 < fixedlen) @@ -429,56 +611,93 @@ char *RNA_property_string_get_alloc(PropertyRNA *prop, PointerRNA *ptr, char *fi int RNA_property_string_length(PropertyRNA *prop, PointerRNA *ptr) { - StringPropertyRNA *sprop; + StringPropertyRNA *sprop= (StringPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - sprop= (StringPropertyRNA*)prop; - - return sprop->length(ptr); + if((idprop=rna_idproperty_check(&prop, ptr))) + return strlen(IDP_String(idprop)); + else if(sprop->length) + return sprop->length(ptr); + else + return strlen(sprop->defaultvalue); } void RNA_property_string_set(PropertyRNA *prop, PointerRNA *ptr, const char *value) { - StringPropertyRNA *sprop; + StringPropertyRNA *sprop= (StringPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - sprop= (StringPropertyRNA*)prop; - - if(sprop->set) + if((idprop=rna_idproperty_check(&prop, ptr))) + IDP_AssignString(idprop, (char*)value); + else if(sprop->set) sprop->set(ptr, value); } int RNA_property_enum_get(PropertyRNA *prop, PointerRNA *ptr) { - EnumPropertyRNA *eprop; + EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - eprop= (EnumPropertyRNA*)prop; - - return eprop->get(ptr); + if((idprop=rna_idproperty_check(&prop, ptr))) + return IDP_Int(idprop); + else if(eprop->get) + return eprop->get(ptr); + else + return eprop->defaultvalue; } void RNA_property_enum_set(PropertyRNA *prop, PointerRNA *ptr, int value) { - EnumPropertyRNA *eprop; + EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - eprop= (EnumPropertyRNA*)prop; - - if(eprop->set) + if((idprop=rna_idproperty_check(&prop, ptr))) + IDP_Int(idprop)= value; + else if(eprop->set) { eprop->set(ptr, value); + } + else if(!(prop->flag & PROP_NOT_EDITABLE)) { + IDPropertyTemplate val; + IDProperty *group; + + val.i= value; + + group= rna_idproperties_get(ptr->type, ptr->data, 1); + if(group) + IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); + } +} + +static StructRNA *rna_property_pointer_type(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_ptr) +{ + PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; + StructRNA *type; + + if(pprop->type) + type= pprop->type(ptr); + else + type= pprop->structtype; + + if(type->refine) + type= type->refine(r_ptr); + + r_ptr->type= type; + return type; } void RNA_property_pointer_get(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_ptr) { - PointerPropertyRNA *pprop; + PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; + IDProperty *idprop; - rna_idproperty_check(&prop, ptr); - pprop= (PointerPropertyRNA*)prop; + if((idprop=rna_idproperty_check(&prop, ptr))) + r_ptr->data= idprop; /* for groups, data is idprop itself */ + else if(pprop->get) + r_ptr->data= pprop->get(ptr); + else + r_ptr->data= NULL; - r_ptr->data= pprop->get(ptr); - - if(r_ptr->data && (r_ptr->type= RNA_property_pointer_type(prop, ptr))) + if(r_ptr->data && rna_property_pointer_type(prop, ptr, r_ptr)) rna_pointer_inherit_id(ptr, r_ptr); else memset(r_ptr, 0, sizeof(*r_ptr)); @@ -486,51 +705,36 @@ void RNA_property_pointer_get(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *r_ void RNA_property_pointer_set(PropertyRNA *prop, PointerRNA *ptr, PointerRNA *ptr_value) { - PointerPropertyRNA *pprop; - - rna_idproperty_check(&prop, ptr); - pprop= (PointerPropertyRNA*)prop; + PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; if(pprop->set) pprop->set(ptr, ptr_value->data); } -StructRNA *RNA_property_pointer_type(PropertyRNA *prop, PointerRNA *ptr) +static StructRNA *rna_property_collection_type(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *r_ptr) { - PointerPropertyRNA *pprop; - - rna_idproperty_check(&prop, ptr); - pprop= (PointerPropertyRNA*)prop; - - if(pprop->type) - return pprop->type(ptr); - - return pprop->structtype; -} - -static StructRNA *rna_property_collection_type(PropertyRNA *prop, CollectionPropertyIterator *iter) -{ - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, NULL); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; + StructRNA *type; if(cprop->type) - return cprop->type(iter); + type= cprop->type(iter); + else + type= cprop->structtype; - return cprop->structtype; + if(type->refine) + type= type->refine(r_ptr); + + r_ptr->type= type; + return type; } static void rna_property_collection_get(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *r_ptr) { - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, NULL); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; r_ptr->data= cprop->get(iter); - if(r_ptr->data && (r_ptr->type= rna_property_collection_type(prop, iter))) + if(r_ptr->data && rna_property_collection_type(prop, iter, r_ptr)) rna_pointer_inherit_id(&iter->parent, r_ptr); else memset(r_ptr, 0, sizeof(*r_ptr)); @@ -538,26 +742,24 @@ static void rna_property_collection_get(PropertyRNA *prop, CollectionPropertyIte void RNA_property_collection_begin(PropertyRNA *prop, CollectionPropertyIterator *iter, PointerRNA *ptr) { - CollectionPropertyRNA *cprop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; - rna_idproperty_check(&prop, ptr); - cprop= (CollectionPropertyRNA*)prop; + if(cprop->begin) { + iter->parent= *ptr; + cprop->begin(iter, ptr); - iter->parent= *ptr; - cprop->begin(iter, ptr); - - if(iter->valid) - rna_property_collection_get(prop, iter, &iter->ptr); + if(iter->valid) + rna_property_collection_get(prop, iter, &iter->ptr); + else + memset(&iter->ptr, 0, sizeof(iter->ptr)); + } else - memset(&iter->ptr, 0, sizeof(iter->ptr)); + memset(&iter, 0, sizeof(*iter)); } void RNA_property_collection_next(PropertyRNA *prop, CollectionPropertyIterator *iter) { - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, NULL); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; cprop->next(iter); @@ -569,10 +771,7 @@ void RNA_property_collection_next(PropertyRNA *prop, CollectionPropertyIterator void RNA_property_collection_end(PropertyRNA *prop, CollectionPropertyIterator *iter) { - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, NULL); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if(cprop->end) cprop->end(iter); @@ -580,10 +779,7 @@ void RNA_property_collection_end(PropertyRNA *prop, CollectionPropertyIterator * int RNA_property_collection_length(PropertyRNA *prop, PointerRNA *ptr) { - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, ptr); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if(cprop->length) { return cprop->length(ptr); @@ -603,10 +799,7 @@ int RNA_property_collection_length(PropertyRNA *prop, PointerRNA *ptr) int RNA_property_collection_lookup_int(PropertyRNA *prop, PointerRNA *ptr, int key, PointerRNA *r_ptr) { - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, ptr); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if(cprop->lookupint) { /* we have a callback defined, use it */ @@ -647,10 +840,7 @@ int RNA_property_collection_lookup_int(PropertyRNA *prop, PointerRNA *ptr, int k int RNA_property_collection_lookup_string(PropertyRNA *prop, PointerRNA *ptr, const char *key, PointerRNA *r_ptr) { - CollectionPropertyRNA *cprop; - - rna_idproperty_check(&prop, ptr); - cprop= (CollectionPropertyRNA*)prop; + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; if(cprop->lookupstring) { /* we have a callback defined, use it */ @@ -1025,3 +1215,370 @@ char *RNA_path_back(const char *path) return result; } +/* Quick name based property access */ + +int RNA_boolean_get(PointerRNA *ptr, const char *name) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return RNA_property_boolean_get(prop, ptr); + } + else { + printf("RNA_boolean_get: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_boolean_set(PointerRNA *ptr, const char *name, int value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) + RNA_property_boolean_set(prop, ptr, value); + else + printf("RNA_boolean_set: %s.%s not found.\n", ptr->type->identifier, name); +} + +int RNA_boolean_default(PointerRNA *ptr, const char *name, int value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + if(!rna_idproperty_find(ptr, name)) + RNA_property_boolean_set(prop, ptr, value); + + return RNA_property_boolean_get(prop, ptr); + } + else { + printf("RNA_boolean_default: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_boolean_get_array(PointerRNA *ptr, const char *name, int *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const int *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +void RNA_boolean_default_array(PointerRNA *ptr, const char *name, int *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + if(!rna_idproperty_find(ptr, name)) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +int RNA_int_get(PointerRNA *ptr, const char *name) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return RNA_property_int_get(prop, ptr); + } + else { + printf("RNA_int_get: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_int_set(PointerRNA *ptr, const char *name, int value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) + RNA_property_int_set(prop, ptr, value); + else + printf("RNA_int_set: %s.%s not found.\n", ptr->type->identifier, name); +} + +int RNA_int_default(PointerRNA *ptr, const char *name, int value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + if(!rna_idproperty_find(ptr, name)) + RNA_property_int_set(prop, ptr, value); + + return RNA_property_int_get(prop, ptr); + } + else { + printf("RNA_int_default: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +void RNA_int_default_array(PointerRNA *ptr, const char *name, int *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + if(!rna_idproperty_find(ptr, name)) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +float RNA_float_get(PointerRNA *ptr, const char *name) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return RNA_property_float_get(prop, ptr); + } + else { + printf("RNA_float_get: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_float_set(PointerRNA *ptr, const char *name, float value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) + RNA_property_float_set(prop, ptr, value); + else + printf("RNA_float_set: %s.%s not found.\n", ptr->type->identifier, name); +} + +float RNA_float_default(PointerRNA *ptr, const char *name, float value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + if(!rna_idproperty_find(ptr, name)) + RNA_property_float_set(prop, ptr, value); + + return RNA_property_float_get(prop, ptr); + } + else { + printf("RNA_float_default: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +void RNA_float_default_array(PointerRNA *ptr, const char *name, float *values) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + int i, length; + + if(prop) { + if(!rna_idproperty_find(ptr, name)) { + length= RNA_property_array_length(prop, ptr); + for(i=0; itype->identifier, name); +} + +int RNA_enum_get(PointerRNA *ptr, const char *name) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return RNA_property_enum_get(prop, ptr); + } + else { + printf("RNA_enum_get: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_enum_set(PointerRNA *ptr, const char *name, int value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) + RNA_property_enum_set(prop, ptr, value); + else + printf("RNA_enum_set: %s.%s not found.\n", ptr->type->identifier, name); +} + +int RNA_enum_default(PointerRNA *ptr, const char *name, int value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + if(!rna_idproperty_find(ptr, name)) + RNA_property_enum_set(prop, ptr, value); + + return RNA_property_enum_get(prop, ptr); + } + else { + printf("RNA_enum_default: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_string_get(PointerRNA *ptr, const char *name, char *value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) + RNA_property_string_get(prop, ptr, value); + else + printf("RNA_string_get: %s.%s not found.\n", ptr->type->identifier, name); +} + +char *RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return RNA_property_string_get_alloc(prop, ptr, fixedbuf, fixedlen); + } + else { + printf("RNA_string_get_alloc: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +int RNA_string_length(PointerRNA *ptr, const char *name) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return RNA_property_string_length(prop, ptr); + } + else { + printf("RNA_string_length: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + +void RNA_string_set(PointerRNA *ptr, const char *name, const char *value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) + RNA_property_string_set(prop, ptr, value); + else + printf("RNA_string_set: %s.%s not found.\n", ptr->type->identifier, name); +} + +void RNA_string_default(PointerRNA *ptr, const char *name, const char *value) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + if(!rna_idproperty_find(ptr, name)) + RNA_property_string_set(prop, ptr, value); + } + else + printf("RNA_string_default: %s.%s not found.\n", ptr->type->identifier, name); +} + +int RNA_property_is_set(PointerRNA *ptr, const char *name) +{ + PropertyRNA *prop= RNA_struct_find_property(ptr, name); + + if(prop) { + return (rna_idproperty_find(ptr, name) != NULL); + } + else { + printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name); + return 0; + } +} + diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index d3ce97d2abe..5f0eb512e3d 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -41,12 +41,14 @@ /* Global used during defining */ -BlenderDefRNA DefRNA; +BlenderDefRNA DefRNA = {0, {0, 0}, {0, 0}, 0, 0, 0}; /* Duplicated code since we can't link in blenkernel or blenlib */ +#ifndef MIN2 #define MIN2(x,y) ((x)<(y)? (x): (y)) #define MAX2(x,y) ((x)>(y)? (x): (y)) +#endif void rna_addtail(ListBase *listbase, void *vlink) { @@ -60,6 +62,23 @@ void rna_addtail(ListBase *listbase, void *vlink) listbase->last = link; } +void rna_remlink(ListBase *listbase, void *vlink) +{ + Link *link= vlink; + + if (link->next) link->next->prev = link->prev; + if (link->prev) link->prev->next = link->next; + + if (listbase->last == link) listbase->last = link->prev; + if (listbase->first == link) listbase->first = link->next; +} + +void rna_freelinkN(ListBase *listbase, void *vlink) +{ + rna_remlink(listbase, vlink); + MEM_freeN(vlink); +} + void rna_freelistN(ListBase *listbase) { Link *link, *next; @@ -151,6 +170,7 @@ BlenderRNA *RNA_create() DefRNA.sdna= DNA_sdna_from_data(DNAstr, DNAlen, 0); DefRNA.structs.first= DefRNA.structs.last= NULL; DefRNA.error= 0; + DefRNA.preprocess= 1; return brna; } @@ -179,39 +199,156 @@ void RNA_define_free(BlenderRNA *brna) void RNA_free(BlenderRNA *brna) { - StructRNA *srna; + StructRNA *srna, *nextsrna; + PropertyRNA *prop, *nextprop; - RNA_define_free(brna); + if(DefRNA.preprocess) { + RNA_define_free(brna); - for(srna=brna->structs.first; srna; srna=srna->next) - rna_freelistN(&srna->properties); + for(srna=brna->structs.first; srna; srna=srna->next) + rna_freelistN(&srna->properties); - rna_freelistN(&brna->structs); - - MEM_freeN(brna); + rna_freelistN(&brna->structs); + + MEM_freeN(brna); + } + else { + for(srna=brna->structs.first; srna; srna=nextsrna) { + nextsrna= srna->next; + + for(prop=srna->properties.first; prop; prop=nextprop) { + nextprop= prop->next; + + if(prop->flag & PROP_RUNTIME) + rna_freelinkN(&srna->properties, prop); + } + + if(srna->flag & STRUCT_RUNTIME) + rna_freelinkN(&brna->structs, srna); + } + } +} + +static size_t rna_property_type_sizeof(PropertyType type) +{ + switch(type) { + case PROP_BOOLEAN: return sizeof(BooleanPropertyRNA); + case PROP_INT: return sizeof(IntPropertyRNA); + case PROP_FLOAT: return sizeof(FloatPropertyRNA); + case PROP_STRING: return sizeof(StringPropertyRNA); + case PROP_ENUM: return sizeof(EnumPropertyRNA); + case PROP_POINTER: return sizeof(PointerPropertyRNA); + case PROP_COLLECTION: return sizeof(CollectionPropertyRNA); + default: return 0; + } } /* Struct Definition */ -StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *name) +StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from, const char *name) { - StructRNA *srna; + StructRNA *srna, *srnafrom= NULL; StructDefRNA *ds; + PropertyRNA *prop, *propfrom; - ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA"); - rna_addtail(&DefRNA.structs, ds); + if(from) { + /* find struct to derive from */ + for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->next) + if(strcmp(srnafrom->identifier, from) == 0) + break; + + if(!srnafrom) { + fprintf(stderr, "RNA_def_struct: struct %s not found to define %s.\n", from, identifier); + DefRNA.error= 1; + } + } srna= MEM_callocN(sizeof(StructRNA), "StructRNA"); + + /* copy from struct to derive stuff, a bit clumsy since we can't + * use MEM_dupallocN, data structs may not be alloced but builtin */ + if(srnafrom) { + memcpy(srna, srnafrom, sizeof(StructRNA)); + srna->properties.first= srna->properties.last= NULL; + + if(DefRNA.preprocess) + srna->from= (StructRNA*)from; + else + srna->from= srnafrom; + + for(propfrom= srnafrom->properties.first; propfrom; propfrom=propfrom->next) { + prop= RNA_def_property(srna, propfrom->identifier, propfrom->type, propfrom->subtype); + + rna_remlink(&srna->properties, prop); + memcpy(prop, propfrom, rna_property_type_sizeof(propfrom->type)); + + if(!DefRNA.preprocess) + prop->flag |= PROP_RUNTIME; + + prop->next= prop->prev= NULL; + rna_addtail(&srna->properties, prop); + + if(propfrom == srnafrom->nameproperty) + srna->nameproperty= prop; + if(propfrom == srnafrom->iteratorproperty) + srna->iteratorproperty= prop; + } + } + srna->identifier= identifier; srna->name= name; - ds->srna= srna; + if(DefRNA.preprocess) { + ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA"); + ds->srna= srna; + rna_addtail(&DefRNA.structs, ds); + } rna_addtail(&brna->structs, srna); - RNA_def_struct_sdna(srna, srna->identifier); + /* in preprocess, try to find sdna */ + if(DefRNA.preprocess) + RNA_def_struct_sdna(srna, srna->identifier); + else + srna->flag |= STRUCT_RUNTIME; - rna_def_builtin_properties(srna); + /* define some builtin properties */ + if(!srnafrom) { + prop= RNA_def_property(srna, "rna_properties", PROP_COLLECTION, PROP_NONE); + RNA_def_property_flag(prop, PROP_BUILTIN); + RNA_def_property_ui_text(prop, "Properties", "RNA property collection."); + + if(DefRNA.preprocess) { + RNA_def_property_struct_type(prop, "Property"); + RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", 0, 0, 0, 0); + } + else { +#ifdef RNA_RUNTIME + CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; + cprop->begin= rna_builtin_properties_begin; + cprop->next= rna_builtin_properties_next; + cprop->next= rna_iterator_listbase_end; + cprop->get= rna_builtin_properties_get; + cprop->structtype= &RNA_Property; +#endif + } + + prop= RNA_def_property(srna, "rna_type", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_ui_text(prop, "RNA", "RNA type definition."); + + if(DefRNA.preprocess) { + RNA_def_property_struct_type(prop, "Struct"); + RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL); + } + else { +#ifdef RNA_RUNTIME + PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; + pprop->get= rna_builtin_type_get; + pprop->structtype= &RNA_Struct; +#endif + } + } return srna; } @@ -220,6 +357,11 @@ void RNA_def_struct_sdna(StructRNA *srna, const char *structname) { StructDefRNA *ds= DefRNA.structs.last; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_struct_sdna: only during preprocessing.\n"); + return; + } + if(!DNA_struct_find_nr(DefRNA.sdna, structname)) { if(!DefRNA.silent) { fprintf(stderr, "RNA_def_struct_sdna: %s not found.\n", structname); @@ -246,26 +388,50 @@ void RNA_def_struct_flag(StructRNA *srna, int flag) srna->flag= flag; } +void RNA_def_struct_funcs(StructRNA *srna, const char *notify, const char *refine) +{ + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_struct_funcs: only during preprocessing.\n"); + return; + } + + if(notify) srna->notify= (NotifyFunc)notify; + if(refine) srna->refine= (StructRefineFunc)refine; +} + + +void RNA_def_struct_identifier(StructRNA *srna, const char *identifier, const char *name) +{ + if(DefRNA.preprocess) { + fprintf(stderr, "RNA_def_struct_name_runtime: only at runtime.\n"); + return; + } + + srna->identifier= identifier; + srna->name= name; +} + /* Property Definition */ PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, int subtype) { StructDefRNA *ds; - PropertyDefRNA *dp; + PropertyDefRNA *dp= NULL; PropertyRNA *prop; - ds= DefRNA.structs.last; - dp= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA"); - rna_addtail(&ds->properties, dp); + if(DefRNA.preprocess) { + ds= DefRNA.structs.last; + dp= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA"); + rna_addtail(&ds->properties, dp); + } + + prop= MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA"); switch(type) { case PROP_BOOLEAN: - prop= MEM_callocN(sizeof(BooleanPropertyRNA), "BooleanPropertyRNA"); break; case PROP_INT: { - IntPropertyRNA *iprop; - iprop= MEM_callocN(sizeof(IntPropertyRNA), "IntPropertyRNA"); - prop= &iprop->property; + IntPropertyRNA *iprop= (IntPropertyRNA*)prop; iprop->hardmin= (subtype == PROP_UNSIGNED)? 0: INT_MIN; iprop->hardmax= INT_MAX; @@ -276,9 +442,7 @@ PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, break; } case PROP_FLOAT: { - FloatPropertyRNA *fprop; - fprop= MEM_callocN(sizeof(FloatPropertyRNA), "FloatPropertyRNA"); - prop= &fprop->property; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; fprop->hardmin= (subtype == PROP_UNSIGNED)? 0.0f: -FLT_MAX; fprop->hardmax= FLT_MAX; @@ -290,31 +454,26 @@ PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, break; } case PROP_STRING: { - StringPropertyRNA *sprop; - sprop= MEM_callocN(sizeof(StringPropertyRNA), "StringPropertyRNA"); - prop= &sprop->property; + StringPropertyRNA *sprop= (StringPropertyRNA*)prop; sprop->defaultvalue= ""; sprop->maxlength= 0; break; } case PROP_ENUM: - prop= MEM_callocN(sizeof(EnumPropertyRNA), "EnumPropertyRNA"); - break; case PROP_POINTER: - prop= MEM_callocN(sizeof(PointerPropertyRNA), "PointerPropertyRNA"); - break; case PROP_COLLECTION: - prop= MEM_callocN(sizeof(CollectionPropertyRNA), "CollectionPropertyRNA"); break; default: - fprintf(stderr, "RNA_def_property: %s.%s, invalid property type.\n", ds->srna->identifier, identifier); + fprintf(stderr, "RNA_def_property: %s.%s, invalid property type.\n", srna->identifier, identifier); DefRNA.error= 1; return NULL; } - dp->srna= srna; - dp->prop= prop; + if(DefRNA.preprocess) { + dp->srna= srna; + dp->prop= prop; + } prop->magic= RNA_MAGIC; prop->identifier= identifier; @@ -328,46 +487,50 @@ PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, else if(type == PROP_POINTER) prop->flag= PROP_NOT_DRIVEABLE; - switch(type) { - case PROP_BOOLEAN: - DefRNA.silent= 1; - RNA_def_property_boolean_sdna(prop, srna->identifier, identifier, 0); - DefRNA.silent= 0; - break; - case PROP_INT: { - DefRNA.silent= 1; - RNA_def_property_int_sdna(prop, srna->identifier, identifier); - DefRNA.silent= 0; - break; + if(DefRNA.preprocess) { + switch(type) { + case PROP_BOOLEAN: + DefRNA.silent= 1; + RNA_def_property_boolean_sdna(prop, NULL, identifier, 0); + DefRNA.silent= 0; + break; + case PROP_INT: { + DefRNA.silent= 1; + RNA_def_property_int_sdna(prop, NULL, identifier); + DefRNA.silent= 0; + break; + } + case PROP_FLOAT: { + DefRNA.silent= 1; + RNA_def_property_float_sdna(prop, NULL, identifier); + DefRNA.silent= 0; + break; + } + case PROP_STRING: { + DefRNA.silent= 1; + RNA_def_property_string_sdna(prop, NULL, identifier); + DefRNA.silent= 0; + break; + } + case PROP_ENUM: + DefRNA.silent= 1; + RNA_def_property_enum_sdna(prop, NULL, identifier); + DefRNA.silent= 0; + break; + case PROP_POINTER: + DefRNA.silent= 1; + RNA_def_property_pointer_sdna(prop, NULL, identifier); + DefRNA.silent= 0; + break; + case PROP_COLLECTION: + DefRNA.silent= 1; + RNA_def_property_collection_sdna(prop, NULL, identifier, NULL); + DefRNA.silent= 0; + break; } - case PROP_FLOAT: { - DefRNA.silent= 1; - RNA_def_property_float_sdna(prop, srna->identifier, identifier); - DefRNA.silent= 0; - break; - } - case PROP_STRING: { - DefRNA.silent= 1; - RNA_def_property_string_sdna(prop, srna->identifier, identifier); - DefRNA.silent= 0; - break; - } - case PROP_ENUM: - DefRNA.silent= 1; - RNA_def_property_enum_sdna(prop, srna->identifier, identifier); - DefRNA.silent= 0; - break; - case PROP_POINTER: - DefRNA.silent= 1; - RNA_def_property_pointer_sdna(prop, srna->identifier, identifier); - DefRNA.silent= 0; - break; - case PROP_COLLECTION: - DefRNA.silent= 1; - RNA_def_property_collection_sdna(prop, srna->identifier, identifier, NULL); - DefRNA.silent= 0; - break; } + else + prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME; rna_addtail(&srna->properties, prop); @@ -377,7 +540,7 @@ PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, void RNA_def_property_flag(PropertyRNA *prop, int flag) { #if 0 - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; #endif prop->flag |= flag; @@ -394,7 +557,7 @@ void RNA_def_property_flag(PropertyRNA *prop, int flag) void RNA_def_property_array(PropertyRNA *prop, int arraylength) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_BOOLEAN: @@ -403,7 +566,7 @@ void RNA_def_property_array(PropertyRNA *prop, int arraylength) prop->arraylength= arraylength; break; default: - fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -417,7 +580,7 @@ void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *d void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_INT: { @@ -436,7 +599,7 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double break; } default: - fprintf(stderr, "RNA_def_property_ui_range: %s.%s, invalid type for ui range.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_ui_range: %s.%s, invalid type for ui range.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -444,7 +607,7 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double void RNA_def_property_range(PropertyRNA *prop, double min, double max) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_INT: { @@ -464,7 +627,7 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max) break; } default: - fprintf(stderr, "RNA_def_property_range: %s.%s, invalid type for range.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_range: %s.%s, invalid type for range.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -472,7 +635,12 @@ void RNA_def_property_range(PropertyRNA *prop, double min, double max) void RNA_def_property_struct_type(PropertyRNA *prop, const char *type) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_struct_type: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_POINTER: { @@ -486,7 +654,7 @@ void RNA_def_property_struct_type(PropertyRNA *prop, const char *type) break; } default: - fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -494,7 +662,7 @@ void RNA_def_property_struct_type(PropertyRNA *prop, const char *type) void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; int i; switch(prop->type) { @@ -508,7 +676,7 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item break; } default: - fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -516,7 +684,7 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_STRING: { @@ -525,7 +693,7 @@ void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength) break; } default: - fprintf(stderr, "RNA_def_property_string_maxlength: %s.%s, type is not string.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_string_maxlength: %s.%s, type is not string.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -533,7 +701,7 @@ void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength) void RNA_def_property_boolean_default(PropertyRNA *prop, int value) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_BOOLEAN: { @@ -542,7 +710,7 @@ void RNA_def_property_boolean_default(PropertyRNA *prop, int value) break; } default: - fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -550,7 +718,7 @@ void RNA_def_property_boolean_default(PropertyRNA *prop, int value) void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_BOOLEAN: { @@ -559,7 +727,7 @@ void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array) break; } default: - fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -567,7 +735,7 @@ void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array) void RNA_def_property_int_default(PropertyRNA *prop, int value) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_INT: { @@ -576,7 +744,7 @@ void RNA_def_property_int_default(PropertyRNA *prop, int value) break; } default: - fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -584,7 +752,7 @@ void RNA_def_property_int_default(PropertyRNA *prop, int value) void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_INT: { @@ -593,7 +761,7 @@ void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array) break; } default: - fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -601,7 +769,7 @@ void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array) void RNA_def_property_float_default(PropertyRNA *prop, float value) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_FLOAT: { @@ -610,7 +778,7 @@ void RNA_def_property_float_default(PropertyRNA *prop, float value) break; } default: - fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -618,7 +786,7 @@ void RNA_def_property_float_default(PropertyRNA *prop, float value) void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_FLOAT: { @@ -627,7 +795,7 @@ void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array) break; } default: - fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -635,7 +803,7 @@ void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array) void RNA_def_property_string_default(PropertyRNA *prop, const char *value) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_STRING: { @@ -644,7 +812,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value) break; } default: - fprintf(stderr, "RNA_def_property_string_default: %s.%s, type is not string.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_string_default: %s.%s, type is not string.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -652,7 +820,7 @@ void RNA_def_property_string_default(PropertyRNA *prop, const char *value) void RNA_def_property_enum_default(PropertyRNA *prop, int value) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; switch(prop->type) { case PROP_ENUM: { @@ -661,7 +829,7 @@ void RNA_def_property_enum_default(PropertyRNA *prop, int value) break; } default: - fprintf(stderr, "RNA_def_property_enum_default: %s.%s, type is not enum.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_enum_default: %s.%s, type is not enum.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -705,6 +873,11 @@ void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, co { PropertyDefRNA *dp; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n"); + return; + } + if((dp=rna_def_property_sdna(prop, structname, propname))) dp->booleanbit= bit; } @@ -714,6 +887,11 @@ void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const PropertyDefRNA *dp; IntPropertyRNA *iprop= (IntPropertyRNA*)prop; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n"); + return; + } + if((dp= rna_def_property_sdna(prop, structname, propname))) { /* SDNA doesn't pass us unsigned unfortunately .. */ if(strcmp(dp->dnatype, "char") == 0) { @@ -746,6 +924,11 @@ void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const { PropertyDefRNA *dp; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n"); + return; + } + if((dp=rna_def_property_sdna(prop, structname, propname))) { if(prop->arraylength) { prop->arraylength= 0; @@ -762,6 +945,11 @@ void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, con PropertyDefRNA *dp; StringPropertyRNA *sprop= (StringPropertyRNA*)prop; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n"); + return; + } + if((dp=rna_def_property_sdna(prop, structname, propname))) { if(prop->arraylength) { sprop->maxlength= prop->arraylength; @@ -774,6 +962,11 @@ void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, co { PropertyDefRNA *dp; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n"); + return; + } + if((dp=rna_def_property_sdna(prop, structname, propname))) { if(prop->arraylength) { prop->arraylength= 0; @@ -789,7 +982,12 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, { PropertyDefRNA *dp; CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; - + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n"); + return; + } + if((dp=rna_def_property_sdna(prop, structname, propname))) { if(prop->arraylength) { prop->arraylength= 0; @@ -833,14 +1031,24 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, /* Functions */ -void RNA_def_property_notify_func(PropertyRNA *prop, const char *notify) +void RNA_def_property_funcs(PropertyRNA *prop, const char *notify) { - if(notify) prop->notify= (PropNotifyFunc)notify; + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_funcs: only during preprocessing.\n"); + return; + } + + if(notify) prop->notify= (NotifyFunc)notify; } void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_BOOLEAN: { @@ -857,7 +1065,7 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch break; } default: - fprintf(stderr, "RNA_def_property_boolean_funcs: %s.%s, type is not boolean.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_boolean_funcs: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -865,7 +1073,12 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_INT: { @@ -882,7 +1095,7 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char * break; } default: - fprintf(stderr, "RNA_def_property_int_funcs: %s.%s, type is not int.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_int_funcs: %s.%s, type is not int.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -890,7 +1103,12 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char * void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_FLOAT: { @@ -907,7 +1125,7 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char break; } default: - fprintf(stderr, "RNA_def_property_float_funcs: %s.%s, type is not float.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_float_funcs: %s.%s, type is not float.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -915,7 +1133,12 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_ENUM: { @@ -926,7 +1149,7 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char break; } default: - fprintf(stderr, "RNA_def_property_enum_funcs: %s.%s, type is not enum.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_enum_funcs: %s.%s, type is not enum.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -934,7 +1157,12 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_STRING: { @@ -946,7 +1174,7 @@ void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const cha break; } default: - fprintf(stderr, "RNA_def_property_string_funcs: %s.%s, type is not string.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_string_funcs: %s.%s, type is not string.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -954,7 +1182,12 @@ void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const cha void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *type, const char *set) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_POINTER: { @@ -966,7 +1199,7 @@ void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const ch break; } default: - fprintf(stderr, "RNA_def_property_pointer_funcs: %s.%s, type is not pointer.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_pointer_funcs: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } @@ -974,7 +1207,12 @@ void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const ch void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *type, const char *length, const char *lookupint, const char *lookupstring) { - StructDefRNA *ds= DefRNA.structs.last; + StructRNA *srna; + + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n"); + return; + } switch(prop->type) { case PROP_COLLECTION: { @@ -991,7 +1229,7 @@ void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, con break; } default: - fprintf(stderr, "RNA_def_property_collection_funcs: %s.%s, type is not collection.\n", ds->srna->identifier, prop->identifier); + fprintf(stderr, "RNA_def_property_collection_funcs: %s.%s, type is not collection.\n", srna->identifier, prop->identifier); DefRNA.error= 1; break; } diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index abf6c16a505..b577e43cb84 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -68,13 +68,37 @@ typedef struct BlenderDefRNA { struct SDNA *sdna; ListBase structs; ListBase allocs; - int error, silent; + struct StructRNA *laststruct; + int error, silent, preprocess; } BlenderDefRNA; extern BlenderDefRNA DefRNA; /* Define functions for all types */ +extern BlenderRNA BLENDER_RNA; + +extern StructRNA RNA_Lamp; +extern StructRNA RNA_Main; +extern StructRNA RNA_Mesh; +extern StructRNA RNA_Object; +extern StructRNA RNA_Operator; +extern StructRNA RNA_Property; +extern StructRNA RNA_Scene; +extern StructRNA RNA_Struct; +extern StructRNA RNA_WindowManager; + +void RNA_def_ID(struct BlenderRNA *brna); +void RNA_def_lamp(struct BlenderRNA *brna); +void RNA_def_main(struct BlenderRNA *brna); +void RNA_def_mesh(struct BlenderRNA *brna); +void RNA_def_object(struct BlenderRNA *brna); +void RNA_def_rna(struct BlenderRNA *brna); +void RNA_def_scene(struct BlenderRNA *brna); +void RNA_def_wm(struct BlenderRNA *brna); + +/* ID Properties */ + extern StringPropertyRNA rna_IDProperty_string; extern IntPropertyRNA rna_IDProperty_int; extern IntPropertyRNA rna_IDProperty_intarray; @@ -84,29 +108,21 @@ extern PointerPropertyRNA rna_IDProperty_group; extern FloatPropertyRNA rna_IDProperty_double; extern FloatPropertyRNA rna_IDProperty_doublearray; -extern StructRNA RNA_Main; -extern StructRNA RNA_Mesh; -extern StructRNA RNA_Object; -extern StructRNA RNA_Scene; -extern StructRNA RNA_Lamp; -extern StructRNA RNA_Struct; - -void RNA_def_ID(struct StructRNA *srna); -void RNA_def_ID_types(struct BlenderRNA *brna); - -void RNA_def_main(struct BlenderRNA *brna); -void RNA_def_mesh(struct BlenderRNA *brna); -void RNA_def_object(struct BlenderRNA *brna); -void RNA_def_rna(struct BlenderRNA *brna); -void RNA_def_scene(struct BlenderRNA *brna); -void RNA_def_lamp(struct BlenderRNA *brna); - -/* Internal Functions */ - -void rna_def_builtin_properties(struct StructRNA *srna); +extern StructRNA RNA_IDProperty; +extern StructRNA RNA_IDPropertyGroup; +struct IDProperty *rna_idproperties_get(struct StructRNA *type, void *data, int create); struct IDProperty *rna_idproperty_check(struct PropertyRNA **prop, struct PointerRNA *ptr); +/* Builtin Property Callbacks */ + +void rna_builtin_properties_begin(struct CollectionPropertyIterator *iter, struct PointerRNA *ptr); +void rna_builtin_properties_next(struct CollectionPropertyIterator *iter); +void *rna_builtin_properties_get(struct CollectionPropertyIterator *iter); +void *rna_builtin_type_get(struct PointerRNA *ptr); + +/* Iterators */ + typedef struct ListBaseIterator { Link *link; int flag; @@ -131,6 +147,7 @@ void rna_iterator_array_end(struct CollectionPropertyIterator *iter); /* Duplicated code since we can't link in blenlib */ void rna_addtail(struct ListBase *listbase, void *vlink); +void rna_freelinkN(struct ListBase *listbase, void *vlink); void rna_freelistN(struct ListBase *listbase); #endif /* RNA_INTERNAL_H */ diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 6deaba547e6..3cb4bbea63e 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -36,7 +36,9 @@ struct bContext; /* Function Callbacks */ -typedef void (*PropNotifyFunc)(struct bContext *C, struct PointerRNA *ptr); +typedef void (*NotifyFunc)(struct bContext *C, struct PointerRNA *ptr); +typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr); + typedef int (*PropBooleanGetFunc)(struct PointerRNA *ptr); typedef void (*PropBooleanSetFunc)(struct PointerRNA *ptr, int value); typedef int (*PropBooleanArrayGetFunc)(struct PointerRNA *ptr, int index); @@ -90,7 +92,7 @@ struct PropertyRNA { unsigned int arraylength; /* callback for notifys on change */ - PropNotifyFunc notify; + NotifyFunc notify; }; /* Property Types */ @@ -209,6 +211,15 @@ struct StructRNA { /* property to iterate over properties */ PropertyRNA *iteratorproperty; + /* struct this is derivedfrom */ + struct StructRNA *from; + + /* callback for notifys on change */ + NotifyFunc notify; + + /* function to give the more specific type */ + StructRefineFunc refine; + /* properties of this struct */ ListBase properties; }; diff --git a/source/blender/makesrna/intern/rna_lamp.c b/source/blender/makesrna/intern/rna_lamp.c index 795b493d63a..f5000b59c51 100644 --- a/source/blender/makesrna/intern/rna_lamp.c +++ b/source/blender/makesrna/intern/rna_lamp.c @@ -33,7 +33,6 @@ #ifdef RNA_RUNTIME - #else void RNA_def_lamp(BlenderRNA *brna) @@ -42,9 +41,7 @@ void RNA_def_lamp(BlenderRNA *brna) PropertyRNA *prop; static EnumPropertyItem prop_type_items[] = {{LA_LOCAL, "LOCAL", "Local"}, {LA_SUN, "SUN", "Sun"}, {LA_SPOT, "SPOT", "Spot"}, {LA_HEMI, "HEMI", "Hemi"}, {LA_AREA, "AREA", "Area"}, {0, NULL, NULL}}; - srna= RNA_def_struct(brna, "Lamp", "Lamp"); - - RNA_def_ID(srna); + srna= RNA_def_struct(brna, "Lamp", "ID", "Lamp"); prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, prop_type_items); diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 1ffba247dfc..b1840b9d216 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -194,13 +194,13 @@ static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA Main *bmain= (Main*)ptr->data; rna_iterator_listbase_begin(iter, &bmain->particle); } +#endif static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Main *bmain= (Main*)ptr->data; rna_iterator_listbase_begin(iter, &bmain->wm); } -#endif #else @@ -213,6 +213,7 @@ void RNA_def_main(BlenderRNA *brna) {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks."}, {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks."}, {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."}, + {"windowmanagers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks."}, {NULL, NULL, NULL, NULL, NULL}, {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."}, {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks."}, @@ -236,11 +237,10 @@ void RNA_def_main(BlenderRNA *brna) {"nodegroups", "NodeGroup", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks."}, {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks."}, {"particles", "Particle", "rna_Main_particle_begin", "Particles", "Particle datablocks."}, - {"windowmanagers", "wmWindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks."}, {NULL, NULL, NULL, NULL, NULL}}; int i; - srna= RNA_def_struct(brna, "Main", "Main"); + srna= RNA_def_struct(brna, "Main", NULL, "Main"); for(i=0; lists[i][0]; i++) { diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 6a4125e6257..64ec78b6a73 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -42,9 +42,7 @@ void RNA_def_mesh(BlenderRNA *brna) PropertyRNA *prop; /* mesh */ - srna= RNA_def_struct(brna, "Mesh", "Mesh"); - - RNA_def_ID(srna); + srna= RNA_def_struct(brna, "Mesh", "ID", "Mesh"); prop= RNA_def_property(srna, "verts", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert"); @@ -52,7 +50,7 @@ void RNA_def_mesh(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh."); /* vertex */ - srna= RNA_def_struct(brna, "MVert", "Mesh Vertex"); + srna= RNA_def_struct(brna, "MVert", NULL, "Mesh Vertex"); prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_VECTOR); RNA_def_property_ui_text(prop, "Location", "Location of the vertex."); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index c618a75ec1c..b57cf31699b 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -34,40 +34,6 @@ #ifdef RNA_RUNTIME -static StructRNA *rna_Object_data_type(PointerRNA *ptr) -{ - Object *ob= (Object*)ptr->data; - - switch(ob->type) { - case OB_EMPTY: - return NULL; - case OB_MESH: - return &RNA_Mesh; - case OB_LAMP: - return &RNA_Lamp; -#if 0 - case OB_CURVE: - return &RNA_Curve; - case OB_SURF: - return &RNA_Surface; - case OB_FONT: - return &RNA_Font; - case OB_MBALL: - return &RNA_MBall; - case OB_LAMP: - return &RNA_Lamp; - case OB_CAMERA: - return &RNA_Camera; - case OB_WAVE: - return &RNA_Wave; - case OB_LATTICE: - return &RNA_Lattice; -#endif - default: - return NULL; - } -} - #else void RNA_def_object(BlenderRNA *brna) @@ -75,12 +41,10 @@ void RNA_def_object(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - srna= RNA_def_struct(brna, "Object", "Object"); - - RNA_def_ID(srna); + srna= RNA_def_struct(brna, "Object", "ID", "Object"); prop= RNA_def_property(srna, "data", PROP_POINTER, PROP_NONE); - RNA_def_property_pointer_funcs(prop, NULL, "rna_Object_data_type", NULL); + RNA_def_property_struct_type(prop, "ID"); RNA_def_property_ui_text(prop, "Data", "Object data."); prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index e3d83e92964..8894a159455 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -57,16 +57,29 @@ static void *rna_Struct_name_property_get(PointerRNA *ptr) return ((StructRNA*)ptr->data)->nameproperty; } +static int rna_idproperty_known(CollectionPropertyIterator *iter) +{ + ListBaseIterator *internal= iter->internal; + IDProperty *idprop= (IDProperty*)internal->link; + PropertyRNA *prop; + + for(prop= iter->parent.type->properties.first; prop; prop=prop->next) + if(strcmp(prop->identifier, idprop->name) == 0) + return 1; + + return 0; +} + static void rna_Struct_properties_next(CollectionPropertyIterator *iter) { ListBaseIterator *internal= iter->internal; - ID *id; - StructRNA *type; IDProperty *group; if(internal->flag) { /* id properties */ - rna_iterator_listbase_next(iter); + do { + rna_iterator_listbase_next(iter); + } while(iter->valid && rna_idproperty_known(iter)); } else { /* regular properties */ @@ -76,21 +89,16 @@ static void rna_Struct_properties_next(CollectionPropertyIterator *iter) /* try id properties */ if(!iter->valid) { - type= iter->parent.id.type; - id= iter->parent.id.data; - - if(iter->parent.type == &RNA_IDPropertyGroup) - group= iter->parent.data; - else if(iter->parent.data == id && type && (type->flag & STRUCT_ID)) - group= IDP_GetProperties(id, 0); - else - group= NULL; + group= rna_idproperties_get(iter->parent.type, iter->parent.data, 0); if(group) { rna_iterator_listbase_end(iter); rna_iterator_listbase_begin(iter, &group->data.group); internal= iter->internal; internal->flag= 1; + + if(iter->valid && rna_idproperty_known(iter)) + rna_Struct_properties_next(iter); } } } @@ -116,26 +124,7 @@ static void *rna_Struct_properties_get(CollectionPropertyIterator *iter) return internal->link; } -static StructRNA *rna_Struct_properties_type(CollectionPropertyIterator *iter) -{ - ListBaseIterator *internal= iter->internal; - PropertyRNA *prop= (PropertyRNA*)internal->link; - - rna_idproperty_check(&prop, NULL); - - switch(prop->type) { - case PROP_BOOLEAN: return &RNA_BooleanProperty; - case PROP_INT: return &RNA_IntProperty; - case PROP_FLOAT: return &RNA_FloatProperty; - case PROP_STRING: return &RNA_StringProperty; - case PROP_ENUM: return &RNA_EnumProperty; - case PROP_POINTER: return &RNA_PointerProperty; - case PROP_COLLECTION: return &RNA_CollectionProperty; - default: return NULL; - } -} - -static void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { PointerRNA newptr; @@ -155,172 +144,185 @@ static void rna_builtin_properties_begin(CollectionPropertyIterator *iter, Point rna_Struct_properties_begin(iter, &newptr); } -static void rna_builtin_properties_next(CollectionPropertyIterator *iter) +void rna_builtin_properties_next(CollectionPropertyIterator *iter) { rna_Struct_properties_next(iter); } -static void *rna_builtin_properties_get(CollectionPropertyIterator *iter) +void *rna_builtin_properties_get(CollectionPropertyIterator *iter) { return rna_Struct_properties_get(iter); } -static StructRNA *rna_builtin_properties_type(CollectionPropertyIterator *iter) -{ - return rna_Struct_properties_type(iter); -} - -static void *rna_builtin_type_get(PointerRNA *ptr) +void *rna_builtin_type_get(PointerRNA *ptr) { return ptr->type; } /* Property */ +static StructRNA *rna_Property_refine(PointerRNA *ptr) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + + rna_idproperty_check(&prop, ptr); /* XXX ptr? */ + + switch(prop->type) { + case PROP_BOOLEAN: return &RNA_BooleanProperty; + case PROP_INT: return &RNA_IntProperty; + case PROP_FLOAT: return &RNA_FloatProperty; + case PROP_STRING: return &RNA_StringProperty; + case PROP_ENUM: return &RNA_EnumProperty; + case PROP_POINTER: return &RNA_PointerProperty; + case PROP_COLLECTION: return &RNA_CollectionProperty; + default: return &RNA_Property; + } +} + static void rna_Property_identifier_get(PointerRNA *ptr, char *value) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); strcpy(value, ((PropertyRNA*)prop)->identifier); } static int rna_Property_identifier_length(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return strlen(prop->identifier); } static void rna_Property_name_get(PointerRNA *ptr, char *value) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); strcpy(value, prop->name); } static int rna_Property_name_length(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return strlen(prop->name); } static void rna_Property_description_get(PointerRNA *ptr, char *value) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); strcpy(value, prop->description); } static int rna_Property_description_length(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return strlen(prop->description); } static int rna_Property_type_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return prop->type; } static int rna_Property_subtype_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return prop->subtype; } static int rna_Property_array_length_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return prop->arraylength; } static int rna_IntProperty_hard_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((IntPropertyRNA*)prop)->hardmin; } static int rna_IntProperty_hard_max_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((IntPropertyRNA*)prop)->hardmax; } static int rna_IntProperty_soft_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((IntPropertyRNA*)prop)->softmin; } static int rna_IntProperty_soft_max_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((IntPropertyRNA*)prop)->softmax; } static int rna_IntProperty_step_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((IntPropertyRNA*)prop)->step; } static float rna_FloatProperty_hard_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((FloatPropertyRNA*)prop)->hardmin; } static float rna_FloatProperty_hard_max_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((FloatPropertyRNA*)prop)->hardmax; } static float rna_FloatProperty_soft_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((FloatPropertyRNA*)prop)->softmin; } static float rna_FloatProperty_soft_max_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((FloatPropertyRNA*)prop)->softmax; } static float rna_FloatProperty_step_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((FloatPropertyRNA*)prop)->step; } static int rna_FloatProperty_precision_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((FloatPropertyRNA*)prop)->precision; } static int rna_StringProperty_max_length_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((StringPropertyRNA*)prop)->maxlength; } @@ -329,7 +331,7 @@ static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, Point PropertyRNA *prop= (PropertyRNA*)ptr->data; EnumPropertyRNA *eprop; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); eprop= (EnumPropertyRNA*)prop; rna_iterator_array_begin(iter, (void*)eprop->item, sizeof(eprop->item[0]), eprop->totitem); @@ -363,21 +365,53 @@ static int rna_EnumPropertyItem_value_get(PointerRNA *ptr) static void *rna_PointerProperty_fixed_type_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((PointerPropertyRNA*)prop)->structtype; } static void *rna_CollectionProperty_fixed_type_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; - rna_idproperty_check(&prop, NULL); + rna_idproperty_check(&prop, ptr); return ((CollectionPropertyRNA*)prop)->structtype; } #else -static void rna_def_property(StructRNA *srna) +static void rna_def_struct(BlenderRNA *brna) { + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "Struct", NULL, "Struct Definition"); + + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_string_funcs(prop, "rna_Struct_name_get", "rna_Struct_name_length", NULL); + RNA_def_property_ui_text(prop, "Name", "Human readable name."); + RNA_def_struct_name_property(srna, prop); + + prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_string_funcs(prop, "rna_Struct_identifier_get", "rna_Struct_identifier_length", NULL); + RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting."); + + prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_struct_type(prop, "StringProperty"); + RNA_def_property_pointer_funcs(prop, "rna_Struct_name_property_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Name Property", "Property that gives the name of the struct."); + + prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_struct_type(prop, "Property"); + RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next", "rna_iterator_listbase_end", "rna_Struct_properties_get", 0, 0, 0, 0); + RNA_def_property_ui_text(prop, "Properties", "Properties in the struct."); +} + +static void rna_def_property(BlenderRNA *brna) +{ + StructRNA *srna; PropertyRNA *prop; static EnumPropertyItem type_items[] = { {PROP_BOOLEAN, "BOOLEAN", "Boolean"}, @@ -398,6 +432,9 @@ static void rna_def_property(StructRNA *srna) {PROP_ROTATION, "ROTATION", "Rotation"}, {0, NULL, NULL}}; + srna= RNA_def_struct(brna, "Property", NULL, "Property Definition"); + RNA_def_struct_funcs(srna, NULL, "rna_Property_refine"); + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_flag(prop, PROP_NOT_EDITABLE); RNA_def_property_string_funcs(prop, "rna_Property_name_get", "rna_Property_name_length", NULL); @@ -477,6 +514,16 @@ static void rna_def_number_property(StructRNA *srna, PropertyType type) } } +static void rna_def_string_property(StructRNA *srna) +{ + PropertyRNA *prop; + + prop= RNA_def_property(srna, "max_length", PROP_INT, PROP_UNSIGNED); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL); + RNA_def_property_ui_text(prop, "Maximum Length", "Maximum length of the string, 0 means unlimited."); +} + static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) { PropertyRNA *prop; @@ -487,7 +534,7 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) RNA_def_property_collection_funcs(prop, "rna_EnumProperty_items_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0, 0); RNA_def_property_ui_text(prop, "Items", "Possible values for the property."); - srna= RNA_def_struct(brna, "EnumPropertyItem", "Enum Item Definition"); + srna= RNA_def_struct(brna, "EnumPropertyItem", NULL, "Enum Item Definition"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_flag(prop, PROP_NOT_EDITABLE); @@ -523,88 +570,41 @@ static void rna_def_pointer_property(StructRNA *srna, PropertyType type) void RNA_def_rna(BlenderRNA *brna) { StructRNA *srna; - PropertyRNA *prop; - /* StructRNA */ - srna= RNA_def_struct(brna, "Struct", "Struct Definition"); + /* Struct*/ + rna_def_struct(brna); - prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); - RNA_def_property_flag(prop, PROP_NOT_EDITABLE); - RNA_def_property_string_funcs(prop, "rna_Struct_name_get", "rna_Struct_name_length", NULL); - RNA_def_property_ui_text(prop, "Name", "Human readable name."); - RNA_def_struct_name_property(srna, prop); - - prop= RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); - RNA_def_property_flag(prop, PROP_NOT_EDITABLE); - RNA_def_property_string_funcs(prop, "rna_Struct_identifier_get", "rna_Struct_identifier_length", NULL); - RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting."); - - prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE); - RNA_def_property_flag(prop, PROP_NOT_EDITABLE); - RNA_def_property_struct_type(prop, "StringProperty"); - RNA_def_property_pointer_funcs(prop, "rna_Struct_name_property_get", NULL, NULL); - RNA_def_property_ui_text(prop, "Name Property", "Property that gives the name of the struct."); - - prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE); - RNA_def_property_flag(prop, PROP_NOT_EDITABLE); - RNA_def_property_collection_funcs(prop, "rna_Struct_properties_begin", "rna_Struct_properties_next", "rna_iterator_listbase_end", "rna_Struct_properties_get", "rna_Struct_properties_type", 0, 0, 0); - RNA_def_property_ui_text(prop, "Properties", "Properties in the struct."); + /* Property */ + rna_def_property(brna); /* BooleanProperty */ - srna= RNA_def_struct(brna, "BooleanProperty", "Boolean Definition"); - rna_def_property(srna); + srna= RNA_def_struct(brna, "BooleanProperty", "Property", "Boolean Definition"); rna_def_number_property(srna, PROP_BOOLEAN); /* IntProperty */ - srna= RNA_def_struct(brna, "IntProperty", "Int Definition"); - rna_def_property(srna); + srna= RNA_def_struct(brna, "IntProperty", "Property", "Int Definition"); rna_def_number_property(srna, PROP_INT); /* FloatProperty */ - srna= RNA_def_struct(brna, "FloatProperty", "Float Definition"); - rna_def_property(srna); + srna= RNA_def_struct(brna, "FloatProperty", "Property", "Float Definition"); rna_def_number_property(srna, PROP_FLOAT); /* StringProperty */ - srna= RNA_def_struct(brna, "StringProperty", "String Definition"); - rna_def_property(srna); - - prop= RNA_def_property(srna, "max_length", PROP_INT, PROP_UNSIGNED); - RNA_def_property_flag(prop, PROP_NOT_EDITABLE); - RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", NULL); - RNA_def_property_ui_text(prop, "Maximum Length", "Maximum length of the string, 0 means unlimited."); + srna= RNA_def_struct(brna, "StringProperty", "Property", "String Definition"); + rna_def_string_property(srna); /* EnumProperty */ - srna= RNA_def_struct(brna, "EnumProperty", "Enum Definition"); - rna_def_property(srna); + srna= RNA_def_struct(brna, "EnumProperty", "Property", "Enum Definition"); rna_def_enum_property(brna, srna); /* PointerProperty */ - srna= RNA_def_struct(brna, "PointerProperty", "Pointer Definition"); - rna_def_property(srna); + srna= RNA_def_struct(brna, "PointerProperty", "Property", "Pointer Definition"); rna_def_pointer_property(srna, PROP_POINTER); /* CollectionProperty */ - srna= RNA_def_struct(brna, "CollectionProperty", "Collection Definition"); - rna_def_property(srna); + srna= RNA_def_struct(brna, "CollectionProperty", "Property", "Collection Definition"); rna_def_pointer_property(srna, PROP_COLLECTION); } -void rna_def_builtin_properties(StructRNA *srna) -{ - PropertyRNA *prop; - - prop= RNA_def_property(srna, "rna_properties", PROP_COLLECTION, PROP_NONE); - RNA_def_property_flag(prop, PROP_BUILTIN); - RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", "rna_builtin_properties_type", 0, 0, 0); - RNA_def_property_ui_text(prop, "Properties", "RNA property collection."); - - prop= RNA_def_property(srna, "rna_type", PROP_POINTER, PROP_NONE); - RNA_def_property_flag(prop, PROP_NOT_EDITABLE); - RNA_def_property_struct_type(prop, "Struct"); - RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL); - RNA_def_property_ui_text(prop, "RNA", "RNA type definition."); -} - #endif diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 217a32ecd84..2a42f7107bc 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -64,9 +64,7 @@ void RNA_def_scene(BlenderRNA *brna) static EnumPropertyItem prop_mode_items[] = {{PROP_SMOOTH, "SMOOTH", "Smooth"}, {PROP_SPHERE, "SPHERE", "Sphere"}, {PROP_ROOT, "ROOT", "Root"}, {PROP_SHARP, "SHARP", "Sharp"}, {PROP_LIN, "LINEAR", "Linear"}, {PROP_CONST, "CONSTANT", "Constant"}, {PROP_RANDOM, "RANDOM", "Random"}, {0, NULL, NULL}}; static EnumPropertyItem unwrapper_items[] = {{0, "CONFORMAL", "Conformal"}, {1, "ANGLEBASED", "Angle Based"}, {0, NULL, NULL}}; - srna= RNA_def_struct(brna, "Scene", "Scene"); - - RNA_def_ID(srna); + srna= RNA_def_struct(brna, "Scene", "ID", "Scene"); prop= RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE); RNA_def_property_ui_text(prop, "Active Camera", "Active camera used for rendering the scene."); diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c new file mode 100644 index 00000000000..f85a29fa780 --- /dev/null +++ b/source/blender/makesrna/intern/rna_wm.c @@ -0,0 +1,93 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Contributor(s): Blender Foundation (2008). + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include + +#include "RNA_define.h" +#include "RNA_types.h" + +#include "rna_internal.h" + +#include "DNA_windowmanager_types.h" + +#ifdef RNA_RUNTIME + +static StructRNA *rna_Operator_refine(PointerRNA *ptr) +{ + wmOperator *op= (wmOperator*)ptr->data; + return op->type->rna; +} + +static void rna_Operator_name_get(PointerRNA *ptr, char *value) +{ + wmOperator *op= (wmOperator*)ptr->data; + strcpy(value, op->type->name); +} + +static int rna_Operator_name_length(PointerRNA *ptr) +{ + wmOperator *op= (wmOperator*)ptr->data; + return strlen(op->type->name); +} + +#else + +static void rna_def_operator(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "Operator", NULL, "Operator"); + RNA_def_struct_sdna(srna, "wmOperator"); + RNA_def_struct_funcs(srna, NULL, "rna_Operator_refine"); + + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_NOT_EDITABLE); + RNA_def_property_ui_text(prop, "Name", "Operator name."); + RNA_def_property_string_funcs(prop, "rna_Operator_name_get", "rna_Operator_name_length", NULL); + + RNA_def_struct_name_property(srna, prop); +} + +static void rna_def_windowmanager(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "WindowManager", "ID", "Window Manager"); + RNA_def_struct_sdna(srna, "wmWindowManager"); + + prop= RNA_def_property(srna, "operators", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "Operator"); + RNA_def_property_ui_text(prop, "Operators", "Operator registry."); +} + +void RNA_def_wm(BlenderRNA *brna) +{ + rna_def_operator(brna); + rna_def_windowmanager(brna); +} + +#endif +