From 5596f79821caae3d4c1eb608ce77371904f74b80 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 28 Mar 2022 17:34:36 +0200 Subject: LibOverride: Massive edits to 'editable' IDs checks in editors code. Add new `BKE_id_is_editable` helper in `BKE_lib_id.h`, that supercedes previous check (simple `ID_IS_LINKED()` macro) for many editing cases. This allows to also take into account 'system override' (aka non-editable override) case. Ref: {T95707}. --- source/blender/editors/object/object_add.cc | 16 +++++++++------- source/blender/editors/object/object_data_transfer.c | 6 +++--- source/blender/editors/object/object_edit.c | 6 ++++-- source/blender/editors/object/object_gpencil_modifier.c | 6 ++++-- source/blender/editors/object/object_modifier.c | 5 +++-- source/blender/editors/object/object_relations.c | 14 +++++++------- source/blender/editors/object/object_shader_fx.c | 5 +++-- source/blender/editors/object/object_transform.cc | 8 ++++---- source/blender/editors/object/object_vgroup.c | 2 +- 9 files changed, 38 insertions(+), 30 deletions(-) (limited to 'source/blender/editors/object') diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index b8ffaf87118..f681f49df90 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -1280,7 +1280,7 @@ static bool object_gpencil_add_poll(bContext *C) Scene *scene = CTX_data_scene(C); Object *obact = CTX_data_active_object(C); - if ((scene == nullptr) || (ID_IS_LINKED(scene))) { + if ((scene == nullptr) || ID_IS_LINKED(scene) || ID_IS_OVERRIDE_LIBRARY(scene)) { return false; } @@ -2752,12 +2752,14 @@ static int object_convert_exec(bContext *C, wmOperator *op) * However, changing this is more design than bug-fix, not to mention convoluted code below, * so that will be for later. * But at the very least, do not do that with linked IDs! */ - if ((ID_IS_LINKED(ob) || (ob->data && ID_IS_LINKED(ob->data))) && !keep_original) { + if ((!BKE_id_is_editable(bmain, &ob->id) || + (ob->data && !BKE_id_is_editable(bmain, static_cast(ob->data)))) && + !keep_original) { keep_original = true; - BKE_report( - op->reports, - RPT_INFO, - "Converting some linked object/object data, enforcing 'Keep Original' option to True"); + BKE_report(op->reports, + RPT_INFO, + "Converting some non-editable object/object data, enforcing 'Keep Original' " + "option to True"); } DEG_id_tag_update(&base->object->id, ID_RECALC_GEOMETRY); @@ -3631,7 +3633,7 @@ static int object_transform_to_mouse_exec(bContext *C, wmOperator *op) /* Don't transform a linked object. There's just nothing to do here in this case, so return * #OPERATOR_FINISHED. */ - if (ID_IS_LINKED(ob)) { + if (!BKE_id_is_editable(bmain, &ob->id)) { return OPERATOR_FINISHED; } diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 3abf0d68eb3..6805c9144d6 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -319,11 +319,11 @@ static void data_transfer_exec_preprocess_objects(bContext *C, } me = ob->data; - if (ID_IS_LINKED(me)) { - /* Do not transfer to linked data, not supported. */ + if (ID_IS_LINKED(me) || ID_IS_OVERRIDE_LIBRARY(me)) { + /* Do not transfer to linked/override data, not supported. */ BKE_reportf(op->reports, RPT_WARNING, - "Skipping object '%s', linked data '%s' cannot be modified", + "Skipping object '%s', linked or override data '%s' cannot be modified", ob->id.name + 2, me->id.name + 2); me->id.tag &= ~LIB_TAG_DOIT; diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 7cef3e1725b..cc8644285c0 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -51,6 +51,7 @@ #include "BKE_image.h" #include "BKE_lattice.h" #include "BKE_layer.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" #include "BKE_mball.h" @@ -973,7 +974,7 @@ static int posemode_exec(bContext *C, wmOperator *op) const View3D *v3d = CTX_wm_view3d(C); FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) { if ((ob != obact) && (ob->type == OB_ARMATURE) && (ob->mode == OB_MODE_OBJECT) && - (!ID_IS_LINKED(ob))) { + BKE_id_is_editable(bmain, &ob->id)) { ED_object_posemode_enter_ex(bmain, ob); } } @@ -1528,6 +1529,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) } } + Main *bmain = CTX_data_main(C); LISTBASE_FOREACH (CollectionPointerLink *, ctx_ob, &ctx_objects) { /* Always un-tag all object data-blocks irrespective of our ability to operate on them. */ Object *ob = ctx_ob->ptr.data; @@ -1538,7 +1540,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op) data->tag &= ~LIB_TAG_DOIT; /* Finished un-tagging, continue with regular logic. */ - if (data && ID_IS_LINKED(data)) { + if (data && !BKE_id_is_editable(bmain, data)) { has_linked_data = true; continue; } diff --git a/source/blender/editors/object/object_gpencil_modifier.c b/source/blender/editors/object/object_gpencil_modifier.c index d0a6a5d44c0..573f048e6b6 100644 --- a/source/blender/editors/object/object_gpencil_modifier.c +++ b/source/blender/editors/object/object_gpencil_modifier.c @@ -26,6 +26,7 @@ #include "BKE_context.h" #include "BKE_gpencil.h" #include "BKE_gpencil_modifier.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_object.h" #include "BKE_report.h" @@ -418,17 +419,18 @@ static bool gpencil_edit_modifier_poll_generic(bContext *C, int obtype_flag, const bool is_liboverride_allowed) { + Main *bmain = CTX_data_main(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type); Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : ED_object_active_context(C); GpencilModifierData *mod = ptr.data; /* May be NULL. */ - if (!ob || ID_IS_LINKED(ob)) { + if (!ob || !BKE_id_is_editable(bmain, &ob->id)) { return false; } if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) { return false; } - if (ptr.owner_id && ID_IS_LINKED(ptr.owner_id)) { + if (ptr.owner_id && !BKE_id_is_editable(bmain, ptr.owner_id)) { return false; } diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 7c3571d3b75..9039556ea93 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -1016,6 +1016,7 @@ bool edit_modifier_poll_generic(bContext *C, const bool is_editmode_allowed, const bool is_liboverride_allowed) { + Main *bmain = CTX_data_main(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type); Object *ob = (ptr.owner_id) ? (Object *)ptr.owner_id : ED_object_active_context(C); ModifierData *mod = ptr.data; /* May be NULL. */ @@ -1024,13 +1025,13 @@ bool edit_modifier_poll_generic(bContext *C, mod = BKE_object_active_modifier(ob); } - if (!ob || ID_IS_LINKED(ob)) { + if (!ob || !BKE_id_is_editable(bmain, &ob->id)) { return false; } if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) { return false; } - if (ptr.owner_id && ID_IS_LINKED(ptr.owner_id)) { + if (ptr.owner_id && !BKE_id_is_editable(bmain, ptr.owner_id)) { return false; } diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 70081b4b5f2..064a84cdea5 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -1350,7 +1350,7 @@ static int make_links_scene_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (ID_IS_LINKED(scene_to)) { + if (!BKE_id_is_editable(bmain, &scene_to->id)) { BKE_report(op->reports, RPT_ERROR, "Cannot link objects into a linked scene"); return OPERATOR_CANCELLED; } @@ -1481,7 +1481,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op) case MAKE_LINKS_ANIMDATA: BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, 0); if (ob_dst->data && ob_src->data) { - if (ID_IS_LINKED(obdata_id)) { + if (!BKE_id_is_editable(bmain, obdata_id)) { is_lib = true; break; } @@ -1525,7 +1525,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op) Curve *cu_src = ob_src->data; Curve *cu_dst = ob_dst->data; - if (ID_IS_LINKED(obdata_id)) { + if (!BKE_id_is_editable(bmain, obdata_id)) { is_lib = true; break; } @@ -1792,7 +1792,7 @@ static void single_obdata_users( ID *id; FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) { - if (!ID_IS_LINKED(ob)) { + if (BKE_id_is_editable(bmain, &ob->id)) { id = ob->data; if (single_data_needs_duplication(id)) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -1897,7 +1897,7 @@ static void single_object_action_users( Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag) { FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) { - if (!ID_IS_LINKED(ob)) { + if (BKE_id_is_editable(bmain, &ob->id)) { AnimData *adt = BKE_animdata_from_id(&ob->id); if (adt == NULL) { continue; @@ -1917,7 +1917,7 @@ static void single_objectdata_action_users( Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d, const int flag) { FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) { - if (!ID_IS_LINKED(ob) && ob->data != NULL) { + if (BKE_id_is_editable(bmain, &ob->id) && ob->data != NULL) { ID *id_obdata = (ID *)ob->data; AnimData *adt = BKE_animdata_from_id(id_obdata); if (adt == NULL) { @@ -1941,7 +1941,7 @@ static void single_mat_users( int a; FOREACH_OBJECT_FLAG_BEGIN (scene, view_layer, v3d, flag, ob) { - if (!ID_IS_LINKED(ob)) { + if (BKE_id_is_editable(bmain, &ob->id)) { for (a = 1; a <= ob->totcol; a++) { ma = BKE_object_material_get(ob, (short)a); if (single_data_needs_duplication(&ma->id)) { diff --git a/source/blender/editors/object/object_shader_fx.c b/source/blender/editors/object/object_shader_fx.c index 973f4d4561d..dd7fc192dc1 100644 --- a/source/blender/editors/object/object_shader_fx.c +++ b/source/blender/editors/object/object_shader_fx.c @@ -25,6 +25,7 @@ #include "BLT_translation.h" #include "BKE_context.h" +#include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_object.h" #include "BKE_report.h" @@ -278,8 +279,8 @@ static bool edit_shaderfx_poll_generic(bContext *C, CTX_wm_operator_poll_msg_set(C, "Object type is not supported"); return false; } - if (ptr.owner_id != NULL && ID_IS_LINKED(ptr.owner_id)) { - CTX_wm_operator_poll_msg_set(C, "Cannot edit library data"); + if (ptr.owner_id != NULL && !BKE_id_is_editable(CTX_data_main(C), ptr.owner_id)) { + CTX_wm_operator_poll_msg_set(C, "Cannot edit library or override data"); return false; } if (!is_liboverride_allowed && BKE_shaderfx_is_nonlocal_in_liboverride(ob, fx)) { diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index afd2c048379..da75703a0d9 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -622,10 +622,10 @@ static int apply_objects_internal(bContext *C, changed = false; } - if (ID_IS_LINKED(obdata)) { + if (ID_IS_LINKED(obdata) || ID_IS_OVERRIDE_LIBRARY(obdata)) { BKE_reportf(reports, RPT_ERROR, - R"(Cannot apply to library data: Object "%s", %s "%s", aborting)", + R"(Cannot apply to library or override data: Object "%s", %s "%s", aborting)", ob->id.name + 2, BKE_idtype_idcode_to_name(GS(obdata->name)), obdata->name + 2); @@ -1138,7 +1138,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) /* Special support for instanced collections. */ if ((ob->transflag & OB_DUPLICOLLECTION) && ob->instance_collection && (ob->instance_collection->id.tag & LIB_TAG_DOIT) == 0) { - if (ID_IS_LINKED(ob->instance_collection)) { + if (!BKE_id_is_editable(bmain, &ob->instance_collection->id)) { tot_lib_error++; } else { @@ -1163,7 +1163,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) } } } - else if (ID_IS_LINKED(ob->data)) { + else if (ID_IS_LINKED(ob->data) || ID_IS_OVERRIDE_LIBRARY(ob->data)) { tot_lib_error++; } else if (ob->type == OB_MESH) { diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index f0fa693bd85..a58ffa4e0a6 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -3062,7 +3062,7 @@ static int vertex_group_select_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); - if (!ob || ID_IS_LINKED(ob)) { + if (!ob || ID_IS_LINKED(ob) || ID_IS_OVERRIDE_LIBRARY(ob)) { return OPERATOR_CANCELLED; } -- cgit v1.2.3