예제 #1
0
        private void EditElement()
        {
            TextLabel selectedTextLabel = FindTextLabel(mouseLocation);
            if (selectedTextLabel != null)
            {
                EditText textForm = new EditText(selectedTextLabel);
                textForm.SetLocation(ctlPicBox.PointToScreen(selectedTextLabel.Location));
                textForm.ShowDialog();
                return;
            }

            Router selectedRouter = FindRouter(mouseLocation);
            if (selectedRouter != null)
            {
                SelectedElements.Clear();
                SelectedElements.Add(selectedRouter);
                UpdateField();
                RouterForm properties = new RouterForm(selectedRouter, Network);
                if (properties.ShowDialog(this) == DialogResult.OK)
                {
                    mainForm.AreasRefresh(this.Network.Areas.Count - 1);
                    Network.RoutersRecolor();
                    UpdateField();
                }
                return;
            }

            if (SelectedChannel != null)
            {
                ChannelForm properties = new ChannelForm(SelectedChannel);
                if (properties.ShowDialog(this) == DialogResult.OK)
                {
                    SelectedChannel.ChangeCriterion(mainForm.Criterion);
                    ctlPicBox.Invalidate();
                }
                SelectedChannel = null;
            }
        }
예제 #2
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();
            }
        }