Collections: API to select all scene collection objects

This commit is contained in:
Dalai Felinto 2018-03-29 20:00:34 -03:00
parent 534916258d
commit 41a81fece4
4 changed files with 50 additions and 6 deletions

View File

@ -44,6 +44,7 @@ struct Main;
struct Object;
struct Scene;
struct SceneCollection;
struct ViewLayer;
struct SceneCollection *BKE_collection_add(
struct ID *owner_id, struct SceneCollection *sc_parent, const int type, const char *name);
@ -61,6 +62,8 @@ void BKE_collection_object_move(struct ID *owner_id, struct SceneCollection *sc_
bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob);
struct SceneCollection *BKE_collection_from_index(struct Scene *scene, const int index);
bool BKE_collection_objects_select(struct ViewLayer *view_layer, struct SceneCollection *scene_collection);
struct Group *BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc);
void BKE_collection_reinsert_after(const struct Scene *scene, struct SceneCollection *sc_reinsert, struct SceneCollection *sc_after);

View File

@ -112,6 +112,7 @@ void BKE_collection_unlink(struct ViewLayer *view_layer, struct LayerCollection
void BKE_collection_enable(struct ViewLayer *view_layer, struct LayerCollection *lc);
struct LayerCollection *BKE_layer_collection_first_from_scene_collection(struct ViewLayer *view_layer, const struct SceneCollection *scene_collection);
bool BKE_view_layer_has_collection(struct ViewLayer *view_layer, const struct SceneCollection *sc);
bool BKE_scene_has_object(struct Scene *scene, struct Object *ob);

View File

@ -573,6 +573,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

View File

@ -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;
}
/**