private void AddToSelection([NotNull] EntityHierarchyElementViewModel element)
        {
            lock (LockObject)
            {
                if (!element.IsSelectable)
                {
                    return;
                }

                // Add the entity id to the selected ids
                SelectedIds.Add(element.Id);

                // Check if one of its parents is in the selection
                var parent = element.TransformParent;
                while (parent != null)
                {
                    if (SelectedIds.Contains(parent.Id))
                    {
                        break;
                    }

                    parent = parent.TransformParent;
                }

                // If so, the SelectedRootIds collection does not need to be updated.
                if (parent != null)
                {
                    return;
                }

                // Otherwise, it's a new root entity in the selection.
                SelectedRootIds.Add(element.Id);

                // Remove its children that were previously root entities in the selection.
                foreach (var child in element.TransformChildren.SelectDeep(x => x.TransformChildren))
                {
                    SelectedRootIds.Remove(child.Id);
                }
            }
        }
        private void RemoveFromSelection([NotNull] EntityHierarchyElementViewModel element)
        {
            lock (LockObject)
            {
                SelectedIds.Remove(element.Id);

                // Remove the root entity from the selected root entities
                if (SelectedRootIds.Remove(element.Id) && element.IsLoaded)
                {
                    // Ensure all children that are selected are properly added to the selected root collection
                    foreach (var child in element.TransformChildren.SelectDeep(x => x.TransformChildren).Where(x => SelectedIds.Contains(x.Id)))
                    {
                        // Check if one of its parents is in the selection
                        var parent = child.TransformParent;
                        while (parent != element && parent != null)
                        {
                            if (SelectedIds.Contains(parent.Id))
                            {
                                break;
                            }

                            parent = parent.TransformParent;
                        }

                        // If so, the SelectedRootIds collection does not need to be updated.
                        if (parent != element)
                        {
                            return;
                        }

                        // Otherwise, it's a new root entity in the selection.
                        SelectedRootIds.Add(child.Id);
                    }
                }
            }
        }