Fix T76710: objects get lost in linked/overridden collections

Right now:
- drag-drop in the Outliner prevents dropping inside linked collections
- drag-drop in the Outliner allows dropping inside overridden
collections (should not be the case)
- `Object Properties` > `Collections` panel allows to add to overridden
collection (should not be the case)
- `Object Properties` > `Collections` panel filters out non-local
collections (so adding to linked collections is forbidden)
- `bpy collection.objects.link()` allows to add to linked collections
(should not be the case)
- `bpy collection.objects.link()` allows to add to overridden
collections (should not be the case)

While this might be supported in the future for overriden collections,
these cases should not be allowed atm. since objects get lost on file
reload.

Note: for the case of the `Object Properties` > `Collections` panel,
this could be improved further to filter out overridden collections as
well.

Reviewers: mont29, brecht

Subscribers:
This commit is contained in:
Philipp Oeser 2020-05-13 17:30:39 +02:00
parent 0ae64a9945
commit 0a32f6c868
Notes: blender-bot 2023-02-14 06:05:22 +01:00
Referenced by commit a269761ec1, Cleanup: clang format
Referenced by issue #76997, Could not link object because the collection 'Master Collection'(of appended scene) is linked
Referenced by issue #76710, Objects can be moved or linked into linked collections (causing them to disappear after file reload)
3 changed files with 37 additions and 0 deletions

View File

@ -481,6 +481,22 @@ static int collection_link_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
/* Currently this should not be allowed (might be supported in the future though...). */
if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) {
BKE_report(op->reports,
RPT_ERROR,
"Could not add the collection because it is overridden.");
return OPERATOR_CANCELLED;
}
/* Linked collections are already checked for by using RNA_collection_local_itemf
* but operator can be called without invoke */
if (ID_IS_LINKED(&collection->id)) {
BKE_report(op->reports,
RPT_ERROR,
"Could not add the collection because it is linked.");
return OPERATOR_CANCELLED;
}
/* Adding object to collection which is used as dupli-collection for self is bad idea.
*
* It is also bad idea to add object to collection which is in collection which

View File

@ -675,6 +675,10 @@ static bool collection_drop_init(bContext *C,
if (ID_IS_LINKED(to_collection)) {
return false;
}
/* Currently this should not be allowed (might be supported in the future though...). */
if (ID_IS_OVERRIDE_LIBRARY(to_collection)) {
return false;
}
/* Get drag datablocks. */
if (drag->type != WM_DRAG_ID) {

View File

@ -82,6 +82,23 @@ static void rna_Collection_objects_link(Collection *collection,
ReportList *reports,
Object *object)
{
/* Currently this should not be allowed (might be supported in the future though...). */
if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) {
BKE_reportf(reports,
RPT_ERROR,
"Could not link the object '%s' because the collection '%s' is overridden.",
object->id.name + 2,
collection->id.name + 2);
return;
}
if (ID_IS_LINKED(&collection->id)) {
BKE_reportf(reports,
RPT_ERROR,
"Could not link the object '%s' because the collection '%s' is linked.",
object->id.name + 2,
collection->id.name + 2);
return;
}
if (!BKE_collection_object_add(bmain, collection, object)) {
BKE_reportf(reports,
RPT_ERROR,