public Main_Form()
        {
            InitializeComponent();

            MinimumSize       = Size;
            panel_main.Width  = Width;
            panel_main.Height = Height;
            KeyPress         += Main_Form_KeyPress;
            PreviewKeyDown   += Main_Form_PreviewKeyDown;

            AutoScroll               = true;
            VerticalScroll.Enabled   = true;
            HorizontalScroll.Enabled = true;
            HorizontalScroll.Visible = true;
            VerticalScroll.Visible   = true;

            graph          = panel_main.CreateGraphics();
            mapPainter     = new MapPainter();
            dotDistributor = new DotDistrubutor(mapPainter);

            //Declare the menu items and the shortcut menu.
            MenuItem[] menuItems = new MenuItem[3];
            menuItems[0]        = new MenuItem("Zoom In");
            menuItems[1]        = new MenuItem("Zoom Out");
            menuItems[2]        = new MenuItem("Restore to default");
            contextMenu         = new ContextMenu(menuItems);
            menuItems[0].Click += new EventHandler((obj, evargs) => ZoomIn());
            menuItems[1].Click += new EventHandler((obj, evargs) => ZoomOut());
            menuItems[2].Click += new EventHandler((obj, evargs) => RestoreToDefault());

            infoForm         = new InfoForm(5);
            infoForm.Visible = true;
            infoForm.TopMost = true;
        }
        /// <summary>
        /// This method generates positions.
        /// basically, for each position, it can possibly contians 1 person.
        /// total number of people is defined by Setting.Propotion * Setting.Propotion
        /// Note that for each position, it is not necessary to contains a person.
        /// For each position, it has its own possibility that it contains a person.
        /// </summary>
        public void GenerateData(List <Dot> dots, MapPainter mapPainter)
        {
            var random = new Random();

            // If there is already raw data, then read the raw data from the disk.
            if (File.Exists("Data.txt"))
            {
                string data       = File.ReadAllText("Data.txt");
                var    splits     = data.Split('#');
                var    splitsList = splits.ToList();
                splitsList.RemoveAt(splitsList.Count - 1);
                foreach (string coordination in splitsList)
                {
                    var xy = coordination.Split(',');
                    GeneratePeople(dots, random, Convert.ToInt32(xy[0]), Convert.ToInt32(xy[1]), Convert.ToInt32(xy[2]));
                }
            }
            // Otherwise create raw data.
            else
            {
                // Raw data, Propotion * Propotion positions, each position can possibly contains 1 person.
                for (int i = 0; i < Setting.Propotion; i++)
                {
                    for (int j = 0; j < Setting.Propotion; j++)
                    {
                        for (int k = 0; k < mapPainter.Blocks.Count; k++)
                        {
                            bool inSideEindhoven     = false;
                            bool inSideSomeCityBlock = false;
                            var  polygonPoints       = new List <PointF>();
                            foreach (PointF point in mapPainter.Blocks[k].Coordinates)
                            {
                                polygonPoints.Add(new PointF(point.X * Setting.Propotion, point.Y * Setting.Propotion));
                            }
                            var checkPoint = new PointF(i, j);
                            // for now, we only give 2 different values, 1 or 0, to indicate whether this position is in the busy area.
                            // 1 means this dot is in busy area, 0 means not.
                            if (IsInPolygon(checkPoint, polygonPoints))
                            {
                                if (k != 0)
                                {
                                    inSideSomeCityBlock = true;
                                }
                                else
                                {
                                    inSideEindhoven = true;
                                }
                                if (inSideSomeCityBlock)
                                {
                                    File.AppendAllText("Data.txt", i + "," + j + "," + 1 + "#");
                                    GeneratePeople(dots, random, i, j, 1);
                                }
                                else if (inSideEindhoven)
                                {
                                    File.AppendAllText("Data.txt", i + "," + j + "," + 0 + "#");
                                    GeneratePeople(dots, random, i, j, 0);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
 public DotDistrubutor(MapPainter mapPainter)
 {
     _mapPainter = mapPainter;
     new DataGenerator().GenerateData(_dots, _mapPainter);
 }