Exemple #1
0
        public ConnectionArrow(DiagramItem fromItem, DiagramItem toItem, double chance)
        {
            FromItem = fromItem;
            TargetItem = toItem;
            ConnectionArrowType = Equals(FromItem, TargetItem)
                                      ? ConnectionArrowType.Loopback
                                      : ConnectionArrowType.Normal;

            ViewType = ConnectionArrowType == ConnectionArrowType.Normal
                           ? Properties.Settings.Default.NormalArrowType
                           : Properties.Settings.Default.OutArrowType;

            if (toItem.GetType() == typeof(OutBuffItem))
            {
                ConnectionArrowType = Properties.Settings.Default.OutArrowType == 0
                                          ? ConnectionArrowType.Normal
                                          : ConnectionArrowType.OutArrowType;
            }

            Chance = chance;

            UpdateLink();
            SetDeafultStyle();

            fromItem.ConnectionArrows.Add(this);
            toItem.ConnectionArrows.Add(this);

            PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;
            MouseEnter += OnMouseEnter;
            MouseLeave += OnMouseLeave;
        }
        /// <summary>
        /// Добавление новой связи
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="chance"></param>
        /// <param name="isGroups">связь между группами</param>
        public void AddNewLink(DiagramItem from, DiagramItem to, double chance, bool isGroups = false)
        {
            if (isGroups)
            {
                _canvas.Children.Add(new ConnectionArrow(from, to, chance));
                return;
            }

            if ((to.GetType() == typeof(InBuffItem)) ||
                (from.GetType() == to.GetType() && to.GetType() != typeof(NodeItem)))
            {
                MessageBox.Show("Невозможно добавить связь", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (_canvas.Children.OfType<ConnectionArrow>().Count(
                x => Equals(x.FromItem, from) && Equals(x.TargetItem, to)) == 0)
            {
                var createWindow = new ChangeLinkWindow(from, to) {Owner = Application.Current.MainWindow};
                createWindow.ShowDialog();
                if (createWindow.Chance > 0)
                {
                    var connection = new ConnectionArrow(from, to, createWindow.Chance);
                    _canvas.Children.Add(connection);
                }
            }
            else MessageBox.Show("Такая связь уже имеется", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
        }