diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_main_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 410 |
1 files changed, 260 insertions, 150 deletions
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index f5c59aa583a..cf9415a75e7 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -71,6 +71,7 @@ #include "BKE_speaker.h" #include "BKE_movieclip.h" #include "BKE_mask.h" +#include "BKE_gpencil.h" #include "DNA_armature_types.h" #include "DNA_camera_types.h" @@ -92,48 +93,55 @@ #include "DNA_node_types.h" #include "DNA_movieclip_types.h" #include "DNA_mask_types.h" +#include "DNA_gpencil_types.h" #include "ED_screen.h" +#include "BLF_translation.h" + static Camera *rna_Main_cameras_new(Main *UNUSED(bmain), const char *name) { ID *id = BKE_camera_add(name); id_us_min(id); return (Camera *)id; } -static void rna_Main_cameras_remove(Main *bmain, ReportList *reports, struct Camera *camera) +static void rna_Main_cameras_remove(Main *bmain, ReportList *reports, PointerRNA *camera_ptr) { - if (ID_REAL_USERS(camera) <= 0) + Camera *camera = camera_ptr->data; + if (ID_REAL_USERS(camera) <= 0) { BKE_libblock_free(&bmain->camera, camera); - else - BKE_reportf(reports, RPT_ERROR, "Camera \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(camera_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Camera '%s' must have zero users to be removed, found %d", camera->id.name + 2, ID_REAL_USERS(camera)); - - /* XXX python now has invalid pointer? */ + } } static Scene *rna_Main_scenes_new(Main *UNUSED(bmain), const char *name) { return BKE_scene_add(name); } -static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, struct Scene *scene) +static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, PointerRNA *scene_ptr) { /* don't call BKE_libblock_free(...) directly */ - Scene *newscene; + Scene *scene = scene_ptr->data; + Scene *scene_new; + + if ((scene_new = scene->id.prev) || + (scene_new = scene->id.next)) + { + bScreen *sc = CTX_wm_screen(C); + if (sc->scene == scene) { + ED_screen_set_scene(C, sc, scene_new); + } - if (scene->id.prev) - newscene = scene->id.prev; - else if (scene->id.next) - newscene = scene->id.next; + BKE_scene_unlink(bmain, scene, scene_new); + RNA_POINTER_INVALIDATE(scene_ptr); + } else { - BKE_reportf(reports, RPT_ERROR, "Scene \"%s\" is the last, cant ve removed", scene->id.name + 2); - return; + BKE_reportf(reports, RPT_ERROR, "Scene '%s' is the last, cannot be removed", scene->id.name + 2); } - - if (CTX_wm_screen(C)->scene == scene) - ED_screen_set_scene(C, CTX_wm_screen(C), newscene); - - BKE_scene_unlink(bmain, scene, newscene); } static Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, const char *name, ID *data) @@ -147,7 +155,7 @@ static Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, co type = OB_MESH; break; case ID_CU: - type = BKE_curve_type_get((struct Curve *)data); + type = BKE_curve_type_get((Curve *)data); break; case ID_MB: type = OB_MBALL; @@ -173,7 +181,7 @@ static Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, co if (RNA_enum_id_from_value(id_type_items, GS(data->name), &idname) == 0) idname = "UNKNOWN"; - BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for a object", idname); + BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for an object", idname); return NULL; } } @@ -190,14 +198,16 @@ static Object *rna_Main_objects_new(Main *UNUSED(bmain), ReportList *reports, co return ob; } -static void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object) +static void rna_Main_objects_remove(Main *bmain, ReportList *reports, PointerRNA *object_ptr) { + Object *object = object_ptr->data; if (ID_REAL_USERS(object) <= 0) { BKE_object_unlink(object); /* needed or ID pointers to this are not cleared */ BKE_libblock_free(&bmain->object, object); + RNA_POINTER_INVALIDATE(object_ptr); } else { - BKE_reportf(reports, RPT_ERROR, "Object \"%s\" must have zero users to be removed, found %d", + BKE_reportf(reports, RPT_ERROR, "Object '%s' must have zero users to be removed, found %d", object->id.name + 2, ID_REAL_USERS(object)); } } @@ -208,15 +218,17 @@ static Material *rna_Main_materials_new(Main *UNUSED(bmain), const char *name) id_us_min(id); return (Material *)id; } -static void rna_Main_materials_remove(Main *bmain, ReportList *reports, struct Material *material) +static void rna_Main_materials_remove(Main *bmain, ReportList *reports, PointerRNA *material_ptr) { - if (ID_REAL_USERS(material) <= 0) + Material *material = material_ptr->data; + if (ID_REAL_USERS(material) <= 0) { BKE_libblock_free(&bmain->mat, material); - else - BKE_reportf(reports, RPT_ERROR, "Material \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(material_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Material '%s' must have zero users to be removed, found %d", material->id.name + 2, ID_REAL_USERS(material)); - - /* XXX python now has invalid pointer? */ + } } static bNodeTree *rna_Main_nodetree_new(Main *UNUSED(bmain), const char *name, int type) @@ -226,15 +238,17 @@ static bNodeTree *rna_Main_nodetree_new(Main *UNUSED(bmain), const char *name, i id_us_min(&tree->id); return tree; } -static void rna_Main_nodetree_remove(Main *bmain, ReportList *reports, struct bNodeTree *tree) +static void rna_Main_nodetree_remove(Main *bmain, ReportList *reports, PointerRNA *tree_ptr) { - if (ID_REAL_USERS(tree) <= 0) + bNodeTree *tree = tree_ptr->data; + if (ID_REAL_USERS(tree) <= 0) { BKE_libblock_free(&bmain->nodetree, tree); - else - BKE_reportf(reports, RPT_ERROR, "Node Tree \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(tree_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Node tree '%s' must have zero users to be removed, found %d", tree->id.name + 2, ID_REAL_USERS(tree)); - - /* XXX python now has invalid pointer? */ + } } static Mesh *rna_Main_meshes_new(Main *UNUSED(bmain), const char *name) @@ -243,15 +257,17 @@ static Mesh *rna_Main_meshes_new(Main *UNUSED(bmain), const char *name) id_us_min(&me->id); return me; } -void rna_Main_meshes_remove(Main *bmain, ReportList *reports, Mesh *mesh) +static void rna_Main_meshes_remove(Main *bmain, ReportList *reports, PointerRNA *mesh_ptr) { - if (ID_REAL_USERS(mesh) <= 0) + Mesh *mesh = mesh_ptr->data; + if (ID_REAL_USERS(mesh) <= 0) { BKE_libblock_free(&bmain->mesh, mesh); - else - BKE_reportf(reports, RPT_ERROR, "Mesh \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(mesh_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Mesh '%s' must have zero users to be removed, found %d", mesh->id.name + 2, ID_REAL_USERS(mesh)); - - /* XXX python now has invalid pointer? */ + } } static Lamp *rna_Main_lamps_new(Main *UNUSED(bmain), const char *name, int type) @@ -261,15 +277,17 @@ static Lamp *rna_Main_lamps_new(Main *UNUSED(bmain), const char *name, int type) id_us_min(&lamp->id); return lamp; } -static void rna_Main_lamps_remove(Main *bmain, ReportList *reports, Lamp *lamp) +static void rna_Main_lamps_remove(Main *bmain, ReportList *reports, PointerRNA *lamp_ptr) { - if (ID_REAL_USERS(lamp) <= 0) + Lamp *lamp = lamp_ptr->data; + if (ID_REAL_USERS(lamp) <= 0) { BKE_libblock_free(&bmain->lamp, lamp); - else - BKE_reportf(reports, RPT_ERROR, "Lamp \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(lamp_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Lamp '%s' must have zero users to be removed, found %d", lamp->id.name + 2, ID_REAL_USERS(lamp)); - - /* XXX python now has invalid pointer? */ + } } static Image *rna_Main_images_new(Main *UNUSED(bmain), const char *name, int width, int height, int alpha, int float_buffer) @@ -286,21 +304,24 @@ static Image *rna_Main_images_load(Main *UNUSED(bmain), ReportList *reports, con errno = 0; ima = BKE_image_load(filepath); - if (!ima) - BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s", filepath, - errno ? strerror(errno) : "Unsupported image format"); + if (!ima) { + BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath, + errno ? strerror(errno) : TIP_("unsupported image format")); + } return ima; } -static void rna_Main_images_remove(Main *bmain, ReportList *reports, Image *image) +static void rna_Main_images_remove(Main *bmain, ReportList *reports, PointerRNA *image_ptr) { - if (ID_REAL_USERS(image) <= 0) + Image *image = image_ptr->data; + if (ID_REAL_USERS(image) <= 0) { BKE_libblock_free(&bmain->image, image); - else - BKE_reportf(reports, RPT_ERROR, "Image \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(image_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Image '%s' must have zero users to be removed, found %d", image->id.name + 2, ID_REAL_USERS(image)); - - /* XXX python now has invalid pointer? */ + } } static Lattice *rna_Main_lattices_new(Main *UNUSED(bmain), const char *name) @@ -309,13 +330,17 @@ static Lattice *rna_Main_lattices_new(Main *UNUSED(bmain), const char *name) id_us_min(<->id); return lt; } -static void rna_Main_lattices_remove(Main *bmain, ReportList *reports, struct Lattice *lt) +static void rna_Main_lattices_remove(Main *bmain, ReportList *reports, PointerRNA *lt_ptr) { - if (ID_REAL_USERS(lt) <= 0) + Lattice *lt = lt_ptr->data; + if (ID_REAL_USERS(lt) <= 0) { BKE_libblock_free(&bmain->latt, lt); - else - BKE_reportf(reports, RPT_ERROR, "Lattice \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(lt_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Lattice '%s' must have zero users to be removed, found %d", lt->id.name + 2, ID_REAL_USERS(lt)); + } } static Curve *rna_Main_curves_new(Main *UNUSED(bmain), const char *name, int type) @@ -324,13 +349,17 @@ static Curve *rna_Main_curves_new(Main *UNUSED(bmain), const char *name, int typ id_us_min(&cu->id); return cu; } -static void rna_Main_curves_remove(Main *bmain, ReportList *reports, struct Curve *cu) +static void rna_Main_curves_remove(Main *bmain, ReportList *reports, PointerRNA *cu_ptr) { - if (ID_REAL_USERS(cu) <= 0) + Curve *cu = cu_ptr->data; + if (ID_REAL_USERS(cu) <= 0) { BKE_libblock_free(&bmain->curve, cu); - else - BKE_reportf(reports, RPT_ERROR, "Curve \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(cu_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Curve '%s' must have zero users to be removed, found %d", cu->id.name + 2, ID_REAL_USERS(cu)); + } } static MetaBall *rna_Main_metaballs_new(Main *UNUSED(bmain), const char *name) @@ -339,13 +368,17 @@ static MetaBall *rna_Main_metaballs_new(Main *UNUSED(bmain), const char *name) id_us_min(&mb->id); return mb; } -static void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, struct MetaBall *mb) +static void rna_Main_metaballs_remove(Main *bmain, ReportList *reports, PointerRNA *mb_ptr) { - if (ID_REAL_USERS(mb) <= 0) + MetaBall *mb = mb_ptr->data; + if (ID_REAL_USERS(mb) <= 0) { BKE_libblock_free(&bmain->mball, mb); - else - BKE_reportf(reports, RPT_ERROR, "Metaball \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(mb_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Metaball '%s' must have zero users to be removed, found %d", mb->id.name + 2, ID_REAL_USERS(mb)); + } } static VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char *filepath) @@ -356,21 +389,23 @@ static VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char * font = BKE_vfont_load(bmain, filepath); if (!font) - BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s", filepath, - errno ? strerror(errno) : "Unsupported font format"); + BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath, + errno ? strerror(errno) : TIP_("unsupported font format")); return font; } -static void rna_Main_fonts_remove(Main *bmain, ReportList *reports, VFont *vfont) +static void rna_Main_fonts_remove(Main *bmain, ReportList *reports, PointerRNA *vfont_ptr) { - if (ID_REAL_USERS(vfont) <= 0) + VFont *vfont = vfont_ptr->data; + if (ID_REAL_USERS(vfont) <= 0) { BKE_libblock_free(&bmain->vfont, vfont); - else - BKE_reportf(reports, RPT_ERROR, "Font \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(vfont_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Font '%s' must have zero users to be removed, found %d", vfont->id.name + 2, ID_REAL_USERS(vfont)); - - /* XXX python now has invalid pointer? */ + } } static Tex *rna_Main_textures_new(Main *UNUSED(bmain), const char *name, int type) @@ -380,13 +415,17 @@ static Tex *rna_Main_textures_new(Main *UNUSED(bmain), const char *name, int typ id_us_min(&tex->id); return tex; } -static void rna_Main_textures_remove(Main *bmain, ReportList *reports, struct Tex *tex) +static void rna_Main_textures_remove(Main *bmain, ReportList *reports, PointerRNA *tex_ptr) { - if (ID_REAL_USERS(tex) <= 0) + Tex *tex = tex_ptr->data; + if (ID_REAL_USERS(tex) <= 0) { BKE_libblock_free(&bmain->tex, tex); - else - BKE_reportf(reports, RPT_ERROR, "Texture \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(tex_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Texture '%s' must have zero users to be removed, found %d", tex->id.name + 2, ID_REAL_USERS(tex)); + } } static Brush *rna_Main_brushes_new(Main *UNUSED(bmain), const char *name) @@ -395,13 +434,17 @@ static Brush *rna_Main_brushes_new(Main *UNUSED(bmain), const char *name) id_us_min(&brush->id); return brush; } -static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, struct Brush *brush) +static void rna_Main_brushes_remove(Main *bmain, ReportList *reports, PointerRNA *brush_ptr) { - if (ID_REAL_USERS(brush) <= 0) + Brush *brush = brush_ptr->data; + if (ID_REAL_USERS(brush) <= 0) { BKE_libblock_free(&bmain->brush, brush); - else - BKE_reportf(reports, RPT_ERROR, "Brush \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(brush_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Brush '%s' must have zero users to be removed, found %d", brush->id.name + 2, ID_REAL_USERS(brush)); + } } static World *rna_Main_worlds_new(Main *UNUSED(bmain), const char *name) @@ -410,24 +453,29 @@ static World *rna_Main_worlds_new(Main *UNUSED(bmain), const char *name) id_us_min(&world->id); return world; } -static void rna_Main_worlds_remove(Main *bmain, ReportList *reports, struct World *world) +static void rna_Main_worlds_remove(Main *bmain, ReportList *reports, PointerRNA *world_ptr) { - if (ID_REAL_USERS(world) <= 0) + Group *world = world_ptr->data; + if (ID_REAL_USERS(world) <= 0) { BKE_libblock_free(&bmain->world, world); - else - BKE_reportf(reports, RPT_ERROR, "World \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(world_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "World '%s' must have zero users to be removed, found %d", world->id.name + 2, ID_REAL_USERS(world)); + } } static Group *rna_Main_groups_new(Main *UNUSED(bmain), const char *name) { return add_group(name); } -static void rna_Main_groups_remove(Main *bmain, Group *group) +static void rna_Main_groups_remove(Main *bmain, PointerRNA *group_ptr) { + Group *group = group_ptr->data; BKE_group_unlink(group); BKE_libblock_free(&bmain->group, group); - /* XXX python now has invalid pointer? */ + RNA_POINTER_INVALIDATE(group_ptr); } static Speaker *rna_Main_speakers_new(Main *UNUSED(bmain), const char *name) @@ -436,26 +484,29 @@ static Speaker *rna_Main_speakers_new(Main *UNUSED(bmain), const char *name) id_us_min(&speaker->id); return speaker; } -static void rna_Main_speakers_remove(Main *bmain, ReportList *reports, Speaker *speaker) +static void rna_Main_speakers_remove(Main *bmain, ReportList *reports, PointerRNA *speaker_ptr) { - if (ID_REAL_USERS(speaker) <= 0) + Speaker *speaker = speaker_ptr->data; + if (ID_REAL_USERS(speaker) <= 0) { BKE_libblock_free(&bmain->speaker, speaker); - else - BKE_reportf(reports, RPT_ERROR, "Speaker \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(speaker_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Speaker '%s' must have zero users to be removed, found %d", speaker->id.name + 2, ID_REAL_USERS(speaker)); - - /* XXX python now has invalid pointer? */ + } } static Text *rna_Main_texts_new(Main *UNUSED(bmain), const char *name) { return BKE_text_add(name); } -static void rna_Main_texts_remove(Main *bmain, Text *text) +static void rna_Main_texts_remove(Main *bmain, PointerRNA *text_ptr) { + Text *text = text_ptr->data; BKE_text_unlink(bmain, text); BKE_libblock_free(&bmain->text, text); - /* XXX python now has invalid pointer? */ + RNA_POINTER_INVALIDATE(text_ptr); } static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath) @@ -466,8 +517,8 @@ static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *f txt = BKE_text_load(filepath, bmain->name); if (!txt) - BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s", filepath, - errno ? strerror(errno) : "Unable to load text"); + BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath, + errno ? strerror(errno) : TIP_("unable to load text")); return txt; } @@ -478,15 +529,17 @@ static bArmature *rna_Main_armatures_new(Main *UNUSED(bmain), const char *name) id_us_min(&arm->id); return arm; } -static void rna_Main_armatures_remove(Main *bmain, ReportList *reports, bArmature *arm) +static void rna_Main_armatures_remove(Main *bmain, ReportList *reports, PointerRNA *arm_ptr) { - if (ID_REAL_USERS(arm) <= 0) + bArmature *arm = arm_ptr->data; + if (ID_REAL_USERS(arm) <= 0) { BKE_libblock_free(&bmain->armature, arm); - else - BKE_reportf(reports, RPT_ERROR, "Armature \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(arm_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Armature '%s' must have zero users to be removed, found %d", arm->id.name + 2, ID_REAL_USERS(arm)); - - /* XXX python now has invalid pointer? */ + } } static bAction *rna_Main_actions_new(Main *UNUSED(bmain), const char *name) @@ -496,15 +549,17 @@ static bAction *rna_Main_actions_new(Main *UNUSED(bmain), const char *name) act->id.flag &= ~LIB_FAKEUSER; return act; } -static void rna_Main_actions_remove(Main *bmain, ReportList *reports, bAction *act) +static void rna_Main_actions_remove(Main *bmain, ReportList *reports, PointerRNA *act_ptr) { - if (ID_REAL_USERS(act) <= 0) + bAction *act = act_ptr->data; + if (ID_REAL_USERS(act) <= 0) { BKE_libblock_free(&bmain->action, act); - else - BKE_reportf(reports, RPT_ERROR, "Action \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(act_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Action '%s' must have zero users to be removed, found %d", act->id.name + 2, ID_REAL_USERS(act)); - - /* XXX python now has invalid pointer? */ + } } static ParticleSettings *rna_Main_particles_new(Main *bmain, const char *name) @@ -513,15 +568,17 @@ static ParticleSettings *rna_Main_particles_new(Main *bmain, const char *name) id_us_min(&part->id); return part; } -static void rna_Main_particles_remove(Main *bmain, ReportList *reports, ParticleSettings *part) +static void rna_Main_particles_remove(Main *bmain, ReportList *reports, PointerRNA *part_ptr) { - if (ID_REAL_USERS(part) <= 0) + ParticleSettings *part = part_ptr->data; + if (ID_REAL_USERS(part) <= 0) { BKE_libblock_free(&bmain->particle, part); - else - BKE_reportf(reports, RPT_ERROR, "Particle Settings \"%s\" must have zero users to be removed, found %d", + RNA_POINTER_INVALIDATE(part_ptr); + } + else { + BKE_reportf(reports, RPT_ERROR, "Particle settings '%s' must have zero users to be removed, found %d", part->id.name + 2, ID_REAL_USERS(part)); - - /* XXX python now has invalid pointer? */ + } } static MovieClip *rna_Main_movieclip_load(Main *UNUSED(bmain), ReportList *reports, const char *filepath) @@ -532,17 +589,18 @@ static MovieClip *rna_Main_movieclip_load(Main *UNUSED(bmain), ReportList *repor clip = BKE_movieclip_file_add(filepath); if (!clip) - BKE_reportf(reports, RPT_ERROR, "Can't read: \"%s\", %s.", filepath, - errno ? strerror(errno) : "Unable to load movie clip"); + BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath, + errno ? strerror(errno) : TIP_("unable to load movie clip")); return clip; } -static void rna_Main_movieclips_remove(Main *bmain, MovieClip *clip) +static void rna_Main_movieclips_remove(Main *bmain, PointerRNA *clip_ptr) { + MovieClip *clip = clip_ptr->data; BKE_movieclip_unlink(bmain, clip); BKE_libblock_free(&bmain->movieclip, clip); - /* XXX python now has invalid pointer? */ + RNA_POINTER_INVALIDATE(clip_ptr); } static Mask *rna_Main_mask_new(Main *UNUSED(bmain), const char *name) @@ -554,11 +612,25 @@ static Mask *rna_Main_mask_new(Main *UNUSED(bmain), const char *name) return mask; } -static void rna_Main_masks_remove(Main *bmain, Mask *mask) +static void rna_Main_masks_remove(Main *bmain, PointerRNA *mask_ptr) { + Mask *mask = mask_ptr->data; BKE_mask_free(bmain, mask); BKE_libblock_free(&bmain->mask, mask); - /* XXX python now has invalid pointer? */ + RNA_POINTER_INVALIDATE(mask_ptr); +} + +static void rna_Main_grease_pencil_remove(Main *bmain, ReportList *reports, PointerRNA *gpd_ptr) +{ + bGPdata *gpd = gpd_ptr->data; + if (ID_REAL_USERS(gpd) <= 0) { + BKE_gpencil_free(gpd); + BKE_libblock_free(&bmain->gpencil, gpd); + RNA_POINTER_INVALIDATE(gpd_ptr); + } + else + BKE_reportf(reports, RPT_ERROR, "Grease pencil '%s' must have zero users to be removed, found %d", + gpd->id.name + 2, ID_REAL_USERS(gpd)); } /* tag functions, all the same */ @@ -664,7 +736,8 @@ void RNA_def_main_cameras(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a camera from the current blendfile"); parm = RNA_def_pointer(func, "camera", "Camera", "", "Camera to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_cameras_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -699,7 +772,8 @@ void RNA_def_main_scenes(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a scene from the current blendfile"); parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_scenes_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -738,7 +812,8 @@ void RNA_def_main_objects(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Remove a object from the current blendfile"); RNA_def_function_flag(func, FUNC_USE_REPORTS); parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_objects_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -773,7 +848,8 @@ void RNA_def_main_materials(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a material from the current blendfile"); parm = RNA_def_pointer(func, "material", "Material", "", "Material to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_materials_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -816,7 +892,8 @@ void RNA_def_main_node_groups(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a node tree from the current blendfile"); parm = RNA_def_pointer(func, "tree", "NodeTree", "", "Node tree to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_node_groups_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -850,7 +927,8 @@ void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a mesh from the current blendfile"); parm = RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_meshes_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -886,7 +964,8 @@ void RNA_def_main_lamps(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a lamp from the current blendfile"); parm = RNA_def_pointer(func, "lamp", "Lamp", "", "Lamp to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_lamps_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -975,9 +1054,9 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a new image to the main database"); parm = RNA_def_string(func, "name", "Image", 0, "", "New name for the datablock"); RNA_def_property_flag(parm, PROP_REQUIRED); - parm = RNA_def_int(func, "width", 1024, 1, INT_MAX, "", "Width of the image", 0, INT_MAX); + parm = RNA_def_int(func, "width", 1024, 1, INT_MAX, "", "Width of the image", 1, INT_MAX); RNA_def_property_flag(parm, PROP_REQUIRED); - parm = RNA_def_int(func, "height", 1024, 1, INT_MAX, "", "Height of the image", 0, INT_MAX); + parm = RNA_def_int(func, "height", 1024, 1, INT_MAX, "", "Height of the image", 1, INT_MAX); RNA_def_property_flag(parm, PROP_REQUIRED); RNA_def_boolean(func, "alpha", 0, "Alpha", "Use alpha channel"); RNA_def_boolean(func, "float_buffer", 0, "Float Buffer", "Create an image with floating point color"); @@ -998,7 +1077,8 @@ void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove an image from the current blendfile"); parm = RNA_def_pointer(func, "image", "Image", "", "Image to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_images_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1033,7 +1113,8 @@ void RNA_def_main_lattices(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a lattice from the current blendfile"); parm = RNA_def_pointer(func, "lattice", "Lattice", "", "Lattice to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_lattices_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1069,7 +1150,8 @@ void RNA_def_main_curves(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a curve from the current blendfile"); parm = RNA_def_pointer(func, "curve", "Curve", "", "Curve to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_curves_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1103,7 +1185,8 @@ void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a metaball from the current blendfile"); parm = RNA_def_pointer(func, "metaball", "MetaBall", "", "Metaball to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_metaballs_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1138,7 +1221,8 @@ void RNA_def_main_fonts(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a font from the current blendfile"); parm = RNA_def_pointer(func, "vfont", "VectorFont", "", "Font to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_fonts_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1174,7 +1258,8 @@ void RNA_def_main_textures(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a texture from the current blendfile"); parm = RNA_def_pointer(func, "texture", "Texture", "", "Texture to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_textures_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1208,7 +1293,8 @@ void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a brush from the current blendfile"); parm = RNA_def_pointer(func, "brush", "Brush", "", "Brush to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_brushes_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1243,7 +1329,8 @@ void RNA_def_main_worlds(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a world from the current blendfile"); parm = RNA_def_pointer(func, "world", "World", "", "World to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_worlds_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1277,7 +1364,8 @@ void RNA_def_main_groups(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "remove", "rna_Main_groups_remove"); RNA_def_function_ui_description(func, "Remove a group from the current blendfile"); parm = RNA_def_pointer(func, "group", "Group", "", "Group to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_groups_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1312,7 +1400,8 @@ void RNA_def_main_speakers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a speaker from the current blendfile"); parm = RNA_def_pointer(func, "speaker", "Speaker", "", "Speaker to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_speakers_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1346,7 +1435,8 @@ void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "remove", "rna_Main_texts_remove"); RNA_def_function_ui_description(func, "Remove a text from the current blendfile"); parm = RNA_def_pointer(func, "text", "Text", "", "Text to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); /* load func */ func = RNA_def_function(srna, "load", "rna_Main_texts_load"); @@ -1414,7 +1504,8 @@ void RNA_def_main_armatures(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a armature from the current blendfile"); parm = RNA_def_pointer(func, "armature", "Armature", "", "Armature to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_armatures_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1448,7 +1539,8 @@ void RNA_def_main_actions(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a action from the current blendfile"); parm = RNA_def_pointer(func, "action", "Action", "", "Action to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_actions_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1482,7 +1574,8 @@ void RNA_def_main_particles(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove a particle settings instance from the current blendfile"); parm = RNA_def_pointer(func, "particle", "ParticleSettings", "", "Particle Settings to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); func = RNA_def_function(srna, "tag", "rna_Main_particles_tag"); parm = RNA_def_boolean(func, "value", 0, "Value", ""); @@ -1509,6 +1602,21 @@ void RNA_def_main_gpencil(BlenderRNA *brna, PropertyRNA *cprop) parm = RNA_def_boolean(func, "value", 0, "Value", ""); RNA_def_property_flag(parm, PROP_REQUIRED); + func = RNA_def_function(srna, "new", "gpencil_data_addnew"); + RNA_def_function_flag(func, FUNC_NO_SELF); + parm = RNA_def_string(func, "name", "GreasePencil", 0, "", "New name for the datablock"); + RNA_def_property_flag(parm, PROP_REQUIRED); + /* return type */ + parm = RNA_def_pointer(func, "grease_pencil", "GreasePencil", "", "New grease pencil datablock"); + RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "remove", "rna_Main_grease_pencil_remove"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a grease pencil instance from the current blendfile"); + parm = RNA_def_pointer(func, "grease_pencil", "GreasePencil", "", "Grease Pencil to remove"); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); + prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_boolean_funcs(prop, "rna_Main_gpencil_is_updated_get", NULL); @@ -1532,7 +1640,8 @@ void RNA_def_main_movieclips(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "remove", "rna_Main_movieclips_remove"); RNA_def_function_ui_description(func, "Remove a movie clip from the current blendfile."); parm = RNA_def_pointer(func, "clip", "MovieClip", "", "Movie clip to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); /* load func */ func = RNA_def_function(srna, "load", "rna_Main_movieclip_load"); @@ -1563,7 +1672,7 @@ void RNA_def_main_masks(BlenderRNA *brna, PropertyRNA *cprop) /* new func */ func = RNA_def_function(srna, "new", "rna_Main_mask_new"); RNA_def_function_ui_description(func, "Add a new mask with a given name to the main database"); - parm = RNA_def_string_file_path(func, "name", "", MAX_ID_NAME - 2, "Mask", "Name of new mask datablock"); + RNA_def_string_file_path(func, "name", "", MAX_ID_NAME - 2, "Mask", "Name of new mask datablock"); /* return type */ parm = RNA_def_pointer(func, "mask", "Mask", "", "New mask datablock"); RNA_def_function_return(func, parm); @@ -1572,7 +1681,8 @@ void RNA_def_main_masks(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "remove", "rna_Main_masks_remove"); RNA_def_function_ui_description(func, "Remove a masks from the current blendfile."); parm = RNA_def_pointer(func, "mask", "Mask", "", "Mask to remove"); - RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR); + RNA_def_property_clear_flag(parm, PROP_THICK_WRAP); } #endif |