diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-05-20 13:52:02 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-05-20 13:52:02 +0400 |
commit | f1286b15a3ce11c1b85b7d387fb7f3e1a243bff5 (patch) | |
tree | dd6b6b3bab836dbe069b08682607224dbdcf25cb /source/blender | |
parent | d80911b8675582dca46ce78c17d5434b66a27f18 (diff) |
RNA:
* Any Struct can now have ID properties, by creating a callback
function to create/return an IDProperty.
* Wrapped PoseChannel ID properties.
* Note there is still no way to create ID Properties in 2.5, though
the callback to get/create the initial group is now exposed through
RNA_struct_idproperties.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 12 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 71 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal_types.h | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_pose.c | 14 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 13 |
11 files changed, 91 insertions, 43 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 5795bfe5b26..36026cbf28c 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -340,6 +340,8 @@ void RNA_struct_py_type_set(StructRNA *srna, void *py_type); void *RNA_struct_blender_type_get(StructRNA *srna); void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type); +struct IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create); + PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier); const struct ListBase *RNA_struct_defined_properties(StructRNA *srna); diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index c3c07f34ae0..5777553ed58 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -53,6 +53,7 @@ void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop); void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname); void RNA_def_struct_flag(StructRNA *srna, int flag); void RNA_def_struct_refine_func(StructRNA *srna, const char *refine); +void RNA_def_struct_idproperties_func(StructRNA *srna, const char *refine); void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg); void RNA_def_struct_path_func(StructRNA *srna, const char *path); void RNA_def_struct_identifier(StructRNA *srna, const char *identifier); diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 615db3628f8..2c383c191d8 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1706,6 +1706,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) fprintf(f, "\t%s,\n", rna_function_string(srna->path)); fprintf(f, "\t%s,\n", rna_function_string(srna->reg)); fprintf(f, "\t%s,\n", rna_function_string(srna->unreg)); + fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties)); if(srna->reg && !srna->refine) { fprintf(stderr, "rna_generate_struct: %s has a register function, must also have refine function.\n", srna->identifier); diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 3146c20a715..ee1a1fedf2c 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -90,6 +90,11 @@ StructRNA *rna_ID_refine(PointerRNA *ptr) } } +IDProperty *rna_ID_idproperties(PointerRNA *ptr, int create) +{ + return IDP_GetProperties(ptr->data, create); +} + void rna_ID_fake_user_set(PointerRNA *ptr, int value) { ID *id= (ID*)ptr->data; @@ -104,6 +109,11 @@ void rna_ID_fake_user_set(PointerRNA *ptr, int value) } } +IDProperty *rna_IDPropertyGroup_idproperties(PointerRNA *ptr, int create) +{ + return ptr->data; +} + #else static void rna_def_ID_properties(BlenderRNA *brna) @@ -161,6 +171,7 @@ static void rna_def_ID_properties(BlenderRNA *brna) * care of the properties here */ srna= RNA_def_struct(brna, "IDPropertyGroup", NULL); RNA_def_struct_ui_text(srna, "ID Property Group", "Group of ID properties."); + RNA_def_struct_idproperties_func(srna, "rna_IDPropertyGroup_idproperties"); } static void rna_def_ID(BlenderRNA *brna) @@ -173,6 +184,7 @@ static void rna_def_ID(BlenderRNA *brna) RNA_def_struct_ui_text(srna, "ID", "Base type for datablocks, defining a unique name, linking from other libraries and garbage collection."); RNA_def_struct_flag(srna, STRUCT_ID); RNA_def_struct_refine_func(srna, "rna_ID_refine"); + RNA_def_struct_idproperties_func(srna, "rna_ID_idproperties"); prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_ui_text(prop, "Name", "Unique datablock ID name."); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 6698335e1cb..36d1089ad7f 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -144,28 +144,19 @@ PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *da /* ID Properties */ -IDProperty *rna_idproperties_get(PointerRNA *ptr, int create) -{ - if(ptr->type->flag & STRUCT_ID) - return IDP_GetProperties(ptr->data, create); - else if(ptr->type == &RNA_IDPropertyGroup || ptr->type->base == &RNA_IDPropertyGroup) - return ptr->data; - else if(ptr->type->base == &RNA_OperatorProperties) { - if(create && !ptr->data) { - IDPropertyTemplate val; - val.i = 0; /* silence MSVC warning about uninitialized var when debugging */ - ptr->data= IDP_New(IDP_GROUP, val, "RNA_OperatorProperties group"); - } +IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create) +{ + StructRNA *type= ptr->type; - return ptr->data; - } - else - return NULL; + if(type->idproperties) + return type->idproperties(ptr, create); + + return NULL; } static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name) { - IDProperty *group= rna_idproperties_get(ptr, 0); + IDProperty *group= RNA_struct_idproperties(ptr, 0); IDProperty *idprop; if(group) { @@ -252,7 +243,7 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier); if(idprop && !rna_idproperty_verify_valid(*prop, idprop)) { - IDProperty *group= rna_idproperties_get(ptr, 0); + IDProperty *group= RNA_struct_idproperties(ptr, 0); IDP_RemFromGroup(group, idprop); IDP_FreeProperty(idprop); @@ -730,12 +721,12 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value) else if(bprop->set) bprop->set(ptr, value); else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.i= value; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); } @@ -786,13 +777,13 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in else if(bprop->setarray) bprop->setarray(ptr, values); else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.array.len= prop->arraylength; val.array.type= IDP_INT; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) { idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); IDP_AddToGroup(group, idprop); @@ -833,12 +824,12 @@ void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value) else if(iprop->set) iprop->set(ptr, value); else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.i= value; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); } @@ -889,13 +880,13 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v else if(iprop->setarray) iprop->setarray(ptr, values); else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.array.len= prop->arraylength; val.array.type= IDP_INT; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) { idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); IDP_AddToGroup(group, idprop); @@ -945,12 +936,12 @@ void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value) fprop->set(ptr, value); } else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.f= value; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_FLOAT, val, (char*)prop->identifier)); } @@ -1014,13 +1005,13 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa fprop->setarray(ptr, values); } else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.array.len= prop->arraylength; val.array.type= IDP_FLOAT; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) { idprop= IDP_New(IDP_ARRAY, val, (char*)prop->identifier); IDP_AddToGroup(group, idprop); @@ -1091,12 +1082,12 @@ void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *val else if(sprop->set) sprop->set(ptr, value); else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.str= (char*)value; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_STRING, val, (char*)prop->identifier)); } @@ -1127,12 +1118,12 @@ void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value) eprop->set(ptr, value); } else if(prop->flag & PROP_EDITABLE) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.i= value; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_INT, val, (char*)prop->identifier)); } @@ -1175,12 +1166,12 @@ void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop) /* already exists */ } else if(prop->flag & PROP_IDPROPERTY) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *group; val.i= 0; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) IDP_AddToGroup(group, IDP_New(IDP_GROUP, val, (char*)prop->identifier)); } @@ -1276,9 +1267,8 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA IDProperty *idprop; if((idprop=rna_idproperty_check(&prop, ptr))) { - IDPropertyTemplate val; + IDPropertyTemplate val = {0}; IDProperty *item; - val.i= 0; item= IDP_New(IDP_GROUP, val, ""); IDP_AppendArray(idprop, item); @@ -1287,10 +1277,9 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA } else if(prop->flag & PROP_IDPROPERTY) { IDProperty *group, *item; - IDPropertyTemplate val; - val.i= 0; + IDPropertyTemplate val = {0}; - group= rna_idproperties_get(ptr, 1); + group= RNA_struct_idproperties(ptr, 1); if(group) { idprop= IDP_NewIDPArray(prop->identifier); IDP_AddToGroup(group, idprop); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 3000390fc0f..a29f6c06b17 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -724,6 +724,16 @@ void RNA_def_struct_refine_func(StructRNA *srna, const char *refine) if(refine) srna->refine= (StructRefineFunc)refine; } +void RNA_def_struct_idproperties_func(StructRNA *srna, const char *idproperties) +{ + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_struct_idproperties_func: only during preprocessing.\n"); + return; + } + + if(idproperties) srna->idproperties= (IDPropertiesFunc)idproperties; +} + void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg) { if(!DefRNA.preprocess) { diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index e91489aa6bf..04779c035d0 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -173,7 +173,9 @@ void rna_ID_name_get(struct PointerRNA *ptr, char *value); int rna_ID_name_length(struct PointerRNA *ptr); void rna_ID_name_set(struct PointerRNA *ptr, const char *value); struct StructRNA *rna_ID_refine(struct PointerRNA *ptr); +struct IDProperty *rna_ID_idproperties(struct PointerRNA *ptr, int create); void rna_ID_fake_user_set(struct PointerRNA *ptr, int value); +struct IDProperty *rna_IDPropertyGroup_idproperties(struct PointerRNA *ptr, int create); void rna_object_vgroup_name_index_get(struct PointerRNA *ptr, char *value, int index); int rna_object_vgroup_name_index_length(struct PointerRNA *ptr, int index); @@ -201,7 +203,6 @@ extern FloatPropertyRNA rna_IDProperty_double_array; extern StructRNA RNA_IDProperty; extern StructRNA RNA_IDPropertyGroup; -struct IDProperty *rna_idproperties_get(struct PointerRNA *ptr, int create); struct IDProperty *rna_idproperty_check(struct PropertyRNA **prop, struct PointerRNA *ptr); /* Builtin Property Callbacks */ diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 50a4db8e158..f7292bdce48 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -36,6 +36,7 @@ struct FunctionRNA; struct ReportList; struct CollectionPropertyIterator; struct bContext; +struct IDProperty; #define RNA_MAX_ARRAY 32 @@ -43,6 +44,7 @@ struct bContext; typedef void (*UpdateFunc)(struct bContext *C, struct PointerRNA *ptr); typedef int (*EditableFunc)(struct PointerRNA *ptr); +typedef struct IDProperty* (*IDPropertiesFunc)(struct PointerRNA *ptr, int create); typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr); typedef char *(*StructPathFunc)(struct PointerRNA *ptr); @@ -287,6 +289,9 @@ struct StructRNA { StructRegisterFunc reg; StructUnregisterFunc unreg; + /* callback to get id properties */ + IDPropertiesFunc idproperties; + /* functions of this struct */ ListBase functions; }; diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index f7964ba52ef..5aad710c712 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -41,12 +41,25 @@ #include "BKE_context.h" #include "BKE_depsgraph.h" +#include "BKE_idprop.h" static void rna_Pose_update(bContext *C, PointerRNA *ptr) { DAG_object_flush_update(CTX_data_scene(C), ptr->id.data, OB_RECALC_DATA); } +IDProperty *rna_PoseChannel_idproperties(PointerRNA *ptr, int create) +{ + bPoseChannel *pchan= ptr->data; + + if(create && !pchan->prop) { + IDPropertyTemplate val = {0}; + pchan->prop= IDP_New(IDP_GROUP, val, "RNA_PoseChannel group"); + } + + return pchan->prop; +} + #else /* users shouldn't be editing pose channel data directly -- better to set ipos and let blender calc pose_channel stuff */ @@ -66,6 +79,7 @@ static void rna_def_pose_channel(BlenderRNA *brna) srna= RNA_def_struct(brna, "PoseChannel", NULL); RNA_def_struct_sdna(srna, "bPoseChannel"); RNA_def_struct_ui_text(srna, "Pose Channel", "Channel defining pose data for a bone in a Pose."); + RNA_def_struct_idproperties_func(srna, "rna_PoseChannel_idproperties"); prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "constraints", NULL); diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index f52e27686bb..55a0f67390e 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -177,7 +177,7 @@ static void rna_Struct_properties_next(CollectionPropertyIterator *iter) /* try id properties */ if(!iter->valid) { - group= rna_idproperties_get(&iter->builtin_parent, 0); + group= RNA_struct_idproperties(&iter->builtin_parent, 0); if(group) { rna_iterator_listbase_end(iter); diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index cabecaaf832..c1bccad4ffa 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -33,6 +33,8 @@ #ifdef RNA_RUNTIME +#include "BKE_idprop.h" + static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr) { wmWindowManager *wm= ptr->id.data; @@ -57,6 +59,16 @@ static StructRNA *rna_OperatorProperties_refine(PointerRNA *ptr) return &RNA_OperatorProperties; } +IDProperty *rna_OperatorProperties_idproperties(PointerRNA *ptr, int create) +{ + if(create && !ptr->data) { + IDPropertyTemplate val = {0}; + ptr->data= IDP_New(IDP_GROUP, val, "RNA_OperatorProperties group"); + } + + return ptr->data; +} + static void rna_Operator_name_get(PointerRNA *ptr, char *value) { wmOperator *op= (wmOperator*)ptr->data; @@ -100,6 +112,7 @@ static void rna_def_operator(BlenderRNA *brna) srna= RNA_def_struct(brna, "OperatorProperties", NULL); RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator."); RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine"); + RNA_def_struct_idproperties_func(srna, "rna_OperatorProperties_idproperties"); } static void rna_def_operator_utils(BlenderRNA *brna) |