Example #1
0
        private void GraphViewer_MouseUp(object sender, MsaglMouseEventArgs e)
        {
            string selectedNode = lastSelectedId;

            CheckObject();
            if (!string.IsNullOrWhiteSpace(lastSelectedId))
            {
                int lastSelectedGraphId;
                if (int.TryParse(lastSelectedId, out lastSelectedGraphId) && !string.IsNullOrWhiteSpace(selectedNode))
                {
                    var first  = graph.FindVertex(graphVisualizer.Nodes.Where(x => x.Id == selectedNode).FirstOrDefault().LabelText);
                    var second = graph.FindVertex(graphVisualizer.Nodes.Where(x => x.Id == lastSelectedId).FirstOrDefault().LabelText);
                    if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                        graph.ConnectVertex(first, second);
                    }
                    else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                    {
                        graph.RemoveEdge(first, second);
                    }
                    else if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
                    {
                        graph.RemoveVertex(first);
                    }
                    DrawGraph();
                }
            }
        }
Example #2
0
        private void GraphViewer_MouseUp(object sender, MsaglMouseEventArgs e)
        {
            string selectedNode = lastSelectedId;

            CheckObject();
            if (!string.IsNullOrWhiteSpace(lastSelectedId))
            {
                int lastSelectedGraphId = int.Parse(lastSelectedId);
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    if (!string.IsNullOrWhiteSpace(selectedNode))
                    {
                        var first  = graph.FindVertex(selectedNode);
                        var second = graph.FindVertex(lastSelectedId);

                        if (first?.Degree == 0 || second?.Degree == 0)
                        {
                            graph.ConnectVertex(first, second);
                        }
                    }
                    else
                    {
                        var vertex = graph.AddVertex();
                        graph.ConnectVertex(lastSelectedGraphId, vertex.Id);
                    }
                    DrawGraph();
                }
                else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    graph.RemoveVertex(graph.Vertices.Where(x => x.Id == lastSelectedGraphId).FirstOrDefault());
                    DrawGraph();
                }
            }
        }