From 9c6fe810a3cae2a5498f5760822b7a7e4a82bf4f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 9 Nov 2015 20:59:42 +0100 Subject: Fake user: add BKE_library helpers to set/clear that flag. Since it also involves usercount manipulation, safer and cleaner to do it in BKE_library... --- source/blender/blenkernel/BKE_library.h | 2 ++ source/blender/blenkernel/intern/brush.c | 17 +++++------------ source/blender/blenkernel/intern/library.c | 21 +++++++++++++++++---- source/blender/blenkernel/intern/mask.c | 12 +++--------- source/blender/blenkernel/intern/paint.c | 2 +- source/blender/blenloader/intern/readfile.c | 3 +-- .../blender/editors/interface/interface_templates.c | 2 +- source/blender/editors/space_action/action_data.c | 5 +---- .../blender/editors/space_outliner/outliner_tools.c | 10 ++-------- source/blender/makesrna/intern/rna_ID.c | 12 +++++------- source/blender/makesrna/intern/rna_main_api.c | 3 +-- 11 files changed, 39 insertions(+), 50 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index e11e9496b21..e27198add4c 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -64,6 +64,8 @@ void BKE_library_filepath_set(struct Library *lib, const char *filepath); void id_us_ensure_real(struct ID *id); void id_us_plus(struct ID *id); void id_us_min(struct ID *id); +void id_fake_user_set(struct ID *id); +void id_fake_user_clear(struct ID *id); bool id_make_local(struct ID *id, bool test); bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 201750df5a7..92ab4d745c1 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -136,7 +136,7 @@ void BKE_brush_init(Brush *brush) BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(brush, id)); /* enable fake user by default */ - brush->id.flag |= LIB_FAKEUSER; + id_fake_user_set(&brush->id); brush_defaults(brush); @@ -193,11 +193,8 @@ Brush *BKE_brush_copy(Brush *brush) brushn->curve = curvemapping_copy(brush->curve); /* enable fake user by default */ - if (!(brushn->id.flag & LIB_FAKEUSER)) { - brushn->id.flag |= LIB_FAKEUSER; - id_us_plus(&brushn->id); - } - + id_fake_user_set(&brush->id); + if (brush->id.lib) { BKE_id_lib_local_paths(G.main, brush->id.lib, &brushn->id); } @@ -280,15 +277,11 @@ void BKE_brush_make_local(Brush *brush) extern_local_brush(brush); /* enable fake user by default */ - if (!(brush->id.flag & LIB_FAKEUSER)) { - brush->id.flag |= LIB_FAKEUSER; - id_us_plus(&brush->id); - } + id_fake_user_set(&brush->id); } else if (is_local && is_lib) { - Brush *brush_new = BKE_brush_copy(brush); + Brush *brush_new = BKE_brush_copy(brush); /* Ensures FAKE_USER is set */ brush_new->id.us = 1; /* only keep fake user */ - brush_new->id.flag |= LIB_FAKEUSER; /* Remap paths of new ID using old library as base. */ BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index fe5ddb5fd93..5091ab7dfa0 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -196,6 +196,22 @@ void id_us_min(ID *id) } } +void id_fake_user_set(ID *id) +{ + if (id && !(id->flag & LIB_FAKEUSER)) { + id->flag |= LIB_FAKEUSER; + id_us_plus(id); + } +} + +void id_fake_user_clear(ID *id) +{ + if (id && (id->flag & LIB_FAKEUSER)) { + id->flag &= ~LIB_FAKEUSER; + id_us_min(id); + } +} + /* calls the appropriate make_local method for the block, unless test. Returns true * if the block can be made local. */ bool id_make_local(ID *id, bool test) @@ -1610,10 +1626,7 @@ void id_clear_lib_data(Main *bmain, ID *id) BKE_id_lib_local_paths(bmain, id->lib, id); - if (id->flag & LIB_FAKEUSER) { - id->us--; - id->flag &= ~LIB_FAKEUSER; - } + id_fake_user_clear(id); id->lib = NULL; id->flag = LIB_LOCAL; diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index b79c72a4251..cd26691c3e1 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -804,7 +804,7 @@ static Mask *mask_alloc(Main *bmain, const char *name) mask = BKE_libblock_alloc(bmain, ID_MSK, name); - mask->id.flag |= LIB_FAKEUSER; + id_fake_user_set(&mask->id); return mask; } @@ -843,10 +843,7 @@ Mask *BKE_mask_copy_nolib(Mask *mask) BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers); /* enable fake user by default */ - if (!(mask_new->id.flag & LIB_FAKEUSER)) { - mask_new->id.flag |= LIB_FAKEUSER; - id_us_plus(&mask_new->id); - } + id_fake_user_set(&mask->id); return mask_new; } @@ -862,10 +859,7 @@ Mask *BKE_mask_copy(Mask *mask) BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers); /* enable fake user by default */ - if (!(mask_new->id.flag & LIB_FAKEUSER)) { - mask_new->id.flag |= LIB_FAKEUSER; - id_us_plus(&mask_new->id); - } + id_fake_user_set(&mask->id); if (mask->id.lib) { BKE_id_lib_local_paths(G.main, mask->id.lib, &mask_new->id); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 06844b09a9b..1b6fc92ef5e 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -373,7 +373,7 @@ Palette *BKE_palette_add(Main *bmain, const char *name) palette = BKE_libblock_alloc(bmain, ID_PAL, name); /* enable fake user by default */ - palette->id.flag |= LIB_FAKEUSER; + id_fake_user_set(&palette->id); return palette; } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 9ebae184dd4..73e13a762a9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7928,8 +7928,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID /* clear first 8 bits */ id->flag = (id->flag & 0xFF00) | flag | LIB_NEED_LINK; id->lib = main->curlib; - if (id->flag & LIB_FAKEUSER) id->us= 1; - else id->us = 0; + id->us = (id->flag & LIB_FAKEUSER) ? 1 : 0; id->icon_id = 0; id->flag &= ~(LIB_ID_RECALC | LIB_ID_RECALC_DATA | LIB_DOIT | LIB_MISSING); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 1238b883e9a..c606dd67f29 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -275,7 +275,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) if (id && CTX_wm_window(C)->eventstate->shift) { /* only way to force-remove data (on save) */ - id->flag &= ~LIB_FAKEUSER; + id_fake_user_clear(id); id->us = 0; } diff --git a/source/blender/editors/space_action/action_data.c b/source/blender/editors/space_action/action_data.c index 8ce126b439e..a3be7791f9a 100644 --- a/source/blender/editors/space_action/action_data.c +++ b/source/blender/editors/space_action/action_data.c @@ -581,10 +581,7 @@ void ED_animedit_unlink_action(bContext *C, ID *id, AnimData *adt, bAction *act, } /* Clear Fake User */ - if (act->id.flag & LIB_FAKEUSER) { - act->id.flag &= ~LIB_FAKEUSER; - id_us_min(&act->id); - } + id_fake_user_clear(&act->id); } /* If in Tweak Mode, don't unlink. Instead, this diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index c0464c84061..313a75f373a 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -421,10 +421,7 @@ static void id_fake_user_set_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeE { ID *id = tselem->id; - if ((id) && ((id->flag & LIB_FAKEUSER) == 0)) { - id->flag |= LIB_FAKEUSER; - id_us_plus(id); - } + id_fake_user_set(id); } static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), TreeElement *UNUSED(te), @@ -432,10 +429,7 @@ static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), Tre { ID *id = tselem->id; - if ((id) && (id->flag & LIB_FAKEUSER)) { - id->flag &= ~LIB_FAKEUSER; - id_us_min(id); - } + id_fake_user_clear(id); } static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 43ffc7743c5..e1e892a6b65 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -223,13 +223,11 @@ void rna_ID_fake_user_set(PointerRNA *ptr, int value) { ID *id = (ID *)ptr->data; - if (value && !(id->flag & LIB_FAKEUSER)) { - id->flag |= LIB_FAKEUSER; - id_us_plus(id); + if (value) { + id_fake_user_set(id); } - else if (!value && (id->flag & LIB_FAKEUSER)) { - id->flag &= ~LIB_FAKEUSER; - id_us_min(id); + else { + id_fake_user_clear(id); } } @@ -329,8 +327,8 @@ static void rna_ID_update_tag(ID *id, ReportList *reports, int flag) static void rna_ID_user_clear(ID *id) { + id_fake_user_clear(id); id->us = 0; /* don't save */ - id->flag &= ~LIB_FAKEUSER; } static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain) diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 057fed50c32..710ae97e4dc 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -639,8 +639,7 @@ static void rna_Main_armatures_remove(Main *bmain, ReportList *reports, PointerR static bAction *rna_Main_actions_new(Main *bmain, const char *name) { bAction *act = add_empty_action(bmain, name); - id_us_min(&act->id); - act->id.flag &= ~LIB_FAKEUSER; + id_fake_user_clear(&act->id); return act; } static void rna_Main_actions_remove(Main *bmain, ReportList *reports, PointerRNA *act_ptr) -- cgit v1.2.3