[Bf-blender-cvs] [f2d6e85] id-remap: ID remapping: first step - modify some editors callback to not only support ID freeing, but also ID remapping.

Bastien Montagne noreply at git.blender.org
Tue Jul 21 22:43:01 CEST 2015


Commit: f2d6e8521239ded63a7ef6ca3839574dc5bcaad8
Author: Bastien Montagne
Date:   Thu Jul 16 21:37:06 2015 +0200
Branches: id-remap
https://developer.blender.org/rBf2d6e8521239ded63a7ef6ca3839574dc5bcaad8

ID remapping: first step - modify some editors callback to not only support ID freeing, but also ID remapping.

This seems to be OK, but will obviously need much more testing - and is useless as-is, we need
the big ID remapping code itself still.

Also, Nodetrees' remapping of Scene IDs is still TODO, not sure yet how to do this.

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/screen.c
M	source/blender/editors/include/ED_buttons.h
M	source/blender/editors/include/ED_node.h
M	source/blender/editors/include/ED_outliner.h
M	source/blender/editors/include/ED_util.h
M	source/blender/editors/space_buttons/buttons_context.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_outliner/outliner_edit.c
M	source/blender/editors/util/ed_util.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_init_exit.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 6ecc955..761a81e 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -109,7 +109,7 @@ struct ID *BKE_libblock_find_name(const short type, const char *name) ATTR_WARN_
 
 void BKE_library_callback_free_window_manager_set(void (*func)(struct bContext *, struct wmWindowManager *));
 void BKE_library_callback_free_notifier_reference_set(void (*func)(const void *));
-void BKE_library_callback_free_editor_id_reference_set(void (*func)(const struct ID *));
+void BKE_library_callback_remap_editor_id_reference_set(void (*func)(const struct ID *, struct ID *));
 
 /* use when "" is given to new_id() */
 #define ID_FALLBACK_NAME N_("Untitled")
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 4861641..6eb19be 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -273,7 +273,7 @@ void BKE_spacedata_freelist(ListBase *lb);
 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2);
 void BKE_spacedata_draw_locks(int set);
 
-void BKE_spacedata_callback_id_unref_set(void (*func)(struct SpaceLink *sl, const struct ID *));
+void BKE_spacedata_callback_id_remap_set(void (*func)(struct SpaceLink *sl, const struct ID *, struct ID *));
 void BKE_spacedata_id_unref(struct SpaceLink *sl, const struct ID *id);
 
 /* area/regions */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index b4bb07f..9a3f43c 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -876,16 +876,16 @@ void BKE_library_callback_free_window_manager_set(void (*func)(bContext *C, wmWi
 
 static void (*free_notifier_reference_cb)(const void *) = NULL;
 
-void BKE_library_callback_free_notifier_reference_set(void (*func)(const void *) )
+void BKE_library_callback_free_notifier_reference_set(void (*func)(const void *))
 {
 	free_notifier_reference_cb = func;
 }
 
-static void (*free_editor_id_reference_cb)(const ID *) = NULL;
+static void (*remap_editor_id_reference_cb)(const ID *, ID *) = NULL;
 
-void BKE_library_callback_free_editor_id_reference_set(void (*func)(const ID *))
+void BKE_library_callback_remap_editor_id_reference_set(void (*func)(const ID *, ID *))
 {
-	free_editor_id_reference_cb = func;
+	remap_editor_id_reference_cb = func;
 }
 
 static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata)
@@ -1048,8 +1048,8 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
 		free_notifier_reference_cb(id);
 	}
 
-	if (free_editor_id_reference_cb) {
-		free_editor_id_reference_cb(id);
+	if (remap_editor_id_reference_cb) {
+		remap_editor_id_reference_cb(id, NULL);
 	}
 
 	BLI_remlink(lb, id);
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 4125a35..d64a57f 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -272,17 +272,18 @@ void BKE_spacedata_draw_locks(int set)
 	}
 }
 
-static void (*spacedata_id_unref_cb)(struct SpaceLink *sl, const struct ID *id) = NULL;
+static void (*spacedata_id_remap_cb)(struct SpaceLink *sl, const ID *old_id, ID *new_id) = NULL;
 
-void BKE_spacedata_callback_id_unref_set(void (*func)(struct SpaceLink *sl, const struct ID *))
+void BKE_spacedata_callback_id_remap_set(void (*func)(struct SpaceLink *sl, const ID *, ID *))
 {
-	spacedata_id_unref_cb = func;
+	spacedata_id_remap_cb = func;
 }
 
+/* UNUSED!!! */
 void BKE_spacedata_id_unref(struct SpaceLink *sl, const struct ID *id)
 {
-	if (spacedata_id_unref_cb) {
-		spacedata_id_unref_cb(sl, id);
+	if (spacedata_id_remap_cb) {
+		spacedata_id_remap_cb(sl, id, NULL);
 	}
 }
 
diff --git a/source/blender/editors/include/ED_buttons.h b/source/blender/editors/include/ED_buttons.h
index 9a987d7..52ca00d 100644
--- a/source/blender/editors/include/ED_buttons.h
+++ b/source/blender/editors/include/ED_buttons.h
@@ -37,6 +37,6 @@ bool ED_texture_context_check_particles(const struct bContext *C);
 bool ED_texture_context_check_linestyle(const struct bContext *C);
 bool ED_texture_context_check_others(const struct bContext *C);
 
-void ED_buttons_id_unref(struct SpaceButs *sbuts, const struct ID *id);
+void ED_buttons_id_remap(struct SpaceButs *sbuts, const struct ID *old_id, struct ID *new_id);
 
 #endif /*  __ED_BUTTONS_H__ */
diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index 1445308..ec72fb4 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -103,7 +103,7 @@ void ED_node_set_active(struct Main *bmain, struct bNodeTree *ntree, struct bNod
 
 void ED_node_composite_job(const struct bContext *C, struct bNodeTree *nodetree, struct Scene *scene_owner);
 
-void ED_node_id_unref(struct SpaceNode *snode, const ID *id);
+void ED_node_id_remap(struct SpaceNode *snode, const ID *old_id, ID *new_id);
 
 /* node_ops.c */
 void ED_operatormacros_node(void);
diff --git a/source/blender/editors/include/ED_outliner.h b/source/blender/editors/include/ED_outliner.h
index af4af8e..cdab233 100644
--- a/source/blender/editors/include/ED_outliner.h
+++ b/source/blender/editors/include/ED_outliner.h
@@ -31,6 +31,6 @@ struct ID;
 struct SpaceOops;
 
 /* Used to check whether a given texture context is valid in current context. */
-void ED_outliner_id_unref(struct SpaceOops *so, const struct ID *id);
+void ED_outliner_id_remap(struct SpaceOops *so, const struct ID *old_id, struct ID *new_id);
 
 #endif /*  __ED_OUTLINER_H__ */
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 496ce7f..24d05b3 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -42,7 +42,7 @@ void    ED_editors_exit(struct bContext *C);
 
 bool    ED_editors_flush_edits(const struct bContext *C, bool for_render);
 
-void ED_spacedata_id_unref(struct SpaceLink *sl, const struct ID *id);
+void ED_spacedata_id_remap(struct SpaceLink *sl, const struct ID *old_id, ID *new_id);
 
 /* ************** Undo ************************ */
 
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index bc42f1d..1d74974 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -1181,11 +1181,13 @@ ID *buttons_context_id_path(const bContext *C)
 	return NULL;
 }
 
-void ED_buttons_id_unref(SpaceButs *sbuts, const ID *id)
+void ED_buttons_id_remap(SpaceButs *sbuts, const ID *old_id, ID *new_id)
 {
-	if (sbuts->pinid == id) {
-		sbuts->pinid = NULL;
-		sbuts->flag &= ~SB_PIN_CONTEXT;
+	if (sbuts->pinid == old_id) {
+		sbuts->pinid = new_id;
+		if (new_id == NULL) {
+			sbuts->flag &= ~SB_PIN_CONTEXT;
+		}
 	}
 
 	if (sbuts->path) {
@@ -1193,7 +1195,7 @@ void ED_buttons_id_unref(SpaceButs *sbuts, const ID *id)
 		int i;
 
 		for (i = 0; i < path->len; i++) {
-			if (path->ptr[i].id.data == id) {
+			if (path->ptr[i].id.data == old_id) {
 				break;
 			}
 		}
@@ -1201,12 +1203,17 @@ void ED_buttons_id_unref(SpaceButs *sbuts, const ID *id)
 		if (i == path->len) {
 			/* pass */
 		}
-		else if (i == 0) {
-			MEM_SAFE_FREE(sbuts->path);
+		else if (new_id == NULL) {
+			if (i == 0) {
+				MEM_SAFE_FREE(sbuts->path);
+			}
+			else {
+				memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i));
+				path->len = i;
+			}
 		}
 		else {
-			memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i));
-			path->len = i;
+			RNA_id_pointer_create(new_id, &path->ptr[i]);
 		}
 	}
 }
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index ffd51bc..eeacfb5 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -740,30 +740,38 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
 	}
 }
 
-void ED_node_id_unref(SpaceNode *snode, const ID *id)
-{
-	if (GS(id->name) == ID_SCE) {
-		if (snode->id == id) {
-			/* nasty DNA logic for SpaceNode:
-			 * ideally should be handled by editor code, but would be bad level call
-			 */
-			bNodeTreePath *path, *path_next;
-			for (path = snode->treepath.first; path; path = path_next) {
-				path_next = path->next;
-				MEM_freeN(path);
-			}
-			BLI_listbase_clear(&snode->treepath);
+void ED_node_id_remap(SpaceNode *snode, const ID *old_id, ID *new_id)
+{
+	if (GS(old_id->name) == ID_SCE) {
+		if (snode->id == old_id) {
+			if (new_id == NULL) {
+				/* nasty DNA logic for SpaceNode:
+				 * ideally should be handled by editor code, but would be bad level call
+				 */
+				bNodeTreePath *path, *path_next;
+				for (path = snode->treepath.first; path; path = path_next) {
+					path_next = path->next;
+					MEM_freeN(path);
+				}
+				BLI_listbase_clear(&snode->treepath);
 
-			snode->id = NULL;
-			snode->from = NULL;
-			snode->nodetree = NULL;
-			snode->edittree = NULL;
+				snode->id = NULL;
+				snode->from = NULL;
+				snode->nodetree = NULL;
+				snode->edittree = NULL;
+			}
+			else {
+				/* XXX ????????????? */
+				printf("WARNING TODO! remapping scene ID in node editor has to be written!\n");
+			}
 		}
 	}
-	else if (GS(id->name) == ID_OB) {
-		if (snode->from == id) {
-			snode->flag &= ~SNODE_PIN;
-			snode->from = NULL;
+	else if (GS(old_id->name) == ID_OB) {
+		if (snode->from == old_id) {
+			if (new_id == NULL) {
+				snode->flag &= ~SNODE_PIN;
+			}
+			snode->from = new_id;
 		}
 	}
 }
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 0821304..d4fee5f 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -1957,17 +1957,17 @@ void OUTLINER_OT_group_link(wmOperatorType *ot)
 	RNA_def_string(ot->srna, "object", "Object", MAX_ID_NAME, "Object", "Target Object");
 }
 
-/******** Utils to clear any ref to freed ID... **********

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list