diff options
author | Bastien Montagne <bastien@blender.org> | 2021-08-04 16:13:20 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-08-04 17:57:08 +0300 |
commit | a8185d2d74d42389d881890897958c1223eb5cf1 (patch) | |
tree | e9eab20ce57ab466979bed877253e450b03cc2e4 | |
parent | 2af789d1f3b8a36d0578997bea5f907e31a613ed (diff) |
LibOverride: Add RNA API to reset/delete overrides.
Ref. T86656.
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 63 | ||||
-rw-r--r-- | tests/python/bl_blendfile_library_overrides.py | 10 |
2 files changed, 72 insertions, 1 deletions
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. |