Esempio n. 1
0
        private void BT_SaveOD_Click(object sender, EventArgs e)
        {
            ds = new DataSet();
            ds.ReadXml(strFileName);
            this.DGV_ODData.DataSource = ds.Tables[1];
            DGV_ODData.Show();

            ISC = SimContext.GetInstance();
            DataTable            dt = ds.Tables[1];
            DataColumnCollection dc = dt.Columns;

            try
            {
                dc.Add(new DataColumn("EntityID"));
                dc.Add(new DataColumn("iCarNum"));

                dc.Add(new DataColumn("iTimeStep"));
                dc.Add(new DataColumn("iPos"));
                dc.Add(new DataColumn("iSpeed"));
                int iMeters = SimSettings.iCellWidth;

                foreach (KeyValuePair <int, CarInfoDic> itemEntity in ISC.DataRecorder)
                {
                    foreach (KeyValuePair <int, CarTrack> item in itemEntity.Value)//carinfo Queue
                    {
                        //同一辆车在不同的位置
                        foreach (var itemCarInfo in item.Value)//车辆信息
                        {
                            DataRow dr = dt.NewRow();
                            dr["EntityID"]  = itemEntity.Key;
                            dr["iCarNum"]   = itemCarInfo.iCarNum;
                            dr["iTimeStep"] = itemCarInfo.iTimeStep;
                            dr["iPos"]      = itemCarInfo.iDrivedMileage * iMeters;
                            dr["iSpeed"]    = itemCarInfo.iSpeed * iMeters;
                            dt.Rows.Add(dr);
                        }
                    }
                }

                ds.WriteXml(strFileName);
                MessageBox.Show("保存成功");
            }
            catch (Exception eX)
            {
                MessageBox.Show("保存失败!" + eX.Message);
            }
        }
Esempio n. 2
0
        public override void DrawChart()
        {                                       //for updating
            CHART_SpaceTime.ChartAreas.Clear(); //.Add(new ChartArea("TimeSpace"));

            CHART_SpaceTime.ChartAreas.Add(new ChartArea("TimeSpace"));
            SeriesCollection dataSRC = CHART_SpaceTime.Series;
            ChartArea        st      = CHART_SpaceTime.ChartAreas[0];

            st.AxisX.MajorGrid.Enabled = false;
            st.AxisY.MajorGrid.Enabled = false;

            st.AxisY.Title = "速度(m/s)";
            st.AxisX.Title = "时间(s)";

            ISimContext ISC = SimContext.GetInstance();
            int         iSpeed;

            foreach (IDataRecorder <int, CarTrack> itemEntity in ISC.DataRecorder.Values)
            {
                foreach (KeyValuePair <int, CarTrack> item in itemEntity)//carinfo Queue
                {
                    Series dataI = dataSRC.FindByName(item.Key.ToString());

                    //同一辆车在不同的位置
                    if (dataI == null)
                    {
                        dataI             = new Series(item.Key.ToString());
                        dataI.MarkerStyle = MarkerStyle.Diamond;
                        dataI.ChartType   = SeriesChartType.Line;
                        dataSRC.Add(dataI);
                    }

                    foreach (var itemCarInfo in item.Value)//车辆信息
                    {
                        iSpeed = itemCarInfo.iSpeed * SimSettings.iCellWidth;
                        dataI.Points.AddXY(itemCarInfo.iTimeStep, iSpeed);
                    }
                }
            }

            CHART_SpaceTime.Show();
        }