public void SetAxleSectionAccessLock() { Num = 0; foreach (var item in InSections) { //(item as Section).IsAccessLock = Info[Num]; Num++; } Dictionary <string, bool> RailSwitchAccessLock = new Dictionary <string, bool>(); foreach (var item in InRailSwitchs) { RailSwitch railswitch = item as RailSwitch; if (RailSwitchAccessLock.Keys.Contains(railswitch.SectionName)) { railswitch.IsAccessLock = RailSwitchAccessLock[railswitch.SectionName]; } else { railswitch.IsAccessLock = Info[Num]; RailSwitchAccessLock.Add(railswitch.SectionName, railswitch.IsAccessLock); Num++; } } }
public void SetSectionAxleState() { Num = 0; foreach (var item in InSections) { Section section = item as Section; if (section.AxleOccupy != Info[Num]) { section.AxleOccupy = Info[Num]; UpdateDevice(section); } Num++; } Dictionary <string, bool> RailSwitchAxleState = new Dictionary <string, bool>(); foreach (var item in InRailSwitchs) { RailSwitch railswitch = item as RailSwitch; if (RailSwitchAxleState.Keys.Contains(railswitch.SectionName)) { railswitch.AxleOccupy = RailSwitchAxleState[railswitch.SectionName]; UpdateDevice(railswitch); } else { if (railswitch.AxleOccupy != Info[Num]) { railswitch.AxleOccupy = Info[Num]; UpdateDevice(railswitch); } RailSwitchAxleState.Add(railswitch.SectionName, railswitch.AxleOccupy); Num++; } } }
public GraphicElement UPdateTrainPosByOffset(int type, int id, byte dir, double offset) { Dir = dir; this.Dispatcher.Invoke(() => { nowid = id; nowtype = type; GraphicElement nowSection = Elements.Find((线路绘图工具.GraphicElement item) => { if (type == (byte)DeviceType.区段 && item is Section) { Section sc = item as Section; return(sc.ID == id); } else if (type == (byte)DeviceType.道岔 && item is RailSwitch) { RailSwitch rs = item as RailSwitch; return(rs.ID == id); } else { return(false); } }); UpdatePos(nowSection, dir, offset); if (Res != null && Res.Count != 0) { ATSRoute OpenRoute = null; List <ATSRoute> routes = Res[0].Routes; OpenRoute = routes.Find((ATSRoute r) => { foreach (Device item in r.IncomingSections) { if (item == nowSection) { return(true); } } return(false); }); this.OpenRoute = OpenRoute; } NowSection = nowSection; return(NowSection); }); return(null); }
private void SetRailSwithPosition() { Num = 0; foreach (var item in InRailSwitchs) { RailSwitch rail = item as RailSwitch; //rail.IsPositionNormal = Info[Num]; //Num++; //rail.IsPositionReverse = Info[Num]; //Num++; rail.State = Info[Num]?RailSwitch.SwitchPosition.PosNormal:RailSwitch.SwitchPosition.PosNeither; Num++; rail.State = Info[Num] ? RailSwitch.SwitchPosition.PosReverse : RailSwitch.SwitchPosition.PosNeither; Num++; } }
//完全特殊处理的 void CalLen(线路绘图工具.GraphicElement Element) { if (Element is Section) { Section sc = Element as Section; double fk = 0, nk = 0;//之前的斜率和当前斜率 foreach (Graphic g in sc.Graphics) { Line l = g as Line; nk = (l.Pt1.Y - l.Pt0.Y) / (l.Pt1.X - l.Pt0.X); if (fk == nk) { sc.Lens[0] += CalDisOf2Point(l.Pt1, l.Pt0); } else { sc.Lens[1] += CalDisOf2Point(l.Pt1, l.Pt0); } fk = nk; } } else if (Element is RailSwitch) { // 直、定、反 RailSwitch rs = Element as RailSwitch; foreach (int i in rs.SectionIndexList[0]) { Line l = rs.Graphics[i] as Line; rs.Lens[0] += CalDisOf2Point(l.Pt0, l.Pt1); } foreach (int i in rs.SectionIndexList[1]) { Line l = rs.Graphics[i] as Line; rs.Lens[1] += CalDisOf2Point(l.Pt0, l.Pt1); } foreach (int i in rs.SectionIndexList[2]) { Line l = rs.Graphics[i] as Line; rs.Lens[2] += CalDisOf2Point(l.Pt0, l.Pt1); } Line l1 = rs.Graphics[rs.SectionIndexList[0].Last()] as Line; Line l2 = rs.Graphics[rs.SectionIndexList[1].First()] as Line; Line l3 = rs.Graphics[rs.SectionIndexList[2].First()] as Line; rs.Lens[1] += CalDisOf2Point(l1.Pt1, l2.Pt0); rs.Lens[2] += CalDisOf2Point(l1.Pt1, l3.Pt0); } }
/// <summary> /// 计算距离 /// </summary> void InitDistance() { foreach (ATSRoute route in Routes) { int sk = 0; foreach (Device d in route.InSections) { if (d is Section) { Section s = d as Section; route.Distance += s.Distance; } else if (d is RailSwitch) { RailSwitch rs = d as RailSwitch; route.Distance += route.SwitchPositions[sk++] == RailSwitch.SwitchPosition.PosNormal ? rs.NormalDistance : rs.ReverseDistance; } } } }
TrainMes TrainMesFactory(GraphicElement ge, ZC2ATS info) { TrainMes mes = new TrainMes(); if (ge is Section) { Section sc = ge as Section; mes.CBIPos = sc == null ? null : sc.StationID.ToString(); } else { RailSwitch rs = ge as RailSwitch; mes.CBIPos = rs == null ? null : rs.StationID.ToString(); } mes.RunMode = "AM"; mes.Speed = "80"; mes.Destnation = "无"; mes.IsPlanTrain = "否"; mes.TrainPos = ge == null ? "无" : ge.Name + " " + info.Offset.ToString(); return(mes); }
//internal void CheckSectionSwitches() //{ // for (int i = 0; i < Elements.Count; i++) // { // if (Elements[i] is RailSwitch) // { // RailSwitch rs_1 = Elements[i] as RailSwitch; // for (int j = i + 1; j < Elements.Count; j++) // { // if (Elements[j] is RailSwitch) // { // RailSwitch rs_2 = Elements[j] as RailSwitch; // if (rs_1.StationID == rs_2.StationID && rs_1.SectionID == rs_2.SectionID) // { // CheckSectionSwitches(rs_1, rs_2); // } // } // } // } // } //} //private void CheckSectionSwitches(RailSwitch rs_1, RailSwitch rs_2) //{ // if (rs_1.IsLeft != rs_2.IsLeft) // { // if (rs_1.IsLeft) // { // rs_1.InsuLine = null; // rs_1.InvalidateVisual(); // } // if (rs_2.IsLeft) // { // rs_2.InsuLine = null; // rs_2.InvalidateVisual(); // } // } //} internal void CheckSectionSwitches() { for (int i = 0; i < Elements.Count; i++) { if (Elements[i] is RailSwitch) { RailSwitch rs_1 = Elements[i] as RailSwitch; for (int j = i + 1; j < Elements.Count; j++) { if (Elements[j] is RailSwitch) { RailSwitch rs_2 = Elements[j] as RailSwitch; if (rs_1.StationID == rs_2.StationID && rs_1.SectionID == rs_2.SectionID) { CheckSectionSwitches(rs_1, rs_2); } } } } } }
private void CheckSectionSwitches(RailSwitch rs_1, RailSwitch rs_2) { if (rs_1.IsLeft != rs_2.IsLeft && rs_1.IsUp == rs_2.IsUp) { if (rs_1.NNSwitch == null && rs_2.NNSwitch == null) { rs_1.NNSwitch = rs_2; rs_2.NNSwitch = rs_1; // 处理绝缘节 if (rs_1.IsLeft) { rs_1.InsuLine = null; } if (rs_2.IsLeft) { rs_2.InsuLine = null; } } } else { List <Point> nsPoints = new List <Point>(); List <Point> sPoints = new List <Point>(); if (rs_1.IsLeft) { rs_1.GetLeftPoints(nsPoints); rs_2.GetRightPoints(sPoints); if (Line.IsPointsMatch(nsPoints[1], sPoints[0], 0.1)) { rs_2.RSSwitch = rs_1; } } } }
/// <summary> /// 更新方向向量,当前的的Element /// </summary> /// <param name="item"></param> /// <param name="dir"></param> /// <returns></returns> void UpdatePos(线路绘图工具.GraphicElement item, byte dir, double offset) { Dir = dir; if (item != null) { Point origin = new Point(Canvas.GetLeft(item), Canvas.GetTop(item)); Log4ATS.Info(origin.X + " " + origin.Y + " " + offset); Vector LineDirVector = new Vector(); Canvas.SetZIndex(this, -1); #region 直道 if (item is Section) { Section s = item as Section; if (s.DirVectorList.Count == 0) { s.CreateDirVectors(); } //左走 if (dir == (byte)(TrainDir.左行)) { if (true) //if (preid!=nowid||pretype!=nowtype) { //D 0斜 1直 线路绘图工具.Line l = s.Graphics.Last() as 线路绘图工具.Line; StartPoint = l.Pt1; DirVector[0] = CalDirUnitVector(l.Pt1, l.Pt0); l = s.Graphics.First() as 线路绘图工具.Line; DirVector[1] = CalDirUnitVector(l.Pt1, l.Pt0); k = (s.Lens[0] + s.Lens[1]) / s.Distance; preid = nowid; pretype = nowtype; } offset *= k; //l 0直道长度 1斜线长度 if (offset > s.Lens[1]) { LineDirVector = s.DirVectorList.First(); double len = offset - s.Lens[1]; double x = len * DirVector[1].X + s.Lens[1] * DirVector[0].X + StartPoint.X + origin.X; double y = len * DirVector[1].Y + s.Lens[1] * DirVector[0].Y + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { LineDirVector = s.DirVectorList.Last(); double x = offset * DirVector[0].X + StartPoint.X + origin.X; double y = offset * DirVector[0].Y + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } else//右行 { if (true) //if (preid != nowid || pretype != nowtype) { //D 0斜 1直 线路绘图工具.Line l = s.Graphics.First() as 线路绘图工具.Line; StartPoint = l.Pt0; DirVector[0] = CalDirUnitVector(l.Pt0, l.Pt1); l = s.Graphics.Last() as 线路绘图工具.Line; DirVector[1] = CalDirUnitVector(l.Pt0, l.Pt1); k = (s.Lens[0] + s.Lens[1]) / s.Distance; preid = nowid; pretype = nowtype; } offset *= k; //l 0直道长度 1斜线长度 if (offset > s.Lens[0]) { LineDirVector = s.DirVectorList.Last(); double len = offset - s.Lens[0]; double x = len * DirVector[1].X + s.Lens[0] * DirVector[0].X + StartPoint.X + origin.X; double y = len * DirVector[1].Y + s.Lens[0] * DirVector[0].Y + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { LineDirVector = s.DirVectorList.First(); double x = offset * DirVector[0].X + StartPoint.X + origin.X; double y = offset * DirVector[0].Y + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } } #endregion #region 弯道 else if (item is RailSwitch) { RailSwitch rs = item as RailSwitch; if (rs.DirVectorList.Count == 0) { rs.CreateDirVectors(); } if (rs.Position == RailSwitch.SwitchPosition.PosNormal) { LineDirVector = rs.DirVectorList.First(); if (dir == (byte)(TrainDir.左行)) { //左行驶 //if (preid != nowid || pretype != nowtype) if (true) { //定 左 k = (rs.Lens[0] + rs.Lens[1]) / rs.NormalDistance; if (!rs.IsLeft) { 线路绘图工具.Line l = rs.Graphics.First() as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt1, l.Pt0); StartPoint = (rs.Graphics[rs.SectionIndexList[1].Last()] as 线路绘图工具.Line).Pt1; DirVector[1] = DirVector[0];//因为直线所以简化处理 } else { 线路绘图工具.Line l = rs.Graphics.First() as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt0, l.Pt1); StartPoint = (rs.Graphics[rs.SectionIndexList[0].First()] as 线路绘图工具.Line).Pt0; DirVector[1] = DirVector[0]; } preid = nowid; pretype = nowtype; } offset *= k; double x = DirVector[0].X * offset + StartPoint.X + origin.X; double y = DirVector[0].Y * offset + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { //右行驶 if (true) //if (preid != nowid || pretype != nowtype) { //定右 k = (rs.Lens[0] + rs.Lens[1]) / rs.NormalDistance; if (!rs.IsLeft) { StartPoint = (rs.Graphics[rs.SectionIndexList[0].First()] as 线路绘图工具.Line).Pt0; 线路绘图工具.Line l = rs.Graphics.First() as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt0, l.Pt1); DirVector[1] = DirVector[0];//因为直线所以简化处理 } else { StartPoint = (rs.Graphics[rs.SectionIndexList[1].Last()] as 线路绘图工具.Line).Pt1; 线路绘图工具.Line l = rs.Graphics.First() as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt1, l.Pt0); DirVector[1] = DirVector[0];//因为直线所以简化处理 } preid = nowid; pretype = nowtype; } offset *= k; double x = DirVector[0].X * offset + StartPoint.X + origin.X; double y = DirVector[0].Y * offset + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } else { //反位左行 if (dir == (byte)(TrainDir.左行)) { //if (preid != nowid || pretype != nowtype) if (true) { if (!rs.IsLeft) { 线路绘图工具.Line l = rs.Graphics[rs.SectionIndexList[2].Last()] as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt1, l.Pt0); StartPoint = l.Pt1; l = rs.Graphics[rs.SectionIndexList[0].First()] as 线路绘图工具.Line; DirVector[1] = CalDirUnitVector(l.Pt1, l.Pt0); } else { 线路绘图工具.Line l = rs.Graphics[rs.SectionIndexList[0].First()] as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt0, l.Pt1); StartPoint = l.Pt0; l = rs.Graphics[rs.SectionIndexList[2].Last()] as 线路绘图工具.Line; DirVector[1] = CalDirUnitVector(l.Pt0, l.Pt1); } //直 定 反 k = (rs.Lens[0] + rs.Lens[2]) / rs.ReverseDistance; preid = nowid; pretype = nowtype; } offset *= k; if (!rs.IsLeft) { if (offset > rs.Lens[2]) { LineDirVector = rs.DirVectorList[0]; double len = offset - rs.Lens[2]; double x = DirVector[0].X * rs.Lens[2] + DirVector[1].X * len + StartPoint.X + origin.X; double y = DirVector[0].Y * rs.Lens[2] + DirVector[1].Y * len + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { LineDirVector = rs.DirVectorList[2]; double x = DirVector[0].X * offset + StartPoint.X + origin.X; double y = DirVector[0].Y * offset + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } else { if (offset > rs.Lens[0]) { LineDirVector = rs.DirVectorList[2]; double len = offset - rs.Lens[0]; double x = DirVector[0].X * rs.Lens[0] + DirVector[1].X * len + StartPoint.X + origin.X; double y = DirVector[0].Y * rs.Lens[0] + DirVector[1].Y * len + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { LineDirVector = rs.DirVectorList[0]; double x = DirVector[0].X * offset + StartPoint.X + origin.X; double y = DirVector[0].Y * offset + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } } else { //反位右行 if (true) //if (preid != nowid || pretype != nowtype) { if (!rs.IsLeft) { 线路绘图工具.Line l = rs.Graphics[rs.SectionIndexList[0].First()] as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt0, l.Pt1); StartPoint = l.Pt0; l = rs.Graphics[rs.SectionIndexList[2].Last()] as 线路绘图工具.Line; DirVector[1] = CalDirUnitVector(l.Pt0, l.Pt1); } else { 线路绘图工具.Line l = rs.Graphics[rs.SectionIndexList[2].Last()] as 线路绘图工具.Line; DirVector[0] = CalDirUnitVector(l.Pt1, l.Pt0); StartPoint = l.Pt1; l = rs.Graphics[rs.SectionIndexList[0].Last()] as 线路绘图工具.Line; DirVector[1] = CalDirUnitVector(l.Pt1, l.Pt0); } //直 定 反 k = (rs.Lens[0] + rs.Lens[2]) / rs.ReverseDistance; preid = nowid; pretype = nowtype; } offset *= k; if (!rs.IsLeft) { if (offset > rs.Lens[0]) { LineDirVector = rs.DirVectorList[2]; double len = offset - rs.Lens[0]; double x = DirVector[0].X * rs.Lens[0] + len * DirVector[1].X + StartPoint.X + origin.X; double y = DirVector[0].Y * rs.Lens[0] + len * DirVector[1].Y + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { LineDirVector = rs.DirVectorList[0]; double x = DirVector[0].X * offset + StartPoint.X + origin.X; double y = DirVector[0].Y * offset + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } else { if (offset > rs.Lens[2]) { LineDirVector = rs.DirVectorList[0]; double len = offset - rs.Lens[2]; double x = DirVector[0].X * rs.Lens[2] + len * DirVector[1].X + StartPoint.X + origin.X; double y = DirVector[0].Y * rs.Lens[2] + len * DirVector[1].Y + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } else { LineDirVector = rs.DirVectorList[2]; double x = DirVector[0].X * offset + StartPoint.X + origin.X; double y = DirVector[0].Y * offset + StartPoint.Y + origin.Y; UpdateTrainPosByXY(new Point(x, y)); } } } } } #endregion if (item is RailSwitch) { RailSwitch rs = item as RailSwitch; if (rs.DirVectorList.Count == 0) { rs.CreateDefaultGraphic(); } if (!rs.IsLeft) { } else { LineDirVector.Negate(); } } this.TrainRotate(LineDirVector, dir); } }
/// <summary> /// 序列化装包函数 /// </summary> /// <param name="Clicks"></param> void SerilizePackage(List <Object> Clicks) { ATS2CBICommand atsCommand = new ATS2CBICommand(); switch (Clicks.Count) { case 1: { //to do 扣车代码 } break; case 2: { //string在前,设备id在后 if (Clicks[1] is string) { Object obj = Clicks[0]; Clicks[0] = Clicks[1]; Clicks[1] = obj; } } break; default: break; } BuildHandleMes(Clicks); foreach (var item in Clicks) { if (item is Device) { Device de = item as Device; atsCommand.StationID = (UInt16)de.StationID; break; } } atsCommand.DeviceNum = (UInt16)Clicks.Count; atsCommand.DeviceQueue = new byte[8]; int k = 0; foreach (var item in Clicks) { if (Clicks[k / 2] is Device) { if (Clicks[k / 2] is SmallButton) { atsCommand.DeviceNum = 2; SmallButton sb = Clicks[k / 2] as SmallButton; atsCommand.DeviceQueue[k++] = (byte)sb.ButtonState; atsCommand.DeviceQueue[k++] = (byte)sb.TypeID; atsCommand.DeviceQueue[k++] = (byte)sb.ID; atsCommand.DeviceQueue[k++] = 1; } else { atsCommand.DeviceQueue[k] = (byte)(Clicks[k / 2] as Device).ID; k++; if (Clicks[k / 2] is Signal) { atsCommand.DeviceQueue[k] = (byte)命令类型.列车按钮; } else if (Clicks[k / 2] is RailSwitch) { atsCommand.DeviceQueue[k] = (byte)命令类型.道岔按钮; } else if (Clicks[k / 2] is Section) { atsCommand.DeviceQueue[k] = (byte)命令类型.区段按钮; } else if (Clicks[k / 2] is RelayButton) { atsCommand.DeviceQueue[k] = (byte)命令类型.功能按钮; } else if (Clicks[k / 2] is SmallButton) { atsCommand.DeviceQueue[k] = (byte)(Clicks[k / 2] as SmallButton).TypeID; } k++; } } else if (Clicks[k / 2] is string) { string s = Clicks[k / 2].ToString(); foreach (byte bt in Enum.GetValues(typeof(功能按钮))) { if (Enum.GetName(typeof(功能按钮), bt) == s) { atsCommand.DeviceQueue[k++] = bt; break; } } atsCommand.DeviceQueue[k++] = (byte)命令类型.功能按钮; } } if (Clicks.Count > 1 && (Clicks[0] as string == "解封" || Clicks[0] as string == "封锁") && Clicks[1] is RailSwitch) { RailSwitch rs = Clicks[1] as RailSwitch; atsCommand.DeviceQueue[2] = (byte)rs.SectionID; atsCommand.DeviceQueue[3] = (byte)命令类型.区段按钮; } byte[] bytes = pacTool.Serialize(atsCommand); bool IsAdd = false; while (!IsAdd) { IsAdd = CBIMes.TryAdd(bytes); } }