LibOverride: Add RNA API to reset/delete overrides.
Ref. T86656.
This commit is contained in:
parent
2af789d1f3
commit
a8185d2d74
Notes:
blender-bot
2023-02-14 04:07:50 +01:00
Referenced by issue #86656, Library Overrides API
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue