[Bf-blender-cvs] [9e307117f83] master: Cleanup: remove hierarchy parameter from `BKE_collection_duplicate`

Bastien Montagne noreply at git.blender.org
Tue Jun 16 17:40:36 CEST 2020


Commit: 9e307117f8399eb84f1c4932a1f577ecdd0c8a2d
Author: Bastien Montagne
Date:   Tue Jun 16 15:36:34 2020 +0200
Branches: master
https://developer.blender.org/rB9e307117f8399eb84f1c4932a1f577ecdd0c8a2d

Cleanup: remove hierarchy parameter from `BKE_collection_duplicate`

It makes no sense to deep-copy a collection and not also copy its
children collections... Parameter was not used anymore anyway.

So now this duplicate function will always at least deep-duplicate all
of its children collections, recursively.

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

M	source/blender/blenkernel/BKE_collection.h
M	source/blender/blenkernel/intern/collection.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/editors/space_outliner/outliner_collections.c

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

diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index f34bcfaf48f..586d4c2d773 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -60,7 +60,6 @@ bool BKE_collection_delete(struct Main *bmain, struct Collection *collection, bo
 struct Collection *BKE_collection_duplicate(struct Main *bmain,
                                             struct Collection *parent,
                                             struct Collection *collection,
-                                            const bool do_hierarchy,
                                             const bool do_objects,
                                             const bool do_obdata);
 
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index e1c58bad9d3..1d084c8ab02 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -326,7 +326,6 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy)
 static Collection *collection_duplicate_recursive(Main *bmain,
                                                   Collection *parent,
                                                   Collection *collection_old,
-                                                  const bool do_hierarchy,
                                                   const bool do_objects,
                                                   const bool do_obdata)
 {
@@ -343,15 +342,13 @@ static Collection *collection_duplicate_recursive(Main *bmain,
     collection_new = collection_old;
     do_full_process = true;
   }
-  else if (!do_hierarchy || collection_old->id.newid == NULL) {
+  else if (collection_old->id.newid == NULL) {
     BKE_id_copy(bmain, &collection_old->id, (ID **)&collection_new);
 
     /* Copying add one user by default, need to get rid of that one. */
     id_us_min(&collection_new->id);
 
-    if (do_hierarchy) {
-      ID_NEW_SET(collection_old, collection_new);
-    }
+    ID_NEW_SET(collection_old, collection_new);
     do_full_process = true;
   }
   else {
@@ -376,7 +373,7 @@ static Collection *collection_duplicate_recursive(Main *bmain,
   /* If we are not doing any kind of deep-copy, we can return immediately.
    * False do_full_process means collection_old had already been duplicated,
    * no need to redo some deep-copy on it. */
-  if (!do_hierarchy || !do_full_process) {
+  if (!do_full_process) {
     return collection_new;
   }
 
@@ -413,7 +410,7 @@ static Collection *collection_duplicate_recursive(Main *bmain,
     }
 
     collection_duplicate_recursive(
-        bmain, collection_new, child_collection_old, do_hierarchy, do_objects, do_obdata);
+        bmain, collection_new, child_collection_old, do_objects, do_obdata);
     collection_child_remove(collection_new, child_collection_old);
   }
 
@@ -421,43 +418,33 @@ static Collection *collection_duplicate_recursive(Main *bmain,
 }
 
 /**
- * Make either a shallow copy, or deeper duplicate of given collection.
- *
- * If \a do_hierarchy and \a do_deep_copy are false, this is a regular (shallow) ID copy.
+ * Make a deep copy (aka duplicate) of the given collection and all of its children, recusrsively.
  *
- * \warning If any 'deep copy' behavior is enabled,
- * this functions will clear all \a bmain id.idnew pointers.
+ * \warning This functions will clear all \a bmain id.idnew pointers.
  *
- * \param do_hierarchy: If true, it will recursively make shallow copies of children collections.
- * \param do_objects: If true, it will also make duplicates of objects.
- * This one does nothing if \a do_hierarchy is not set.
- * \param do_obdata: If true, it will also make deep duplicates of objects,
+ * \param do_objects: If true, it will also make copies of objects.
+ * \param do_obdata: If true, it will also make duplicates of objects,
  * using behavior defined in user settings (#U.dupflag).
- * This one does nothing if \a do_hierarchy and \a do_objects are not set.
+ * This one does nothing if \a do_objects is not set.
  */
 Collection *BKE_collection_duplicate(Main *bmain,
                                      Collection *parent,
                                      Collection *collection,
-                                     const bool do_hierarchy,
                                      const bool do_objects,
                                      const bool do_obdata)
 {
-  if (do_hierarchy) {
-    BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
-    BKE_main_id_clear_newpoins(bmain);
-  }
+  BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
+  BKE_main_id_clear_newpoins(bmain);
 
   Collection *collection_new = collection_duplicate_recursive(
-      bmain, parent, collection, do_hierarchy, do_objects, do_obdata);
+      bmain, parent, collection, do_objects, do_obdata);
 
   /* This code will follow into all ID links using an ID tagged with LIB_TAG_NEW.*/
   BKE_libblock_relink_to_newid(&collection_new->id);
 
-  if (do_hierarchy) {
-    /* Cleanup. */
-    BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
-    BKE_main_id_clear_newpoins(bmain);
-  }
+  /* Cleanup. */
+  BKE_main_id_tag_all(bmain, LIB_TAG_NEW, false);
+  BKE_main_id_clear_newpoins(bmain);
 
   BKE_main_collection_sync(bmain);
 
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 7cf424f53e0..d3f1efb5975 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -863,7 +863,7 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type)
 
       /* Deep-duplicate collections and objects (using preferences' settings for which sub-data to
        * duplicate along the object itself). */
-      BKE_collection_duplicate(bmain, NULL, sce_copy->master_collection, true, true, true);
+      BKE_collection_duplicate(bmain, NULL, sce_copy->master_collection, true, true);
     }
     else {
       /* Remove sequencer if not full copy */
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index 82ff9e06194..6ff3ccc5bb4 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -581,7 +581,7 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op)
                "it won't be linked to any view layer");
   }
 
-  BKE_collection_duplicate(bmain, parent, collection, true, true, !linked);
+  BKE_collection_duplicate(bmain, parent, collection, true, !linked);
 
   DEG_relations_tag_update(bmain);
   WM_main_add_notifier(NC_SCENE | ND_LAYER, CTX_data_scene(C));



More information about the Bf-blender-cvs mailing list