【半自动闭塞、复原逻辑代码】

This commit is contained in:
weizhihong 2022-05-05 10:52:50 +08:00
parent d1837c50ec
commit f835731df5
4 changed files with 207 additions and 31 deletions

View File

@ -853,7 +853,15 @@ public class Operation {
/**
* 发辅助按钮操作
*/
ASSIST_PRESS_DELIVER_ASSIST
ASSIST_PRESS_DELIVER_ASSIST,
/**
* 按下闭塞按钮
*/
ASSIST_PRESS_BLOCK,
/**
* 按下复原按钮
*/
ASSIST_PRESS_RESTORE
}
/**

View File

@ -78,4 +78,30 @@ public class StationDirectionOperateHandler {
stationDirectionService.changeButtonAspect(simulation, stationCode, labelEnum, StationDirection.ButtonTypeEnum.DELIVER_ASSIST
, Boolean.TRUE, stationDirectionService.turnAssistValid, stationDirectionService.deliverAssistThen);
}
/**
* 点击闭塞按钮只做按钮的按下操作
*
* @param simulation 仿真数据
* @param stationCode 车站编码
* @param labelEnum 运行方向
*/
@OperateHandlerMapping(type = Operation.Type.ASSIST_PRESS_BLOCK)
public void pressBlockBtn(Simulation simulation, String stationCode, DirectionLabelEnum labelEnum) {
stationDirectionService.changeButtonAspect(simulation, stationCode, labelEnum, StationDirection.ButtonTypeEnum.BLOCK
, Boolean.TRUE, null, null);
}
/**
* 按下复原按钮
*
* @param simulation 仿真数据
* @param stationCode 车站编码
* @param labelEnum 运行方向
*/
@OperateHandlerMapping(type = Operation.Type.ASSIST_PRESS_RESTORE)
public void pressRestoreBtn(Simulation simulation, String stationCode, DirectionLabelEnum labelEnum) {
stationDirectionService.changeButtonAspect(simulation, stationCode, labelEnum, StationDirection.ButtonTypeEnum.BLOCK
, Boolean.TRUE, null, stationDirectionService.turnRestoreThen);
}
}

View File

@ -109,7 +109,6 @@ public class StationDirectionService {
}
};
/**
* 发辅助按钮操作校验
*/
@ -119,6 +118,7 @@ public class StationDirectionService {
}
};
/**
* 总辅助后续操作
*/
@ -151,6 +151,48 @@ public class StationDirectionService {
stationDirection.getRemain().set(StationDirection.DEFAULT_DELIVER_DELAY_TIME);
};
/**
* 复原按钮操作验证
*/
public ButtonValidInterface turnRestoreValid = (simulation, stationDirection) -> {
};
/**
* 恢复按钮后续操作
*/
public ButtonThenInterface turnRestoreThen = (simulation, stationDirection) -> {
try {
// 只有半自动闭塞接车方向可以操作
if (StationDirection.DirectionRunModel.S.equals(stationDirection.getRunModel())
&& StationDirection.ReceiveAndDeliverModel.R.equals(stationDirection.getRunStatus())) {
// 将本方向接发车状态恢复
stationDirection.reset();
// 接车进路方向朝向
boolean right = stationDirection.getReceiveRouteList().stream().findFirst().stream().anyMatch(Route::isRight);
// 寻找车站位置用于获取邻站
List<Station> stationList = simulation.getRepository().getStationList();
int index = stationList.indexOf(stationDirection.getStation());
// 范围内
if (index != 0 && index != stationList.size() - 1) {
index = right ? index + 1 : index - 1;
Station adjacentStation = stationList.get(index);
if (adjacentStation != null) {
adjacentStation.getStationDirectionMap().values()
.stream()
.filter(sd -> StationDirection.DirectionRunModel.S.equals(sd.getRunModel()))
.filter(sd -> sd.getDeliverRouteList().stream().anyMatch(route -> route.isRight() == right))
.forEach(sd -> sd.reset());
}
}
}
} finally {
// 恢复完成后恢复按钮需要自动弹起
stationDirection.setRestoreStatus(false);
}
};
/**
* 获取当前车站实体
*

View File

@ -49,6 +49,11 @@ public class StationDirection extends MapNamedElement {
*/
private AtomicInteger remain = new AtomicInteger(0);
/**
* 所属模式自动闭塞半自动闭塞
*/
private DirectionRunModel runModel;
/**
* 处于接发状态
*/
@ -94,6 +99,16 @@ public class StationDirection extends MapNamedElement {
*/
private boolean deliverAssistStatus;
/**
* 闭塞
*/
private boolean blockStatus;
/**
* 恢复
*/
private boolean restoreStatus;
/**
* 接车进路以指示灯为起点的进路
*/
@ -109,10 +124,10 @@ public class StationDirection extends MapNamedElement {
*/
private List<Section> sectionList;
public StationDirection(String code, String name, DirectionLabelEnum labelEnum) {
this(code, name);
this.labelEnum = labelEnum;
this.runModel = getDefaultDirectionRunModel();
this.runStatus = this.getDefaultReceiveAndDeliver();
}
@ -134,34 +149,12 @@ public class StationDirection extends MapNamedElement {
* 刷新接发车灯颜色
*/
public void refreshAspectStatus() {
// 进路锁闭判断接发状态
// 接车进路锁闭
boolean receiveRouteBlock = this.receiveRouteList.stream().anyMatch(Route::isLock);
// 发车进路锁闭
boolean deliverRouteBlock = this.deliverRouteList.stream().anyMatch(Route::isLock);
// 接发状态
this.runStatus = receiveRouteBlock ? ReceiveAndDeliverModel.R : this.runStatus;
this.runStatus = deliverRouteBlock ? ReceiveAndDeliverModel.D : this.runStatus;
// 接车进路锁闭亮红灯否则默认
IndicatorStatusEnum receiveAspect;
// 发车进路锁闭亮红灯否则默认
IndicatorStatusEnum deliverAspect;
// 进路区段占用判断点灯颜色
if (ReceiveAndDeliverModel.R.equals(this.runStatus)) {
deliverAspect = IndicatorStatusEnum.F;
// 接车进路锁闭
receiveAspect = judgeSignalLock() ? IndicatorStatusEnum.O : IndicatorStatusEnum.F;
} else if (ReceiveAndDeliverModel.D.equals(this.runStatus)) {
receiveAspect = IndicatorStatusEnum.F;
// 发车进路锁闭
deliverAspect = judgeSignalLock() ? IndicatorStatusEnum.O : IndicatorStatusEnum.F;
} else {
receiveAspect = this.receiveAspect;
deliverAspect = this.receiveAspect;
// 自动模式
if (DirectionRunModel.A.equals(this.runModel)) {
automaticModelAspectStatus();
} else { // 半自动
semiAutomaticModelAspectStatus();
}
// 赋值点灯信息
this.deliverAspect = deliverAspect;
this.receiveAspect = receiveAspect;
}
/**
@ -218,6 +211,14 @@ public class StationDirection extends MapNamedElement {
case MAIN_ASSIST:
this.mainAssistStatus = pressDown;
break;
// 复原
case RESTORE:
this.restoreStatus = pressDown;
break;
// 闭塞
case BLOCK:
this.blockStatus = pressDown;
break;
}
}
@ -229,6 +230,7 @@ public class StationDirection extends MapNamedElement {
this.mainAssistStatus = false;
this.receiveAssistStatus = false;
this.deliverAssistStatus = false;
this.blockStatus = false;
this.receiveAspect = IndicatorStatusEnum.F;
this.deliverAspect = IndicatorStatusEnum.F;
this.sectionAspect = IndicatorStatusEnum.F;
@ -242,8 +244,21 @@ public class StationDirection extends MapNamedElement {
// XS方向为接车方向默认亮起
if (DirectionLabelEnum.X.equals(labelEnum) || DirectionLabelEnum.S.equals(labelEnum)) {
return ReceiveAndDeliverModel.R;
} else { // 其他方向默认发车灯亮起
} else if (DirectionLabelEnum.XF.equals(labelEnum) || DirectionLabelEnum.SF.equals(labelEnum)) { // SFXF方向默认发车灯亮起
return ReceiveAndDeliverModel.D;
} else { // SDXD方向默认发车灯亮起
return ReceiveAndDeliverModel.N;
}
}
/**
* 默认运行模式
*/
private DirectionRunModel getDefaultDirectionRunModel() {
if (DirectionLabelEnum.XD.equals(labelEnum) || DirectionLabelEnum.SD.equals(labelEnum)) {
return DirectionRunModel.S;
} else { // SDXD
return DirectionRunModel.A;
}
}
@ -283,11 +298,83 @@ public class StationDirection extends MapNamedElement {
return isReady;
}
/**
* 自动模式下的接发车判断
*/
private void automaticModelAspectStatus() {
// 进路锁闭判断接发状态
// 接车进路锁闭
boolean receiveRouteBlock = this.receiveRouteList.stream().anyMatch(Route::isLock);
// 发车进路锁闭
boolean deliverRouteBlock = this.deliverRouteList.stream().anyMatch(Route::isLock);
// 接发状态
this.runStatus = receiveRouteBlock ? ReceiveAndDeliverModel.R : this.runStatus;
this.runStatus = deliverRouteBlock ? ReceiveAndDeliverModel.D : this.runStatus;
// 接车进路锁闭亮红灯否则默认
IndicatorStatusEnum receiveAspect;
// 发车进路锁闭亮红灯否则默认
IndicatorStatusEnum deliverAspect;
// 进路区段占用判断点灯颜色
if (ReceiveAndDeliverModel.R.equals(this.runStatus)) {
deliverAspect = IndicatorStatusEnum.F;
// 接车进路锁闭
receiveAspect = judgeSignalLock() ? IndicatorStatusEnum.O : IndicatorStatusEnum.F;
} else if (ReceiveAndDeliverModel.D.equals(this.runStatus)) {
receiveAspect = IndicatorStatusEnum.F;
// 发车进路锁闭
deliverAspect = judgeSignalLock() ? IndicatorStatusEnum.O : IndicatorStatusEnum.F;
} else {
receiveAspect = this.receiveAspect;
deliverAspect = this.receiveAspect;
}
// 赋值点灯信息
this.deliverAspect = deliverAspect;
this.receiveAspect = receiveAspect;
}
/**
* 半自动闭塞,不会自动恢复
*/
private void semiAutomaticModelAspectStatus() {
// 只有当状态为空时才做判断
if (ReceiveAndDeliverModel.N.equals(this.runStatus)) {
// 进路锁闭判断接发状态
// 接车进路锁闭
boolean receiveRouteBlock = this.receiveRouteList.stream().anyMatch(Route::isLock);
if (receiveRouteBlock) {
// 接发状态
this.runStatus = ReceiveAndDeliverModel.R;
} else {
// 发车进路锁闭
boolean deliverRouteBlock = this.deliverRouteList.stream().anyMatch(Route::isLock);
this.runStatus = deliverRouteBlock ? ReceiveAndDeliverModel.D : this.runStatus;
}
}
// 点灯
if (ReceiveAndDeliverModel.R.equals(this.runStatus)) { // 接车方向
if (IndicatorStatusEnum.F.equals(this.receiveAspect) && IndicatorStatusEnum.O.equals(this.sectionAspect)) {
receiveAspect = IndicatorStatusEnum.O;
}
} else if (ReceiveAndDeliverModel.D.equals(this.runStatus)) { // 发车方向
// 进入区间后标为占用且不主动恢复
if (IndicatorStatusEnum.F.equals(this.deliverAspect) && IndicatorStatusEnum.O.equals(this.sectionAspect)) {
this.deliverAspect = IndicatorStatusEnum.O;
}
} else if (ReceiveAndDeliverModel.N.equals(this.runStatus)) {
this.deliverAspect = IndicatorStatusEnum.F;
this.receiveAspect = IndicatorStatusEnum.F;
}
}
public enum ReceiveAndDeliverModel {
//
R,
//
D,
//
A,
//
N
}
public enum IndicatorStatusEnum {
@ -306,6 +393,19 @@ public class StationDirection extends MapNamedElement {
DELIVER_ASSIST,
// 改方
CHANGE_DIRECTION,
// 复原
RESTORE,
// 闭塞
BLOCK,
NO;
}
public enum DirectionRunModel {
// 自动
A,
// 半自动
S,
// 非自动
N
}
}