From ff655373ed8a1f4e4dac131c339e1a40305e53c3 Mon Sep 17 00:00:00 2001 From: fan Date: Thu, 21 Dec 2023 10:29:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=85=B3=E8=81=94=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../draw-app/properties/SignalProperty.vue | 62 ++++++ src/drawApp/graphics/SignalInteraction.ts | 6 + src/graphics/CommonGraphics.ts | 2 +- src/graphics/signal/Signal.ts | 98 ++++++++- src/protos/device_info.ts | 62 +++--- src/protos/stationLayoutGraphics.ts | 26 +++ src/protos/system_warn_message.ts | 188 ++++++++++++++++++ xian-ncc-da-message | 2 +- 8 files changed, 412 insertions(+), 34 deletions(-) create mode 100644 src/protos/system_warn_message.ts diff --git a/src/components/draw-app/properties/SignalProperty.vue b/src/components/draw-app/properties/SignalProperty.vue index 09a661d..a9abedd 100644 --- a/src/components/draw-app/properties/SignalProperty.vue +++ b/src/components/draw-app/properties/SignalProperty.vue @@ -7,6 +7,35 @@ @blur="onUpdate" label="编号" /> + + + import { useFormData } from 'src/components/DrawAppFormUtils'; import { SignalData } from 'src/drawApp/graphics/SignalInteraction'; +import { Section } from 'src/graphics/section/Section'; +import { Turnout } from 'src/graphics/turnout/Turnout'; +import { graphicData } from 'src/protos/stationLayoutGraphics'; import { useDrawStore } from 'src/stores/draw-store'; +import { computed } from 'vue'; const drawStore = useDrawStore(); const { data: signalModel, onUpdate } = useFormData( @@ -39,6 +72,35 @@ const { data: signalModel, onUpdate } = useFormData( drawStore.getDrawApp() ); +const refDevData = computed(() => { + console.log(signalModel, '===='); + return signalModel.refDevice + ? { + ...signalModel.refDevice.toObject(), + code: drawStore + .getDrawApp() + .queryStore.queryById
(signalModel.refDevice.id) + .datas.code, + } + : { + id: 0, + deviceType: graphicData.RelatedRef.DeviceType.Section, + devicePort: graphicData.RelatedRef.DevicePort.A, + code: '', + }; +}); + +const DeviceTypeOptions = [ + { label: '区段', value: graphicData.RelatedRef.DeviceType.Section }, + { label: '道岔', value: graphicData.RelatedRef.DeviceType.Turnout }, +]; + +const DevicePortOptions = [ + { label: 'A端', value: graphicData.RelatedRef.DevicePort.A }, + { label: 'B端', value: graphicData.RelatedRef.DevicePort.B }, + { label: 'C端', value: graphicData.RelatedRef.DevicePort.C }, +]; + const CoordinateSystemOptions = [ { label: '车辆段', value: 'DEPOT' }, { label: '停车场', value: 'PARKING_LOT' }, diff --git a/src/drawApp/graphics/SignalInteraction.ts b/src/drawApp/graphics/SignalInteraction.ts index 5b2e4ba..a5e6a0f 100644 --- a/src/drawApp/graphics/SignalInteraction.ts +++ b/src/drawApp/graphics/SignalInteraction.ts @@ -47,6 +47,12 @@ export class SignalData extends GraphicDataBase implements ISignalData { set mirror(v: boolean) { this.data.mirror = v; } + get refDevice(): graphicData.RelatedRef { + return this.data.refDevice; + } + set refDevice(v: graphicData.RelatedRef) { + this.data.refDevice = v; + } get kilometerSystem(): KilometerSystem { if (!this.data.kilometerSystem) { this.data.kilometerSystem = new graphicData.KilometerSystem(); diff --git a/src/graphics/CommonGraphics.ts b/src/graphics/CommonGraphics.ts index ad150ba..55e9d00 100644 --- a/src/graphics/CommonGraphics.ts +++ b/src/graphics/CommonGraphics.ts @@ -77,7 +77,7 @@ export function drawArrow( export function createRelatedRefProto( type: string, - id: string, + id: number, port?: TurnoutPort | SectionPort ) { const typeMap = new Map([ diff --git a/src/graphics/signal/Signal.ts b/src/graphics/signal/Signal.ts index b40741a..2cd20a6 100644 --- a/src/graphics/signal/Signal.ts +++ b/src/graphics/signal/Signal.ts @@ -5,11 +5,20 @@ import { JlGraphic, JlGraphicTemplate, calculateMirrorPoint, + calculateDistanceFromPointToLine, + calculateFootPointFromPointToLine, + isPointOnLine, } from 'jl-graphic'; import { LampMainBody } from './LampMainBody'; -import { drawArrow } from '../CommonGraphics'; +import { + createRelatedRefProto, + drawArrow, + IRelatedRefData, +} from '../CommonGraphics'; import { SignalCode } from './SignalCode'; import { Station } from '../station/Station'; +import { Turnout, TurnoutPort } from '../turnout/Turnout'; +import { Section, SectionPort } from '../section/Section'; export interface KilometerSystem { get coordinateSystem(): string; @@ -25,6 +34,8 @@ export interface ISignalData extends GraphicData { set mirror(v: boolean); get kilometerSystem(): KilometerSystem; set kilometerSystem(v: KilometerSystem); + get refDevice(): IRelatedRefData | undefined; + set refDevice(v: IRelatedRefData | undefined); clone(): ISignalData; copyFrom(data: ISignalData): void; eq(other: ISignalData): boolean; @@ -206,6 +217,91 @@ export class Signal extends JlGraphic { } this.humanControl.endFill(); } + buildRelation() { + const sections = this.queryStore.queryByType
(Section.Type); + const turnouts = this.queryStore.queryByType(Turnout.Type); + let deviceId = 0; + let deviceType = ''; + let minD = Number.MAX_SAFE_INTEGER; + let port: SectionPort | TurnoutPort | undefined = undefined; + sections.forEach((sec: Section) => { + const verticesList = sec.datas.points; + for (let i = 0; i < verticesList.length - 1; i++) { + const d = calculateDistanceFromPointToLine( + sec.localToCanvasPoint(verticesList[i]), + sec.localToCanvasPoint(verticesList[i + 1]), + this.position + ); + const p = calculateFootPointFromPointToLine( + sec.localToCanvasPoint(verticesList[i]), + sec.localToCanvasPoint(verticesList[i + 1]), + this.position + ); + const onLine = isPointOnLine( + sec.localToCanvasPoint(verticesList[i]), + sec.localToCanvasPoint(verticesList[i + 1]), + p + ); + if (onLine && d < minD) { + minD = d; + deviceId = sec.id; + deviceType = sec.type; + port = SectionPort.A; + } + } + }); + + turnouts.forEach((turnout: Turnout) => { + for (let i = 0; i < turnout.datas.pointA.length; i++) { + const p1 = turnout.localToCanvasPoint( + i === 0 ? new Point(0, 0) : turnout.datas.pointA[i - 1] + ); + const p2 = turnout.localToCanvasPoint(turnout.datas.pointA[i]); + const d = calculateDistanceFromPointToLine(p1, p2, this.position); + const p = calculateFootPointFromPointToLine(p1, p2, this.position); + const onLine = isPointOnLine(p1, p2, p); + if (onLine && d < minD) { + minD = d; + deviceId = turnout.id; + deviceType = turnout.type; + port = TurnoutPort.A; + } + } + for (let i = 0; i < turnout.datas.pointB.length; i++) { + const p1 = turnout.localToCanvasPoint( + i === 0 ? new Point(0, 0) : turnout.datas.pointB[i - 1] + ); + const p2 = turnout.localToCanvasPoint(turnout.datas.pointB[i]); + const d = calculateDistanceFromPointToLine(p1, p2, this.position); + const p = calculateFootPointFromPointToLine(p1, p2, this.position); + const onLine = isPointOnLine(p1, p2, p); + if (onLine && d < minD) { + minD = d; + deviceId = turnout.id; + deviceType = turnout.type; + port = TurnoutPort.B; + } + } + for (let i = 0; i < turnout.datas.pointC.length; i++) { + const p1 = turnout.localToCanvasPoint( + i === 0 ? new Point(0, 0) : turnout.datas.pointC[i - 1] + ); + const p2 = turnout.localToCanvasPoint(turnout.datas.pointC[i]); + const d = calculateDistanceFromPointToLine(p1, p2, this.position); + const p = calculateFootPointFromPointToLine(p1, p2, this.position); + const onLine = isPointOnLine(p1, p2, p); + if (onLine && d < minD) { + minD = d; + deviceId = turnout.id; + deviceType = turnout.type; + port = TurnoutPort.C; + } + } + }); + if (deviceId) { + this.datas.refDevice = createRelatedRefProto(deviceType, deviceId, port); + } + } } export class SignalTemplate extends JlGraphicTemplate { diff --git a/src/protos/device_info.ts b/src/protos/device_info.ts index 2de0198..0de4fa0 100644 --- a/src/protos/device_info.ts +++ b/src/protos/device_info.ts @@ -9,10 +9,10 @@ export namespace state { export class Section extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { - id?: string; + id?: number; code?: string; - childrenId?: string[]; - physicalSectionId?: string; + childrenId?: number[]; + physicalSectionId?: number; destinationCode?: string; kilometer?: DeviceKilometer; }) { @@ -40,9 +40,9 @@ export namespace state { } } get id() { - return pb_1.Message.getFieldWithDefault(this, 1, "") as string; + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; } - set id(value: string) { + set id(value: number) { pb_1.Message.setField(this, 1, value); } get code() { @@ -52,15 +52,15 @@ export namespace state { pb_1.Message.setField(this, 2, value); } get childrenId() { - return pb_1.Message.getFieldWithDefault(this, 3, []) as string[]; + return pb_1.Message.getFieldWithDefault(this, 3, []) as number[]; } - set childrenId(value: string[]) { + set childrenId(value: number[]) { pb_1.Message.setField(this, 3, value); } get physicalSectionId() { - return pb_1.Message.getFieldWithDefault(this, 4, "") as string; + return pb_1.Message.getFieldWithDefault(this, 4, 0) as number; } - set physicalSectionId(value: string) { + set physicalSectionId(value: number) { pb_1.Message.setField(this, 4, value); } get destinationCode() { @@ -79,10 +79,10 @@ export namespace state { return pb_1.Message.getField(this, 6) != null; } static fromObject(data: { - id?: string; + id?: number; code?: string; - childrenId?: string[]; - physicalSectionId?: string; + childrenId?: number[]; + physicalSectionId?: number; destinationCode?: string; kilometer?: ReturnType; }): Section { @@ -109,10 +109,10 @@ export namespace state { } toObject() { const data: { - id?: string; + id?: number; code?: string; - childrenId?: string[]; - physicalSectionId?: string; + childrenId?: number[]; + physicalSectionId?: number; destinationCode?: string; kilometer?: ReturnType; } = {}; @@ -140,14 +140,14 @@ export namespace state { 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.id != 0) + writer.writeUint32(1, this.id); if (this.code.length) writer.writeString(2, this.code); if (this.childrenId.length) - writer.writeRepeatedString(3, this.childrenId); - if (this.physicalSectionId.length) - writer.writeString(4, this.physicalSectionId); + writer.writePackedUint32(3, this.childrenId); + if (this.physicalSectionId != 0) + writer.writeUint32(4, this.physicalSectionId); if (this.destinationCode.length) writer.writeString(5, this.destinationCode); if (this.has_kilometer) @@ -162,16 +162,16 @@ export namespace state { break; switch (reader.getFieldNumber()) { case 1: - message.id = reader.readString(); + message.id = reader.readUint32(); break; case 2: message.code = reader.readString(); break; case 3: - pb_1.Message.addToRepeatedField(message, 3, reader.readString()); + message.childrenId = reader.readPackedUint32(); break; case 4: - message.physicalSectionId = reader.readString(); + message.physicalSectionId = reader.readUint32(); break; case 5: message.destinationCode = reader.readString(); @@ -194,7 +194,7 @@ export namespace state { export class Turnout extends pb_1.Message { #one_of_decls: number[][] = []; constructor(data?: any[] | { - id?: string; + id?: number; code?: string; kilometer?: DeviceKilometer; }) { @@ -213,9 +213,9 @@ export namespace state { } } get id() { - return pb_1.Message.getFieldWithDefault(this, 1, "") as string; + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; } - set id(value: string) { + set id(value: number) { pb_1.Message.setField(this, 1, value); } get code() { @@ -234,7 +234,7 @@ export namespace state { return pb_1.Message.getField(this, 3) != null; } static fromObject(data: { - id?: string; + id?: number; code?: string; kilometer?: ReturnType; }): Turnout { @@ -252,7 +252,7 @@ export namespace state { } toObject() { const data: { - id?: string; + id?: number; code?: string; kilometer?: ReturnType; } = {}; @@ -271,8 +271,8 @@ export namespace state { 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.id != 0) + writer.writeUint32(1, this.id); if (this.code.length) writer.writeString(2, this.code); if (this.has_kilometer) @@ -287,7 +287,7 @@ export namespace state { break; switch (reader.getFieldNumber()) { case 1: - message.id = reader.readString(); + message.id = reader.readUint32(); break; case 2: message.code = reader.readString(); diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index fe3a294..893e3ba 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -3252,6 +3252,7 @@ export namespace graphicData { code?: string; mirror?: boolean; kilometerSystem?: KilometerSystem; + refDevice?: RelatedRef; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); @@ -3268,6 +3269,9 @@ export namespace graphicData { if ("kilometerSystem" in data && data.kilometerSystem != undefined) { this.kilometerSystem = data.kilometerSystem; } + if ("refDevice" in data && data.refDevice != undefined) { + this.refDevice = data.refDevice; + } } } get common() { @@ -3300,11 +3304,21 @@ export namespace graphicData { get has_kilometerSystem() { return pb_1.Message.getField(this, 6) != null; } + get refDevice() { + return pb_1.Message.getWrapperField(this, RelatedRef, 7) as RelatedRef; + } + set refDevice(value: RelatedRef) { + pb_1.Message.setWrapperField(this, 7, value); + } + get has_refDevice() { + return pb_1.Message.getField(this, 7) != null; + } static fromObject(data: { common?: ReturnType; code?: string; mirror?: boolean; kilometerSystem?: ReturnType; + refDevice?: ReturnType; }): Signal { const message = new Signal({}); if (data.common != null) { @@ -3319,6 +3333,9 @@ export namespace graphicData { if (data.kilometerSystem != null) { message.kilometerSystem = KilometerSystem.fromObject(data.kilometerSystem); } + if (data.refDevice != null) { + message.refDevice = RelatedRef.fromObject(data.refDevice); + } return message; } toObject() { @@ -3327,6 +3344,7 @@ export namespace graphicData { code?: string; mirror?: boolean; kilometerSystem?: ReturnType; + refDevice?: ReturnType; } = {}; if (this.common != null) { data.common = this.common.toObject(); @@ -3340,6 +3358,9 @@ export namespace graphicData { if (this.kilometerSystem != null) { data.kilometerSystem = this.kilometerSystem.toObject(); } + if (this.refDevice != null) { + data.refDevice = this.refDevice.toObject(); + } return data; } serialize(): Uint8Array; @@ -3354,6 +3375,8 @@ export namespace graphicData { writer.writeBool(3, this.mirror); if (this.has_kilometerSystem) writer.writeMessage(6, this.kilometerSystem, () => this.kilometerSystem.serialize(writer)); + if (this.has_refDevice) + writer.writeMessage(7, this.refDevice, () => this.refDevice.serialize(writer)); if (!w) return writer.getResultBuffer(); } @@ -3375,6 +3398,9 @@ export namespace graphicData { case 6: reader.readMessage(message.kilometerSystem, () => message.kilometerSystem = KilometerSystem.deserialize(reader)); break; + case 7: + reader.readMessage(message.refDevice, () => message.refDevice = RelatedRef.deserialize(reader)); + break; default: reader.skipField(); } } diff --git a/src/protos/system_warn_message.ts b/src/protos/system_warn_message.ts new file mode 100644 index 0000000..42bb039 --- /dev/null +++ b/src/protos/system_warn_message.ts @@ -0,0 +1,188 @@ +/** + * Generated by the protoc-gen-ts. DO NOT EDIT! + * compiler version: 4.23.1 + * source: system_warn_message.proto + * git: https://github.com/thesayyn/protoc-gen-ts */ +import * as pb_1 from "google-protobuf"; +export namespace state { + export class WarnLineMessage extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + msgs?: WarnMessage[]; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [1], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("msgs" in data && data.msgs != undefined) { + this.msgs = data.msgs; + } + } + } + get msgs() { + return pb_1.Message.getRepeatedWrapperField(this, WarnMessage, 1) as WarnMessage[]; + } + set msgs(value: WarnMessage[]) { + pb_1.Message.setRepeatedWrapperField(this, 1, value); + } + static fromObject(data: { + msgs?: ReturnType[]; + }): WarnLineMessage { + const message = new WarnLineMessage({}); + if (data.msgs != null) { + message.msgs = data.msgs.map(item => WarnMessage.fromObject(item)); + } + return message; + } + toObject() { + const data: { + msgs?: ReturnType[]; + } = {}; + if (this.msgs != null) { + data.msgs = this.msgs.map((item: WarnMessage) => 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.msgs.length) + writer.writeRepeatedMessage(1, this.msgs, (item: WarnMessage) => item.serialize(writer)); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): WarnLineMessage { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new WarnLineMessage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + reader.readMessage(message.msgs, () => pb_1.Message.addToRepeatedWrapperField(message, 1, WarnMessage.deserialize(reader), WarnMessage)); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): WarnLineMessage { + return WarnLineMessage.deserialize(bytes); + } + } + export class WarnMessage extends pb_1.Message { + #one_of_decls: number[][] = []; + constructor(data?: any[] | { + lineId?: number; + occRealConned?: boolean; + occUnrealConned?: boolean; + }) { + super(); + pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); + if (!Array.isArray(data) && typeof data == "object") { + if ("lineId" in data && data.lineId != undefined) { + this.lineId = data.lineId; + } + if ("occRealConned" in data && data.occRealConned != undefined) { + this.occRealConned = data.occRealConned; + } + if ("occUnrealConned" in data && data.occUnrealConned != undefined) { + this.occUnrealConned = data.occUnrealConned; + } + } + } + get lineId() { + return pb_1.Message.getFieldWithDefault(this, 1, 0) as number; + } + set lineId(value: number) { + pb_1.Message.setField(this, 1, value); + } + get occRealConned() { + return pb_1.Message.getFieldWithDefault(this, 2, false) as boolean; + } + set occRealConned(value: boolean) { + pb_1.Message.setField(this, 2, value); + } + get occUnrealConned() { + return pb_1.Message.getFieldWithDefault(this, 3, false) as boolean; + } + set occUnrealConned(value: boolean) { + pb_1.Message.setField(this, 3, value); + } + static fromObject(data: { + lineId?: number; + occRealConned?: boolean; + occUnrealConned?: boolean; + }): WarnMessage { + const message = new WarnMessage({}); + if (data.lineId != null) { + message.lineId = data.lineId; + } + if (data.occRealConned != null) { + message.occRealConned = data.occRealConned; + } + if (data.occUnrealConned != null) { + message.occUnrealConned = data.occUnrealConned; + } + return message; + } + toObject() { + const data: { + lineId?: number; + occRealConned?: boolean; + occUnrealConned?: boolean; + } = {}; + if (this.lineId != null) { + data.lineId = this.lineId; + } + if (this.occRealConned != null) { + data.occRealConned = this.occRealConned; + } + if (this.occUnrealConned != null) { + data.occUnrealConned = this.occUnrealConned; + } + 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.lineId != 0) + writer.writeInt32(1, this.lineId); + if (this.occRealConned != false) + writer.writeBool(2, this.occRealConned); + if (this.occUnrealConned != false) + writer.writeBool(3, this.occUnrealConned); + if (!w) + return writer.getResultBuffer(); + } + static deserialize(bytes: Uint8Array | pb_1.BinaryReader): WarnMessage { + const reader = bytes instanceof pb_1.BinaryReader ? bytes : new pb_1.BinaryReader(bytes), message = new WarnMessage(); + while (reader.nextField()) { + if (reader.isEndGroup()) + break; + switch (reader.getFieldNumber()) { + case 1: + message.lineId = reader.readInt32(); + break; + case 2: + message.occRealConned = reader.readBool(); + break; + case 3: + message.occUnrealConned = reader.readBool(); + break; + default: reader.skipField(); + } + } + return message; + } + serializeBinary(): Uint8Array { + return this.serialize(); + } + static deserializeBinary(bytes: Uint8Array): WarnMessage { + return WarnMessage.deserialize(bytes); + } + } +} diff --git a/xian-ncc-da-message b/xian-ncc-da-message index fa88eaa..509c8f3 160000 --- a/xian-ncc-da-message +++ b/xian-ncc-da-message @@ -1 +1 @@ -Subproject commit fa88eaa4292a4818d28628d66227d38765eacf84 +Subproject commit 509c8f3f91257e1c489c2bb2435fa66f0fc29cab