IDManagement: Add new `BKE_id_owner_get` accessor.
Essentially calls `IDTypeInfo->owner_get` for now, will make more sense once the callback is changed to return the address of the pointer instead.
This commit is contained in:
parent
4ac69c26db
commit
462014b59b
Notes:
blender-bot
2023-02-14 09:33:11 +01:00
Referenced by commit 59f6c60fb6
, Cleanup: Remove unused variable in RNA path function
|
@ -620,6 +620,13 @@ bool BKE_id_is_in_global_main(struct ID *id);
|
|||
|
||||
bool BKE_id_can_be_asset(const struct ID *id);
|
||||
|
||||
/**
|
||||
* Return the owner ID of the given `id`, if any.
|
||||
*
|
||||
* \note: This will only return non-NULL for embedded IDs (master collections etc.), and shapekeys.
|
||||
*/
|
||||
struct ID *BKE_id_owner_get(struct ID *id);
|
||||
|
||||
/** Check if that ID can be considered as editable from a high-level (editor) perspective.
|
||||
*
|
||||
* NOTE: This used to be done with a check on whether ID was linked or not, but now with system
|
||||
|
|
|
@ -1965,6 +1965,15 @@ bool BKE_id_can_be_asset(const ID *id)
|
|||
BKE_idtype_idcode_is_linkable(GS(id->name));
|
||||
}
|
||||
|
||||
ID *BKE_id_owner_get(ID *id)
|
||||
{
|
||||
const IDTypeInfo *idtype = BKE_idtype_get_info_from_id(id);
|
||||
if (idtype->owner_get != NULL) {
|
||||
return idtype->owner_get(id);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool BKE_id_is_editable(const Main *bmain, const ID *id)
|
||||
{
|
||||
return !(ID_IS_LINKED(id) || BKE_lib_override_library_is_system_defined(bmain, id));
|
||||
|
|
|
@ -97,22 +97,18 @@ BLI_INLINE const IDOverrideLibrary *BKE_lib_override_library_get(const Main * /*
|
|||
const ID * /*owner_id_hint*/,
|
||||
const ID **r_owner_id)
|
||||
{
|
||||
if (id->flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE) {
|
||||
const ID *owner_id = BKE_id_owner_get(const_cast<ID *>(id));
|
||||
BLI_assert_msg(owner_id != nullptr, "Liboverride-embedded ID with no owner");
|
||||
if (r_owner_id != nullptr) {
|
||||
*r_owner_id = owner_id;
|
||||
}
|
||||
return owner_id->override_library;
|
||||
}
|
||||
|
||||
if (r_owner_id != nullptr) {
|
||||
*r_owner_id = id;
|
||||
}
|
||||
if (id->flag & LIB_EMBEDDED_DATA_LIB_OVERRIDE) {
|
||||
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
|
||||
if (id_type->owner_get != nullptr) {
|
||||
/* The #IDTypeInfo::owner_get callback should not modify the arguments, so casting away const
|
||||
* is okay. */
|
||||
const ID *owner_id = id_type->owner_get(const_cast<ID *>(id));
|
||||
if (r_owner_id != nullptr) {
|
||||
*r_owner_id = owner_id;
|
||||
}
|
||||
return owner_id->override_library;
|
||||
}
|
||||
BLI_assert_msg(0, "IDTypeInfo of liboverride-embedded ID with no owner getter");
|
||||
}
|
||||
return id->override_library;
|
||||
}
|
||||
|
||||
|
@ -2211,9 +2207,9 @@ static bool lib_override_resync_id_lib_level_is_valid(ID *id,
|
|||
static ID *lib_override_library_main_resync_root_get(Main * /*bmain*/, ID *id)
|
||||
{
|
||||
if (!ID_IS_OVERRIDE_LIBRARY_REAL(id)) {
|
||||
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
|
||||
if (id_type->owner_get != nullptr) {
|
||||
id = id_type->owner_get(id);
|
||||
ID *id_owner = BKE_id_owner_get(id);
|
||||
if (id_owner != nullptr) {
|
||||
id = id_owner;
|
||||
}
|
||||
BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id));
|
||||
}
|
||||
|
|
|
@ -711,9 +711,8 @@ static void lib_query_unused_ids_tag_recurse(Main *bmain,
|
|||
ID *id_from = id_from_item->id_pointer.from;
|
||||
if ((id_from->flag & LIB_EMBEDDED_DATA) != 0) {
|
||||
/* Directly 'by-pass' to actual real ID owner. */
|
||||
const IDTypeInfo *type_info_from = BKE_idtype_get_info_from_id(id_from);
|
||||
BLI_assert(type_info_from->owner_get != NULL);
|
||||
id_from = type_info_from->owner_get(id_from);
|
||||
id_from = BKE_id_owner_get(id_from);
|
||||
BLI_assert(id_from != NULL);
|
||||
}
|
||||
|
||||
lib_query_unused_ids_tag_recurse(
|
||||
|
|
|
@ -377,10 +377,8 @@ void outliner_collection_delete(
|
|||
if (parent->flag & COLLECTION_IS_MASTER) {
|
||||
BLI_assert(parent->id.flag & LIB_EMBEDDED_DATA);
|
||||
|
||||
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(&parent->id);
|
||||
BLI_assert(id_type->owner_get != nullptr);
|
||||
|
||||
ID *scene_owner = id_type->owner_get(&parent->id);
|
||||
ID *scene_owner = BKE_id_owner_get(&parent->id);
|
||||
BLI_assert(scene_owner != nullptr);
|
||||
BLI_assert(GS(scene_owner->name) == ID_SCE);
|
||||
if (ID_IS_LINKED(scene_owner) || ID_IS_OVERRIDE_LIBRARY(scene_owner)) {
|
||||
skip = true;
|
||||
|
@ -610,10 +608,7 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op)
|
|||
else if (parent != nullptr && (parent->flag & COLLECTION_IS_MASTER) != 0) {
|
||||
BLI_assert(parent->id.flag & LIB_EMBEDDED_DATA);
|
||||
|
||||
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(&parent->id);
|
||||
BLI_assert(id_type->owner_get != nullptr);
|
||||
|
||||
Scene *scene_owner = (Scene *)id_type->owner_get(&parent->id);
|
||||
Scene *scene_owner = reinterpret_cast<Scene *>(BKE_id_owner_get(&parent->id));
|
||||
BLI_assert(scene_owner != nullptr);
|
||||
BLI_assert(GS(scene_owner->id.name) == ID_SCE);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "BKE_idprop.h"
|
||||
#include "BKE_idtype.h"
|
||||
#include "BKE_lib_id.h"
|
||||
|
||||
#include "DNA_ID.h" /* For ID properties. */
|
||||
|
||||
|
@ -940,11 +941,9 @@ ID *RNA_find_real_ID_and_path(ID *id, const char **r_path)
|
|||
}
|
||||
}
|
||||
|
||||
if (id_type->owner_get == nullptr) {
|
||||
BLI_assert_msg(0, "Missing handling of embedded id type.");
|
||||
return id;
|
||||
}
|
||||
return id_type->owner_get(id);
|
||||
ID *owner_id = BKE_id_owner_get(id);
|
||||
BLI_assert_msg(owner_id != nullptr, "Missing handling of embedded id type.");
|
||||
return (owner_id != nullptr) ? owner_id : id;
|
||||
}
|
||||
|
||||
static char *rna_prepend_real_ID_path(Main * /*bmain*/, ID *id, char *path, ID **r_real_id)
|
||||
|
|
|
@ -1482,8 +1482,7 @@ static void rna_ImageFormatSettings_color_management_set(PointerRNA *ptr, int va
|
|||
ID *owner_id = ptr->owner_id;
|
||||
if (owner_id && GS(owner_id->name) == ID_NT) {
|
||||
/* For compositing nodes, find the corresponding scene. */
|
||||
const IDTypeInfo *type_info = BKE_idtype_get_info_from_id(owner_id);
|
||||
owner_id = type_info->owner_get(owner_id);
|
||||
owner_id = BKE_id_owner_get(owner_id);
|
||||
}
|
||||
if (owner_id && GS(owner_id->name) == ID_SCE) {
|
||||
BKE_image_format_color_management_copy_from_scene(imf, (Scene *)owner_id);
|
||||
|
|
Loading…
Reference in New Issue