Cleanup: LibOverride: Replace raw pointers checks by proper macros.

This is cleaner, but also crucial to avoid weird issues when behaviors
of those checks are modified...
This commit is contained in:
Bastien Montagne 2020-06-30 10:52:02 +02:00
parent 4783520bfa
commit 0b3313e532
7 changed files with 23 additions and 22 deletions

View File

@ -1229,7 +1229,7 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int ori
/* We may need our own flag to control that at some point, but for now 'no main' one should be
* good enough. */
if ((orig_flag & LIB_ID_CREATE_NO_MAIN) == 0 && id->override_library != NULL) {
if ((orig_flag & LIB_ID_CREATE_NO_MAIN) == 0 && ID_IS_OVERRIDE_LIBRARY(id)) {
/* We do not want to copy existing override rules here, as they would break the proper
* remapping between IDs. Proper overrides rules will be re-generated anyway. */
BKE_lib_override_library_copy(new_id, id, false);

View File

@ -114,7 +114,7 @@ IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id)
/** Shalow or deep copy of a whole override from \a src_id to \a dst_id. */
void BKE_lib_override_library_copy(ID *dst_id, const ID *src_id, const bool do_full_copy)
{
BLI_assert(src_id->override_library != NULL);
BLI_assert(ID_IS_OVERRIDE_LIBRARY(src_id));
if (dst_id->override_library != NULL) {
if (src_id->override_library == NULL) {
@ -620,7 +620,7 @@ bool BKE_lib_override_library_property_operation_operands_validate(
* \return true if status is OK, false otherwise. */
bool BKE_lib_override_library_status_check_local(Main *bmain, ID *local)
{
BLI_assert(local->override_library != NULL);
BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
ID *reference = local->override_library->reference;
@ -676,7 +676,7 @@ bool BKE_lib_override_library_status_check_local(Main *bmain, ID *local)
* \return true if status is OK, false otherwise. */
bool BKE_lib_override_library_status_check_reference(Main *bmain, ID *local)
{
BLI_assert(local->override_library != NULL);
BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
ID *reference = local->override_library->reference;
@ -895,7 +895,7 @@ void BKE_lib_override_library_main_tag(struct Main *bmain, const short tag, cons
/** Remove all tagged-as-unused properties and operations from that ID override data. */
void BKE_lib_override_library_id_unused_cleanup(struct ID *local)
{
if (local->override_library != NULL) {
if (ID_IS_OVERRIDE_LIBRARY(local)) {
LISTBASE_FOREACH_MUTABLE (
IDOverrideLibraryProperty *, op, &local->override_library->properties) {
if (op->tag & IDOVERRIDE_LIBRARY_TAG_UNUSED) {
@ -928,7 +928,7 @@ void BKE_lib_override_library_main_unused_cleanup(struct Main *bmain)
/** Update given override from its reference (re-applying overridden properties). */
void BKE_lib_override_library_update(Main *bmain, ID *local)
{
if (local->override_library == NULL || local->override_library->reference == NULL) {
if (!ID_IS_OVERRIDE_LIBRARY(local)) {
return;
}
@ -1054,15 +1054,14 @@ ID *BKE_lib_override_library_operations_store_start(Main *bmain,
OverrideLibraryStorage *override_storage,
ID *local)
{
BLI_assert(local->override_library != NULL);
BLI_assert(override_storage != NULL);
const bool is_template = (local->override_library->reference == NULL);
if (is_template) {
if (ID_IS_OVERRIDE_LIBRARY_TEMPLATE(local)) {
/* This is actually purely local data with an override template, nothing to do here! */
return NULL;
}
BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
BLI_assert(override_storage != NULL);
/* Forcefully ensure we know about all needed override operations. */
BKE_lib_override_library_operations_create(bmain, local);
@ -1106,7 +1105,7 @@ ID *BKE_lib_override_library_operations_store_start(Main *bmain,
void BKE_lib_override_library_operations_store_end(
OverrideLibraryStorage *UNUSED(override_storage), ID *local)
{
BLI_assert(local->override_library != NULL);
BLI_assert(ID_IS_OVERRIDE_LIBRARY(local));
/* Nothing else to do here really, we need to keep all temp override storage data-blocks in
* memory until whole file is written anyway (otherwise we'd get mem pointers overlap...). */

View File

@ -4070,7 +4070,8 @@ static bool write_file_handle(Main *mainvar,
BLI_assert(
(id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override_library;
const bool do_override = !ELEM(override_storage, NULL, bmain) &&
ID_IS_OVERRIDE_LIBRARY(id);
if (do_override) {
BKE_lib_override_library_operations_store_start(bmain, override_storage, id);

View File

@ -613,7 +613,7 @@ static bool override_remove_button_poll(bContext *C)
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
const int override_status = RNA_property_override_library_status(&ptr, prop, index);
const uint override_status = RNA_property_override_library_status(&ptr, prop, index);
return (ptr.data && ptr.owner_id && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN));
}
@ -634,7 +634,7 @@ static int override_remove_button_exec(bContext *C, wmOperator *op)
BLI_assert(oprop != NULL);
BLI_assert(id != NULL && id->override_library != NULL);
const bool is_template = (id->override_library->reference == NULL);
const bool is_template = ID_IS_OVERRIDE_LIBRARY_TEMPLATE(id);
/* We need source (i.e. linked data) to restore values of deleted overrides...
* If this is an override template, we obviously do not need to restore anything. */

View File

@ -584,7 +584,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
}
break;
case UI_ID_OVERRIDE:
if (id && id->override_library) {
if (id && ID_IS_OVERRIDE_LIBRARY(id)) {
BKE_lib_override_library_free(&id->override_library, true);
/* reassign to get get proper updates/notifiers */
idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);

View File

@ -2064,9 +2064,10 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop_orig)
PropertyRNA *prop = rna_ensure_property(prop_orig);
flag = prop->editable ? prop->editable(ptr, &dummy_info) : prop->flag;
return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 &&
(!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) &&
(!id->override_library || RNA_property_overridable_get(ptr, prop_orig)))));
return (
(flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0 &&
(!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) &&
(!ID_IS_OVERRIDE_LIBRARY(id) || RNA_property_overridable_get(ptr, prop_orig)))));
}
/**
@ -2100,7 +2101,7 @@ bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char *
}
return false;
}
if (id->override_library != NULL) {
if (ID_IS_OVERRIDE_LIBRARY(id)) {
/* We need the real data property in case of IDProperty here... */
PropertyRNA *real_prop = rna_ensure_property_realdata(&prop, ptr);
if (real_prop == NULL || !RNA_property_overridable_get(ptr, real_prop)) {

View File

@ -108,7 +108,7 @@ bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop)
char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
ID *id = ptr->owner_id;
if (rna_path == NULL || id == NULL || id->override_library == NULL) {
if (rna_path == NULL || id == NULL || !ID_IS_OVERRIDE_LIBRARY(id)) {
return false;
}
@ -1156,7 +1156,7 @@ eRNAOverrideStatus RNA_property_override_library_status(PointerRNA *ptr,
return override_status;
}
if (!ptr || !prop || !ptr->owner_id || !(ptr->owner_id)->override_library) {
if (!ptr || !prop || !ptr->owner_id || !ID_IS_OVERRIDE_LIBRARY(ptr->owner_id)) {
return override_status;
}