Example #1
0
        //Initializes all the objects in main_form
        private void Initialization()
        {
            int BoardersWidth = 2 * SystemInformation.Border3DSize.Width;

            if (Globals._FirstFormLoad)
            {
                if (File.Exists("info.txt"))
                {
                    StreamReader reader = new StreamReader("info.txt");
                    try {
                        Globals._WidthBlocks  = Convert.ToInt32(reader.ReadLine());
                        Globals._HeightBlocks = Convert.ToInt32(reader.ReadLine());
                        Globals._BlockSide    = Convert.ToInt32(reader.ReadLine());
                    } catch { MessageBox.Show("An error has occured while parsing the file to initialize form.\nPlease delete the file."); }
                    reader.Dispose();
                }
                Globals._FirstFormLoad = false;
            }


            isLoad = new int[Globals._WidthBlocks, Globals._HeightBlocks];
            //m_rectangels is an array of two 1d arrays
            //declares the length of the first 1d array
            m_rectangles = new GridBox[Globals._WidthBlocks][];


            for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
            {
                //declares the length of the seconds 1d array
                m_rectangles[widthTrav] = new GridBox[Globals._HeightBlocks];
                for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                {
                    //dynamically add the gridboxes into the m_rectangles.
                    //size of the m_rectangels is constantly increasing (while adding
                    //the gridbox values) until size=height or size = width.
                    //if (imported) { //this IF is executed as long as the user has imported a map of his choice
                    //    m_rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals._BlockSide) - BoardersWidth, heightTrav * Globals._BlockSide + Globals._TopBarOffset, importmap[widthTrav, heightTrav]);
                    //if (importmap[widthTrav, heightTrav] == BoxType.Load) {
                    //     isLoad[widthTrav, heightTrav] = 1;
                    // }
                    //} else {
                    m_rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals._BlockSide) - BoardersWidth, heightTrav * Globals._BlockSide + Globals._TopBarOffset, BoxType.Normal);
                    isLoad[widthTrav, heightTrav]       = 2;
                    //}
                }
            }
            if (imported)
            {
                imported = false;
            }


            searchGrid = new StaticGrid(Globals._WidthBlocks, Globals._HeightBlocks);
            jumpParam  = new AStarParam(searchGrid, Convert.ToSingle(Globals._AStarWeight)); //Default value until user edit it
            jumpParam.SetHeuristic(HeuristicMode.MANHATTAN);                                 //default value until user edit it

            ConfigUI();
        }
Example #2
0
 public GridLine(GridBox iFrom, GridBox iTo)
 {
     fromX     = iFrom.boxRec.X + ((Globals._BlockSide / 2) - 1);
     fromY     = iFrom.boxRec.Y + ((Globals._BlockSide / 2) - 1);
     toX       = iTo.boxRec.X + ((Globals._BlockSide / 2) - 1);
     toY       = iTo.boxRec.Y + ((Globals._BlockSide / 2) - 1);
     pen       = new Pen(Color.BlueViolet);
     pen.Width = 1;
 }
Example #3
0
        //function that resets all of the used objects so they are ready for reuse, preventing memory leaks
        private void FullyRestore()
        {
            if (trappedStatus != null)
            {
                Array.Clear(trappedStatus, 0, trappedStatus.GetLength(0));
            }

            //if (importmap != null) {
            //    Array.Clear(importmap, 0, importmap.GetLength(0));
            //     Array.Clear(importmap, 0, importmap.GetLength(1));
            // }

            if (BackgroundImage != null)
            {
                BackgroundImage = null;
            }

            startPos      = new List <GridPos>();
            selectedColor = Color.DarkGray;

            for (int i = 0; i < startPos.Count(); i++)
            {
                AGVs[i].JumpPoints = new List <GridPos>();
            }


            searchGrid = new StaticGrid(Globals._WidthBlocks, Globals._HeightBlocks);

            alwaysCross =
                aGVIndexToolStripMenuItem.Checked =
                    beforeStart        =
                        allowHighlight = true;

            atLeastOneObstacle                    =
                ifNoObstacles                     =
                    never                         =
                        imported                  =
                            calibrated            =
                                isMouseDown       =
                                    mapHasLoads   =
                                        overImage = false;

            menuPanel.Enabled = false;

            use_Halt = false;
            priorityRulesbetaToolStripMenuItem.Checked = false;

            importedLayout = null;
            jumpParam      = null;
            paper          = null;

            a
                  = b
                  = new int();


            AGVs = new List <Vehicle>();

            allowHighlight = true;
            highlightOverCurrentBoxToolStripMenuItem.Enabled = true;
            highlightOverCurrentBoxToolStripMenuItem.Checked = true;



            isLoad       = new int[Globals._WidthBlocks, Globals._HeightBlocks];
            m_rectangles = new GridBox[Globals._WidthBlocks][];
            for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
            {
                m_rectangles[widthTrav] = new GridBox[Globals._HeightBlocks];
            }

            //jagged array has to be resetted like this
            for (int i = 0; i < Globals._WidthBlocks; i++)
            {
                for (int j = 0; j < Globals._HeightBlocks; j++)
                {
                    m_rectangles[i][j] = new GridBox(i * Globals._BlockSide, j * Globals._BlockSide + Globals._TopBarOffset, BoxType.Normal);
                }
            }


            Initialization();

            main_form_Load(new object(), new EventArgs());

            for (int i = 0; i < AGVs.Count; i++)
            {
                AGVs[i].Status.Busy = false;
            }

            Globals._TimerStep = 0;

            nUD_AGVs.Value = AGVs.Count;
        }
Example #4
0
        //The most important event.When we let our mouse click up,all our changes are
        //shown in the screen
        private void main_form_MouseUp(object sender, MouseEventArgs e)
        {
            if (timer0.Enabled ||
                timer1.Enabled ||
                timer2.Enabled ||
                timer3.Enabled ||
                timer4.Enabled)
            {
                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                _tp.Hide(this);
                return;
            }

            Point clickCoords = new Point(e.X, e.Y);

            if (!Isvalid(clickCoords) || nUD_AGVs.Value == 0)
            {
                return;
            }

            _isMouseDown = false;

            if (rb_load.Checked)
            {
                for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                {
                    for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                    {
                        if (_rectangles[widthTrav][heightTrav].BoxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
                        {
                            _lastBoxType   = _rectangles[widthTrav][heightTrav].BoxType;
                            _lastBoxSelect = _rectangles[widthTrav][heightTrav];
                            switch (_lastBoxType)
                            {
                            case BoxType.Normal:
                                _rectangles[widthTrav][heightTrav].SwitchLoad();
                                _isLoad[widthTrav, heightTrav] = 1;
                                break;

                            case BoxType.Load:
                                _loads--;
                                _rectangles[widthTrav][heightTrav].SwitchLoad();
                                _isLoad[widthTrav, heightTrav] = 2;
                                break;

                            case BoxType.Wall:
                            case BoxType.Start:
                            case BoxType.End:
                                break;
                            }
                        }
                    }
                }
            }

            if (rb_start.Checked)
            {
                if (nUD_AGVs.Value == 1)//Saves only the last Click position to place the Start (1 start exists)
                {
                    for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                    {
                        for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                        {
                            if (_rectangles[widthTrav][heightTrav].BoxType == BoxType.Start)
                            {
                                _rectangles[widthTrav][heightTrav].SwitchEnd_StartToNormal();
                            }
                        }
                    }
                }
                else if (nUD_AGVs.Value > 1)    //Deletes the start with the smallest iX - iY coords and keeps the rest

                {
                    int startsCounter = 0;
                    int[,] startsPosition = new int[2, Convert.ToInt32(nUD_AGVs.Value)];


                    for (int widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                    {
                        for (int heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                        {
                            if (_rectangles[widthTrav][heightTrav].BoxType == BoxType.Start)
                            {
                                startsPosition[0, startsCounter] = widthTrav;
                                startsPosition[1, startsCounter] = heightTrav;
                                startsCounter++;
                            }
                            if (startsCounter == nUD_AGVs.Value)
                            {
                                _rectangles[startsPosition[0, 0]][startsPosition[1, 0]].SwitchEnd_StartToNormal();
                            }
                        }
                    }
                }


                //Converts the clicked box to Start point
                for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                {
                    for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                    {
                        if (_rectangles[widthTrav][heightTrav].BoxRec.Contains(clickCoords) &&
                            _rectangles[widthTrav][heightTrav].BoxType == BoxType.Normal)
                        {
                            _rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals.BlockSide) + Globals.LeftBarOffset, heightTrav * Globals.BlockSide + Globals.TopBarOffset, BoxType.Start);
                        }
                    }
                }
            }
            //same for Stop

            if (rb_stop.Checked)
            {
                for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                {
                    for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                    {
                        if (_rectangles[widthTrav][heightTrav].BoxType == BoxType.End)
                        {
                            _rectangles[widthTrav][heightTrav].SwitchEnd_StartToNormal();//allow only one end point
                        }
                    }
                }
                for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                {
                    for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                    {
                        if (_rectangles[widthTrav][heightTrav].BoxRec.Contains(clickCoords)
                            &&
                            _rectangles[widthTrav][heightTrav].BoxType == BoxType.Normal)
                        {
                            _rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * Globals.BlockSide + Globals.LeftBarOffset, heightTrav * Globals.BlockSide + Globals.TopBarOffset, BoxType.End);
                        }
                    }
                }
            }

            Redraw();//The main function of this executable.Contains almost every drawing and calculating stuff
            Invalidate();
        }
Example #5
0
        private void main_form_MouseDown(object sender, MouseEventArgs e)
        {
            //If the simulation is running, do not do anything.leave the function explicitly
            if (timer0.Enabled || timer1.Enabled || timer2.Enabled || timer3.Enabled || timer4.Enabled)
            {
                return;
            }

            //Supposing that timers are not enabled(that means that the simulation is not running)
            //we have a clicked point.Check if that point is valid.if not explicitly leave
            if (!Isvalid(new Point(e.X, e.Y)))
            {
                return;
            }
            //if the clicked point is inside a rectangle...
            _isMouseDown = true;
            if ((e.Button == MouseButtons.Left) && (rb_wall.Checked))
            {
                for (int widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                {
                    for (int heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                    {
                        if (_rectangles[widthTrav][heightTrav].BoxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
                        {
                            _lastBoxType   = _rectangles[widthTrav][heightTrav].BoxType;
                            _lastBoxSelect = _rectangles[widthTrav][heightTrav];
                            switch (_lastBoxType)   //...measure the reaction
                            {
                            case BoxType.Normal:    //if its wall or normal ,switch it to the opposite.
                            case BoxType.Wall:
                                _rectangles[widthTrav][heightTrav].SwitchBox();
                                Invalidate();
                                break;

                            case BoxType.Start:     //if its start or end,do nothing.
                            case BoxType.End:
                                break;
                            }
                        }
                    }
                }
            }
            //if the user press the right button of the mouse
            if (e.Button == MouseButtons.Right)
            {
                //prepare the tooltip
                Point   mycoords         = new Point(e.X, e.Y);
                GridBox clickedBox       = null;
                bool    isBorder         = true;
                string  currentBoxCoords = "X: - Y: -\r\n";
                string  currentBoxIndex  = "Index: N/A\r\n";
                string  currentBoxType   = "Block type: Border\r\n";
                string  isPath           = "Is part of path: N/A\r\n";
                bool    isPathBlock      = false;
                for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
                {
                    for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                    {
                        if (_rectangles[widthTrav][heightTrav].BoxRec.Contains(mycoords))
                        {
                            currentBoxType =
                                "Block type: " +
                                _rectangles[widthTrav][heightTrav].BoxType + "\r\n";
                            currentBoxCoords =
                                "X: " +
                                _rectangles[widthTrav][heightTrav].BoxRec.X + " " +
                                "Y: " +
                                _rectangles[widthTrav][heightTrav].BoxRec.Y + "\r\n";
                            currentBoxIndex =
                                "Index: " +
                                "iX: " + widthTrav + " " + "iY: " + heightTrav + "\r\n";

                            int agvIndex = 0;

                            if (_startPos != null)
                            {
                                for (int j = 0; j < _startPos.Count; j++)
                                {
                                    for (int i = 0; i < Globals.MaximumSteps; i++)
                                    {
                                        if (_rectangles[widthTrav][heightTrav].BoxRec.Contains
                                            (
                                                new Point(
                                                    Convert.ToInt32(_AGVs[j].Steps[i].X),
                                                    Convert.ToInt32(_AGVs[j].Steps[i].Y)
                                                    )
                                            ))
                                        {
                                            isPathBlock = true;
                                            agvIndex    = j;
                                            i           = Globals.MaximumSteps;
                                            j           = _startPos.Count;
                                        }
                                    }
                                }
                                clickedBox = _rectangles[widthTrav][heightTrav];
                            }
                            _tp.ToolTipIcon = ToolTipIcon.Info;
                            if (isPathBlock && _startPos != null)
                            {
                                isPath = "Is part of AGV" + (agvIndex) + " path";
                                _tp.Show(currentBoxType + currentBoxCoords + currentBoxIndex + isPath
                                         , this
                                         , clickedBox.BoxRec.X
                                         , clickedBox.BoxRec.Y - Globals.TopBarOffset + 17);
                                isBorder = false;
                            }
                            else
                            {
                                isPath     = "Is part of path:No\r\n";
                                clickedBox = new GridBox(e.X, e.Y, BoxType.Normal);
                                //show the tooltip
                                _tp.Show(currentBoxType + currentBoxCoords + currentBoxIndex + isPath
                                         , this
                                         , clickedBox.BoxRec.X - 10
                                         , clickedBox.BoxRec.Y - Globals.TopBarOffset + 12);
                                isBorder = false;
                            }
                        }
                    }
                }



                if (isBorder)
                {
                    _tp.ToolTipIcon = ToolTipIcon.Error;
                    //show the tooltip
                    _tp.Show(currentBoxType + currentBoxCoords + currentBoxIndex + isPath
                             , this
                             , e.X - 8
                             , e.Y - Globals.TopBarOffset + 14);
                }
            }
        }
Example #6
0
        private void main_form_MouseClick(object sender, MouseEventArgs e)
        {
            if (!menuPanel.Enabled)
            {
                return;
            }
            Point click_coords = new Point(e.X, e.Y);

            if (!Isvalid(click_coords) || e.Button != MouseButtons.Left || !overImage)
            {
                return;
            }

            if (rb_load.Checked)
            {
                for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
                {
                    for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                    {
                        if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1))))
                        {
                            m_lastBoxType   = m_rectangles[widthTrav][heightTrav].boxType;
                            m_lastBoxSelect = m_rectangles[widthTrav][heightTrav];
                            switch (m_lastBoxType)
                            {
                            case BoxType.Normal:
                                //loads++;
                                m_rectangles[widthTrav][heightTrav].SwitchLoad();
                                //isLoad[widthTrav, heightTrav] = 1;
                                //Invalidate();
                                break;

                            case BoxType.Load:
                                m_rectangles[widthTrav][heightTrav].SwitchLoad();
                                //isLoad[widthTrav, heightTrav] = 2;
                                //Invalidate();
                                break;

                                /*case BoxType.Wall:
                                 * case BoxType.Start:
                                 * case BoxType.End:
                                 *  break;
                                 */
                            }
                        }
                    }
                }
            }
            return;

            if (rb_start.Checked && nUD_AGVs.Value != 0)
            {
                if (nUD_AGVs.Value == 1)//Saves only the last Click position to place the Start (1 start exists)
                {
                    for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
                    {
                        for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                        {
                            if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.Start)
                            {
                                m_rectangles[widthTrav][heightTrav].SwitchEnd_StartToNormal();
                            }
                        }
                    }
                }
                else if (nUD_AGVs.Value > 1)  //Deletes the start with the smallest iX - iY coords and keeps the rest
                {
                    int starts_counter = 0;
                    int[,] starts_position = new int[2, Convert.ToInt32(nUD_AGVs.Value)];


                    for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
                    {
                        for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                        {
                            if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.Start)
                            {
                                starts_position[0, starts_counter] = widthTrav;
                                starts_position[1, starts_counter] = heightTrav;
                                starts_counter++;
                            }
                            if (starts_counter == nUD_AGVs.Value)
                            {
                                m_rectangles[starts_position[0, 0]][starts_position[1, 0]].SwitchEnd_StartToNormal();
                            }
                        }
                    }
                }

                //Converts the clicked box to Start point
                for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
                {
                    for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                    {
                        if (m_rectangles[widthTrav][heightTrav].boxRec.Contains(click_coords) &&
                            m_rectangles[widthTrav][heightTrav].boxType == BoxType.Normal)
                        {
                            m_rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals._BlockSide), heightTrav * Globals._BlockSide + Globals._TopBarOffset, BoxType.Start);
                        }
                    }
                }
            }
            //same for Stop
            if (rb_stop.Checked)
            {
                for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
                {
                    for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                    {
                        if (m_rectangles[widthTrav][heightTrav].boxType == BoxType.End)
                        {
                            m_rectangles[widthTrav][heightTrav].SwitchEnd_StartToNormal();//allow only one end point
                        }
                    }
                }
                for (int widthTrav = 0; widthTrav < Globals._WidthBlocks; widthTrav++)
                {
                    for (int heightTrav = 0; heightTrav < Globals._HeightBlocks; heightTrav++)
                    {
                        if (m_rectangles[widthTrav][heightTrav].boxRec.Contains(click_coords)
                            &&
                            m_rectangles[widthTrav][heightTrav].boxType == BoxType.Normal)
                        {
                            m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * Globals._BlockSide, heightTrav * Globals._BlockSide + Globals._TopBarOffset, BoxType.End);
                        }
                    }
                }
            }

            Invalidate();
        }
Example #7
0
        //function that resets all of the used objects so they are ready for reuse, preventing memory leaks
        private void FullyRestore()
        {
            if (tree_stats.Nodes[1].IsExpanded)
            {
                tree_stats.Nodes[1].Collapse();
            }

            tree_stats.Nodes[1].Nodes[0].Text = "CO: -";
            tree_stats.Nodes[1].Nodes[1].Text = "CO2: -";
            tree_stats.Nodes[1].Nodes[2].Text = "NOx: -";
            tree_stats.Nodes[1].Nodes[3].Text = "THC: -";
            tree_stats.Nodes[1].Nodes[4].Text = "Global Warming eq: -";

            _labeled_loads = 0;

            if (_onWhichStep != null)
            {
                Array.Clear(_onWhichStep, 0, _onWhichStep.GetLength(0));
            }

            if (_trappedStatus != null)
            {
                Array.Clear(_trappedStatus, 0, _trappedStatus.GetLength(0));
            }


            for (short i = 0; i < _AGVs.Count; i++)
            {
                _AGVs[i].KillIcon();
            }


            if (_importmap != null)
            {
                Array.Clear(_importmap, 0, _importmap.GetLength(0));
                Array.Clear(_importmap, 0, _importmap.GetLength(1));
            }

            if (BackgroundImage != null)
            {
                BackgroundImage = null;
            }

            StackTrace trace = new StackTrace();

            if (trace.GetFrame(1).GetMethod().Name != "Import")
            {
                Globals.SemiTransparency = false;
                _boxDefaultColor         = (Globals.SemiTransparency) ? Color.FromArgb(Globals.Opacity, Color.WhiteSmoke) : Color.WhiteSmoke;
            }

            _fromstart = new bool[Globals.MaximumAGVs];


            _startPos       = new List <GridPos>();
            _endPointCoords = new Point(-1, -1);
            _selectedColor  = Color.DarkGray;

            for (short i = 0; i < _startPos.Count(); i++)
            {
                _AGVs[i].JumpPoints = new List <GridPos>();
            }


            _searchGrid = new StaticGrid(Globals.WidthBlocks, Globals.HeightBlocks);

            _alwaysCross =
                aGVIndexToolStripMenuItem.Checked =
                    _beforeStart        =
                        _allowHighlight = true;

            _atLeastOneObstacle                  =
                _ifNoObstacles                   =
                    _never                       =
                        _imported                =
                            _calibrated          =
                                _isMouseDown     =
                                    _mapHasLoads = false;

            _useHalt = false;
            priorityRulesbetaToolStripMenuItem.Checked = false;

            _importedLayout = null;
            _jumpParam      = null;
            _paper          = null;
            _loads          = _posIndex = 0;

            _a
                  = _b
                  = new int();


            _AGVs = new List <Vehicle>();
            _CO2  = _CO = _NOx = _THC = _globalWarming = 0;

            _allowHighlight = true;
            highlightOverCurrentBoxToolStripMenuItem.Enabled = true;
            highlightOverCurrentBoxToolStripMenuItem.Checked = true;



            _isLoad     = new int[Globals.WidthBlocks, Globals.HeightBlocks];
            _rectangles = new GridBox[Globals.WidthBlocks][];
            for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
            {
                _rectangles[widthTrav] = new GridBox[Globals.HeightBlocks];
            }

            //jagged array has to be resetted like this
            for (var i = 0; i < Globals.WidthBlocks; i++)
            {
                for (var j = 0; j < Globals.HeightBlocks; j++)
                {
                    _rectangles[i][j] = new GridBox(i * Globals.BlockSide, j * Globals.BlockSide + Globals.TopBarOffset, BoxType.Normal);
                }
            }


            Initialization();

            main_form_Load(new object(), new EventArgs());

            for (short i = 0; i < _AGVs.Count; i++)
            {
                _AGVs[i].Status.Busy = false;
            }

            Globals.TimerStep = 0;
            timer0.Interval   = timer1.Interval = timer2.Interval = timer3.Interval = timer4.Interval = Globals.TimerInterval;


            nUD_AGVs.Value           = _AGVs.Count;
            tree_stats.Nodes[2].Text = "Loads remaining: ";
        }
Example #8
0
        //Initializes all the objects in main_form
        private void Initialization()
        {
            DiagonalMovement diagonalMovement = DiagonalMovement.Always;
            HeuristicMode    heuristicMode    = HeuristicMode.Manhattan;

            char[] delim = { ':', ' ', '(' };
            if (File.Exists("info.txt"))
            {
                if (Globals.FirstFormLoad)
                {
                    StreamReader reader = new StreamReader("info.txt");
                    try {
                        Globals.WidthBlocks              = Convert.ToInt32(reader.ReadLine().Split(delim)[1]);
                        Globals.HeightBlocks             = Convert.ToInt32(reader.ReadLine().Split(delim)[1]);
                        Globals.BlockSide                = Convert.ToInt32(reader.ReadLine().Split(delim)[1]);
                        diagonalMovement                 = (DiagonalMovement)Enum.Parse(typeof(DiagonalMovement), reader.ReadLine().Split(delim)[1]);
                        heuristicMode                    = (HeuristicMode)Enum.Parse(typeof(HeuristicMode), reader.ReadLine().Split(delim)[2]);
                        stepsToolStripMenuItem.Checked   = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        linesToolStripMenuItem.Checked   = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        dotsToolStripMenuItem.Checked    = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        bordersToolStripMenuItem.Checked = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        highlightOverCurrentBoxToolStripMenuItem.Checked = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                        aGVIndexToolStripMenuItem.Checked = Convert.ToBoolean(reader.ReadLine().Split(delim)[1]);
                    } catch {
                        MessageBox.Show("An error has occured while parsing the file to initialize form.\nPlease delete the file.");
                    }
                    reader.Close();
                }
                Globals.FirstFormLoad = false;
            }



            _isLoad = new int[Globals.WidthBlocks, Globals.HeightBlocks];
            //m_rectangels is an array of two 1d arrays
            //declares the length of the first 1d array
            _rectangles = new GridBox[Globals.WidthBlocks][];


            for (var widthTrav = 0; widthTrav < Globals.WidthBlocks; widthTrav++)
            {
                //declares the length of the seconds 1d array
                _rectangles[widthTrav] = new GridBox[Globals.HeightBlocks];
                for (var heightTrav = 0; heightTrav < Globals.HeightBlocks; heightTrav++)
                {
                    //dynamically add the gridboxes into the _rectangles.
                    //size of the m_rectangels is constantly increasing (while adding
                    //the gridbox values) until size=height or size = width.
                    if (_imported)   //this IF is executed as long as the user has imported a map of his choice
                    {
                        _rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals.BlockSide) + Globals.LeftBarOffset, heightTrav * Globals.BlockSide + Globals.TopBarOffset, _importmap[widthTrav, heightTrav]);
                        if (_importmap[widthTrav, heightTrav] == BoxType.Load)
                        {
                            _isLoad[widthTrav, heightTrav] = 1;
                            _loads++;
                        }
                    }
                    else
                    {
                        _rectangles[widthTrav][heightTrav] = new GridBox((widthTrav * Globals.BlockSide) + Globals.LeftBarOffset, heightTrav * Globals.BlockSide + Globals.TopBarOffset, BoxType.Normal);
                        _isLoad[widthTrav, heightTrav]     = 2;
                    }
                }
            }
            if (_imported)
            {
                _imported = false;
            }


            _searchGrid = new StaticGrid(Globals.WidthBlocks, Globals.HeightBlocks);
            _jumpParam  = new AStarParam(
                _searchGrid,
                Convert.ToSingle(Globals.AStarWeight),
                diagonalMovement,
                heuristicMode
                );

            ConfigUi();
        }