diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-09 16:08:24 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-09 16:44:12 +0300 |
commit | 11f64f494b715498e4cbc147ae6a9d10538dc055 (patch) | |
tree | 9d7e7f9dfdce67c5ab285315e67736b56762faa7 /source/blender | |
parent | 9044ccec5f811fd380fc0348d91d1c53729eea22 (diff) |
Refactor/enhance BKE_curve_make_local(), and add BKE_curve_copy_ex() that takes a Main as parameter.
Now using modern features from libquery/libremap areas.
Provides same kind of fixes/improvements as for BKE_object_make_local() (see rBd1a4ae3f395a6).
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_curve.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 84 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 2 | ||||
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 10 | ||||
-rw-r--r-- | source/blender/editors/object/object_relations.c | 2 |
8 files changed, 51 insertions, 58 deletions
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 659884d96a4..ef3d14ce16b 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -71,7 +71,8 @@ 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); struct Curve *BKE_curve_copy(struct Curve *cu); -void BKE_curve_make_local(struct Curve *cu); +struct Curve *BKE_curve_copy_ex(struct Main *bmain, struct Curve *cu); +void BKE_curve_make_local(struct Main *bmain, struct Curve *cu); short BKE_curve_type_get(struct Curve *cu); void BKE_curve_type_test(struct Object *ob); void BKE_curve_curve_dimension_update(struct Curve *cu); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 61c4b1b3368..d3c5d28ddbb 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -58,6 +58,8 @@ #include "BKE_global.h" #include "BKE_key.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_object.h" #include "BKE_material.h" @@ -172,12 +174,13 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type) return cu; } -Curve *BKE_curve_copy(Curve *cu) +Curve *BKE_curve_copy_ex(Main *bmain, Curve *cu) { Curve *cun; int a; - cun = BKE_libblock_copy(&cu->id); + cun = BKE_libblock_copy_ex(bmain, &cu->id); + BLI_listbase_clear(&cun->nurb); BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb)); @@ -210,28 +213,34 @@ Curve *BKE_curve_copy(Curve *cu) id_us_plus((ID *)cun->vfontbi); if (ID_IS_LINKED_DATABLOCK(cu)) { - BKE_id_lib_local_paths(G.main, cu->id.lib, &cun->id); + BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id); } return cun; } -static void extern_local_curve(Curve *cu) +Curve *BKE_curve_copy(Curve *cu) { - id_lib_extern((ID *)cu->vfont); - id_lib_extern((ID *)cu->vfontb); - id_lib_extern((ID *)cu->vfonti); - id_lib_extern((ID *)cu->vfontbi); + return BKE_curve_copy_ex(G.main, cu); +} - if (cu->mat) { - extern_local_matarar(cu->mat, cu->totcol); +static int extern_local_curve_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; } -void BKE_curve_make_local(Curve *cu) +static void extern_local_curve(Curve *cu) +{ + BKE_library_foreach_ID_link(&cu->id, extern_local_curve_callback, NULL, 0); +} + +void BKE_curve_make_local(Main *bmain, Curve *cu) { - Main *bmain = G.main; - Object *ob; bool is_local = false, is_lib = false; /* - when there are only lib users: don't do @@ -239,46 +248,29 @@ void BKE_curve_make_local(Curve *cu) * - mixed: do a copy */ - if (!ID_IS_LINKED_DATABLOCK(cu)) - return; - - if (cu->id.us == 1) { - id_clear_lib_data(bmain, &cu->id); - if (cu->key) { - BKE_key_make_local(bmain, cu->key); - } - extern_local_curve(cu); + if (!ID_IS_LINKED_DATABLOCK(cu)) { return; } - for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { - if (ob->data == cu) { - if (ID_IS_LINKED_DATABLOCK(ob)) is_lib = true; - else is_local = true; - } - } + BKE_library_ID_test_usages(bmain, cu, &is_local, &is_lib); - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &cu->id); - if (cu->key) { - BKE_key_make_local(bamin, cu->key); + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &cu->id); + if (cu->key) { + BKE_key_make_local(bmain, cu->key); + } + extern_local_curve(cu); } - extern_local_curve(cu); - } - else if (is_local && is_lib) { - Curve *cu_new = BKE_curve_copy(cu); - cu_new->id.us = 0; + else { + Curve *cu_new = BKE_curve_copy_ex(bmain, cu); - BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id); + cu_new->id.us = 0; - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->data == cu) { - if (!ID_IS_LINKED_DATABLOCK(ob)) { - ob->data = cu_new; - id_us_plus(&cu_new->id); - id_us_min(&cu->id); - } - } + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id); + + BKE_libblock_remap(bmain, cu, cu_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index fbffe56a1e8..c7a7bb0c0f7 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -270,7 +270,7 @@ bool id_make_local(Main *bmain, ID *id, bool test) if (!test) BKE_mesh_make_local(bmain, (Mesh *)id); return true; case ID_CU: - if (!test) BKE_curve_make_local((Curve *)id); + if (!test) BKE_curve_make_local(bmain, (Curve *)id); return true; case ID_MB: if (!test) BKE_mball_make_local((MetaBall *)id); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 82667484f1c..de9be3d835d 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -589,7 +589,7 @@ static int extern_local_mesh_callback( if ((cd_flag & IDWALK_USER) && *id_pointer) { id_lib_extern(*id_pointer); } - return IDWALK_NOP; + return IDWALK_RET_NOP; } static void expand_local_mesh(Mesh *me) @@ -2338,7 +2338,7 @@ Mesh *BKE_mesh_new_from_object( BKE_object_free_modifiers(tmpobj); /* copies the data */ - copycu = tmpobj->data = BKE_curve_copy((Curve *) ob->data); + copycu = tmpobj->data = BKE_curve_copy_ex(bmain, (Curve *) ob->data); /* temporarily set edit so we get updates from edit mode, but * also because for text datablocks copying it while in edit diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index e95e860e18b..623c437fea5 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1193,7 +1193,7 @@ static int extern_local_object_callback( if ((cd_flag & IDWALK_USER) && *id_pointer) { id_lib_extern(*id_pointer); } - return IDWALK_NOP; + return IDWALK_RET_NOP; } static void extern_local_object(Object *ob) diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index d87f8a6d93d..9e04f410333 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1301,7 +1301,7 @@ static int separate_exec(bContext *C, wmOperator *op) DAG_relations_tag_update(bmain); newob = newbase->object; - newcu = newob->data = BKE_curve_copy(oldcu); + newcu = newob->data = BKE_curve_copy_ex(bmain, oldcu); newcu->editnurb = NULL; id_us_min(&oldcu->id); /* because new curve is a copy: reduce user count */ diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 69950ccc9a9..d160a62a3f4 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -1673,7 +1673,7 @@ static int convert_exec(bContext *C, wmOperator *op) id_us_min(&((Curve *)newob->data)->id); /* make a new copy of the curve */ - newob->data = BKE_curve_copy(ob->data); + newob->data = BKE_curve_copy_ex(bmain, ob->data); } else { newob = ob; @@ -1744,7 +1744,7 @@ static int convert_exec(bContext *C, wmOperator *op) id_us_min(&((Curve *)newob->data)->id); /* make a new copy of the curve */ - newob->data = BKE_curve_copy(ob->data); + newob->data = BKE_curve_copy_ex(bmain, ob->data); } else { newob = ob; @@ -1986,7 +1986,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_CURVE) { ID_NEW_US2(obn->data) else { - obn->data = BKE_curve_copy(obn->data); + obn->data = BKE_curve_copy_ex(bmain, obn->data); didit = 1; } id_us_min(id); @@ -1996,7 +1996,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_SURF) { ID_NEW_US2(obn->data) else { - obn->data = BKE_curve_copy(obn->data); + obn->data = BKE_curve_copy_ex(bmain, obn->data); didit = 1; } id_us_min(id); @@ -2006,7 +2006,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base if (dupflag & USER_DUP_FONT) { ID_NEW_US2(obn->data) else { - obn->data = BKE_curve_copy(obn->data); + obn->data = BKE_curve_copy_ex(bmain, obn->data); didit = 1; } id_us_min(id); diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 255477b4d90..fff4725951c 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1886,7 +1886,7 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag) case OB_CURVE: case OB_SURF: case OB_FONT: - ob->data = cu = BKE_curve_copy(ob->data); + ob->data = cu = BKE_curve_copy_ex(bmain, ob->data); ID_NEW(cu->bevobj); ID_NEW(cu->taperobj); if (cu->key) |