[Bf-blender-cvs] [140b26909ea] master: LibOverride: Move code tagging reauired dependencies of an override into BKE.

Bastien Montagne noreply at git.blender.org
Tue Jul 14 14:51:25 CEST 2020


Commit: 140b26909ea9cf910aa39efd0c2f81a2a410bc84
Author: Bastien Montagne
Date:   Tue Jul 14 11:38:25 2020 +0200
Branches: master
https://developer.blender.org/rB140b26909ea9cf910aa39efd0c2f81a2a410bc84

LibOverride: Move code tagging reauired dependencies of an override into BKE.

This is fairly generic code that can be re-used in other places.

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

M	source/blender/blenkernel/BKE_lib_override.h
M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/editors/object/object_relations.c

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

diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h
index 22ede6dfa2d..07baebf54a9 100644
--- a/source/blender/blenkernel/BKE_lib_override.h
+++ b/source/blender/blenkernel/BKE_lib_override.h
@@ -63,6 +63,10 @@ struct ID *BKE_lib_override_library_create_from_id(struct Main *bmain,
                                                    struct ID *reference_id,
                                                    const bool do_tagged_remap);
 bool BKE_lib_override_library_create_from_tag(struct Main *bmain);
+void BKE_lib_override_dependencies_tag(struct Main *bmain,
+                                       struct ID *id_root,
+                                       const uint tag,
+                                       const bool do_create_main_relashionships);
 
 struct IDOverrideLibraryProperty *BKE_lib_override_library_property_find(
     struct IDOverrideLibrary *override, const char *rna_path);
diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 009303b8c83..d2730f1fa19 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -38,6 +38,7 @@
 #include "BKE_key.h"
 #include "BKE_lib_id.h"
 #include "BKE_lib_override.h"
+#include "BKE_lib_query.h"
 #include "BKE_lib_remap.h"
 #include "BKE_main.h"
 
@@ -354,6 +355,56 @@ bool BKE_lib_override_library_create_from_tag(Main *bmain)
   return success;
 }
 
+static bool lib_override_hierarchy_recursive_tag(Main *bmain, ID *id)
+{
+  MainIDRelationsEntry *entry = BLI_ghash_lookup(bmain->relations->id_user_to_used, id);
+
+  /* This way we won't process again that ID should we encounter it again through another
+   * relationship hierarchy.
+   * Note that this does not free any memory from relations, so we can still use the entries.
+   */
+  BKE_main_relations_ID_remove(bmain, id);
+
+  for (; entry != NULL; entry = entry->next) {
+    /* We only consider IDs from the same library. */
+    if (entry->id_pointer != NULL && (*entry->id_pointer)->lib == id->lib) {
+      if (lib_override_hierarchy_recursive_tag(bmain, *entry->id_pointer)) {
+        id->tag |= LIB_TAG_DOIT;
+      }
+    }
+  }
+
+  return (id->tag & LIB_TAG_DOIT) != 0;
+}
+
+/**
+ * Tag all IDs in given \a bmain that use (depends on) given \a id_root ID.
+ *
+ * This will include all local IDs, and all IDs from the same library as the \a id_root.
+ *
+ * \param id_root The root of the hierarchy of dependencies to be tagged.
+ * \param do_create_main_relashionships Whether main relations needs to be created or already exist
+ *                                      (in any case, they will be freed by this function).
+ */
+void BKE_lib_override_dependencies_tag(struct Main *bmain,
+                                       struct ID *id_root,
+                                       const uint tag,
+                                       const bool do_create_main_relashionships)
+{
+  id_root->tag |= tag;
+
+  if (do_create_main_relashionships) {
+    BKE_main_relations_create(bmain, 0);
+  }
+
+  /* Then we tag all intermediary data-blocks in-between two overridden ones (e.g. if a shapekey
+   * has a driver using an armature object's bone, we need to override the shapekey/obdata, the
+   * objects using them, etc.) */
+  lib_override_hierarchy_recursive_tag(bmain, id_root);
+
+  BKE_main_relations_free(bmain);
+}
+
 /* We only build override GHash on request. */
 BLI_INLINE IDOverrideLibraryRuntime *override_library_rna_path_mapping_ensure(
     IDOverrideLibrary *override)
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index b81fea1848c..6186eefb214 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -2242,28 +2242,6 @@ void OBJECT_OT_make_local(wmOperatorType *ot)
 /** \name Make Library Override Operator
  * \{ */
 
-static bool make_override_hierarchy_recursive_tag(Main *bmain, ID *id)
-{
-  MainIDRelationsEntry *entry = BLI_ghash_lookup(bmain->relations->id_user_to_used, id);
-
-  /* This way we won't process again that ID should we encounter it again through another
-   * relationship hierarchy.
-   * Note that this does not free any memory from relations, so we can still use the entries.
-   */
-  BKE_main_relations_ID_remove(bmain, id);
-
-  for (; entry != NULL; entry = entry->next) {
-    /* We only consider IDs from the same library. */
-    if (entry->id_pointer != NULL && (*entry->id_pointer)->lib == id->lib) {
-      if (make_override_hierarchy_recursive_tag(bmain, *entry->id_pointer)) {
-        id->tag |= LIB_TAG_DOIT;
-      }
-    }
-  }
-
-  return (id->tag & LIB_TAG_DOIT) != 0;
-}
-
 static int make_override_tag_ids_cb(LibraryIDLinkCallbackData *cb_data)
 {
   if (cb_data->cb_flag & (IDWALK_CB_EMBEDDED | IDWALK_CB_LOOPBACK)) {
@@ -2399,12 +2377,8 @@ static int make_override_library_exec(bContext *C, wmOperator *op)
     }
   }
 
-  /* Then we tag all intermediary data-blocks in-between two overridden ones (e.g. if a shapekey
-   * has a driver using an armature object's bone, we need to override the shapekey/obdata, the
-   * objects using them, etc.) */
-  make_override_hierarchy_recursive_tag(bmain, id_root);
-
-  BKE_main_relations_free(bmain);
+  /* Note that this call will also free the main relations data we created above. */
+  BKE_lib_override_dependencies_tag(bmain, id_root, LIB_TAG_DOIT, false);
 
   ID *id;
   FOREACH_MAIN_ID_BEGIN (bmain, id) {



More information about the Bf-blender-cvs mailing list