调整proto对应的数据

This commit is contained in:
dong 2023-07-14 14:20:12 +08:00
parent 507ddc5c45
commit e02581b1de
4 changed files with 59 additions and 80 deletions

View File

@ -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<graphicData.Train>();
}
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;

View File

@ -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));
});

View File

@ -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;
},
});

View File

@ -412,8 +412,8 @@ export class Train extends JlGraphic {
}
export class TrainTemplate extends JlGraphicTemplate<Train> {
constructor(dataTemplate: ITrainData, stateTemplate: ITrainState) {
super(Train.Type, { dataTemplate, stateTemplate });
constructor(stateTemplate: ITrainState) {
super(Train.Type, { stateTemplate });
}
new(): Train {
const train = new Train();