[Bf-blender-cvs] [e969ac64137] blender2.8: Fix collections names no longer unique when moved around

Dalai Felinto noreply at git.blender.org
Fri Jan 19 21:44:59 CET 2018


Commit: e969ac64137e53c0a375886d5e175f1e6b05073a
Author: Dalai Felinto
Date:   Fri Jan 19 18:44:11 2018 -0200
Branches: blender2.8
https://developer.blender.org/rBe969ac64137e53c0a375886d5e175f1e6b05073a

Fix collections names no longer unique when moved around

We were not checking for uniqueness after moving. And in some cases the new
siblings of our collection may have conflicting names.

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

M	source/blender/blenkernel/intern/collection.c
M	tests/python/view_layer/CMakeLists.txt
R100	tests/python/view_layer/test_collection_rename.py	tests/python/view_layer/test_collection_rename_a.py
A	tests/python/view_layer/test_collection_rename_b.py

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index d0f89eb46e5..edd29f793ec 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -314,6 +314,15 @@ void BKE_collection_rename(const Scene *scene, SceneCollection *sc, const char *
 	collection_rename(&scene->id, sc, name);
 }
 
+/**
+ * Make sure the collection name is still unique within its siblings.
+ */
+static void collection_name_check(const ID *owner_id, SceneCollection *sc)
+{
+	/* It's a bit of a hack, we simply try to make sure the collection name is valid. */
+	collection_rename(owner_id, sc, sc->name);
+}
+
 /**
  * Free (or release) any data used by the master collection (does not free the master collection itself).
  * Used only to clear the entire scene or group data since it's not doing re-syncing of the LayerCollection tree
@@ -589,6 +598,9 @@ bool BKE_collection_move_above(const ID *owner_id, SceneCollection *sc_dst, Scen
 	BKE_layer_collection_resync(owner_id, sc_src_parent);
 	BKE_layer_collection_resync(owner_id, sc_dst_parent);
 
+	/* Keep names unique. */
+	collection_name_check(owner_id, sc_src);
+
 	return true;
 }
 
@@ -628,6 +640,9 @@ bool BKE_collection_move_below(const ID *owner_id, SceneCollection *sc_dst, Scen
 	BKE_layer_collection_resync(owner_id, sc_src_parent);
 	BKE_layer_collection_resync(owner_id, sc_dst_parent);
 
+	/* Keep names unique. */
+	collection_name_check(owner_id, sc_src);
+
 	return true;
 }
 
@@ -663,6 +678,9 @@ bool BKE_collection_move_into(const ID *owner_id, SceneCollection *sc_dst, Scene
 	BKE_layer_collection_resync(owner_id, sc_src_parent);
 	BKE_layer_collection_resync(owner_id, sc_dst);
 
+	/* Keep names unique. */
+	collection_name_check(owner_id, sc_src);
+
 	return true;
 }
 
diff --git a/tests/python/view_layer/CMakeLists.txt b/tests/python/view_layer/CMakeLists.txt
index 69b02416487..e308e2e0952 100644
--- a/tests/python/view_layer/CMakeLists.txt
+++ b/tests/python/view_layer/CMakeLists.txt
@@ -62,7 +62,8 @@ endmacro()
 
 VIEW_LAYER_TEST(active_collection)
 VIEW_LAYER_TEST(background_set)
-VIEW_LAYER_TEST(collection_rename)
+VIEW_LAYER_TEST(collection_rename_a)
+VIEW_LAYER_TEST(collection_rename_b)
 VIEW_LAYER_TEST(evaluation_render_settings_a)
 VIEW_LAYER_TEST(evaluation_render_settings_b)
 VIEW_LAYER_TEST(evaluation_render_settings_c)
diff --git a/tests/python/view_layer/test_collection_rename.py b/tests/python/view_layer/test_collection_rename_a.py
similarity index 100%
rename from tests/python/view_layer/test_collection_rename.py
rename to tests/python/view_layer/test_collection_rename_a.py
diff --git a/tests/python/view_layer/test_collection_rename_b.py b/tests/python/view_layer/test_collection_rename_b.py
new file mode 100644
index 00000000000..3787066e1b9
--- /dev/null
+++ b/tests/python/view_layer/test_collection_rename_b.py
@@ -0,0 +1,58 @@
+# ############################################################
+# Importing - Same For All Render Layer Tests
+# ############################################################
+
+import unittest
+import os
+import sys
+
+from view_layer_common import *
+
+
+# ############################################################
+# Testing
+# ############################################################
+
+class UnitTesting(ViewLayerTesting):
+    def setup_collections(self):
+        import bpy
+        scene = bpy.context.scene
+
+        master = scene.master_collection
+        one = master.collections[0]
+        two = master.collections.new()
+        sub = two.collections.new(one.name)
+
+        self.assertEqual(one.name, sub.name)
+
+        lookup = {
+            'master': master,
+            'one': one,
+            'two': two,
+            'sub': sub,
+        }
+        return lookup
+
+    def test_move_above(self):
+        collections = self.setup_collections()
+        collections['sub'].move_above(collections['one'])
+        self.assertNotEqual(collections['one'].name, collections['sub'].name)
+
+    def test_move_below(self):
+        collections = self.setup_collections()
+        collections['sub'].move_below(collections['one'])
+        self.assertNotEqual(collections['one'].name, collections['sub'].name)
+
+    def test_move_into(self):
+        collections = self.setup_collections()
+        collections['sub'].move_into(collections['master'])
+        self.assertNotEqual(collections['one'].name, collections['sub'].name)
+
+
+# ############################################################
+# Main - Same For All Render Layer Tests
+# ############################################################
+
+if __name__ == '__main__':
+    UnitTesting._extra_arguments = setup_extra_arguments(__file__)
+    unittest.main()



More information about the Bf-blender-cvs mailing list