Exemple #1
0
 private void btnRemoveNode_Click(object sender, RoutedEventArgs e)
 {
     if (_sourceElement is VertexVisual)
     {
         VertexVisualsList.Remove(_sourceElement as VertexVisual);
         pnlMap.Children.Remove(_sourceElement as VertexVisual);
         _sourceElement = null;
     }
 }
Exemple #2
0
        private void btnAddEdge_Click(object sender, RoutedEventArgs e)
        {
            int from, to;

            if (!int.TryParse(tbStart.Text, out from) || !int.TryParse(tbFinish.Text, out to))
            {
                lblErrorInfo.Content = "Укажите номер вершины";
                return;
            }
            try
            {
                WayPoint NodeFrom, NodeTo;
                NodeFrom = VertexVisualsList[VertexVisualsList.FindIndex(delegate(VertexVisual vv){ return(int.Parse(vv.Number) == from); })].Node;
                NodeTo   = VertexVisualsList[VertexVisualsList.FindIndex(delegate(VertexVisual vv){ return(int.Parse(vv.Number) == to); })].Node;
                if (EdgeVisualsList.FindIndex(delegate(EdgeVisual obj) { return(obj.NodeFrom == NodeFrom && obj.NodeTo == NodeTo); }) == -1)
                {
                    EdgeVisual ev = new EdgeVisual(new PathFigure(NodeFrom.LocationPoint, new List <PathSegment>()
                    {
                        new LineSegment(NodeTo.LocationPoint, true)
                    }, false))
                    {
                        NodeFrom = NodeFrom,
                        NodeTo   = NodeTo,
                        Zoom     = Zoom
                    };
                    EdgeVisualsList.Add(ev);
                    pnlMap.Children.Insert(0, ev);
                    foreach (var vertex in VertexVisualsList.FindAll(delegate(VertexVisual vv) { return(vv.Node == NodeFrom); }))
                    {
                        vertex.OutCount++;
                    }
                    foreach (var vertex in VertexVisualsList.FindAll(delegate(VertexVisual vv) { return(vv.Node == NodeTo); }))
                    {
                        vertex.InCount++;
                    }
                }
                else
                {
                    lblErrorInfo.Content = "Такое ребро уже существует";
                    return;
                }
            }
            catch (IndexOutOfRangeException ee)
            {
                lblErrorInfo.Content = "Одна из вершин не найдена";
                return;
            }
            catch (ArgumentOutOfRangeException ee)
            {
                lblErrorInfo.Content = "Одна из вершин не найдена";
                return;
            }
            lblErrorInfo.Content = "Ребро добавлено";
        }
Exemple #3
0
        private void pnlMap_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Point    position = e.GetPosition(pnlMap);
            WayPoint wp       = new WayPoint()
            {
                LocationPoint = new Point(position.X / Zoom, position.Y / Zoom)
            };
            VertexVisual vv = new VertexVisual(wp)
            {
                Number = (VertexVisualsList.Count + 1).ToString(),
                Zoom   = Zoom
            };

            VertexVisualsList.Add(vv);
            pnlMap.Children.Add(vv);
        }