diff options
author | Jacques Lucke <jacques@blender.org> | 2021-11-19 17:28:44 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-11-19 17:28:44 +0300 |
commit | 04ec36f677d47e3a70baa944bb26fc03d5e8d52e (patch) | |
tree | df6eb9d4a1c57e18ee7585a79d688f351f7734ea /source/blender/editors/object/object_add.c | |
parent | a20e703d1a5cc0d3e4294825e31609d9b92da06d (diff) |
Fix T87912: use session id instead of name to identify dropped object
The old code did not work when there were multiple ids with
the same name (which can happen when ids are linked in).
The solution is to use the session ids instead. Those are different
even when two ids have the same name.
Differential Revision: https://developer.blender.org/D11116
Diffstat (limited to 'source/blender/editors/object/object_add.c')
-rw-r--r-- | source/blender/editors/object/object_add.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 90caeecd91f..f81e2a65b9f 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -1657,12 +1657,25 @@ static int collection_instance_add_exec(bContext *C, wmOperator *op) PropertyRNA *prop_name = RNA_struct_find_property(op->ptr, "name"); PropertyRNA *prop_location = RNA_struct_find_property(op->ptr, "location"); + PropertyRNA *prop_session_uuid = RNA_struct_find_property(op->ptr, "session_uuid"); + bool update_location_if_necessary = false; if (RNA_property_is_set(op->ptr, prop_name)) { char name[MAX_ID_NAME - 2]; RNA_property_string_get(op->ptr, prop_name, name); collection = (Collection *)BKE_libblock_find_name(bmain, ID_GR, name); + update_location_if_necessary = true; + } + else if (RNA_property_is_set(op->ptr, prop_session_uuid)) { + const uint32_t session_uuid = (uint32_t)RNA_property_int_get(op->ptr, prop_session_uuid); + collection = (Collection *)BKE_libblock_find_session_uuid(bmain, ID_GR, session_uuid); + update_location_if_necessary = true; + } + else { + collection = BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")); + } + if (update_location_if_necessary) { int mval[2]; if (!RNA_property_is_set(op->ptr, prop_location) && object_add_drop_xy_get(C, op, &mval)) { ED_object_location_from_view(C, loc); @@ -1670,9 +1683,6 @@ static int collection_instance_add_exec(bContext *C, wmOperator *op) RNA_property_float_set_array(op->ptr, prop_location, loc); } } - else { - collection = BLI_findlink(&bmain->collections, RNA_enum_get(op->ptr, "collection")); - } if (collection == NULL) { return OPERATOR_CANCELLED; @@ -1707,7 +1717,8 @@ static int object_instance_add_invoke(bContext *C, wmOperator *op, const wmEvent RNA_int_set(op->ptr, "drop_y", event->xy[1]); } - if (!RNA_struct_property_is_set(op->ptr, "name")) { + if (!RNA_struct_property_is_set(op->ptr, "name") && + !RNA_struct_property_is_set(op->ptr, "session_uuid")) { return WM_enum_search_invoke(C, op, event); } return op->type->exec(C, op); @@ -1740,6 +1751,16 @@ void OBJECT_OT_collection_instance_add(wmOperatorType *ot) ot->prop = prop; ED_object_add_generic_props(ot, false); + RNA_def_int(ot->srna, + "session_uuid", + 0, + INT32_MIN, + INT32_MAX, + "Session UUID", + "Session UUID of the collection to add", + INT32_MIN, + INT32_MAX); + object_add_drop_xy_props(ot); } |