Ejemplo n.º 1
0
        private void addOperationButton_Click(object sender, RoutedEventArgs e)
        {
            if ((_operationMenu != null) && ((TileMenuItemViewModel)_operationMenu.DataContext).AreChildrenExpanded)
            {
                ((TileMenuItemViewModel)_operationMenu.DataContext).AreChildrenExpanded = false;
            }
            else if ((_operationMenu != null) && !((TileMenuItemViewModel)_operationMenu.DataContext).AreChildrenExpanded)
            {
                ((TileMenuItemViewModel)_operationMenu.DataContext).AreChildrenExpanded = true;
            }
            else if (_operationMenu == null)
            {
                var mainModel    = DataContext as MainModel;
                var buttonBounds = addOperationButton.GetBounds(this);
                var taskModels   =
                    mainModel.OperationTypeModels;

                if (_operationMenu != null)
                {
                    ((TileMenuItemViewModel)_operationMenu.DataContext).AreChildrenExpanded = false;
                    ((TileMenuItemViewModel)_operationMenu.DataContext).IsBeingRemoved      = true;
                    _operationMenu.Dispose();
                    menuCanvas.Children.Remove(_operationMenu);
                }

                var parentModel = new TileMenuItemViewModel(null);
                parentModel.ChildrenNrColumns = (int)Math.Ceiling(taskModels.Count() / 10.0);
                parentModel.ChildrenNrRows    = (int)Math.Min(10.0, taskModels.Count());
                parentModel.Alignment         = Alignment.Center;
                parentModel.AttachPosition    = AttachPosition.Right;

                var count = 0;
                foreach (var inputModel in taskModels)
                {
                    var tileMenuItemViewModel = recursiveCreateTileMenu(inputModel, parentModel);
                    tileMenuItemViewModel.Row        = count;
                    tileMenuItemViewModel.Column     = parentModel.ChildrenNrColumns - (int)Math.Floor((parentModel.Children.Count - 1) / 10.0) - 1;
                    tileMenuItemViewModel.RowSpan    = 1;
                    tileMenuItemViewModel.ColumnSpan = 1;
                    Debug.WriteLine(inputModel.Name + " c: " + tileMenuItemViewModel.Column + " r : " + tileMenuItemViewModel.Row);
                    count++;
                    if (count == 10.0)
                    {
                        count = 0;
                    }
                }

                _operationMenu = new TileMenuItemView {
                    MenuCanvas = menuCanvas, DataContext = parentModel
                };
                menuCanvas.Children.Add(_operationMenu);

                parentModel.CurrentPosition     = new Pt(-buttonBounds.Width, buttonBounds.Top);
                parentModel.TargetPosition      = new Pt(-buttonBounds.Width, buttonBounds.Top);
                parentModel.Size                = new Vec(buttonBounds.Width, buttonBounds.Height);
                parentModel.AreChildrenExpanded = true;
            }
        }
        private double getMaxColumnHeight(TileMenuItemViewModel model)
        {
            double max = 0;

            for (int col = 0; col < model.ChildrenNrColumns; col++)
            {
                var items = model.Children.Where(
                    mi =>
                    (mi.Column == col || (mi.Column < col && mi.Column + mi.ColumnSpan - 1 >= col)));
                double current = items.Sum(mi => mi.Size.Y) + (items.Count() - 1) * model.Gap;
                max = Math.Max(max, current);
            }
            return(max);
        }
Ejemplo n.º 3
0
        private TileMenuItemViewModel recursiveCreateTileMenu(object inputModel, TileMenuItemViewModel parent)
        {
            TileMenuItemViewModel currentTileMenuItemViewModel = null;

            if (inputModel is AttributeGroupModel)
            {
                var inputGroupModel = inputModel as AttributeGroupModel;
                currentTileMenuItemViewModel = new TileMenuItemViewModel(parent);
                var inputGroupViewModel = new InputGroupViewModel(null, inputGroupModel);
                currentTileMenuItemViewModel.TileMenuContentViewModel = new InputGroupViewTileMenuContentViewModel
                {
                    Name = inputGroupModel.RawName,
                    InputGroupViewModel = inputGroupViewModel
                };

                currentTileMenuItemViewModel.ChildrenNrColumns =
                    (int)Math.Ceiling(inputGroupModel.InputModels.Count() / 10.0);
                currentTileMenuItemViewModel.ChildrenNrRows = (int)Math.Min(10.0, inputGroupModel.InputModels.Count());
                currentTileMenuItemViewModel.Alignment      = Alignment.Center;
                currentTileMenuItemViewModel.AttachPosition = AttachPosition.Right;

                var count = 0;
                foreach (var childInputModel in inputGroupModel.InputModels /*.OrderBy(am => am.RawName)*/)
                {
                    var childTileMenu = recursiveCreateTileMenu(childInputModel, currentTileMenuItemViewModel);
                    childTileMenu.Row    = count; // TileMenuItemViewModel.Children.Count;
                    childTileMenu.Column = currentTileMenuItemViewModel.ChildrenNrColumns - 1 -
                                           (int)Math.Floor((currentTileMenuItemViewModel.Children.Count - 1) / 10.0);
                    childTileMenu.RowSpan    = 1;
                    childTileMenu.ColumnSpan = 1;
                    //currentTileMenuItemViewModel.Children.Add(childTileMenu);
                    count++;
                    if (count == 10.0)
                    {
                        count = 0;
                    }
                }
            }
            else if (inputModel is AttributeFieldModel)
            {
                currentTileMenuItemViewModel = new TileMenuItemViewModel(parent);
                var attributeTransformationViewModel = new AttributeTransformationViewModel(null,
                                                                                            new AttributeTransformationModel(inputModel as AttributeFieldModel));
                currentTileMenuItemViewModel.TileMenuContentViewModel = new InputFieldViewTileMenuContentViewModel
                {
                    Name = (inputModel as AttributeFieldModel).RawName,
                    AttributeTransformationViewModel = attributeTransformationViewModel
                };
            }
            else if (inputModel is OperationTypeGroupModel)
            {
                var taskGroupModel = inputModel as OperationTypeGroupModel;
                currentTileMenuItemViewModel = new TileMenuItemViewModel(parent);
                currentTileMenuItemViewModel.TileMenuContentViewModel = new OperationTypeGroupTileMenuContentViewModel
                {
                    Name = taskGroupModel.Name,
                    OperationTypeGroupModel = taskGroupModel
                };

                currentTileMenuItemViewModel.ChildrenNrColumns =
                    (int)Math.Ceiling(taskGroupModel.OperationTypeModels.Count() / 10.0);
                currentTileMenuItemViewModel.ChildrenNrRows = (int)Math.Min(10.0, taskGroupModel.OperationTypeModels.Count());
                currentTileMenuItemViewModel.Alignment      = Alignment.Center;
                currentTileMenuItemViewModel.AttachPosition = AttachPosition.Right;

                var count = 0;
                foreach (var childInputModel in taskGroupModel.OperationTypeModels /*.OrderBy(am => am.RawName)*/)
                {
                    var childTileMenu = recursiveCreateTileMenu(childInputModel, currentTileMenuItemViewModel);
                    childTileMenu.Row    = count; // TileMenuItemViewModel.Children.Count;
                    childTileMenu.Column = currentTileMenuItemViewModel.ChildrenNrColumns - 1 -
                                           (int)Math.Floor((currentTileMenuItemViewModel.Children.Count - 1) / 10.0);
                    childTileMenu.RowSpan    = 1;
                    childTileMenu.ColumnSpan = 1;
                    //currentTileMenuItemViewModel.Children.Add(childTileMenu);
                    count++;
                    if (count == 10.0)
                    {
                        count = 0;
                    }
                }
            }
            else if (inputModel is OperationTypeModel)
            {
                currentTileMenuItemViewModel = new TileMenuItemViewModel(parent);
                currentTileMenuItemViewModel.TileMenuContentViewModel = new OperationTypeTileMenuContentViewModel
                {
                    Name = (inputModel as OperationTypeModel).Name,
                    OperationTypeModel = inputModel as OperationTypeModel
                };
            }
            parent.Children.Add(currentTileMenuItemViewModel);
            currentTileMenuItemViewModel.Alignment      = Alignment.Center;
            currentTileMenuItemViewModel.AttachPosition = AttachPosition.Right;
            return(currentTileMenuItemViewModel);
        }
Ejemplo n.º 4
0
        private void addAttributeButton_Click(object sender, RoutedEventArgs e)
        {
            var mainModel = DataContext as MainModel;

            if ((_attributeMenu != null) && ((TileMenuItemViewModel)_attributeMenu.DataContext).AreChildrenExpanded)
            {
                ((TileMenuItemViewModel)_attributeMenu.DataContext).AreChildrenExpanded = false;
            }
            else if ((_attributeMenu != null) && !((TileMenuItemViewModel)_attributeMenu.DataContext).AreChildrenExpanded)
            {
                ((TileMenuItemViewModel)_attributeMenu.DataContext).AreChildrenExpanded = true;
            }
            else if ((_attributeMenu == null) && (mainModel.SchemaModel != null))
            {
                var buttonBounds = addAttributeButton.GetBounds(this);
                var inputModels  =
                    mainModel.SchemaModel.OriginModels.First()
                    .InputModels.Where(am => am.IsDisplayed) /*.OrderBy(am => am.RawName)*/;

                if (_attributeMenu != null)
                {
                    ((TileMenuItemViewModel)_attributeMenu.DataContext).AreChildrenExpanded = false;
                    ((TileMenuItemViewModel)_attributeMenu.DataContext).IsBeingRemoved      = true;
                    _attributeMenu.Dispose();
                    menuCanvas.Children.Remove(_attributeMenu);
                }

                var parentModel = new TileMenuItemViewModel(null);
                parentModel.ChildrenNrColumns = (int)Math.Ceiling(inputModels.Count() / 10.0);
                parentModel.ChildrenNrRows    = (int)Math.Min(10.0, inputModels.Count());
                parentModel.Alignment         = Alignment.Center;
                parentModel.AttachPosition    = AttachPosition.Right;

                var count = 0;
                foreach (var inputModel in inputModels)
                {
                    var tileMenuItemViewModel = recursiveCreateTileMenu(inputModel, parentModel);
                    tileMenuItemViewModel.Row    = count;
                    tileMenuItemViewModel.Column = parentModel.ChildrenNrColumns -
                                                   (int)Math.Floor((parentModel.Children.Count - 1) / 10.0) - 1;
                    tileMenuItemViewModel.RowSpan    = 1;
                    tileMenuItemViewModel.ColumnSpan = 1;

                    count++;
                    if (count == 10.0)
                    {
                        count = 0;
                    }
                }

                _attributeMenu = new TileMenuItemView {
                    MenuCanvas = menuCanvas, DataContext = parentModel
                };
                menuCanvas.Children.Add(_attributeMenu);

                parentModel.CurrentPosition     = new Pt(-buttonBounds.Width, buttonBounds.Top);
                parentModel.TargetPosition      = new Pt(-buttonBounds.Width, buttonBounds.Top);
                parentModel.Size                = new Vec(buttonBounds.Width, buttonBounds.Height);
                parentModel.AreChildrenExpanded = true;
            }
        }
        private void MenuItemView_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            TileMenuItemViewModel model = (TileMenuItemViewModel)DataContext;

            model.PropertyChanged            -= model_PropertyChanged;
            model.Children.CollectionChanged -= Children_CollectionChanged;
            model.PropertyChanged            += model_PropertyChanged;
            model.Children.CollectionChanged += Children_CollectionChanged;

            // initialize children
            foreach (var oldChildrenViews in _childernMenuItemViews)
            {
                oldChildrenViews.Dispose();
                if (MenuCanvas != null && MenuCanvas.Children.Contains(oldChildrenViews))
                {
                    MenuCanvas.Children.Remove(oldChildrenViews);
                }
            }
            _childernMenuItemViews.Clear();
            foreach (var menuItemViewModel in model.Children)
            {
                TileMenuItemView menutItemView = new TileMenuItemView()
                {
                    DataContext = menuItemViewModel
                };
                _childernMenuItemViews.Add(menutItemView);
            }
            updateChildrenTargetPositions();


            if (model.TileMenuContentViewModel == null)
            {
                this.Visibility = Visibility.Collapsed;
            }
            else
            {
                if (model.TileMenuContentViewModel is InputFieldViewTileMenuContentViewModel)
                {
                    mainGrid.Children.Clear();
                    mainGrid.Children.Add(new AttributeFieldView()
                    {
                        DataContext =
                            ((InputFieldViewTileMenuContentViewModel)model.TileMenuContentViewModel).AttributeTransformationViewModel
                    });
                }
                else if (model.TileMenuContentViewModel is OperationTypeTileMenuContentViewModel)
                {
                    mainGrid.Children.Clear();
                    mainGrid.Children.Add(new OperationTypeView()
                    {
                        DataContext =
                            ((OperationTypeTileMenuContentViewModel)model.TileMenuContentViewModel).OperationTypeModel
                    });
                }
                else if (model.TileMenuContentViewModel is OperationTypeGroupTileMenuContentViewModel)
                {
                    mainGrid.Children.Clear();
                    mainGrid.Children.Add(new OperationTypeView()
                    {
                        DataContext =
                            ((OperationTypeGroupTileMenuContentViewModel)model.TileMenuContentViewModel).OperationTypeGroupModel
                    });
                }
                else if (model.TileMenuContentViewModel is InputGroupViewTileMenuContentViewModel)
                {
                    mainGrid.Children.Clear();
                    mainGrid.Children.Add(new AttributeGroupView()
                    {
                        DataContext =
                            ((InputGroupViewTileMenuContentViewModel)model.TileMenuContentViewModel).InputGroupViewModel
                    });
                }
            }
        }
        private void updateChildrenTargetPositions()
        {
            TileMenuItemViewModel model = (DataContext as TileMenuItemViewModel);

            if (model.AreChildrenExpanded)
            {
                if (model.TileMenuContentViewModel != null && model.TileMenuContentViewModel.Name == "bmp")
                {
                }
                if (model.AttachPosition == AttachPosition.Left)
                {
                    for (int col = model.ChildrenNrColumns - 1; col >= 0; col--)
                    {
                        for (int row = 0; row < model.ChildrenNrRows; row++)
                        {
                            var itemsInSameCol =
                                model.Children.Where(mi => mi.Row < row && mi.Column == col).ToList();
                            var itemsInSameRow =
                                model.Children.Where(
                                    mi =>
                                    mi.Column > col &&
                                    (mi.Row == row || (mi.Row < row && mi.Row + mi.RowSpan - 1 >= row))).ToList();

                            double currentY = model.CurrentPosition.Y + itemsInSameCol.Sum(mi => mi.Size.Y) +
                                              itemsInSameCol.Count * model.Gap;
                            double currentX = model.CurrentPosition.X - itemsInSameRow.Sum(mi => mi.Size.X) -
                                              itemsInSameRow.Count() * model.Gap - model.Gap;

                            var rowItem = model.Children.FirstOrDefault(mi => mi.Row == row && mi.Column == col);
                            if (rowItem != null)
                            {
                                rowItem.TargetPosition = new Pt(currentX - rowItem.Size.X, currentY);
                            }
                        }
                    }
                }
                else if (model.AttachPosition == AttachPosition.Right)
                {
                    for (int col = model.ChildrenNrColumns - 1; col >= 0; col--)
                    {
                        for (int row = 0; row < model.ChildrenNrRows; row++)
                        {
                            var itemsInSameCol =
                                model.Children.Where(mi => mi.Row < row && mi.Column == col).ToList();
                            var itemsInSameRow =
                                model.Children.Where(
                                    mi =>
                                    mi.Column > col &&
                                    (mi.Row == row || (mi.Row < row && mi.Row + mi.RowSpan - 1 >= row))).ToList();

                            double currentY = model.CurrentPosition.Y + itemsInSameCol.Sum(mi => mi.Size.Y) +
                                              itemsInSameCol.Count * model.Gap;
                            if (model.Alignment == Alignment.RightOrBottom)
                            {
                                var colMaxY = getMaxColumnHeight(model);
                                currentY -= colMaxY;
                                currentY += model.Size.Y + model.Gap;
                            }
                            if (model.Alignment == Alignment.Center)
                            {
                                var colMaxY = getMaxColumnHeight(model);
                                currentY -= colMaxY / 2.0;
                                currentY += model.Size.Y / 2.0;
                            }
                            double currentX = model.CurrentPosition.X + itemsInSameRow.Sum(mi => mi.Size.X) +
                                              model.Size.X +
                                              itemsInSameRow.Count() * model.Gap + model.Gap;

                            var rowItem = model.Children.FirstOrDefault(mi => mi.Row == row && mi.Column == col);
                            if (rowItem != null)
                            {
                                rowItem.TargetPosition = new Pt(currentX, currentY);
                            }
                        }
                    }
                }
                else if (model.AttachPosition == AttachPosition.Bottom)
                {
                    for (int col = 0; col < model.ChildrenNrColumns; col++)
                    {
                        for (int row = model.ChildrenNrRows - 1; row >= 0; row--)
                        {
                            var itemsInSameCol =
                                model.Children.Where(mi => mi.Row > row && mi.Column == col).ToList();
                            var itemsInSameRow =
                                model.Children.Where(mi => mi.Column < col && mi.Row == row).ToList();

                            double currentY = model.CurrentPosition.Y + itemsInSameCol.Sum(mi => mi.Size.Y) +
                                              model.Size.Y +
                                              itemsInSameCol.Count * model.Gap + model.Gap;
                            double currentX = model.CurrentPosition.X + itemsInSameRow.Sum(mi => mi.Size.X) +
                                              itemsInSameRow.Count() * model.Gap;

                            var rowItem = model.Children.FirstOrDefault(mi => mi.Row == row && mi.Column == col);
                            if (rowItem != null)
                            {
                                rowItem.TargetPosition = new Pt(currentX, currentY);
                            }
                        }
                    }
                }
                else if (model.AttachPosition == AttachPosition.Top)
                {
                    for (int col = 0; col < model.ChildrenNrColumns; col++)
                    {
                        for (int row = model.ChildrenNrRows - 1; row >= 0; row--)
                        {
                            var itemsInSameCol =
                                model.Children.Where(mi => mi.Row > row && mi.Column == col).ToList();
                            var itemsInSameRow =
                                model.Children.Where(mi => mi.Column < col && mi.Row == row).ToList();

                            double currentY = model.CurrentPosition.Y - itemsInSameCol.Sum(mi => mi.Size.Y) -
                                              itemsInSameCol.Count * model.Gap - model.Gap;
                            double currentX = model.CurrentPosition.X + itemsInSameRow.Sum(mi => mi.Size.X) +
                                              itemsInSameRow.Count() * model.Gap;

                            var rowItem = model.Children.FirstOrDefault(mi => mi.Row == row && mi.Column == col);
                            if (rowItem != null)
                            {
                                rowItem.TargetPosition = new Pt(currentX, currentY - rowItem.Size.Y);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var menuItemViewModel in model.Children)
                {
                    menuItemViewModel.TargetPosition = model.TargetPosition;
                }
            }
        }
        void model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName != "CurrentPosition")
            {
                TileMenuItemViewModel model = (TileMenuItemViewModel)DataContext;

                if (e.PropertyName == model.GetPropertyName(() => model.AreChildrenExpanded))
                {
                    if (model.AreChildrenExpanded)
                    {
                        if (MenuCanvas != null)
                        {
                            foreach (var menuItemViewModel in model.Children)
                            {
                                var view = _childernMenuItemViews.FirstOrDefault(v => v.DataContext == menuItemViewModel);
                                view.MenuCanvas = MenuCanvas;
                                if (!MenuCanvas.Children.Contains(view))
                                {
                                    MenuCanvas.Children.Add(view);
                                    //view.SendToBack();
                                }
                                menuItemViewModel.IsEnabled       = true;
                                menuItemViewModel.IsDisplayed     = true;
                                menuItemViewModel.IsBeingRemoved  = false;
                                menuItemViewModel.CurrentPosition = model.CurrentPosition;
                                view._animationTimer.Start();
                            }
                        }
                        //updateChildrenTargetPositions();
                    }
                    else
                    {
                        foreach (var menuItemViewModel in model.Children)
                        {
                            menuItemViewModel.IsEnabled      = false;
                            menuItemViewModel.IsBeingRemoved = true;
                        }
                    }
                    this.SendToFront();
                }
                else if (e.PropertyName == model.GetPropertyName(() => model.TargetPosition))
                {
                    //updateChildrenTargetPositions();
                }
                else if (e.PropertyName == model.GetPropertyName(() => model.IsBeingRemoved))
                {
                    if (model.IsBeingRemoved)
                    {
                        ExponentialEase easingFunction = new ExponentialEase();
                        easingFunction.EasingMode = EasingMode.EaseInOut;

                        DoubleAnimation animation = new DoubleAnimation();
                        animation.Duration       = TimeSpan.FromMilliseconds(400);
                        animation.From           = this.Opacity;
                        animation.To             = 0;
                        animation.EasingFunction = easingFunction;
                        Storyboard storyboard = new Storyboard();
                        storyboard.Children.Add(animation);
                        Storyboard.SetTarget(animation, this);
                        Storyboard.SetTargetProperty(animation, "Opacity");
                        storyboard.Begin();
                    }
                    else
                    {
                        ExponentialEase easingFunction = new ExponentialEase();
                        easingFunction.EasingMode = EasingMode.EaseInOut;

                        DoubleAnimation animation = new DoubleAnimation();
                        animation.Duration       = TimeSpan.FromMilliseconds(400);
                        animation.From           = this.Opacity;
                        animation.To             = 1;
                        animation.EasingFunction = easingFunction;
                        Storyboard storyboard = new Storyboard();
                        storyboard.Children.Add(animation);
                        Storyboard.SetTarget(animation, this);
                        Storyboard.SetTargetProperty(animation, "Opacity");
                        storyboard.Begin();
                    }
                }

                updateChildrenTargetPositions();
            }
        }