diff --git a/src/components/draw-app/properties/PlatformProperty.vue b/src/components/draw-app/properties/PlatformProperty.vue index 298a098..f94a60e 100644 --- a/src/components/draw-app/properties/PlatformProperty.vue +++ b/src/components/draw-app/properties/PlatformProperty.vue @@ -48,6 +48,16 @@ + + + 关联的物理区段 +
+ + {{ sectionName }} + +
+
+
@@ -56,16 +66,36 @@ import { useFormData } from 'src/components/DrawAppFormUtils'; import { PlatformData } from 'src/drawApp/graphics/PlatformInteraction'; import { Platform } from 'src/graphics/platform/Platform'; +import { Section } from 'src/graphics/section/Section'; import { Station } from 'src/graphics/station/Station'; import { useDrawStore } from 'src/stores/draw-store'; -import { onMounted, ref } from 'vue'; +import { computed, ref } from 'vue'; const drawStore = useDrawStore(); const { data: platformModel, onUpdate } = useFormData( new PlatformData(), drawStore.getDrawApp() ); -const stationName = ref(''); +const stationName = computed(() => { + const platform = drawStore.selectedGraphic as Platform; + if (platformModel.refStation) { + const refStation = platform.queryStore.queryById( + platformModel.refStation + ); + return refStation.datas.name; + } + return ''; +}); +const sectionName = computed(() => { + const platform = drawStore.selectedGraphic as Platform; + if (platformModel.refSectionId) { + const refSection = platform.queryStore.queryById
( + platformModel.refSectionId + ); + return refSection.datas.code; + } + return ''; +}); const optionsDoor = [ { label: '是', value: true }, { label: '否', value: false }, @@ -78,16 +108,4 @@ const optionsUpAndDown = [ { label: '上行', value: true }, { label: '下行', value: false }, ]; - -onMounted(() => { - const platform = drawStore.selectedGraphic as Platform; - if (platform) { - if (platformModel.refStation) { - const refStation = platform.queryStore.queryById( - platformModel.refStation - ) as Station; - stationName.value = refStation.datas.name; - } - } -}); diff --git a/src/drawApp/graphics/PlatformInteraction.ts b/src/drawApp/graphics/PlatformInteraction.ts index 005bfe2..22db1ef 100644 --- a/src/drawApp/graphics/PlatformInteraction.ts +++ b/src/drawApp/graphics/PlatformInteraction.ts @@ -65,6 +65,12 @@ export class PlatformData extends GraphicDataBase implements IPlatformData { set refStation(v: string) { this.data.refStation = v; } + get refSectionId(): string { + return this.data.refSectionId; + } + set refSectionId(v: string) { + this.data.refSectionId = v; + } clone(): PlatformData { return new PlatformData(this.data.cloneMessage()); diff --git a/src/graphics/platform/Platform.ts b/src/graphics/platform/Platform.ts index 89c03bb..4a1e9e9 100644 --- a/src/graphics/platform/Platform.ts +++ b/src/graphics/platform/Platform.ts @@ -6,9 +6,11 @@ import { JlGraphicTemplate, VectorText, calculateMirrorPoint, + distance2, getRectangleCenter, } from 'src/jl-graphic'; import { Station } from '../station/Station'; +import { Section } from '../section/Section'; export interface IPlatformData extends GraphicData { get code(): string; // 编号 @@ -21,6 +23,8 @@ export interface IPlatformData extends GraphicData { set up(v: boolean); get refStation(): string; // 关联的车站 set refStation(v: string); + get refSectionId(): string; // 关联的物理区段 + set refSectionId(v: string); clone(): IPlatformData; copyFrom(data: IPlatformData): void; eq(other: IPlatformData): boolean; @@ -435,6 +439,29 @@ export class Platform extends JlGraphic { break; } } + const sections = this.queryStore.queryByType
(Section.Type); + const minDistanceRefSections: Section[] = []; + sections.forEach((section) => { + const sP = section.localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + minDistanceRefSections.push(section); + } + }); + if (minDistanceRefSections) { + const refSection = minDistanceRefSections.reduce((prev, cur) => { + return distance2( + prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), + this.position + ) > + distance2( + cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), + this.position + ) + ? cur + : prev; + }); + this.datas.refSectionId = refSection.id; + } } } diff --git a/src/protos/stationLayoutGraphics.ts b/src/protos/stationLayoutGraphics.ts index 3373256..8c71917 100644 --- a/src/protos/stationLayoutGraphics.ts +++ b/src/protos/stationLayoutGraphics.ts @@ -1708,6 +1708,7 @@ export namespace graphicData { direction?: string; refStation?: string; up?: boolean; + refSectionId?: string; }) { super(); pb_1.Message.initialize(this, Array.isArray(data) ? data : [], 0, -1, [], this.#one_of_decls); @@ -1730,6 +1731,9 @@ export namespace graphicData { if ("up" in data && data.up != undefined) { this.up = data.up; } + if ("refSectionId" in data && data.refSectionId != undefined) { + this.refSectionId = data.refSectionId; + } } } get common() { @@ -1771,6 +1775,12 @@ export namespace graphicData { set up(value: boolean) { pb_1.Message.setField(this, 7, value); } + get refSectionId() { + return pb_1.Message.getFieldWithDefault(this, 8, "") as string; + } + set refSectionId(value: string) { + pb_1.Message.setField(this, 8, value); + } static fromObject(data: { common?: ReturnType; code?: string; @@ -1778,6 +1788,7 @@ export namespace graphicData { direction?: string; refStation?: string; up?: boolean; + refSectionId?: string; }): Platform { const message = new Platform({}); if (data.common != null) { @@ -1798,6 +1809,9 @@ export namespace graphicData { if (data.up != null) { message.up = data.up; } + if (data.refSectionId != null) { + message.refSectionId = data.refSectionId; + } return message; } toObject() { @@ -1808,6 +1822,7 @@ export namespace graphicData { direction?: string; refStation?: string; up?: boolean; + refSectionId?: string; } = {}; if (this.common != null) { data.common = this.common.toObject(); @@ -1827,6 +1842,9 @@ export namespace graphicData { if (this.up != null) { data.up = this.up; } + if (this.refSectionId != null) { + data.refSectionId = this.refSectionId; + } return data; } serialize(): Uint8Array; @@ -1845,6 +1863,8 @@ export namespace graphicData { writer.writeString(6, this.refStation); if (this.up != false) writer.writeBool(7, this.up); + if (this.refSectionId.length) + writer.writeString(8, this.refSectionId); if (!w) return writer.getResultBuffer(); } @@ -1872,6 +1892,9 @@ export namespace graphicData { case 7: message.up = reader.readBool(); break; + case 8: + message.refSectionId = reader.readString(); + break; default: reader.skipField(); } }