Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                var wndChange = new ChangeLinkWindow(FromItem, TargetItem, Chance)
                                    {
                                        Owner = Application.Current.MainWindow,
                                    };

                MouseLeave -= OnMouseLeave;
                SetColoredStyle();
                wndChange.ShowDialog();
                SetDeafultStyle();
                MouseLeave += OnMouseLeave;

                var chance = wndChange.Chance;
                if (chance == 0) return;
                var tempChance = Chance;
                Chance = chance;
                if (FromItem.SumChanceOut > 1)
                {
                    MessageBox.Show("Сумма вероятностей > 100%", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
                    Chance = tempChance;
                }
            }
        }