Exemplo n.º 1
0
        public async Task AddNewEdge(bool done)
        {
            if (done && NewEdge.Head != null && NewEdge.Tail != null)
            {
                if (!Graph.MultiGraph && NewEdge.Head == NewEdge.Tail)
                {
                    Graph.MultiGraph = true;
                }
                else if (NewEdge.MultiGraph == false && NewEdge.MultiEdges != null)
                {
                    foreach (Edge edge in NewEdge.MultiEdges)
                    {
                        Graph.Edges.Remove(edge);
                    }
                }
                else if (!Graph.MultiGraph)
                {
                    Graph.MultiGraph = true;
                }
                if (Graph.Weighted)
                {
                    EdgeService.AddEdge(Graph.Edges, Options.Default, NewEdge.Head, NewEdge.Tail, Math.Round(NewEdge.Weight, 2));
                }
                else
                {
                    EdgeService.AddEdge(Graph.Edges, Options.Default, NewEdge.Head, NewEdge.Tail);
                }
            }
            await NewEdgeChanged.InvokeAsync(new NewEdge());

            await ActiveGraphChanged.InvokeAsync(new Graph());
        }
Exemplo n.º 2
0
        public async Task IterateNodes(int i)
        {
            Counter = Math.Abs((Counter + i) % FilterNodes.Count);
            ActiveGraph.Nodes.Clear();
            ActiveGraph.Nodes.Add(FilterNodes[Counter]);
            await ActiveGraphChanged.InvokeAsync(ActiveGraph);

            await OnRecenter();
        }
Exemplo n.º 3
0
        public async Task Paste()
        {
            int nextNodeId = NodeService.NextId(Graph.Nodes);

            PasteOffset += 5 * SVGControl.Scale;
            ActiveGraph  = new Graph();
            foreach (Node node in CopiedGraph.Nodes)
            {
                ActiveGraph.Nodes.Add(NodeService.AddNode(Graph.Nodes, node, nextNodeId, PasteOffset));
            }
            foreach (Edge edge in CopiedGraph.Edges)
            {
                ActiveGraph.Edges.Add(EdgeService.AddEdge(Graph, edge, nextNodeId));
            }
            await GraphChanged.InvokeAsync(Graph);

            await ActiveGraphChanged.InvokeAsync(ActiveGraph);
        }
Exemplo n.º 4
0
        public async Task Activate(string type)
        {
            switch (type)
            {
            case "nodes":
                ActiveGraph.Nodes = Graph.Nodes;
                await ActiveGraphChanged.InvokeAsync(ActiveGraph);

                break;

            case "edges":
                ActiveGraph.Edges = Graph.Edges;
                await ActiveGraphChanged.InvokeAsync(ActiveGraph);

                break;

            case "all":
                await ActiveGraphChanged.InvokeAsync(Graph);

                break;
            }
        }
Exemplo n.º 5
0
 public async Task GoUpdateActiveEdges()
 {
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 6
0
 public async Task SelectEdges()
 {
     ActiveGraph.Edges = Graph.Edges;
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 7
0
 public async Task RemoveActiveNode(Node node)
 {
     ActiveGraph.Nodes.Remove(node);
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 8
0
 public async Task JustThisNodeActive(Node node)
 {
     ActiveGraph = new Graph();
     ActiveGraph.Nodes.Add(node);
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 9
0
 public async Task AddActiveNode(Node node)
 {
     ActiveGraph.Nodes.Add(node);
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 10
0
 public async Task RemoveActiveEdge(Edge edge)
 {
     ActiveGraph.Edges.Remove(edge);
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 11
0
 public async Task AddActiveEdge(Edge edge)
 {
     ActiveGraph.Edges.Add(edge);
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 12
0
 public async Task OnEdgeClick(Edge edge)
 {
     ActiveGraph = new Graph();
     ActiveGraph.Edges.Add(edge);
     await ActiveGraphChanged.InvokeAsync(ActiveGraph);
 }
Exemplo n.º 13
0
 public async Task OnMouseUp(MouseEventArgs e)
 {
     MouseDown = false;
     if (e.Button == 2)
     {
         RectSelection.Create = false;
         if (!e.CtrlKey && RectSelection.Width <= 0 && RectSelection.Height <= 0)
         {
             if (ObjectClicked.Right)
             {
                 ObjectClicked.Right = false;
                 ObjectContextMenu.Open(e.ClientX, e.ClientY);
             }
             else
             {
                 if (GraphMode == GraphMode.Algorithm)
                 {
                     AlgorithmContextMenu.Open(e.ClientX, e.ClientY);
                 }
                 else
                 {
                     CanvasContextMenu.Open(e.ClientX, e.ClientY);
                     origin[0] = e.ClientX;
                     origin[1] = e.ClientY;
                     if (ActiveGraph.Nodes.Any() || ActiveGraph.Edges.Any())
                     {
                         await ActiveGraphChanged.InvokeAsync(new Graph());
                     }
                 }
             }
         }
         else
         {
             bool aNodesChanged = false;
             bool aEdgesChanged = false;
             foreach (Node node in Graph.Nodes)
             {
                 if (node.Xaxis <= RectSelection.X + RectSelection.Width &&
                     node.Xaxis >= RectSelection.X &&
                     node.Yaxis <= RectSelection.Y + RectSelection.Height &&
                     node.Yaxis >= RectSelection.Y)
                 {
                     if (!ActiveGraph.Nodes.Contains(node))
                     {
                         ActiveGraph.Nodes.Add(node);
                         aNodesChanged = true;
                     }
                 }
                 else if (ActiveGraph.Nodes.Remove(node))
                 {
                     aNodesChanged = true;
                 }
             }
             foreach (Edge edge in Graph.Edges)
             {
                 ShowEdge showEdge = new ShowEdge(edge);
                 var      x        = 0.25 * edge.Head.Xaxis + 0.5 * showEdge.CurvePoint[0] + 0.25 * edge.Tail.Xaxis;
                 var      y        = 0.25 * edge.Head.Yaxis + 0.5 * showEdge.CurvePoint[1] + 0.25 * edge.Tail.Yaxis;
                 if (x <= RectSelection.X + RectSelection.Width &&
                     x >= RectSelection.X &&
                     y <= RectSelection.Y + RectSelection.Height &&
                     y >= RectSelection.Y)
                 {
                     if (!ActiveGraph.Edges.Contains(edge))
                     {
                         ActiveGraph.Edges.Add(edge);
                         aEdgesChanged = true;
                     }
                 }
                 else if (ActiveGraph.Edges.Remove(edge))
                 {
                     aEdgesChanged = true;
                 }
             }
             if (aNodesChanged || aEdgesChanged)
             {
                 await ActiveGraphChanged.InvokeAsync(ActiveGraph);
             }
         }
         RectSelection = new RectSelection();
         return;
     }
     if (ObjectClicked.Left)
     {
         ObjectClicked.Left = false;
         if (GraphMode == GraphMode.InsertNode)
         {
             SvgClass = "pointer";
         }
         else
         {
             SvgClass = "grab";
         }
     }
     else if (!e.CtrlKey && !ActiveGraph.Nodes.Any() && !ActiveGraph.Nodes.Any() && GraphMode == GraphMode.InsertNode)
     {
         NodeService.AddNode(Graph.Nodes, Options.Default, e.ClientX * SVGControl.Scale + SVGControl.Xaxis, e.ClientY * SVGControl.Scale + SVGControl.Yaxis);
     }
     else if (ActiveGraph.Nodes.Any() || ActiveGraph.Edges.Any())
     {
         await ActiveGraphChanged.InvokeAsync(new Graph());
     }
     if (SVGControl.Pan)
     {
         SVGControl.Pan      = false;
         SvgClass            = "grab";
         SVGControl.OldXaxis = SVGControl.Xaxis;
         SVGControl.OldYaxis = SVGControl.Yaxis;
     }
 }