diff --git a/src/components/draw-app/DrawRelayCabinetProperties.vue b/src/components/draw-app/DrawRelayCabinetProperties.vue new file mode 100644 index 0000000..0e44fbc --- /dev/null +++ b/src/components/draw-app/DrawRelayCabinetProperties.vue @@ -0,0 +1,37 @@ + + + diff --git a/src/components/draw-app/properties/RelayCabinetProperty.vue b/src/components/draw-app/properties/RelayCabinetProperty.vue new file mode 100644 index 0000000..9a174d2 --- /dev/null +++ b/src/components/draw-app/properties/RelayCabinetProperty.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/components/draw-app/properties/RelayProperty.vue b/src/components/draw-app/properties/RelayProperty.vue new file mode 100644 index 0000000..2e654bd --- /dev/null +++ b/src/components/draw-app/properties/RelayProperty.vue @@ -0,0 +1,46 @@ + + + diff --git a/src/drawApp/relayCabinetGraphics/GraphicDataBase.ts b/src/drawApp/relayCabinetGraphics/GraphicDataBase.ts new file mode 100644 index 0000000..af6a411 --- /dev/null +++ b/src/drawApp/relayCabinetGraphics/GraphicDataBase.ts @@ -0,0 +1,152 @@ +import * as pb_1 from 'google-protobuf'; +import { + ChildTransform, + GraphicData, + GraphicState, + GraphicTransform, + IChildTransform, + IGraphicTransform, +} from 'src/jl-graphic'; +// import { toStorageTransform } from '..'; +import { graphicData } from 'src/protos/relayCabinetLayoutGraphics'; +import { IPointData, Point } from 'pixi.js'; + +export interface ICommonInfo { + id: string; + graphicType: string; + transform: IGraphicTransform; + childTransforms: IChildTransform[]; +} +export function fromStoragePoint(p: graphicData.Point): Point { + return new Point(p.x, p.y); +} + +export function toStoragePoint(p: IPointData): graphicData.Point { + return new graphicData.Point({ x: p.x, y: p.y }); +} +export function fromStorageTransfrom( + transfrom: graphicData.Transform +): GraphicTransform { + return new GraphicTransform( + fromStoragePoint(transfrom.position), + fromStoragePoint(transfrom.scale), + transfrom.rotation, + fromStoragePoint(transfrom.skew) + ); +} + +export function toStorageTransform( + transform: GraphicTransform +): graphicData.Transform { + return new graphicData.Transform({ + position: toStoragePoint(transform.position), + scale: toStoragePoint(transform.scale), + rotation: transform.rotation, + skew: toStoragePoint(transform.skew), + }); +} + +export interface IProtoGraphicData extends pb_1.Message { + common: ICommonInfo; + code?: string; +} + +export abstract class GraphicDataBase implements GraphicData { + _data: IProtoGraphicData; + constructor(data: IProtoGraphicData) { + this._data = data; + } + + static defaultCommonInfo(graphicType: string): graphicData.CommonInfo { + return new graphicData.CommonInfo({ + id: '', + graphicType: graphicType, + transform: new graphicData.Transform({ + position: new graphicData.Point({ x: 0, y: 0 }), + scale: new graphicData.Point({ x: 1, y: 1 }), + rotation: 0, + skew: new graphicData.Point({ x: 0, y: 0 }), + }), + childTransforms: [], + }); + } + + getData(): D { + return this._data as D; + } + + get id(): string { + return this._data.common.id; + } + set id(v: string) { + this._data.common.id = v; + } + get graphicType(): string { + return this._data.common.graphicType; + } + set graphicType(v: string) { + this._data.common.graphicType = v; + } + get transform(): GraphicTransform { + return GraphicTransform.from(this._data.common.transform); + } + set transform(v: GraphicTransform) { + this._data.common.transform = toStorageTransform(v); + } + get childTransforms(): ChildTransform[] | undefined { + const cts: ChildTransform[] = []; + if (this._data.common.childTransforms) { + this._data.common.childTransforms.forEach((ct) => { + cts.push(ChildTransform.from(ct)); + }); + } + return cts; + } + set childTransforms(v: ChildTransform[] | undefined) { + if (v) { + const cts: graphicData.ChildTransform[] = []; + v.forEach((ct) => + cts.push( + new graphicData.ChildTransform({ + ...ct, + transform: toStorageTransform(ct.transform), + }) + ) + ); + this._data.common.childTransforms = cts; + } else { + this._data.common.childTransforms = []; + } + } + + clone(): GraphicData { + throw new Error('Method not implemented.'); + } + copyFrom(gd: GraphicDataBase): void { + pb_1.Message.copyInto(gd._data, this._data); + } + eq(other: GraphicDataBase): boolean { + return pb_1.Message.equals(this._data, other._data); + } +} + +export abstract class GraphicStateBase implements GraphicState { + _graphicType: string; + _state: pb_1.Message; + constructor(state: pb_1.Message, graphicType: string) { + this._state = state; + this._graphicType = graphicType; + } + abstract get code(): string; + abstract copyFrom(data: GraphicState): void; + abstract eq(data: GraphicState): boolean; + getState(): S { + return this._state as S; + } + get graphicType(): string { + return this._graphicType; + } + clone(): GraphicState { + throw new Error('Method not implemented.'); + } +} diff --git a/src/drawApp/relayCabinetGraphics/RelayCabinetInteraction.ts b/src/drawApp/relayCabinetGraphics/RelayCabinetInteraction.ts new file mode 100644 index 0000000..7d8d4f6 --- /dev/null +++ b/src/drawApp/relayCabinetGraphics/RelayCabinetInteraction.ts @@ -0,0 +1,44 @@ +import * as pb_1 from 'google-protobuf'; +import { + IRelayCabinetData, + RelayCabinet, +} from 'src/graphics/relayCabinet/RelayCabinet'; +import { graphicData } from 'src/protos/relayCabinetLayoutGraphics'; +import { GraphicDataBase } from './GraphicDataBase'; + +export class RelayCabinetData + extends GraphicDataBase + implements IRelayCabinetData +{ + constructor(data?: graphicData.RelayCabinet) { + let relayCabinet; + if (!data) { + relayCabinet = new graphicData.RelayCabinet({ + common: GraphicDataBase.defaultCommonInfo(RelayCabinet.Type), + }); + } else { + relayCabinet = data; + } + super(relayCabinet); + } + + public get data(): graphicData.RelayCabinet { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + clone(): RelayCabinetData { + return new RelayCabinetData(this.data.cloneMessage()); + } + copyFrom(data: RelayCabinetData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: RelayCabinetData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/relayCabinetGraphics/RelayInteraction.ts b/src/drawApp/relayCabinetGraphics/RelayInteraction.ts new file mode 100644 index 0000000..459dcf2 --- /dev/null +++ b/src/drawApp/relayCabinetGraphics/RelayInteraction.ts @@ -0,0 +1,44 @@ +import * as pb_1 from 'google-protobuf'; +import { + IRelayData, + Relay, +} from 'src/graphics/relay/Relay'; +import { graphicData } from 'src/protos/relayCabinetLayoutGraphics'; +import { GraphicDataBase } from './GraphicDataBase'; + +export class RelayData + extends GraphicDataBase + implements IRelayData +{ + constructor(data?: graphicData.Relay) { + let relay; + if (!data) { + relay = new graphicData.Relay({ + common: GraphicDataBase.defaultCommonInfo(Relay.Type), + }); + } else { + relay = data; + } + super(relay); + } + + public get data(): graphicData.Relay { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + clone(): RelayData { + return new RelayData(this.data.cloneMessage()); + } + copyFrom(data: RelayData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: RelayData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/relayCabinetLayoutApp.ts b/src/drawApp/relayCabinetLayoutApp.ts new file mode 100644 index 0000000..112272a --- /dev/null +++ b/src/drawApp/relayCabinetLayoutApp.ts @@ -0,0 +1,205 @@ +import { fromUint8Array, toUint8Array } from 'js-base64'; + +import { + CombinationKey, + GraphicApp, + GraphicData, + JlDrawApp, + KeyListener, +} from 'src/jl-graphic'; +import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu'; +import { MenuItemOptions } from 'src/jl-graphic/ui/Menu'; +import { successNotify, errorNotify } from '../utils/CommonNotify'; +import { Dialog } from 'quasar'; +import { saveDraft, getDraft } from 'src/api/DraftApi'; +import { checkMapData } from 'src/api/Simulation'; +import { useDrawStore } from 'src/stores/draw-store'; +import { graphicData } from 'src/protos/relayCabinetLayoutGraphics'; +import { toStorageTransform } from './relayCabinetGraphics/GraphicDataBase'; +import { + RelayCabinet, + RelayCabinetTemplate, +} from 'src/graphics/relayCabinet/RelayCabinet'; +import { RelayCabinetData } from './relayCabinetGraphics/RelayCabinetInteraction'; +import { RelayCabinetDraw } from 'src/graphics/relayCabinet/RelayCabinetDrawAssistant'; +import { Relay, RelayTemplate } from 'src/graphics/relay/Relay'; +import { RelayData } from './relayCabinetGraphics/RelayInteraction'; +import { RelayDraw } from 'src/graphics/relay/RelayDrawAssistant'; + +const UndoOptions: MenuItemOptions = { + name: '撤销', +}; +const RedoOptions: MenuItemOptions = { + name: '重做', +}; +const SelectAllOptions: MenuItemOptions = { + name: '全选', +}; + +export const DefaultCanvasMenu = new ContextMenu({ + name: '绘制-画布菜单', + groups: [ + { + items: [UndoOptions, RedoOptions], + }, + { + items: [SelectAllOptions], + }, + ], +}); + +let drawApp: JlDrawApp | null = null; + +export function getDrawApp(): JlDrawApp | null { + return drawApp; +} + +export function destroyDrawApp(): void { + if (drawApp) { + drawApp.destroy(); + drawApp = null; + } +} + +export function initDrawApp(dom: HTMLElement): JlDrawApp { + drawApp = new JlDrawApp(dom); + const app = drawApp; + //根据草稿图类型加载绘图工具 + const draftType = useDrawStore().$state.draftType; + let drawAssistants: (RelayDraw | RelayCabinetDraw)[] = []; + if (draftType === 'Line') { + drawAssistants = [ + new RelayCabinetDraw( + app, + new RelayCabinetTemplate(new RelayCabinetData()) + ), + new RelayDraw(app, new RelayTemplate(new RelayData())), + ]; + } + app.setOptions({ drawAssistants: drawAssistants }); + + // 画布右键菜单 + app.registerMenu(DefaultCanvasMenu); + app.canvas.on('_rightclick', (e) => { + if (app._drawing) return; + UndoOptions.disabled = !app.opRecord.hasUndo; + RedoOptions.disabled = !app.opRecord.hasRedo; + + UndoOptions.handler = () => { + app.opRecord.undo(); + }; + RedoOptions.handler = () => { + app.opRecord.redo(); + }; + SelectAllOptions.handler = () => { + app.selectAllGraphics(); + }; + DefaultCanvasMenu.open(e.global); + }); + app.addKeyboardListener( + new KeyListener({ + value: 'KeyS', + global: true, + combinations: [CombinationKey.Ctrl], + onPress: () => { + saveDrawToServer(app); + }, + }) + ); + return drawApp; +} + +export function checkDataToServer(app: JlDrawApp) { + const base64 = saveDrawDatas(app); + checkMapData({ mapProto: base64 }) + .then((res) => { + if (res.data.success) { + successNotify('校验数据成功!'); + } else { + let message = ''; + res.data.errors.forEach((err: string) => { + message += `
${err};
`; + }); + Dialog.create({ + title: '校验失败', + message: message, + html: true, + persistent: true, + ok: { + ali: 'center', + }, + }); + } + }) + .catch((err) => { + errorNotify(err.message, err); + }); +} + +export function saveDrawToServer(app: JlDrawApp) { + const base64 = saveDrawDatas(app); + const drawStore = useDrawStore(); + const id = drawStore.draftId; + if (!id) { + return; + } + saveDraft(id as number, { proto: base64 }) + .then(() => { + successNotify('保存数据成功!'); + }) + .catch((err) => { + errorNotify(err.message, err); + }); +} + +// const StorageKey = 'graphic-storage'; +export function saveDrawDatas(app: JlDrawApp) { + const storage = new graphicData.RelayCabinetGraphicStorage(); + const canvasData = app.canvas.saveData(); + storage.canvas = new graphicData.Canvas({ + ...canvasData, + viewportTransform: toStorageTransform(canvasData.viewportTransform), + }); + const graphics = app.queryStore.getAllGraphics(); + graphics.forEach((g) => { + if (RelayCabinet.Type === g.type) { + const relayCabinetData = (g as RelayCabinet).saveData(); + storage.relayCabinets.push((relayCabinetData as RelayCabinetData).data); + } + if (Relay.Type === g.type) { + const relayData = (g as Relay).saveData(); + storage.relays.push((relayData as RelayData).data); + } + }); + const base64 = fromUint8Array(storage.serialize()); + console.log('保存数据', storage); + // localStorage.setItem(StorageKey, base64); + return base64; +} + +export async function loadDrawDatas(app: GraphicApp) { + // const base64 = localStorage.getItem(StorageKey); + const drawStore = useDrawStore(); + const id = drawStore.draftId; + if (!id) { + return; + } + const { proto: base64 } = await getDraft(id); + if (base64) { + const storage = graphicData.RelayCabinetGraphicStorage.deserialize( + toUint8Array(base64) + ); + app.updateCanvas(storage.canvas); + const datas: GraphicData[] = []; + storage.relayCabinets.forEach((relayCabinet) => { + datas.push(new RelayCabinetData(relayCabinet)); + }); + storage.relays.forEach((relay) => { + datas.push(new RelayData(relay)); + }); + + await app.loadGraphic(datas); + } else { + app.loadGraphic([]); + } +} diff --git a/src/graphics/relay/Relay.ts b/src/graphics/relay/Relay.ts new file mode 100644 index 0000000..2b383af --- /dev/null +++ b/src/graphics/relay/Relay.ts @@ -0,0 +1,76 @@ +import { Color, Graphics } from 'pixi.js'; +import { + GraphicData, + JlGraphic, + JlGraphicTemplate, + VectorText, +} from 'src/jl-graphic'; + +export interface IRelayData extends GraphicData { + get code(): string; // 编号 + set code(v: string); + clone(): IRelayData; + copyFrom(data: IRelayData): void; + eq(other: IRelayData): boolean; +} + +export const relayConsts = { + radius: 15, + lineWidth: 3, + lineColor: '0xff0000', +}; + +export class Relay extends JlGraphic { + static Type = 'Relay'; + relayGraphic: Graphics = new Graphics(); + labelGraphic = new VectorText(); + + constructor() { + super(Relay.Type); + this.addChild(this.relayGraphic); + this.setTextGraphic(this.labelGraphic, 'label'); + this.addChild(this.labelGraphic); + } + + get datas(): IRelayData { + return this.getDatas(); + } + doRepaint(): void { + this.labelGraphic.text = this.datas.code; + const labelPosition = this.datas.childTransforms?.find( + (t) => t.name === this.labelGraphic.name + )?.transform.position; + if (labelPosition) { + this.labelGraphic.position.set(labelPosition.x, labelPosition.y); + } else { + this.labelGraphic.position.set(0, 0); + } + const relayGraphic = this.relayGraphic; + relayGraphic + .clear() + .lineStyle(relayConsts.lineWidth, new Color(relayConsts.lineColor)); + relayGraphic.beginFill(relayConsts.lineColor); + relayGraphic.drawCircle(0, 0, relayConsts.radius); + relayGraphic.endFill; + } + setTextGraphic(g: VectorText, name: string) { + g.setVectorFontSize(14); + g.anchor.set(0.5); + g.style.fill = '#0f0'; + g.transformSave = true; + g.name = name; + } +} + +export class RelayTemplate extends JlGraphicTemplate { + constructor(dataTemplate: IRelayData) { + super(Relay.Type, { + dataTemplate, + }); + } + new(): Relay { + const relay = new Relay(); + relay.loadData(this.datas); + return relay; + } +} diff --git a/src/graphics/relay/RelayDrawAssistant.ts b/src/graphics/relay/RelayDrawAssistant.ts new file mode 100644 index 0000000..ff0d266 --- /dev/null +++ b/src/graphics/relay/RelayDrawAssistant.ts @@ -0,0 +1,102 @@ +import { FederatedPointerEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + JlDrawApp, + JlGraphic, +} from 'src/jl-graphic'; + +import { IRelayData, Relay, RelayTemplate } from './Relay'; + +export interface IRelayDrawOptions { + newData: () => IRelayData; +} + +export class RelayDraw extends GraphicDrawAssistant { + relayGraphic: Relay; + + constructor(app: JlDrawApp, template: RelayTemplate) { + super(app, template, 'sym_o_circle', '继电器Relay'); + this.relayGraphic = this.graphicTemplate.new(); + this.container.addChild(this.relayGraphic); + relayInteraction.init(app); + } + bind(): void { + super.bind(); + this.relayGraphic.loadData(this.graphicTemplate.datas); + this.relayGraphic.doRepaint(); + } + + clearCache(): void { + //this.relayGraphic.clear(); + } + onLeftDown(e: FederatedPointerEvent): void { + this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + + redraw(p: Point): void { + this.container.position.copyFrom(p); + } + prepareData(data: IRelayData): boolean { + data.transform = this.container.saveTransform(); + return true; + } +} + +/** + * 构建吸附位置 + * @param polygon + * @returns + */ +function buildAbsorbablePositions(relayCabinet: Relay): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const relayCabinets = relayCabinet.queryStore.queryByType(Relay.Type); + const { width, height } = relayCabinet.getGraphicApp().canvas; + relayCabinets.forEach((other) => { + if (other.id == relayCabinet.id) { + return; + } + const ps = other.datas.transform.position; + const xs = new AbsorbableLine({ x: 0, y: ps.y }, { x: width, y: ps.y }); + const ys = new AbsorbableLine({ x: ps.x, y: 0 }, { x: ps.x, y: height }); + aps.push(xs, ys); + }); + return aps; +} + +export class relayInteraction extends GraphicInteractionPlugin { + static Name = 'relay_transform'; + constructor(app: JlDrawApp) { + super(relayInteraction.Name, app); + } + static init(app: JlDrawApp) { + return new relayInteraction(app); + } + filter(...grahpics: JlGraphic[]): Relay[] | undefined { + return grahpics.filter((g) => g.type === Relay.Type).map((g) => g as Relay); + } + bind(g: Relay): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.labelGraphic.eventMode = 'static'; + g.labelGraphic.selectable = true; + g.labelGraphic.draggable = true; + g.on('transformstart', this.move, this); + } + unbind(g: Relay): void { + g.eventMode = 'none'; + g.labelGraphic.eventMode = 'none'; + g.labelGraphic.selectable = false; + g.labelGraphic.draggable = false; + g.off('transformstart', this.move, this); + } + move(): void { + const trainWindow = this.app.selectedGraphics[0] as Relay; + this.app.setOptions({ + absorbablePositions: buildAbsorbablePositions(trainWindow), + }); + } +} diff --git a/src/graphics/relayCabinet/RelayCabinet.ts b/src/graphics/relayCabinet/RelayCabinet.ts new file mode 100644 index 0000000..67a02db --- /dev/null +++ b/src/graphics/relayCabinet/RelayCabinet.ts @@ -0,0 +1,92 @@ +import { Color, Graphics, Rectangle } from 'pixi.js'; +import { + GraphicData, + JlGraphic, + JlGraphicTemplate, + VectorText, + getRectangleCenter, +} from 'src/jl-graphic'; + +export interface IRelayCabinetData extends GraphicData { + get code(): string; // 编号 + set code(v: string); + clone(): IRelayCabinetData; + copyFrom(data: IRelayCabinetData): void; + eq(other: IRelayCabinetData): boolean; +} + +export const relayCabinetConsts = { + width: 150, + height: 300, + lineWidth: 3, + lineColor: '0x0fe81f', +}; + +export class RelayCabinet extends JlGraphic { + static Type = 'RelayCabinet'; + relayCabinetGraphic: Graphics = new Graphics(); + labelGraphic = new VectorText(); + constructor() { + super(RelayCabinet.Type); + this.addChild(this.relayCabinetGraphic); + this.setTextGraphic(this.labelGraphic, 'label'); + this.addChild(this.labelGraphic); + } + + get datas(): IRelayCabinetData { + return this.getDatas(); + } + doRepaint(): void { + this.labelGraphic.text = this.datas.code; + const labelPosition = this.datas.childTransforms?.find( + (t) => t.name === this.labelGraphic.name + )?.transform.position; + if (labelPosition) { + this.labelGraphic.position.set(labelPosition.x, labelPosition.y); + } else { + this.labelGraphic.position.set(0, -relayCabinetConsts.height / 2 - 15); + } + const relayCabinetGraphic = this.relayCabinetGraphic; + relayCabinetGraphic + .clear() + .lineStyle( + relayCabinetConsts.lineWidth, + new Color(relayCabinetConsts.lineColor) + ); + relayCabinetGraphic.beginFill(relayCabinetConsts.lineColor, 0.00001); + relayCabinetGraphic.drawRect( + 0, + 0, + relayCabinetConsts.width, + relayCabinetConsts.height + ); + relayCabinetGraphic.endFill; + const rectP = new Rectangle( + 0, + 0, + relayCabinetConsts.width, + relayCabinetConsts.height + ); + relayCabinetGraphic.pivot = getRectangleCenter(rectP); + } + setTextGraphic(g: VectorText, name: string) { + g.setVectorFontSize(14); + g.anchor.set(0.5); + g.style.fill = '#0f0'; + g.transformSave = true; + g.name = name; + } +} + +export class RelayCabinetTemplate extends JlGraphicTemplate { + constructor(dataTemplate: IRelayCabinetData) { + super(RelayCabinet.Type, { + dataTemplate, + }); + } + new(): RelayCabinet { + const relayCabinet = new RelayCabinet(); + relayCabinet.loadData(this.datas); + return relayCabinet; + } +} diff --git a/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts b/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts new file mode 100644 index 0000000..ec337d8 --- /dev/null +++ b/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts @@ -0,0 +1,115 @@ +import { FederatedPointerEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + JlDrawApp, + JlGraphic, +} from 'src/jl-graphic'; + +import { + IRelayCabinetData, + RelayCabinet, + RelayCabinetTemplate, +} from './RelayCabinet'; + +export interface IRelayCabinetDrawOptions { + newData: () => IRelayCabinetData; +} + +export class RelayCabinetDraw extends GraphicDrawAssistant< + RelayCabinetTemplate, + IRelayCabinetData +> { + relayCabinetGraphic: RelayCabinet; + + constructor(app: JlDrawApp, template: RelayCabinetTemplate) { + super(app, template, 'sym_o_square', '继电器柜RelayCabinet'); + this.relayCabinetGraphic = this.graphicTemplate.new(); + this.container.addChild(this.relayCabinetGraphic); + relayCabinetInteraction.init(app); + } + bind(): void { + super.bind(); + this.relayCabinetGraphic.loadData(this.graphicTemplate.datas); + this.relayCabinetGraphic.doRepaint(); + } + + clearCache(): void { + //this.relayCabinetGraphic.clear(); + } + onLeftDown(e: FederatedPointerEvent): void { + this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + + redraw(p: Point): void { + this.container.position.copyFrom(p); + } + prepareData(data: IRelayCabinetData): boolean { + data.transform = this.container.saveTransform(); + return true; + } +} + +/** + * 构建吸附位置 + * @param polygon + * @returns + */ +function buildAbsorbablePositions( + relayCabinet: RelayCabinet +): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const relayCabinets = relayCabinet.queryStore.queryByType( + RelayCabinet.Type + ); + const { width, height } = relayCabinet.getGraphicApp().canvas; + relayCabinets.forEach((other) => { + if (other.id == relayCabinet.id) { + return; + } + const ps = other.datas.transform.position; + const xs = new AbsorbableLine({ x: 0, y: ps.y }, { x: width, y: ps.y }); + const ys = new AbsorbableLine({ x: ps.x, y: 0 }, { x: ps.x, y: height }); + aps.push(xs, ys); + }); + return aps; +} + +export class relayCabinetInteraction extends GraphicInteractionPlugin { + static Name = 'relayCabinet_transform'; + constructor(app: JlDrawApp) { + super(relayCabinetInteraction.Name, app); + } + static init(app: JlDrawApp) { + return new relayCabinetInteraction(app); + } + filter(...grahpics: JlGraphic[]): RelayCabinet[] | undefined { + return grahpics + .filter((g) => g.type === RelayCabinet.Type) + .map((g) => g as RelayCabinet); + } + bind(g: RelayCabinet): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.labelGraphic.eventMode = 'static'; + g.labelGraphic.selectable = true; + g.labelGraphic.draggable = true; + g.on('transformstart', this.move, this); + } + unbind(g: RelayCabinet): void { + g.eventMode = 'none'; + g.labelGraphic.eventMode = 'none'; + g.labelGraphic.selectable = false; + g.labelGraphic.draggable = false; + g.off('transformstart', this.move, this); + } + move(): void { + const trainWindow = this.app.selectedGraphics[0] as RelayCabinet; + this.app.setOptions({ + absorbablePositions: buildAbsorbablePositions(trainWindow), + }); + } +} diff --git a/src/jl-graphic/graphic/VectorText.ts b/src/jl-graphic/graphic/VectorText.ts index e8e912b..925f61d 100644 --- a/src/jl-graphic/graphic/VectorText.ts +++ b/src/jl-graphic/graphic/VectorText.ts @@ -29,8 +29,9 @@ export class VectorText extends Text implements VectorGraphic { * 设置矢量文字的字体大小 */ setVectorFontSize(fontSize: number) { - this.vectorFontSize = fontSize; - // this.style.fontSize = fontSize; - this.updateOnScaled(); + if (this.vectorFontSize !== fontSize) { + this.vectorFontSize = fontSize; + this.updateOnScaled(); + } } } diff --git a/src/layouts/RelayCabinetLayout.vue b/src/layouts/RelayCabinetLayout.vue new file mode 100644 index 0000000..1a44589 --- /dev/null +++ b/src/layouts/RelayCabinetLayout.vue @@ -0,0 +1,383 @@ + + + diff --git a/src/protos/device_state.ts b/src/protos/device_state.ts index 86f5513..5408356 100644 --- a/src/protos/device_state.ts +++ b/src/protos/device_state.ts @@ -533,12 +533,359 @@ export namespace state { constructor(data?: any[] | { id?: string; up?: boolean; + speed?: number; + trainLength?: number; + show?: boolean; + headDeviceId?: string; + headOffset?: number; + devicePort?: string; + pointTo?: boolean; + runDirection?: boolean; + headDirection?: boolean; + dynamicState?: TrainDynamicState; + vobcState?: TrainVobcState; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], 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 ("speed" in data && data.speed != undefined) { + this.speed = data.speed; + } + if ("trainLength" in data && data.trainLength != undefined) { + this.trainLength = data.trainLength; + } + if ("show" in data && data.show != undefined) { + this.show = data.show; + } + if ("headDeviceId" in data && data.headDeviceId != undefined) { + this.headDeviceId = data.headDeviceId; + } + if ("headOffset" in data && data.headOffset != undefined) { + this.headOffset = data.headOffset; + } + if ("devicePort" in data && data.devicePort != undefined) { + this.devicePort = data.devicePort; + } + if ("pointTo" in data && data.pointTo != undefined) { + this.pointTo = data.pointTo; + } + if ("runDirection" in data && data.runDirection != undefined) { + this.runDirection = data.runDirection; + } + if ("headDirection" in data && data.headDirection != undefined) { + this.headDirection = data.headDirection; + } + if ("dynamicState" in data && data.dynamicState != undefined) { + this.dynamicState = data.dynamicState; + } + if ("vobcState" in data && data.vobcState != undefined) { + this.vobcState = data.vobcState; + } + } + } + get id() { + return pb_1.Message.getFieldWithDefault(this, 1, "") as string; + } + set id(value: string) { + pb_1.Message.setField(this, 1, value); + } + get up() { + return pb_1.Message.getFieldWithDefault(this, 2, false) as boolean; + } + set up(value: boolean) { + pb_1.Message.setField(this, 2, value); + } + get speed() { + return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; + } + set speed(value: number) { + pb_1.Message.setField(this, 3, value); + } + get trainLength() { + return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; + } + set trainLength(value: number) { + pb_1.Message.setField(this, 4, value); + } + get show() { + return pb_1.Message.getFieldWithDefault(this, 5, false) as boolean; + } + set show(value: boolean) { + pb_1.Message.setField(this, 5, value); + } + get headDeviceId() { + return pb_1.Message.getFieldWithDefault(this, 6, "") as string; + } + set headDeviceId(value: string) { + pb_1.Message.setField(this, 6, value); + } + get headOffset() { + return pb_1.Message.getFieldWithDefault(this, 7, 0) as number; + } + set headOffset(value: number) { + pb_1.Message.setField(this, 7, value); + } + get devicePort() { + return pb_1.Message.getFieldWithDefault(this, 8, "") as string; + } + set devicePort(value: string) { + pb_1.Message.setField(this, 8, value); + } + get pointTo() { + return pb_1.Message.getFieldWithDefault(this, 9, false) as boolean; + } + set pointTo(value: boolean) { + pb_1.Message.setField(this, 9, value); + } + get runDirection() { + return pb_1.Message.getFieldWithDefault(this, 10, false) as boolean; + } + set runDirection(value: boolean) { + pb_1.Message.setField(this, 10, value); + } + get headDirection() { + return pb_1.Message.getFieldWithDefault(this, 11, false) as boolean; + } + set headDirection(value: boolean) { + pb_1.Message.setField(this, 11, value); + } + get dynamicState() { + return pb_1.Message.getWrapperField(this, TrainDynamicState, 12) as TrainDynamicState; + } + set dynamicState(value: TrainDynamicState) { + pb_1.Message.setWrapperField(this, 12, value); + } + get has_dynamicState() { + return pb_1.Message.getField(this, 12) != null; + } + get vobcState() { + return pb_1.Message.getWrapperField(this, TrainVobcState, 13) as TrainVobcState; + } + set vobcState(value: TrainVobcState) { + pb_1.Message.setWrapperField(this, 13, value); + } + get has_vobcState() { + return pb_1.Message.getField(this, 13) != null; + } + static fromObject(data: { + id?: string; + up?: boolean; + speed?: number; + trainLength?: number; + show?: boolean; + headDeviceId?: string; + headOffset?: number; + devicePort?: string; + pointTo?: boolean; + runDirection?: boolean; + headDirection?: boolean; + dynamicState?: ReturnType; + vobcState?: ReturnType; + }): TrainState { + const message = new TrainState({}); + if (data.id != null) { + message.id = data.id; + } + if (data.up != null) { + message.up = data.up; + } + if (data.speed != null) { + message.speed = data.speed; + } + if (data.trainLength != null) { + message.trainLength = data.trainLength; + } + if (data.show != null) { + message.show = data.show; + } + if (data.headDeviceId != null) { + message.headDeviceId = data.headDeviceId; + } + if (data.headOffset != null) { + message.headOffset = data.headOffset; + } + if (data.devicePort != null) { + message.devicePort = data.devicePort; + } + if (data.pointTo != null) { + message.pointTo = data.pointTo; + } + if (data.runDirection != null) { + message.runDirection = data.runDirection; + } + if (data.headDirection != null) { + message.headDirection = data.headDirection; + } + if (data.dynamicState != null) { + message.dynamicState = TrainDynamicState.fromObject(data.dynamicState); + } + if (data.vobcState != null) { + message.vobcState = TrainVobcState.fromObject(data.vobcState); + } + return message; + } + toObject() { + const data: { + id?: string; + up?: boolean; + speed?: number; + trainLength?: number; + show?: boolean; + headDeviceId?: string; + headOffset?: number; + devicePort?: string; + pointTo?: boolean; + runDirection?: boolean; + headDirection?: boolean; + dynamicState?: ReturnType; + vobcState?: ReturnType; + } = {}; + if (this.id != null) { + data.id = this.id; + } + if (this.up != null) { + data.up = this.up; + } + if (this.speed != null) { + data.speed = this.speed; + } + if (this.trainLength != null) { + data.trainLength = this.trainLength; + } + if (this.show != null) { + data.show = this.show; + } + if (this.headDeviceId != null) { + data.headDeviceId = this.headDeviceId; + } + if (this.headOffset != null) { + data.headOffset = this.headOffset; + } + if (this.devicePort != null) { + data.devicePort = this.devicePort; + } + if (this.pointTo != null) { + data.pointTo = this.pointTo; + } + if (this.runDirection != null) { + data.runDirection = this.runDirection; + } + if (this.headDirection != null) { + data.headDirection = this.headDirection; + } + if (this.dynamicState != null) { + data.dynamicState = this.dynamicState.toObject(); + } + if (this.vobcState != null) { + data.vobcState = this.vobcState.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + 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.speed != 0) + writer.writeFloat(3, this.speed); + if (this.trainLength != 0) + writer.writeInt64(4, this.trainLength); + if (this.show != false) + writer.writeBool(5, this.show); + if (this.headDeviceId.length) + writer.writeString(6, this.headDeviceId); + if (this.headOffset != 0) + writer.writeInt64(7, this.headOffset); + if (this.devicePort.length) + writer.writeString(8, this.devicePort); + if (this.pointTo != false) + writer.writeBool(9, this.pointTo); + if (this.runDirection != false) + writer.writeBool(10, this.runDirection); + if (this.headDirection != false) + writer.writeBool(11, this.headDirection); + if (this.has_dynamicState) + writer.writeMessage(12, this.dynamicState, () => this.dynamicState.serialize(writer)); + if (this.has_vobcState) + writer.writeMessage(13, this.vobcState, () => this.vobcState.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): TrainState { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new TrainState(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.id = reader.readString(); + break; + case 2: + message.up = reader.readBool(); + break; + case 3: + message.speed = reader.readFloat(); + break; + case 4: + message.trainLength = reader.readInt64(); + break; + case 5: + message.show = reader.readBool(); + break; + case 6: + message.headDeviceId = reader.readString(); + break; + case 7: + message.headOffset = reader.readInt64(); + break; + case 8: + message.devicePort = reader.readString(); + break; + case 9: + message.pointTo = reader.readBool(); + break; + case 10: + message.runDirection = reader.readBool(); + break; + case 11: + message.headDirection = reader.readBool(); + break; + case 12: + reader.readMessage(message.dynamicState, () => message.dynamicState = TrainDynamicState.deserialize(reader)); + break; + case 13: + reader.readMessage(message.vobcState, () => message.vobcState = TrainVobcState.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): TrainState { + return TrainState.deserialize(bytes); + } + } + export class TrainDynamicState extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + heartbeat?: number; headLinkId?: string; headLinkOffset?: number; tailLinkId?: string; tailLinkOffset?: number; occupiedLinkIndex?: string[]; - heartbeat?: number; slope?: number; upslope?: boolean; runningUp?: boolean; @@ -553,23 +900,12 @@ export namespace state { tailSensorSpeed2?: number; headRadarSpeed?: number; tailRadarSpeed?: number; - trainLength?: number; - show?: boolean; - headDeviceId?: string; - headOffset?: number; - devicePort?: string; - pointTo?: boolean; - runDirection?: boolean; - headDirection?: boolean; }) { super(); - pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [7], this.#one_of_decls); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [6], 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 ("heartbeat" in data && data.heartbeat != undefined) { + this.heartbeat = data.heartbeat; } if ("headLinkId" in data && data.headLinkId != undefined) { this.headLinkId = data.headLinkId; @@ -586,9 +922,6 @@ export namespace state { if ("occupiedLinkIndex" in data && data.occupiedLinkIndex != undefined) { this.occupiedLinkIndex = data.occupiedLinkIndex; } - if ("heartbeat" in data && data.heartbeat != undefined) { - this.heartbeat = data.heartbeat; - } if ("slope" in data && data.slope != undefined) { this.slope = data.slope; } @@ -631,221 +964,135 @@ export namespace state { if ("tailRadarSpeed" in data && data.tailRadarSpeed != undefined) { this.tailRadarSpeed = data.tailRadarSpeed; } - if ("trainLength" in data && data.trainLength != undefined) { - this.trainLength = data.trainLength; - } - if ("show" in data && data.show != undefined) { - this.show = data.show; - } - if ("headDeviceId" in data && data.headDeviceId != undefined) { - this.headDeviceId = data.headDeviceId; - } - if ("headOffset" in data && data.headOffset != undefined) { - this.headOffset = data.headOffset; - } - if ("devicePort" in data && data.devicePort != undefined) { - this.devicePort = data.devicePort; - } - if ("pointTo" in data && data.pointTo != undefined) { - this.pointTo = data.pointTo; - } - if ("runDirection" in data && data.runDirection != undefined) { - this.runDirection = data.runDirection; - } - if ("headDirection" in data && data.headDirection != undefined) { - this.headDirection = data.headDirection; - } } } - get id() { - return pb_1.Message.getFieldWithDefault(this, 1, "") as string; - } - set id(value: string) { - pb_1.Message.setField(this, 1, value); - } - get up() { - return pb_1.Message.getFieldWithDefault(this, 2, false) as boolean; - } - set up(value: boolean) { - pb_1.Message.setField(this, 2, value); - } - get headLinkId() { - return pb_1.Message.getFieldWithDefault(this, 3, "") as string; - } - set headLinkId(value: string) { - pb_1.Message.setField(this, 3, value); - } - get headLinkOffset() { - return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; - } - set headLinkOffset(value: number) { - pb_1.Message.setField(this, 4, value); - } - get tailLinkId() { - return pb_1.Message.getFieldWithDefault(this, 5, "") as string; - } - set tailLinkId(value: string) { - pb_1.Message.setField(this, 5, value); - } - get tailLinkOffset() { - return pb_1.Message.getFieldWithDefault(this, 6, 0) as number; - } - 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); - } get heartbeat() { - return pb_1.Message.getFieldWithDefault(this, 8, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; } set heartbeat(value: number) { - pb_1.Message.setField(this, 8, value); + pb_1.Message.setField(this, 1, value); + } + get headLinkId() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set headLinkId(value: string) { + pb_1.Message.setField(this, 2, value); + } + get headLinkOffset() { + return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; + } + set headLinkOffset(value: number) { + pb_1.Message.setField(this, 3, value); + } + get tailLinkId() { + return pb_1.Message.getFieldWithDefault(this, 4, "") as string; + } + set tailLinkId(value: string) { + pb_1.Message.setField(this, 4, value); + } + get tailLinkOffset() { + return pb_1.Message.getFieldWithDefault(this, 5, 0) as number; + } + set tailLinkOffset(value: number) { + pb_1.Message.setField(this, 5, value); + } + get occupiedLinkIndex() { + return pb_1.Message.getFieldWithDefault(this, 6, []) as string[]; + } + set occupiedLinkIndex(value: string[]) { + pb_1.Message.setField(this, 6, value); } get slope() { - return pb_1.Message.getFieldWithDefault(this, 9, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 7, 0) as number; } set slope(value: number) { - pb_1.Message.setField(this, 9, value); + pb_1.Message.setField(this, 7, value); } get upslope() { - return pb_1.Message.getFieldWithDefault(this, 10, false) as boolean; + return pb_1.Message.getFieldWithDefault(this, 8, false) as boolean; } set upslope(value: boolean) { - pb_1.Message.setField(this, 10, value); + pb_1.Message.setField(this, 8, value); } get runningUp() { - return pb_1.Message.getFieldWithDefault(this, 11, false) as boolean; + return pb_1.Message.getFieldWithDefault(this, 9, false) as boolean; } set runningUp(value: boolean) { - pb_1.Message.setField(this, 11, value); + pb_1.Message.setField(this, 9, value); } get runningResistanceSum() { - return pb_1.Message.getFieldWithDefault(this, 12, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 10, 0) as number; } set runningResistanceSum(value: number) { - pb_1.Message.setField(this, 12, value); + pb_1.Message.setField(this, 10, value); } get airResistance() { - return pb_1.Message.getFieldWithDefault(this, 13, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 11, 0) as number; } set airResistance(value: number) { - pb_1.Message.setField(this, 13, value); + pb_1.Message.setField(this, 11, value); } get rampResistance() { - return pb_1.Message.getFieldWithDefault(this, 14, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 12, 0) as number; } set rampResistance(value: number) { - pb_1.Message.setField(this, 14, value); + pb_1.Message.setField(this, 12, value); } get curveResistance() { - return pb_1.Message.getFieldWithDefault(this, 15, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 13, 0) as number; } set curveResistance(value: number) { - pb_1.Message.setField(this, 15, value); + pb_1.Message.setField(this, 13, value); } get speed() { - return pb_1.Message.getFieldWithDefault(this, 16, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 14, 0) as number; } set speed(value: number) { - pb_1.Message.setField(this, 16, value); + pb_1.Message.setField(this, 14, value); } get headSensorSpeed1() { - return pb_1.Message.getFieldWithDefault(this, 17, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 15, 0) as number; } set headSensorSpeed1(value: number) { - pb_1.Message.setField(this, 17, value); + pb_1.Message.setField(this, 15, value); } get headSensorSpeed2() { - return pb_1.Message.getFieldWithDefault(this, 18, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 16, 0) as number; } set headSensorSpeed2(value: number) { - pb_1.Message.setField(this, 18, value); + pb_1.Message.setField(this, 16, value); } get tailSensorSpeed1() { - return pb_1.Message.getFieldWithDefault(this, 19, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 17, 0) as number; } set tailSensorSpeed1(value: number) { - pb_1.Message.setField(this, 19, value); + pb_1.Message.setField(this, 17, value); } get tailSensorSpeed2() { - return pb_1.Message.getFieldWithDefault(this, 20, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 18, 0) as number; } set tailSensorSpeed2(value: number) { - pb_1.Message.setField(this, 20, value); + pb_1.Message.setField(this, 18, value); } get headRadarSpeed() { - return pb_1.Message.getFieldWithDefault(this, 21, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 19, 0) as number; } set headRadarSpeed(value: number) { - pb_1.Message.setField(this, 21, value); + pb_1.Message.setField(this, 19, value); } get tailRadarSpeed() { - return pb_1.Message.getFieldWithDefault(this, 22, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 20, 0) as number; } set tailRadarSpeed(value: number) { - pb_1.Message.setField(this, 22, value); - } - get trainLength() { - return pb_1.Message.getFieldWithDefault(this, 23, 0) as number; - } - set trainLength(value: number) { - pb_1.Message.setField(this, 23, value); - } - get show() { - return pb_1.Message.getFieldWithDefault(this, 24, false) as boolean; - } - set show(value: boolean) { - pb_1.Message.setField(this, 24, value); - } - get headDeviceId() { - return pb_1.Message.getFieldWithDefault(this, 25, "") as string; - } - set headDeviceId(value: string) { - pb_1.Message.setField(this, 25, value); - } - get headOffset() { - return pb_1.Message.getFieldWithDefault(this, 26, 0) as number; - } - set headOffset(value: number) { - pb_1.Message.setField(this, 26, value); - } - get devicePort() { - return pb_1.Message.getFieldWithDefault(this, 27, "") as string; - } - set devicePort(value: string) { - pb_1.Message.setField(this, 27, value); - } - get pointTo() { - return pb_1.Message.getFieldWithDefault(this, 28, false) as boolean; - } - set pointTo(value: boolean) { - pb_1.Message.setField(this, 28, value); - } - get runDirection() { - return pb_1.Message.getFieldWithDefault(this, 29, false) as boolean; - } - set runDirection(value: boolean) { - pb_1.Message.setField(this, 29, value); - } - get headDirection() { - return pb_1.Message.getFieldWithDefault(this, 30, false) as boolean; - } - set headDirection(value: boolean) { - pb_1.Message.setField(this, 30, value); + pb_1.Message.setField(this, 20, value); } static fromObject(data: { - id?: string; - up?: boolean; + heartbeat?: number; headLinkId?: string; headLinkOffset?: number; tailLinkId?: string; tailLinkOffset?: number; occupiedLinkIndex?: string[]; - heartbeat?: number; slope?: number; upslope?: boolean; runningUp?: boolean; @@ -860,21 +1107,10 @@ export namespace state { tailSensorSpeed2?: number; headRadarSpeed?: number; tailRadarSpeed?: number; - trainLength?: number; - show?: boolean; - headDeviceId?: string; - headOffset?: number; - devicePort?: string; - pointTo?: boolean; - runDirection?: boolean; - headDirection?: boolean; - }): TrainState { - const message = new TrainState({}); - if (data.id != null) { - message.id = data.id; - } - if (data.up != null) { - message.up = data.up; + }): TrainDynamicState { + const message = new TrainDynamicState({}); + if (data.heartbeat != null) { + message.heartbeat = data.heartbeat; } if (data.headLinkId != null) { message.headLinkId = data.headLinkId; @@ -891,9 +1127,6 @@ export namespace state { if (data.occupiedLinkIndex != null) { message.occupiedLinkIndex = data.occupiedLinkIndex; } - if (data.heartbeat != null) { - message.heartbeat = data.heartbeat; - } if (data.slope != null) { message.slope = data.slope; } @@ -936,42 +1169,16 @@ export namespace state { if (data.tailRadarSpeed != null) { message.tailRadarSpeed = data.tailRadarSpeed; } - if (data.trainLength != null) { - message.trainLength = data.trainLength; - } - if (data.show != null) { - message.show = data.show; - } - if (data.headDeviceId != null) { - message.headDeviceId = data.headDeviceId; - } - if (data.headOffset != null) { - message.headOffset = data.headOffset; - } - if (data.devicePort != null) { - message.devicePort = data.devicePort; - } - if (data.pointTo != null) { - message.pointTo = data.pointTo; - } - if (data.runDirection != null) { - message.runDirection = data.runDirection; - } - if (data.headDirection != null) { - message.headDirection = data.headDirection; - } return message; } toObject() { const data: { - id?: string; - up?: boolean; + heartbeat?: number; headLinkId?: string; headLinkOffset?: number; tailLinkId?: string; tailLinkOffset?: number; occupiedLinkIndex?: string[]; - heartbeat?: number; slope?: number; upslope?: boolean; runningUp?: boolean; @@ -986,20 +1193,9 @@ export namespace state { tailSensorSpeed2?: number; headRadarSpeed?: number; tailRadarSpeed?: number; - trainLength?: number; - show?: boolean; - headDeviceId?: string; - headOffset?: number; - devicePort?: string; - pointTo?: boolean; - runDirection?: boolean; - headDirection?: boolean; } = {}; - if (this.id != null) { - data.id = this.id; - } - if (this.up != null) { - data.up = this.up; + if (this.heartbeat != null) { + data.heartbeat = this.heartbeat; } if (this.headLinkId != null) { data.headLinkId = this.headLinkId; @@ -1016,9 +1212,6 @@ export namespace state { if (this.occupiedLinkIndex != null) { data.occupiedLinkIndex = this.occupiedLinkIndex; } - if (this.heartbeat != null) { - data.heartbeat = this.heartbeat; - } if (this.slope != null) { data.slope = this.slope; } @@ -1061,195 +1254,121 @@ export namespace state { if (this.tailRadarSpeed != null) { data.tailRadarSpeed = this.tailRadarSpeed; } - if (this.trainLength != null) { - data.trainLength = this.trainLength; - } - if (this.show != null) { - data.show = this.show; - } - if (this.headDeviceId != null) { - data.headDeviceId = this.headDeviceId; - } - if (this.headOffset != null) { - data.headOffset = this.headOffset; - } - if (this.devicePort != null) { - data.devicePort = this.devicePort; - } - if (this.pointTo != null) { - data.pointTo = this.pointTo; - } - if (this.runDirection != null) { - data.runDirection = this.runDirection; - } - if (this.headDirection != null) { - data.headDirection = this.headDirection; - } return data; } serialize(): Uint8Array; serialize(w: pb_1.BinaryWriter): void; serialize(w?: pb_1.BinaryWriter): Uint8Array | void { 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(3, this.headLinkId); - if (this.headLinkOffset != 0) - writer.writeInt64(4, this.headLinkOffset); - if (this.tailLinkId.length) - writer.writeString(5, this.tailLinkId); - if (this.tailLinkOffset != 0) - writer.writeInt64(6, this.tailLinkOffset); - if (this.occupiedLinkIndex.length) - writer.writeRepeatedString(7, this.occupiedLinkIndex); if (this.heartbeat != 0) - writer.writeInt32(8, this.heartbeat); + writer.writeInt32(1, this.heartbeat); + if (this.headLinkId.length) + writer.writeString(2, this.headLinkId); + if (this.headLinkOffset != 0) + writer.writeInt64(3, this.headLinkOffset); + if (this.tailLinkId.length) + writer.writeString(4, this.tailLinkId); + if (this.tailLinkOffset != 0) + writer.writeInt64(5, this.tailLinkOffset); + if (this.occupiedLinkIndex.length) + writer.writeRepeatedString(6, this.occupiedLinkIndex); if (this.slope != 0) - writer.writeInt32(9, this.slope); + writer.writeInt32(7, this.slope); if (this.upslope != false) - writer.writeBool(10, this.upslope); + writer.writeBool(8, this.upslope); if (this.runningUp != false) - writer.writeBool(11, this.runningUp); + writer.writeBool(9, this.runningUp); if (this.runningResistanceSum != 0) - writer.writeFloat(12, this.runningResistanceSum); + writer.writeFloat(10, this.runningResistanceSum); if (this.airResistance != 0) - writer.writeFloat(13, this.airResistance); + writer.writeFloat(11, this.airResistance); if (this.rampResistance != 0) - writer.writeFloat(14, this.rampResistance); + writer.writeFloat(12, this.rampResistance); if (this.curveResistance != 0) - writer.writeFloat(15, this.curveResistance); + writer.writeFloat(13, this.curveResistance); if (this.speed != 0) - writer.writeFloat(16, this.speed); + writer.writeFloat(14, this.speed); if (this.headSensorSpeed1 != 0) - writer.writeFloat(17, this.headSensorSpeed1); + writer.writeFloat(15, this.headSensorSpeed1); if (this.headSensorSpeed2 != 0) - writer.writeFloat(18, this.headSensorSpeed2); + writer.writeFloat(16, this.headSensorSpeed2); if (this.tailSensorSpeed1 != 0) - writer.writeFloat(19, this.tailSensorSpeed1); + writer.writeFloat(17, this.tailSensorSpeed1); if (this.tailSensorSpeed2 != 0) - writer.writeFloat(20, this.tailSensorSpeed2); + writer.writeFloat(18, this.tailSensorSpeed2); if (this.headRadarSpeed != 0) - writer.writeFloat(21, this.headRadarSpeed); + writer.writeFloat(19, this.headRadarSpeed); if (this.tailRadarSpeed != 0) - writer.writeFloat(22, this.tailRadarSpeed); - if (this.trainLength != 0) - writer.writeInt64(23, this.trainLength); - if (this.show != false) - writer.writeBool(24, this.show); - if (this.headDeviceId.length) - writer.writeString(25, this.headDeviceId); - if (this.headOffset != 0) - writer.writeInt64(26, this.headOffset); - if (this.devicePort.length) - writer.writeString(27, this.devicePort); - if (this.pointTo != false) - writer.writeBool(28, this.pointTo); - if (this.runDirection != false) - writer.writeBool(29, this.runDirection); - if (this.headDirection != false) - writer.writeBool(30, this.headDirection); + writer.writeFloat(20, this.tailRadarSpeed); if (!w) return writer.getResultBuffer(); } - static deserialize(bytes: Uint8Array | pb_1.BinaryReader): TrainState { - const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new TrainState(); + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): TrainDynamicState { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new TrainDynamicState(); while (reader.nextField()) { if (reader.isEndGroup()) break; switch (reader.getFieldNumber()) { case 1: - message.id = reader.readString(); - break; - case 2: - message.up = reader.readBool(); - break; - case 3: - message.headLinkId = reader.readString(); - break; - case 4: - message.headLinkOffset = reader.readInt64(); - break; - case 5: - message.tailLinkId = reader.readString(); - break; - case 6: - message.tailLinkOffset = reader.readInt64(); - break; - case 7: - pb_1.Message.addToRepeatedField(message, 7, reader.readString()); - break; - case 8: message.heartbeat = reader.readInt32(); break; - case 9: + case 2: + message.headLinkId = reader.readString(); + break; + case 3: + message.headLinkOffset = reader.readInt64(); + break; + case 4: + message.tailLinkId = reader.readString(); + break; + case 5: + message.tailLinkOffset = reader.readInt64(); + break; + case 6: + pb_1.Message.addToRepeatedField(message, 6, reader.readString()); + break; + case 7: message.slope = reader.readInt32(); break; - case 10: + case 8: message.upslope = reader.readBool(); break; - case 11: + case 9: message.runningUp = reader.readBool(); break; - case 12: + case 10: message.runningResistanceSum = reader.readFloat(); break; - case 13: + case 11: message.airResistance = reader.readFloat(); break; - case 14: + case 12: message.rampResistance = reader.readFloat(); break; - case 15: + case 13: message.curveResistance = reader.readFloat(); break; - case 16: + case 14: message.speed = reader.readFloat(); break; - case 17: + case 15: message.headSensorSpeed1 = reader.readFloat(); break; - case 18: + case 16: message.headSensorSpeed2 = reader.readFloat(); break; - case 19: + case 17: message.tailSensorSpeed1 = reader.readFloat(); break; - case 20: + case 18: message.tailSensorSpeed2 = reader.readFloat(); break; - case 21: + case 19: message.headRadarSpeed = reader.readFloat(); break; - case 22: + case 20: message.tailRadarSpeed = reader.readFloat(); break; - case 23: - message.trainLength = reader.readInt64(); - break; - case 24: - message.show = reader.readBool(); - break; - case 25: - message.headDeviceId = reader.readString(); - break; - case 26: - message.headOffset = reader.readInt64(); - break; - case 27: - message.devicePort = reader.readString(); - break; - case 28: - message.pointTo = reader.readBool(); - break; - case 29: - message.runDirection = reader.readBool(); - break; - case 30: - message.headDirection = reader.readBool(); - break; default: reader.skipField(); } } @@ -1258,8 +1377,8 @@ export namespace state { serializeBinary(): Uint8Array { return this.serialize(); } - static deserializeBinary(bytes: Uint8Array): TrainState { - return TrainState.deserialize(bytes); + static deserializeBinary(bytes: Uint8Array): TrainDynamicState { + return TrainDynamicState.deserialize(bytes); } } export class TrainVobcState extends pb_1.Message { diff --git a/src/protos/picture.ts b/src/protos/picture.ts index bb96506..70c4790 100644 --- a/src/protos/picture.ts +++ b/src/protos/picture.ts @@ -6,5 +6,6 @@ import * as pb_1 from "google-protobuf"; export enum PictureType { StationLayout = 0, - Psl = 1 + Psl = 1, + RelayCabinetLayout = 2 } diff --git a/src/protos/relayCabinetLayoutGraphics.ts b/src/protos/relayCabinetLayoutGraphics.ts new file mode 100644 index 0000000..9084cab --- /dev/null +++ b/src/protos/relayCabinetLayoutGraphics.ts @@ -0,0 +1,916 @@ +/** + * Generated by the protoc-gen-ts. DO NOT EDIT! + * compiler version: 4.23.1 + * source: relayCabinetLayoutGraphics.proto + * git: https://github.com/thesayyn/protoc-gen-ts */ +import * as pb_1 from "google-protobuf"; +export namespace graphicData { + export class RelayCabinetGraphicStorage extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + canvas?: Canvas; + relayCabinets?: RelayCabinet[]; + relays?: Relay[]; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [2, 3], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("canvas" in data && data.canvas != undefined) { + this.canvas = data.canvas; + } + if ("relayCabinets" in data && data.relayCabinets != undefined) { + this.relayCabinets = data.relayCabinets; + } + if ("relays" in data && data.relays != undefined) { + this.relays = data.relays; + } + } + } + get canvas() { + return pb_1.Message.getWrapperField(this, Canvas, 1) as Canvas; + } + set canvas(value: Canvas) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_canvas() { + return pb_1.Message.getField(this, 1) != null; + } + get relayCabinets() { + return pb_1.Message.getRepeatedWrapperField(this, RelayCabinet, 2) as RelayCabinet[]; + } + set relayCabinets(value: RelayCabinet[]) { + pb_1.Message.setRepeatedWrapperField(this, 2, value); + } + get relays() { + return pb_1.Message.getRepeatedWrapperField(this, Relay, 3) as Relay[]; + } + set relays(value: Relay[]) { + pb_1.Message.setRepeatedWrapperField(this, 3, value); + } + static fromObject(data: { + canvas?: ReturnType; + relayCabinets?: ReturnType[]; + relays?: ReturnType[]; + }): RelayCabinetGraphicStorage { + const message = new RelayCabinetGraphicStorage({}); + if (data.canvas != null) { + message.canvas = Canvas.fromObject(data.canvas); + } + if (data.relayCabinets != null) { + message.relayCabinets = data.relayCabinets.map(item => RelayCabinet.fromObject(item)); + } + if (data.relays != null) { + message.relays = data.relays.map(item => Relay.fromObject(item)); + } + return message; + } + toObject() { + const data: { + canvas?: ReturnType; + relayCabinets?: ReturnType[]; + relays?: ReturnType[]; + } = {}; + if (this.canvas != null) { + data.canvas = this.canvas.toObject(); + } + if (this.relayCabinets != null) { + data.relayCabinets = this.relayCabinets.map((item: RelayCabinet) => item.toObject()); + } + if (this.relays != null) { + data.relays = this.relays.map((item: Relay) => item.toObject()); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_canvas) + writer.writeMessage(1, this.canvas, () => this.canvas.serialize(writer)); + if (this.relayCabinets.length) + writer.writeRepeatedMessage(2, this.relayCabinets, (item: RelayCabinet) => item.serialize(writer)); + if (this.relays.length) + writer.writeRepeatedMessage(3, this.relays, (item: Relay) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): RelayCabinetGraphicStorage { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new RelayCabinetGraphicStorage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.canvas, () => message.canvas = Canvas.deserialize(reader)); + break; + case 2: + reader.readMessage(message.relayCabinets, () => pb_1.Message.addToRepeatedWrapperField(message, 2, RelayCabinet.deserialize(reader), RelayCabinet)); + break; + case 3: + reader.readMessage(message.relays, () => pb_1.Message.addToRepeatedWrapperField(message, 3, Relay.deserialize(reader), Relay)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): RelayCabinetGraphicStorage { + return RelayCabinetGraphicStorage.deserialize(bytes); + } + } + export class Canvas extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + width?: number; + height?: number; + backgroundColor?: string; + viewportTransform?: Transform; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("width" in data && data.width != undefined) { + this.width = data.width; + } + if ("height" in data && data.height != undefined) { + this.height = data.height; + } + if ("backgroundColor" in data && data.backgroundColor != undefined) { + this.backgroundColor = data.backgroundColor; + } + if ("viewportTransform" in data && data.viewportTransform != undefined) { + this.viewportTransform = data.viewportTransform; + } + } + } + get width() { + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; + } + set width(value: number) { + pb_1.Message.setField(this, 1, value); + } + get height() { + return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; + } + set height(value: number) { + pb_1.Message.setField(this, 2, value); + } + get backgroundColor() { + return pb_1.Message.getFieldWithDefault(this, 3, "") as string; + } + set backgroundColor(value: string) { + pb_1.Message.setField(this, 3, value); + } + get viewportTransform() { + return pb_1.Message.getWrapperField(this, Transform, 4) as Transform; + } + set viewportTransform(value: Transform) { + pb_1.Message.setWrapperField(this, 4, value); + } + get has_viewportTransform() { + return pb_1.Message.getField(this, 4) != null; + } + static fromObject(data: { + width?: number; + height?: number; + backgroundColor?: string; + viewportTransform?: ReturnType; + }): Canvas { + const message = new Canvas({}); + if (data.width != null) { + message.width = data.width; + } + if (data.height != null) { + message.height = data.height; + } + if (data.backgroundColor != null) { + message.backgroundColor = data.backgroundColor; + } + if (data.viewportTransform != null) { + message.viewportTransform = Transform.fromObject(data.viewportTransform); + } + return message; + } + toObject() { + const data: { + width?: number; + height?: number; + backgroundColor?: string; + viewportTransform?: ReturnType; + } = {}; + if (this.width != null) { + data.width = this.width; + } + if (this.height != null) { + data.height = this.height; + } + if (this.backgroundColor != null) { + data.backgroundColor = this.backgroundColor; + } + if (this.viewportTransform != null) { + data.viewportTransform = this.viewportTransform.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.width != 0) + writer.writeInt32(1, this.width); + if (this.height != 0) + writer.writeInt32(2, this.height); + if (this.backgroundColor.length) + writer.writeString(3, this.backgroundColor); + if (this.has_viewportTransform) + writer.writeMessage(4, this.viewportTransform, () => this.viewportTransform.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Canvas { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Canvas(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.width = reader.readInt32(); + break; + case 2: + message.height = reader.readInt32(); + break; + case 3: + message.backgroundColor = reader.readString(); + break; + case 4: + reader.readMessage(message.viewportTransform, () => message.viewportTransform = Transform.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Canvas { + return Canvas.deserialize(bytes); + } + } + export class Point extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + x?: number; + y?: number; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("x" in data && data.x != undefined) { + this.x = data.x; + } + if ("y" in data && data.y != undefined) { + this.y = data.y; + } + } + } + get x() { + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; + } + set x(value: number) { + pb_1.Message.setField(this, 1, value); + } + get y() { + return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; + } + set y(value: number) { + pb_1.Message.setField(this, 2, value); + } + static fromObject(data: { + x?: number; + y?: number; + }): Point { + const message = new Point({}); + if (data.x != null) { + message.x = data.x; + } + if (data.y != null) { + message.y = data.y; + } + return message; + } + toObject() { + const data: { + x?: number; + y?: number; + } = {}; + if (this.x != null) { + data.x = this.x; + } + if (this.y != null) { + data.y = this.y; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.x != 0) + writer.writeFloat(1, this.x); + if (this.y != 0) + writer.writeFloat(2, this.y); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Point { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Point(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.x = reader.readFloat(); + break; + case 2: + message.y = reader.readFloat(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Point { + return Point.deserialize(bytes); + } + } + export class Transform extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + position?: Point; + scale?: Point; + rotation?: number; + skew?: Point; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("position" in data && data.position != undefined) { + this.position = data.position; + } + if ("scale" in data && data.scale != undefined) { + this.scale = data.scale; + } + if ("rotation" in data && data.rotation != undefined) { + this.rotation = data.rotation; + } + if ("skew" in data && data.skew != undefined) { + this.skew = data.skew; + } + } + } + get position() { + return pb_1.Message.getWrapperField(this, Point, 1) as Point; + } + set position(value: Point) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_position() { + return pb_1.Message.getField(this, 1) != null; + } + get scale() { + return pb_1.Message.getWrapperField(this, Point, 2) as Point; + } + set scale(value: Point) { + pb_1.Message.setWrapperField(this, 2, value); + } + get has_scale() { + return pb_1.Message.getField(this, 2) != null; + } + get rotation() { + return pb_1.Message.getFieldWithDefault(this, 3, 0) as number; + } + set rotation(value: number) { + pb_1.Message.setField(this, 3, value); + } + get skew() { + return pb_1.Message.getWrapperField(this, Point, 4) as Point; + } + set skew(value: Point) { + pb_1.Message.setWrapperField(this, 4, value); + } + get has_skew() { + return pb_1.Message.getField(this, 4) != null; + } + static fromObject(data: { + position?: ReturnType; + scale?: ReturnType; + rotation?: number; + skew?: ReturnType; + }): Transform { + const message = new Transform({}); + if (data.position != null) { + message.position = Point.fromObject(data.position); + } + if (data.scale != null) { + message.scale = Point.fromObject(data.scale); + } + if (data.rotation != null) { + message.rotation = data.rotation; + } + if (data.skew != null) { + message.skew = Point.fromObject(data.skew); + } + return message; + } + toObject() { + const data: { + position?: ReturnType; + scale?: ReturnType; + rotation?: number; + skew?: ReturnType; + } = {}; + if (this.position != null) { + data.position = this.position.toObject(); + } + if (this.scale != null) { + data.scale = this.scale.toObject(); + } + if (this.rotation != null) { + data.rotation = this.rotation; + } + if (this.skew != null) { + data.skew = this.skew.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_position) + writer.writeMessage(1, this.position, () => this.position.serialize(writer)); + if (this.has_scale) + writer.writeMessage(2, this.scale, () => this.scale.serialize(writer)); + if (this.rotation != 0) + writer.writeFloat(3, this.rotation); + if (this.has_skew) + writer.writeMessage(4, this.skew, () => this.skew.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Transform { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Transform(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.position, () => message.position = Point.deserialize(reader)); + break; + case 2: + reader.readMessage(message.scale, () => message.scale = Point.deserialize(reader)); + break; + case 3: + message.rotation = reader.readFloat(); + break; + case 4: + reader.readMessage(message.skew, () => message.skew = Point.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Transform { + return Transform.deserialize(bytes); + } + } + export class ChildTransform extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + name?: string; + transform?: Transform; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("name" in data && data.name != undefined) { + this.name = data.name; + } + if ("transform" in data && data.transform != undefined) { + this.transform = data.transform; + } + } + } + get name() { + return pb_1.Message.getFieldWithDefault(this, 1, "") as string; + } + set name(value: string) { + pb_1.Message.setField(this, 1, value); + } + get transform() { + return pb_1.Message.getWrapperField(this, Transform, 2) as Transform; + } + set transform(value: Transform) { + pb_1.Message.setWrapperField(this, 2, value); + } + get has_transform() { + return pb_1.Message.getField(this, 2) != null; + } + static fromObject(data: { + name?: string; + transform?: ReturnType; + }): ChildTransform { + const message = new ChildTransform({}); + if (data.name != null) { + message.name = data.name; + } + if (data.transform != null) { + message.transform = Transform.fromObject(data.transform); + } + return message; + } + toObject() { + const data: { + name?: string; + transform?: ReturnType; + } = {}; + if (this.name != null) { + data.name = this.name; + } + if (this.transform != null) { + data.transform = this.transform.toObject(); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.name.length) + writer.writeString(1, this.name); + if (this.has_transform) + writer.writeMessage(2, this.transform, () => this.transform.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): ChildTransform { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new ChildTransform(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.name = reader.readString(); + break; + case 2: + reader.readMessage(message.transform, () => message.transform = Transform.deserialize(reader)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): ChildTransform { + return ChildTransform.deserialize(bytes); + } + } + export class CommonInfo extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + id?: string; + graphicType?: string; + transform?: Transform; + childTransforms?: ChildTransform[]; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [4], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("id" in data && data.id != undefined) { + this.id = data.id; + } + if ("graphicType" in data && data.graphicType != undefined) { + this.graphicType = data.graphicType; + } + if ("transform" in data && data.transform != undefined) { + this.transform = data.transform; + } + if ("childTransforms" in data && data.childTransforms != undefined) { + this.childTransforms = data.childTransforms; + } + } + } + get id() { + return pb_1.Message.getFieldWithDefault(this, 1, "") as string; + } + set id(value: string) { + pb_1.Message.setField(this, 1, value); + } + get graphicType() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set graphicType(value: string) { + pb_1.Message.setField(this, 2, value); + } + get transform() { + return pb_1.Message.getWrapperField(this, Transform, 3) as Transform; + } + set transform(value: Transform) { + pb_1.Message.setWrapperField(this, 3, value); + } + get has_transform() { + return pb_1.Message.getField(this, 3) != null; + } + get childTransforms() { + return pb_1.Message.getRepeatedWrapperField(this, ChildTransform, 4) as ChildTransform[]; + } + set childTransforms(value: ChildTransform[]) { + pb_1.Message.setRepeatedWrapperField(this, 4, value); + } + static fromObject(data: { + id?: string; + graphicType?: string; + transform?: ReturnType; + childTransforms?: ReturnType[]; + }): CommonInfo { + const message = new CommonInfo({}); + if (data.id != null) { + message.id = data.id; + } + if (data.graphicType != null) { + message.graphicType = data.graphicType; + } + if (data.transform != null) { + message.transform = Transform.fromObject(data.transform); + } + if (data.childTransforms != null) { + message.childTransforms = data.childTransforms.map(item => ChildTransform.fromObject(item)); + } + return message; + } + toObject() { + const data: { + id?: string; + graphicType?: string; + transform?: ReturnType; + childTransforms?: ReturnType[]; + } = {}; + if (this.id != null) { + data.id = this.id; + } + if (this.graphicType != null) { + data.graphicType = this.graphicType; + } + if (this.transform != null) { + data.transform = this.transform.toObject(); + } + if (this.childTransforms != null) { + data.childTransforms = this.childTransforms.map((item: ChildTransform) => item.toObject()); + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.id.length) + writer.writeString(1, this.id); + if (this.graphicType.length) + writer.writeString(2, this.graphicType); + if (this.has_transform) + writer.writeMessage(3, this.transform, () => this.transform.serialize(writer)); + if (this.childTransforms.length) + writer.writeRepeatedMessage(4, this.childTransforms, (item: ChildTransform) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): CommonInfo { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new CommonInfo(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.id = reader.readString(); + break; + case 2: + message.graphicType = reader.readString(); + break; + case 3: + reader.readMessage(message.transform, () => message.transform = Transform.deserialize(reader)); + break; + case 4: + reader.readMessage(message.childTransforms, () => pb_1.Message.addToRepeatedWrapperField(message, 4, ChildTransform.deserialize(reader), ChildTransform)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): CommonInfo { + return CommonInfo.deserialize(bytes); + } + } + export class RelayCabinet extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + common?: CommonInfo; + code?: string; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("code" in data && data.code != undefined) { + this.code = data.code; + } + } + } + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; + } + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_common() { + return pb_1.Message.getField(this, 1) != null; + } + get code() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set code(value: string) { + pb_1.Message.setField(this, 2, value); + } + static fromObject(data: { + common?: ReturnType; + code?: string; + }): RelayCabinet { + const message = new RelayCabinet({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.code != null) { + message.code = data.code; + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + code?: string; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.code != null) { + data.code = this.code; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.code.length) + writer.writeString(2, this.code); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): RelayCabinet { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new RelayCabinet(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + message.code = reader.readString(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): RelayCabinet { + return RelayCabinet.deserialize(bytes); + } + } + export class Relay extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + common?: CommonInfo; + code?: string; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("common" in data && data.common != undefined) { + this.common = data.common; + } + if ("code" in data && data.code != undefined) { + this.code = data.code; + } + } + } + get common() { + return pb_1.Message.getWrapperField(this, CommonInfo, 1) as CommonInfo; + } + set common(value: CommonInfo) { + pb_1.Message.setWrapperField(this, 1, value); + } + get has_common() { + return pb_1.Message.getField(this, 1) != null; + } + get code() { + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; + } + set code(value: string) { + pb_1.Message.setField(this, 2, value); + } + static fromObject(data: { + common?: ReturnType; + code?: string; + }): Relay { + const message = new Relay({}); + if (data.common != null) { + message.common = CommonInfo.fromObject(data.common); + } + if (data.code != null) { + message.code = data.code; + } + return message; + } + toObject() { + const data: { + common?: ReturnType; + code?: string; + } = {}; + if (this.common != null) { + data.common = this.common.toObject(); + } + if (this.code != null) { + data.code = this.code; + } + return data; + } + serialize(): Uint8Array; + serialize(w: pb_1.BinaryWriter): void; + serialize(w?: pb_1.BinaryWriter): Uint8Array | void { + const writer = w || new pb_1.BinaryWriter(); + if (this.has_common) + writer.writeMessage(1, this.common, () => this.common.serialize(writer)); + if (this.code.length) + writer.writeString(2, this.code); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): Relay { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new Relay(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.common, () => message.common = CommonInfo.deserialize(reader)); + break; + case 2: + message.code = reader.readString(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): Relay { + return Relay.deserialize(bytes); + } + } +} diff --git a/src/stores/relayCabinet-store.ts b/src/stores/relayCabinet-store.ts new file mode 100644 index 0000000..b33ffc0 --- /dev/null +++ b/src/stores/relayCabinet-store.ts @@ -0,0 +1,91 @@ +import { defineStore } from 'pinia'; +import { + destroyDrawApp, + getDrawApp, + initDrawApp, +} from 'src/drawApp/relayCabinetLayoutApp'; +import { DrawAssistant, JlCanvas, JlDrawApp, JlGraphic } from 'src/jl-graphic'; + +export const useDrawStore = defineStore('draw', { + state: () => ({ + drawAssistant: null as DrawAssistant | null, + selectedGraphics: null as JlGraphic[] | null, + draftId: null as number | null, + draftType: 'Line', + oneClickType: '', + }), + getters: { + drawMode: (state) => state.drawAssistant != null, + drawGraphicType: (state) => state.drawAssistant?.type, + drawGraphicName: (state) => state.drawAssistant?.description, + drawGraphicTemplate: (state) => state.drawAssistant?.graphicTemplate, + + selectedGraphicType: (state) => { + if (state.selectedGraphics) { + if (state.selectedGraphics.length === 1) { + return state.selectedGraphics[0].type; + } + } + }, + selectedObjName: (state) => { + if (state.selectedGraphics) { + if (state.selectedGraphics.length == 0) { + return '画布'; + } else if (state.selectedGraphics.length == 1) { + return state.selectedGraphics[0].type; + } + return '多选'; + } + return ''; + }, + selectedGraphic: (state) => { + if (state.selectedGraphics) { + if (state.selectedGraphics.length === 1) { + return state.selectedGraphics[0]; + } + } + return null; + }, + }, + actions: { + getDrawApp(): JlDrawApp { + const app = getDrawApp(); + if (app == null) { + throw new Error('未初始化app'); + } + return app; + }, + getJlCanvas(): JlCanvas { + return this.getDrawApp().canvas; + }, + initDrawApp(dom: HTMLElement) { + const app = initDrawApp(dom); + app.on('interaction-plugin-resume', (plugin) => { + if (plugin.isAppPlugin()) { + if (Object.hasOwn(plugin, '__GraphicDrawAssistant')) { + this.drawAssistant = plugin as DrawAssistant; + } else { + this.drawAssistant = null; + } + } + }); + app.on('graphicselectedchange', () => { + this.selectedGraphics = app.selectedGraphics; + }); + this.selectedGraphics = []; + return app; + }, + destroy() { + // console.log('绘制状态清空,绘制应用销毁'); + this.drawAssistant = null; + this.selectedGraphics = null; + destroyDrawApp(); + }, + setDraftId(id: number | null) { + this.draftId = id; + }, + setDraftType(type: string) { + this.draftType = type; + }, + }, +});