列车图例显示位置

This commit is contained in:
tiger_zhou 2023-04-20 17:42:05 +08:00
parent 77ee7005f1
commit e83d5dfae6
5 changed files with 46 additions and 18 deletions

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.simulation.cbtc.ATS; package club.joylink.rtss.simulation.cbtc.ATS;
import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm;
import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram; import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
@ -18,11 +17,14 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.DecimalFormat; import java.util.List;
import java.util.*; import java.util.Objects;
import java.util.Optional;
import java.util.Set;
/** /**
* 收集列车相关信息 * 收集列车相关信息
@ -45,14 +47,16 @@ public class ATSTrainMessageDiagram {
if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){ if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){
continue; continue;
} }
Optional<StationDiagram> optionalDiagram = this.calculate(train); Optional<StationDiagram> optionalDiagram = this.calculate(train);
optionalDiagram.ifPresent(stationDiagramList::add); optionalDiagram.ifPresent(stationDiagramList::add);
} }
SocketMessageVO<List<StationDiagram>> messageVO = SocketMessageVO<List<StationDiagram>> messageVO =
SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList); SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList);
stompMessageService.send(messageVO); Set<String> sessions = simulation.getSimulationUserIds();
} stompMessageService.sendToUser(sessions, messageVO);
}
/*public void collect(Simulation simulation){ /*public void collect(Simulation simulation){
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
@ -101,34 +105,35 @@ public class ATSTrainMessageDiagram {
boolean finalStation = true; boolean finalStation = true;
Section targetSecion = train.getTarget(); Section targetSecion = train.getTarget();
SectionPosition tailSP = train.getTailPosition(); Section tailSection = train.getTailPosition().getSection();
Section tailSection = tailSP.getSection();
Section parent = tailSection.isPhysical() ? tailSection : tailSection.getParent();
if(!Objects.equals(train.getNextStation().getCode(),train.getTerminalStation().getCode())) { if(!Objects.equals(train.getNextStation().getCode(),train.getTerminalStation().getCode())) {
//车辆的下一站不是终点站,获取下一站的停车位置 //车辆的下一站不是终点站,获取下一站的停车位置
finalStation = false; finalStation = false;
SectionPosition sp = train.calculateNextStandStopPosition(); SectionPosition sp = train.calculateNextStandStopPosition();
if(Objects.isNull(sp)){ if(Objects.isNull(sp)){
return Optional.empty(); StationDiagram sd = new StationDiagram(train,false);
return Optional.of(sd);
} }
targetSecion = sp.getSection(); targetSecion = sp.getSection();
} }
if(!tailSection.isStandTrack()){
//如果车尾所在的区段是逻辑区段那么就查找车辆后方的车站 //如果车尾所在的区段是逻辑区段那么就查找车辆后方的车站
if(Objects.isNull(parent.getStation())){
SectionPosition sp1 = train.calculateBackStandStopPosition(); SectionPosition sp1 = train.calculateBackStandStopPosition();
if(Objects.isNull(sp1)){ if(Objects.isNull(sp1)){
//未找到列车后面的车站,可能还未进始发站 //未找到列车后面的车站,可能还未进始发站
return Optional.empty(); StationDiagram sd = new StationDiagram(train,false);
return Optional.of(sd);
} }
tailSection = sp1.getSection(); tailSection = sp1.getSection();
} }
Float complateDis = 1F; Float complateDis = 1F;
if(!train.isParkingAt()){ if(!train.isParkingAt()){
complateDis = this.calculateStationRatio(tailSection,targetSecion,train); complateDis = this.calculateStationRatio(tailSection,targetSecion,train);
} }
StationDiagram stationDiagram = new StationDiagram(train,complateDis,finalStation); StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,finalStation);
stationDiagram.setStartStation(tailSection.getStation()); stationDiagram.setStartStation(tailSection.getStation());
stationDiagram.setEndStation(train.getNextStation()); stationDiagram.setEndStation(train.getNextStation());
return Optional.of(stationDiagram); return Optional.of(stationDiagram);
@ -160,6 +165,6 @@ public class ATSTrainMessageDiagram {
} }
public void addJobs(Simulation simulation){ public void addJobs(Simulation simulation){
simulation.addJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_RUNNING_RATE); simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE);
} }
} }

View File

@ -12,6 +12,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor @NoArgsConstructor
public class StationDiagram { public class StationDiagram {
public StationDiagram(VirtualRealityTrain train,Float stationComplateRatio, Boolean finalStation){ public StationDiagram(VirtualRealityTrain train,Float stationComplateRatio, Boolean finalStation){
this.groupNum = train.getGroupNumber(); this.groupNum = train.getGroupNumber();
this.right = train.isRight(); this.right = train.isRight();
@ -19,6 +20,21 @@ public class StationDiagram {
this.finalStation = finalStation; this.finalStation = finalStation;
} }
public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram){
this.groupNum = train.getGroupNumber();
this.right = train.isRight();
this.showTrainDiagram = showTrainDiagram;
}
public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram,Float stationComplateRatio, Boolean finalStation){
this.groupNum = train.getGroupNumber();
this.right = train.isRight();
this.stationComplateRatio = stationComplateRatio;
this.finalStation = finalStation;
this.showTrainDiagram = showTrainDiagram;
}
/** /**
* 车组号 * 车组号
*/ */
@ -37,6 +53,10 @@ public class StationDiagram {
*/ */
private Boolean finalStation; private Boolean finalStation;
/**
* 图例是否显示车辆
*/
private Boolean showTrainDiagram;
/** /**
* 运行开始车站 * 运行开始车站
*/ */

View File

@ -108,7 +108,10 @@ public interface SimulationConstants {
/** 停车场/车辆段循环逻辑频率单位ms */ /** 停车场/车辆段循环逻辑频率单位ms */
int DEPOT_LOOP_RATE = 1000; int DEPOT_LOOP_RATE = 1000;
/**
* ncc 车站图例频率(ms)
*/
int TRAIN_DIAGRAM_RATE = 1000;
/** /**
* 获取仿真运行计划日期运营日 * 获取仿真运行计划日期运营日
* @return * @return

View File

@ -60,7 +60,7 @@ public enum SimulationModule {
ROBOT(SimulationConstants.ROBOT_LOGIC_LOOP_RATE), ROBOT(SimulationConstants.ROBOT_LOGIC_LOOP_RATE),
YJDDZH(SimulationConstants.ROBOT_LOGIC_LOOP_RATE), YJDDZH(SimulationConstants.ROBOT_LOGIC_LOOP_RATE),
TRAIN_DIAGRAM(SimulationConstants.TRAIN_RUNNING_RATE) TRAIN_DIAGRAM(SimulationConstants.TRAIN_DIAGRAM_RATE)
; ;
/** 执行频率-单位ms */ /** 执行频率-单位ms */

View File

@ -55,14 +55,14 @@ public class StompTest {
WebSocketStompClient stompClient = new WebSocketStompClient(socketClient); WebSocketStompClient stompClient = new WebSocketStompClient(socketClient);
SimulationSessionHandler handler = new SimulationSessionHandler(); SimulationSessionHandler handler = new SimulationSessionHandler();
ListenableFuture<StompSession> future = stompClient ListenableFuture<StompSession> future = stompClient
.connect("ws://127.0.0.1:9000/joylink-websocket?token=6a8dbf62d3683844a6aa722b73b989f1",handler, "null"); .connect("ws://127.0.0.1:9000/joylink-websocket?token=62ee9df6368415439b46d3293c22b6c6",handler, "null");
StompSession stompSession = null; StompSession stompSession = null;
try { try {
stompSession = future.get(); stompSession = future.get();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
stompSession.subscribe("/topic/yjddzh/trainPosition", new StompFrameHandler() { stompSession.subscribe("/queue/simulation/63-8146", new StompFrameHandler() {
@Override @Override
public Type getPayloadType(StompHeaders stompHeaders) { public Type getPayloadType(StompHeaders stompHeaders) {
return byte[].class; return byte[].class;