PathWays.cs
5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.LinkLabel;
namespace CtuDeviceLib
{
public class PathWays
{
/// <summary>
/// 所有的路线
/// </summary>
static List<PathWay> _pathWays { get; set; }
public static bool Load(string linefilePath)
{
if (!File.Exists(linefilePath))
{
LogUtil.error($"未找到路线配置路径:{linefilePath}");
return false;
}
LogUtil.info($"加载路线配置:{linefilePath}");
string[] lines = File.ReadAllLines(linefilePath);
List<PathWay> _tempPathWays = new List<PathWay>();
for (int i = 1; i < lines.Length; i++)
{
string[] fields = lines[i].Split(',');
if (fields.Length < 5)
continue;
var pathway = new PathWay();
uint.TryParse(fields[0], out uint id);
pathway.Id = id;
pathway.Name = fields[1];
string[] paths = fields[2].Split('#');
pathway.Paths = new List<uint>();
foreach (string s in paths)
{
uint landId = uint.Parse(s);
pathway.Paths.Add(landId);
}
pathway.IsTwoWayLanes = bool.Parse(fields[3]);
string isLimitOneCtu = fields[4];
if (string.IsNullOrEmpty(isLimitOneCtu))
{
pathway.IsLimitOneCtu = false;
}
else
{
if (bool.TryParse(isLimitOneCtu, out bool isLimitCtu))
{
pathway.IsLimitOneCtu = isLimitCtu;
}
}
_tempPathWays.Add(pathway);
LogUtil.debug($"【加载路线:Id={pathway.Id},Name={pathway.Name}," +
$"【{(pathway.IsTwoWayLanes ? string.Join("<->", pathway.Paths) : string.Join(">", pathway.Paths))}】");
}
_pathWays = _tempPathWays.ToList();
NeighboringPathWays.Reload();
return true;
}
public static List<PathWay> GetAllPathWays()
{
return _pathWays;
}
public static PathWay GetPathWay(uint pointCode)
{
return _pathWays.Find(s => s.Paths.Contains(pointCode));
}
public static PathWay GetPathWay(uint pointCode1, uint pointCode2)
{
return _pathWays.Find(s => s.Paths.Contains(pointCode1) && s.Paths.Contains(pointCode2));
}
/// <summary>
/// 邻接点是否满足方向
/// </summary>
/// <param name="srcLand"></param>
/// <param name="dstLand"></param>
/// <returns></returns>
public static bool IsTwoWay(uint srcLand, uint dstLand)
{
if (_pathWays == null || _pathWays.Count == 0) return true;
var pathway = _pathWays.Find(s => s.Paths.Contains(srcLand) && s.Paths.Contains(dstLand));
if (pathway != null)
{
if (pathway.IsTwoWayLanes)
{
return true;
}
var srcIdx = pathway.Paths.IndexOf(srcLand);
var dstIdx = pathway.Paths.IndexOf(dstLand);
if (srcIdx < dstIdx)
{
return true;
}
}
return false;
}
public static bool IsInSamePath(uint land1, uint land2)
{
var pathway = _pathWays.Find(s => s.Paths.Contains(land1) && s.Paths.Contains(land2));
if (pathway != null)
{
return true;
}
else
return false;
}
/// <summary>
/// 该点所在路径是否限制单辆车
/// </summary>
/// <param name="land1"></param>
/// <returns></returns>
public static bool IsPathwayLimitOneCtu(uint land1)
{
var pathways = _pathWays.FindAll(s => s.Paths.Contains(land1));
if (pathways != null)
{
var find = pathways.Find(s => !s.IsLimitOneCtu);
if (find == null)//未找到不限制单辆车的路线
return true;
}
return false;
}
}
/// <summary>
/// 路线
/// </summary>
public class PathWay
{
/// <summary>
/// 路线编号
/// </summary>
public uint Id { get; set; }
/// <summary>
/// 路线名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 线路
/// 路标集合
/// </summary>
public List<uint> Paths { get; set; }
/// <summary>
/// 是否是双向路线
/// </summary>
public bool IsTwoWayLanes { get; set; }
/// <summary>
/// 是否限制单辆车在此路线
/// 死胡同
/// </summary>
public bool IsLimitOneCtu { get; set; } = false;
}
}