LibOverride: add a generic macro to check whetehr an ID is overridable.
...and use it in code generating library overrides.
This commit is contained in:
parent
8622849beb
commit
5f4caa8c4f
|
@ -516,13 +516,15 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
|
|||
if (id) {
|
||||
Main *bmain = CTX_data_main(C);
|
||||
if (BKE_override_library_is_enabled() && CTX_wm_window(C)->eventstate->shift) {
|
||||
/* Only remap that specific ID usage to overriding local data-block. */
|
||||
ID *override_id = BKE_override_library_create_from_id(bmain, id, false);
|
||||
if (override_id != NULL) {
|
||||
BKE_main_id_clear_newpoins(bmain);
|
||||
if (ID_IS_OVERRIDABLE_LIBRARY(id)) {
|
||||
/* Only remap that specific ID usage to overriding local data-block. */
|
||||
ID *override_id = BKE_override_library_create_from_id(bmain, id, false);
|
||||
if (override_id != NULL) {
|
||||
BKE_main_id_clear_newpoins(bmain);
|
||||
|
||||
/* Assign new pointer, takes care of updates/notifiers */
|
||||
RNA_id_pointer_create(override_id, &idptr);
|
||||
/* Assign new pointer, takes care of updates/notifiers */
|
||||
RNA_id_pointer_create(override_id, &idptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -2426,6 +2426,14 @@ static int make_override_library_exec(bContext *C, wmOperator *op)
|
|||
|
||||
if (!ID_IS_LINKED(obact) && obact->instance_collection != NULL &&
|
||||
ID_IS_LINKED(obact->instance_collection)) {
|
||||
if (!ID_IS_OVERRIDABLE_LIBRARY(obact->instance_collection)) {
|
||||
BKE_reportf(op->reports,
|
||||
RPT_ERROR_INVALID_INPUT,
|
||||
"Collection '%s' (instantiated by the active object) is not overridable",
|
||||
obact->instance_collection->id.name + 2);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
|
||||
|
||||
Object *obcollection = obact;
|
||||
|
@ -2507,6 +2515,13 @@ static int make_override_library_exec(bContext *C, wmOperator *op)
|
|||
BKE_main_id_clear_newpoins(bmain);
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
|
||||
}
|
||||
else if (!ID_IS_OVERRIDABLE_LIBRARY(obact)) {
|
||||
BKE_reportf(op->reports,
|
||||
RPT_ERROR_INVALID_INPUT,
|
||||
"Active object '%s' is not overridable",
|
||||
obact->id.name + 2);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
/* Else, poll func ensures us that ID_IS_LINKED(obact) is true. */
|
||||
else if (obact->type == OB_ARMATURE) {
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
|
||||
|
|
|
@ -713,7 +713,7 @@ static void id_override_library_cb(bContext *C,
|
|||
TreeStoreElem *tselem,
|
||||
void *UNUSED(user_data))
|
||||
{
|
||||
if (ID_IS_LINKED(tselem->id) && (tselem->id->tag & LIB_TAG_EXTERN)) {
|
||||
if (ID_IS_OVERRIDABLE_LIBRARY(tselem->id)) {
|
||||
Main *bmain = CTX_data_main(C);
|
||||
/* For now, remapp all local usages of linked ID to local override one here. */
|
||||
BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, true);
|
||||
|
|
|
@ -432,10 +432,15 @@ typedef enum ID_Type {
|
|||
#define ID_BLEND_PATH_FROM_GLOBAL(_id) \
|
||||
((_id)->lib ? (_id)->lib->filepath : BKE_main_blendfile_path_from_global())
|
||||
|
||||
#define ID_MISSING(_id) (((_id)->tag & LIB_TAG_MISSING) != 0)
|
||||
#define ID_MISSING(_id) ((((ID *)(_id))->tag & LIB_TAG_MISSING) != 0)
|
||||
|
||||
#define ID_IS_LINKED(_id) (((ID *)(_id))->lib != NULL)
|
||||
|
||||
/* Note that this is a fairly high-level check, should be used at user interaction level, not in
|
||||
* BKE_library_override typically (especially due to the check on LIB_TAG_EXTERN). */
|
||||
#define ID_IS_OVERRIDABLE_LIBRARY(_id) \
|
||||
(ID_IS_LINKED(_id) && !ID_MISSING(_id) && (((ID *)(_id))->tag & LIB_TAG_EXTERN) != 0)
|
||||
|
||||
#define ID_IS_OVERRIDE_LIBRARY(_id) \
|
||||
(((ID *)(_id))->override_library != NULL && ((ID *)(_id))->override_library->reference != NULL)
|
||||
|
||||
|
|
|
@ -493,7 +493,7 @@ static ID *rna_ID_copy(ID *id, Main *bmain)
|
|||
|
||||
static ID *rna_ID_override_create(ID *id, Main *bmain, bool remap_local_usages)
|
||||
{
|
||||
if (!BKE_override_library_is_enabled() || id->lib == NULL) {
|
||||
if (!BKE_override_library_is_enabled() || !ID_IS_OVERRIDABLE_LIBRARY(id)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue