fix: 站台占用图生成器无法处理中文站台名

This commit is contained in:
denglihong2007
2026-01-01 01:28:49 +08:00
parent 08046e5a14
commit a25a047f14

View File

@@ -120,24 +120,42 @@ namespace CRSim.PlatformDiagram
}
}
// 1. 初始化字典(保持不变)
Dictionary<string, float> platformHeights = station.TrainStops
.Select(x => x.Platform)
.Where(p => p != null)
.Distinct()
.ToDictionary(p => p!, p => 0f);
// 2. 绘制底线(保持不变)
canvas.MoveTo(xBase, yBottom).LineTo(xEnd - TimelineExtLength, yBottom).Stroke();
// 3. 遍历所有站台,按索引分配高度
for (int i = 0; i < platformCount; i++)
{
string name = station.Platforms[i].Name;
if (double.TryParse(name, out double platformNumber))
var platform = station.Platforms[i];
string name = platform.Name;
// 计算当前站台的 Y 坐标高度
// 逻辑i 越大(后面的站台),高度越高
float currentY = yBottom + (platformCount - i - 1) * PlatformHeight;
// 直接存入字典,不再判断是否为数字
if (platformHeights.ContainsKey(name))
{
platformHeights[name] = yBottom + (platformCount - i - 1f) * PlatformHeight;
platformHeights[name] = currentY;
}
// 绘制站台分隔线
canvas.SetLineWidth(1f);
canvas.MoveTo(xBase, yBottom + (platformCount - i) * PlatformHeight)
.LineTo(xEnd - TimelineExtLength, yBottom + (platformCount - i) * PlatformHeight)
canvas.MoveTo(xBase, currentY)
.LineTo(xEnd - TimelineExtLength, currentY)
.Stroke();
}
canvas.SetLineWidth(1f);
canvas.MoveTo(xBase, yBottom + platformCount * PlatformHeight)
.LineTo(xEnd - TimelineExtLength, yBottom + platformCount * PlatformHeight)
.Stroke();
#endregion
#region