From 0f0eeffeceafdb47b4cdb2975865d4306d0d94b4 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 10 Jul 2016 15:49:01 +0200 Subject: Refactor/enhance BKE_brush_make_local() and BKE_speaker_make_local(). Now using modern features from libquery/libremap areas. Provides same kind of fixes/improvements as for BKE_object_make_local() (see rBd1a4ae3f395a6). --- source/blender/blenkernel/intern/brush.c | 75 +++++++++++++++----------------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'source/blender/blenkernel/intern/brush.c') diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 5505d3861d7..ee7af7e6dd1 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -38,6 +38,8 @@ #include "BKE_colortools.h" #include "BKE_global.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_paint.h" #include "BKE_texture.h" @@ -216,63 +218,58 @@ void BKE_brush_free(Brush *brush) BKE_previewimg_free(&(brush->preview)); } +static int extern_local_brush_callback( + void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag) +{ + /* We only tag usercounted ID usages as extern... Why? */ + if ((cd_flag & IDWALK_USER) && *id_pointer) { + id_lib_extern(*id_pointer); + } + return IDWALK_RET_NOP; +} + static void extern_local_brush(Brush *brush) { - id_lib_extern((ID *)brush->mtex.tex); - id_lib_extern((ID *)brush->mask_mtex.tex); - id_lib_extern((ID *)brush->clone.image); - id_lib_extern((ID *)brush->toggle_brush); - id_lib_extern((ID *)brush->paint_curve); + BKE_library_foreach_ID_link(&brush->id, extern_local_brush_callback, NULL, 0); } -void BKE_brush_make_local(Brush *brush) +void BKE_brush_make_local(Main *bmain, Brush *brush) { + bool is_local = false, is_lib = false; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - Main *bmain = G.main; - Scene *scene; - bool is_local = false, is_lib = false; - - if (!ID_IS_LINKED_DATABLOCK(brush)) return; + if (!ID_IS_LINKED_DATABLOCK(brush)) { + return; + } if (brush->clone.image) { - /* special case: ima always local immediately. Clone image should only - * have one user anyway. */ - id_clear_lib_data(bmain, &brush->clone.image->id); - extern_local_brush(brush); + /* Special case: ima always local immediately. Clone image should only have one user anyway. */ + id_make_local(bmain, &brush->clone.image->id, false); } - for (scene = bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene = scene->id.next) { - if (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) { - if (ID_IS_LINKED_DATABLOCK(scene)) is_lib = true; - else is_local = true; + BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib); + + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &brush->id); + extern_local_brush(brush); + + /* enable fake user by default */ + id_fake_user_set(&brush->id); } - } + else { + Brush *brush_new = BKE_brush_copy(bmain, brush); /* Ensures FAKE_USER is set */ - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &brush->id); - extern_local_brush(brush); + brush_new->id.us = 0; - /* enable fake user by default */ - id_fake_user_set(&brush->id); - } - else if (is_local && is_lib) { - Brush *brush_new = BKE_brush_copy(bmain, brush); /* Ensures FAKE_USER is set */ - id_us_min(&brush_new->id); /* Remove user added by standard BKE_libblock_copy(). */ - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id); - - for (scene = bmain->scene.first; scene; scene = scene->id.next) { - if (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) { - if (!ID_IS_LINKED_DATABLOCK(scene)) { - BKE_paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new); - } - } + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id); + + BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } -- cgit v1.2.3