示例#1
0
 public void Remove(ConnectionArrow arrow)
 {
     arrow.FromItem.ConnectionArrows.Remove(arrow);
     arrow.TargetItem.ConnectionArrows.Remove(arrow);
     ConnectionArrows.Remove(arrow);
     _canvas.Children.Remove(arrow);
 }
示例#2
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);
        }