Commit: 713010bd7795c539c1c18afc3df9f25ab8ba6c12 Author: Dalai Felinto Date: Tue Mar 12 19:55:33 2019 -0300 Branches: master https://developer.blender.org/rB713010bd7795c539c1c18afc3df9f25ab8ba6c12
Fix T62313 - No way to remove object from master collection in 3d view This introduces a new iterator, FOREACH_COLLECTION, that unlike the FOREACH_SCENE_COLLECTION it iterates over all the Blender file collections, including the scene master collection, as well the database ones (bmain). Reviewers: brecht =================================================================== M source/blender/blenkernel/BKE_collection.h M source/blender/blenkernel/BKE_object.h M source/blender/blenkernel/intern/collection.c M source/blender/blenkernel/intern/object.c M source/blender/editors/object/object_collection.c M source/blender/editors/object/object_relations.c =================================================================== diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index a4b68a8cba2..f46405dceab 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -72,7 +72,7 @@ struct Scene *BKE_collection_master_scene_search(const struct Main *bmain, const bool BKE_collection_has_object(struct Collection *collection, struct Object *ob); bool BKE_collection_has_object_recursive(struct Collection *collection, struct Object *ob); -struct Collection *BKE_collection_object_find(struct Main *bmain, struct Collection *collection, struct Object *ob); +struct Collection *BKE_collection_object_find(struct Main *bmain, struct Scene *scene, struct Collection *collection, struct Object *ob); bool BKE_collection_is_empty(struct Collection *collection); bool BKE_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *ob); @@ -179,6 +179,32 @@ void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter); #define FOREACH_SCENE_COLLECTION_END \ ITER_END +#define FOREACH_COLLECTION_BEGIN(_bmain, _scene, Type, _instance) \ +{ \ + Type _instance; \ + Collection *_instance_next; \ + bool is_scene_collection = (_scene) != NULL; \ + \ + if (_scene) { \ + _instance_next = BKE_collection_master(_scene); \ + } \ + else { \ + _instance_next = (_bmain)->collections.first; \ + } \ + \ + while ((_instance = _instance_next)) { \ + if (is_scene_collection) { \ + _instance_next = (_bmain)->collections.first; \ + is_scene_collection = false; \ + } \ + else { \ + _instance_next = _instance->id.next; \ + } + +#define FOREACH_COLLECTION_END \ + } \ +} + #define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \ ITER_BEGIN(BKE_scene_objects_iterator_begin, \ BKE_scene_objects_iterator_next, \ diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index 9cd98232375..9e6366f9992 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -336,8 +336,8 @@ typedef enum eObjectSet { struct LinkNode *BKE_object_relational_superset( struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter); -struct LinkNode *BKE_object_groups(struct Main *bmain, struct Object *ob); -void BKE_object_groups_clear(struct Main *bmain, struct Object *object); +struct LinkNode *BKE_object_groups(struct Main *bmain, struct Scene *scene, struct Object *ob); +void BKE_object_groups_clear(struct Main *bmain, struct Scene *scene, struct Object *object); struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot); diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index b00448cc8c3..29d9d105d6b 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -558,17 +558,32 @@ bool BKE_collection_has_object_recursive(Collection *collection, Object *ob) return (BLI_findptr(&objects, ob, offsetof(Base, object))); } -Collection *BKE_collection_object_find(Main *bmain, Collection *collection, Object *ob) +static Collection *collection_next_find(Main *bmain, Scene *scene, Collection *collection) { - if (collection) - collection = collection->id.next; - else + if (scene && collection == BKE_collection_master(scene)) { + return bmain->collections.first; + } + else { + return collection->id.next; + } +} + +Collection *BKE_collection_object_find(Main *bmain, Scene *scene, Collection *collection, Object *ob) +{ + if (collection) { + collection = collection_next_find(bmain, scene, collection); + } + else if (scene) { + collection = BKE_collection_master(scene); + } + else { collection = bmain->collections.first; + } while (collection) { if (BKE_collection_has_object(collection, ob)) return collection; - collection = collection->id.next; + collection = collection_next_find(bmain, scene, collection); } return NULL; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 02b6f64a7c7..f7a719726b9 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -3944,21 +3944,21 @@ LinkNode *BKE_object_relational_superset(struct ViewLayer *view_layer, eObjectSe /** * return all groups this object is apart of, caller must free. */ -struct LinkNode *BKE_object_groups(Main *bmain, Object *ob) +struct LinkNode *BKE_object_groups(Main *bmain, Scene *scene, Object *ob) { LinkNode *collection_linknode = NULL; Collection *collection = NULL; - while ((collection = BKE_collection_object_find(bmain, collection, ob))) { + while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) { BLI_linklist_prepend(&collection_linknode, collection); } return collection_linknode; } -void BKE_object_groups_clear(Main *bmain, Object *ob) +void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *ob) { Collection *collection = NULL; - while ((collection = BKE_collection_object_find(bmain, collection, ob))) { + while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) { BKE_collection_object_remove(bmain, collection, ob, false); DEG_id_tag_update(&collection->id, ID_RECALC_COPY_ON_WRITE); } diff --git a/source/blender/editors/object/object_collection.c b/source/blender/editors/object/object_collection.c index 4aad3c14a62..c226ad7a47f 100644 --- a/source/blender/editors/object/object_collection.c +++ b/source/blender/editors/object/object_collection.c @@ -59,6 +59,7 @@ static const EnumPropertyItem *collection_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) { Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); Object *ob; EnumPropertyItem *item = NULL, item_tmp = {0}; int totitem = 0; @@ -76,7 +77,7 @@ static const EnumPropertyItem *collection_object_active_itemf(bContext *C, Point /* if 2 or more collections, add option to add to all collections */ collection = NULL; - while ((collection = BKE_collection_object_find(bmain, collection, ob))) + while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) count++; if (count >= 2) { @@ -88,7 +89,7 @@ static const EnumPropertyItem *collection_object_active_itemf(bContext *C, Point /* add collections */ collection = NULL; - while ((collection = BKE_collection_object_find(bmain, collection, ob))) { + while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) { item_tmp.identifier = item_tmp.name = collection->id.name + 2; /* item_tmp.icon = ICON_ARMATURE_DATA; */ item_tmp.value = i; @@ -104,11 +105,11 @@ static const EnumPropertyItem *collection_object_active_itemf(bContext *C, Point } /* get the collection back from the enum index, quite awkward and UI specific */ -static Collection *collection_object_active_find_index(Main *bmain, Object *ob, const int collection_object_index) +static Collection *collection_object_active_find_index(Main *bmain, Scene *scene, Object *ob, const int collection_object_index) { Collection *collection = NULL; int i = 0; - while ((collection = BKE_collection_object_find(bmain, collection, ob))) { + while ((collection = BKE_collection_object_find(bmain, scene, collection, ob))) { if (i == collection_object_index) { break; } @@ -122,9 +123,9 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); int single_collection_index = RNA_enum_get(op->ptr, "collection"); - Collection *single_collection = collection_object_active_find_index(bmain, ob, single_collection_index); - Collection *collection; + Collection *single_collection = collection_object_active_find_index(bmain, scene, ob, single_collection_index); bool is_cycle = false; bool updated = false; @@ -132,7 +133,8 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* now add all selected objects to the collection(s) */ - for (collection = bmain->collections.first; collection; collection = collection->id.next) { + FOREACH_COLLECTION_BEGIN(bmain, scene, Collection *, collection) + { if (single_collection && collection != single_collection) continue; if (!BKE_collection_has_object(collection, ob)) @@ -154,6 +156,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) } CTX_DATA_END; } + FOREACH_COLLECTION_END; if (is_cycle) BKE_report(op->reports, RPT_WARNING, "Skipped some collections because of cycle detected"); @@ -194,20 +197,20 @@ void COLLECTION_OT_objects_add_active(wmOperatorType *ot) static int objects_remove_active_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Scene *scene @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs