diff options
author | Szymon Ulatowski <szulat> | 2020-04-09 20:33:57 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-04-09 22:46:22 +0300 |
commit | f3433fcd3bf87c9405fb05c96fde036eb658e8aa (patch) | |
tree | 48dc84c573a7ca00c1c408312ce5e87b060aacb3 /source/blender/blenkernel/intern/layer.c | |
parent | 07bb7206c202fdea3645b01887e9eeba3d2e6ae3 (diff) |
Collections: preserve exclude flag of child collections when unexcluding
Excluding a collection also changes the exclude setting on all child collections
so that it is possible to selectively enable some children without the parent
being enabled.
This change makes it so that if you unexclude the parent, the exclude setting
of children are restored again instead of being permanently lost.
Original patch by Szymon with modifications by Brecht.
Differential Revision: https://developer.blender.org/D7016
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index d8f0bda8c22..f6e80d66ad1 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -1359,6 +1359,49 @@ void BKE_layer_collection_set_visible(ViewLayer *view_layer, } } +/** + * Set layer collection hide/exclude/indirect flag on a layer collection. + * recursively. + */ +static void layer_collection_flag_recursive_set(LayerCollection *lc, + const int flag, + const bool value, + const bool restore_flag) +{ + if (flag == LAYER_COLLECTION_EXCLUDE) { + /* For exclude flag, we remember the state the children had before + * excluding and restoring it when enabling the parent collection again. */ + if (value) { + if (restore_flag) { + SET_FLAG_FROM_TEST( + lc->flag, (lc->flag & LAYER_COLLECTION_EXCLUDE), LAYER_COLLECTION_PREVIOUSLY_EXCLUDED); + } + else { + lc->flag &= ~LAYER_COLLECTION_PREVIOUSLY_EXCLUDED; + } + + lc->flag |= flag; + } + else { + if (!(lc->flag & LAYER_COLLECTION_PREVIOUSLY_EXCLUDED)) { + lc->flag &= ~flag; + } + } + } + else { + SET_FLAG_FROM_TEST(lc->flag, value, flag); + } + + LISTBASE_FOREACH (LayerCollection *, nlc, &lc->layer_collections) { + layer_collection_flag_recursive_set(nlc, flag, value, true); + } +} + +void BKE_layer_collection_set_flag(LayerCollection *lc, const int flag, const bool value) +{ + layer_collection_flag_recursive_set(lc, flag, value, false); +} + /* ---------------------------------------------------------------------- */ static LayerCollection *find_layer_collection_by_scene_collection(LayerCollection *lc, |