线网调整

This commit is contained in:
fan 2023-06-30 16:17:00 +08:00
parent bc2de121ab
commit c9dabfe457
12 changed files with 299 additions and 51 deletions

View File

@ -1,8 +1,20 @@
<template>
<q-form>
<q-input outlined readonly v-model="runLineModel.id" label="id" hint="" />
<q-select
outlined
style="margin-top: 10px"
v-model="runLineModel.lineId"
:options="lineList"
:map-options="true"
:emit-value="true"
@update:model-value="onUpdate"
label="关联线路"
>
</q-select>
<q-input
outlined
style="margin-top: 10px"
v-model="runLineModel.code"
@blur="onUpdate"
label="名称"
@ -10,6 +22,7 @@
<q-input
outlined
v-model="runLineModel.nameColor"
style="margin-top: 10px"
@blur="onUpdate"
label="名称颜色"
lazy-rules
@ -108,16 +121,18 @@
import { RunLineData } from 'src/drawApp/graphics/RunLineInteraction';
import { RunLine } from 'src/graphics/runLine/RunLine';
import { useDrawStore } from 'src/stores/draw-store';
import { onMounted, reactive, watch } from 'vue';
import { onMounted, reactive, watch, ref } from 'vue';
import { Point } from 'pixi.js';
import {
IStationLineData,
StationLine,
} from 'src/graphics/stationLine/StationLine';
import { getLineList } from 'src/api/LineInfoApi';
const drawStore = useDrawStore();
const runLineModel = reactive(new RunLineData());
const stationLines: IStationLineData[] = reactive([]);
const lineList: { label: string; value: string }[] = reactive([]);
drawStore.$subscribe;
watch(
@ -130,6 +145,15 @@ watch(
);
onMounted(() => {
getLineList()
.then((res) => {
res.forEach((item) => {
lineList.push({ value: item.lineId + '', label: item.name });
});
})
.catch((err) => {
console.error('获取线路列表失败:' + err.message);
});
const runLine = drawStore.selectedGraphic as RunLine;
const stations = drawStore
.getDrawApp()

View File

@ -130,33 +130,24 @@ export abstract class GraphicDataBase implements GraphicData {
return pb_1.Message.equals(this._data, other._data);
}
}
export interface IProtoGraphicState extends pb_1.Message {
id: string;
}
export abstract class GraphicStateBase implements GraphicState {
_graphicType: string;
_state: IProtoGraphicState;
constructor(state: IProtoGraphicState, graphicType: string) {
_state: pb_1.Message;
constructor(state: pb_1.Message, graphicType: string) {
this._state = state;
this._graphicType = graphicType;
}
getState<S extends IProtoGraphicState>(): S {
abstract get code(): string;
abstract copyFrom(data: GraphicState): void;
abstract eq(data: GraphicState): boolean;
getState<S extends pb_1.Message>(): S {
return this._state as S;
}
get code(): string {
return this._state.id;
}
get graphicType(): string {
return this._graphicType;
}
clone(): GraphicState {
throw new Error('Method not implemented.');
}
copyFrom(data: GraphicStateBase): void {
pb_1.Message.copyInto(data._state, this._state);
}
eq(data: GraphicStateBase): boolean {
return pb_1.Message.equals(this._state, data._state);
}
}

View File

@ -82,6 +82,18 @@ export class RunLineData extends GraphicDataBase implements IRunLineData {
set containSta(v: string[]) {
this.data.containSta = v;
}
get linkPathLines(): string[] {
return this.data.linkPathLines;
}
set linkPathLines(v: string[]) {
this.data.linkPathLines = v;
}
get lineId(): string {
return this.data.lineId;
}
set lineId(v: string) {
this.data.lineId = v;
}
clone(): RunLineData {
return new RunLineData(this.data.cloneMessage());
}

View File

@ -71,7 +71,9 @@ export class SignalState extends GraphicStateBase implements ISignalState {
}
super(states, Signal.Type);
}
get code(): string {
return this.states.id;
}
get redOpen(): boolean {
return this.states.redOpen;
}
@ -214,10 +216,15 @@ export class SignalState extends GraphicStateBase implements ISignalState {
get states(): state.Signal {
return this.getState<state.Signal>();
}
clone(): SignalState {
return new SignalState(this.states.cloneMessage());
}
copyFrom(data: GraphicStateBase): void {
pb_1.Message.copyInto(data._state, this._state);
}
eq(data: GraphicStateBase): boolean {
return pb_1.Message.equals(this._state, data._state);
}
}
const mirrorFlipConfig: MenuItemOptions = {

View File

@ -1,7 +1,12 @@
import * as pb_1 from 'google-protobuf';
import { ITrainLineData, TrainLine } from 'src/graphics/trainLine/TrainLine';
import {
ITrainLineData,
TrainLine,
ITrainLineState,
} from 'src/graphics/trainLine/TrainLine';
import { graphicData } from 'src/protos/stationLayoutGraphics';
import { GraphicDataBase } from './GraphicDataBase';
import { GraphicDataBase, GraphicStateBase } from './GraphicDataBase';
import { state } from 'src/protos/ws_message';
export class TrainLineData extends GraphicDataBase implements ITrainLineData {
constructor(data?: graphicData.TrainLine) {
@ -36,3 +41,70 @@ export class TrainLineData extends GraphicDataBase implements ITrainLineData {
return pb_1.Message.equals(this.data, other.data);
}
}
export class TrainLineState
extends GraphicStateBase
implements ITrainLineState
{
constructor(proto?: state.WsLineNetTrainOffsetMessage) {
let states;
if (proto) {
states = proto;
} else {
states = new state.WsLineNetTrainOffsetMessage();
}
super(states, TrainLine.Type);
}
get code(): string {
return this.states.groupId;
}
get lineId(): number {
return this.states.lineId;
}
set lineId(v: number) {
this.states.lineId = v;
}
get trainIndex(): string {
return this.states.trainIndex;
}
set trainIndex(v: string) {
this.states.trainIndex = v;
}
get groupId(): string {
return this.states.groupId;
}
set groupId(v: string) {
this.states.groupId = v;
}
get show(): boolean {
return this.states.show;
}
set show(v: boolean) {
this.states.show = v;
}
get kilometerCode(): number {
return this.states.kilometerCode;
}
set kilometerCode(v: number) {
this.states.kilometerCode = v;
}
get dir(): number {
return this.states.dir;
}
set dir(v: number) {
this.states.dir = v;
}
get states(): state.WsLineNetTrainOffsetMessage {
return this.getState<state.WsLineNetTrainOffsetMessage>();
}
clone(): TrainLineState {
return new TrainLineState(this.states.cloneMessage());
}
copyFrom(data: GraphicStateBase): void {
pb_1.Message.copyInto(data._state, this._state);
}
eq(data: GraphicStateBase): boolean {
return pb_1.Message.equals(this._state, data._state);
}
}

View File

@ -363,6 +363,9 @@ export async function loadDrawDatas(app: GraphicApp) {
datas.push(new SignalData(signal));
});
storage.runLines.forEach((runLine) => {
runLine.linkPathLines = [runLine.upPathLineId, runLine.downPathLineId];
runLine.upPathLineId = '';
runLine.downPathLineId = '';
datas.push(new RunLineData(runLine));
});
storage.section.forEach((section) => {

View File

@ -22,7 +22,7 @@ import {
} from 'src/graphics/stationLine/StationLine';
import { StationLineData } from './graphics/StationLineInteraction';
import { ItrainLineTemplate } from 'src/graphics/trainLine/TrainLine';
import { TrainLineData } from './graphics/TrainLineInteraction';
import { TrainLineData, TrainLineState } from './graphics/TrainLineInteraction';
import { RectTemplate } from 'src/graphics/rect/Rect';
import { RectData } from './graphics/RectInteraction';
@ -32,6 +32,7 @@ import { getWebsocketUrl } from 'src/configs/UrlManage';
import { getJwtToken } from 'src/configs/TokenManage';
let lineNetApp: GraphicApp | null = null;
let msgBroker: AppWsMsgBroker | null = null;
export function getLineNetApp(): GraphicApp | null {
return lineNetApp;
@ -42,6 +43,9 @@ export function destroyLineNetApp(): void {
lineNetApp.destroy();
lineNetApp = null;
}
if (msgBroker) {
msgBroker.close();
}
}
export function initLineNetApp(dom: HTMLElement): GraphicApp {
@ -50,7 +54,7 @@ export function initLineNetApp(dom: HTMLElement): GraphicApp {
new RunLineTemplate(new RunLineData()),
new PathLineTemplate(new PathLineData()),
new StationLineTemplate(new StationLineData()),
new ItrainLineTemplate(new TrainLineData()),
new ItrainLineTemplate(new TrainLineData(), new TrainLineState()),
new RectTemplate(new RectData()),
];
lineNetApp.registerGraphicTemplates(...graphicTemplate);
@ -79,8 +83,8 @@ export async function loadLineNetDatas(app: GraphicApp) {
console.log('加载数据', storage);
app.updateCanvas(storage.canvas);
const datas: GraphicData[] = [];
storage.runLines.forEach((runLines) => {
const g = new RunLineData(runLines);
storage.runLines.forEach((runLine) => {
const g = new RunLineData(runLine);
datas.push(g);
});
storage.pathLines.forEach((pathLine) => {
@ -105,20 +109,22 @@ export async function loadLineNetDatas(app: GraphicApp) {
pathLine.visible = false;
});
// StompCli.new({
// wsUrl: `${getWebsocketUrl()}`,
// token: getJwtToken() as string,
// });
// // export type MessageConverter = (message: Uint8Array) => GraphicState[];
// const msgBroker = new AppWsMsgBroker(app);
// const states: GraphicState[] = [];
// msgBroker.subscribe({
// destination: '/queue/lineNet',
// messageConverter: (message: Uint8Array) => {
// const storage = state.WsLineNetMessage.deserialize(message);
// storage.offset.forEach((item) => {});
// },
// });
StompCli.new({
wsUrl: `${getWebsocketUrl()}`,
token: getJwtToken() as string,
});
msgBroker = new AppWsMsgBroker(app);
const states: GraphicState[] = [];
msgBroker.subscribe({
destination: '/queue/lineNet',
messageConverter: (message: Uint8Array) => {
const storage = state.WsLineNetMessage.deserialize(message);
storage.offset.forEach((item) => {
states.push(new TrainLineState(item));
});
return states;
},
});
} else {
app.loadGraphic([]);
}

View File

@ -30,6 +30,10 @@ export interface IRunLineData extends GraphicData {
set downPathLineId(v: string);
get containSta(): string[];
set containSta(v: string[]);
get linkPathLines(): string[];
set linkPathLines(v: string[]);
get lineId(): string;
set lineId(v: string);
clone(): IRunLineData;
copyFrom(data: IRunLineData): void;

View File

@ -1,4 +1,10 @@
import { GraphicData, JlGraphic, JlGraphicTemplate } from 'src/jl-graphic';
import {
GraphicData,
GraphicState,
GraphicIdGenerator,
JlGraphic,
JlGraphicTemplate,
} from 'src/jl-graphic';
import trainLineSprites from './trainLineSprites.png';
import { Assets, Sprite, Texture } from 'pixi.js';
@ -8,6 +14,21 @@ export interface ITrainLineData extends GraphicData {
set code(v: string);
}
export interface ITrainLineState extends GraphicState {
get lineId(): number;
set lineId(v: number);
get trainIndex(): string;
set trainIndex(v: string);
get groupId(): string;
set groupId(v: string);
get show(): boolean;
set show(v: boolean);
get kilometerCode(): number;
set kilometerCode(v: number);
get dir(): number;
set dir(v: number);
}
export class TrainLine extends JlGraphic {
static Type = 'TrainLine';
train: Sprite;
@ -22,21 +43,34 @@ export class TrainLine extends JlGraphic {
this.train.scale.set(0.02, 0.02);
this.addChild(this.train);
}
get states(): ITrainLineState {
return this.getStates<ITrainLineState>();
}
doRepaint(): void {
this.train.texture = this.trainTextures;
console.log(this.states, '****');
this.train.position.set(100, 100);
const runLine = this.queryStore.queryById(this.states.lineId + '');
}
}
export class ItrainLineTemplate extends JlGraphicTemplate<TrainLine> {
trainTextures?: Texture;
constructor(dataTemplate: ITrainLineData) {
constructor(dataTemplate: ITrainLineData, stateTemplate: ITrainLineState) {
super(TrainLine.Type, {
dataTemplate,
stateTemplate,
});
}
new(): TrainLine {
if (this.trainTextures) {
return new TrainLine(this.trainTextures);
const data = this.datas as GraphicData;
data.id = GraphicIdGenerator.next();
data.graphicType = this.type;
const g = new TrainLine(this.trainTextures);
g.loadData(data);
g.loadState(this.states);
return g;
}
throw new Error('资源未加载/加载失败');
}

View File

@ -193,11 +193,13 @@ export namespace state {
constructor(data?: any[] | {
id?: string;
code?: string;
switchKilometerSystem?: dependency_1.graphicData.KilometerSystem;
switchConvertKilometer?: number;
kilometerSystem?: dependency_1.graphicData.KilometerSystem[];
convertKilometer?: number[];
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [3, 4], this.#one_of_decls);
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [5, 6], this.#one_of_decls);
if (!Array.isArray(data) && typeof data == "object") {
if ("id" in data && data.id != undefined) {
this.id = data.id;
@ -205,6 +207,12 @@ export namespace state {
if ("code" in data && data.code != undefined) {
this.code = data.code;
}
if ("switchKilometerSystem" in data && data.switchKilometerSystem != undefined) {
this.switchKilometerSystem = data.switchKilometerSystem;
}
if ("switchConvertKilometer" in data && data.switchConvertKilometer != undefined) {
this.switchConvertKilometer = data.switchConvertKilometer;
}
if ("kilometerSystem" in data && data.kilometerSystem != undefined) {
this.kilometerSystem = data.kilometerSystem;
}
@ -225,21 +233,38 @@ export namespace state {
set code(value: string) {
pb_1.Message.setField(this, 2, value);
}
get switchKilometerSystem() {
return pb_1.Message.getWrapperField(this, dependency_1.graphicData.KilometerSystem, 3) as dependency_1.graphicData.KilometerSystem;
}
set switchKilometerSystem(value: dependency_1.graphicData.KilometerSystem) {
pb_1.Message.setWrapperField(this, 3, value);
}
get has_switchKilometerSystem() {
return pb_1.Message.getField(this, 3) != null;
}
get switchConvertKilometer() {
return pb_1.Message.getFieldWithDefault(this, 4, 0) as number;
}
set switchConvertKilometer(value: number) {
pb_1.Message.setField(this, 4, value);
}
get kilometerSystem() {
return pb_1.Message.getRepeatedWrapperField(this, dependency_1.graphicData.KilometerSystem, 3) as dependency_1.graphicData.KilometerSystem[];
return pb_1.Message.getRepeatedWrapperField(this, dependency_1.graphicData.KilometerSystem, 5) as dependency_1.graphicData.KilometerSystem[];
}
set kilometerSystem(value: dependency_1.graphicData.KilometerSystem[]) {
pb_1.Message.setRepeatedWrapperField(this, 3, value);
pb_1.Message.setRepeatedWrapperField(this, 5, value);
}
get convertKilometer() {
return pb_1.Message.getFieldWithDefault(this, 4, []) as number[];
return pb_1.Message.getFieldWithDefault(this, 6, []) as number[];
}
set convertKilometer(value: number[]) {
pb_1.Message.setField(this, 4, value);
pb_1.Message.setField(this, 6, value);
}
static fromObject(data: {
id?: string;
code?: string;
switchKilometerSystem?: ReturnType<typeof dependency_1.graphicData.KilometerSystem.prototype.toObject>;
switchConvertKilometer?: number;
kilometerSystem?: ReturnType<typeof dependency_1.graphicData.KilometerSystem.prototype.toObject>[];
convertKilometer?: number[];
}): Switch {
@ -250,6 +275,12 @@ export namespace state {
if (data.code != null) {
message.code = data.code;
}
if (data.switchKilometerSystem != null) {
message.switchKilometerSystem = dependency_1.graphicData.KilometerSystem.fromObject(data.switchKilometerSystem);
}
if (data.switchConvertKilometer != null) {
message.switchConvertKilometer = data.switchConvertKilometer;
}
if (data.kilometerSystem != null) {
message.kilometerSystem = data.kilometerSystem.map(item => dependency_1.graphicData.KilometerSystem.fromObject(item));
}
@ -262,6 +293,8 @@ export namespace state {
const data: {
id?: string;
code?: string;
switchKilometerSystem?: ReturnType<typeof dependency_1.graphicData.KilometerSystem.prototype.toObject>;
switchConvertKilometer?: number;
kilometerSystem?: ReturnType<typeof dependency_1.graphicData.KilometerSystem.prototype.toObject>[];
convertKilometer?: number[];
} = {};
@ -271,6 +304,12 @@ export namespace state {
if (this.code != null) {
data.code = this.code;
}
if (this.switchKilometerSystem != null) {
data.switchKilometerSystem = this.switchKilometerSystem.toObject();
}
if (this.switchConvertKilometer != null) {
data.switchConvertKilometer = this.switchConvertKilometer;
}
if (this.kilometerSystem != null) {
data.kilometerSystem = this.kilometerSystem.map((item: dependency_1.graphicData.KilometerSystem) => item.toObject());
}
@ -287,10 +326,14 @@ export namespace state {
writer.writeString(1, this.id);
if (this.code.length)
writer.writeString(2, this.code);
if (this.has_switchKilometerSystem)
writer.writeMessage(3, this.switchKilometerSystem, () => this.switchKilometerSystem.serialize(writer));
if (this.switchConvertKilometer != 0)
writer.writeInt64(4, this.switchConvertKilometer);
if (this.kilometerSystem.length)
writer.writeRepeatedMessage(3, this.kilometerSystem, (item: dependency_1.graphicData.KilometerSystem) => item.serialize(writer));
writer.writeRepeatedMessage(5, this.kilometerSystem, (item: dependency_1.graphicData.KilometerSystem) => item.serialize(writer));
if (this.convertKilometer.length)
writer.writePackedInt64(4, this.convertKilometer);
writer.writePackedInt64(6, this.convertKilometer);
if (!w)
return writer.getResultBuffer();
}
@ -307,9 +350,15 @@ export namespace state {
message.code = reader.readString();
break;
case 3:
reader.readMessage(message.kilometerSystem, () => pb_1.Message.addToRepeatedWrapperField(message, 3, dependency_1.graphicData.KilometerSystem.deserialize(reader), dependency_1.graphicData.KilometerSystem));
reader.readMessage(message.switchKilometerSystem, () => message.switchKilometerSystem = dependency_1.graphicData.KilometerSystem.deserialize(reader));
break;
case 4:
message.switchConvertKilometer = reader.readInt64();
break;
case 5:
reader.readMessage(message.kilometerSystem, () => pb_1.Message.addToRepeatedWrapperField(message, 5, dependency_1.graphicData.KilometerSystem.deserialize(reader), dependency_1.graphicData.KilometerSystem));
break;
case 6:
message.convertKilometer = reader.readPackedInt64();
break;
default: reader.skipField();

View File

@ -3165,9 +3165,11 @@ export namespace graphicData {
upPathLineId?: string;
downPathLineId?: string;
containSta?: string[];
linkPathLines?: string[];
lineId?: string;
}) {
super();
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [3, 8], this.#one_of_decls);
pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [3, 8, 9], this.#one_of_decls);
if (!Array.isArray(data) && typeof data == "object") {
if ("common" in data && data.common != undefined) {
this.common = data.common;
@ -3193,6 +3195,12 @@ export namespace graphicData {
if ("containSta" in data && data.containSta != undefined) {
this.containSta = data.containSta;
}
if ("linkPathLines" in data && data.linkPathLines != undefined) {
this.linkPathLines = data.linkPathLines;
}
if ("lineId" in data && data.lineId != undefined) {
this.lineId = data.lineId;
}
}
}
get common() {
@ -3246,6 +3254,18 @@ export namespace graphicData {
set containSta(value: string[]) {
pb_1.Message.setField(this, 8, value);
}
get linkPathLines() {
return pb_1.Message.getFieldWithDefault(this, 9, []) as string[];
}
set linkPathLines(value: string[]) {
pb_1.Message.setField(this, 9, value);
}
get lineId() {
return pb_1.Message.getFieldWithDefault(this, 10, "") as string;
}
set lineId(value: string) {
pb_1.Message.setField(this, 10, value);
}
static fromObject(data: {
common?: ReturnType<typeof CommonInfo.prototype.toObject>;
code?: string;
@ -3255,6 +3275,8 @@ export namespace graphicData {
upPathLineId?: string;
downPathLineId?: string;
containSta?: string[];
linkPathLines?: string[];
lineId?: string;
}): RunLine {
const message = new RunLine({});
if (data.common != null) {
@ -3281,6 +3303,12 @@ export namespace graphicData {
if (data.containSta != null) {
message.containSta = data.containSta;
}
if (data.linkPathLines != null) {
message.linkPathLines = data.linkPathLines;
}
if (data.lineId != null) {
message.lineId = data.lineId;
}
return message;
}
toObject() {
@ -3293,6 +3321,8 @@ export namespace graphicData {
upPathLineId?: string;
downPathLineId?: string;
containSta?: string[];
linkPathLines?: string[];
lineId?: string;
} = {};
if (this.common != null) {
data.common = this.common.toObject();
@ -3318,6 +3348,12 @@ export namespace graphicData {
if (this.containSta != null) {
data.containSta = this.containSta;
}
if (this.linkPathLines != null) {
data.linkPathLines = this.linkPathLines;
}
if (this.lineId != null) {
data.lineId = this.lineId;
}
return data;
}
serialize(): Uint8Array;
@ -3340,6 +3376,10 @@ export namespace graphicData {
writer.writeString(7, this.downPathLineId);
if (this.containSta.length)
writer.writeRepeatedString(8, this.containSta);
if (this.linkPathLines.length)
writer.writeRepeatedString(9, this.linkPathLines);
if (this.lineId.length)
writer.writeString(10, this.lineId);
if (!w)
return writer.getResultBuffer();
}
@ -3373,6 +3413,12 @@ export namespace graphicData {
case 8:
pb_1.Message.addToRepeatedField(message, 8, reader.readString());
break;
case 9:
pb_1.Message.addToRepeatedField(message, 9, reader.readString());
break;
case 10:
message.lineId = reader.readString();
break;
default: reader.skipField();
}
}

@ -1 +1 @@
Subproject commit a850c9b8b6bb71db94daaf8a394aff290a76cfd0
Subproject commit 28119c07431f5207ba4a37691dd0e499cb9973f0