The goal of this refactor is to improve resync of LayerCollections
hierarchy to match again Collection one.
Current code would destroy and re-create valid layers whenever a parent
collection would be removed, which leads to losing way too often
layer-related settings when editing collection hierarchies.
While this could be partially addressed from operators side, there was
no way to fix those issues from lower level, more generic ID management
code like ID remapping or library override resync processes.
The new code builds a shallow wrapper around existing (aka old) layers
hierarchy, does a set of checks to define the status of all existing
layers, and try to find the closest matching unused layer in cases where
layers and collections hierarchies do not match anymore.
The intent is to both re-use as much as possible existing layers, and
to pick the 'best' possible layer to re-use, following those heuristics:
- Prefer layers children of current one first (in old hierarchy), and only use those from other higher-level hierarchies in no (grand-)child is found.
- Prefer to use closest layers available in the old hierarchy.
This commit also removes the dedicated code in BKE_collection_move to
preserve LayerCollection flags. This code was actually forcefully
re-enabling excluded layers in some cases...