Esempio n. 1
0
        public void CreateNetwork(int width, int height)
        {
            int offset = 150;
            double countX = width / (Drawing.xOffset + offset);
            countX = Math.Floor(countX);

            double countY = height / (Drawing.yOffset + offset);
            countY = Math.Floor(countY);

            Router[,] mass = new Router[(int)countX, (int)countY];
            int constx = Drawing.xOffset + offset;
            int consty = Drawing.yOffset + offset;

            int x = 70;
            int y = 70;
            int routerNumber = 0;

            Network.Areas.Add(new Area());

            for (int i = 0; i < countX; i++)
            {
                for (int j = 0; j < countY; j++)
                {
                    Router router = new Router(new Point(x, y), routerNumber);
                    Network.MainArea.AddRouter(router);
                    mass[i, j] = router;
                    Network.Routers.Add(router);
                    routerNumber += 1;
                    y += consty;
                }
                x += constx;
                y = 70;
            }

            Random random = new Random();

            if (mainForm.FullMesh == false)
            {
                for (int i = 0; i < countX; i++)
                {
                    for (int j = 0; j < countY; j++)
                    {
                        if (j < countY - 1)
                        {
                            Channel channel = new Channel(mass[i, j], mass[i, j + 1]);
                            Network.Channels.Add(channel);
                            channel.Delay = 1 + random.Next(15);
                            channel.Cost = 1 + random.Next(15);
                            channel.Metric = 1 + random.Next(15);
                            channel.ChangeCriterion(mainForm.Criterion);
                        }

                        if (i > 0)
                        {
                            Channel channel = new Channel(mass[i, j], mass[i - 1, j]);
                            Network.Channels.Add(channel);
                            channel.Delay = 1 + random.Next(15);
                            channel.Cost = 1 + random.Next(15);
                            channel.Metric = 1 + random.Next(15);
                            channel.ChangeCriterion(mainForm.Criterion);
                        }
                    }
                }
            }
            else
            {
                foreach (Router router in Network.Routers)
                {
                    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);
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        // событие: клавиша мыши нажата
        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();
            }
        }