Cleanup: factorize the 'ensure local' part of datablock copy into a single BKE_id_copy_ensure_local function.

This commit is contained in:
2016-07-25 16:15:37 +02:00
parent d9cc3ea2c6
commit 1870e166de
24 changed files with 34 additions and 88 deletions

View File

@@ -86,6 +86,7 @@ bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, s
bool id_copy(struct Main *bmain, struct ID *id, struct ID **newid, bool test); bool id_copy(struct Main *bmain, struct ID *id, struct ID **newid, bool test);
void id_sort_by_name(struct ListBase *lb, struct ID *id); void id_sort_by_name(struct ListBase *lb, struct ID *id);
void BKE_id_expand_local(struct ID *id); void BKE_id_expand_local(struct ID *id);
void BKE_id_copy_ensure_local(struct Main *bmain, struct ID *old_id, struct ID *new_id);
bool new_id(struct ListBase *lb, struct ID *id, const char *name); bool new_id(struct ListBase *lb, struct ID *id, const char *name);
void id_clear_lib_data(struct Main *bmain, struct ID *id); void id_clear_lib_data(struct Main *bmain, struct ID *id);

View File

@@ -156,10 +156,7 @@ bAction *BKE_action_copy(Main *bmain, bAction *src)
} }
} }
if (ID_IS_LINKED_DATABLOCK(src)) { BKE_id_copy_ensure_local(bmain, &src->id, &dst->id);
BKE_id_expand_local(&dst->id);
BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id);
}
return dst; return dst;
} }

View File

@@ -194,10 +194,7 @@ bArmature *BKE_armature_copy(Main *bmain, bArmature *arm)
newArm->act_edbone = NULL; newArm->act_edbone = NULL;
newArm->sketch = NULL; newArm->sketch = NULL;
if (ID_IS_LINKED_DATABLOCK(arm)) { BKE_id_copy_ensure_local(bmain, &arm->id, &newArm->id);
BKE_id_expand_local(&newArm->id);
BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id);
}
return newArm; return newArm;
} }

View File

@@ -197,10 +197,7 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
/* enable fake user by default */ /* enable fake user by default */
id_fake_user_set(&brush->id); id_fake_user_set(&brush->id);
if (ID_IS_LINKED_DATABLOCK(brush)) { BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id);
BKE_id_expand_local(&brushn->id);
BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id);
}
return brushn; return brushn;
} }

View File

@@ -99,10 +99,7 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam)
camn = BKE_libblock_copy(bmain, &cam->id); camn = BKE_libblock_copy(bmain, &cam->id);
if (ID_IS_LINKED_DATABLOCK(cam)) { BKE_id_copy_ensure_local(bmain, &cam->id, &camn->id);
BKE_id_expand_local(&camn->id);
BKE_id_lib_local_paths(bmain, cam->id.lib, &camn->id);
}
return camn; return camn;
} }

View File

@@ -207,10 +207,7 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
id_us_plus((ID *)cun->vfonti); id_us_plus((ID *)cun->vfonti);
id_us_plus((ID *)cun->vfontbi); id_us_plus((ID *)cun->vfontbi);
if (ID_IS_LINKED_DATABLOCK(cu)) { BKE_id_copy_ensure_local(bmain, &cu->id, &cun->id);
BKE_id_expand_local(&cun->id);
BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id);
}
return cun; return cun;
} }

View File

@@ -97,10 +97,7 @@ Group *BKE_group_copy(Main *bmain, Group *group)
/* Do not copy group's preview (same behavior as for objects). */ /* Do not copy group's preview (same behavior as for objects). */
groupn->preview = NULL; groupn->preview = NULL;
if (ID_IS_LINKED_DATABLOCK(group)) { BKE_id_copy_ensure_local(bmain, &group->id, &groupn->id);
BKE_id_expand_local(&groupn->id);
BKE_id_lib_local_paths(bmain, group->id.lib, &groupn->id);
}
return groupn; return groupn;
} }

View File

@@ -462,10 +462,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
BKE_previewimg_id_copy(&nima->id, &ima->id); BKE_previewimg_id_copy(&nima->id, &ima->id);
if (ID_IS_LINKED_DATABLOCK(ima)) { BKE_id_copy_ensure_local(bmain, &ima->id, &nima->id);
BKE_id_expand_local(&nima->id);
BKE_id_lib_local_paths(bmain, ima->id.lib, &nima->id);
}
return nima; return nima;
} }

View File

@@ -170,10 +170,7 @@ Key *BKE_key_copy(Main *bmain, Key *key)
kb = kb->next; kb = kb->next;
} }
if (ID_IS_LINKED_DATABLOCK(key)) { BKE_id_copy_ensure_local(bmain, &key->id, &keyn->id);
BKE_id_expand_local(&keyn->id);
BKE_id_lib_local_paths(bmain, key->id.lib, &keyn->id);
}
return keyn; return keyn;
} }

View File

@@ -138,10 +138,7 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
BKE_previewimg_id_copy(&lan->id, &la->id); BKE_previewimg_id_copy(&lan->id, &la->id);
if (ID_IS_LINKED_DATABLOCK(la)) { BKE_id_copy_ensure_local(bmain, &la->id, &lan->id);
BKE_id_expand_local(&lan->id);
BKE_id_lib_local_paths(bmain, la->id.lib, &lan->id);
}
return lan; return lan;
} }

View File

@@ -297,10 +297,7 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
ltn->editlatt = NULL; ltn->editlatt = NULL;
if (ID_IS_LINKED_DATABLOCK(lt)) { BKE_id_copy_ensure_local(bmain, &lt->id, &ltn->id);
BKE_id_expand_local(&ltn->id);
BKE_id_lib_local_paths(bmain, lt->id.lib, &ltn->id);
}
return ltn; return ltn;
} }

View File

@@ -271,6 +271,17 @@ void BKE_id_expand_local(ID *id)
BKE_library_foreach_ID_link(id, id_expand_local_callback, NULL, 0); BKE_library_foreach_ID_link(id, id_expand_local_callback, NULL, 0);
} }
/**
* Ensure new (copied) ID is fully made local.
*/
void BKE_id_copy_ensure_local(Main *bmain, ID *old_id, ID *new_id)
{
if (ID_IS_LINKED_DATABLOCK(old_id)) {
BKE_id_expand_local(new_id);
BKE_id_lib_local_paths(bmain, old_id->lib, new_id);
}
}
/** /**
* Generic 'make local' function, works for most of datablock types... * Generic 'make local' function, works for most of datablock types...
*/ */

View File

@@ -218,10 +218,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle *l
for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next) for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next)
BKE_linestyle_geometry_modifier_copy(new_linestyle, m); BKE_linestyle_geometry_modifier_copy(new_linestyle, m);
if (ID_IS_LINKED_DATABLOCK(linestyle)) { BKE_id_copy_ensure_local(bmain, &linestyle->id, &new_linestyle->id);
BKE_id_expand_local(&new_linestyle->id);
BKE_id_lib_local_paths(bmain, linestyle->id.lib, &new_linestyle->id);
}
return new_linestyle; return new_linestyle;
} }

View File

@@ -853,10 +853,7 @@ Mask *BKE_mask_copy(Main *bmain, Mask *mask)
/* enable fake user by default */ /* enable fake user by default */
id_fake_user_set(&mask->id); id_fake_user_set(&mask->id);
if (ID_IS_LINKED_DATABLOCK(mask)) { BKE_id_copy_ensure_local(bmain, &mask->id, &mask_new->id);
BKE_id_expand_local(&mask_new->id);
BKE_id_lib_local_paths(bmain, mask->id.lib, &mask_new->id);
}
return mask_new; return mask_new;
} }

View File

@@ -247,10 +247,7 @@ Material *BKE_material_copy(Main *bmain, Material *ma)
BLI_listbase_clear(&man->gpumaterial); BLI_listbase_clear(&man->gpumaterial);
if (ID_IS_LINKED_DATABLOCK(ma)) { BKE_id_copy_ensure_local(bmain, &ma->id, &man->id);
BKE_id_expand_local(&man->id);
BKE_id_lib_local_paths(bmain, ma->id.lib, &man->id);
}
return man; return man;
} }

View File

@@ -119,10 +119,7 @@ MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
mbn->editelems = NULL; mbn->editelems = NULL;
mbn->lastelem = NULL; mbn->lastelem = NULL;
if (ID_IS_LINKED_DATABLOCK(mb)) { BKE_id_copy_ensure_local(bmain, &mb->id, &mbn->id);
BKE_id_expand_local(&mbn->id);
BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id);
}
return mbn; return mbn;
} }

View File

@@ -531,10 +531,7 @@ Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
men->key->from = (ID *)men; men->key->from = (ID *)men;
} }
if (ID_IS_LINKED_DATABLOCK(me)) { BKE_id_copy_ensure_local(bmain, &me->id, &men->id);
BKE_id_expand_local(&men->id);
BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);
}
return men; return men;
} }

View File

@@ -1290,10 +1290,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, Main *bmain, bool ski
/* node tree will generate its own interface type */ /* node tree will generate its own interface type */
newtree->interface_type = NULL; newtree->interface_type = NULL;
if (ID_IS_LINKED_DATABLOCK(ntree)) { BKE_id_copy_ensure_local(bmain, &ntree->id, &newtree->id);
BKE_id_expand_local(&newtree->id);
BKE_id_lib_local_paths(bmain, ntree->id.lib, &newtree->id);
}
return newtree; return newtree;
} }

View File

@@ -1169,10 +1169,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches)
/* Copy runtime surve data. */ /* Copy runtime surve data. */
obn->curve_cache = NULL; obn->curve_cache = NULL;
if (ID_IS_LINKED_DATABLOCK(ob)) { BKE_id_copy_ensure_local(bmain, &ob->id, &obn->id);
BKE_id_expand_local(&obn->id);
BKE_id_lib_local_paths(bmain, ob->id.lib, &obn->id);
}
/* Do not copy object's preview (mostly due to the fact renderers create temp copy of objects). */ /* Do not copy object's preview (mostly due to the fact renderers create temp copy of objects). */
obn->preview = NULL; obn->preview = NULL;

View File

@@ -3335,10 +3335,7 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
BLI_duplicatelist(&partn->dupliweights, &part->dupliweights); BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
if (ID_IS_LINKED_DATABLOCK(part)) { BKE_id_copy_ensure_local(bmain, &part->id, &partn->id);
BKE_id_expand_local(&partn->id);
BKE_id_lib_local_paths(bmain, part->id.lib, &partn->id);
}
return partn; return partn;
} }

View File

@@ -77,10 +77,7 @@ Speaker *BKE_speaker_copy(Main *bmain, Speaker *spk)
if (spkn->sound) if (spkn->sound)
id_us_plus(&spkn->sound->id); id_us_plus(&spkn->sound->id);
if (ID_IS_LINKED_DATABLOCK(spk)) { BKE_id_copy_ensure_local(bmain, &spk->id, &spkn->id);
BKE_id_expand_local(&spkn->id);
BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
}
return spkn; return spkn;
} }

View File

@@ -491,10 +491,7 @@ Text *BKE_text_copy(Main *bmain, Text *ta)
init_undo_text(tan); init_undo_text(tan);
if (ID_IS_LINKED_DATABLOCK(ta)) { BKE_id_copy_ensure_local(bmain, &ta->id, &tan->id);
BKE_id_expand_local(&tan->id);
BKE_id_lib_local_paths(bmain, ta->id.lib, &tan->id);
}
return tan; return tan;
} }

View File

@@ -873,10 +873,7 @@ Tex *BKE_texture_copy(Main *bmain, Tex *tex)
BKE_previewimg_id_copy(&texn->id, &tex->id); BKE_previewimg_id_copy(&texn->id, &tex->id);
if (ID_IS_LINKED_DATABLOCK(tex)) { BKE_id_copy_ensure_local(bmain, &tex->id, &texn->id);
BKE_id_expand_local(&texn->id);
BKE_id_lib_local_paths(bmain, tex->id.lib, &texn->id);
}
return texn; return texn;
} }

View File

@@ -142,10 +142,7 @@ World *BKE_world_copy(Main *bmain, World *wrld)
BLI_listbase_clear(&wrldn->gpumaterial); BLI_listbase_clear(&wrldn->gpumaterial);
if (ID_IS_LINKED_DATABLOCK(wrld)) { BKE_id_copy_ensure_local(bmain, &wrld->id, &wrldn->id);
BKE_id_expand_local(&wrldn->id);
BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrldn->id);
}
return wrldn; return wrldn;
} }