Exemplo n.º 1
0
        /// <summary>
        /// Draw the edge on the graph that connects 2 nodes passed, if edge param is null, create a new edge
        /// </summary>
        /// <param name="startNode"></param>
        /// <param name="endNode"></param>
        /// <param name="edge"></param>
        private void DrawEdge(CanvasNode startNode, CanvasNode endNode, CanvasEdge edge = null)
        {
            Point startPoint, endPoint;

            startPoint = new Point(startNode.X, startNode.Y);
            endPoint   = new Point(endNode.X, endNode.Y);

            if (edge == null)
            {
                edge = new CanvasEdge()
                {
                    Stroke = Brushes.DarkGray,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    StrokeThickness     = 3,
                    X1         = startNode.X,
                    Y1         = startNode.Y,
                    X2         = endNode.X,
                    Y2         = endNode.Y,
                    IsDirected = ArcType.SelectedItem == DirectedArc
                };

                // Add attributes to the edge
                foreach (KeyValuePair <string, double> attr in graph.CommonAttributes)
                {
                    if (!edge.Impl.HasNumericAttribute(attr.Key))
                    {
                        edge.Impl.NumericAttributes.Add(attr.Key, attr.Value);
                    }
                }

                graph.Call(graph =>
                {
                    graph.ConnectNodeToWith(startNode.Impl, endNode.Impl, edge.Impl);
                });
                graph[edge.Impl] = edge;
            }
            else
            {
                edge.Stroke = Brushes.DarkGray;
                edge.HorizontalAlignment = HorizontalAlignment.Center;
                edge.VerticalAlignment   = VerticalAlignment.Center;
                edge.StrokeThickness     = 3;
            }


            MainCanvas.Children.Add(edge);
            Canvas.SetZIndex(edge, -1);

            startNode.OutLines.Add(edge);
            endNode.InLines.Add(edge);

            MainCanvas.UpdateLines(startNode);
            MainCanvas.UpdateLines(endNode);
        }