[Bf-blender-cvs] [b708dce] master: Cleanup: Rename BKE_libblock_relink, and move it to BKE_library_remap.h

Bastien Montagne noreply at git.blender.org
Mon Dec 12 15:06:58 CET 2016


Commit: b708dce34f8caa52efba7ddf7ed00582a36e38f9
Author: Bastien Montagne
Date:   Mon Dec 12 14:58:10 2016 +0100
Branches: master
https://developer.blender.org/rBb708dce34f8caa52efba7ddf7ed00582a36e38f9

Cleanup: Rename BKE_libblock_relink, and move it to BKE_library_remap.h

Was a waaaaayyyyy to much generic name for such a specific func, renamed
to much more descriptive BKE_libblock_relink_to_newid().

In near future (few weeks, to limit as much as possible silent mismatch
in branches), will rename BKE_libblock_relink_ex to BKE_libblock_relink,
this is the real generic data-block relinking func!

===================================================================

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/BKE_library_remap.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/library_remap.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_relations.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 77ea7ec..2d9c35f 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -56,7 +56,6 @@ void  BKE_libblock_init_empty(struct ID *id);
 void *BKE_libblock_copy(struct Main *bmain, struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 void *BKE_libblock_copy_nolib(struct ID *id, const bool do_action) ATTR_NONNULL();
 void  BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const bool do_action);
-void  BKE_libblock_relink(struct ID *id);
 void  BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
 void  BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
 
diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h
index 89b0870..53d438a 100644
--- a/source/blender/blenkernel/BKE_library_remap.h
+++ b/source/blender/blenkernel/BKE_library_remap.h
@@ -64,6 +64,7 @@ void BKE_libblock_relink_ex(
         struct Main *bmain, void *idv, void *old_idv, void *new_idv,
         const bool us_min_never_null) ATTR_NONNULL(1, 2);
 
+void  BKE_libblock_relink_to_newid(struct ID *id) ATTR_NONNULL();
 
 typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
 typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 31c10c8..65f37d0 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -1173,31 +1173,6 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action)
 	return idn;
 }
 
-static int id_relink_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag)
-{
-	ID *id = *id_pointer;
-	if (id) {
-		/* See: NEW_ID macro */
-		if (id->newid) {
-			BKE_library_update_ID_link_user(id->newid, id, cd_flag);
-			*id_pointer = id->newid;
-		}
-		else if (id->tag & LIB_TAG_NEW) {
-			id->tag &= ~LIB_TAG_NEW;
-			BKE_libblock_relink(id);
-		}
-	}
-	return IDWALK_RET_NOP;
-}
-
-void BKE_libblock_relink(ID *id)
-{
-	if (ID_IS_LINKED_DATABLOCK(id))
-		return;
-
-	BKE_library_foreach_ID_link(id, id_relink_looper, NULL, 0);
-}
-
 void BKE_library_free(Library *lib)
 {
 	if (lib->packedfile)
diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c
index 62f5983..4f1f6d9 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -680,6 +680,35 @@ void BKE_libblock_relink_ex(
 	}
 }
 
+static int id_relink_to_newid_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag)
+{
+	ID *id = *id_pointer;
+	if (id) {
+		/* See: NEW_ID macro */
+		if (id->newid) {
+			BKE_library_update_ID_link_user(id->newid, id, cd_flag);
+			*id_pointer = id->newid;
+		}
+		else if (id->tag & LIB_TAG_NEW) {
+			id->tag &= ~LIB_TAG_NEW;
+			BKE_libblock_relink_to_newid(id);
+		}
+	}
+	return IDWALK_RET_NOP;
+}
+
+/** Similar to libblock_relink_ex, but is remapping IDs to their newid value if non-NULL, in given \a id.
+ *
+ * Very specific usage, not sure we'll keep it on the long run, currently only used in Object duplication code...
+ */
+void BKE_libblock_relink_to_newid(ID *id)
+{
+	if (ID_IS_LINKED_DATABLOCK(id))
+		return;
+
+	BKE_library_foreach_ID_link(id, id_relink_to_newid_looper, NULL, 0);
+}
+
 void BKE_libblock_free_data(Main *UNUSED(bmain), ID *id)
 {
 	if (id->properties) {
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 02dd3ed..f42dafd 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -75,6 +75,7 @@
 #include "BKE_lattice.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
+#include "BKE_library_remap.h"
 #include "BKE_key.h"
 #include "BKE_main.h"
 #include "BKE_material.h"
@@ -1241,7 +1242,7 @@ static void copy_object_set_idnew(bContext *C)
 
 	CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
 	{
-		BKE_libblock_relink(&ob->id);
+		BKE_libblock_relink_to_newid(&ob->id);
 	}
 	CTX_DATA_END;
 
@@ -1395,7 +1396,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
 		}
 
 		/* Remap new object to itself, and clear again newid pointer of orig object. */
-		BKE_libblock_relink(&ob->id);
+		BKE_libblock_relink_to_newid(&ob->id);
 		set_sca_new_poins_ob(ob);
 		BKE_id_clear_newpoin(&dob->ob->id);
 
@@ -2219,7 +2220,7 @@ Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag
 	ob = basen->object;
 
 	/* link own references to the newly duplicated data [#26816] */
-	BKE_libblock_relink(&ob->id);
+	BKE_libblock_relink_to_newid(&ob->id);
 	set_sca_new_poins_ob(ob);
 
 	/* DAG_relations_tag_update(bmain); */ /* caller must do */
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index d670f4b..d30022c 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -76,6 +76,7 @@
 #include "BKE_lattice.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
+#include "BKE_library_remap.h"
 #include "BKE_main.h"
 #include "BKE_material.h"
 #include "BKE_mball.h"
@@ -1806,7 +1807,7 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in
 
 	/* object and group pointers */
 	for (base = FIRSTBASE; base; base = base->next) {
-		BKE_libblock_relink(&base->object->id);
+		BKE_libblock_relink_to_newid(&base->object->id);
 	}
 
 	set_sca_new_poins();




More information about the Bf-blender-cvs mailing list