// конструктор public RouterForm(Router r, Network net) { InitializeComponent(); network = net; router = r; selectedPort = router.Ports[0]; InitializeInterfaces(); FindAreas(); }
public Channel(Router sRouter, Port sPort, Router eRouter, Port ePort) { startRouter = sRouter; sRouter.Channels.Add(this); endRouter = eRouter; eRouter.Channels.Add(this); endPort = ePort; endPort.Connect(this, sRouter); startPort = sPort; startPort.Connect(this, eRouter); endPort.OppositePort = sPort; startPort.OppositePort = ePort; // добавление ребра в сегмент if (sRouter.Area == eRouter.Area) { Area = sRouter.Area; Area.Channels.Add(this); } UpdateOspf(); UpdateCenter(); }
private void InitializeInterfaces() { Int32 i = 0; foreach (Port port in router.Ports) { Button button = new Button(); button.Location = new Point(11, 5 + 21 * i); i++; button.Size = new Size(116, 20); button.Text = port.FullName; button.Name = String.Format("ctl{0}", port.FullName); button.Click += (_sender, _e) => { selectedPort = port; lblSelectedInterface.Text = port.FullName; ckOn.Checked = port.Status; switch (port.Bandwidth) { case 10: rbtn10Mbps.Checked = true; break; case 100: rbtn100Mbps.Checked = true; break; case 1000: rbtn1000Mbps.Checked = true; break; } }; ctlInterfacesPanel.Controls.Add(button); } lblSelectedInterface.Text = router.Ports[0].FullName; ckOn.Checked = router.Ports[0].Status; switch (router.Ports[0].Bandwidth) { case 10: rbtn10Mbps.Checked = true; break; case 100: rbtn100Mbps.Checked = true; break; case 1000: rbtn1000Mbps.Checked = true; break; } }
public void CreateChannel(Router r1, Port port1, Router r2, Port port2, Int32 delay, Int32 cost, Int32 metric) { Channel channel = new Channel(r1, port1, r2, port2); Network.Channels.Add(channel); drawingChannels.Add(channel); channel.Delay = delay; channel.Cost = cost; channel.Metric = metric; channel.ChangeCriterion(mainForm.Criterion); mainForm.ChannelsRefresh(Network.Channels.Count); }
public void CreateChannel(Router r1, Port port1, Router r2, Port port2) { Channel channel = new Channel(r1, port1, r2, port2); Network.Channels.Add(channel); drawingChannels.Add(channel); if (mainForm.AutoWeight == false) { ChannelForm properties = new ChannelForm(channel); properties.ShowDialog(this); } else { Random random = new Random(); channel.Delay = 1 + random.Next(15); channel.Cost = 1 + random.Next(15); channel.Metric = 1 + random.Next(15); } if (mainForm.AutoPortName == true) { CreateTextLabel(port1.ShortName, new Point(r1.Location.X + (r2.Location.X - r1.Location.X) / 6, r1.Location.Y + (r2.Location.Y - r1.Location.Y) / 6)); CreateTextLabel(port2.ShortName, new Point(r2.Location.X + (r1.Location.X - r2.Location.X) / 6, r2.Location.Y + (r1.Location.Y - r2.Location.Y) / 6)); } channel.ChangeCriterion(mainForm.Criterion); mainForm.ChannelsRefresh(Network.Channels.Count); }
// событие: клавиша мыши нажата private void ctlPicBox_MouseDown(object sender, MouseEventArgs e) { // обработка события if (e.Button == MouseButtons.Left) { switch (mainForm.Instrument) { case Instruments.Edit: IDrag selectedElement = null; if ((selectedElement = FindElement(e.Location)) == null) { if ((SelectedChannel = FindChannel(e.Location)) == null) multiSelect = true; SelectedElements.Clear(); } else { if (SelectedElements.Count == 0) SelectedElements.Add(selectedElement); else if (SelectedElements.Count == 1) { if (CtrlIsCliced == true) { if (selectedElement != SelectedElements[0]) SelectedElements.Add(selectedElement); else SelectedElements.Clear(); } else SelectedElements[0] = selectedElement; } else { if (CtrlIsCliced == true) { if (SelectedElements.Contains(selectedElement) == false) SelectedElements.Add(selectedElement); else SelectedElements.Remove(selectedElement); } else { if (SelectedElements.Contains(selectedElement) == false) { SelectedElements.Clear(); SelectedElements.Add(selectedElement); } } } foreach (IDrag element in SelectedElements) { element.XOffset = e.X - element.Location.X; element.YOffset = e.Y - element.Location.Y; } SelectedChannel = null; } rectPoint = e.Location; mouseIsCliced = true; break; case Instruments.Insert_Router: Router router = new Router(e.Location, Network.RouterMaxNumber + 1); Network.MainArea.AddRouter(router); Network.Routers.Add(router); drawingRouters.Add(router); if (mainForm.FullMesh == true) { Random random = new Random(); foreach (Router r in Network.Routers) { if (router != r) { Channel channel = new Channel(router, r); Network.Channels.Add(channel); drawingChannels.Add(channel); channel.Delay = 1 + random.Next(15); channel.Cost = 1 + random.Next(15); channel.Metric = 1 + random.Next(15); channel.ChangeCriterion(mainForm.Criterion); mainForm.ChannelsRefresh(Network.Channels.Count); } } } mainForm.RoutersRefresh(Network.Routers.Count); break; case Instruments.Insert_Channel: if (mouseIsCliced == true && tmpRouter1 != null) { if ((tmpRouter2 = FindRouter(e.Location)) != null) { ctlPicBoxContextMenu.Show(ctlPicBox.PointToScreen(e.Location)); } else { mouseIsCliced = false; tmpPort1 = tmpPort2 = null; tmpRouter1 = tmpRouter2 = null; } } else { if ((tmpRouter1 = FindRouter(e.Location)) != null) ctlPicBoxContextMenu.Show(ctlPicBox.PointToScreen(e.Location)); } break; case Instruments.Create_Text: TextLabel textLabel = CreateTextLabel(null, e.Location); EditText editTextForm = new EditText(textLabel); editTextForm.SetLocation(ctlPicBox.PointToScreen(textLabel.Location)); editTextForm.ShowDialog(); break; } UpdateField(); } }
// событие: раскрытие контекстного меню Рабочего Поля private void ctlPicBoxContextMenu_Opening(object sender, CancelEventArgs e) { ctlPicBoxContextMenu.Items.Clear(); switch (mainForm.Instrument) { case Instruments.Edit: // заполнить меню узла связи Router selectedRouter = FindRouter(mouseLocation); if (selectedRouter != null) { SelectedElements.Add(selectedRouter); SelectedChannel = null; ctlPicBoxContextMenu.Items.Clear(); ctlRemove.Image = Properties.Resources.ToolRouterRemove; ctlPicBoxContextMenu.Items.Add(ctlRemove); ctlPicBoxContextMenu.Items.Add(contextSeparator1); ctlPicBoxContextMenu.Items.Add(ctlDejkstra); ctlPicBoxContextMenu.Items.Add(ctlOptimalRout); ctlPicBoxContextMenu.Items.Add(ctlPrim); ctlPicBoxContextMenu.Items.Add(ctlSegmentation); ctlPicBoxContextMenu.Items.Add(ctlPairSwitch); ctlPicBoxContextMenu.Items.Add(contextSeparator2); ctlPicBoxContextMenu.Items.Add(ctlProperties); ctlRemove.Text = "Remove Router"; ctlPicBox.Invalidate(); return; } // заполнить меню канала связи SelectedChannel = FindChannel(mouseLocation); if (SelectedChannel != null) { SelectedElements.Clear(); ctlRemove.Image = Properties.Resources.ToolLineRemove; ctlPicBoxContextMenu.Items.Add(ctlRemove); ctlPicBoxContextMenu.Items.Add(contextSeparator1); ctlPicBoxContextMenu.Items.Add(ctlProperties); ctlRemove.Text = "Remove Channel"; ctlPicBox.Invalidate(); return; } // заполнить меню Рабочего Поля ctlPicBoxContextMenu.Items.Add(ctlDeleteAll); ctlPicBoxContextMenu.Items.Add(contextSeparator1); ctlPicBoxContextMenu.Items.Add(ctlProperties); UpdateField(); break; case Instruments.Insert_Channel: Router router = FindRouter(mouseLocation); if (router != null) { foreach (Port port in router.Ports) { ToolStripMenuItem item = new ToolStripMenuItem(); item.Name = port.FullName; item.Text = port.FullName; item.Enabled = !port.IsConnected; item.Size = new Size(32, 19); item.Click += (_sender, _e) => { if (tmpPort1 == null) { tmpPort1 = port; mouseIsCliced = true; } else { tmpPort2 = port; if (tmpRouter1 != null && tmpRouter1 != tmpRouter2) { CreateChannel(tmpRouter1, tmpPort1, tmpRouter2, tmpPort2); mouseIsCliced = false; tmpPort1 = tmpPort2 = null; tmpRouter1 = tmpRouter2 = null; } } }; ctlPicBoxContextMenu.Items.Add(item); } } break; } }
public Channel(Router sRouter, Router eRouter) { Port sPort = null; Port ePort = null; foreach (Port port in sRouter.Ports) { if (port.IsConnected == false) { sPort = port; break; } } foreach (Port port in eRouter.Ports) { if (port.IsConnected == false) { ePort = port; break; } } startRouter = sRouter; sRouter.Channels.Add(this); endRouter = eRouter; eRouter.Channels.Add(this); endPort = ePort; endPort.Connect(this, sRouter); startPort = sPort; startPort.Connect(this, eRouter); endPort.OppositePort = sPort; startPort.OppositePort = ePort; // добавление ребра в сегмент if (sRouter.Area == eRouter.Area) { Area = sRouter.Area; Area.Channels.Add(this); } UpdateOspf(); UpdateCenter(); }