Use new generic BKE_id_expand_local() for both make_local() and copy() functions of actions, brushes and particles.

This greatly simplifies said code, once again no change expected from user PoV.
This commit is contained in:
Bastien Montagne 2016-07-11 19:39:34 +02:00
parent 2ec17e655c
commit 13f0b59f11
3 changed files with 10 additions and 42 deletions

View File

@ -113,6 +113,7 @@ void BKE_action_make_local(Main *bmain, bAction *act)
if (is_local) {
if (!is_lib) {
id_clear_lib_data(bmain, &act->id);
BKE_id_expand_local(&act->id, false);
}
else {
bAction *act_new = BKE_action_copy(bmain, act);
@ -183,6 +184,8 @@ bAction *BKE_action_copy(Main *bmain, bAction *src)
}
}
BKE_id_expand_local(&dst->id, true);
if (ID_IS_LINKED_DATABLOCK(src)) {
BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id);
}

View File

@ -178,15 +178,6 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
brushn = BKE_libblock_copy(bmain, &brush->id);
if (brush->mtex.tex)
id_us_plus((ID *)brush->mtex.tex);
if (brush->mask_mtex.tex)
id_us_plus((ID *)brush->mask_mtex.tex);
if (brush->paint_curve)
id_us_plus((ID *)brush->paint_curve);
if (brush->icon_imbuf)
brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
@ -197,6 +188,8 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
/* enable fake user by default */
id_fake_user_set(&brush->id);
BKE_id_expand_local(&brushn->id, true);
if (ID_IS_LINKED_DATABLOCK(brush)) {
BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id);
}
@ -218,21 +211,6 @@ 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)
{
BKE_library_foreach_ID_link(&brush->id, extern_local_brush_callback, NULL, 0);
}
void BKE_brush_make_local(Main *bmain, Brush *brush)
{
bool is_local = false, is_lib = false;
@ -256,7 +234,7 @@ void BKE_brush_make_local(Main *bmain, Brush *brush)
if (is_local) {
if (!is_lib) {
id_clear_lib_data(bmain, &brush->id);
extern_local_brush(brush);
BKE_id_expand_local(&brush->id, false);
/* enable fake user by default */
id_fake_user_set(&brush->id);

View File

@ -3312,6 +3312,7 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
int a;
partn = BKE_libblock_copy(bmain, &part->id);
partn->pd = MEM_dupallocN(part->pd);
partn->pd2 = MEM_dupallocN(part->pd2);
partn->effector_weights = MEM_dupallocN(part->effector_weights);
@ -3328,12 +3329,13 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
if (part->mtex[a]) {
partn->mtex[a] = MEM_mallocN(sizeof(MTex), "psys_copy_tex");
memcpy(partn->mtex[a], part->mtex[a], sizeof(MTex));
id_us_plus((ID *)partn->mtex[a]->tex);
}
}
BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
BKE_id_expand_local(&partn->id, true);
if (ID_IS_LINKED_DATABLOCK(part)) {
BKE_id_lib_local_paths(bmain, part->id.lib, &partn->id);
}
@ -3341,21 +3343,6 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
return partn;
}
static int extern_local_particlesettings_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 expand_local_particlesettings(ParticleSettings *part)
{
BKE_library_foreach_ID_link(&part->id, extern_local_particlesettings_callback, NULL, 0);
}
void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part)
{
bool is_local = false, is_lib = false;
@ -3374,7 +3361,7 @@ void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part)
if (is_local) {
if (!is_lib) {
id_clear_lib_data(bmain, &part->id);
expand_local_particlesettings(part);
BKE_id_expand_local(&part->id, false);
}
else {
ParticleSettings *part_new = BKE_particlesettings_copy(bmain, part);