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;
        }
 public ChangeLinkWindow(DiagramItem fromItem, DiagramItem targetItem, double chance = 0)
 {
     Chance = chance;
     InitializeComponent();
     tbChance.PreviewTextInput += TbChanceOnPreviewTextInput;
     Title = string.Format("{0} -> {1} ({2}%)", fromItem.LabelName, targetItem.LabelName,
         Chance*100);
     KeyDown += (sender, args) =>
     {
         if (args.Key == Key.Enter) OkHandle();
     };
 }
Exemple #3
0
 /// <summary>
 /// Обновить положение элемента на экрани относительно его LatLng
 /// </summary>
 /// <param name="item"></param>
 public void UpdateScreenCoords(DiagramItem item)
 {
     var point = _map.FromLatLngToLocal(item.PositionLatLng);
     item.CenterPoint = new Point(point.X, point.Y);
 }
Exemple #4
0
 /// <summary>
 /// Обновить положение элемента относительно экранных координат
 /// </summary>
 /// <param name="item"></param>
 public void UpdateLatLngPoses(DiagramItem item)
 {
     item.PositionLatLng = _map.FromLocalToLatLng(Convert.ToInt32(item.CenterPoint.X),
                                                  Convert.ToInt32(item.CenterPoint.Y));
 }
 private void AddItemToVisual(DiagramItem dItem)
 {
     _canvas.Children.Add(dItem);
     MapHelper.Instance.UpdateLatLngPoses(dItem);
     dItem.UpdateLayout();
 }
 public void Remove(DiagramItem item)
 {
     Items.Remove(item);
     _canvas.Children.Remove(item);
 }
        /// <summary>
        /// Загрузить элементы на форму
        /// </summary>
        public void LoadDefaultElements()
        {
            var matrix = ReadFromFile.ReadMatrix();
            var vector = ReadFromFile.ReadMatrixRow();
            var positions = ReadFromFile.ReadLatLngPositions();

            var fromFileCoords = vector.Rows + vector.Cols + 1 == positions.Rows;

            var inBuffers = new DiagramItem[vector.Rows];
            for (int i = 0; i < vector.Rows; i++)
            {
                inBuffers[i] = AddNewItemBufferIn(new Point(30, 240 + 100*i));
                if (fromFileCoords)
                {
                    inBuffers[i].PositionLatLng = new PointLatLng(positions[i + 1, 1], positions[i + 1, 2]);
                    MapHelper.Instance.UpdateScreenCoords(inBuffers[i]);
                }
            }

            var outBuffer = new OutBuffItem("outBuf", _canvas.ActualWidth - 60, 200);

            if (fromFileCoords)
            {
                outBuffer.PositionLatLng = new PointLatLng(positions[vector.Rows + 1, 1], positions[vector.Rows + 1, 2]);
                MapHelper.Instance.UpdateScreenCoords(outBuffer);
            }
            _canvas.Children.Add(outBuffer);

            double curX = 140, curY = 200;
            for (int i = 1; i <= matrix.Rows; i++)
            {
                var dItem = AddNewItemDevice(new Point(curX + 30, curY + 40));
                if (fromFileCoords)
                {
                    dItem.PositionLatLng = new PointLatLng(positions[vector.Rows + 1 + i, 1],
                                                           positions[vector.Rows + 1 + i, 2]);
                    MapHelper.Instance.UpdateScreenCoords(dItem);
                }

                for (int vectIndex = 1; vectIndex <= vector.Rows; vectIndex++)
                {
                    if (vector[vectIndex, i] > 0) AddNewLink(inBuffers[vectIndex - 1], dItem, vector[vectIndex, i]);
                }
                var chance = MatrixHelper.CalculateRowChance(matrix, i);
                if (chance < 1.0f)
                {
                    AddNewLink(dItem, outBuffer, 1.0f - chance);
                }

                curX += 90;
                curY += (i%2 == 1) ? -80 : 80;
                if (curX > _canvas.ActualWidth - 100)
                {
                    curX = 100;
                    curY += 140;
                }
            }

            for (int i = 1; i <= matrix.Rows; i++)
            {
                for (int j = 1; j <= matrix.Cols; j++)
                {
                    if (matrix[i, j] > 0)
                    {
                        AddNewLink(DiagramItemsDevices[i-1], DiagramItemsDevices[j-1], matrix[i, j]);
                    }
                }
            }
        }
        /// <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);
        }
Exemple #9
0
        private void CanvasPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_addNewElement)
            {
                switch (_idOfNewElement)
                {
                    case 0:
                        DiagramItemManager.Instance.AddNewItemDevice(e.GetPosition(this));
                        ResetAddNew();
                        return;

                    case 1:
                        DiagramItemManager.Instance.AddNewItemBufferIn(e.GetPosition(this));
                        ResetAddNew();
                        return;
                }
            }

            if (Equals(e.Source, this) || !(e.Source is DiagramItem))
            {
                ClearSelection();

                _isLeftMouseButtonDownOnWindow = true;
                _origMouseDownPoint = e.GetPosition(this);

                CaptureMouse();
                return;
            }

            if (_addNewElement)
            {
                _line.X1 = e.GetPosition(this).X;
                _line.Y1 = e.GetPosition(this).Y;
                _line.Stroke = Brushes.Black;
                _line.StrokeThickness = 3;
                _line.IsHitTestVisible = false;
                _fromElement = e.Source as DiagramItem;
                return;
            }

            if (!_isDragging)
            {
                _startPoint = e.GetPosition(this);
                _selectedElement = (DiagramItem) e.Source;
                if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !_selectedElement.IsSelected)
                {
                    ClearSelection();
                }
                if (Keyboard.IsKeyDown(Key.LeftCtrl))
                {
                    _selectedElement.IsSelected = !_selectedElement.IsSelected;
                } else if (!_selectedElement.IsSelected)
                {
                    _selectedElement.IsSelected = true;
                }

                CaptureMouse();

                //_isDragging = true;

                _selectedItems.Clear();
                foreach (var selectedItem in DiagramItemManager.Instance.SelectedItems)
                {
                    //selectedItem.AddDragEffect();
                    _selectedItems.Add(selectedItem, selectedItem.CenterPoint);
                }
            }
            e.Handled = true;
        }