Пример #1
0
        //--------------------------------------------------------------------------------------------------

        public BodyShapeTreeShape(Shape shape, BodyShapeTreeItem parent, ObservableCollection <BodyShapeTreeItem> currentList)
            : base(parent)
        {
            Shape = shape;

            // Set inactive, if
            // - the parent was not active
            // - the last sibling was not active
            // - the shape itself is not the current shape of the body
            if ((parent == null || parent.IsInactive) &&
                (!currentList.Any() || currentList.Last().IsInactive) &&
                (shape.Body.Shape != shape))
            {
                IsInactive = true;
            }

            currentList.Add(this);

            if (shape is ModifierBase modifierBase)
            {
                // The first children is the predecessor, sort it into the current list
                CreateItem(modifierBase.Operands[0], parent, currentList);

                for (int i = 1; i < modifierBase.Operands.Count; i++)
                {
                    CreateItem(modifierBase.Operands[i], this, Children);
                }
            }
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------


        public BodyShapeTreeBody(BodyShapeOperand bodyOperand, BodyShapeTreeItem parent, ObservableCollection <BodyShapeTreeItem> currentList)
            : base(parent)
        {
            BodyOperand = bodyOperand;
            if (parent == null)
            {
                // Are we operand 0?
                var supposedParent      = currentList.LastOrDefault();
                var supposedParentShape = (supposedParent as BodyShapeTreeShape)?.Shape as ModifierBase;
                if (supposedParentShape?.Operands.FirstOrDefault() == bodyOperand)
                {
                    ParentShape = supposedParentShape;
                }
            }
            else
            {
                ParentShape = (parent as BodyShapeTreeShape)?.Shape as ModifierBase;
            }

            // Set inactive, if
            // - the parent was not active
            // - the last sibling was not active
            if ((parent == null || parent.IsInactive) &&
                (!currentList.Any() || currentList.Last().IsInactive))
            {
                IsInactive = true;
            }

            currentList.Add(this);
        }
Пример #3
0
        //--------------------------------------------------------------------------------------------------

        public static BodyShapeTreeItem CreateItem(object obj, BodyShapeTreeItem parent, ObservableCollection <BodyShapeTreeItem> parentList)
        {
            switch (obj)
            {
            case Shape shape:
                return(new BodyShapeTreeShape(shape, parent, parentList));

            case BodyShapeOperand bodyOperand:
                return(new BodyShapeTreeBody(bodyOperand, parent, parentList));
            }
            return(null);
        }
Пример #4
0
        //--------------------------------------------------------------------------------------------------

        public override void Cleanup()
        {
            _SelectedEditor?.Stop();
            _SelectedEditor = null;

            Body.PropertyChanged -= Body_PropertyChanged;
            Body = null;

            SelectedItems.Clear();
            SelectedItems.CollectionChanged -= _SelectedItems_CollectionChanged;
            _SelectedItem = null;
            Items.Clear();
        }
Пример #5
0
        //--------------------------------------------------------------------------------------------------

        void _SelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (SelectedItems.Count != 1)
            {
                _SelectedEditor?.Stop();
                _SelectedEditor = null;
                return;
            }
            if (_SelectedItem != SelectedItems[0])
            {
                _SelectedItem = SelectedItems[0];
                _SelectedEditor?.Stop();
                _SelectedEditor = _SelectedItem.CreateEditor();
                _SelectedEditor?.Start();
            }
        }
Пример #6
0
        //--------------------------------------------------------------------------------------------------

        void _UpdateTree()
        {
            var expandedObjects = new List <object>();

            foreach (var item in Items)
            {
                item.UpdateExpandedState(expandedObjects, true);
            }

            var oldSelectedItem = SelectedItems.FirstOrDefault();

            if (oldSelectedItem != null && Items.FirstOrDefault() == SelectedItems.FirstOrDefault())
            {
                oldSelectedItem = null;
            }

            var lastVerticalOffset = TreeView?.ScrollViewer?.VerticalOffset;

            Items.Clear();
            SelectedItems.Clear();

            BodyShapeTreeItem.CreateItem(Body.RootShape, null, Items);

            foreach (var item in Items)
            {
                item.UpdateExpandedState(expandedObjects, false);
            }

            if (oldSelectedItem != null)
            {
                foreach (var item in Items)
                {
                    var same = item.FindSame(oldSelectedItem);
                    if (same != null)
                    {
                        SelectedItems.Add(same);
                        break;
                    }
                }
            }
            else
            {
                var needle = Body.Shape;
                foreach (var item in Items)
                {
                    var same = item.FindSame(needle);
                    if (same != null)
                    {
                        SelectedItems.Add(same);
                        break;
                    }
                }
            }

            if (lastVerticalOffset.HasValue)
            {
                TreeView.ScrollViewer.ScrollToVerticalOffset(lastVerticalOffset.Value);
            }

            if (SelectedItems.Any())
            {
                var item = SelectedItems.First();
                while (item.ParentItem != null)
                {
                    item            = item.ParentItem;
                    item.IsExpanded = true;
                }

                TreeView?.BringIntoView(item);
            }
        }
Пример #7
0
        //--------------------------------------------------------------------------------------------------

        protected BodyShapeTreeItem(BodyShapeTreeItem parentItem)
        {
            ParentItem = parentItem;
        }