public List <int> AllDensity = new List <int>();//读取所有密度值,用来在Assessform中判断可视化条形图大小 /// <summary> /// 计算所有站的列车密度 /// </summary> public Dictionary <List <string>, List <int> > GetTrainDensity(DataManager dmm)//列车密度表_返回形式(<站名,站名> -> <上行列车数,下行列车数>) { //调用方法实现PaintTool中str1的读取 完成密度值的计算 DataManager dm = dmm; PaintTool pt = new PaintTool(); PaintForm pf = new PaintForm(); int ix = dm.stationDrawList.Count; List <double> staMile = new List <double>(); for (int i = 0; i < ix; i++) { staMile.Add(dm.stationDrawList[i].totalMile); } pt.Branch(dm.stationDrawStringList, staMile, pf.bmp.Width, pf.bmp.Height); Dictionary <List <string>, List <int> > TrainDensity = new Dictionary <List <string>, List <int> >(); for (int jjj = 1; jjj < pt.str1.Count + 1; jjj++) { List <string> StationName = pt.str1[jjj];//读取各个线路的站名列表 for (int i = 0; i < StationName.Count - 1; i++) { List <string> Section = new List <string>();//读取区间名称 Section.Add(StationName[i]); Section.Add(StationName[i + 1]); List <int> Density = new List <int>(); int DensityUp = 0; int DensityDown = 0; foreach (Train aTrain in dm.UpTrainDic.Values)//上行列车 { for (int j = 0; j < aTrain.staList.Count - 1; j++) { if (StationName[i + 1] == aTrain.staList[j] && StationName[i] == aTrain.staList[j + 1])//判断列车经过车站顺序符合则区间列车密度加1 { DensityUp++; } } } Density.Add(DensityUp); AllDensity.Add(DensityUp); foreach (Train aTrain in dm.DownTrainDic.Values)//下行列车 { for (int j = 0; j < aTrain.staList.Count - 1; j++) { if (StationName[i] == aTrain.staList[j] && StationName[i + 1] == aTrain.staList[j + 1])//判断列车经过车站顺序符合则区间列车密度加1 { DensityDown++; } } } Density.Add(DensityDown); AllDensity.Add(DensityDown); TrainDensity.Add(Section, Density); } } return(TrainDensity); }
/// <summary> ///判断鼠标点位,生成选中列车和冲突点信息 /// </summary> private void TimetableViewCtrl_MouseMove(object sender, MouseEventArgs e) { pictureBox2.Size = new Size(TD_Width, TD_Height); float precision = 5f; int n = -1; int c = -1; if (checkBox1.Checked) { foreach (Train train in dm.upTrainList) { Graphics gs; gs = Graphics.FromImage(bmp); if (checkBox1.Checked) { for (int i = 0; i < ci.ConflictList.Count; i++) { if (ci.ConflictList[i].FrontTrain.Dir == "up") { c = PaintTool.PointInCircle(e.Location, ci.ConflictList[i].ConflictLocation, 5f); if (c == 0) { dataGridView1.Visible = false; this.pictureBox2.Refresh(); DrawPicture(); int k = pt.border2.Count; for (int i1 = 0; i1 < k; i1++) { int ii = i1 + 1; double total1 = pt.Mile1[ii].Last(); if (YesOrNo) { pt.ConflictDrawUp(gs, ConflictTable, dm.TrainDic, dm.stationStringList); } } ShowInfoTooltip(ci.ConflictList[i], e.Location); Pen SelectedPen = new Pen(Color.Blue, 2); if (YesOrNo) { gs.DrawEllipse(SelectedPen, ci.ConflictList[i].ConflictLocation.X - 2, ci.ConflictList[i].ConflictLocation.Y - 2, 5, 5); } break; } } } } if (c != 0) { dataGridView2.Visible = false; for (int i = 0; i < train.TrainPointList.Count; i++) { for (int s = 0; s < pt.str1.Count; s++) { for (int m = 0; m < train.staList.Count - 1; m++) { if ((train.TrainPointList[s].ContainsKey(train.staList[m])) && (train.TrainPointList[s].ContainsKey(train.staList[m + 1]))) { n = PaintTool.PointInLine(e.Location, train.TrainPointList[s][train.staList[m]][1], train.TrainPointList[s][train.staList[m + 1]][0], precision); if (n == 0) { break; } } } if (n == 0) { break; } } if (n == 0) { this.pictureBox2.Refresh(); DrawPicture(); if (checkBox1.Checked) { int k = pt.border2.Count; for (int i1 = 0; i1 < k; i1++) { int ii = i1 + 1; double total1 = pt.Mile1[ii].Last(); if (YesOrNo) { pt.ConflictDrawUp(gs, ConflictTable, dm.TrainDic, dm.stationStringList); } } } if (checkBox2.Checked) { int k = pt.border2.Count; for (int i1 = 0; i1 < k; i1++) { int ii = i1 + 1; double total1 = pt.Mile1[ii].Last(); if (YesOrNo) { pt.ConflictDrawDown(gs, ConflictTable, dm.TrainDic, dm.stationStringList); } } } ShowInfoTooltip(train, e.Location); Pen SelectedPen = new Pen(Color.Blue, 2); for (int j = 1; j < pt.str1.Count + 1; j++) { for (int p = 0; p < pt.str1[j].Count - 1; p++) { if (train.TrainPointList[j - 1].Count <= 1) { break; } if ((train.staList.Contains(pt.str1[j][p])) && (train.staList.Contains(pt.str1[j][p + 1]))) { gs.DrawLine(SelectedPen, train.TrainPointList[j - 1][pt.str1[j][p]][0], train.TrainPointList[j - 1][pt.str1[j][p + 1]][1]); } } for (int p = 1; p < pt.str1[j].Count - 1; p++) { if (train.TrainPointList[j - 1].Count <= 1) { break; } if (train.staList.Contains(pt.str1[j][p])) { gs.DrawLine(SelectedPen, train.TrainPointList[j - 1][pt.str1[j][p]][1], train.TrainPointList[j - 1][pt.str1[j][p]][0]); } } } break; } } } if ((c == 0) || (n == 0)) { break; } } Refresh(); } if (checkBox2.Checked) { foreach (Train train in dm.downTrainList) { Graphics gs; gs = Graphics.FromImage(bmp); if (checkBox2.Checked) { for (int i = 0; i < ci.ConflictList.Count; i++) { if (ci.ConflictList[i].FrontTrain.Dir == "down") { c = PaintTool.PointInCircle(e.Location, ci.ConflictList[i].ConflictLocation, 5f); if (c == 0) { dataGridView1.Visible = false; this.pictureBox2.Refresh(); DrawPicture(); int k = pt.border2.Count; for (int i1 = 0; i1 < k; i1++) { int ii = i1 + 1; double total1 = pt.Mile1[ii].Last(); if (YesOrNo) { pt.ConflictDrawDown(gs, ConflictTable, dm.TrainDic, dm.stationStringList); } } ShowInfoTooltip(ci.ConflictList[i], e.Location); Pen SelectedPen = new Pen(Color.Blue, 2); if (YesOrNo) { gs.DrawEllipse(SelectedPen, ci.ConflictList[i].ConflictLocation.X - 2, ci.ConflictList[i].ConflictLocation.Y - 2, 5, 5); } break; } } } } if (c != 0) { dataGridView2.Visible = false; for (int i = 0; i < train.TrainPointList.Count - 1; i++) { for (int s = 0; s < pt.str1.Count; s++) { for (int m = 0; m < train.staList.Count - 1; m++) { if ((train.TrainPointList[s].ContainsKey(train.staList[m])) && (train.TrainPointList[s].ContainsKey(train.staList[m + 1]))) { n = PaintTool.PointInLine(e.Location, train.TrainPointList[s][train.staList[m]][1], train.TrainPointList[s][train.staList[m + 1]][0], precision); if (n == 0) { break; } } } if (n == 0) { break; } } if (n == 0) { this.pictureBox2.Refresh(); DrawPicture(); if (checkBox1.Checked) { int k = pt.border2.Count; for (int i1 = 0; i1 < k; i1++) { int ii = i1 + 1; double total1 = pt.Mile1[ii].Last(); if (YesOrNo) { pt.ConflictDrawUp(gs, ConflictTable, dm.TrainDic, dm.stationStringList); } } } if (checkBox2.Checked) { int k = pt.border2.Count; for (int i1 = 0; i1 < k; i1++) { int ii = i1 + 1; double total1 = pt.Mile1[ii].Last(); if (YesOrNo) { pt.ConflictDrawDown(gs, ConflictTable, dm.TrainDic, dm.stationStringList); } } } ShowInfoTooltip(train, e.Location); Pen SelectedPen = new Pen(Color.Blue, 2); for (int j = 1; j < pt.str1.Count + 1; j++) { for (int p = 0; p < pt.str1[j].Count - 1; p++) { if (train.TrainPointList[j - 1].Count <= 0) { break; } if (train.staList.Contains(pt.str1[j][p]) && train.staList.Contains(pt.str1[j][p + 1])) { gs.DrawLine(SelectedPen, train.TrainPointList[j - 1][pt.str1[j][p]][1], train.TrainPointList[j - 1][pt.str1[j][p + 1]][0]); } } for (int p = 1; p < pt.str1[j].Count - 1; p++) { if (train.TrainPointList[j - 1].Count <= 1) { break; } if (train.staList.Contains(pt.str1[j][p])) { gs.DrawLine(SelectedPen, train.TrainPointList[j - 1][pt.str1[j][p]][1], train.TrainPointList[j - 1][pt.str1[j][p]][0]); } } } break; } } } if ((c == 0) || (n == 0)) { break; } } Refresh(); } }