Commit: 90a463dcfc65a2e21134423d75101e32eba7b791 Author: Bastien Montagne Date: Tue Jun 20 21:34:18 2017 +0200 Branches: id_copy_refactor https://developer.blender.org/rB90a463dcfc65a2e21134423d75101e32eba7b791
Add new Curve copying code. =================================================================== M source/blender/blenkernel/BKE_curve.h M source/blender/blenkernel/intern/curve.c M source/blender/blenkernel/intern/library.c =================================================================== diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 0d382c8a49c..340a3e842e6 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -78,6 +78,7 @@ void BKE_curve_free(struct Curve *cu); void BKE_curve_editfont_free(struct Curve *cu); void BKE_curve_init(struct Curve *cu); struct Curve *BKE_curve_add(struct Main *bmain, const char *name, int type); +void BKE_curve_copy_ex(struct Main *bmain, struct Curve *cu_dst, const struct Curve *cu_src, const int flag); struct Curve *BKE_curve_copy(struct Main *bmain, const struct Curve *cu); void BKE_curve_make_local(struct Main *bmain, struct Curve *cu, const bool lib_local); short BKE_curve_type_get(struct Curve *cu); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 8b32109cf2b..9e3d8dccd3a 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -187,42 +187,46 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type) return cu; } -Curve *BKE_curve_copy(Main *bmain, const Curve *cu) +void BKE_curve_copy_ex(Main *bmain, Curve *cu_dst, const Curve *cu_src, const int flag) { - Curve *cun; int a; - cun = BKE_libblock_copy(bmain, &cu->id); - - BLI_listbase_clear(&cun->nurb); - BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb)); + BLI_listbase_clear(&cu_dst->nurb); + BKE_nurbList_duplicate(&(cu_dst->nurb), &(cu_src->nurb)); - cun->mat = MEM_dupallocN(cu->mat); - for (a = 0; a < cun->totcol; a++) { - id_us_plus((ID *)cun->mat[a]); + cu_dst->mat = MEM_dupallocN(cu_src->mat); + if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) { + for (a = 0; a < cu_dst->totcol; a++) { + id_us_plus((ID *)cu_dst->mat[a]); + } } - cun->str = MEM_dupallocN(cu->str); - cun->strinfo = MEM_dupallocN(cu->strinfo); - cun->tb = MEM_dupallocN(cu->tb); - cun->bb = MEM_dupallocN(cu->bb); + cu_dst->str = MEM_dupallocN(cu_src->str); + cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo); + cu_dst->tb = MEM_dupallocN(cu_src->tb); + cu_dst->bb = MEM_dupallocN(cu_src->bb); - if (cu->key) { - cun->key = BKE_key_copy(bmain, cu->key); - cun->key->from = (ID *)cun; + if (cu_src->key) { + BKE_id_copy_ex(bmain, &cu_src->key->id, (ID **)&cu_dst->key, flag, false); + cu_dst->key->id.tag &= ~LIB_TAG_FREE_NO_USER_REFCOUNT; /* XXX Bad hack, to be solved better hopefully :( */ } - cun->editnurb = NULL; - cun->editfont = NULL; - - id_us_plus((ID *)cun->vfont); - id_us_plus((ID *)cun->vfontb); - id_us_plus((ID *)cun->vfonti); - id_us_plus((ID *)cun->vfontbi); + cu_dst->editnurb = NULL; + cu_dst->editfont = NULL; - BKE_id_copy_ensure_local(bmain, &cu->id, &cun->id); + if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) { + id_us_plus((ID *)cu_dst->vfont); + id_us_plus((ID *)cu_dst->vfontb); + id_us_plus((ID *)cu_dst->vfonti); + id_us_plus((ID *)cu_dst->vfontbi); + } +} - return cun; +Curve *BKE_curve_copy(Main *bmain, const Curve *cu) +{ + Curve *cu_copy; + BKE_id_copy_ex(bmain, &cu->id, (ID **)&cu_copy, 0, false); + return cu_copy; } void BKE_curve_make_local(Main *bmain, Curve *cu, const bool lib_local) diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 4f2adfef5e3..b765eafa141 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -532,7 +532,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con if (!test) { /* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */ - if (ELEM(GS(id->name), ID_OB, ID_ME, ID_KE)) { + if (ELEM(GS(id->name), ID_OB, ID_ME, ID_CU, ID_KE)) { BKE_libblock_copy_ex(bmain, id, r_newid, flag); } } @@ -545,7 +545,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con if (!test) BKE_mesh_copy_ex(bmain, (Mesh *)*r_newid, (Mesh *)id, flag_idtype_copy); break; case ID_CU: - if (!test) *r_newid = (ID *)BKE_curve_copy(bmain, (Curve *)id); + if (!test) BKE_curve_copy_ex(bmain, (Curve *)*r_newid, (Curve *)id, flag_idtype_copy); break; case ID_MB: if (!test) *r_newid = (ID *)BKE_mball_copy(bmain, (MetaBall *)id); @@ -633,7 +633,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con if (!test) { /* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */ - if (ELEM(GS(id->name), ID_OB, ID_ME, ID_KE)) { + if (ELEM(GS(id->name), ID_OB, ID_ME, ID_CU, ID_KE)) { /* Update ID refcount, remap pointers to self in new ID. */ struct IDCopyLibManagementData data = {.id_src=id, .flag=flag}; BKE_library_foreach_ID_link(bmain, *r_newid, id_copy_libmanagement_cb, &data, IDWALK_NOP); @@ -642,10 +642,10 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con * Since we call IDType-spefici copying logic without 'userrefcount' flag, we need to redo this here. * Note/TODO: maybe we'll make IDType copying functions 'private' to be only used by this one, * in which case we could solve this issue in a better and nicer way. */ - Key *key = BKE_key_from_id(*r_newid); + ID *key = (ID *)BKE_key_from_id(*r_newid); if (key) { - data.id_src = BKE_key_from_id((ID *)id); - BKE_library_foreach_ID_link(bmain, &key->id, id_copy_libmanagement_cb, &data, IDWALK_NOP); + data.id_src = (ID *)BKE_key_from_id((ID *)id); + BKE_library_foreach_ID_link(bmain, key, id_copy_libmanagement_cb, &data, IDWALK_NOP); } /* TODO: most likely same for nodes too? */ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs