Example #1
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            buttonStart.Enabled = false;
            buttonCreate.Enabled = false;
            int stationCount = Convert.ToInt32(numericStationCount.Value);
            int trainCount = Convert.ToInt32(numericTrainCount.Value);
            // пример =) new System.Threading.Thread(delegate() { MyMetod(2, 2); }).Start();
            #region Потоки

            for (int i = 0; i < trainCount; i++)
            {
                int t1, t2;
                var rend1 = new Random(System.DateTime.Now.Millisecond);
                bool flag = true;
                if (checkBoxRend.Checked)
                {
                    while (flag)
                    {
                        flag = true;
                        t1 = rend1.Next(0, stationCount);
                        t2 = rend1.Next(0, stationCount);
                        if (t1 != t2)
                        {
                            listTrain.Add(new Train(tops[t1], tops[t2]));
                            listTrain[i].GetPath(tops, rebro);
                            //listTrain[i].MyEvent +=new MyDel(Handler);
                            listTrain[i].SetTrainName(i.ToString(CultureInfo.InvariantCulture));
                            flag = false;
                        }
                    }
                }
                else
                {
                    t1 = Convert.ToInt32(dataGridViewTrain.Rows[i].Cells[1].Value);
                    t2 = Convert.ToInt32(dataGridViewTrain.Rows[i].Cells[2].Value);
                    if (t1!=t2)
                    {
                        listTrain.Add(new Train(tops[t1], tops[t2]));
                        listTrain[i].GetPath(tops, rebro);
                        //listTrain[i].MyEvent += new MyDel(Handler);
                        listTrain[i].SetTrainName(i.ToString(CultureInfo.InvariantCulture));
                    }
                }

            }
            Dispatcher dis=new Dispatcher(listTrain);
            dis.stopThear += new MyDel(Handler);
            foreach (var t in listTrain)
            {
                t.MyDispatcher = dis;
            }
            DisThread = new Thread(dis.Function);
            DisThread.Start();
            #endregion
            graphics = new GraphicsMy(this, ListStation, rebro,listTrain);
            //graphics.RenderingTest();
            threadGraphic = new Thread(graphics.Refresh);
            threadGraphic.Name = "Graphic";
            //graphics.stopThreads += new MyDelTr(StopThreads);
            threadGraphic.Start();
        }
Example #2
0
        private void Create_Click(object sender, EventArgs e)
        {
            ListStation.Clear();
            listTrain.Clear();
            threads.Clear();
            int stationCount = Convert.ToInt32(numericStationCount.Value);
            int trainCount = Convert.ToInt32(numericTrainCount.Value);
            double alfa = 0;
            double stepAlfa = 360 / stationCount * Math.PI / 180;
            int A_widht = 370;
            int B_height = 220;
            double radius;
            tops = new PointG[stationCount];
            for (int i = 0; i < stationCount; i++)
            {
                radius = B_height * A_widht /
                         Math.Sqrt(B_height * B_height * Math.Cos(alfa) * Math.Cos(alfa) +
                                   A_widht * A_widht * Math.Sin(alfa) * Math.Sin(alfa));
                ListStation.Add(new Station(new Point(Convert.ToInt32(radius * Math.Cos(alfa)), Convert.ToInt32(-radius * Math.Sin(alfa))),
                    i.ToString()));

                tops[i] = new PointG(999, false, (i).ToString(CultureInfo.InvariantCulture),
                                     Convert.ToInt32(radius * Math.Cos(alfa)), Convert.ToInt32(-radius * Math.Sin(alfa)));
                alfa += stepAlfa;
            }
            //dataGridViewTrain.Rows.Add(trainCount);
            dataGridViewTrain.Rows.Clear();
            ((DataGridViewComboBoxColumn)dataGridViewTrain.Columns[1]).Items.Clear();
            ((DataGridViewComboBoxColumn)dataGridViewTrain.Columns[2]).Items.Clear();
            //var cell = new DataGridViewComboBoxCell();
            //GridItemCollection It;
            for (int i = 0; i < stationCount; i++)
            {
                ((DataGridViewComboBoxColumn)dataGridViewTrain.Columns[1]).Items.Add(ListStation[i].name);
                ((DataGridViewComboBoxColumn)dataGridViewTrain.Columns[2]).Items.Add(ListStation[i].name);
            }
            for (int i = 0; i < trainCount; i++)
            {

                //((DataGridViewComboBoxColumn)dataGridViewTrain.Columns[1]).Items.Add(ListStation[i].name);
                //((DataGridViewComboBoxColumn)dataGridViewTrain.Columns[2]).Items.Add(ListStation[i].name);
                dataGridViewTrain.Rows.Add();
                dataGridViewTrain[0, i].Value = i + 1;
            }

            GenerateGraph();
            graphics = new GraphicsMy(this, ListStation, rebro, listTrain);
            graphics.RenderingTest();
        }