public void update(NodeUI sender, RoutingTable table) { foreach (RoutingTuple offeredTuple in table.routingTable.Values) { if (offeredTuple.Destination == sender) continue; int distanceOffered = routingTable[sender].Distance + offeredTuple.Distance; if (routingTable.ContainsKey(offeredTuple.Destination)) { if (routingTable[offeredTuple.Destination].Distance > distanceOffered) { routingTable[offeredTuple.Destination].Distance = distanceOffered; routingTable[offeredTuple.Destination].Link = routingTable[sender].Link; } } else { routingTable.Add(offeredTuple.Destination, new RoutingTuple( offeredTuple.Destination, distanceOffered, routingTable[sender].Link ) ); } } }
public LinkUI(NodeUI ep1, NodeUI ep2, int c) { endPoint1 = ep1; endPoint2 = ep2; InitializeComponent(); Cost = c; updateLink(); }
// Triggered when a node is clicked, highlight the node and capture the mouse private void node_MouseLeftButtonDown(object sender, MouseEventArgs e) { NodeUI node = (NodeUI)sender; // dataGrid1.ItemsSource = node.RoutingTable.displayRoutingTable(); // if (!selectedNodes.Contains(node)) { node.CaptureMouse(); Mouse.OverrideCursor = System.Windows.Input.Cursors.Cross; ForceCursor = true; selectedNodes.Add(node); node.Selected = true; } }
// Triggered when the mouse is moved and the node is selected, used to update the GUI private void node_MouseMove(object sender, MouseEventArgs e) { NodeUI node = (NodeUI)sender; if (Mouse.LeftButton == MouseButtonState.Pressed && node.Selected) { Point pos = e.GetPosition(canvas1); Canvas.SetLeft(node, pos.X - node.RenderSize.Width / 2); Canvas.SetTop(node, pos.Y - node.RenderSize.Height / 2); if (links.ContainsKey(node)) { foreach (LinkUI l in links[node]) { l.updateLink(); } } } }
// private void Button_Click(object sender, RoutedEventArgs e) { // if (!(String.IsNullOrWhiteSpace(textBox1.Text) || nodes.ContainsKey(textBox1.Text))) { NodeUI nui = new NodeUI(); Canvas.SetLeft(nui, 50); Canvas.SetTop(nui, 50); nui.Label = textBox1.Text; nui.MouseLeftButtonDown += new MouseButtonEventHandler(node_MouseLeftButtonDown); nui.MouseLeftButtonUp += new MouseButtonEventHandler(node_MouseLeftButtonUp); nui.MouseMove += new MouseEventHandler(node_MouseMove); nodes.Add(nui.Label, nui); canvas1.Children.Add(nui); textBox1.Text = String.Empty; } else listBox1.Items.Add("The node name specified is incorrect."); }
// private void Button_Click(object sender, RoutedEventArgs e) { // if (!(String.IsNullOrWhiteSpace(textBox1.Text) || nodes.ContainsKey(textBox1.Text))) { NodeUI nui = new NodeUI(); Canvas.SetLeft(nui, 50); Canvas.SetTop(nui, 50); nui.Label = textBox1.Text; nui.MouseLeftButtonDown += new MouseButtonEventHandler(node_MouseLeftButtonDown); nui.MouseLeftButtonUp += new MouseButtonEventHandler(node_MouseLeftButtonUp); nui.MouseMove += new MouseEventHandler(node_MouseMove); nodes.Add(nui.Label, nui); canvas1.Children.Add(nui); textBox1.Text = String.Empty; } else { listBox1.Items.Add("The node name specified is incorrect."); } }
public void addRoutingEntry(NodeUI dest, int distance, LinkUI link) { routingTable.Add(dest, new RoutingTuple(dest, distance, link)); }
public RoutingTuple(NodeUI dest, int dist, LinkUI l) { Destination = dest; Distance = dist; Link = l; }