LibOverride: Add initial System Override flag.

This merely adds the flag, exposes it in RMA, and uses it in some of the
most common 'is editable' checks (RNA, `BASE_EDITABLE` macro...).

Next step: do_version and defining systemoverrides at creation.

Ref: {T95707}.
This commit is contained in:
Bastien Montagne 2022-02-22 17:20:18 +01:00
parent 1013084038
commit 5adcf6c85e
6 changed files with 54 additions and 6 deletions

View File

@ -64,6 +64,11 @@ void BKE_lib_override_library_free(struct IDOverrideLibrary **override, bool do_
*/
bool BKE_lib_override_library_is_user_edited(struct ID *id);
/**
* Check if given ID is a system override.
*/
bool BKE_lib_override_library_is_system_defined(struct Main *bmain, struct ID *id);
/**
* Create an overridden local copy of linked reference.
*

View File

@ -276,6 +276,18 @@ bool BKE_lib_override_library_is_user_edited(struct ID *id)
return false;
}
bool BKE_lib_override_library_is_system_defined(Main *bmain, ID *id)
{
if (ID_IS_OVERRIDE_LIBRARY(id)) {
ID *override_owner_id;
lib_override_get(bmain, id, &override_owner_id);
return (override_owner_id->override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) !=
0;
}
return false;
}
ID *BKE_lib_override_library_create_from_id(Main *bmain,
ID *reference_id,
const bool do_tagged_remap)

View File

@ -319,6 +319,11 @@ enum {
* because it was created as an single override, outside of any hierarchy consideration).
*/
IDOVERRIDE_LIBRARY_FLAG_NO_HIERARCHY = 1 << 0,
/**
* The override ID is required for the system to work (because of ID dependencies), but is not
* seen as editable by the user.
*/
IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED = 1 << 1,
};
/* watch it: Sequence has identical beginning. */

View File

@ -2017,7 +2017,10 @@ extern const char *RE_engine_id_CYCLES;
((v3d == NULL) || (((1 << (base)->object->type) & (v3d)->object_type_exclude_select) == 0)) && \
(((base)->flag & BASE_SELECTABLE) != 0))
#define BASE_SELECTED(v3d, base) (BASE_VISIBLE(v3d, base) && (((base)->flag & BASE_SELECTED) != 0))
#define BASE_EDITABLE(v3d, base) (BASE_VISIBLE(v3d, base) && !ID_IS_LINKED((base)->object))
#define BASE_EDITABLE(v3d, base) \
(BASE_VISIBLE(v3d, base) && !ID_IS_LINKED((base)->object) && \
(!ID_IS_OVERRIDE_LIBRARY_REAL((base)->object) || \
((base)->object->id.override_library->flag & IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED) == 0))
#define BASE_SELECTED_EDITABLE(v3d, base) \
(BASE_EDITABLE(v3d, base) && (((base)->flag & BASE_SELECTED) != 0))

View File

@ -1833,6 +1833,15 @@ static void rna_def_ID_override_library(BlenderRNA *brna)
RNA_def_property_update(prop, NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", IDOVERRIDE_LIBRARY_FLAG_NO_HIERARCHY);
prop = RNA_def_boolean(srna,
"is_system_override",
false,
"Is System Override",
"Whether this library override exists only for the override hierarchy, "
"or if it is actually editable by the user");
RNA_def_property_update(prop, NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL);
RNA_def_property_boolean_sdna(prop, NULL, "flag", IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED);
prop = RNA_def_collection(srna,
"properties",
"IDOverrideLibraryProperty",

View File

@ -32,8 +32,10 @@
#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_lib_override.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_report.h"
@ -1930,17 +1932,29 @@ static bool rna_property_editable_do(PointerRNA *ptr,
/* Handle linked or liboverride ID cases. */
const bool is_linked_prop_exception = (prop->flag & PROP_LIB_EXCEPTION) != 0;
if (ID_IS_LINKED(id) && !is_linked_prop_exception) {
if (ID_IS_LINKED(id)) {
if (is_linked_prop_exception) {
return true;
}
if (r_info != NULL && (*r_info)[0] == '\0') {
*r_info = N_("Can't edit this property from a linked data-block");
}
return false;
}
if (ID_IS_OVERRIDE_LIBRARY(id) && !RNA_property_overridable_get(ptr, prop_orig)) {
if (r_info != NULL && (*r_info)[0] == '\0') {
*r_info = N_("Can't edit this property from an override data-block");
if (ID_IS_OVERRIDE_LIBRARY(id)) {
const bool is_liboverride_system = BKE_lib_override_library_is_system_defined(G_MAIN, id);
if (!RNA_property_overridable_get(ptr, prop_orig)) {
if (r_info != NULL && (*r_info)[0] == '\0') {
*r_info = N_("Can't edit this property from an override data-block");
}
return false;
}
if (is_liboverride_system && !is_linked_prop_exception) {
if (r_info != NULL && (*r_info)[0] == '\0') {
*r_info = N_("Can't edit this property from a system override data-block");
}
return false;
}
return false;
}
/* At this point, property is owned by a local ID and therefore fully editable. */