From 141d3517941b4432cddd343dbaa037817996ce3a Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Thu, 6 Jul 2023 16:43:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/TrainApi.ts | 80 +++++++++++++++++++++ src/drawApp/graphics/TrainInteraction.ts | 90 +++++++++++++++--------- src/drawApp/lineApp.ts | 12 +++- src/graphics/separator/Separator.ts | 2 +- src/graphics/train/Train.ts | 90 ++++++++++++++---------- 5 files changed, 199 insertions(+), 75 deletions(-) create mode 100644 src/api/TrainApi.ts diff --git a/src/api/TrainApi.ts b/src/api/TrainApi.ts new file mode 100644 index 0000000..739168e --- /dev/null +++ b/src/api/TrainApi.ts @@ -0,0 +1,80 @@ +import { api } from 'src/boot/axios'; + +const PublishUriBase = '/mock/train'; + +export interface Mode { + ipModeTrainTypeManual: boolean; + ipModeTrainTypeHead: boolean; + ipModeTrainTypeSpecial: boolean; + ipModeTrainTypeSchedule: boolean; + ipModeTrainSchdEarly: boolean; + ipModeTrainSchdLate: boolean; + ipModeTrainSkipstop: boolean; + ipModeTrainCbtcMode: boolean; + ipModeTrainAtpCut: boolean; + ipModeTrainBerthed: boolean; + ipModeTrainHolded: boolean; + ipModeTrainDirUp: boolean; + ipModeTrainDirDown: boolean; + ipModeTrainDirHeadUp: boolean; + ipModeTrainDirHeadDown: boolean; + ipModeTrainDoorOpen: boolean; + ipModeTrainEbAlarm: boolean; + ipModeTrainIntegrityAlarm: boolean; + ipModeTrainDriveModeAm: boolean; + ipModeTrainDriveModeCm: boolean; + ipModeTrainDriveModeRmf: boolean; + ipModeTrainDriveModeAtb: boolean; + ipModeTrainDriveBlockAm: boolean; + ipModeTrainDriveBlockCm: boolean; + ipModeTrainDriveModeRmr: boolean; +} +export enum DevType { + DEVICE_TYPE_UNKNOW = 'DEVICE_TYPE_UNKNOW', + DEVICE_TYPE_RTU = 'DEVICE_TYPE_RTU', + DEVICE_TYPE_STATION = 'DEVICE_TYPE_STATION', + DEVICE_TYPE_SIGNAL = 'DEVICE_TYPE_SIGNAL', + DEVICE_TYPE_SWITCH = 'DEVICE_TYPE_SWITCH', + DEVICE_TYPE_TRACK = 'DEVICE_TYPE_TRACK', + DEVICE_TYPE_ENTRY = 'DEVICE_TYPE_ENTRY', + DEVICE_TYPE_PLATFORM = 'DEVICE_TYPE_PLATFORM', + DEVICE_TYPE_SCADA = 'DEVICE_TYPE_SCADA', + DEVICE_TYPE_WATERPROOF_DOOR = 'DEVICE_TYPE_WATERPROOF_DOOR', + DEVICE_TYPE_WORK_AREA = 'DEVICE_TYPE_WORK_AREA', + DEVICE_TYPE_GAMA = 'DEVICE_TYPE_GAMA', +} + +export function trainMockApi( + lineId: number, + data: { + groupId: string; + window: { + nccWindow: number; + nccWinOffset: number; + }; + mode: Mode; + devType: DevType; + devName: string; + type: boolean; + } +) { + return api.post(`${PublishUriBase}/offset/${lineId}`, data); +} + +export function removeTrainMockApi( + lineId: number, + data: { + lineId: number; + rtuId: number; + window: { + nccWindow: number; + nccWinOffset: number; + }; + deviceType: string; + devName: string; + trainIndex: string; + groupId: string; + } +) { + return api.post(`${PublishUriBase}/remove/${lineId}`, data); +} diff --git a/src/drawApp/graphics/TrainInteraction.ts b/src/drawApp/graphics/TrainInteraction.ts index 7f840e4..61a8280 100644 --- a/src/drawApp/graphics/TrainInteraction.ts +++ b/src/drawApp/graphics/TrainInteraction.ts @@ -12,6 +12,8 @@ import { JlGraphic, } from 'src/jl-graphic'; import { DisplayObject, FederatedMouseEvent } from 'pixi.js'; +import { DevType, removeTrainMockApi } from 'src/api/TrainApi'; +import { useLineStore } from 'src/stores/line-store'; export class TrainData extends GraphicDataBase implements ITrainData { constructor(data?: graphicData.Train) { @@ -58,7 +60,7 @@ export class TrainState extends GraphicStateBase implements ITrainState { } get code(): string { - return this.states.trainIndex; + return this.states.groupId; } get states(): train.TrainInfo { @@ -78,13 +80,10 @@ export class TrainState extends GraphicStateBase implements ITrainState { this.states.rtuId = v; } get window(): train.NccWindow { - if (!this.states.window) { - this.states.window = new train.NccWindow(); - } return this.states.window; } set window(v: train.NccWindow) { - this.states.window = v; + this.states.window = new train.NccWindow(v); } get devType(): number { return this.states.devType; @@ -98,10 +97,10 @@ export class TrainState extends GraphicStateBase implements ITrainState { set devName(v: string) { this.states.devName = v; } - get id(): string { + get trainIndex(): string { return this.states.trainIndex; } - set id(v: string) { + set trainIndex(v: string) { this.states.trainIndex = v; } get groupId(): string { @@ -147,13 +146,10 @@ export class TrainState extends GraphicStateBase implements ITrainState { 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; + this.states.mode = new state.TrainMode(v); } get arriveTime(): number { return this.states.arriveTime; @@ -195,19 +191,19 @@ export class TrainState extends GraphicStateBase implements ITrainState { return this.states.remove; } set remove(v: train.TrainRemove) { - this.states.remove = v; + this.states.remove = new train.TrainRemove(v); } get block(): train.TrainBlock { return this.states.block; } set block(v: train.TrainBlock) { - this.states.block = v; + this.states.block = new train.TrainBlock(v); } get record(): train.TrainRecord { return this.states.record; } set record(v: train.TrainRecord) { - this.states.record = v; + this.states.record = new train.TrainRecord(v); } clone(): TrainState { @@ -239,17 +235,21 @@ const openDoorConfig: MenuItemOptions = { const editGroupConfig: MenuItemOptions = { name: '修改车组号', }; +const removeTrainConfig: MenuItemOptions = { + name: '删除列车', +}; const TrainOperateMenu: ContextMenu = ContextMenu.init({ name: '列车操作菜单', groups: [ { items: [ - negativeDirectionConfig, - runStopConfig, - diriveModelConfig, - HoldTrainConfig, - openDoorConfig, - editGroupConfig, + // negativeDirectionConfig, + // runStopConfig, + // diriveModelConfig, + // HoldTrainConfig, + // openDoorConfig, + // editGroupConfig, + removeTrainConfig, ], }, ], @@ -268,49 +268,49 @@ export class TrainOperateInteraction extends GraphicInteractionPlugin { return grahpics.filter((g) => g.type === Train.Type).map((g) => g as Train); } bind(g: Train): void { - g.eventMode = 'static'; - g.cursor = 'pointer'; - g.selectable = true; + g.trainbody.eventMode = 'static'; + g.trainbody.cursor = 'pointer'; + g.trainbody.selectable = true; g.on('_rightclick', this.onContextMenu, this); } unbind(g: Train): void { - g.selectable = false; - g.eventMode = 'none'; + g.trainbody.eventMode = 'none'; + g.trainbody.selectable = false; g.off('_rightclick', this.onContextMenu, this); } onContextMenu(e: FederatedMouseEvent) { const target = e.target as DisplayObject; const train = target.getGraphic() as Train; - this.app.updateSelected(train); + const lineStore = useLineStore(); + const lineId = lineStore.lineId; negativeDirectionConfig.handler = () => { const mode = train.states.mode; - if (!train.states.mode.ipModeTrainDirUp) { + if (!mode.ipModeTrainDirUp) { mode.ipModeTrainDirUp = true; mode.ipModeTrainDirDown = false; - } else if (!train.states.mode.ipModeTrainDirDown) { + } else if (!mode.ipModeTrainDirDown) { mode.ipModeTrainDirUp = false; mode.ipModeTrainDirDown = true; } train.doRepaint(); }; runStopConfig.handler = () => { - train.states.mode.ipModeTrainStoped = - !train.states.mode.ipModeTrainStoped; + train.states.mode.ipModeTrainBerthed = + !train.states.mode.ipModeTrainBerthed; train.doRepaint(); }; diriveModelConfig.handler = () => { const arr = [ 'ipModeTrainDriveModeAm', 'ipModeTrainDriveModeCm', - 'ipModeTrainDriveBlockAm', - 'ipModeTrainDriveBlockCm', + 'ipModeTrainDriveModeRmf', ]; let findIndex = arr.findIndex((key) => { return train.states.mode[key]; }); - if (findIndex == 3) { + if (findIndex == 2) { findIndex = -1; } arr.forEach((key) => { @@ -334,6 +334,30 @@ export class TrainOperateInteraction extends GraphicInteractionPlugin { train.states.globalId = '3333'; train.doRepaint(); }; + removeTrainConfig.handler = () => { + const params = { + lineId: train.states.lineId, + rtuId: train.states.rtuId, + window: { + nccWindow: train.states.window.nccWindow, + nccWinOffset: train.states.window.nccWindow, + }, + deviceType: 'DEVICE_TYPE_TRACK', + devName: train.states.devName, + trainIndex: train.states.trainIndex, + groupId: train.states.groupId, + }; + if (lineId) { + removeTrainMockApi(lineId, params) + .then((res) => { + this.app.deleteGraphics(train); + console.log(res, '---res--'); + }) + .catch((err) => { + console.log(err, '---err---'); + }); + } + }; TrainOperateMenu.open(e.global); } } diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 7253a85..76577fd 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -4,9 +4,14 @@ import { StompCli, AppWsMsgBroker, GraphicState, + GraphicIdGenerator, } from 'src/jl-graphic'; -import { TrainData, TrainState } from './graphics/TrainInteraction'; -import { TrainTemplate } from 'src/graphics/train/Train'; +import { + TrainData, + TrainOperateInteraction, + TrainState, +} from './graphics/TrainInteraction'; +import { Train, TrainTemplate } from 'src/graphics/train/Train'; import { SignalData, SignalOperateInteraction, @@ -48,7 +53,6 @@ import { import { TrainWindowData } from './graphics/TrainWindowInteraction'; import { SeparatorTemplate } from 'src/graphics/separator/Separator'; import { SeparatorData } from './graphics/SeparatorInteraction'; -import { train } from 'src/protos/train'; let lineApp: GraphicApp | null = null; let msgBroker: AppWsMsgBroker | null = null; @@ -92,12 +96,14 @@ export function initLineApp(dom: HTMLElement): GraphicApp { Signal.Type, Platform.Type, Station.Type, + Train.Type, ], }, }); SignalOperateInteraction.init(lineApp); PlatformOperateInteraction.init(lineApp); StationOperateInteraction.init(lineApp); + TrainOperateInteraction.init(lineApp); return lineApp; } diff --git a/src/graphics/separator/Separator.ts b/src/graphics/separator/Separator.ts index 032ee1e..93417c0 100644 --- a/src/graphics/separator/Separator.ts +++ b/src/graphics/separator/Separator.ts @@ -19,7 +19,7 @@ export enum separatorTypeEnum { } export const SeparatorConsts = { - height: 15, + height: 12, lineWidth: 2, lineColor: '0x617799', circleColor: '0xEF0200', diff --git a/src/graphics/train/Train.ts b/src/graphics/train/Train.ts index 0d11a04..18fd923 100644 --- a/src/graphics/train/Train.ts +++ b/src/graphics/train/Train.ts @@ -1,6 +1,7 @@ -import { Color, Graphics, Container, Point } from 'pixi.js'; +import { Graphics, Container, Point } from 'pixi.js'; import { GraphicData, + GraphicIdGenerator, GraphicState, JlGraphic, JlGraphicTemplate, @@ -9,6 +10,7 @@ import { } from 'src/jl-graphic'; import { train } from 'src/protos/train'; import { state } from 'src/protos/device_status'; +import { TrainWindow } from '../trainWindow/TrainWindow'; export interface ITrainData extends GraphicData { get code(): string; // 车号 @@ -29,8 +31,8 @@ export interface ITrainState extends GraphicState { set devType(v: state.DeviceType); get devName(): string; // 所在设备名称 set devName(v: string); - get id(): string; // 设备唯一,与trainIndex相同 - set id(v: string); + get trainIndex(): string; // 设备唯一,与trainIndex相同 + set trainIndex(v: string); get groupId(): string; // 列车车组号 set groupId(v: string); get trainId(): string; // 列车表号 @@ -88,12 +90,10 @@ enum DiriveModelColorEnum { // 驾驶模式对应颜色 NRM = '0xA0522D', // 非限制人工驾驶模式 red = '0xF80103', // 红色表示通信中断 } -enum AAColorEnum { // 识别号AA颜色 +enum BBBColorEnum { // 识别号颜色 accuracy = '0xffffff', // 准点 early = '0x00FF00', // 早点 - late = '0xA0522D', // 晚点 -} -enum typeColorEnum { // 识别号BBB颜色 + late = '0xFFFF00', // 晚点 schedule = '0xffffff', // 计划车 head = '0xE9FC01', // 头码车 manual = '0xE9FC01', // 人工车 @@ -136,10 +136,10 @@ export class TrainHead extends Container { } doRepaint(states: ITrainState, bodyWH?: bodyWH) { let direction = ''; - if (states.mode?.ipModeTrainDirUp) { + if (states.mode?.ipModeTrainDirDown) { direction = 'left'; } - if (states.mode?.ipModeTrainDirDown) { + if (states.mode?.ipModeTrainDirUp) { direction = 'right'; } this.clear(); @@ -189,14 +189,14 @@ export class TrainHead extends Container { if (states.mode?.ipModeTrainDriveModeCm) { aColor = DiriveModelColorEnum.SM; pColor = DiriveModelColorEnum.SM; - } else if (states.mode?.ipModeTrainDriveBlockAm) { + } else if ( + states.mode?.ipModeTrainDriveModeRmf || + states.mode?.ipModeTrainDriveModeRmr + ) { aColor = DiriveModelColorEnum.RM; pColor = DiriveModelColorEnum.RM; - } else if (states.mode?.ipModeTrainDriveBlockCm) { - aColor = DiriveModelColorEnum.NRM; - pColor = DiriveModelColorEnum.NRM; } - if (states.mode?.ipModeTrainStoped) { + if (states.mode?.ipModeTrainBerthed) { this.pause.lineStyle(pauseW, pColor, 1); this.pause.moveTo(pausePoint[0], pausePoint[1]); this.pause.lineTo(pausePoint[2], pausePoint[3]); @@ -210,27 +210,27 @@ export class TrainHead extends Container { } export class TrainBody extends Container { - codeRact: Graphics; + // codeRact: Graphics; codeAGraph: VectorText = new VectorText(''); //识别号AA codeBGraph: VectorText = new VectorText(''); //识别号BBB constructor() { super(); - this.codeRact = new Graphics(); - this.addChild(this.codeRact); + // this.codeRact = new Graphics(); + // this.addChild(this.codeRact); this.addChild(this.codeAGraph); this.addChild(this.codeBGraph); this.codeAGraph.setVectorFontSize(trainConsts.codeFontSize); this.codeBGraph.setVectorFontSize(trainConsts.codeFontSize); } clear() { - this.codeRact.clear(); + // this.codeRact.clear(); } getBodyWH(): bodyWH { const bodyAWH = this.codeAGraph.getLocalBounds(); const bodyBWH = this.codeBGraph.getLocalBounds(); return { - width: bodyAWH.width + bodyBWH.width + trainConsts.codePadding * 2, - height: bodyAWH.height + trainConsts.codePadding * 2, + width: bodyAWH.width + bodyBWH.width, + height: bodyAWH.height, }; } @@ -238,27 +238,28 @@ export class TrainBody extends Container { this.clear(); const codeAGraph = this.codeAGraph; const codeBGraph = this.codeBGraph; - const codeRact = this.codeRact; - let codeA = states?.trainId; - let fillAColor = AAColorEnum.accuracy; - if (states.mode?.ipModeTrainSchdLate) { - fillAColor = AAColorEnum.late; - } else if (states.mode?.ipModeTrainSchdEarly) { - fillAColor = AAColorEnum.early; - } - let fillBColor = typeColorEnum.schedule; - if (states.mode?.ipModeTrainTypeHead) { + // const codeRact = this.codeRact; + let codeA = states?.groupId; + const fillAColor = BBBColorEnum.schedule; + let fillBColor = BBBColorEnum.schedule; + if (states.mode?.ipModeTrainTypeSchedule) { + if (states.mode?.ipModeTrainSchdLate) { + fillBColor = BBBColorEnum.late; + } else if (states.mode?.ipModeTrainSchdEarly) { + fillBColor = BBBColorEnum.early; + } + } else if (states.mode?.ipModeTrainTypeHead) { codeA = states?.destinationId + ''; - fillBColor = typeColorEnum.head; + fillBColor = BBBColorEnum.head; } else if (states.mode?.ipModeTrainTypeManual) { codeA = 'MM'; - fillBColor = typeColorEnum.manual; + fillBColor = BBBColorEnum.manual; } else if (states.mode?.ipModeTrainTypeSpecial) { codeA = ''; } const codeB = states?.globalId; codeAGraph.text = codeA || '01'; - codeBGraph.text = codeB || '2222'; + codeBGraph.text = codeB || '222'; codeAGraph.anchor.set(0.5); codeBGraph.anchor.set(0.5); const styleA = { @@ -277,10 +278,10 @@ export class TrainBody extends Container { codeBGraph.position.set(bodyAWH.width / 2, 0); codeAGraph.updateOnScaled(); codeBGraph.updateOnScaled(); - const { width: codeWidth, height: codeHeight } = this.getBodyWH(); - codeRact.beginFill(new Color(TrainColorEnum.bodyColor)); - codeRact.drawRect(-codeWidth / 2, -codeHeight / 2, codeWidth, codeHeight); - codeRact.endFill(); + // const { width: codeWidth, height: codeHeight } = this.getBodyWH(); + // codeRact.beginFill(new Color(TrainColorEnum.bodyColor)); + // codeRact.drawRect(-codeWidth / 2, -codeHeight / 2, codeWidth, codeHeight); + // codeRact.endFill(); } } @@ -342,6 +343,10 @@ export class Train extends JlGraphic { return this.getStates(); } + get code(): string { + return this.states.code; + } + doRepaint(): void { this.trainbody.doRepaint(this.states); const bodyWH = this.trainbody.getBodyWH(); @@ -366,6 +371,7 @@ export class Train extends JlGraphic { } else { this.hideStatus('A'); } + this.setPosition(); } showStatus(s: string) { @@ -388,6 +394,14 @@ export class Train extends JlGraphic { this.statusTextMap.delete(s); } } + setPosition(): void { + const wId = this.states.window?.nccWindow; + if (wId) { + const window = this.queryStore.queryById(wId + ''); + const p = window.getPositionOnCanvas(); + this.position.set(p.x, p.y); + } + } } export class TrainTemplate extends JlGraphicTemplate { @@ -396,7 +410,7 @@ export class TrainTemplate extends JlGraphicTemplate { } new(): Train { const train = new Train(); - train.loadData(this.datas); + train.id = GraphicIdGenerator.next(); train.loadState(this.states); return train; }