Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-08-18 05:29:25 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-08-18 05:29:25 +0400
commit4fb19159ea47027bbaf31d379da3d6b0ea0f0f28 (patch)
treeb50c21dd7873b33912516c9f59429afec5a856c7 /source/blender/makesrna
parenta5da26f59d8cd820ca4d27a06028dd6aaee65784 (diff)
2.5: RNA, defining enums, pointers and collections properties is now
possible from python, but it's still work in progress. Pointers and collections are restricted to types derived from IDPropertyGroup (same as for operators), because RNA knows how to allocate/deallocate those. Collections have .add() and .remove(number) functions that can be used. The remove function should be fixed to take an other argument than a number. With the IDPropertyGroup restriction, pointers are more like nested structs. They don't have add(), remove() yet, not sure where to put them. Currently the pointer / nested struct is automatically allocated in the get() function, this needs to be fixed, rule is that RNA get() will not change any data for thread safety. Also, it is only possible to add properties to structs after they have been registered, which needs to be improved as well. Example code: http://www.pasteall.org/7201/python
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h2
-rw-r--r--source/blender/makesrna/RNA_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_ID.c26
-rw-r--r--source/blender/makesrna/intern/rna_access.c36
-rw-r--r--source/blender/makesrna/intern/rna_define.c17
-rw-r--r--source/blender/makesrna/intern/rna_internal.h3
-rw-r--r--source/blender/makesrna/intern/rna_main.c58
-rw-r--r--source/blender/makesrna/intern/rna_render.c2
-rw-r--r--source/blender/makesrna/intern/rna_ui.c6
9 files changed, 104 insertions, 48 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 95c46515204..d5680ac77ba 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -649,7 +649,7 @@ RawPropertyType RNA_property_raw_type(PropertyRNA *prop);
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop);
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop);
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr);
-void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key);
+int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key);
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop);
/* Path
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 72ecf0e7a93..042f7578cf4 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -263,7 +263,7 @@ typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_
typedef int (*StructCallbackFunc)(struct PointerRNA *ptr, struct FunctionRNA *func, ParameterList *list);
typedef void (*StructFreeFunc)(void *data);
typedef struct StructRNA *(*StructRegisterFunc)(const struct bContext *C, struct ReportList *reports, void *data,
- StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free);
+ const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free);
typedef void (*StructUnregisterFunc)(const struct bContext *C, struct StructRNA *type);
typedef struct StructRNA StructRNA;
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index cf3d59f78a0..f6e0a2468c4 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -152,6 +152,30 @@ IDProperty *rna_IDPropertyGroup_idproperties(PointerRNA *ptr, int create)
return ptr->data;
}
+void rna_IDPropertyGroup_unregister(const bContext *C, StructRNA *type)
+{
+ RNA_struct_free(&BLENDER_RNA, type);
+}
+
+StructRNA *rna_IDPropertyGroup_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+{
+ PointerRNA dummyptr;
+
+ /* create dummy pointer */
+ RNA_pointer_create(NULL, &RNA_IDPropertyGroup, NULL, &dummyptr);
+
+ /* validate the python class */
+ if(validate(&dummyptr, data, NULL) != 0)
+ return NULL;
+
+ return RNA_def_struct(&BLENDER_RNA, identifier, "IDPropertyGroup"); // XXX
+}
+
+StructRNA* rna_IDPropertyGroup_refine(PointerRNA *ptr)
+{
+ return ptr->type;
+}
+
#else
static void rna_def_ID_properties(BlenderRNA *brna)
@@ -210,6 +234,8 @@ static void rna_def_ID_properties(BlenderRNA *brna)
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");
+ RNA_def_struct_register_funcs(srna, "rna_IDPropertyGroup_register", "rna_IDPropertyGroup_unregister");
+ RNA_def_struct_refine_func(srna, "rna_IDPropertyGroup_refine");
}
static void rna_def_ID(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 2de59586611..54cde57a54f 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1259,8 +1259,15 @@ PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
else if(pprop->get) {
return pprop->get(ptr);
}
+ else if(prop->flag & PROP_IDPROPERTY) {
+ /* XXX temporary hack to add it automatically, reading should
+ never do any write ops, to ensure thread safety etc .. */
+ RNA_property_pointer_add(ptr, prop);
+ return RNA_property_pointer_get(ptr, prop);
+ }
else {
PointerRNA result;
+
memset(&result, 0, sizeof(result));
return result;
}
@@ -1398,7 +1405,7 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
{
IDProperty *idprop;
- //CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
+ CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
if((idprop=rna_idproperty_check(&prop, ptr))) {
IDPropertyTemplate val = {0};
@@ -1424,7 +1431,6 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
MEM_freeN(item);
}
}
-#if 0
else if(cprop->add){
if(!(cprop->add->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
ParameterList params;
@@ -1433,9 +1439,8 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
RNA_parameter_list_free(&params);
}
}
-#endif
- else
- printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier);
+ /*else
+ printf("RNA_property_collection_add %s.%s: not implemented for this property.\n", ptr->type->identifier, prop->identifier);*/
if(r_ptr) {
if(idprop) {
@@ -1450,10 +1455,10 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
}
}
-void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
+int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
{
IDProperty *idprop;
- //CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
+ CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
if((idprop=rna_idproperty_check(&prop, ptr))) {
IDProperty tmp, *array;
@@ -1472,20 +1477,25 @@ void RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
IDP_ResizeIDPArray(idprop, len-1);
}
+
+ return 1;
}
- else if(prop->flag & PROP_IDPROPERTY);
-#if 0
+ else if(prop->flag & PROP_IDPROPERTY)
+ return 1;
else if(cprop->remove){
if(!(cprop->remove->flag & FUNC_USE_CONTEXT)) { /* XXX check for this somewhere else */
ParameterList params;
- RNA_parameter_list_create(&ptr, cprop->remove);
+ RNA_parameter_list_create(&params, ptr, cprop->remove);
RNA_function_call(NULL, NULL, ptr, cprop->remove, &params);
RNA_parameter_list_free(&params);
}
+
+ return 0;
}
-#endif
- else
- printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);
+ /*else
+ printf("RNA_property_collection_remove %s.%s: only supported for id properties.\n", ptr->type->identifier, prop->identifier);*/
+
+ return 0;
}
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 0861d7d51a0..9bdbc8baed7 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -2419,6 +2419,7 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
EnumPropertyItem *earray;
float *farray;
int *iarray;
+ int a;
if(prop->identifier) prop->identifier= BLI_strdup(prop->identifier);
if(prop->name) prop->name= BLI_strdup(prop->name);
@@ -2452,7 +2453,14 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
earray= MEM_callocN(sizeof(EnumPropertyItem)*(eprop->totitem+1), "RNA_def_property_store"),
memcpy(earray, eprop->item, sizeof(EnumPropertyItem)*(eprop->totitem+1));
eprop->item= earray;
+
+ for(a=0; a<eprop->totitem; a++) {
+ if(eprop->item[a].identifier) eprop->item[a].identifier= BLI_strdup(eprop->item[a].identifier);
+ if(eprop->item[a].name) eprop->item[a].name= BLI_strdup(eprop->item[a].name);
+ if(eprop->item[a].description) eprop->item[a].description= BLI_strdup(eprop->item[a].description);
+ }
}
+ break;
}
case PROP_FLOAT: {
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
@@ -2479,6 +2487,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
void RNA_def_property_free_pointers(PropertyRNA *prop)
{
if(prop->flag & PROP_FREE_POINTERS) {
+ int a;
+
if(prop->identifier) MEM_freeN((void*)prop->identifier);
if(prop->name) MEM_freeN((void*)prop->name);
if(prop->description) MEM_freeN((void*)prop->description);
@@ -2502,6 +2512,13 @@ void RNA_def_property_free_pointers(PropertyRNA *prop)
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
if(eprop->item) MEM_freeN((void*)eprop->item);
+
+ for(a=0; a<eprop->totitem; a++) {
+ if(eprop->item[a].identifier) MEM_freeN((void*)eprop->item[a].identifier);
+ if(eprop->item[a].name) MEM_freeN((void*)eprop->item[a].name);
+ if(eprop->item[a].description) MEM_freeN((void*)eprop->item[a].description);
+ }
+ break;
}
case PROP_STRING: {
StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index a8c7032733f..579441691ff 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -181,6 +181,9 @@ 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_IDPropertyGroup_unregister(const struct bContext *C, struct StructRNA *type);
+struct StructRNA *rna_IDPropertyGroup_register(const struct bContext *C, struct ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free);
+struct StructRNA* rna_IDPropertyGroup_refine(struct PointerRNA *ptr);
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);
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index 26fc3c2941e..c09b83dd682 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -220,34 +220,34 @@ void RNA_def_main(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
- const char *lists[][5]= {
- {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks."},
- {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks."},
- {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks."},
- {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks."},
- {"nodetrees", "NodeTree", "rna_Main_nodetree_begin", "Node Trees", "Nodetree datablocks."},
- {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks."},
- {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."},
- {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."},
- {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks."},
- {"windowmanagers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks."},
- {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks."},
- {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks."},
- {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks."},
- {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks."},
- {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks."},
- {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks."},
- {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks."},
- {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks."},
- {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks."},
- {"keys", "ID", "rna_Main_key_begin", "Keys", "Key datablocks."},
- {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks."},
- {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks."},
- {"sounds", "ID", "rna_Main_sound_begin", "Sounds", "Sound datablocks."},
- {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks."},
- {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks."},
- {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks."},
- {NULL, NULL, NULL, NULL, NULL}};
+ const char *lists[][7]= {
+ {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks.", NULL, NULL},
+ {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks.", NULL, NULL},
+ {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks.", NULL, NULL},
+ {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks.", NULL, NULL},
+ {"nodetrees", "NodeTree", "rna_Main_nodetree_begin", "Node Trees", "Nodetree datablocks.", NULL, NULL},
+ {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks.", "add_mesh", "remove_mesh"},
+ {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks.", NULL, NULL},
+ {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks.", NULL, NULL},
+ {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks.", NULL, NULL},
+ {"windowmanagers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks.", NULL, NULL},
+ {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks.", NULL, NULL},
+ {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks.", NULL, NULL},
+ {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks.", NULL, NULL} ,
+ {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks.", NULL, NULL},
+ {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks.", NULL, NULL},
+ {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks.", NULL, NULL},
+ {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", NULL, NULL},
+ {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", NULL, NULL},
+ {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks.", NULL, NULL},
+ {"keys", "ID", "rna_Main_key_begin", "Keys", "Key datablocks.", NULL, NULL},
+ {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks.", NULL, NULL},
+ {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks.", NULL, NULL},
+ {"sounds", "ID", "rna_Main_sound_begin", "Sounds", "Sound datablocks.", NULL, NULL},
+ {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks.", NULL, NULL},
+ {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks.", NULL, NULL},
+ {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks.", NULL, NULL},
+ {NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
int i;
srna= RNA_def_struct(brna, "Main", NULL);
@@ -264,7 +264,7 @@ void RNA_def_main(BlenderRNA *brna)
{
prop= RNA_def_property(srna, lists[i][0], PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, lists[i][1]);
- RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0);
+ RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, lists[i][5], lists[i][6]);
RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]);
}
diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c
index a219bd5aefa..9137e596da1 100644
--- a/source/blender/makesrna/intern/rna_render.c
+++ b/source/blender/makesrna/intern/rna_render.c
@@ -111,7 +111,7 @@ static void rna_RenderEngine_unregister(const bContext *C, StructRNA *type)
RNA_struct_free(&BLENDER_RNA, type);
}
-static StructRNA *rna_RenderEngine_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+static StructRNA *rna_RenderEngine_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
RenderEngineType *et, dummyet = {0};
RenderEngine dummyengine= {0};
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index 660dbb49027..f16180451a7 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -148,7 +148,7 @@ static void rna_Panel_unregister(const bContext *C, StructRNA *type)
WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
}
-static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
ARegionType *art;
PanelType *pt, dummypt = {0};
@@ -245,7 +245,7 @@ static void rna_Header_unregister(const bContext *C, StructRNA *type)
WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
}
-static StructRNA *rna_Header_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+static StructRNA *rna_Header_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
ARegionType *art;
HeaderType *ht, dummyht = {0};
@@ -361,7 +361,7 @@ static void rna_Menu_unregister(const bContext *C, StructRNA *type)
WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL);
}
-static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+static StructRNA *rna_Menu_register(const bContext *C, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
ARegionType *art;
MenuType *mt, dummymt = {0};