Beispiel #1
0
        public void CreateEdge(Vertex start, Vertex finish)
        {
            var edge = new Edge(start, finish, EdgesAreDirected, EdgesAreWeighted);

            if (EdgesAreDirected)
            {
                if (start.AdjacentNodes.Contains(finish)) return;
                start.AdjacentNodes.Add(finish);
                mainWindow.AdjacencyWindow.SetElement(start,finish,"1");
            }
            else
            {
                if (start.AdjacentNodes.Contains(finish)||finish.AdjacentNodes.Contains(start)) return;
                start.AdjacentNodes.Add(finish);
                finish.AdjacentNodes.Add(start);
                mainWindow.AdjacencyWindow.SetElement(start, finish, "1");
                mainWindow.AdjacencyWindow.SetElement(finish, start, "1");
            }

            start.IncidentEdges.Add(edge);
            finish.IncidentEdges.Add(edge);

            Edges.Add(edge);
            Panel.SetZIndex(edge.Body, -1);
            mainWindow.MainCanvas.Children.Add(edge.Body);
            
            if (EdgesAreWeighted)
                mainWindow.MainCanvas.Children.Add(edge.TbWeight);

            edge.Update();
        }
Beispiel #2
0
        public void FinalizeEdgeCreation(Vertex finish, Edge draggedEdge)
        {
            draggedEdge.B = finish;
            finish.IncidentEdges.Add(draggedEdge);
            draggedEdge.A.IncidentEdges.Add(draggedEdge);

            if (EdgesAreWeighted)
            {
                draggedEdge.CreateWeightBlock();
                mainWindow.MainCanvas.Children.Add(draggedEdge.TbWeight);
                Keyboard.Focus(draggedEdge.TbWeight);
            }

            if (EdgesAreDirected)
            {
                draggedEdge.A.AdjacentNodes.Add(finish);
                mainWindow.AdjacencyWindow.SetElement(draggedEdge.A, finish, "1");
            }
            else
            {
                finish.AdjacentNodes.Add(draggedEdge.A);
                draggedEdge.A.AdjacentNodes.Add(finish);
                mainWindow.AdjacencyWindow.SetElement(draggedEdge.A, finish, "1");
                mainWindow.AdjacencyWindow.SetElement(finish, draggedEdge.A, "1");
            }

            draggedEdge.Update();
        }