Exemplo n.º 1
0
        /// <summary>
        /// Calls the method that starts the simulation, changes the visible controls
        /// on the left panel to controls relevant to the running simulation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartSim_Click(object sender, EventArgs e)
        {
            DrawArea = new Bitmap(pbMain.Size.Width, pbMain.Size.Height);
            startSimulation();

            SimulationControlPanel duringSimPanel = new SimulationControlPanel();

            this.Controls.Add(duringSimPanel);
            duringSimPanel.Location = new Point(10, 34);
            duringSimPanel.BringToFront();

            duringSimPanel.OnStopSim += (s, ec) => OnStopSimulation(duringSimPanel);

            PictureBox pictureOutbound = new PictureBox
            {
                Name     = "pictureOutbound",
                Location = new Point(130, 550),
                Image    = Properties.Resources.bound,
                SizeMode = PictureBoxSizeMode.CenterImage
            };

            pbMain.Controls.Add(pictureOutbound);


            wh.AGVList.Add(new AGV(pbMain.Size.Height, pbMain.Size.Width)); // adding agv with the start position
            wh.LinesList.Add(new Line()
            {
            });
            wh.LinesList.Add(new Line()
            {
            });
            Rack A10 = new Rack(new Point(374, 267));
            Rack A9  = new Rack(new Point(344, 267));
            Rack A8  = new Rack(new Point(314, 267));
            Rack A7  = new Rack(new Point(284, 267));
            Rack A6  = new Rack(new Point(254, 267));
            Rack A5  = new Rack(new Point(224, 267));
            Rack A4  = new Rack(new Point(194, 267));
            Rack A3  = new Rack(new Point(164, 267));
            Rack A2  = new Rack(new Point(134, 267));
            Rack A1  = new Rack(new Point(104, 267));

            wh.LinesList[0].RackList.Add(A1);   //Adding all racks to the first line
            wh.LinesList[0].RackList.Add(A2);
            wh.LinesList[0].RackList.Add(A3);
            wh.LinesList[0].RackList.Add(A4);
            wh.LinesList[0].RackList.Add(A5);
            wh.LinesList[0].RackList.Add(A6);
            wh.LinesList[0].RackList.Add(A7);
            wh.LinesList[0].RackList.Add(A8);
            wh.LinesList[0].RackList.Add(A9);
            wh.LinesList[0].RackList.Add(A10);
            Rack B10 = new Rack(new Point(772, 267));
            Rack B9  = new Rack(new Point(742, 267));
            Rack B8  = new Rack(new Point(712, 267));
            Rack B7  = new Rack(new Point(682, 267));
            Rack B6  = new Rack(new Point(652, 267));
            Rack B5  = new Rack(new Point(622, 267));
            Rack B4  = new Rack(new Point(592, 267));
            Rack B3  = new Rack(new Point(562, 267));
            Rack B2  = new Rack(new Point(532, 267));
            Rack B1  = new Rack(new Point(502, 267));

            wh.LinesList[1].RackList.Add(B1);   //Adding all racks to the second line
            wh.LinesList[1].RackList.Add(B2);
            wh.LinesList[1].RackList.Add(B3);
            wh.LinesList[1].RackList.Add(B4);
            wh.LinesList[1].RackList.Add(B5);
            wh.LinesList[1].RackList.Add(B6);
            wh.LinesList[1].RackList.Add(B7);
            wh.LinesList[1].RackList.Add(B8);
            wh.LinesList[1].RackList.Add(B9);
            wh.LinesList[1].RackList.Add(B10);
            wh.AGVList[0].LoadImage();

            //ShortestPathAsync(104,267);
            //ShortestPathAsync(300, 400);
            AGVtimer.Enabled = true;

            try
            {
                if (comboBox1.SelectedItem.ToString() == "chair")
                {
                    ShortestPathAsync(502, 267);
                    ShortestPathAsync(750, 520);
                }
                else if (comboBox1.SelectedItem.ToString() == "sofa")
                {
                    ShortestPathAsync(314, 267);
                    ShortestPathAsync(665, 550);
                    // wh.AGVList[0].changeDirection("right");
                    // timer1.Enabled = true;
                }
                else if (comboBox1.SelectedItem.ToString() == "table")
                {
                    ShortestPathAsync(622, 267);
                    ShortestPathAsync(750, 520);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please select an item.");
            }

            PictureBox pictureInbound = new PictureBox
            {
                Name     = "pictureOutbound",
                Location = new Point(700, 550),
                Image    = Properties.Resources.bound,
                SizeMode = PictureBoxSizeMode.CenterImage
            };

            pbMain.Controls.Add(pictureInbound);


            pictureInbound.Paint += new PaintEventHandler((senderi, ei) =>
            {
                ei.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                string text = "INBOUND";

                SizeF textSize        = ei.Graphics.MeasureString(text, Font);
                PointF locationToDraw = new PointF();
                locationToDraw.X      = (pictureInbound.Width / 2) - (textSize.Width / 2);
                locationToDraw.Y      = (pictureInbound.Height / 2) - (textSize.Height / 2);

                ei.Graphics.DrawString(text, Font, Brushes.Black, locationToDraw);
            });

            pictureInbound.Paint += new PaintEventHandler((senderi, ei) =>
            {
                ei.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                string text = "OUTBOUND";

                SizeF textSize        = ei.Graphics.MeasureString(text, Font);
                PointF locationToDraw = new PointF();
                locationToDraw.X      = (pictureInbound.Width / 2) - (textSize.Width / 2);
                locationToDraw.Y      = (pictureInbound.Height / 2) - (textSize.Height / 2);

                ei.Graphics.DrawString(text, Font, Brushes.Black, locationToDraw);
            });

            pictureOutbound.Paint += new PaintEventHandler((sendero, eo) =>
            {
                eo.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                string text = "INBOUND";

                SizeF textSize        = eo.Graphics.MeasureString(text, Font);
                PointF locationToDraw = new PointF();
                locationToDraw.X      = (pictureInbound.Width / 2) - (textSize.Width / 2);
                locationToDraw.Y      = (pictureInbound.Height / 2) - (textSize.Height / 2);

                eo.Graphics.DrawString(text, Font, Brushes.Black, locationToDraw);
            });
        }