diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-03-30 02:00:34 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-03-30 02:03:47 +0300 |
commit | 41a81fece4ff031b512d2303ca8956824d76e6ff (patch) | |
tree | 088c76e02fbf5ff3b554fc97cc58696e4e6df720 /source/blender/blenkernel/intern | |
parent | 534916258d619554106f5e8fd6bb62558e8980bc (diff) |
Collections: API to select all scene collection objects
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 25 |
2 files changed, 46 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 669bbfb00cc..29e3539ab59 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -574,6 +574,33 @@ static void layer_collection_sync(LayerCollection *lc_dst, LayerCollection *lc_s } /** + * Select all the objects in this SceneCollection (and its nested collections) for this ViewLayer. + * Return true if any object was selected. + */ +bool BKE_collection_objects_select(ViewLayer *view_layer, SceneCollection *scene_collection) +{ + LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection(view_layer, scene_collection); + if (layer_collection != NULL) { + BKE_layer_collection_objects_select(layer_collection); + return true; + } + else { + /* Slower approach, we need to iterate over all the objects and for each one we see if there is a base. */ + bool changed = false; + for (LinkData *link = scene_collection->objects.first; link; link = link->next) { + Base *base = BKE_view_layer_base_find(view_layer, link->data); + if (base != NULL) { + if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) { + base->flag |= BASE_SELECTED; + changed = true; + } + } + } + return changed; + } +} + +/** * Leave only the master collection in, remove everything else. * @param group */ diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 78af18fa362..65e76e619f2 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -1282,16 +1282,29 @@ static LayerCollection *layer_collection_add(ViewLayer *view_layer, LayerCollect /* ---------------------------------------------------------------------- */ /** - * See if render layer has the scene collection linked directly, or indirectly (nested) + * Return the first matching LayerCollection in the ViewLayer for the SceneCollection. */ -bool BKE_view_layer_has_collection(ViewLayer *view_layer, const SceneCollection *sc) +LayerCollection *BKE_layer_collection_first_from_scene_collection(ViewLayer *view_layer, const SceneCollection *scene_collection) { - for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) { - if (find_layer_collection_by_scene_collection(lc, sc) != NULL) { - return true; + for (LayerCollection *layer_collection = view_layer->layer_collections.first; + layer_collection != NULL; + layer_collection = layer_collection->next) + { + LayerCollection *found = find_layer_collection_by_scene_collection(layer_collection, scene_collection); + + if (found != NULL) { + return found; } } - return false; + return NULL; +} + +/** + * See if view layer has the scene collection linked directly, or indirectly (nested) + */ +bool BKE_view_layer_has_collection(ViewLayer *view_layer, const SceneCollection *scene_collection) +{ + return BKE_layer_collection_first_from_scene_collection(view_layer, scene_collection) != NULL; } /** |