diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-12-29 21:57:42 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-12-29 22:05:22 +0300 |
commit | f874aeef70f2f315c3062d9694ae816674d0cdd0 (patch) | |
tree | e2c8ddb8ecfc415d89225a081ae8755f355993bd /source/blender/makesrna/intern/rna_main_api.c | |
parent | 6ecab6dd8e48d564a2b43e0e81e79d079e8b4c77 (diff) | |
parent | bf7d7bc323d5505b78688af2df1f66e1053f62e1 (diff) |
Merge branch 'master' into blender2.8
Please **DO NOT** add changes from master when it's totally uneeded!
Changes to BLI_ area most certainly shall *always* be done in master,
there is absolutely no point in adding more diff between the two
branches than needed, will only makes merging more cumbersome!
Conflicts:
CMakeLists.txt
source/blender/blenlib/intern/math_vector_inline.c
Diffstat (limited to 'source/blender/makesrna/intern/rna_main_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 127 |
1 files changed, 100 insertions, 27 deletions
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 673f7acbd6a..244820f5a49 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -116,6 +116,13 @@ #endif +static void rna_idname_validate(const char *name, char *r_name) +{ + BLI_strncpy(r_name, name, MAX_ID_NAME - 2); + BLI_utf8_invalid_strip(r_name, strlen(r_name)); +} + + static void rna_Main_ID_remove(Main *bmain, ReportList *reports, PointerRNA *id_ptr, int do_unlink) { ID *id = id_ptr->data; @@ -137,14 +144,20 @@ static void rna_Main_ID_remove(Main *bmain, ReportList *reports, PointerRNA *id_ static Camera *rna_Main_cameras_new(Main *bmain, const char *name) { - ID *id = BKE_camera_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + ID *id = BKE_camera_add(bmain, safe_name); id_us_min(id); return (Camera *)id; } static Scene *rna_Main_scenes_new(Main *bmain, const char *name) { - return BKE_scene_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + return BKE_scene_add(bmain, safe_name); } static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, PointerRNA *scene_ptr, int do_unlink) { @@ -180,6 +193,9 @@ static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char *name, ID *data) { + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + Object *ob; int type = OB_EMPTY; if (data) { @@ -223,7 +239,7 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char id_us_plus(data); } - ob = BKE_object_add_only_object(bmain, type, name); + ob = BKE_object_add_only_object(bmain, type, safe_name); id_us_min(&ob->id); ob->data = data; @@ -234,7 +250,10 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char static Material *rna_Main_materials_new(Main *bmain, const char *name) { - ID *id = (ID *)BKE_material_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + ID *id = (ID *)BKE_material_add(bmain, safe_name); id_us_min(id); return (Material *)id; } @@ -245,20 +264,27 @@ static EnumPropertyItem *rna_Main_nodetree_type_itemf(bContext *UNUSED(C), Point } static struct bNodeTree *rna_Main_nodetree_new(Main *bmain, const char *name, int type) { + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + bNodeTreeType *typeinfo = rna_node_tree_type_from_enum(type); if (typeinfo) { - bNodeTree *ntree = ntreeAddTree(bmain, name, typeinfo->idname); + bNodeTree *ntree = ntreeAddTree(bmain, safe_name, typeinfo->idname); id_us_min(&ntree->id); return ntree; } - else + else { return NULL; + } } static Mesh *rna_Main_meshes_new(Main *bmain, const char *name) { - Mesh *me = BKE_mesh_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Mesh *me = BKE_mesh_add(bmain, safe_name); id_us_min(&me->id); return me; } @@ -286,7 +312,10 @@ Mesh *rna_Main_meshes_new_from_object( static Lamp *rna_Main_lamps_new(Main *bmain, const char *name, int type) { - Lamp *lamp = BKE_lamp_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Lamp *lamp = BKE_lamp_add(bmain, safe_name); lamp->type = type; id_us_min(&lamp->id); return lamp; @@ -294,8 +323,11 @@ static Lamp *rna_Main_lamps_new(Main *bmain, const char *name, int type) static Image *rna_Main_images_new(Main *bmain, const char *name, int width, int height, int alpha, int float_buffer, int stereo3d) { + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + float color[4] = {0.0, 0.0, 0.0, 1.0}; - Image *image = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, float_buffer, 0, color, stereo3d); + Image *image = BKE_image_add_generated(bmain, width, height, safe_name, alpha ? 32 : 24, float_buffer, 0, color, stereo3d); id_us_min(&image->id); return image; } @@ -322,21 +354,30 @@ static Image *rna_Main_images_load(Main *bmain, ReportList *reports, const char static Lattice *rna_Main_lattices_new(Main *bmain, const char *name) { - Lattice *lt = BKE_lattice_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Lattice *lt = BKE_lattice_add(bmain, safe_name); id_us_min(<->id); return lt; } static Curve *rna_Main_curves_new(Main *bmain, const char *name, int type) { - Curve *cu = BKE_curve_add(bmain, name, type); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Curve *cu = BKE_curve_add(bmain, safe_name, type); id_us_min(&cu->id); return cu; } static MetaBall *rna_Main_metaballs_new(Main *bmain, const char *name) { - MetaBall *mb = BKE_mball_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + MetaBall *mb = BKE_mball_add(bmain, safe_name); id_us_min(&mb->id); return mb; } @@ -364,7 +405,10 @@ static VFont *rna_Main_fonts_load(Main *bmain, ReportList *reports, const char * static Tex *rna_Main_textures_new(Main *bmain, const char *name, int type) { - Tex *tex = BKE_texture_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Tex *tex = BKE_texture_add(bmain, safe_name); BKE_texture_type_set(tex, type); id_us_min(&tex->id); return tex; @@ -372,26 +416,38 @@ static Tex *rna_Main_textures_new(Main *bmain, const char *name, int type) static Brush *rna_Main_brushes_new(Main *bmain, const char *name, int mode) { - Brush *brush = BKE_brush_add(bmain, name, mode); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Brush *brush = BKE_brush_add(bmain, safe_name, mode); id_us_min(&brush->id); return brush; } static World *rna_Main_worlds_new(Main *bmain, const char *name) { - World *world = add_world(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + World *world = add_world(bmain, safe_name); id_us_min(&world->id); return world; } static Group *rna_Main_groups_new(Main *bmain, const char *name) { - return BKE_group_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + return BKE_group_add(bmain, safe_name); } static Speaker *rna_Main_speakers_new(Main *bmain, const char *name) { - Speaker *speaker = BKE_speaker_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Speaker *speaker = BKE_speaker_add(bmain, safe_name); id_us_min(&speaker->id); return speaker; } @@ -413,7 +469,10 @@ static bSound *rna_Main_sounds_load(Main *bmain, const char *name, int check_exi static Text *rna_Main_texts_new(Main *bmain, const char *name) { - return BKE_text_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + return BKE_text_add(bmain, safe_name); } static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath, int is_internal) @@ -432,28 +491,40 @@ static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *f static bArmature *rna_Main_armatures_new(Main *bmain, const char *name) { - bArmature *arm = BKE_armature_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + bArmature *arm = BKE_armature_add(bmain, safe_name); id_us_min(&arm->id); return arm; } static bAction *rna_Main_actions_new(Main *bmain, const char *name) { - bAction *act = add_empty_action(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + bAction *act = add_empty_action(bmain, safe_name); id_fake_user_clear(&act->id); return act; } static ParticleSettings *rna_Main_particles_new(Main *bmain, const char *name) { - ParticleSettings *part = psys_new_settings(name, bmain); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + ParticleSettings *part = psys_new_settings(safe_name, bmain); id_us_min(&part->id); return part; } static Palette *rna_Main_palettes_new(Main *bmain, const char *name) { - Palette *palette = BKE_palette_add(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + Palette *palette = BKE_palette_add(bmain, safe_name); id_us_min(&palette->id); return (Palette *)palette; } @@ -481,16 +552,18 @@ static MovieClip *rna_Main_movieclip_load(Main *bmain, ReportList *reports, cons static Mask *rna_Main_mask_new(Main *bmain, const char *name) { - Mask *mask; - - mask = BKE_mask_new(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); - return mask; + return BKE_mask_new(bmain, safe_name); } static FreestyleLineStyle *rna_Main_linestyles_new(Main *bmain, const char *name) { - FreestyleLineStyle *linestyle = BKE_linestyle_new(bmain, name); + char safe_name[MAX_ID_NAME - 2]; + rna_idname_validate(name, safe_name); + + FreestyleLineStyle *linestyle = BKE_linestyle_new(bmain, safe_name); id_us_min(&linestyle->id); return linestyle; } |