[Bf-blender-cvs] [6669c559e32] soc-2021-uv-editor-improvements: LibOverride: Add RNA API to reset/delete overrides.

Bastien Montagne noreply at git.blender.org
Mon Aug 9 03:24:41 CEST 2021


Commit: 6669c559e32f401ff0b0e784fb0ce6a2f0b8cfae
Author: Bastien Montagne
Date:   Wed Aug 4 15:13:20 2021 +0200
Branches: soc-2021-uv-editor-improvements
https://developer.blender.org/rB6669c559e32f401ff0b0e784fb0ce6a2f0b8cfae

LibOverride: Add RNA API to reset/delete overrides.

Ref. T86656.

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

M	source/blender/makesrna/intern/rna_ID.c
M	tests/python/bl_blendfile_library_overrides.py

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

diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 15704fc2523..e4c9b70a1ec 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -747,13 +747,52 @@ static void rna_ID_override_library_operations_update(ID *id,
                                                       ReportList *reports)
 {
   if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
-    BKE_report(reports, RPT_ERROR, "ID isn't an override");
+    BKE_reportf(reports, RPT_ERROR, "ID '%s' isn't an override", id->name);
     return;
   }
 
   BKE_lib_override_library_operations_create(bmain, id);
 }
 
+static void rna_ID_override_library_reset(ID *id,
+                                          IDOverrideLibrary *UNUSED(override_library),
+                                          Main *bmain,
+                                          ReportList *reports,
+                                          bool do_hierarchy)
+{
+  if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
+    BKE_reportf(reports, RPT_ERROR, "ID '%s' isn't an override", id->name);
+    return;
+  }
+
+  if (do_hierarchy) {
+    BKE_lib_override_library_id_hierarchy_reset(bmain, id);
+  }
+  else {
+    BKE_lib_override_library_id_reset(bmain, id);
+  }
+}
+
+static void rna_ID_override_library_destroy(ID *id,
+                                            IDOverrideLibrary *UNUSED(override_library),
+                                            Main *bmain,
+                                            ReportList *reports,
+                                            bool do_hierarchy)
+{
+  if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
+    BKE_reportf(reports, RPT_ERROR, "ID '%s' isn't an override", id->name);
+    return;
+  }
+
+  if (do_hierarchy) {
+    BKE_lib_override_library_delete(bmain, id);
+  }
+  else {
+    BKE_libblock_remap(bmain, id, id->override_library->reference, ID_REMAP_SKIP_INDIRECT_USAGE);
+    BKE_id_delete(bmain, id);
+  }
+}
+
 static IDOverrideLibraryProperty *rna_ID_override_library_properties_add(
     IDOverrideLibrary *override_library, ReportList *reports, const char rna_path[])
 {
@@ -1731,6 +1770,28 @@ static void rna_def_ID_override_library(BlenderRNA *brna)
                                   "Update the library override operations based on the "
                                   "differences between this override ID and its reference");
 
+  func = RNA_def_function(srna, "reset", "rna_ID_override_library_reset");
+  RNA_def_function_ui_description(func,
+                                  "Reset this override to match again its linked reference ID");
+  RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_SELF_ID | FUNC_USE_REPORTS);
+  RNA_def_boolean(
+      func,
+      "do_hierarchy",
+      true,
+      "",
+      "Also reset all the dependencies of this override to match their reference linked IDs");
+
+  func = RNA_def_function(srna, "destroy", "rna_ID_override_library_destroy");
+  RNA_def_function_ui_description(
+      func, "Delete this override ID and remap its usages to its linked reference ID instead");
+  RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_SELF_ID | FUNC_USE_REPORTS);
+  RNA_def_boolean(func,
+                  "do_hierarchy",
+                  true,
+                  "",
+                  "Also delete all the dependencies of this override and remap their usages to "
+                  "their reference linked IDs");
+
   rna_def_ID_override_library_property(brna);
 }
 
diff --git a/tests/python/bl_blendfile_library_overrides.py b/tests/python/bl_blendfile_library_overrides.py
index 19f06dc698e..358f77d49ea 100644
--- a/tests/python/bl_blendfile_library_overrides.py
+++ b/tests/python/bl_blendfile_library_overrides.py
@@ -71,6 +71,16 @@ class TestLibraryOverrides(TestHelper, unittest.TestCase):
         # Setting location.y overridded all elements in the location array. -1 is a wildcard.
         assert(override_operation.subitem_local_index == -1)
 
+        local_id.override_library.reset()
+
+        assert(len(local_id.override_library.properties) == 0)
+        assert(local_id.location == local_id.override_library.reference.location)
+
+        local_id_name = local_id.name
+        assert(bpy.data.objects.get((local_id_name, None), None) == local_id)
+        local_id.override_library.destroy()
+        assert(bpy.data.objects.get((local_id_name, None), None) == None)
+
     def test_link_permissive(self):
         """
         Linked assets with a permissive template.



More information about the Bf-blender-cvs mailing list