diff options
39 files changed, 1220 insertions, 756 deletions
diff --git a/release/ui/buttons_objects.py b/release/ui/buttons_objects.py index a8cfa40f253..9c1efacf10a 100644 --- a/release/ui/buttons_objects.py +++ b/release/ui/buttons_objects.py @@ -1,9 +1,15 @@ + import bpy -class OBJECT_PT_transform(bpy.types.Panel): - __label__ = "Transform" +class ObjectButtonsPanel(bpy.types.Panel): + __space_type__ = "BUTTONS_WINDOW" + __region_type__ = "WINDOW" __context__ = "object" +class OBJECT_PT_transform(ObjectButtonsPanel): + __idname__ = "OBJECT_PT_transform" + __label__ = "Transform" + def draw(self, context): ob = context.active_object layout = self.layout @@ -16,9 +22,9 @@ class OBJECT_PT_transform(bpy.types.Panel): layout.itemR(ob, "rotation") layout.itemR(ob, "scale") -class OBJECT_PT_groups(bpy.types.Panel): +class OBJECT_PT_groups(ObjectButtonsPanel): + __idname__ = "OBJECT_PT_groups" __label__ = "Groups" - __context__ = "object" def draw(self, context): ob = context.active_object @@ -46,9 +52,9 @@ class OBJECT_PT_groups(bpy.types.Panel): sub.itemR(group, "layer") sub.itemR(group, "dupli_offset") -class OBJECT_PT_display(bpy.types.Panel): +class OBJECT_PT_display(ObjectButtonsPanel): + __idname__ = "OBJECT_PT_display" __label__ = "Display" - __context__ = "object" def draw(self, context): ob = context.active_object @@ -69,9 +75,9 @@ class OBJECT_PT_display(bpy.types.Panel): layout.itemR(ob, "x_ray", text="X-Ray") layout.itemR(ob, "draw_transparent", text="Transparency") -class OBJECT_PT_duplication(bpy.types.Panel): +class OBJECT_PT_duplication(ObjectButtonsPanel): + __idname__ = "OBJECT_PT_duplication" __label__ = "Duplication" - __context__ = "object" def draw(self, context): ob = context.active_object @@ -90,9 +96,9 @@ class OBJECT_PT_duplication(bpy.types.Panel): layout.itemR(ob, "dupli_frames_on", text="On:") layout.itemR(ob, "dupli_frames_off", text="Off:") -class OBJECT_PT_animation(bpy.types.Panel): +class OBJECT_PT_animation(ObjectButtonsPanel): + __idname__ = "OBJECT_PT_animation" __label__ = "Animation" - __context__ = "object" def draw(self, context): ob = context.active_object @@ -119,9 +125,9 @@ class OBJECT_PT_animation(bpy.types.Panel): sub.itemR(ob, "up_axis", text="Up Axis") sub.itemR(ob, "track_rotation", text="Rotation") -bpy.ui.addPanel(OBJECT_PT_transform, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(OBJECT_PT_groups, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(OBJECT_PT_display, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(OBJECT_PT_duplication, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(OBJECT_PT_animation, "BUTTONS_WINDOW", "WINDOW") +bpy.types.register(OBJECT_PT_transform) +bpy.types.register(OBJECT_PT_groups) +bpy.types.register(OBJECT_PT_display) +bpy.types.register(OBJECT_PT_duplication) +bpy.types.register(OBJECT_PT_animation) diff --git a/release/ui/buttons_scene.py b/release/ui/buttons_scene.py index 21fe503f840..52f9560a061 100644 --- a/release/ui/buttons_scene.py +++ b/release/ui/buttons_scene.py @@ -1,10 +1,14 @@ import bpy -class RENDER_PT_shading(bpy.types.Panel): - __label__ = "Shading" +class RenderButtonsPanel(bpy.types.Panel): + __space_type__ = "BUTTONS_WINDOW" + __region_type__ = "WINDOW" __context__ = "render" +class RENDER_PT_shading(RenderButtonsPanel): + __label__ = "Shading" + def draw(self, context): scene = context.scene layout = self.layout @@ -25,7 +29,7 @@ class RENDER_PT_shading(bpy.types.Panel): layout.row() layout.itemR(rd, "alpha_mode") -class RENDER_PT_image(bpy.types.Panel): +class RENDER_PT_image(RenderButtonsPanel): __label__ = "Image" __context__ = "render" @@ -47,7 +51,7 @@ class RENDER_PT_image(bpy.types.Panel): layout.row() layout.itemR(rd, "crop_to_border") -class RENDER_PT_antialiasing(bpy.types.Panel): +class RENDER_PT_antialiasing(RenderButtonsPanel): __label__ = "Anti-Aliasing" __context__ = "render" @@ -66,7 +70,7 @@ class RENDER_PT_antialiasing(bpy.types.Panel): layout.itemR(rd, "pixel_filter") layout.itemR(rd, "filter_size") -class RENDER_PT_render(bpy.types.Panel): +class RENDER_PT_render(RenderButtonsPanel): __label__ = "Render" __context__ = "render" @@ -118,8 +122,8 @@ class RENDER_PT_render(bpy.types.Panel): layout.itemR(rd, "border", text="Border Render") layout.itemR(rd, "panorama") -bpy.ui.addPanel(RENDER_PT_shading, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(RENDER_PT_image, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(RENDER_PT_antialiasing, "BUTTONS_WINDOW", "WINDOW") -bpy.ui.addPanel(RENDER_PT_render, "BUTTONS_WINDOW", "WINDOW") +bpy.types.register(RENDER_PT_shading) +bpy.types.register(RENDER_PT_image) +bpy.types.register(RENDER_PT_antialiasing) +bpy.types.register(RENDER_PT_render) diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index e43b2b3b737..fb0c65b3cf9 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -45,6 +45,9 @@ struct wmWindowManager; struct uiLayout; struct uiMenuItem; struct StructRNA; +struct PointerRNA; +struct FunctionRNA; +struct ParameterList; /* spacetype has everything stored to get an editor working, it gets initialized via ED_spacetypes_init() in editors/area/spacetypes.c */ @@ -143,18 +146,22 @@ typedef struct ARegionType { typedef struct PanelType { struct PanelType *next, *prev; - char *idname; /* unique name */ - char *name; /* for panel header */ - char *context; /* for buttons window */ + char idname[BKE_ST_MAXNAME]; /* unique name */ + char label[BKE_ST_MAXNAME]; /* for panel header */ + char context[BKE_ST_MAXNAME]; /* for buttons window */ + char space_type[BKE_ST_MAXNAME]; + char region_type[BKE_ST_MAXNAME]; /* verify if the panel should draw or not */ - int (*poll)(const struct bContext *); + int (*poll)(const struct bContext *, struct PanelType *); /* draw entirely, view changes should be handled here */ void (*draw)(const struct bContext *, struct Panel *); /* python integration */ void *py_data; - struct StructRNA *srna; + struct StructRNA *py_srna; + int (*py_call)(struct PointerRNA *, struct FunctionRNA *, struct ParameterList *); + void (*py_free)(void *py_data); } PanelType; /* header types */ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 1d819b7de8b..5b10f921d7d 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -377,22 +377,22 @@ static short animsys_write_rna_setting (PointerRNA *ptr, char *path, int array_i /* set value - only for animatable numerical values */ if (RNA_property_animateable(&new_ptr, prop)) { - switch (RNA_property_type(&new_ptr, prop)) + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (RNA_property_array_length(&new_ptr, prop)) + if (RNA_property_array_length(prop)) RNA_property_boolean_set_index(&new_ptr, prop, array_index, (int)value); else RNA_property_boolean_set(&new_ptr, prop, (int)value); break; case PROP_INT: - if (RNA_property_array_length(&new_ptr, prop)) + if (RNA_property_array_length(prop)) RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value); else RNA_property_int_set(&new_ptr, prop, (int)value); break; case PROP_FLOAT: - if (RNA_property_array_length(&new_ptr, prop)) + if (RNA_property_array_length(prop)) RNA_property_float_set_index(&new_ptr, prop, array_index, value); else RNA_property_float_set(&new_ptr, prop, value); diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index d7b1bdaeff3..cce4f3a1217 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -679,21 +679,21 @@ static float driver_get_target_value (ChannelDriver *driver, DriverTarget *dtar) /* get property to read from, and get value as appropriate */ if (RNA_path_resolve(&id_ptr, path, &ptr, &prop)) { - switch (RNA_property_type(&ptr, prop)) { + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (RNA_property_array_length(&ptr, prop)) + if (RNA_property_array_length(prop)) value= (float)RNA_property_boolean_get_index(&ptr, prop, index); else value= (float)RNA_property_boolean_get(&ptr, prop); break; case PROP_INT: - if (RNA_property_array_length(&ptr, prop)) + if (RNA_property_array_length(prop)) value= (float)RNA_property_int_get_index(&ptr, prop, index); else value= (float)RNA_property_int_get(&ptr, prop); break; case PROP_FLOAT: - if (RNA_property_array_length(&ptr, prop)) + if (RNA_property_array_length(prop)) value= RNA_property_float_get_index(&ptr, prop, index); else value= RNA_property_float_get(&ptr, prop); diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 2f3ca52a09e..f43dc287062 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -53,25 +53,16 @@ static ListBase spacetypes= {NULL, NULL}; static void spacetype_free(SpaceType *st) { ARegionType *art; + PanelType *pt; for(art= st->regiontypes.first; art; art= art->next) { BLI_freelistN(&art->drawcalls); -#ifdef DISABLE_PYTHON + + for(pt= art->paneltypes.first; pt; pt= pt->next) + if(pt->py_free) + pt->py_free(pt->py_data); + BLI_freelistN(&art->paneltypes); -#else - { - PanelType *pnl, *pnl_next; - for(pnl= art->paneltypes.first; pnl; pnl= pnl_next) { - pnl_next= pnl->next; - - if(pnl->py_data) - BPY_DECREF(pnl->py_data); - - MEM_freeN(pnl); - } - art->paneltypes.first= art->paneltypes.last= NULL; - } -#endif BLI_freelistN(&art->headertypes); } diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index 3d55a048d5f..137a32c4689 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -848,6 +848,12 @@ char *BLI_gethome_folder(char *folder_name) char *s; int i; + /* use argv[0] (bprogname) to get the path to the executable */ + s = BLI_last_slash(bprogname); + + i = s - bprogname + 1; + BLI_strncpy(bprogdir, bprogname, i); + /* try path_to_executable/release/folder_name (in svn) */ if (folder_name) { BLI_snprintf(tmpdir, sizeof(tmpdir), "release/%s", folder_name); @@ -889,16 +895,6 @@ char *BLI_gethome_folder(char *folder_name) else homedir[0] = '\0'; - /* if either: - * no homedir was found or - * folder_name = 1 but there's no folder_name/ inside homedir, - * use argv[0] (bprogname) to get .blender/ in - * Blender's installation dir */ - s = BLI_last_slash(bprogname); - - i = s - bprogname + 1; - BLI_strncpy(bprogdir, bprogname, i); - /* using tmpdir to preserve homedir (if) found above: * the ideal is to have a home dir with folder_name dir inside * it, but if that isn't available, it's possible to diff --git a/source/blender/editors/animation/anim_ipo_utils.c b/source/blender/editors/animation/anim_ipo_utils.c index ae0b8435635..4d4079a260a 100644 --- a/source/blender/editors/animation/anim_ipo_utils.c +++ b/source/blender/editors/animation/anim_ipo_utils.c @@ -135,19 +135,19 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu) /* for structname, we use a custom name if one is available */ // xxx we might want an icon from types? // xxx it is hard to differentiate between object and bone channels then, if ob + bone motion occur together... - nameprop= RNA_struct_name_property(&ptr); + nameprop= RNA_struct_name_property(ptr.type); if (nameprop) { /* this gets a string which will need to be freed */ structname= RNA_property_string_get_alloc(&ptr, nameprop, NULL, 0); } else - structname= (char *)RNA_struct_ui_name(&ptr); + structname= (char *)RNA_struct_ui_name(ptr.type); /* Property Name is straightforward */ - propname= (char *)RNA_property_ui_name(&ptr, prop); + propname= (char *)RNA_property_ui_name(prop); /* Array Index - only if applicable */ - if (RNA_property_array_length(&ptr, prop)) { + if (RNA_property_array_length(prop)) { // XXX the format of these is not final... we don't know how this will go yet // format 1 style //static char *vectoritem[4]= {".X", ".Y", ".Z", ".W"}; @@ -158,8 +158,8 @@ void getname_anim_fcurve(char *name, ID *id, FCurve *fcu) static char *quatitem[4]= {"W ", "X ", "Y ", "Z "}; static char *coloritem[4]= {"R ", "G ", "B ", "A "}; - int tot= RNA_property_array_length(&ptr, prop); - int propsubtype= RNA_property_subtype(&ptr, prop); + int tot= RNA_property_array_length(prop); + int propsubtype= RNA_property_subtype(prop); /* get string to use for array index */ if ((tot == 4) && (propsubtype == PROP_ROTATION)) diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c index ef8ac517e54..9c401289011 100644 --- a/source/blender/editors/animation/drivers.c +++ b/source/blender/editors/animation/drivers.c @@ -183,7 +183,7 @@ static int add_driver_button_exec (bContext *C, wmOperator *op) if (path) { if (all) { - length= RNA_property_array_length(&ptr, prop); + length= RNA_property_array_length(prop); if (length) index= 0; else length= 1; @@ -245,7 +245,7 @@ static int remove_driver_button_exec (bContext *C, wmOperator *op) if (path) { if (all) { - length= RNA_property_array_length(&ptr, prop); + length= RNA_property_array_length(prop); if(length) index= 0; else length= 1; diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 0a911f2281a..c341e32db8c 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -473,21 +473,21 @@ static float setting_get_rna_value (PointerRNA *ptr, PropertyRNA *prop, int inde { float value= 0.0f; - switch (RNA_property_type(ptr, prop)) { + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: - if (RNA_property_array_length(ptr, prop)) + if (RNA_property_array_length(prop)) value= (float)RNA_property_boolean_get_index(ptr, prop, index); else value= (float)RNA_property_boolean_get(ptr, prop); break; case PROP_INT: - if (RNA_property_array_length(ptr, prop)) + if (RNA_property_array_length(prop)) value= (float)RNA_property_int_get_index(ptr, prop, index); else value= (float)RNA_property_int_get(ptr, prop); break; case PROP_FLOAT: - if (RNA_property_array_length(ptr, prop)) + if (RNA_property_array_length(prop)) value= RNA_property_float_get_index(ptr, prop, index); else value= RNA_property_float_get(ptr, prop); @@ -538,14 +538,14 @@ static short visualkey_can_use (PointerRNA *ptr, PropertyRNA *prop) Object *ob= (Object *)ptr->data; con= ob->constraints.first; - identifier= (char *)RNA_property_identifier(ptr, prop); + identifier= (char *)RNA_property_identifier(prop); } else if (ptr->type == &RNA_PoseChannel) { /* Pose Channel */ bPoseChannel *pchan= (bPoseChannel *)ptr->data; con= pchan->constraints.first; - identifier= (char *)RNA_property_identifier(ptr, prop); + identifier= (char *)RNA_property_identifier(prop); } /* check if any data to search using */ @@ -624,7 +624,7 @@ static short visualkey_can_use (PointerRNA *ptr, PropertyRNA *prop) */ static float visualkey_get_value (PointerRNA *ptr, PropertyRNA *prop, int array_index) { - char *identifier= (char *)RNA_property_identifier(ptr, prop); + char *identifier= (char *)RNA_property_identifier(prop); /* handle for Objects or PoseChannels only * - constraints can be on either Objects or PoseChannels, so we only check if the @@ -726,7 +726,7 @@ short insert_keyframe (ID *id, bAction *act, const char group[], const char rna_ float curval= 0.0f; /* set additional flags for the F-Curve (i.e. only integer values) */ - if (RNA_property_type(&ptr, prop) != PROP_FLOAT) + if (RNA_property_type(prop) != PROP_FLOAT) fcu->flag |= FCURVE_INT_VALUES; /* apply special time tweaking */ @@ -1201,12 +1201,12 @@ static int insert_key_button_exec (bContext *C, wmOperator *op) memset(&ptr, 0, sizeof(PointerRNA)); uiAnimContextProperty(C, &ptr, &prop, &index); - if(ptr.data && prop && RNA_property_animateable(ptr.data, prop)) { + if(ptr.data && prop && RNA_property_animateable(&ptr, prop)) { path= RNA_path_from_ID_to_property(&ptr, prop); if(path) { if(all) { - length= RNA_property_array_length(&ptr, prop); + length= RNA_property_array_length(prop); if(length) index= 0; else length= 1; @@ -1270,7 +1270,7 @@ static int delete_key_button_exec (bContext *C, wmOperator *op) if(path) { if(all) { - length= RNA_property_array_length(&ptr, prop); + length= RNA_property_array_length(prop); if(length) index= 0; else length= 1; diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index adc0b744d53..0f5cef51bdb 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -1031,7 +1031,7 @@ int modify_keyframes (bContext *C, ListBase *dsources, bAction *act, KeyingSet * RNA_id_pointer_create(ksp->id, &id_ptr); if (RNA_path_resolve(&id_ptr, ksp->rna_path, &ptr, &prop) && prop) - arraylen= RNA_property_array_length(&ptr, prop); + arraylen= RNA_property_array_length(prop); } /* for each possible index, perform operation @@ -1133,7 +1133,7 @@ int modify_keyframes (bContext *C, ListBase *dsources, bAction *act, KeyingSet * RNA_id_pointer_create(cks->id, &id_ptr); if (RNA_path_resolve(&id_ptr, path, &ptr, &prop) && prop) - arraylen= RNA_property_array_length(&ptr, prop); + arraylen= RNA_property_array_length(prop); } /* for each possible index, perform operation diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 47c73c3398d..eb4bd5f940b 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -1127,8 +1127,8 @@ void ui_get_but_vectorf(uiBut *but, float *vec) vec[0]= vec[1]= vec[2]= 0.0f; - if(RNA_property_type(&but->rnapoin, prop) == PROP_FLOAT) { - tot= RNA_property_array_length(&but->rnapoin, prop); + if(RNA_property_type(prop) == PROP_FLOAT) { + tot= RNA_property_array_length(prop); tot= MIN2(tot, 3); for(a=0; a<tot; a++) @@ -1161,8 +1161,8 @@ void ui_set_but_vectorf(uiBut *but, float *vec) if(but->rnaprop) { prop= but->rnaprop; - if(RNA_property_type(&but->rnapoin, prop) == PROP_FLOAT) { - tot= RNA_property_array_length(&but->rnapoin, prop); + if(RNA_property_type(prop) == PROP_FLOAT) { + tot= RNA_property_array_length(prop); tot= MIN2(tot, 3); for(a=0; a<tot; a++) @@ -1186,7 +1186,7 @@ int ui_is_but_float(uiBut *but) if(but->pointype==FLO && but->poin) return 1; - if(but->rnaprop && RNA_property_type(&but->rnapoin, but->rnaprop) == PROP_FLOAT) + if(but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT) return 1; return 0; @@ -1203,21 +1203,21 @@ double ui_get_but_val(uiBut *but) if(but->rnaprop) { prop= but->rnaprop; - switch(RNA_property_type(&but->rnapoin, prop)) { + switch(RNA_property_type(prop)) { case PROP_BOOLEAN: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_length(prop)) value= RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex); else value= RNA_property_boolean_get(&but->rnapoin, prop); break; case PROP_INT: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_length(prop)) value= RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex); else value= RNA_property_int_get(&but->rnapoin, prop); break; case PROP_FLOAT: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_length(prop)) value= RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex); else value= RNA_property_float_get(&but->rnapoin, prop); @@ -1267,21 +1267,21 @@ void ui_set_but_val(uiBut *but, double value) prop= but->rnaprop; if(RNA_property_editable(&but->rnapoin, prop)) { - switch(RNA_property_type(&but->rnapoin, prop)) { + switch(RNA_property_type(prop)) { case PROP_BOOLEAN: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_length(prop)) RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value); else RNA_property_boolean_set(&but->rnapoin, prop, value); break; case PROP_INT: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_length(prop)) RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, value); else RNA_property_int_set(&but->rnapoin, prop, value); break; case PROP_FLOAT: - if(RNA_property_array_length(&but->rnapoin, prop)) + if(RNA_property_array_length(prop)) RNA_property_float_set_index(&but->rnapoin, prop, but->rnaindex, value); else RNA_property_float_set(&but->rnapoin, prop, value); @@ -1364,7 +1364,7 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen) PropertyType type; char *buf= NULL; - type= RNA_property_type(&but->rnapoin, but->rnaprop); + type= RNA_property_type(but->rnaprop); if(type == PROP_STRING) { /* RNA string */ @@ -1375,7 +1375,7 @@ void ui_get_but_string(uiBut *but, char *str, int maxlen) PointerRNA ptr= RNA_property_pointer_get(&but->rnapoin, but->rnaprop); PropertyRNA *nameprop; - if(ptr.data && (nameprop = RNA_struct_name_property(&ptr))) + if(ptr.data && (nameprop = RNA_struct_name_property(ptr.type))) buf= RNA_property_string_get_alloc(&ptr, nameprop, str, maxlen); else BLI_strncpy(str, "", maxlen); @@ -1433,7 +1433,7 @@ static void ui_rna_ID_collection(bContext *C, uiBut *but, PointerRNA *ptr, Prope /* look for collection property in Main */ RNA_pointer_create(NULL, &RNA_Main, CTX_data_main(C), ptr); - iterprop= RNA_struct_iterator_property(ptr); + iterprop= RNA_struct_iterator_property(ptr->type); RNA_property_collection_begin(ptr, iterprop, &iter); *prop= NULL; @@ -1441,10 +1441,10 @@ static void ui_rna_ID_collection(bContext *C, uiBut *but, PointerRNA *ptr, Prope iprop= iter.ptr.data; /* if it's a collection and has same pointer type, we've got it */ - if(RNA_property_type(ptr, iprop) == PROP_COLLECTION) { - srna= RNA_property_pointer_type(ptr, iprop); + if(RNA_property_type(iprop) == PROP_COLLECTION) { + srna= RNA_property_pointer_type(iprop); - if(RNA_property_pointer_type(&but->rnapoin, but->rnaprop) == srna) { + if(RNA_property_pointer_type(but->rnaprop) == srna) { *prop= iprop; break; } @@ -1475,7 +1475,7 @@ static void ui_rna_ID_autocomplete(bContext *C, char *str, void *arg_but) /* loop over items in collection */ for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) { + if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { name= RNA_property_string_get_alloc(&iter.ptr, nameprop, NULL, 0); if(name) { @@ -1496,7 +1496,7 @@ int ui_set_but_string(bContext *C, uiBut *but, const char *str) if(RNA_property_editable(&but->rnapoin, but->rnaprop)) { PropertyType type; - type= RNA_property_type(&but->rnapoin, but->rnaprop); + type= RNA_property_type(but->rnaprop); if(type == PROP_STRING) { /* RNA string */ @@ -1593,7 +1593,7 @@ void ui_set_but_soft_range(uiBut *but, double value) double softmin, softmax, step, precision; if(but->rnaprop) { - type= RNA_property_type(&but->rnapoin, but->rnaprop); + type= RNA_property_type(but->rnaprop); if(type == PROP_INT) { int imin, imax, istep; @@ -1885,7 +1885,7 @@ void ui_check_but(uiBut *but) } if(but->rnaprop) { - PropertySubType pstype = RNA_property_subtype(&but->rnapoin, but->rnaprop); + PropertySubType pstype = RNA_property_subtype(but->rnaprop); if (pstype == PROP_PERCENTAGE) strcat(but->drawstr, "%"); @@ -2243,7 +2243,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, prop= RNA_struct_find_property(ptr, propname); if(prop) { - proptype= RNA_property_type(ptr, prop); + proptype= RNA_property_type(prop); /* use rna values if parameters are not specified */ if(!str) { @@ -2255,7 +2255,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, RNA_property_enum_items(ptr, prop, &item, &totitem); dynstr= BLI_dynstr_new(); - BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(ptr, prop)); + BLI_dynstr_appendf(dynstr, "%s%%t", RNA_property_ui_name(prop)); for(i=0; i<totitem; i++) BLI_dynstr_appendf(dynstr, "|%s %%x%d", item[i].name, item[i].value); str= BLI_dynstr_get_cstring(dynstr); @@ -2273,10 +2273,10 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, str= (char*)item[i].name; if(!str) - str= (char*)RNA_property_ui_name(ptr, prop); + str= (char*)RNA_property_ui_name(prop); } else - str= (char*)RNA_property_ui_name(ptr, prop); + str= (char*)RNA_property_ui_name(prop); } if(!tip) { @@ -2297,7 +2297,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, } if(!tip) - tip= (char*)RNA_property_ui_description(ptr, prop); + tip= (char*)RNA_property_ui_description(prop); if(min == max || a1 == -1 || a2 == -1) { if(proptype == PROP_INT) { @@ -2332,7 +2332,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, } else if(proptype == PROP_STRING) { min= 0; - max= RNA_property_string_maxlength(ptr, prop); + max= RNA_property_string_maxlength(prop); if(max == 0) /* interface code should ideally support unlimited length */ max= UI_MAX_DRAW_STR; } @@ -2348,7 +2348,7 @@ uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, char *str, short x1, but->rnapoin= *ptr; but->rnaprop= prop; - if(RNA_property_array_length(&but->rnapoin, but->rnaprop)) + if(RNA_property_array_length(but->rnaprop)) but->rnaindex= index; else but->rnaindex= 0; @@ -2767,7 +2767,7 @@ uiBut *uiDefMenuTogR(uiBlock *block, PointerRNA *ptr, char *propname, char *prop prop= RNA_struct_find_property(ptr, propname); if(prop) { - type= RNA_property_type(ptr, prop); + type= RNA_property_type(prop); if(type == PROP_BOOLEAN) { if(RNA_property_boolean_get(ptr, prop)) diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 3b89fbddebc..6775a639597 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -118,9 +118,9 @@ void ui_but_anim_menu(bContext *C, uiBut *but) int length; if(but->rnapoin.data && but->rnaprop) { - head= uiPupMenuBegin(RNA_property_ui_name(&but->rnapoin, but->rnaprop), 0); + head= uiPupMenuBegin(RNA_property_ui_name(but->rnaprop), 0); - length= RNA_property_array_length(&but->rnapoin, but->rnaprop); + length= RNA_property_array_length(but->rnaprop); if(but->flag & UI_BUT_ANIMATED_KEY) { if(length) { diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 795483ac177..7d27934f691 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -191,14 +191,14 @@ static void ui_item_array(uiBlock *block, uiItemRNA *rnaitem, int len, int x, in int a; /* retrieve type and subtype */ - type= RNA_property_type(&rnaitem->ptr, rnaitem->prop); - subtype= RNA_property_subtype(&rnaitem->ptr, rnaitem->prop); + type= RNA_property_type(rnaitem->prop); + subtype= RNA_property_subtype(rnaitem->prop); /* create label */ if(rnaitem->item.name) name= (char*)rnaitem->item.name; else - name= (char*)RNA_property_ui_name(&rnaitem->ptr, rnaitem->prop); + name= (char*)RNA_property_ui_name(rnaitem->prop); if(strcmp(name, "") != 0) uiDefBut(block, LABEL, 0, name, x, y + h - EM_UNIT_Y, w, EM_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); @@ -289,7 +289,7 @@ static void ui_item_enum_row(uiBlock *block, uiItemRNA *rnaitem, int x, int y, i int a, totitem, pos, itemw; const char *propname; - propname= RNA_property_identifier(&rnaitem->ptr, rnaitem->prop); + propname= RNA_property_identifier(rnaitem->prop); RNA_property_enum_items(&rnaitem->ptr, rnaitem->prop, &item, &totitem); uiBlockBeginAlign(block); @@ -310,7 +310,7 @@ static void ui_item_with_label(uiBlock *block, uiItemRNA *rnaitem, int x, int y, if(rnaitem->item.name) name= (char*)rnaitem->item.name; else - name= (char*)RNA_property_ui_name(&rnaitem->ptr, rnaitem->prop); + name= (char*)RNA_property_ui_name(rnaitem->prop); if(strcmp(name, "") != 0) { w= w/2; @@ -331,8 +331,8 @@ static void ui_item_buts(uiBlock *block, uiItem *item, int x, int y, int w, int int len; /* retrieve info */ - type= RNA_property_type(&rnaitem->ptr, rnaitem->prop); - len= RNA_property_array_length(&rnaitem->ptr, rnaitem->prop); + type= RNA_property_type(rnaitem->prop); + len= RNA_property_array_length(rnaitem->prop); /* array property */ if(rnaitem->index == RNA_NO_INDEX && len > 0) @@ -416,9 +416,9 @@ static void ui_item_size(uiItem *item, int *r_w, int *r_h) h= EM_UNIT_Y; /* arbitrary extended width by type */ - type= RNA_property_type(&rnaitem->ptr, rnaitem->prop); - subtype= RNA_property_subtype(&rnaitem->ptr, rnaitem->prop); - len= RNA_property_array_length(&rnaitem->ptr, rnaitem->prop); + type= RNA_property_type(rnaitem->prop); + subtype= RNA_property_subtype(rnaitem->prop); + len= RNA_property_array_length(rnaitem->prop); if(type == PROP_STRING) w += 10*EM_UNIT_X; @@ -506,7 +506,7 @@ void uiItemsEnumO(uiLayout *layout, char *opname, char *propname) RNA_pointer_create(NULL, ot->srna, NULL, &ptr); prop= RNA_struct_find_property(&ptr, propname); - if(prop && RNA_property_type(&ptr, prop) == PROP_ENUM) { + if(prop && RNA_property_type(prop) == PROP_ENUM) { const EnumPropertyItem *item; int totitem, i; @@ -1214,7 +1214,7 @@ void uiRegionPanelLayout(const bContext *C, ARegion *ar, int vertical, char *con if(!pt->context || strcmp(context, pt->context) != 0) continue; - if(pt->draw && (!pt->poll || pt->poll(C))) { + if(pt->draw && (!pt->poll || pt->poll(C, pt))) { block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS); panel= uiBeginPanel(ar, block, pt); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 42033a40624..7d1f8d59552 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -158,8 +158,8 @@ static void ui_panel_copy_offset(Panel *pa, Panel *papar) Panel *uiBeginPanel(ARegion *ar, uiBlock *block, PanelType *pt) { Panel *pa, *patab, *palast, *panext; - char *panelname= pt->name; - char *tabname= pt->name; + char *panelname= pt->label; + char *tabname= pt->label; char *hookname= NULL; int newpanel; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 47afd03d051..73fdb7fd83c 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -1861,7 +1861,7 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, else if(item->type==MENU_ITEM_RNA_BOOL) { PropertyRNA *prop= RNA_struct_find_property(&item->rnapoin, item->propname); - if(prop && RNA_property_type(&item->rnapoin, prop) == PROP_BOOLEAN) { + if(prop && RNA_property_type(prop) == PROP_BOOLEAN) { icon= (RNA_property_boolean_get(&item->rnapoin, prop))? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; uiDefIconTextButR(block, TOG, 0, icon, NULL, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &item->rnapoin, item->propname, 0, 0, 0, 0, 0, NULL); } @@ -1876,7 +1876,7 @@ static uiBlock *ui_block_func_MENU_ITEM(bContext *C, uiPopupBlockHandle *handle, else if(item->type==MENU_ITEM_RNA_ENUM) { PropertyRNA *prop= RNA_struct_find_property(&item->rnapoin, item->propname); - if(prop && RNA_property_type(&item->rnapoin, prop) == PROP_ENUM) { + if(prop && RNA_property_type(prop) == PROP_ENUM) { icon= (RNA_property_enum_get(&item->rnapoin, prop) == item->enumval)? ICON_CHECKBOX_HLT: ICON_CHECKBOX_DEHLT; uiDefIconTextButR(block, ROW, 0, icon, NULL, x1, y1, width+16, MENU_BUTTON_HEIGHT-1, &item->rnapoin, item->propname, 0, 0, item->enumval, 0, 0, NULL); } @@ -2074,7 +2074,7 @@ void uiMenuItemsEnumO(uiMenuItem *head, char *opname, char *propname) RNA_pointer_create(NULL, ot->srna, NULL, &ptr); prop= RNA_struct_find_property(&ptr, propname); - if(prop && RNA_property_type(&ptr, prop) == PROP_ENUM) { + if(prop && RNA_property_type(prop) == PROP_ENUM) { const EnumPropertyItem *item; int totitem, i; @@ -2112,7 +2112,7 @@ void uiMenuItemsEnumR(uiMenuItem *head, PointerRNA *ptr, char *propname) prop= RNA_struct_find_property(ptr, propname); - if(prop && RNA_property_type(ptr, prop) == PROP_ENUM) { + if(prop && RNA_property_type(prop) == PROP_ENUM) { const EnumPropertyItem *item; int totitem, i; @@ -2156,7 +2156,7 @@ void uiMenuLevelEnumR(uiMenuItem *head, PointerRNA *ptr, char *propname) item->type = MENU_ITEM_LEVEL_RNA_ENUM; prop= RNA_struct_find_property(ptr, propname); if(prop) - BLI_strncpy(item->name, RNA_property_ui_name(ptr, prop), MAX_MENU_STR); + BLI_strncpy(item->name, RNA_property_ui_name(prop), MAX_MENU_STR); item->rnapoin= *ptr; item->propname= propname; // static! diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 884e5bee615..5ef1e68bd59 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -220,17 +220,17 @@ int UI_GetIconRNA(PointerRNA *ptr) uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2) { uiBut *but=NULL; - const char *propname= RNA_property_identifier(ptr, prop); - int arraylen= RNA_property_array_length(ptr, prop); + const char *propname= RNA_property_identifier(prop); + int arraylen= RNA_property_array_length(prop); - switch(RNA_property_type(ptr, prop)) { + switch(RNA_property_type(prop)) { case PROP_BOOLEAN: { int value, length; if(arraylen && index == -1) return NULL; - length= RNA_property_array_length(ptr, prop); + length= RNA_property_array_length(prop); if(length) value= RNA_property_boolean_get_index(ptr, prop, index); @@ -248,10 +248,10 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind case PROP_INT: case PROP_FLOAT: if(arraylen && index == -1) { - if(RNA_property_subtype(ptr, prop) == PROP_COLOR) + if(RNA_property_subtype(prop) == PROP_COLOR) but= uiDefButR(block, COL, 0, name, x1, y1, x2, y2, ptr, propname, 0, 0, 0, -1, -1, NULL); } - else if(RNA_property_subtype(ptr, prop) == PROP_PERCENTAGE) + else if(RNA_property_subtype(prop) == PROP_PERCENTAGE) but= uiDefButR(block, NUMSLI, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); else but= uiDefButR(block, NUM, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); @@ -268,7 +268,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind pptr= RNA_property_pointer_get(ptr, prop); if(!pptr.type) - pptr.type= RNA_property_pointer_type(ptr, prop); + pptr.type= RNA_property_pointer_type(prop); icon= UI_GetIconRNA(&pptr); but= uiDefIconTextButR(block, IDPOIN, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL); @@ -300,20 +300,20 @@ int uiDefAutoButsRNA(const bContext *C, uiBlock *block, PointerRNA *ptr) layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, x, y, DEF_BUT_WIDTH*2, 20); uiLayoutColumn(layout); - uiItemL(layout, (char*)RNA_struct_ui_name(ptr), 0); + uiItemL(layout, (char*)RNA_struct_ui_name(ptr->type), 0); - iterprop= RNA_struct_iterator_property(ptr); + iterprop= RNA_struct_iterator_property(ptr->type); RNA_property_collection_begin(ptr, iterprop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { prop= iter.ptr.data; - if(strcmp(RNA_property_identifier(ptr, prop), "rna_type") == 0) + if(strcmp(RNA_property_identifier(prop), "rna_type") == 0) continue; uiLayoutSplit(layout, 2, 0); - name= (char*)RNA_property_ui_name(ptr, prop); + name= (char*)RNA_property_ui_name(prop); uiLayoutColumn(uiLayoutSub(layout, 0)); uiItemL(uiLayoutSub(layout, 0), name, 0); uiLayoutColumn(uiLayoutSub(layout, 1)); diff --git a/source/blender/editors/space_outliner/outliner.c b/source/blender/editors/space_outliner/outliner.c index 46f8bc77149..b03d938843f 100644 --- a/source/blender/editors/space_outliner/outliner.c +++ b/source/blender/editors/space_outliner/outliner.c @@ -1042,20 +1042,20 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i } else if(type == TSE_RNA_STRUCT) { /* struct */ - nameprop= RNA_struct_name_property(ptr); + nameprop= RNA_struct_name_property(ptr->type); if(nameprop) { te->name= RNA_property_string_get_alloc(ptr, nameprop, NULL, 0); te->flag |= TE_FREE_NAME; } else - te->name= (char*)RNA_struct_ui_name(ptr); + te->name= (char*)RNA_struct_ui_name(ptr->type); - iterprop= RNA_struct_iterator_property(ptr); + iterprop= RNA_struct_iterator_property(ptr->type); tot= RNA_property_collection_length(ptr, iterprop); /* auto open these cases */ - if(!parent || (RNA_property_type(&parent->rnaptr, parent->directdata)) == PROP_POINTER) + if(!parent || (RNA_property_type(parent->directdata)) == PROP_POINTER) if(!tselem->used) tselem->flag &= ~TSE_CLOSED; @@ -1070,13 +1070,13 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i } else if(type == TSE_RNA_PROPERTY) { /* property */ - iterprop= RNA_struct_iterator_property(ptr); + iterprop= RNA_struct_iterator_property(ptr->type); RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr); prop= propptr.data; - proptype= RNA_property_type(ptr, prop); + proptype= RNA_property_type(prop); - te->name= (char*)RNA_property_ui_name(ptr, prop); + te->name= (char*)RNA_property_ui_name(prop); te->directdata= prop; te->rnaptr= *ptr; @@ -1103,7 +1103,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i te->flag |= TE_LAZY_CLOSED; } else if(ELEM3(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) { - tot= RNA_property_array_length(ptr, prop); + tot= RNA_property_array_length(prop); if(!(tselem->flag & TSE_CLOSED)) { for(a=0; a<tot; a++) @@ -1120,9 +1120,9 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i static char *coloritem[4]= {" r", " g", " b", " a"}; prop= parent->directdata; - proptype= RNA_property_type(ptr, prop); - propsubtype= RNA_property_subtype(ptr, prop); - tot= RNA_property_array_length(ptr, prop); + proptype= RNA_property_type(prop); + propsubtype= RNA_property_subtype(prop); + tot= RNA_property_array_length(prop); te->directdata= prop; te->rnaptr= *ptr; @@ -3146,16 +3146,16 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle * - to prevent memory leaks, we must write to newpath not path, then free old path + swap them */ if(tse->type == TSE_RNA_PROPERTY) { - if(RNA_property_type(ptr, prop) == PROP_POINTER) { + if(RNA_property_type(prop) == PROP_POINTER) { /* for pointer we just append property name */ newpath= RNA_path_append(*path, ptr, prop, 0, NULL); } - else if(RNA_property_type(ptr, prop) == PROP_COLLECTION) { + else if(RNA_property_type(prop) == PROP_COLLECTION) { temnext= (TreeElement*)(ld->next->data); tsenext= TREESTORE(temnext); nextptr= &temnext->rnaptr; - nameprop= RNA_struct_name_property(nextptr); + nameprop= RNA_struct_name_property(nextptr->type); if(nameprop) { /* if possible, use name as a key in the path */ @@ -3192,7 +3192,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle /* no ID, so check if entry is RNA-struct, and if that RNA-struct is an ID datablock to extract info from */ if (tse->type == TSE_RNA_STRUCT) { /* ptr->data not ptr->id.data seems to be the one we want, since ptr->data is sometimes the owner of this ID? */ - if(RNA_struct_is_ID(ptr)) { + if(RNA_struct_is_ID(ptr->type)) { *id= (ID *)ptr->data; /* clear path */ @@ -3216,7 +3216,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle /* item is part of an array, so must set the array_index */ *array_index= te->index; } - else if (RNA_property_array_length(ptr, prop)) { + else if (RNA_property_array_length(prop)) { /* entire array was selected, so keyframe all */ *flag |= KSP_FLAG_WHOLE_ARRAY; } @@ -4203,7 +4203,7 @@ static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, Spa ptr= &te->rnaptr; prop= te->directdata; - if(!(RNA_property_type(ptr, prop) == PROP_POINTER && (tselem->flag & TSE_CLOSED)==0)) + if(!(RNA_property_type(prop) == PROP_POINTER && (tselem->flag & TSE_CLOSED)==0)) uiDefAutoButR(block, ptr, prop, -1, "", 0, sizex, (int)te->ys, OL_RNA_COL_SIZEX, OL_H-1); } else if(tselem->type == TSE_RNA_ARRAY_ELEM) { diff --git a/source/blender/editors/space_text/text_header.c b/source/blender/editors/space_text/text_header.c index be3a57afbf5..b2069b14d06 100644 --- a/source/blender/editors/space_text/text_header.c +++ b/source/blender/editors/space_text/text_header.c @@ -487,15 +487,15 @@ void text_properties_register(ARegionType *art) /* panels: properties */ pt= MEM_callocN(sizeof(PanelType), "spacetype text panel"); - pt->idname= "TEXT_PT_properties"; - pt->name= "Properties"; + strcpy(pt->idname, "TEXT_PT_properties"); + strcpy(pt->label, "Properties"); pt->draw= text_properties_panel_draw; BLI_addtail(&art->paneltypes, pt); /* panels: find */ pt= MEM_callocN(sizeof(PanelType), "spacetype text panel"); - pt->idname= "TEXT_PT_find"; - pt->name= "Find"; + strcpy(pt->idname, "TEXT_PT_find"); + strcpy(pt->label, "Find"); pt->draw= text_find_panel_draw; BLI_addtail(&art->paneltypes, pt); } diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 7c7ecf29bb9..5795bfe5b26 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -321,19 +321,25 @@ void RNA_blender_rna_pointer_create(PointerRNA *r_ptr); /* Structs */ -const char *RNA_struct_identifier(PointerRNA *ptr); -const char *RNA_struct_ui_name(PointerRNA *ptr); -const char *RNA_struct_ui_description(PointerRNA *ptr); +const char *RNA_struct_identifier(StructRNA *type); +const char *RNA_struct_ui_name(StructRNA *type); +const char *RNA_struct_ui_description(StructRNA *type); -PropertyRNA *RNA_struct_name_property(PointerRNA *ptr); -PropertyRNA *RNA_struct_iterator_property(PointerRNA *ptr); +PropertyRNA *RNA_struct_name_property(StructRNA *type); +PropertyRNA *RNA_struct_iterator_property(StructRNA *type); -int RNA_struct_is_ID(PointerRNA *ptr); -int RNA_struct_is_a(PointerRNA *ptr, StructRNA *srna); +int RNA_struct_is_ID(StructRNA *type); +int RNA_struct_is_a(StructRNA *type, StructRNA *srna); + +StructRegisterFunc RNA_struct_register(StructRNA *type); +StructUnregisterFunc RNA_struct_unregister(StructRNA *type); void *RNA_struct_py_type_get(StructRNA *srna); 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); + PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier); const struct ListBase *RNA_struct_defined_properties(StructRNA *srna); @@ -347,12 +353,20 @@ const struct ListBase *RNA_struct_defined_functions(StructRNA *srna); /* Property Information */ -const char *RNA_property_identifier(PointerRNA *ptr, PropertyRNA *prop); -PropertyType RNA_property_type(PointerRNA *ptr, PropertyRNA *prop); -PropertySubType RNA_property_subtype(PointerRNA *ptr, PropertyRNA *prop); -int RNA_property_flag(PointerRNA *ptr, PropertyRNA *prop); +const char *RNA_property_identifier(PropertyRNA *prop); +PropertyType RNA_property_type(PropertyRNA *prop); +PropertySubType RNA_property_subtype(PropertyRNA *prop); +int RNA_property_flag(PropertyRNA *prop); + +int RNA_property_array_length(PropertyRNA *prop); + +StructRNA *RNA_property_pointer_type(PropertyRNA *prop); +int RNA_property_string_maxlength(PropertyRNA *prop); -int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop); +const char *RNA_property_ui_name(PropertyRNA *prop); +const char *RNA_property_ui_description(PropertyRNA *prop); + +/* Dynamic Property Information */ void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax); void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step); @@ -360,16 +374,10 @@ void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax); void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision); -int RNA_property_string_maxlength(PointerRNA *ptr, PropertyRNA *prop); -StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop); - void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **item, int *totitem); int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value); int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier); -const char *RNA_property_ui_name(PointerRNA *ptr, PropertyRNA *prop); -const char *RNA_property_ui_description(PointerRNA *ptr, PropertyRNA *prop); - int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop); int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop); int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop); @@ -518,13 +526,14 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop); /* Function */ -const char *RNA_function_identifier(PointerRNA *ptr, FunctionRNA *func); -PropertyRNA *RNA_function_return(PointerRNA *ptr, FunctionRNA *func); -const char *RNA_function_ui_description(PointerRNA *ptr, FunctionRNA *func); +const char *RNA_function_identifier(FunctionRNA *func); +PropertyRNA *RNA_function_return(FunctionRNA *func); +const char *RNA_function_ui_description(FunctionRNA *func); +int RNA_function_flag(FunctionRNA *func); PropertyRNA *RNA_function_get_parameter(PointerRNA *ptr, FunctionRNA *func, int index); PropertyRNA *RNA_function_find_parameter(PointerRNA *ptr, FunctionRNA *func, const char *identifier); -const struct ListBase *RNA_function_defined_parameters(PointerRNA *ptr, FunctionRNA *func); +const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func); /* Utility */ diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index aede53aff94..c3c07f34ae0 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_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); void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 2020ca1edb8..69d9a6db7ce 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -35,6 +35,8 @@ struct PropertyRNA; struct StructRNA; struct BlenderRNA; struct IDProperty; +struct bContext; +struct ReportList; /* Pointer * @@ -91,6 +93,11 @@ typedef enum PropertyFlag { /* function paramater flags */ PROP_REQUIRED = 4, + PROP_RETURN = 8, + + /* registering */ + PROP_REGISTER = 16, + PROP_REGISTER_OPTIONAL = 16|32, /* internal flags */ PROP_BUILTIN = 128, @@ -147,6 +154,10 @@ typedef struct ParameterIterator { typedef enum FunctionFlag { FUNC_TYPESTATIC = 1, /* for static functions, FUNC_ STATIC is taken by some windows header it seems */ + /* registering */ + FUNC_REGISTER = 2, + FUNC_REGISTER_OPTIONAL = 2|4, + /* internal flags */ FUNC_BUILTIN = 128, FUNC_EXPORT = 256, @@ -168,6 +179,13 @@ typedef enum StructFlag { STRUCT_GENERATED = 4 } StructFlag; +typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function); +typedef int (*StructCallbackFunc)(struct PointerRNA *ptr, struct FunctionRNA *func, struct 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); +typedef void (*StructUnregisterFunc)(const struct bContext *C, struct StructRNA *type); + typedef struct StructRNA StructRNA; /* Blender RNA diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 1daf8625ce2..132a81ad274 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1086,6 +1086,9 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA srna= dsrna->srna; func= dfunc->func; + if(func->flag & FUNC_REGISTER) + return; + funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call"); fprintf(f, "void %s(PointerRNA *_ptr, ParameterList *_parms)", funcname); @@ -1396,6 +1399,9 @@ static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA fprintf(f, "/* Repeated prototypes to detect errors */\n\n"); for(func= srna->functions.first; func; func= func->cont.next) { + if(func->flag & FUNC_REGISTER) + continue; + dfunc= rna_find_function_def(func); if(dfunc->call) rna_generate_static_parameter_prototypes(brna, srna, dfunc, f); @@ -1664,7 +1670,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier); else fprintf(f, "NULL}},\n"); - fprintf(f, "\tNULL,\n"); /* PyType - Cant initialize here */ + fprintf(f, "\tNULL,NULL,\n"); /* PyType - Cant initialize here */ fprintf(f, "\t"); rna_print_c_string(f, srna->identifier); @@ -1698,6 +1704,13 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f) fprintf(f, "\t%s,\n", rna_function_string(srna->refine)); 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)); + + if(srna->reg && !srna->refine) { + fprintf(stderr, "rna_generate_struct: %s has a register function, must also have refine function.\n", srna->identifier); + DefRNA.error= 1; + } func= srna->functions.first; if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s, ", srna->identifier, func->identifier); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index ebe434377ee..5532ab90e42 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -208,6 +208,21 @@ static int rna_idproperty_verify_valid(PropertyRNA *prop, IDProperty *idprop) return 1; } +static PropertyRNA *typemap[IDP_NUMTYPES] = + {(PropertyRNA*)&rna_IDProperty_string, + (PropertyRNA*)&rna_IDProperty_int, + (PropertyRNA*)&rna_IDProperty_float, + NULL, NULL, NULL, + (PropertyRNA*)&rna_IDProperty_group, NULL, + (PropertyRNA*)&rna_IDProperty_double}; + +static PropertyRNA *arraytypemap[IDP_NUMTYPES] = + {NULL, (PropertyRNA*)&rna_IDProperty_int_array, + (PropertyRNA*)&rna_IDProperty_float_array, + NULL, NULL, NULL, + (PropertyRNA*)&rna_IDProperty_collection, NULL, + (PropertyRNA*)&rna_IDProperty_double_array}; + IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) { /* This is quite a hack, but avoids some complexity in the API. we @@ -237,21 +252,6 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) } { - static PropertyRNA *typemap[IDP_NUMTYPES] = - {(PropertyRNA*)&rna_IDProperty_string, - (PropertyRNA*)&rna_IDProperty_int, - (PropertyRNA*)&rna_IDProperty_float, - NULL, NULL, NULL, - (PropertyRNA*)&rna_IDProperty_group, NULL, - (PropertyRNA*)&rna_IDProperty_double}; - - static PropertyRNA *arraytypemap[IDP_NUMTYPES] = - {NULL, (PropertyRNA*)&rna_IDProperty_int_array, - (PropertyRNA*)&rna_IDProperty_float_array, - NULL, NULL, NULL, - (PropertyRNA*)&rna_IDProperty_collection, NULL, - (PropertyRNA*)&rna_IDProperty_double_array}; - IDProperty *idprop= (IDProperty*)(*prop); if(idprop->type == IDP_ARRAY) @@ -263,45 +263,95 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) } } +PropertyRNA *rna_ensure_property(PropertyRNA *prop) +{ + /* the quick version if we don't need the idproperty */ + + if(prop->magic == RNA_MAGIC) + return prop; + + { + IDProperty *idprop= (IDProperty*)prop; + + if(idprop->type == IDP_ARRAY) + return arraytypemap[(int)(idprop->subtype)]; + else + return typemap[(int)(idprop->type)]; + } +} + +const char *rna_ensure_property_identifier(PropertyRNA *prop) +{ + if(prop->magic == RNA_MAGIC) + return prop->identifier; + else + return ((IDProperty*)prop)->name; +} + +const char *rna_ensure_property_name(PropertyRNA *prop) +{ + if(prop->magic == RNA_MAGIC) + return prop->name; + else + return ((IDProperty*)prop)->name; +} + +int rna_ensure_property_array_length(PropertyRNA *prop) +{ + if(prop->magic == RNA_MAGIC) + return prop->arraylength; + else { + IDProperty *idprop= (IDProperty*)prop; + + if(idprop->type == IDP_ARRAY) + return idprop->len; + else + return 0; + } +} + /* Structs */ -const char *RNA_struct_identifier(PointerRNA *ptr) +const char *RNA_struct_identifier(StructRNA *type) { - return ptr->type->identifier; + return type->identifier; } -const char *RNA_struct_ui_name(PointerRNA *ptr) +const char *RNA_struct_ui_name(StructRNA *type) { - return ptr->type->name; + return type->name; } -const char *RNA_struct_ui_description(PointerRNA *ptr) +const char *RNA_struct_ui_description(StructRNA *type) { - return ptr->type->description; + return type->description; } -PropertyRNA *RNA_struct_name_property(PointerRNA *ptr) +PropertyRNA *RNA_struct_name_property(StructRNA *type) { - return ptr->type->nameproperty; + return type->nameproperty; } -PropertyRNA *RNA_struct_iterator_property(PointerRNA *ptr) +PropertyRNA *RNA_struct_iterator_property(StructRNA *type) { - return ptr->type->iteratorproperty; + return type->iteratorproperty; } -int RNA_struct_is_ID(PointerRNA *ptr) +int RNA_struct_is_ID(StructRNA *type) { - return (ptr->type->flag & STRUCT_ID) != 0; + return (type->flag & STRUCT_ID) != 0; } -int RNA_struct_is_a(PointerRNA *ptr, StructRNA *srna) +int RNA_struct_is_a(StructRNA *type, StructRNA *srna) { - StructRNA *type; + StructRNA *base; + + if(!type) + return 0; /* ptr->type is always maximally refined */ - for(type=ptr->type; type; type=type->base) - if(type == srna) + for(base=type; base; base=base->base) + if(base == srna) return 1; return 0; @@ -313,12 +363,12 @@ PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier) PropertyRNA *iterprop, *prop; int i = 0; - iterprop= RNA_struct_iterator_property(ptr); + iterprop= RNA_struct_iterator_property(ptr->type); RNA_property_collection_begin(ptr, iterprop, &iter); prop= NULL; for(; iter.valid; RNA_property_collection_next(&iter), i++) { - if(strcmp(identifier, RNA_property_identifier(ptr, iter.ptr.data)) == 0) { + if(strcmp(identifier, RNA_property_identifier(iter.ptr.data)) == 0) { prop= iter.ptr.data; break; } @@ -349,7 +399,7 @@ FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier) func= NULL; for(; iter.valid; RNA_property_collection_next(&iter), i++) { - if(strcmp(identifier, RNA_function_identifier(&tptr, iter.ptr.data)) == 0) { + if(strcmp(identifier, RNA_function_identifier(iter.ptr.data)) == 0) { func= iter.ptr.data; break; } @@ -365,6 +415,21 @@ const struct ListBase *RNA_struct_defined_functions(StructRNA *srna) return &srna->functions; } +StructRegisterFunc RNA_struct_register(StructRNA *type) +{ + return type->reg; +} + +StructUnregisterFunc RNA_struct_unregister(StructRNA *type) +{ + do { + if(type->unreg) + return type->unreg; + } while((type=type->base)); + + return NULL; +} + void *RNA_struct_py_type_get(StructRNA *srna) { return srna->py_type; @@ -375,55 +440,46 @@ void RNA_struct_py_type_set(StructRNA *srna, void *py_type) srna->py_type= py_type; } -/* Property Information */ - -const char *RNA_property_identifier(PointerRNA *ptr, PropertyRNA *prop) +void *RNA_struct_blender_type_get(StructRNA *srna) { - IDProperty *idprop; - - if((idprop=rna_idproperty_check(&prop, ptr))) - return idprop->name; - else - return prop->identifier; + return srna->blender_type; } -PropertyType RNA_property_type(PointerRNA *ptr, PropertyRNA *prop) +void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type) { - rna_idproperty_check(&prop, ptr); - - return prop->type; + srna->blender_type= blender_type; } -PropertySubType RNA_property_subtype(PointerRNA *ptr, PropertyRNA *prop) -{ - rna_idproperty_check(&prop, ptr); +/* Property Information */ - return prop->subtype; +const char *RNA_property_identifier(PropertyRNA *prop) +{ + return rna_ensure_property_identifier(prop); } -int RNA_property_flag(PointerRNA *ptr, PropertyRNA *prop) +PropertyType RNA_property_type(PropertyRNA *prop) { - rna_idproperty_check(&prop, ptr); + return rna_ensure_property(prop)->type; +} - return prop->flag; +PropertySubType RNA_property_subtype(PropertyRNA *prop) +{ + return rna_ensure_property(prop)->subtype; } -int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop) +int RNA_property_flag(PropertyRNA *prop) { - IDProperty *idprop; + return rna_ensure_property(prop)->flag; +} - if((idprop=rna_idproperty_check(&prop, ptr)) && idprop->type==IDP_ARRAY) - return idprop->len; - else - return prop->arraylength; +int RNA_property_array_length(PropertyRNA *prop) +{ + return rna_ensure_property_array_length(prop); } void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax) { - IntPropertyRNA *iprop; - - rna_idproperty_check(&prop, ptr); - iprop= (IntPropertyRNA*)prop; + IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop); if(iprop->range) { iprop->range(ptr, hardmin, hardmax); @@ -436,12 +492,9 @@ void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, in void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step) { - IntPropertyRNA *iprop; + IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop); int hardmin, hardmax; - rna_idproperty_check(&prop, ptr); - iprop= (IntPropertyRNA*)prop; - if(iprop->range) { iprop->range(ptr, &hardmin, &hardmax); *softmin= MAX2(iprop->softmin, hardmin); @@ -457,10 +510,7 @@ void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax) { - FloatPropertyRNA *fprop; - - rna_idproperty_check(&prop, ptr); - fprop= (FloatPropertyRNA*)prop; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop); if(fprop->range) { fprop->range(ptr, hardmin, hardmax); @@ -473,12 +523,9 @@ void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision) { - FloatPropertyRNA *fprop; + FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop); float hardmin, hardmax; - rna_idproperty_check(&prop, ptr); - fprop= (FloatPropertyRNA*)prop; - if(fprop->range) { fprop->range(ptr, &hardmin, &hardmax); *softmin= MAX2(fprop->softmin, hardmin); @@ -493,19 +540,15 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft *precision= (float)fprop->precision; } -int RNA_property_string_maxlength(PointerRNA *ptr, PropertyRNA *prop) +int RNA_property_string_maxlength(PropertyRNA *prop) { - StringPropertyRNA *sprop; - - rna_idproperty_check(&prop, ptr); - sprop= (StringPropertyRNA*)prop; - + StringPropertyRNA *sprop= (StringPropertyRNA*)rna_ensure_property(prop); return sprop->maxlength; } -StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop) +StructRNA *RNA_property_pointer_type(PropertyRNA *prop) { - rna_idproperty_check(&prop, ptr); + prop= rna_ensure_property(prop); if(prop->type == PROP_POINTER) { PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; @@ -525,10 +568,7 @@ StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **item, int *totitem) { - EnumPropertyRNA *eprop; - - rna_idproperty_check(&prop, ptr); - eprop= (EnumPropertyRNA*)prop; + EnumPropertyRNA *eprop= (EnumPropertyRNA*)rna_ensure_property(prop); *item= eprop->item; *totitem= eprop->totitem; @@ -568,32 +608,21 @@ int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int v return 0; } -const char *RNA_property_ui_name(PointerRNA *ptr, PropertyRNA *prop) +const char *RNA_property_ui_name(PropertyRNA *prop) { - PropertyRNA *oldprop= prop; - IDProperty *idprop; - - if((idprop=rna_idproperty_check(&prop, ptr)) && oldprop!=prop) - return idprop->name; - else - return prop->name; + return rna_ensure_property_name(prop); } -const char *RNA_property_ui_description(PointerRNA *ptr, PropertyRNA *prop) +const char *RNA_property_ui_description(PropertyRNA *prop) { - PropertyRNA *oldprop= prop; - - if(rna_idproperty_check(&prop, ptr) && oldprop!=prop) - return ""; - else - return prop->description; + return rna_ensure_property(prop)->description; } int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop) { int flag; - rna_idproperty_check(&prop, ptr); + prop= rna_ensure_property(prop); if(prop->editable) flag= prop->editable(ptr); @@ -607,7 +636,7 @@ int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop) { int flag; - rna_idproperty_check(&prop, ptr); + prop= rna_ensure_property(prop); if(!(prop->flag & PROP_ANIMATEABLE)) return 0; @@ -629,7 +658,7 @@ int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop) { - rna_idproperty_check(&prop, ptr); + prop= rna_ensure_property(prop); if(prop->update) prop->update(C, ptr); @@ -1512,12 +1541,12 @@ int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, Prope if(!token) return 0; - iterprop= RNA_struct_iterator_property(&curptr); + iterprop= RNA_struct_iterator_property(curptr.type); RNA_property_collection_begin(&curptr, iterprop, &iter); prop= NULL; for(; iter.valid; RNA_property_collection_next(&iter)) { - if(strcmp(token, RNA_property_identifier(&curptr, iter.ptr.data)) == 0) { + if(strcmp(token, RNA_property_identifier(iter.ptr.data)) == 0) { prop= iter.ptr.data; break; } @@ -1534,7 +1563,7 @@ int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, Prope /* now look up the value of this property if it is a pointer or * collection, otherwise return the property rna so that the * caller can read the value of the property itself */ - if(RNA_property_type(&curptr, prop) == PROP_POINTER) { + if(RNA_property_type(prop) == PROP_POINTER) { nextptr= RNA_property_pointer_get(&curptr, prop); if(nextptr.data) @@ -1542,7 +1571,7 @@ int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, Prope else return 0; } - else if(RNA_property_type(&curptr, prop) == PROP_COLLECTION && *path) { + else if(RNA_property_type(prop) == PROP_COLLECTION && *path) { /* resolve the lookup with [] brackets */ token= rna_path_token(&path, fixedbuf, sizeof(fixedbuf), 1); @@ -1594,9 +1623,9 @@ char *RNA_path_append(const char *path, PointerRNA *ptr, PropertyRNA *prop, int BLI_dynstr_append(dynstr, "."); } - BLI_dynstr_append(dynstr, (char*)RNA_property_identifier(ptr, prop)); + BLI_dynstr_append(dynstr, (char*)RNA_property_identifier(prop)); - if(RNA_property_type(ptr, prop) == PROP_COLLECTION) { + if(RNA_property_type(prop) == PROP_COLLECTION) { /* add ["strkey"] or [intkey] */ BLI_dynstr_append(dynstr, "["); @@ -1685,14 +1714,14 @@ char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop) if(!ptr->id.data || !ptr->data || !prop) return NULL; - if(!RNA_struct_is_ID(ptr)) { + if(!RNA_struct_is_ID(ptr->type)) { if(ptr->type->path) ptrpath= ptr->type->path(ptr); else return NULL; } - propname= RNA_property_identifier(ptr, prop); + propname= RNA_property_identifier(prop); if(ptrpath) { path= BLI_sprintfN("%s.%s", ptrpath, propname); @@ -2039,8 +2068,8 @@ int RNA_property_is_set(PointerRNA *ptr, const char *name) * compatible but can be used for display too*/ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop) { - int type = RNA_property_type(ptr, prop); - int len = RNA_property_array_length(ptr, prop); + int type = RNA_property_type(prop); + int len = RNA_property_array_length(prop); int i; DynStr *dynstr= BLI_dynstr_new(); @@ -2128,21 +2157,26 @@ char *RNA_property_as_string(PointerRNA *ptr, PropertyRNA *prop) /* Function */ -const char *RNA_function_identifier(PointerRNA *ptr, FunctionRNA *func) +const char *RNA_function_identifier(FunctionRNA *func) { return func->identifier; } -PropertyRNA *RNA_function_return(PointerRNA *ptr, FunctionRNA *func) +PropertyRNA *RNA_function_return(FunctionRNA *func) { return func->ret; } -const char *RNA_function_ui_description(PointerRNA *ptr, FunctionRNA *func) +const char *RNA_function_ui_description(FunctionRNA *func) { return func->description; } +int RNA_function_flag(FunctionRNA *func) +{ + return func->flag; +} + PropertyRNA *RNA_function_get_parameter(PointerRNA *ptr, FunctionRNA *func, int index) { PropertyRNA *parm; @@ -2168,7 +2202,7 @@ PropertyRNA *RNA_function_find_parameter(PointerRNA *ptr, FunctionRNA *func, con return NULL; } -const struct ListBase *RNA_function_defined_parameters(PointerRNA *ptr, FunctionRNA *func) +const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func) { return &func->cont.properties; } @@ -2216,7 +2250,7 @@ void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter) if(iter->valid) { iter->size= rna_parameter_size(iter->parm); iter->data= (((char*)iter->parms->data)+iter->offset); - ptype= RNA_property_type(&iter->funcptr, iter->parm); + ptype= RNA_property_type(iter->parm); } } @@ -2231,7 +2265,7 @@ void RNA_parameter_list_next(ParameterIterator *iter) if(iter->valid) { iter->size= rna_parameter_size(iter->parm); iter->data= (((char*)iter->parms->data)+iter->offset); - ptype= RNA_property_type(&iter->funcptr, iter->parm); + ptype= RNA_property_type(iter->parm); } } @@ -2260,14 +2294,11 @@ void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **value) void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **value) { - PointerRNA funcptr; PropertyRNA *parm; - RNA_pointer_create(NULL, &RNA_Function, parms->func, &funcptr); - parm= parms->func->cont.properties.first; for(; parm; parm= parm->next) - if(strcmp(RNA_property_identifier(&funcptr, parm), identifier)==0) + if(strcmp(RNA_property_identifier(parm), identifier)==0) break; if(parm) @@ -2276,10 +2307,8 @@ void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, void *value) { - PointerRNA funcptr; ParameterIterator iter; - RNA_pointer_create(NULL, &RNA_Function, parms->func, &funcptr); RNA_parameter_list_begin(parms, &iter); for(; iter.valid; RNA_parameter_list_next(&iter)) @@ -2294,14 +2323,11 @@ void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, void *value) void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, void *value) { - PointerRNA funcptr; PropertyRNA *parm; - RNA_pointer_create(NULL, &RNA_Function, parms->func, &funcptr); - parm= parms->func->cont.properties.first; for(; parm; parm= parm->next) - if(strcmp(RNA_property_identifier(&funcptr, parm), identifier)==0) + if(strcmp(RNA_property_identifier(parm), identifier)==0) break; if(parm) @@ -2463,21 +2489,14 @@ static int rna_function_parameter_parse(PointerRNA *ptr, PropertyRNA *prop, Prop return -1; } - ptype= RNA_property_pointer_type(ptr, prop); + ptype= RNA_property_pointer_type(prop); if(ptype == &RNA_AnyType) { *((PointerRNA*)dest)= *((PointerRNA*)src); } else if (ptype!=srna) { - PointerRNA pptr; - - RNA_pointer_create(NULL, srna, *((void**)src), &pptr); - - if (!RNA_struct_is_a(&pptr, ptype)) { - PointerRNA tmp; - RNA_pointer_create(NULL, ptype, NULL, &tmp); - - fprintf(stderr, "%s.%s: wrong type for parameter %s, an object of type %s was expected, passed an object of type %s\n", tid, fid, pid, RNA_struct_identifier(&tmp), RNA_struct_identifier(&pptr)); + if (!RNA_struct_is_a(srna, ptype)) { + fprintf(stderr, "%s.%s: wrong type for parameter %s, an object of type %s was expected, passed an object of type %s\n", tid, fid, pid, RNA_struct_identifier(ptype), RNA_struct_identifier(ptype)); return -1; } @@ -2520,9 +2539,9 @@ int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char * RNA_pointer_create(NULL, &RNA_Function, func, &funcptr); - tid= RNA_struct_identifier(ptr); - fid= RNA_function_identifier(ptr, func); - pret= RNA_function_return(ptr, func); + tid= RNA_struct_identifier(ptr->type); + fid= RNA_function_identifier(func); + pret= RNA_function_return(func); flen= strlen(format); parms= RNA_parameter_list_create(ptr, func); @@ -2536,8 +2555,8 @@ int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char * continue; } - pid= RNA_property_identifier(&funcptr, parm); - flag= RNA_property_flag(&funcptr, parm); + pid= RNA_property_identifier(parm); + flag= RNA_property_flag(parm); if (ofs>=flen || format[ofs]=='N') { if (flag & PROP_REQUIRED) { @@ -2549,9 +2568,9 @@ int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char * continue; } - type= RNA_property_type(&funcptr, parm); + type= RNA_property_type(parm); ftype= format[ofs++]; - len= RNA_property_array_length(&funcptr, parm); + len= RNA_property_array_length(parm); alen= rna_function_format_array_length(format, ofs, flen); if (len!=alen) { @@ -2607,9 +2626,9 @@ int RNA_function_call_direct_va(PointerRNA *ptr, FunctionRNA *func, const char * if (err==0 && pret && ofs<flen && format[ofs++]=='R') { parm= pret; - type= RNA_property_type(&funcptr, parm); + type= RNA_property_type(parm); ftype= format[ofs++]; - len= RNA_property_array_length(&funcptr, parm); + len= RNA_property_array_length(parm); alen= rna_function_format_array_length(format, ofs, flen); if (len!=alen) { diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index bfe7705818a..bc990ae48f9 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -422,13 +422,43 @@ void RNA_define_free(BlenderRNA *brna) DefRNA.error= 0; } -void RNA_free(BlenderRNA *brna) +void RNA_struct_free(BlenderRNA *brna, StructRNA *srna) { - StructRNA *srna, *nextsrna; - PropertyRNA *prop, *nextprop; FunctionRNA *func, *nextfunc; + PropertyRNA *prop, *nextprop; PropertyRNA *parm, *nextparm; + for(prop=srna->cont.properties.first; prop; prop=nextprop) { + nextprop= prop->next; + + if(prop->flag & PROP_RUNTIME) + rna_freelinkN(&srna->cont.properties, prop); + } + + for(func=srna->functions.first; func; func=nextfunc) { + nextfunc= func->cont.next; + + for(parm=func->cont.properties.first; parm; parm=nextparm) { + nextparm= parm->next; + + if(parm->flag & PROP_RUNTIME) + rna_freelinkN(&func->cont.properties, parm); + } + + if(func->flag & FUNC_RUNTIME) { + rna_freelinkN(&srna->functions, func); + } + } + + if(srna->flag & STRUCT_RUNTIME) + rna_freelinkN(&brna->structs, srna); +} + +void RNA_free(BlenderRNA *brna) +{ + StructRNA *srna, *nextsrna; + FunctionRNA *func; + if(DefRNA.preprocess) { RNA_define_free(brna); @@ -447,31 +477,7 @@ void RNA_free(BlenderRNA *brna) else { for(srna=brna->structs.first; srna; srna=nextsrna) { nextsrna= srna->cont.next; - - for(prop=srna->cont.properties.first; prop; prop=nextprop) { - nextprop= prop->next; - - if(prop->flag & PROP_RUNTIME) - rna_freelinkN(&srna->cont.properties, prop); - } - - for(func=srna->functions.first; func; func=nextfunc) { - nextfunc= func->cont.next; - - for(parm=func->cont.properties.first; parm; parm=nextparm) { - nextparm= parm->next; - - if(parm->flag & PROP_RUNTIME) - rna_freelinkN(&func->cont.properties, parm); - } - - if(func->flag & FUNC_RUNTIME) { - rna_freelinkN(&srna->functions, func); - } - } - - if(srna->flag & STRUCT_RUNTIME) - rna_freelinkN(&brna->structs, srna); + RNA_struct_free(brna, srna); } } } @@ -704,6 +710,17 @@ void RNA_def_struct_refine_func(StructRNA *srna, const char *refine) if(refine) srna->refine= (StructRefineFunc)refine; } +void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg) +{ + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_struct_register_funcs: only during preprocessing.\n"); + return; + } + + if(reg) srna->reg= (StructRegisterFunc)reg; + if(unreg) srna->unreg= (StructUnregisterFunc)unreg; +} + void RNA_def_struct_path_func(StructRNA *srna, const char *path) { if(!DefRNA.preprocess) { @@ -730,12 +747,6 @@ void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *descr srna->description= description; } -void RNA_struct_free(BlenderRNA *brna, StructRNA *srna) -{ - rna_freelistN(&srna->cont.properties); - rna_freelinkN(&brna->structs, srna); -} - /* Property Definition */ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype) @@ -2125,6 +2136,7 @@ FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, C void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret) { func->ret= ret; + ret->flag|=PROP_RETURN; } void RNA_def_function_flag(FunctionRNA *func, int flag) diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 5e44b7f7452..50a4db8e158 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -32,6 +32,8 @@ struct ContainerRNA; struct StructRNA; struct PropertyRNA; struct PointerRNA; +struct FunctionRNA; +struct ReportList; struct CollectionPropertyIterator; struct bContext; @@ -248,6 +250,7 @@ struct StructRNA { /* python type, this is a subtype of pyrna_struct_Type but used so each struct can have its own type * which is useful for subclassing RNA */ void *py_type; + void *blender_type; /* unique identifier */ const char *identifier; @@ -280,6 +283,10 @@ struct StructRNA { /* function to find path to this struct in an ID */ StructPathFunc path; + /* function to register/unregister subclasses */ + StructRegisterFunc reg; + StructUnregisterFunc unreg; + /* functions of this struct */ ListBase functions; }; diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index ae0a44f9ac2..f7039d9c756 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -368,6 +368,18 @@ static int rna_Property_array_length_get(PointerRNA *ptr) return prop->arraylength; } +static int rna_Property_registered_get(PointerRNA *ptr) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + return prop->flag & PROP_REGISTER; +} + +static int rna_Property_registered_optional_get(PointerRNA *ptr) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + return prop->flag & PROP_REGISTER_OPTIONAL; +} + static int rna_IntProperty_hard_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; @@ -529,6 +541,18 @@ static void rna_Function_parameters_begin(CollectionPropertyIterator *iter, Poin rna_iterator_listbase_begin(iter, &((FunctionRNA*)ptr->data)->cont.properties, rna_property_builtin); } +static int rna_Function_registered_get(PointerRNA *ptr) +{ + FunctionRNA *func= (FunctionRNA*)ptr->data; + return func->flag & FUNC_REGISTER; +} + +static int rna_Function_registered_optional_get(PointerRNA *ptr) +{ + FunctionRNA *func= (FunctionRNA*)ptr->data; + return func->flag & FUNC_REGISTER_OPTIONAL; +} + /* Blender RNA */ static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) @@ -655,6 +679,16 @@ static void rna_def_property(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_boolean_funcs(prop, "rna_Property_editable_get", NULL); RNA_def_property_ui_text(prop, "Editable", "Property is editable through RNA."); + + prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Property_registered_get", NULL); + RNA_def_property_ui_text(prop, "Registered", "Property is registerd as part of type registration."); + + prop= RNA_def_property(srna, "registered_optional", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Property_registered_optional_get", NULL); + RNA_def_property_ui_text(prop, "Registered Optionally", "Property is optionally registerd as part of type registration."); } static void rna_def_function(BlenderRNA *brna) @@ -681,6 +715,16 @@ static void rna_def_function(BlenderRNA *brna) RNA_def_property_struct_type(prop, "Property"); RNA_def_property_collection_funcs(prop, "rna_Function_parameters_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0); RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function."); + + prop= RNA_def_property(srna, "registered", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Function_registered_get", NULL); + RNA_def_property_ui_text(prop, "Registered", "Function is registerd as callback as part of type registration."); + + prop= RNA_def_property(srna, "registered_optional", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Function_registered_optional_get", NULL); + RNA_def_property_ui_text(prop, "Registered Optionally", "Function is optionally registerd as callback part of type registration."); } static void rna_def_number_property(StructRNA *srna, PropertyType type) diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index a976cd54abc..5be3130609c 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -69,19 +69,6 @@ static void rna_def_scrarea(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Regions", "Regions this area is subdivided in."); } -static void rna_def_panel(BlenderRNA *brna) -{ - StructRNA *srna; - PropertyRNA *prop; - - srna= RNA_def_struct(brna, "Panel", NULL); - RNA_def_struct_ui_text(srna, "Panel", "Buttons panel."); - RNA_def_struct_sdna(srna, "Panel"); - - prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop, "UILayout"); -} - static void rna_def_region(BlenderRNA *brna) { StructRNA *srna; @@ -113,7 +100,6 @@ void RNA_def_screen(BlenderRNA *brna) { rna_def_bscreen(brna); rna_def_scrarea(brna); - rna_def_panel(brna); rna_def_region(brna); } diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 8a93fb4a49d..2d624db8ad8 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -31,8 +31,221 @@ #ifdef RNA_RUNTIME +#include "MEM_guardedalloc.h" + +#include "RNA_access.h" +#include "RNA_enum_types.h" + +#include "DNA_screen_types.h" + +#include "BLI_dynstr.h" + +#include "BKE_context.h" +#include "BKE_report.h" +#include "BKE_screen.h" + #include "UI_interface.h" +#include "WM_api.h" +#include "WM_types.h" + +#define RNA_STRING_FUNCTIONS(fname, member) \ +static void fname##_get(PointerRNA *ptr, char *value) \ +{ \ + BLI_strncpy(value, member, sizeof(member)); \ +} \ +\ +static int fname##_length(PointerRNA *ptr) \ +{ \ + return strlen(member); \ +} \ +\ +static void fname##_set(PointerRNA *ptr, const char *value) \ +{ \ + BLI_strncpy(member, value, sizeof(member)); \ +} \ + +RNA_STRING_FUNCTIONS(rna_Panel_idname, ((Panel*)ptr->data)->type->idname) +RNA_STRING_FUNCTIONS(rna_Panel_label, ((Panel*)ptr->data)->type->label) +RNA_STRING_FUNCTIONS(rna_Panel_context, ((Panel*)ptr->data)->type->context) +RNA_STRING_FUNCTIONS(rna_Panel_space_type, ((Panel*)ptr->data)->type->space_type) +RNA_STRING_FUNCTIONS(rna_Panel_region_type, ((Panel*)ptr->data)->type->region_type) + +static void panel_draw(const bContext *C, Panel *pnl) +{ + PointerRNA ptr; + ParameterList *list; + FunctionRNA *func; + + RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->py_srna, pnl, &ptr); + func= RNA_struct_find_function(&ptr, "draw"); + + list= RNA_parameter_list_create(&ptr, func); + RNA_parameter_set_lookup(list, "context", &C); + pnl->type->py_call(&ptr, func, list); + + RNA_parameter_list_free(list); +} + +static int panel_poll(const bContext *C, PanelType *pt) +{ + PointerRNA ptr; + ParameterList *list; + FunctionRNA *func; + void *ret; + int visible; + + RNA_pointer_create(NULL, pt->py_srna, NULL, &ptr); /* dummy */ + func= RNA_struct_find_function(&ptr, "poll"); + + list= RNA_parameter_list_create(&ptr, func); + RNA_parameter_set_lookup(list, "context", &C); + pt->py_call(&ptr, func, list); + + RNA_parameter_get_lookup(list, "visible", &ret); + visible= *(int*)ret; + + RNA_parameter_list_free(list); + + return visible; +} + +static char *enum_as_string(EnumPropertyItem *item) +{ + DynStr *dynstr= BLI_dynstr_new(); + EnumPropertyItem *e; + char *cstring; + + for (e= item; item->identifier; item++) { + BLI_dynstr_appendf(dynstr, (e==item)?"'%s'":", '%s'", item->identifier); + } + + cstring = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + return cstring; +} + +static int space_region_type_from_panel(PanelType *pt, ReportList *reports, SpaceType **r_st, ARegionType **r_art) +{ + SpaceType *st; + ARegionType *art; + int space_value; + int region_value; + + /* find the space type */ + if (RNA_enum_value_from_id(space_type_items, pt->space_type, &space_value)==0) { + char *cstring= enum_as_string(space_type_items); + BKE_reportf(reports, RPT_ERROR, "SpaceType \"%s\" is not one of [%s]", pt->space_type, cstring); + MEM_freeN(cstring); + return 0; + } + + /* find the region type */ + if (RNA_enum_value_from_id(region_type_items, pt->region_type, ®ion_value)==0) { + char *cstring= enum_as_string(region_type_items); + BKE_reportf(reports, RPT_ERROR, "RegionType \"%s\" is not one of [%s]", pt->region_type, cstring); + MEM_freeN(cstring); + return 0; + } + + st= BKE_spacetype_from_id(space_value); + + for(art= st->regiontypes.first; art; art= art->next) { + if (art->regionid==region_value) + break; + } + + /* region type not found? abort */ + if (art==NULL) { + BKE_reportf(reports, RPT_ERROR, "SpaceType \"%s\" does not have a UI region '%s'", pt->space_type, pt->region_type); + return 0; + } + + *r_st= st; + *r_art= art; + + return 1; +} + +static StructRNA *rna_Panel_register(const bContext *C, ReportList *reports, void *data, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) +{ + SpaceType *st; + ARegionType *art; + PanelType *pt; + Panel dummypanel; + PanelType dummypt; + PointerRNA dummyptr; + int have_function[2]; + + /* setup dummy panel & panel type to store static properties in */ + memset(&dummypanel, 0, sizeof(dummypanel)); + memset(&dummypt, 0, sizeof(dummypt)); + dummypanel.type= &dummypt; + RNA_pointer_create(NULL, &RNA_Panel, &dummypanel, &dummyptr); + + /* validate the python class */ + if(validate(&dummyptr, data, have_function) != 0) + return NULL; + + if(!space_region_type_from_panel(&dummypt, reports, &st, &art)) + return NULL; + + /* check if we have registered this panel type before */ + for(pt=art->paneltypes.first; pt; pt=pt->next) + if(strcmp(pt->idname, dummypt.idname) == 0) + break; + + /* create a new panel type if needed, otherwise we overwrite */ + if(!pt) { + pt= MEM_callocN(sizeof(PanelType), "python buttons panel"); + BLI_strncpy(pt->idname, dummypt.idname, sizeof(pt->idname)); + pt->py_srna= RNA_def_struct(&BLENDER_RNA, pt->idname, "Panel"); + RNA_struct_blender_type_set(pt->py_srna, pt); + BLI_addtail(&art->paneltypes, pt); + } + + BLI_strncpy(pt->label, dummypt.label, sizeof(pt->label)); + BLI_strncpy(pt->space_type, dummypt.space_type, sizeof(pt->space_type)); + BLI_strncpy(pt->region_type, dummypt.region_type, sizeof(pt->region_type)); + BLI_strncpy(pt->context, dummypt.context, sizeof(pt->context)); + + pt->poll= (have_function[0])? panel_poll: NULL; + pt->draw= (have_function[1])? panel_draw: NULL; + + pt->py_data= data; + pt->py_call= call; + pt->py_free= free; + + /* update while blender is running */ + if(C) + WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL); + + return pt->py_srna; +} + +static void rna_Panel_unregister(const bContext *C, StructRNA *type) +{ + SpaceType *st; + ARegionType *art; + PanelType *pt= RNA_struct_blender_type_get(type); + + if(!space_region_type_from_panel(pt, NULL, &st, &art)) + return; + + BLI_freelinkN(&art->paneltypes, pt); + RNA_struct_free(&BLENDER_RNA, type); + + /* update while blender is running */ + if(C) + WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL); +} + +static StructRNA* rna_Panel_refine(struct PointerRNA *ptr) +{ + Panel *pnl= (Panel*)ptr->data; + return (pnl->type)? pnl->type->py_srna: &RNA_Panel; +} + #else static void rna_def_ui_layout(BlenderRNA *brna) @@ -46,9 +259,57 @@ static void rna_def_ui_layout(BlenderRNA *brna) RNA_api_ui_layout(srna); } +static void rna_def_panel(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + FunctionRNA *func; + + srna= RNA_def_struct(brna, "Panel", NULL); + RNA_def_struct_ui_text(srna, "Panel", "Buttons panel."); + RNA_def_struct_sdna(srna, "Panel"); + RNA_def_struct_refine_func(srna, "rna_Panel_refine"); + RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister"); + + func= RNA_def_function(srna, "poll", NULL); + RNA_def_function_ui_description(func, "Test if the panel is visible or not."); + RNA_def_function_flag(func, FUNC_REGISTER|FUNC_REGISTER_OPTIONAL); + RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", "")); + RNA_def_pointer(func, "context", "Context", "", ""); + + func= RNA_def_function(srna, "draw", NULL); + RNA_def_function_ui_description(func, "Draw buttons into the panel UI layout."); + RNA_def_function_flag(func, FUNC_REGISTER); + RNA_def_pointer(func, "context", "Context", "", ""); + + prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "UILayout"); + + prop= RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_REGISTER); + RNA_def_property_string_funcs(prop, "rna_Panel_idname_get", "rna_Panel_idname_length", "rna_Panel_idname_set"); + + prop= RNA_def_property(srna, "label", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_REGISTER); + RNA_def_property_string_funcs(prop, "rna_Panel_label_get", "rna_Panel_label_length", "rna_Panel_label_set"); + + prop= RNA_def_property(srna, "space_type", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_REGISTER); + RNA_def_property_string_funcs(prop, "rna_Panel_space_type_get", "rna_Panel_space_type_length", "rna_Panel_space_type_set"); + + prop= RNA_def_property(srna, "region_type", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_REGISTER); + RNA_def_property_string_funcs(prop, "rna_Panel_region_type_get", "rna_Panel_region_type_length", "rna_Panel_region_type_set"); + + prop= RNA_def_property(srna, "context", PROP_STRING, PROP_NONE); + RNA_def_property_flag(prop, PROP_REGISTER); + RNA_def_property_string_funcs(prop, "rna_Panel_context_get", "rna_Panel_context_length", "rna_Panel_context_set"); +} + void RNA_def_ui(BlenderRNA *brna) { rna_def_ui_layout(brna); + rna_def_panel(brna); } #endif diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 660e1d01b6c..f8dcb1f43a1 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -27,6 +27,7 @@ #include "bpy_operator_wrap.h" #include "bpy_rna.h" /* for setting arg props only - pyrna_py_to_prop() */ #include "bpy_compat.h" +#include "bpy_util.h" //#include "blendef.h" #include "BLI_dynstr.h" @@ -54,7 +55,7 @@ int PYOP_props_from_dict(PointerRNA *ptr, PyObject *kw) PropertyRNA *prop, *iterprop; CollectionPropertyIterator iter; - iterprop= RNA_struct_iterator_property(ptr); + iterprop= RNA_struct_iterator_property(ptr->type); RNA_property_collection_begin(ptr, iterprop, &iter); totkw = kw ? PyDict_Size(kw):0; @@ -62,7 +63,7 @@ int PYOP_props_from_dict(PointerRNA *ptr, PyObject *kw) for(; iter.valid; RNA_property_collection_next(&iter)) { prop= iter.ptr.data; - arg_name= RNA_property_identifier(&iter.ptr, prop); + arg_name= RNA_property_identifier(prop); if (strcmp(arg_name, "rna_type")==0) continue; @@ -128,7 +129,6 @@ static PyObject *pyop_base_call( PyObject * self, PyObject * args, PyObject * k bContext *C = (bContext *)PyCObject_AsVoidPtr(PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__")); char *opname = _PyUnicode_AsString(self); - char *report_str= NULL; if (PyTuple_Size(args)) { PyErr_SetString( PyExc_AttributeError, "All operator args must be keywords"); @@ -157,16 +157,10 @@ static PyObject *pyop_base_call( PyObject * self, PyObject * args, PyObject * k WM_operator_call_py(C, ot, &ptr, &reports); - report_str= BKE_reports_string(&reports, RPT_ERROR); - - if (report_str) { - PyErr_SetString(PyExc_SystemError, report_str); - MEM_freeN(report_str); + if(BPy_reports_to_error(&reports)) error_val = -1; - } - if (reports.list.first) - BKE_reports_clear(&reports); + BKE_reports_clear(&reports); } WM_operator_properties_free(&ptr); diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c index 02a87450a06..4fa72fe18bc 100644 --- a/source/blender/python/intern/bpy_operator_wrap.c +++ b/source/blender/python/intern/bpy_operator_wrap.c @@ -208,12 +208,12 @@ static int PYTHON_OT_generic(int mode, bContext *C, wmOperator *op, wmEvent *eve CollectionPropertyIterator iter; const char *arg_name; - iterprop= RNA_struct_iterator_property(op->ptr); + iterprop= RNA_struct_iterator_property(op->ptr->type); RNA_property_collection_begin(op->ptr, iterprop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { prop= iter.ptr.data; - arg_name= RNA_property_identifier(&iter.ptr, prop); + arg_name= RNA_property_identifier(prop); if (strcmp(arg_name, "rna_type")==0) continue; diff --git a/source/blender/python/intern/bpy_panel_wrap.c b/source/blender/python/intern/bpy_panel_wrap.c deleted file mode 100644 index a8409d44553..00000000000 --- a/source/blender/python/intern/bpy_panel_wrap.c +++ /dev/null @@ -1,252 +0,0 @@ -/** - * $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): Campbell Barton - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "bpy_panel_wrap.h" -#include "bpy_rna.h" -#include "bpy_util.h" -#include "bpy_compat.h" - -#include "RNA_define.h" -#include "RNA_enum_types.h" - -#include "BLI_listbase.h" -#include "BKE_context.h" -#include "BKE_screen.h" -#include "DNA_screen_types.h" -#include "MEM_guardedalloc.h" -#include "ED_screen.h" -#include "WM_api.h" -#include "WM_types.h" - -#define PYPANEL_ATTR_UINAME "__label__" -#define PYPANEL_ATTR_IDNAME "__name__" /* use pythons class name */ -#define PYPANEL_ATTR_CONTEXT "__context__" - -#define PYPANEL_DRAW 1 -#define PYPANEL_POLL 2 - -extern void BPY_update_modules( void ); //XXX temp solution - -static int PyPanel_generic(int mode, const bContext *C, Panel *pnl) -{ - PyObject *py_class= (PyObject *)(pnl->type->py_data); - - PyObject *args; - PyObject *ret= NULL, *py_class_instance, *item; - PointerRNA panelptr; - int ret_flag= 0; - - PyGILState_STATE gilstate = PyGILState_Ensure(); - - BPY_update_modules(); // XXX - the RNA pointers can change so update before running, would like a nicer solutuon for this. - - args = PyTuple_New(1); - RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->srna, pnl, &panelptr); - PyTuple_SET_ITEM(args, 0, pyrna_struct_CreatePyObject(&panelptr)); - py_class_instance = PyObject_Call(py_class, args, NULL); - Py_DECREF(args); - - if (py_class_instance) { /* Initializing the class worked, now run its invoke function */ - PointerRNA context_ptr; - - if (mode==PYPANEL_DRAW) { - item= PyObject_GetAttrString(py_class, "draw"); - } - else if (mode==PYPANEL_POLL) { - item= PyObject_GetAttrString(py_class, "poll"); - } - args = PyTuple_New(2); - PyTuple_SET_ITEM(args, 0, py_class_instance); - - RNA_pointer_create(NULL, &RNA_Context, (void *)C, &context_ptr); - - PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&context_ptr)); - - ret = PyObject_Call(item, args, NULL); - - /* args is decref'd from item */ - Py_DECREF(item); - } - - if (ret == NULL) { /* covers py_class_instance failing too */ - PyErr_Print(); /* XXX use reporting api? */ - } - else { - if (mode==PYPANEL_POLL) { - if (PyBool_Check(ret) == 0) { - PyErr_SetString(PyExc_ValueError, "Python poll function return value "); - PyErr_Print(); /* XXX use reporting api? */ - } - else { - ret_flag= ret==Py_True ? 1:0; - } - } - else { - //XXX - draw stuff - } - - Py_DECREF(ret); - } - PyGILState_Release(gilstate); - - return ret_flag; -} - -static void PyPanel_draw(const bContext *C, Panel *pnl) -{ - PyPanel_generic(PYPANEL_DRAW, C, pnl); -} - -static int PyPanel_poll(const bContext *C) -{ - //return PyPanel_generic(PYPANEL_POLL, C, NULL); - return 1; // XXX we need the panel type to access the PyObject grr! -} - -/* pyOperators - Operators defined IN Python */ -PyObject *PyPanel_wrap_add(PyObject *self, PyObject *args) -{ - bContext *C; - PyObject *item; - PyObject *py_class; - PyObject *base_class; - char *space_identifier; - char *region_identifier; - char *idname; - int space_value; - int region_value; - - PanelType *pt; - SpaceType *st; - ARegionType *art; - - static struct BPY_class_attr_check pypnl_class_attr_values[]= { - {PYPANEL_ATTR_IDNAME, 's', 0, 0}, - {PYPANEL_ATTR_UINAME, 's', 0, 0}, - {PYPANEL_ATTR_CONTEXT, 's', 0, 0}, - {"draw", 'f', 2, 0}, /* Do we need the Panel struct?, could be an extra arg */ - {"poll", 'f', 2, BPY_CLASS_ATTR_OPTIONAL}, - {NULL, 0, 0, 0}}; - - enum { - PYPANEL_ATTR_IDNAME_IDX=0, - PYPANEL_ATTR_UINAME_IDX, - PYPANEL_ATTR_CONTEXT_IDX, - PYPANEL_ATTR_DRAW_IDX, - PYPANEL_ATTR_POLL_IDX - }; - - PyObject *pypnl_class_attrs[6]= {NULL, NULL, NULL, NULL, NULL, NULL}; - - if( !PyArg_ParseTuple( args, "Oss:addPanel", &py_class, &space_identifier, ®ion_identifier)) - return NULL; - - base_class = PyObject_GetAttrStringArgs(PyDict_GetItemString(PyEval_GetGlobals(), "bpy"), 2, "types", "Panel"); - Py_DECREF(base_class); - - /* Should this use a base class? */ - if (BPY_class_validate("Panel", py_class, base_class, pypnl_class_attr_values, pypnl_class_attrs) < 0) { - return NULL; /* BPY_class_validate sets the error */ - } - - if (RNA_enum_value_from_id(space_type_items, space_identifier, &space_value)==0) { - char *cstring= BPy_enum_as_string(space_type_items); - PyErr_Format( PyExc_AttributeError, "SpaceType \"%s\" is not one of [%s]", space_identifier, cstring); - MEM_freeN(cstring); - return NULL; - } - - if (RNA_enum_value_from_id(region_type_items, region_identifier, ®ion_value)==0) { - char *cstring= BPy_enum_as_string(region_type_items); - PyErr_Format( PyExc_AttributeError, "RegionType \"%s\" is not one of [%s]", region_identifier, cstring); - MEM_freeN(cstring); - return NULL; - } - - st= BKE_spacetype_from_id(space_value); - -#if 0 - // for printing what panels we have - for(art= st->regiontypes.first; art; art= art->next) { - - printf("REG %d\n", art->regionid); - - for(pt= art->paneltypes.first; pt; pt= pt->next) { - printf("\tREG %s %s - %s\n", pt->idname, pt->name, pt->context); - } - } -#endif - - for(art= st->regiontypes.first; art; art= art->next) { - if (art->regionid==region_value) - break; - } - - if (art==NULL) { - PyErr_Format( PyExc_AttributeError, "SpaceType \"%s\" does not have a UI region '%s'", space_identifier, region_identifier); - return NULL; - } - - idname= _PyUnicode_AsString(pypnl_class_attrs[PYPANEL_ATTR_IDNAME_IDX]); - - for(pt=art->paneltypes.first; pt; pt=pt->next) - if(strcmp(pt->idname, idname) == 0) - break; - - if(!pt) { - pt= MEM_callocN(sizeof(PanelType), "python buttons panel"); - pt->srna= RNA_def_struct(&BLENDER_RNA, pt->idname, "Panel"); - BLI_addtail(&art->paneltypes, pt); - } - - pt->idname= idname; - - item= pypnl_class_attrs[PYPANEL_ATTR_UINAME_IDX]; - pt->name= item? _PyUnicode_AsString(item): pt->idname; - pt->context= _PyUnicode_AsString(pypnl_class_attrs[PYPANEL_ATTR_CONTEXT_IDX]); - - if (pypnl_class_attrs[PYPANEL_ATTR_POLL_IDX]) - pt->poll= PyPanel_poll; - else - pt->poll= NULL; - - pt->draw= PyPanel_draw; - - Py_INCREF(py_class); - pt->py_data= (void *)py_class; - RNA_struct_py_type_set(pt->srna, py_class); - - item= PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__"); - if(item && (C=(bContext *)PyCObject_AsVoidPtr(item))) - WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL); - - Py_RETURN_NONE; -} - -PyObject *PyPanel_wrap_remove(PyObject *self, PyObject *args) -{ - // XXX - todo - Py_RETURN_NONE; -} - diff --git a/source/blender/python/intern/bpy_panel_wrap.h b/source/blender/python/intern/bpy_panel_wrap.h deleted file mode 100644 index 42b24703d00..00000000000 --- a/source/blender/python/intern/bpy_panel_wrap.h +++ /dev/null @@ -1,36 +0,0 @@ - -/** - * $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): Campbell Barton - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef BPY_PANEL_WRAP_H -#define BPY_PANEL_WRAP_H - -#include <Python.h> - -/* these are used for operator methods, used by bpy_operator.c */ - -PyObject *PyPanel_wrap_add(PyObject *self, PyObject *args); -PyObject *PyPanel_wrap_remove(PyObject *self, PyObject *args); - -#endif diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 87ce11b76d9..627b240c65d 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -28,13 +28,16 @@ //#include "blendef.h" #include "BLI_dynstr.h" #include "BLI_listbase.h" +#include "BLI_string.h" #include "float.h" /* FLT_MIN/MAX */ +#include "RNA_access.h" #include "RNA_define.h" /* for defining our own rna */ #include "MEM_guardedalloc.h" #include "BKE_context.h" #include "BKE_global.h" /* evil G.* */ +#include "BKE_report.h" static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b ) { @@ -74,13 +77,13 @@ static PyObject *pyrna_struct_repr( BPy_StructRNA * self ) char str[512]; /* print name if available */ - prop= RNA_struct_name_property(&self->ptr); + prop= RNA_struct_name_property(self->ptr.type); if(prop) { RNA_property_string_get(&self->ptr, prop, str); - return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(&self->ptr), str); + return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(self->ptr.type), str); } - return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\"]", RNA_struct_identifier(&self->ptr)); + return PyUnicode_FromFormat( "[BPy_StructRNA \"%s\"]", RNA_struct_identifier(self->ptr.type)); } static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self ) @@ -90,19 +93,19 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self ) char str[512]; /* if a pointer, try to print name of pointer target too */ - if(RNA_property_type(&self->ptr, self->prop) == PROP_POINTER) { + if(RNA_property_type(self->prop) == PROP_POINTER) { ptr= RNA_property_pointer_get(&self->ptr, self->prop); if(ptr.data) { - prop= RNA_struct_name_property(&ptr); + prop= RNA_struct_name_property(ptr.type); if(prop) { RNA_property_string_get(&ptr, prop, str); - return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop), str); + return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\" -> \"%s\" ]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), str); } } } - return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(&self->ptr), RNA_property_identifier(&self->ptr, self->prop)); + return PyUnicode_FromFormat( "[BPy_PropertyRNA \"%s\" -> \"%s\"]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop)); } static long pyrna_struct_hash( BPy_StructRNA * self ) @@ -136,8 +139,8 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) { PyObject *ret; - int type = RNA_property_type(ptr, prop); - int len = RNA_property_array_length(ptr, prop); + int type = RNA_property_type(prop); + int len = RNA_property_array_length(prop); if (len > 0) { /* resolve the array from a new pytype */ @@ -221,8 +224,8 @@ PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func) int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value) { /* XXX hard limits should be checked here */ - int type = RNA_property_type(ptr, prop); - int len = RNA_property_array_length(ptr, prop); + int type = RNA_property_type(prop); + int len = RNA_property_array_length(prop); if (len > 0) { PyObject *item; @@ -402,12 +405,12 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v } case PROP_POINTER: { - StructRNA *ptype= RNA_property_pointer_type(ptr, prop); + StructRNA *ptype= RNA_property_pointer_type(prop); if(!BPy_StructRNA_Check(value)) { PointerRNA tmp; RNA_pointer_create(NULL, ptype, NULL, &tmp); - PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(&tmp)); + PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(tmp.type)); return -1; } else { BPy_StructRNA *param= (BPy_StructRNA*)value; @@ -416,7 +419,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v if(ptype == &RNA_AnyType) { *((PointerRNA*)data)= param->ptr; } - else if(RNA_struct_is_a(¶m->ptr, ptype)) { + else if(RNA_struct_is_a(param->ptr.type, ptype)) { *((void**)data)= param->ptr.data; } else { raise_error= 1; @@ -424,12 +427,12 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v } else { /* data==NULL, assign to RNA */ - if(RNA_struct_is_a(¶m->ptr, ptype)) { + if(RNA_struct_is_a(param->ptr.type, ptype)) { RNA_property_pointer_set(ptr, prop, param->ptr); } else { PointerRNA tmp; RNA_pointer_create(NULL, ptype, NULL, &tmp); - PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(&tmp)); + PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(tmp.type)); return -1; } } @@ -437,7 +440,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v if(raise_error) { PointerRNA tmp; RNA_pointer_create(NULL, ptype, NULL, &tmp); - PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(&tmp)); + PyErr_Format(PyExc_TypeError, "expected a %s type", RNA_struct_identifier(tmp.type)); return -1; } } @@ -460,7 +463,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v static PyObject * pyrna_prop_to_py_index(PointerRNA *ptr, PropertyRNA *prop, int index) { PyObject *ret; - int type = RNA_property_type(ptr, prop); + int type = RNA_property_type(prop); /* see if we can coorce into a python type - PropertyType */ switch (type) { @@ -485,7 +488,7 @@ static PyObject * pyrna_prop_to_py_index(PointerRNA *ptr, PropertyRNA *prop, int static int pyrna_py_to_prop_index(PointerRNA *ptr, PropertyRNA *prop, int index, PyObject *value) { int ret = 0; - int type = RNA_property_type(ptr, prop); + int type = RNA_property_type(prop); /* see if we can coorce into a python type - PropertyType */ switch (type) { @@ -537,10 +540,10 @@ static Py_ssize_t pyrna_prop_len( BPy_PropertyRNA * self ) { Py_ssize_t len; - if (RNA_property_type(&self->ptr, self->prop) == PROP_COLLECTION) { + if (RNA_property_type(self->prop) == PROP_COLLECTION) { len = RNA_property_collection_length(&self->ptr, self->prop); } else { - len = RNA_property_array_length(&self->ptr, self->prop); + len = RNA_property_array_length(self->prop); if (len==0) { /* not an array*/ PyErr_SetString(PyExc_AttributeError, "len() only available for collection RNA types"); @@ -567,7 +570,7 @@ static PyObject *pyrna_prop_subscript( BPy_PropertyRNA * self, PyObject *key ) return NULL; } - if (RNA_property_type(&self->ptr, self->prop) == PROP_COLLECTION) { + if (RNA_property_type(self->prop) == PROP_COLLECTION) { int ok; if (keyname) ok = RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr); else ok = RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum, &newptr); @@ -583,7 +586,7 @@ static PyObject *pyrna_prop_subscript( BPy_PropertyRNA * self, PyObject *key ) PyErr_SetString(PyExc_AttributeError, "string keys are only supported for collections"); ret = NULL; } else { - int len = RNA_property_array_length(&self->ptr, self->prop); + int len = RNA_property_array_length(self->prop); if (len==0) { /* not an array*/ PyErr_Format(PyExc_AttributeError, "not an array or collection %d", keynum); @@ -609,7 +612,7 @@ static int pyrna_prop_assign_subscript( BPy_PropertyRNA * self, PyObject *key, P char *keyname = NULL; if (!RNA_property_editable(&self->ptr, self->prop)) { - PyErr_Format( PyExc_AttributeError, "PropertyRNA - attribute \"%s\" from \"%s\" is read-only", RNA_property_identifier(&self->ptr, self->prop), RNA_struct_identifier(&self->ptr) ); + PyErr_Format( PyExc_AttributeError, "PropertyRNA - attribute \"%s\" from \"%s\" is read-only", RNA_property_identifier(self->prop), RNA_struct_identifier(self->ptr.type) ); return -1; } @@ -622,14 +625,14 @@ static int pyrna_prop_assign_subscript( BPy_PropertyRNA * self, PyObject *key, P return -1; } - if (RNA_property_type(&self->ptr, self->prop) == PROP_COLLECTION) { + if (RNA_property_type(self->prop) == PROP_COLLECTION) { PyErr_SetString(PyExc_AttributeError, "PropertyRNA - assignment is not supported for collections (yet)"); ret = -1; } else if (keyname) { PyErr_SetString(PyExc_AttributeError, "PropertyRNA - string keys are only supported for collections"); ret = -1; } else { - int len = RNA_property_array_length(&self->ptr, self->prop); + int len = RNA_property_array_length(self->prop); if (len==0) { /* not an array*/ PyErr_Format(PyExc_AttributeError, "PropertyRNA - not an array or collection %d", keynum); @@ -693,11 +696,11 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self) PropertyRNA *nameprop; char name[256], *nameptr; - iterprop= RNA_struct_iterator_property(&self->ptr); + iterprop= RNA_struct_iterator_property(self->ptr.type); RNA_property_collection_begin(&self->ptr, iterprop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) { + if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name)); pystring = PyUnicode_FromString(nameptr); @@ -725,7 +728,7 @@ static PyObject *pyrna_struct_dir(BPy_StructRNA * self) RNA_property_collection_begin(&tptr, iterprop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - pystring = PyUnicode_FromString(RNA_function_identifier(&tptr, iter.ptr.data)); + pystring = PyUnicode_FromString(RNA_function_identifier(iter.ptr.data)); PyList_Append(ret, pystring); Py_DECREF(pystring); } @@ -814,7 +817,7 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje } if (!RNA_property_editable(&self->ptr, prop)) { - PyErr_Format( PyExc_AttributeError, "StructRNA - Attribute \"%s\" from \"%s\" is read-only", RNA_property_identifier(&self->ptr, prop), RNA_struct_identifier(&self->ptr) ); + PyErr_Format( PyExc_AttributeError, "StructRNA - Attribute \"%s\" from \"%s\" is read-only", RNA_property_identifier(prop), RNA_struct_identifier(self->ptr.type) ); return -1; } @@ -825,7 +828,7 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje PyObject *pyrna_prop_keys(BPy_PropertyRNA *self) { PyObject *ret; - if (RNA_property_type(&self->ptr, self->prop) != PROP_COLLECTION) { + if (RNA_property_type(self->prop) != PROP_COLLECTION) { PyErr_SetString( PyExc_TypeError, "keys() is only valid for collection types" ); ret = NULL; } else { @@ -838,7 +841,7 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self) RNA_property_collection_begin(&self->ptr, self->prop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) { + if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name)); /* add to python list */ @@ -860,7 +863,7 @@ PyObject *pyrna_prop_keys(BPy_PropertyRNA *self) PyObject *pyrna_prop_items(BPy_PropertyRNA *self) { PyObject *ret; - if (RNA_property_type(&self->ptr, self->prop) != PROP_COLLECTION) { + if (RNA_property_type(self->prop) != PROP_COLLECTION) { PyErr_SetString( PyExc_TypeError, "items() is only valid for collection types" ); ret = NULL; } else { @@ -873,7 +876,7 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self) RNA_property_collection_begin(&self->ptr, self->prop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) { + if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { nameptr= RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name)); /* add to python list */ @@ -896,7 +899,7 @@ PyObject *pyrna_prop_items(BPy_PropertyRNA *self) PyObject *pyrna_prop_values(BPy_PropertyRNA *self) { PyObject *ret; - if (RNA_property_type(&self->ptr, self->prop) != PROP_COLLECTION) { + if (RNA_property_type(self->prop) != PROP_COLLECTION) { PyErr_SetString( PyExc_TypeError, "values() is only valid for collection types" ); ret = NULL; } else { @@ -908,7 +911,7 @@ PyObject *pyrna_prop_values(BPy_PropertyRNA *self) RNA_property_collection_begin(&self->ptr, self->prop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { - if(iter.ptr.data && (nameprop = RNA_struct_name_property(&iter.ptr))) { + if(iter.ptr.data && (nameprop = RNA_struct_name_property(iter.ptr.type))) { item = pyrna_struct_CreatePyObject(&iter.ptr); PyList_Append(ret, item); Py_DECREF(item); @@ -929,7 +932,7 @@ PyObject *pyrna_prop_iter(BPy_PropertyRNA *self) if (ret==NULL) { /* collection did not work, try array */ - int len = RNA_property_array_length(&self->ptr, self->prop); + int len = RNA_property_array_length(self->prop); if (len) { int i; @@ -1005,8 +1008,8 @@ static PyObject * pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *k PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) { PyObject *ret; - int type = RNA_property_type(ptr, prop); - int len = RNA_property_array_length(ptr, prop); + int type = RNA_property_type(prop); + int len = RNA_property_array_length(prop); int a; if(len > 0) { @@ -1066,7 +1069,7 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) case PROP_POINTER: { PointerRNA newptr; - StructRNA *type= RNA_property_pointer_type(ptr, prop); + StructRNA *type= RNA_property_pointer_type(prop); if(type == &RNA_AnyType) { /* in this case we get the full ptr */ @@ -1116,7 +1119,7 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw) /* setup */ RNA_pointer_create(NULL, &RNA_Function, self_func, &funcptr); - pret= RNA_function_return(self_ptr, self_func); + pret= RNA_function_return(self_func); tlen= PyTuple_GET_SIZE(args); parms= RNA_parameter_list_create(self_ptr, self_func); @@ -1131,8 +1134,8 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw) continue; } - pid= RNA_property_identifier(&funcptr, parm); - flag= RNA_property_flag(&funcptr, parm); + pid= RNA_property_identifier(parm); + flag= RNA_property_flag(parm); item= NULL; if ((i < tlen) && (flag & PROP_REQUIRED)) { @@ -1144,8 +1147,8 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw) if (item==NULL) { if(flag & PROP_REQUIRED) { - tid= RNA_struct_identifier(self_ptr); - fid= RNA_function_identifier(self_ptr, self_func); + tid= RNA_struct_identifier(self_ptr->type); + fid= RNA_function_identifier(self_func); PyErr_Format(PyExc_AttributeError, "%s.%s(): required parameter \"%s\" not specified", tid, fid, pid); err= -1; @@ -1355,6 +1358,21 @@ PyTypeObject pyrna_prop_Type = { NULL }; +static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna) +{ + PointerRNA ptr; + PyObject *item; + + RNA_struct_py_type_set(srna, (void *)newclass); /* Store for later use */ + + /* Not 100% needed but useful, + * having an instance within a type looks wrong however this instance IS an rna type */ + RNA_pointer_create(NULL, &RNA_Struct, srna, &ptr); + item = pyrna_struct_CreatePyObject(&ptr); + PyDict_SetItemString(((PyTypeObject *)newclass)->tp_dict, "__rna__", item); + Py_DECREF(item); + /* done with rna instance */ +} PyObject* pyrna_struct_Subtype(PointerRNA *ptr) { @@ -1365,7 +1383,7 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr) newclass= NULL; /* Nothing to do */ } else if ((newclass= RNA_struct_py_type_get(ptr->data))) { Py_INCREF(newclass); - } else if ((nameprop = RNA_struct_name_property(ptr))) { + } else if ((nameprop = RNA_struct_name_property(ptr->type))) { /* for now, return the base RNA type rather then a real module */ /* Assume RNA_struct_py_type_get(ptr->data) was alredy checked */ @@ -1376,7 +1394,7 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr) - myClass = type(name='myClass', bases=(myBase,), dict={'some':'value'}) */ char name[256], *nameptr; - const char *descr= RNA_struct_ui_description(ptr); + const char *descr= RNA_struct_ui_description(ptr->type); PyObject *args = PyTuple_New(3); PyObject *bases = PyTuple_New(1); @@ -1413,16 +1431,8 @@ PyObject* pyrna_struct_Subtype(PointerRNA *ptr) newclass = PyObject_CallObject((PyObject *)&PyType_Type, args); Py_DECREF(args); - if (newclass) { - RNA_struct_py_type_set(ptr->data, (void *)newclass); /* Store for later use */ - - /* Not 100% needed but useful, - * having an instance within a type looks wrong however this instance IS an rna type */ - item = pyrna_struct_CreatePyObject(ptr); - PyDict_SetItemString(((PyTypeObject *)newclass)->tp_dict, "__rna__", item); - Py_DECREF(item); - /* done with rna instance */ - } + if (newclass) + pyrna_subtype_set_rna(newclass, ptr->data); if (name != nameptr) MEM_freeN(nameptr); @@ -1545,6 +1555,8 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA * self, PyObject *pyna static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self); static struct PyMethodDef pyrna_basetype_methods[] = { {"__dir__", (PyCFunction)pyrna_basetype_dir, METH_NOARGS, ""}, + {"register", (PyCFunction)pyrna_basetype_register, METH_VARARGS, ""}, + {"unregister", (PyCFunction)pyrna_basetype_unregister, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; @@ -1676,3 +1688,356 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw) return ret; } } + +/*-------------------- Type Registration ------------------------*/ + +static int rna_function_arg_count(FunctionRNA *func) +{ + const ListBase *lb= RNA_function_defined_parameters(func); + PropertyRNA *parm; + Link *link; + int count= 1; + + for(link=lb->first; link; link=link->next) { + parm= (PropertyRNA*)link; + if(!(RNA_property_flag(parm) & PROP_RETURN)) + count++; + } + + return count; +} + +static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_function) +{ + const ListBase *lb; + Link *link; + FunctionRNA *func; + PropertyRNA *prop; + StructRNA *srna= dummyptr->type; + const char *class_type= RNA_struct_identifier(srna); + PyObject *py_class= (PyObject*)py_data; + PyObject *base_class= RNA_struct_py_type_get(srna); + PyObject *item, *fitem; + PyObject *py_arg_count; + int i, flag, arg_count, func_arg_count; + char identifier[128]; + + if (base_class) { + if (!PyObject_IsSubclass(py_class, base_class)) { + PyObject *name= PyObject_GetAttrString(base_class, "__name__"); + PyErr_Format( PyExc_AttributeError, "expected %s subclass of class \"%s\"", class_type, name ? _PyUnicode_AsString(name):"<UNKNOWN>"); + Py_XDECREF(name); + return -1; + } + } + + /* verify callback functions */ + lb= RNA_struct_defined_functions(srna); + i= 0; + for(link=lb->first; link; link=link->next) { + func= (FunctionRNA*)link; + flag= RNA_function_flag(func); + + if(!(flag & FUNC_REGISTER)) + continue; + + item = PyObject_GetAttrString(py_class, RNA_function_identifier(func)); + + have_function[i]= (item != NULL); + i++; + + if (item==NULL) { + if ((flag & FUNC_REGISTER_OPTIONAL)==0) { + PyErr_Format( PyExc_AttributeError, "expected %s class to have an \"%s\" attribute", class_type, RNA_function_identifier(func)); + return -1; + } + + PyErr_Clear(); + } + else { + Py_DECREF(item); /* no need to keep a ref, the class owns it */ + + if (PyMethod_Check(item)) + fitem= PyMethod_Function(item); /* py 2.x */ + else + fitem= item; /* py 3.x */ + + if (PyFunction_Check(fitem)==0) { + PyErr_Format( PyExc_AttributeError, "expected %s class \"%s\" attribute to be a function", class_type, RNA_function_identifier(func)); + return -1; + } + + func_arg_count= rna_function_arg_count(func); + + if (func_arg_count >= 0) { /* -1 if we dont care*/ + py_arg_count = PyObject_GetAttrString(PyFunction_GET_CODE(fitem), "co_argcount"); + arg_count = PyLong_AsSsize_t(py_arg_count); + Py_DECREF(py_arg_count); + + if (arg_count != func_arg_count) { + PyErr_Format( PyExc_AttributeError, "expected %s class \"%s\" function to have %d args", class_type, RNA_function_identifier(func), func_arg_count); + return -1; + } + } + } + } + + /* verify properties */ + lb= RNA_struct_defined_properties(srna); + for(link=lb->first; link; link=link->next) { + prop= (PropertyRNA*)link; + flag= RNA_property_flag(prop); + + if(!(flag & PROP_REGISTER)) + continue; + + BLI_snprintf(identifier, sizeof(identifier), "__%s__", RNA_property_identifier(prop)); + item = PyObject_GetAttrString(py_class, identifier); + + if (item==NULL) { + if(strcmp(identifier, "__idname__") == 0) { + item= PyObject_GetAttrString(py_class, "__name__"); + + if(item) { + Py_DECREF(item); /* no need to keep a ref, the class owns it */ + + if(pyrna_py_to_prop(dummyptr, prop, NULL, item) != 0) + return -1; + } + } + + if (item==NULL && (flag & PROP_REGISTER_OPTIONAL)==0) { + PyErr_Format( PyExc_AttributeError, "expected %s class to have an \"%s\" attribute", class_type, identifier); + return -1; + } + + PyErr_Clear(); + } + else { + Py_DECREF(item); /* no need to keep a ref, the class owns it */ + + if(pyrna_py_to_prop(dummyptr, prop, NULL, item) != 0) + return -1; + } + } + + return 0; +} + +extern void BPY_update_modules( void ); //XXX temp solution + +static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) +{ + PyObject *args; + PyObject *ret= NULL, *py_class, *py_class_instance, *item, *parmitem; + PropertyRNA *pret= NULL, *parm; + ParameterIterator iter; + PointerRNA funcptr; + void *retdata= NULL; + int err= 0, i, flag; + + PyGILState_STATE gilstate = PyGILState_Ensure(); + + BPY_update_modules(); // XXX - the RNA pointers can change so update before running, would like a nicer solution for this. + + py_class= RNA_struct_py_type_get(ptr->type); + + args = PyTuple_New(1); + PyTuple_SET_ITEM(args, 0, pyrna_struct_CreatePyObject(ptr)); + py_class_instance = PyObject_Call(py_class, args, NULL); + Py_DECREF(args); + + if (py_class_instance) { /* Initializing the class worked, now run its invoke function */ + item= PyObject_GetAttrString(py_class, RNA_function_identifier(func)); + flag= RNA_function_flag(func); + + if(item) { + pret= RNA_function_return(func); + RNA_pointer_create(NULL, &RNA_Function, func, &funcptr); + + args = PyTuple_New(rna_function_arg_count(func)); + PyTuple_SET_ITEM(args, 0, py_class_instance); + + RNA_parameter_list_begin(parms, &iter); + + /* parse function parameters */ + for (i= 1; iter.valid; RNA_parameter_list_next(&iter)) { + parm= iter.parm; + + if (parm==pret) { + retdata= iter.data; + continue; + } + + parmitem= pyrna_param_to_py(&funcptr, parm, iter.data); + PyTuple_SET_ITEM(args, i, parmitem); + i++; + } + + ret = PyObject_Call(item, args, NULL); + + /* args is decref'd from item */ + Py_DECREF(item); + } + else { + Py_DECREF(py_class_instance); + PyErr_Format(PyExc_AttributeError, "could not find function %s in %s to execute callback.", RNA_function_identifier(func), RNA_struct_identifier(ptr->type)); + err= -1; + } + } + else { + PyErr_Format(PyExc_AttributeError, "could not create instance of %s to call callback function %s.", RNA_struct_identifier(ptr->type), RNA_function_identifier(func)); + err= -1; + } + + if (ret == NULL) { /* covers py_class_instance failing too */ + PyErr_Print(); /* XXX use reporting api? */ + err= -1; + } + else { + if(retdata) + err= pyrna_py_to_prop(&funcptr, pret, retdata, ret); + Py_DECREF(ret); + } + + PyGILState_Release(gilstate); + + return err; +} + +static void bpy_class_free(void *pyob_ptr) +{ + Py_DECREF((PyObject *)pyob_ptr); +} + +PyObject *pyrna_basetype_register(PyObject *self, PyObject *args) +{ + bContext *C= NULL; + PyObject *py_class, *item; + ReportList reports; + StructRegisterFunc reg; + BPy_StructRNA *py_srna; + StructRNA *srna; + + if(!PyArg_ParseTuple(args, "O:register", &py_class)) + return NULL; + + if(!PyType_Check(py_class)) { + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no a Type object)."); + return NULL; + } + + /* check we got an __rna__ attribute */ + item= PyObject_GetAttrString(py_class, "__rna__"); + + if(!item || !BPy_StructRNA_Check(item)) { + if(item) { + Py_DECREF(item); + } + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no __rna__ property)."); + return NULL; + } + + /* check the __rna__ attribute has the right type */ + Py_DECREF(item); + py_srna= (BPy_StructRNA*)item; + + if(py_srna->ptr.type != &RNA_Struct) { + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (not a Struct)."); + return NULL; + } + + /* check that we have a register callback for this type */ + reg= RNA_struct_register(py_srna->ptr.data); + + if(!reg) { + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no register supported)."); + return NULL; + } + + /* get the context, so register callback can do necessary refreshes */ + item= PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__"); + + if(item) { + C= (bContext*)PyCObject_AsVoidPtr(item); + Py_DECREF(item); + } + + /* call the register callback */ + BKE_reports_init(&reports, RPT_PRINT); + srna= reg(C, &reports, py_class, bpy_class_validate, bpy_class_call, bpy_class_free); + + if(!srna) { + BPy_reports_to_error(&reports); + BKE_reports_clear(&reports); + return NULL; + } + + BKE_reports_clear(&reports); + + pyrna_subtype_set_rna(py_class, srna); + Py_INCREF(py_class); + + Py_RETURN_NONE; +} + +PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args) +{ + bContext *C= NULL; + PyObject *py_class, *item; + BPy_StructRNA *py_srna; + StructUnregisterFunc unreg; + + if(!PyArg_ParseTuple(args, "O:register", &py_class)) + return NULL; + + if(!PyType_Check(py_class)) { + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no a Type object)."); + return NULL; + } + + /* check we got an __rna__ attribute */ + item= PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "__rna__"); + + if(!item || !BPy_StructRNA_Check(item)) { + if(item) { + Py_DECREF(item); + } + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no __rna__ property)."); + return NULL; + } + + /* check the __rna__ attribute has the right type */ + Py_DECREF(item); + py_srna= (BPy_StructRNA*)item; + + if(py_srna->ptr.type != &RNA_Struct) { + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (not a Struct)."); + return NULL; + } + + /* check that we have a unregister callback for this type */ + unreg= RNA_struct_unregister(py_srna->ptr.data); + + if(!unreg) { + PyErr_SetString(PyExc_AttributeError, "expected a Type subclassed from a registerable rna type (no unregister supported)."); + return NULL; + } + + /* get the context, so register callback can do necessary refreshes */ + item= PyDict_GetItemString(PyEval_GetGlobals(), "__bpy_context__"); + + if(item) { + C= (bContext*)PyCObject_AsVoidPtr(item); + Py_DECREF(item); + } + + /* call unregister */ + unreg(C, py_srna->ptr.data); + + /* remove reference to old type */ + Py_DECREF(py_class); + + Py_RETURN_NONE; +} + diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 5ddaf991a51..a97d450fb2f 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -76,5 +76,8 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw); PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw); PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw); +/* function for registering types */ +PyObject *pyrna_basetype_register(PyObject *self, PyObject *args); +PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args); #endif diff --git a/source/blender/python/intern/bpy_ui.c b/source/blender/python/intern/bpy_ui.c index b53cc523f05..e7143e8f84c 100644 --- a/source/blender/python/intern/bpy_ui.c +++ b/source/blender/python/intern/bpy_ui.c @@ -27,7 +27,6 @@ #include "bpy_rna.h" /* for rna buttons */ #include "bpy_operator.h" /* for setting button operator properties */ #include "bpy_compat.h" -#include "bpy_panel_wrap.h" /* for setting button operator properties */ #include "WM_types.h" /* for WM_OP_INVOKE_DEFAULT & friends */ @@ -431,9 +430,6 @@ static struct PyMethodDef ui_methods[] = { {"getSpacePtr", (PyCFunction)Method_getSpacePtr, METH_NOARGS, ""}, {"getWindowPtr", (PyCFunction)Method_getWindowPtr, METH_NOARGS, ""}, - /* Adding panels should be moved, at the moment there is no obvious place as there is with operators */ - {"addPanel", (PyCFunction)PyPanel_wrap_add, METH_VARARGS, ""}, - {"removePanel", (PyCFunction)PyPanel_wrap_remove, METH_VARARGS, ""}, {NULL, NULL, 0, NULL} }; diff --git a/source/blender/python/intern/bpy_util.c b/source/blender/python/intern/bpy_util.c index 0623124009c..66cf244e3bd 100644 --- a/source/blender/python/intern/bpy_util.c +++ b/source/blender/python/intern/bpy_util.c @@ -22,10 +22,12 @@ * ***** END GPL LICENSE BLOCK ***** */ - +#include "DNA_listBase.h" +#include "RNA_access.h" #include "bpy_util.h" #include "BLI_dynstr.h" #include "MEM_guardedalloc.h" +#include "BKE_report.h" PyObject *BPY_flag_to_list(struct BPY_flag_def *flagdef, int flag) { @@ -241,7 +243,6 @@ PyObject *PyObject_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...) return item; } - int BPY_class_validate(const char *class_type, PyObject *class, PyObject *base_class, BPY_class_attr_check* class_attrs, PyObject **py_class_attrs) { PyObject *item, *fitem; @@ -333,3 +334,18 @@ char *BPy_enum_as_string(EnumPropertyItem *item) BLI_dynstr_free(dynstr); return cstring; } + +int BPy_reports_to_error(ReportList *reports) +{ + char *report_str; + + report_str= BKE_reports_string(reports, RPT_ERROR); + + if(report_str) { + PyErr_SetString(PyExc_SystemError, report_str); + MEM_freeN(report_str); + } + + return (report_str != NULL); +} + diff --git a/source/blender/python/intern/bpy_util.h b/source/blender/python/intern/bpy_util.h index 9ce7a17b9e3..db31f403714 100644 --- a/source/blender/python/intern/bpy_util.h +++ b/source/blender/python/intern/bpy_util.h @@ -31,6 +31,7 @@ #include "RNA_types.h" /* for EnumPropertyItem only */ struct EnumPropertyItem; +struct ReportList; /* for internal use only, so python can interchange a sequence of strings with flags */ typedef struct BPY_flag_def { @@ -70,4 +71,7 @@ char *BPy_enum_as_string(struct EnumPropertyItem *item); #define BLANK_PYTHON_TYPE {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +/* error reporting */ +int BPy_reports_to_error(struct ReportList *reports); + #endif diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 36b442c6c2f..c8a0dbd018a 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -148,12 +148,12 @@ char *WM_operator_pystring(wmOperator *op) BLI_dynstr_appendf(dynstr, "%s(", op->idname); - iterprop= RNA_struct_iterator_property(op->ptr); + iterprop= RNA_struct_iterator_property(op->ptr->type); RNA_property_collection_begin(op->ptr, iterprop, &iter); for(; iter.valid; RNA_property_collection_next(&iter)) { prop= iter.ptr.data; - arg_name= RNA_property_identifier(&iter.ptr, prop); + arg_name= RNA_property_identifier(prop); if (strcmp(arg_name, "rna_type")==0) continue; @@ -206,7 +206,7 @@ int WM_menu_invoke(bContext *C, wmOperator *op, wmEvent *event) if(prop==NULL) { printf("WM_menu_invoke: %s has no \"type\" enum property\n", op->type->idname); } - else if (RNA_property_type(op->ptr, prop) != PROP_ENUM) { + else if (RNA_property_type(prop) != PROP_ENUM) { printf("WM_menu_invoke: %s \"type\" is not an enum property\n", op->type->idname); } else { |