From e02581b1de4eed087408fbeab83c453708fb4409 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Fri, 14 Jul 2023 14:20:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4proto=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/graphics/TrainInteraction.ts | 38 +------------- src/drawApp/index.ts | 30 ++--------- src/drawApp/lineApp.ts | 67 ++++++++++++++++++------ src/graphics/train/Train.ts | 4 +- 4 files changed, 59 insertions(+), 80 deletions(-) diff --git a/src/drawApp/graphics/TrainInteraction.ts b/src/drawApp/graphics/TrainInteraction.ts index 687e8bc..a76ec3e 100644 --- a/src/drawApp/graphics/TrainInteraction.ts +++ b/src/drawApp/graphics/TrainInteraction.ts @@ -1,7 +1,6 @@ import * as pb_1 from 'google-protobuf'; -import { ITrainData, ITrainState, Train } from 'src/graphics/train/Train'; -import { graphicData } from 'src/protos/stationLayoutGraphics'; -import { GraphicDataBase, GraphicStateBase } from './GraphicDataBase'; +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 { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; @@ -13,39 +12,6 @@ import { } from 'src/jl-graphic'; import { DisplayObject, FederatedMouseEvent } from 'pixi.js'; -export class TrainData extends GraphicDataBase implements ITrainData { - constructor(data?: graphicData.Train) { - let train; - if (!data) { - train = new graphicData.Train({ - common: GraphicDataBase.defaultCommonInfo(Train.Type), - }); - } else { - train = data; - } - super(train); - } - - public get data(): graphicData.Train { - return this.getData(); - } - get code(): string { - return this.data.code; - } - set code(v: string) { - this.data.code = v; - } - clone(): TrainData { - return new TrainData(this.data.cloneMessage()); - } - copyFrom(data: TrainData): void { - pb_1.Message.copyInto(data.data, this.data); - } - eq(other: TrainData): boolean { - return pb_1.Message.equals(this.data, other.data); - } -} - export class TrainState extends GraphicStateBase implements ITrainState { constructor(proto?: train.TrainInfo) { let states; diff --git a/src/drawApp/index.ts b/src/drawApp/index.ts index 32ba6a1..9514ae4 100644 --- a/src/drawApp/index.ts +++ b/src/drawApp/index.ts @@ -1,6 +1,5 @@ import { fromUint8Array, toUint8Array } from 'js-base64'; -import { Link } from 'src/graphics/link/Link'; -import { Train, TrainTemplate } from 'src/graphics/train/Train'; +import { TrainTemplate } from 'src/graphics/train/Train'; import { TrainDraw } from 'src/graphics/train/TrainDrawAssistant'; import { Signal, SignalTemplate } from 'src/graphics/signal/Signal'; import { SignalDraw } from 'src/graphics/signal/SignalDrawAssistant'; @@ -14,17 +13,14 @@ import { } from 'src/jl-graphic'; import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; -import { LinkData } from './graphics/LinkInteraction'; -import { TrainData, TrainState } from './graphics/TrainInteraction'; +import { TrainState } from './graphics/TrainInteraction'; import { SignalData, DrawSignalInteraction, SignalState, } from './graphics/SignalInteraction'; import { graphicData } from 'src/protos/stationLayoutGraphics'; -import { Rect } from 'src/graphics/rect/Rect'; import { RectDraw } from 'src/graphics/rect/RectDrawAssistant'; -import { RectData } from './graphics/RectInteraction'; import { Platform, PlatformTemplate } from 'src/graphics/platform/Platform'; import { PlatformData, PlatformState } from './graphics/PlatformInteraction'; import { PlatformDraw } from 'src/graphics/platform/PlatformDrawAssistant'; @@ -210,7 +206,7 @@ export function initDrawApp(dom: HTMLElement): JlDrawApp { app, new SignalTemplate(new SignalData(), new SignalState()) ), - new TrainDraw(app, new TrainTemplate(new TrainData(), new TrainState())), + new TrainDraw(app, new TrainTemplate(new TrainState())), new SectionDraw(app, new SectionTemplate(new SectionData())), new TurnoutDraw( app, @@ -350,21 +346,12 @@ export function saveDrawDatas(app: JlDrawApp) { }); const graphics = app.queryStore.getAllGraphics(); graphics.forEach((g) => { - if (Link.Type === g.type) { - const linkData = (g as Link).saveData(); - storage.links.push((linkData as LinkData).data); - } else if (Rect.Type === g.type) { - const rectData = (g as Rect).saveData(); - storage.rects.push((rectData as RectData).data); - } else if (Platform.Type === g.type) { + if (Platform.Type === g.type) { const platformData = (g as Platform).saveData(); storage.Platforms.push((platformData as PlatformData).data); } else if (Station.Type === g.type) { const stationData = (g as Station).saveData(); storage.stations.push((stationData as StationData).data); - } else if (Train.Type === g.type) { - const trainData = (g as Train).saveData(); - storage.train.push((trainData as TrainData).data); } else if (Turnout.Type === g.type) { const turnoutData = (g as Turnout).saveData(); storage.turnouts.push((turnoutData as TurnoutData).data); @@ -418,21 +405,12 @@ export async function loadDrawDatas(app: GraphicApp) { ); app.updateCanvas(storage.canvas); const datas: GraphicData[] = []; - storage.links.forEach((link) => { - datas.push(new LinkData(link)); - }); - storage.rects.forEach((rect) => { - datas.push(new RectData(rect)); - }); storage.Platforms.forEach((platform) => { datas.push(new PlatformData(platform)); }); storage.stations.forEach((station) => { datas.push(new StationData(station)); }); - storage.train.forEach((train) => { - datas.push(new TrainData(train)); - }); storage.turnouts.forEach((turnout) => { datas.push(new TurnoutData(turnout)); }); diff --git a/src/drawApp/lineApp.ts b/src/drawApp/lineApp.ts index 3ecfa47..17692bd 100644 --- a/src/drawApp/lineApp.ts +++ b/src/drawApp/lineApp.ts @@ -5,7 +5,7 @@ import { AppWsMsgBroker, GraphicState, } from 'src/jl-graphic'; -import { TrainData, TrainState } from './graphics/TrainInteraction'; +import { TrainState } from './graphics/TrainInteraction'; import { TrainTemplate } from 'src/graphics/train/Train'; import { SignalData, @@ -35,7 +35,7 @@ import { useLineStore } from 'src/stores/line-store'; import { toUint8Array } from 'js-base64'; import { getWebsocketUrl } from 'src/configs/UrlManage'; import { getJwtToken } from 'src/configs/TokenManage'; -import { state } from 'src/protos/ws_message'; +import { state } from 'src/protos/device_state'; import { AxleCounting, AxleCountingTemplate, @@ -68,7 +68,7 @@ export function destroyLineApp(): void { export function initLineApp(dom: HTMLElement): GraphicApp { lineApp = new GraphicApp(dom); const graphicTemplate = [ - new TrainTemplate(new TrainData(), new TrainState()), + new TrainTemplate(new TrainState()), new SignalTemplate(new SignalData(), new SignalState()), new PlatformTemplate(new PlatformData(), new PlatformState()), new StationTemplate(new StationData(), new StationState()), @@ -124,9 +124,6 @@ export async function loadLineDatas(app: GraphicApp) { storage.stations.forEach((station) => { datas.push(new StationData(station)); }); - storage.train.forEach((train) => { - datas.push(new TrainData(train)); - }); storage.turnouts.forEach((turnout) => { datas.push(new TurnoutData(turnout)); }); @@ -167,16 +164,54 @@ export async function loadLineDatas(app: GraphicApp) { msgBroker.subscribe({ destination: `/simulation/${simulationId}/devices/status`, messageConverter: (message: Uint8Array) => { - const storage = state.WsLineMessage.deserialize(message); - storage.signal.forEach((item) => { - states.push(new SignalState(item)); - }); - storage.platform.forEach((item) => { - states.push(new PlatformState(item)); - }); - storage.rtu.forEach((item) => { - states.push(new StationState(item)); - }); + const storage = state.PushedDevicesStatus.deserialize(message); + if (storage.all) { + storage.allStatus.sectionState.forEach((item) => { + if (state.SectionType[item.type] == 'Axle') { + //计轴区段 + // states.push(new AxleCountingState(item)); + } else if (state.SectionType[item.type] == 'Logic') { + // 逻辑区段 + // states.push(new LogicSectionState(item)); + } else if (state.SectionType[item.type] == 'Physic') { + // 物理区段 + // states.push(new SectionState(item)); + } + }); + storage.allStatus.switchState.forEach((item) => { + // 道岔 + // states.push(new TurnoutState(item)); + }); + storage.allStatus.trainState.forEach((item) => { + // 列车 + // states.push(new TrainState(item)); + }); + } else { + storage.varStatus.updatedSection.forEach((item) => { + if (state.SectionType[item.type] == 'Axle') { + //计轴区段 + // states.push(new AxleCountingState(item)); + } else if (state.SectionType[item.type] == 'Logic') { + // 逻辑区段 + // states.push(new LogicSectionState(item)); + } else if (state.SectionType[item.type] == 'Physic') { + // 物理区段 + // states.push(new SectionState(item)); + } + }); + storage.varStatus.updatedSwitch.forEach((item) => { + // 道岔 + // states.push(new TurnoutState(item)); + }); + storage.varStatus.updatedTrain.forEach((item) => { + // 列车 + // states.push(new TrainState(item)); + }); + storage.varStatus.removedTrainId.forEach((item) => { + // 移除列车 + // states.push(new TrainState(item)); + }); + } return states; }, }); diff --git a/src/graphics/train/Train.ts b/src/graphics/train/Train.ts index d432abf..71a511a 100644 --- a/src/graphics/train/Train.ts +++ b/src/graphics/train/Train.ts @@ -412,8 +412,8 @@ export class Train extends JlGraphic { } export class TrainTemplate extends JlGraphicTemplate { - constructor(dataTemplate: ITrainData, stateTemplate: ITrainState) { - super(Train.Type, { dataTemplate, stateTemplate }); + constructor(stateTemplate: ITrainState) { + super(Train.Type, { stateTemplate }); } new(): Train { const train = new Train();