添加列车移除列车

This commit is contained in:
fan 2023-07-18 13:44:06 +08:00
parent 76733a8b26
commit 67f65c36bd
21 changed files with 297 additions and 421 deletions

@ -1 +1 @@
Subproject commit 5ead82f5bfc0fe13025cfc89d4a825c4a3105565
Subproject commit 0e8a73e1028177059ac306ca0c5abb8c52c2b3e2

View File

@ -19,3 +19,30 @@ export async function destroySimulation(data: { simulationId: string }) {
const response = await api.post(`${UriBase}/destroy`, data);
return response.data;
}
/**
*
* @param simulationId 仿id
* @param up
* @param headLinkId link索引
* @param headLinkOffset link偏移
*/
export async function addTrain(data: {
simulationId: string;
up: boolean;
headLinkId: string;
headLinkOffset: number;
}) {
const response = await api.post(`${UriBase}/train/add`, data);
return response.data;
}
/**
*
*/
export async function removeTrain(data: {
simulationId: string;
trainId: string;
}) {
const response = await api.post(`${UriBase}/train/remove`, data);
return response.data;
}

View File

@ -58,7 +58,6 @@ const props = defineProps({
required: true,
},
});
const dir = ref(1);
const offset = ref(0);
const dirOptions = [

View File

@ -3,8 +3,8 @@ function getHost(): string {
// return '192.168.3.47:9091';
// return '192.168.3.37:9091';
// return '192.168.3.15:9091';
// return '192.168.3.5:9091';
return '192.168.3.233:9091';
return '192.168.3.5:9091';
// return '192.168.3.233:9091';
}
export function getHttpBase() {

View File

@ -13,10 +13,11 @@ import {
} from 'src/jl-graphic';
import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu';
import { MenuItemOptions } from 'src/jl-graphic/ui/Menu';
import { SignalOperateInteraction } from './SignalInteraction';
import { Dialog } from 'quasar';
import AddTrainDialog from '../../components/draw-app/dialogs/AddTrainDialog.vue';
import { addTrain } from 'src/api/Simulation';
import { useLineStore } from 'src/stores/line-store';
import { successNotify, errorNotify } from '../../utils/CommonNotify';
export class SectionLinkData
extends GraphicDataBase
implements ISectionLinkData
@ -114,7 +115,7 @@ export class SectionLinkOperateInteraction extends GraphicInteractionPlugin<Sect
app.registerMenu(SectionLinkOperateMenu);
}
static init(app: GraphicApp) {
return new SignalOperateInteraction(app);
return new SectionLinkOperateInteraction(app);
}
filter(...grahpics: JlGraphic[]): SectionLink[] | undefined {
return grahpics
@ -138,17 +139,31 @@ export class SectionLinkOperateInteraction extends GraphicInteractionPlugin<Sect
const target = e.target as DisplayObject;
const link = target.getGraphic() as SectionLink;
this.app.updateSelected(link);
const lineStore = useLineStore();
const simulationId = lineStore.simulationId || '';
addTrainConfig.handler = () => {
Dialog.create({
title: '创建列车',
message: '',
component: AddTrainDialog,
componentProps: link.datas.index,
componentProps: { linkIndex: link.datas.index },
cancel: true,
persistent: true,
}).onOk((data: { offset: number; dir: 1 | 0 }) => {
console.log(data, 'data');
addTrain({
simulationId,
up: !!data.dir,
headLinkId: link.datas.index.toString(),
headLinkOffset: data.offset,
})
.then(() => {
successNotify('添加列车成功!');
})
.catch((err) => {
errorNotify('添加列车失败!', err);
});
});
};
SectionLinkOperateMenu.open(e.global);
}
}

View File

@ -1,8 +1,7 @@
import * as pb_1 from 'google-protobuf';
import { ITrainState, Train } from 'src/graphics/train/Train';
import { GraphicStateBase } from './GraphicDataBase';
import { state } from 'src/protos/device_status';
import { train } from 'src/protos/train';
import { state } from 'src/protos/device_state';
import { MenuItemOptions } from 'src/jl-graphic/ui/Menu';
import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu';
import {
@ -11,169 +10,69 @@ import {
JlGraphic,
} from 'src/jl-graphic';
import { DisplayObject, FederatedMouseEvent } from 'pixi.js';
import { removeTrain } from 'src/api/Simulation';
import { useLineStore } from 'src/stores/line-store';
import { successNotify, errorNotify } from '../../utils/CommonNotify';
export class TrainState extends GraphicStateBase implements ITrainState {
constructor(proto?: train.TrainInfo) {
constructor(proto?: state.TrainState) {
let states;
if (proto) {
states = proto;
} else {
states = new train.TrainInfo();
states = new state.TrainState();
}
super(states, Train.Type);
}
get code(): string {
return this.states.trainIndex;
return this.states.id;
}
get states(): train.TrainInfo {
return this.getState<train.TrainInfo>();
get states(): state.TrainState {
return this.getState<state.TrainState>();
}
get lineId(): number {
return this.states.lineId;
get id(): string {
return this.states.id;
}
set lineId(v: number) {
this.states.lineId = v;
set id(v: string) {
this.states.id = v;
}
get rtuId(): number {
return this.states.rtuId;
get up(): boolean {
return this.states.up;
}
set rtuId(v: number) {
this.states.rtuId = v;
set up(v: boolean) {
this.states.up = v;
}
get window(): train.NccWindow {
if (!this.states.window) {
this.states.window = new train.NccWindow();
get headLinkId(): string {
return this.states.headLinkId;
}
return this.states.window;
set headLinkId(v: string) {
this.states.headLinkId = v;
}
set window(v: train.NccWindow) {
this.states.window = v;
get headLinkOffset(): number {
return this.states.headLinkOffset;
}
get devType(): number {
return this.states.devType;
set headLinkOffset(v: number) {
this.states.headLinkOffset = v;
}
set devType(v: number) {
this.states.devType = v;
get tailLinkId(): string {
return this.states.tailLinkId;
}
get devName(): string {
return this.states.devName;
set tailLinkId(v: string) {
this.states.tailLinkId = v;
}
set devName(v: string) {
this.states.devName = v;
get tailLinkOffset(): number {
return this.states.tailLinkOffset;
}
get trainIndex(): string {
return this.states.trainIndex;
set tailLinkOffset(v: number) {
this.states.tailLinkOffset = v;
}
set trainIndex(v: string) {
this.states.trainIndex = v;
get occupiedLinkIndex(): string[] {
return this.states.occupiedLinkIndex;
}
get groupId(): string {
return this.states.groupId;
}
set groupId(v: string) {
this.states.groupId = v;
}
get trainId(): string {
return this.states.trainId;
}
set trainId(v: string) {
this.states.trainId = v;
}
get globalId(): string {
return this.states.globalId;
}
set globalId(v: string) {
this.states.globalId = v;
}
get destinationId(): number {
return this.states.destinationId;
}
set destinationId(v: number) {
this.states.destinationId = v;
}
get rollingStock(): number {
return this.states.rollingStock;
}
set rollingStock(v: number) {
this.states.rollingStock = v;
}
get driverId(): string {
return this.states.driverId;
}
set driverId(v: string) {
this.states.driverId = v;
}
get otpTime(): number {
return this.states.otpTime;
}
set otpTime(v: number) {
this.states.otpTime = v;
}
get mode(): state.TrainMode {
if (!this.states.mode) {
this.states.mode = new state.TrainMode();
}
return this.states.mode;
}
set mode(v: state.TrainMode) {
this.states.mode = v;
}
get arriveTime(): number {
return this.states.arriveTime;
}
set arriveTime(v: number) {
this.states.arriveTime = v;
}
get departTime(): number {
return this.states.departTime;
}
set departTime(v: number) {
this.states.departTime = v;
}
get speed(): number {
return this.states.speed;
}
set speed(v: number) {
this.states.speed = v;
}
get type(): boolean {
return this.states.type;
}
set type(v: boolean) {
this.states.type = v;
}
get routeId(): number {
return this.states.routeId;
}
set routeId(v: number) {
this.states.routeId = v;
}
get rate(): number {
return this.states.rate;
}
set rate(v: number) {
this.states.rate = v;
}
get remove(): train.TrainRemove {
return this.states.remove;
}
set remove(v: train.TrainRemove) {
this.states.remove = v;
}
get block(): train.TrainBlock {
return this.states.block;
}
set block(v: train.TrainBlock) {
this.states.block = v;
}
get record(): train.TrainRecord {
return this.states.record;
}
set record(v: train.TrainRecord) {
this.states.record = v;
set occupiedLinkIndex(v: string[]) {
this.states.occupiedLinkIndex = v;
}
clone(): TrainState {
@ -187,40 +86,14 @@ export class TrainState extends GraphicStateBase implements ITrainState {
}
}
const negativeDirectionConfig: MenuItemOptions = {
name: '反方向运行',
};
const runStopConfig: MenuItemOptions = {
name: '前进/停止',
};
const diriveModelConfig: MenuItemOptions = {
name: '驾驶模式',
};
const accuracyConfig: MenuItemOptions = {
name: '正常/早点/晚点',
};
const HoldTrainConfig: MenuItemOptions = {
name: '扣车',
};
const openDoorConfig: MenuItemOptions = {
name: '开门',
};
const editGroupConfig: MenuItemOptions = {
name: '修改车组号',
const removeTrainConfig: MenuItemOptions = {
name: '清除列车',
};
const TrainOperateMenu: ContextMenu = ContextMenu.init({
name: '列车操作菜单',
groups: [
{
items: [
negativeDirectionConfig,
runStopConfig,
diriveModelConfig,
accuracyConfig,
HoldTrainConfig,
openDoorConfig,
editGroupConfig,
],
items: [removeTrainConfig],
},
],
});
@ -254,84 +127,21 @@ export class TrainOperateInteraction extends GraphicInteractionPlugin<Train> {
const target = e.target as DisplayObject;
const train = target.getGraphic() as Train;
this.app.updateSelected(train);
negativeDirectionConfig.handler = () => {
const mode = train.states.mode;
if (!train.states.mode.ipModeTrainDirUp) {
mode.ipModeTrainDirUp = true;
mode.ipModeTrainDirDown = false;
} else if (!train.states.mode.ipModeTrainDirDown) {
mode.ipModeTrainDirUp = false;
mode.ipModeTrainDirDown = true;
}
train.doRepaint();
};
runStopConfig.handler = () => {
train.states.mode.ipModeTrainStoped =
!train.states.mode.ipModeTrainStoped;
train.doRepaint();
};
diriveModelConfig.handler = () => {
const arr: Array<keyof state.TrainMode> = [
'ipModeTrainDriveModeAm',
'ipModeTrainDriveModeCm',
'ipModeTrainDriveBlockAm',
'ipModeTrainDriveBlockCm',
'ipModeTrainDriveModeRmf',
];
let findIndex = arr.findIndex((key) => {
return train.states.mode[key];
const lineStore = useLineStore();
const simulationId = lineStore.simulationId || '';
removeTrainConfig.handler = () => {
removeTrain({
simulationId,
trainId: train.code,
})
.then(() => {
successNotify('移除列车成功!');
})
.catch((err) => {
errorNotify('移除列车失败!', err);
});
if (findIndex == arr.length - 1) {
findIndex = -1;
}
arr.forEach((key) => {
(train.states.mode[key] as boolean) = false;
});
(train.states.mode[arr[findIndex + 1]] as boolean) = true;
train.doRepaint();
};
HoldTrainConfig.handler = () => {
train.states.mode.ipModeTrainHolded =
!train.states.mode.ipModeTrainHolded;
train.doRepaint();
};
accuracyConfig.handler = () => {
const arr: Array<keyof state.TrainMode> = [
'ipModeTrainTypeSchedule',
'ipModeTrainSchdEarly',
'ipModeTrainSchdLate',
];
let findIndex = -1;
arr.forEach((key, index) => {
if (train.states.mode[key]) {
findIndex = index;
}
});
arr.forEach((key, index) => {
if (index != 0) {
(train.states.mode[key] as boolean) = false;
}
});
if (findIndex != arr.length - 1) {
train.states.mode.ipModeTrainTypeSchedule = true;
}
if (findIndex == arr.length - 1) {
train.states.mode.ipModeTrainTypeSchedule = false;
} else {
(train.states.mode[arr[findIndex + 1]] as boolean) = true;
}
train.doRepaint();
};
openDoorConfig.handler = () => {
train.states.mode.ipModeTrainDoorOpen =
!train.states.mode.ipModeTrainDoorOpen;
train.doRepaint();
};
editGroupConfig.handler = () => {
train.states.trainId = '02';
train.states.destinationId = 123;
train.doRepaint();
};
TrainOperateMenu.open(e.global);
}
}

View File

@ -430,9 +430,17 @@ export async function loadDrawDatas(app: GraphicApp) {
datas.push(new SeparatorData(separator));
});
storage.sectionLinks.forEach((sectionLink) => {
if (sectionLink.code) {
sectionLink.index = parseInt(sectionLink.code);
}
// if (sectionLink.code) {
// sectionLink.index = parseInt(sectionLink.code);
// }
// if (
// sectionLink.points[sectionLink.points.length - 1].x <
// sectionLink.points[0].x
// ) {
// console.log('1111111');
// const ps = [...sectionLink.points];
// sectionLink.points = ps.reverse();
// }
datas.push(new SectionLinkData(sectionLink));
});
storage.axleCountingSections.forEach((axleCountingSection) => {

View File

@ -6,7 +6,8 @@ import {
GraphicState,
} from 'src/jl-graphic';
import { TrainState } from './graphics/TrainInteraction';
import { TrainTemplate } from 'src/graphics/train/Train';
import { Train, TrainTemplate } from 'src/graphics/train/Train';
import { TrainOperateInteraction } from './graphics/TrainInteraction';
import {
SignalData,
SignalOperateInteraction,
@ -54,7 +55,10 @@ import {
} from 'src/graphics/sectionLink/SectionLink';
import { Separator, SeparatorTemplate } from 'src/graphics/separator/Separator';
import { SeparatorData } from './graphics/SeparatorInteraction';
import { SectionLinkData } from './graphics/SectionLinkInteraction';
import {
SectionLinkData,
SectionLinkOperateInteraction,
} from './graphics/SectionLinkInteraction';
import { AxleCountingSectionData } from './graphics/AxleCountingSectionInteraction';
import { LogicSectionData } from './graphics/LogicSectionInteraction';
@ -137,12 +141,16 @@ export function initLineApp(dom: HTMLElement): GraphicApp {
Signal.Type,
Platform.Type,
Station.Type,
SectionLink.Type,
Train.Type,
],
},
});
SignalOperateInteraction.init(lineApp);
PlatformOperateInteraction.init(lineApp);
StationOperateInteraction.init(lineApp);
SectionLinkOperateInteraction.init(lineApp);
TrainOperateInteraction.init(lineApp);
// 画布右键菜单
lineApp.registerMenu(DefaultCanvasMenu);
lineApp.canvas.on('_rightclick', (e) => {
@ -164,6 +172,7 @@ export function initLineApp(dom: HTMLElement): GraphicApp {
g.visible = false;
}
});
console.log(lineApp);
};
DefaultCanvasMenu.open(e.global);
});
@ -215,9 +224,6 @@ export async function loadLineDatas(app: GraphicApp) {
datas.push(new SeparatorData(separator));
});
storage.sectionLinks.forEach((sectionLink) => {
if (sectionLink.code) {
sectionLink.index = parseInt(sectionLink.code);
}
datas.push(new SectionLinkData(sectionLink));
});
storage.axleCountingSections.forEach((axleCountingSection) => {
@ -247,6 +253,7 @@ export async function loadLineDatas(app: GraphicApp) {
messageConverter: (message: Uint8Array) => {
const states: GraphicState[] = [];
const storage = state.PushedDevicesStatus.deserialize(message);
console.log(storage, 'storage');
if (storage.all) {
storage.allStatus.sectionState.forEach((item) => {
if (state.SectionType[item.type] == 'Axle') {
@ -287,11 +294,14 @@ export async function loadLineDatas(app: GraphicApp) {
});
storage.varStatus.updatedTrain.forEach((item) => {
// 列车
// states.push(new TrainState(item));
states.push(new TrainState(item));
});
storage.varStatus.removedTrainId.forEach((item) => {
// 移除列车
// states.push(new TrainState(item));
const train = app.queryStore.queryByCodeAndType(item, Train.Type);
if (train) {
app.deleteGraphics(train);
}
});
}
return states;

View File

@ -61,6 +61,9 @@ export class AxleCountingSection extends JlGraphic {
get datas(): IAxleCountingSectionData {
return this.getDatas<IAxleCountingSectionData>();
}
get code(): string {
return this.datas.index + '';
}
doRepaint(): void {
if (this.datas.points.length < 2) {
throw new Error('AxleCountingSection坐标数据异常');

View File

@ -57,6 +57,9 @@ export class LogicSection extends JlGraphic {
get datas(): ILogicSectionData {
return this.getDatas<ILogicSectionData>();
}
get code(): string {
return this.datas.index + '';
}
doRepaint(): void {
if (this.datas.points.length < 2) {
throw new Error('LogicSection坐标数据异常');

View File

@ -402,6 +402,9 @@ export class Platform extends JlGraphic {
get states(): IPlatformState {
return this.getStates<IPlatformState>();
}
get code(): string {
return this.datas.index + '';
}
doRepaint(): void {
this.doorGraphic.clear();
if (this.datas.hasdoor) {

View File

@ -123,6 +123,9 @@ export class Section extends JlGraphic implements ILineGraphic {
get datas(): ISectionData {
return this.getDatas<ISectionData>();
}
get code(): string {
return this.datas.index + '';
}
get linePoints(): IPointData[] {
return this.datas.points;

View File

@ -137,7 +137,9 @@ export class SectionLink extends JlGraphic implements ILineGraphic {
get datas(): ISectionLinkData {
return this.getDatas<ISectionLinkData>();
}
get code(): string {
return this.datas.index + '';
}
get linePoints(): IPointData[] {
return this.datas.points;
}

View File

@ -150,6 +150,9 @@ export class SectionLinkDraw extends GraphicDrawAssistant<
} else {
throw new Error('无法判断linkAB端');
}
if (points[points.length - 1].x < points[0].x) {
points.reverse();
}
sectionLink.datas.points = points;
return sectionLink;
}
@ -216,6 +219,9 @@ export class SectionLinkDraw extends GraphicDrawAssistant<
points.push(turnout.localToCanvasPoint(dataPoint[pLength - i]));
}
points.push(forkP2);
if (points[points.length - 1].x < points[0].x) {
points.reverse();
}
sectionLink.datas.points = points;
return sectionLink;
}

View File

@ -116,7 +116,9 @@ export class Signal extends JlGraphic {
get states(): ISignalState {
return this.getStates<ISignalState>();
}
get code(): string {
return this.datas.index + '';
}
get mirror(): boolean {
return this.datas.mirror;
}

View File

@ -297,6 +297,9 @@ export class Station extends JlGraphic {
get states(): IStationState {
return this.getStates<IStationState>();
}
get code(): string {
return this.datas.index + '';
}
doRepaint(): void {
const codeGraph = this.codeGraph;
const kilometerGraph = this.kilometerGraph;

View File

@ -7,9 +7,9 @@ import {
JlGraphicTemplate,
VectorText,
calculateMirrorPoint,
distance,
} from 'src/jl-graphic';
import { train } from 'src/protos/train';
import { state } from 'src/protos/device_status';
import { SectionLink } from '../sectionLink/SectionLink';
export interface ITrainData extends GraphicData {
get code(): string; // 车号
@ -20,52 +20,20 @@ export interface ITrainData extends GraphicData {
}
export interface ITrainState extends GraphicState {
get lineId(): number; // 线路id
set lineId(v: number);
get rtuId(): number; // 集中站站号
set rtuId(v: number);
get window(): train.NccWindow; // NccWindow
set window(v: train.NccWindow);
get devType(): state.DeviceType; // 所在设备类型
set devType(v: state.DeviceType);
get devName(): string; // 所在设备名称
set devName(v: string);
get trainIndex(): string; // 设备唯一与trainIndex相同
set trainIndex(v: string);
get groupId(): string; // 列车车组号
set groupId(v: string);
get trainId(): string; // 列车表号
set trainId(v: string);
get globalId(): string; // 列车车次号
set globalId(v: string);
get destinationId(): number; // 目的地ID
set destinationId(v: number);
get rollingStock(): number; // 编组数量
set rollingStock(v: number);
get driverId(): string; // 司机号
set driverId(v: string);
get otpTime(): number; // 计划偏离时间
set otpTime(v: number);
get mode(): state.TrainMode; // 列车状态
set mode(v: state.TrainMode);
get arriveTime(): number; // 到点
set arriveTime(v: number);
get departTime(): number; // 发点
set departTime(v: number);
get speed(): number; // 速度
set speed(v: number);
get type(): boolean; // 车次号变化状态
set type(v: boolean);
get routeId(): number; // 运行路径号
set routeId(v: number);
get rate(): number; // 满载率
set rate(v: number);
get remove(): train.TrainRemove;
set remove(v: train.TrainRemove);
get block(): train.TrainBlock;
set block(v: train.TrainBlock);
get record(): train.TrainRecord;
set record(v: train.TrainRecord);
get id(): string; // 列车id
set id(v: string);
get up(): boolean;
set up(v: boolean);
get headLinkId(): string; // 头部link位置
set headLinkId(v: string);
get headLinkOffset(): number;
set headLinkOffset(v: number);
get tailLinkId(): string;
set tailLinkId(v: string);
get tailLinkOffset(): number;
set tailLinkOffset(v: number);
get occupiedLinkIndex(): string[];
set occupiedLinkIndex(v: string[]);
}
interface bodyWH {
@ -136,13 +104,10 @@ export class TrainHead extends Container {
this.pause.clear();
}
doRepaint(states: ITrainState, bodyWH?: bodyWH) {
let direction = '';
if (states.mode?.ipModeTrainDirDown) {
let direction = 'right';
if (states.up) {
direction = 'left';
}
if (states.mode?.ipModeTrainDirUp) {
direction = 'right';
}
this.clear();
if (!direction) {
return;
@ -185,21 +150,8 @@ export class TrainHead extends Container {
});
pausePoint = pP;
}
let aColor = DiriveModelColorEnum.AM;
let pColor = DiriveModelColorEnum.AM;
if (
states.mode?.ipModeTrainDriveModeCm ||
states.mode?.ipModeTrainDriveBlockCm
) {
aColor = DiriveModelColorEnum.SM;
pColor = DiriveModelColorEnum.SM;
} else if (
states.mode?.ipModeTrainDriveModeRmf ||
states.mode?.ipModeTrainDriveModeRmr
) {
aColor = DiriveModelColorEnum.RM;
pColor = DiriveModelColorEnum.RM;
}
const aColor = DiriveModelColorEnum.AM;
const pColor = DiriveModelColorEnum.AM;
this.pause.lineStyle(pauseW, pColor, 1);
this.pause.moveTo(pausePoint[0], pausePoint[1]);
this.pause.lineTo(pausePoint[2], pausePoint[3]);
@ -207,11 +159,11 @@ export class TrainHead extends Container {
arrow.beginFill(aColor, 1);
arrow.drawPolygon(arrowPoint);
arrow.endFill();
if (states.mode?.ipModeTrainStoped) {
this.arrow.visible = false;
} else {
this.arrow.visible = true;
}
// if (states.mode?.ipModeTrainStoped) {
// this.arrow.visible = false;
// } else {
// this.arrow.visible = true;
// }
}
}
@ -245,45 +197,15 @@ export class TrainBody extends Container {
const codeAGraph = this.codeAGraph;
const codeBGraph = this.codeBGraph;
const codeRact = this.codeRact;
const codeA = states?.groupId;
let codeB = states?.destinationId ? states?.destinationId + '' : '';
const codeA = states?.code;
const fillAColor = typeColorEnum.schedule;
let fillBColor = typeColorEnum.schedule;
if (states.mode?.ipModeTrainTypeSchedule) {
fillBColor = typeColorEnum.accuracy;
if (states.mode?.ipModeTrainSchdLate) {
fillBColor = typeColorEnum.late;
} else if (states.mode?.ipModeTrainSchdEarly) {
fillBColor = typeColorEnum.early;
}
} else if (states.mode?.ipModeTrainTypeHead) {
codeB = states?.destinationId ? states?.destinationId + '' : '';
} else if (states.mode?.ipModeTrainTypeManual) {
codeB = '---';
} else if (states.mode?.ipModeTrainTypeSpecial) {
codeB = 'MM';
}
let bgColor = TrainColorEnum.ITCbodyColor;
if (
states.mode?.ipModeTrainDriveModeAm ||
states.mode?.ipModeTrainDriveModeCm
) {
bgColor = TrainColorEnum.bodyColor;
}
codeAGraph.text = codeA || '01';
codeBGraph.text = codeB || '222';
codeAGraph.text = codeA || '';
codeAGraph.anchor.set(0.5);
codeBGraph.anchor.set(0.5);
const styleA = {
fill: fillAColor,
fontSize: trainConsts.codeFontSize,
};
const styleB = {
fill: fillBColor,
fontSize: trainConsts.codeFontSize,
};
codeAGraph.style = styleA;
codeBGraph.style = styleB;
const bodyAWH = codeAGraph.getLocalBounds();
const bodyBWH = codeBGraph.getLocalBounds();
codeAGraph.position.set(-bodyBWH.width / 2, 0);
@ -295,6 +217,7 @@ export class TrainBody extends Container {
trainConsts.borderWidth,
new Color(TrainColorEnum.borderColor)
);
const bgColor = TrainColorEnum.ITCbodyColor;
codeRact.beginFill(new Color(bgColor));
codeRact.drawRect(-codeWidth / 2, -codeHeight / 2, codeWidth, codeHeight);
codeRact.endFill();
@ -367,26 +290,51 @@ export class Train extends JlGraphic {
this.trainbody.doRepaint(this.states);
const bodyWH = this.trainbody.getBodyWH();
this.trainHead.doRepaint(this.states, bodyWH);
if (this.states.mode?.ipModeTrainHolded) {
this.showStatus('扣');
} else {
this.hideStatus('扣');
// this.position.set(0, 0);
const link =
this.getGraphicApp().queryStore.queryByCodeAndType<SectionLink>(
this.states.headLinkId,
SectionLink.Type
);
if (!link) {
return;
}
if (this.states.mode?.ipModeTrainSkipstop) {
this.showStatus('跳');
} else {
this.hideStatus('跳');
const lengths = [];
let totalLength = 0;
const points = [...link.datas.points];
for (let i = 0; i < points.length - 1; i++) {
const l = distance(
points[i].x,
points[i].y,
points[i + 1].x,
points[i + 1].y
);
lengths.push(l);
totalLength += l;
}
if (this.states.mode?.ipModeTrainDoorOpen) {
this.showStatus('门');
} else {
this.hideStatus('门');
let offsetL = totalLength * this.states.headLinkOffset;
if (this.states.up) {
lengths.reverse();
points.reverse();
}
if (this.states.mode?.ipModeTrainRsAlarm) {
this.showStatus('警');
const indexP = lengths.findIndex((l) => {
offsetL -= l;
return offsetL <= 0;
});
const startP = points[indexP];
const endP = points[indexP + 1];
const px =
startP.x + Math.round(this.states.headLinkOffset * (endP.x - startP.x));
const py =
startP.y + Math.round(this.states.headLinkOffset * (endP.y - startP.y));
let angle = 0;
if (this.states.up) {
angle = Math.atan2(startP.y - endP.y, startP.x - endP.x);
} else {
this.hideStatus('警');
angle = Math.atan2(endP.y - startP.y, endP.x - startP.x);
}
this.position.set(px, py);
this.rotation = angle;
}
showStatus(s: string) {

View File

@ -194,6 +194,10 @@ export class Turnout extends JlGraphic {
return this.getStates<ITurnoutState>();
}
get code(): string {
return this.datas.index + '';
}
getPortPoints() {
return [this.datas.pointA, this.datas.pointB, this.datas.pointC];
}

View File

@ -52,6 +52,7 @@ import { pageQuery, deletePublish } from '../api/PublishApi';
import { useRouter } from 'vue-router';
import { createSimulation } from 'src/api/Simulation';
import { ApiError } from 'src/boot/axios';
import { useLineStore } from 'src/stores/line-store';
const router = useRouter();
const $q = useQuasar();
@ -89,6 +90,7 @@ const columnDefs: QTableColumn[] = [
const operateDisabled = ref(false);
const tableRef = ref();
const lineStore = useLineStore();
const rows = reactive([]);
const filter = reactive({
name: '',
@ -138,6 +140,7 @@ async function create(row: any) {
mapId: res.mapId,
simulationId: res.simulationId,
};
lineStore.setSimulationId(res.simulationId);
router.push({ path: '/linemap', query });
})
.catch((err) => {

View File

@ -331,18 +331,22 @@ export namespace state {
#one_of_decls: number[][] = [];
constructor(data?: any[] | {
id?: string;
up?: boolean;
headLinkId?: string;
headLinkOffset?: number;
tailLinkId?: string;
tailLinkOffset?: number;
occupiedLinkId?: string[];
occupiedLinkIndex?: string[];
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [6], this.#one_of_decls);
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [7], this.#one_of_decls);
if (!Array.isArray(data) && typeof data == "object") {
if ("id" in data && data.id != undefined) {
this.id = data.id;
}
if ("up" in data && data.up != undefined) {
this.up = data.up;
}
if ("headLinkId" in data && data.headLinkId != undefined) {
this.headLinkId = data.headLinkId;
}
@ -355,8 +359,8 @@ export namespace state {
if ("tailLinkOffset" in data && data.tailLinkOffset != undefined) {
this.tailLinkOffset = data.tailLinkOffset;
}
if ("occupiedLinkId" in data && data.occupiedLinkId != undefined) {
this.occupiedLinkId = data.occupiedLinkId;
if ("occupiedLinkIndex" in data && data.occupiedLinkIndex != undefined) {
this.occupiedLinkIndex = data.occupiedLinkIndex;
}
}
}
@ -366,48 +370,58 @@ export namespace state {
set id(value: string) {
pb_1.Message.setField(this, 1, value);
}
get headLinkId() {
return pb_1.Message.getFieldWithDefault(this, 2, "") as string;
get up() {
return pb_1.Message.getFieldWithDefault(this, 2, false) as boolean;
}
set headLinkId(value: string) {
set up(value: boolean) {
pb_1.Message.setField(this, 2, value);
}
get headLinkOffset() {
return pb_1.Message.getFieldWithDefault(this, 3, 0) as number;
get headLinkId() {
return pb_1.Message.getFieldWithDefault(this, 3, "") as string;
}
set headLinkOffset(value: number) {
set headLinkId(value: string) {
pb_1.Message.setField(this, 3, value);
}
get tailLinkId() {
return pb_1.Message.getFieldWithDefault(this, 4, "") as string;
get headLinkOffset() {
return pb_1.Message.getFieldWithDefault(this, 4, 0) as number;
}
set tailLinkId(value: string) {
set headLinkOffset(value: number) {
pb_1.Message.setField(this, 4, value);
}
get tailLinkOffset() {
return pb_1.Message.getFieldWithDefault(this, 5, 0) as number;
get tailLinkId() {
return pb_1.Message.getFieldWithDefault(this, 5, "") as string;
}
set tailLinkOffset(value: number) {
set tailLinkId(value: string) {
pb_1.Message.setField(this, 5, value);
}
get occupiedLinkId() {
return pb_1.Message.getFieldWithDefault(this, 6, []) as string[];
get tailLinkOffset() {
return pb_1.Message.getFieldWithDefault(this, 6, 0) as number;
}
set occupiedLinkId(value: string[]) {
set tailLinkOffset(value: number) {
pb_1.Message.setField(this, 6, value);
}
get occupiedLinkIndex() {
return pb_1.Message.getFieldWithDefault(this, 7, []) as string[];
}
set occupiedLinkIndex(value: string[]) {
pb_1.Message.setField(this, 7, value);
}
static fromObject(data: {
id?: string;
up?: boolean;
headLinkId?: string;
headLinkOffset?: number;
tailLinkId?: string;
tailLinkOffset?: number;
occupiedLinkId?: string[];
occupiedLinkIndex?: string[];
}): TrainState {
const message = new TrainState({});
if (data.id != null) {
message.id = data.id;
}
if (data.up != null) {
message.up = data.up;
}
if (data.headLinkId != null) {
message.headLinkId = data.headLinkId;
}
@ -420,23 +434,27 @@ export namespace state {
if (data.tailLinkOffset != null) {
message.tailLinkOffset = data.tailLinkOffset;
}
if (data.occupiedLinkId != null) {
message.occupiedLinkId = data.occupiedLinkId;
if (data.occupiedLinkIndex != null) {
message.occupiedLinkIndex = data.occupiedLinkIndex;
}
return message;
}
toObject() {
const data: {
id?: string;
up?: boolean;
headLinkId?: string;
headLinkOffset?: number;
tailLinkId?: string;
tailLinkOffset?: number;
occupiedLinkId?: string[];
occupiedLinkIndex?: string[];
} = {};
if (this.id != null) {
data.id = this.id;
}
if (this.up != null) {
data.up = this.up;
}
if (this.headLinkId != null) {
data.headLinkId = this.headLinkId;
}
@ -449,8 +467,8 @@ export namespace state {
if (this.tailLinkOffset != null) {
data.tailLinkOffset = this.tailLinkOffset;
}
if (this.occupiedLinkId != null) {
data.occupiedLinkId = this.occupiedLinkId;
if (this.occupiedLinkIndex != null) {
data.occupiedLinkIndex = this.occupiedLinkIndex;
}
return data;
}
@ -460,16 +478,18 @@ export namespace state {
const writer = w || new pb_1.BinaryWriter();
if (this.id.length)
writer.writeString(1, this.id);
if (this.up != false)
writer.writeBool(2, this.up);
if (this.headLinkId.length)
writer.writeString(2, this.headLinkId);
writer.writeString(3, this.headLinkId);
if (this.headLinkOffset != 0)
writer.writeInt64(3, this.headLinkOffset);
writer.writeInt64(4, this.headLinkOffset);
if (this.tailLinkId.length)
writer.writeString(4, this.tailLinkId);
writer.writeString(5, this.tailLinkId);
if (this.tailLinkOffset != 0)
writer.writeInt64(5, this.tailLinkOffset);
if (this.occupiedLinkId.length)
writer.writeRepeatedString(6, this.occupiedLinkId);
writer.writeInt64(6, this.tailLinkOffset);
if (this.occupiedLinkIndex.length)
writer.writeRepeatedString(7, this.occupiedLinkIndex);
if (!w)
return writer.getResultBuffer();
}
@ -483,19 +503,22 @@ export namespace state {
message.id = reader.readString();
break;
case 2:
message.headLinkId = reader.readString();
message.up = reader.readBool();
break;
case 3:
message.headLinkOffset = reader.readInt64();
message.headLinkId = reader.readString();
break;
case 4:
message.tailLinkId = reader.readString();
message.headLinkOffset = reader.readInt64();
break;
case 5:
message.tailLinkOffset = reader.readInt64();
message.tailLinkId = reader.readString();
break;
case 6:
pb_1.Message.addToRepeatedField(message, 6, reader.readString());
message.tailLinkOffset = reader.readInt64();
break;
case 7:
pb_1.Message.addToRepeatedField(message, 7, reader.readString());
break;
default: reader.skipField();
}

View File

@ -7,6 +7,7 @@ export const useLineStore = defineStore('line', {
selectedGraphics: null as JlGraphic[] | null,
lineId: null as number | null,
lineName: null as string | null,
simulationId: null as string | null,
}),
getters: {
selectedGraphicType: (state) => {
@ -46,5 +47,8 @@ export const useLineStore = defineStore('line', {
setLineName(name: string | null) {
this.lineName = name;
},
setSimulationId(id: string | null) {
this.simulationId = id;
},
},
});