diff --git a/bj-rtss-message b/bj-rtss-message index 86bf1f0..1db1960 160000 --- a/bj-rtss-message +++ b/bj-rtss-message @@ -1 +1 @@ -Subproject commit 86bf1f0c76ade5866afd8063e8f263ca9eda55a5 +Subproject commit 1db196077c6293a757d3462b0aa0c7a62d219035 diff --git a/src/components/draw-app/properties/SignalProperty.vue b/src/components/draw-app/properties/SignalProperty.vue index 79b63f6..f9aaa7c 100644 --- a/src/components/draw-app/properties/SignalProperty.vue +++ b/src/components/draw-app/properties/SignalProperty.vue @@ -37,6 +37,7 @@ style="margin-top: 10px" v-model="refDevData.deviceType" :options="DeviceTypeOptions" + :readonly="true" :map-options="true" :emit-value="true" @update:model-value="onUpdate" @@ -47,6 +48,7 @@ v-if="refDevData.deviceType === graphicData.RelatedRef.DeviceType.Section" style="margin-top: 10px" v-model="refDevData.id" + :readonly="true" :options="sectionList" :map-options="true" :emit-value="true" @@ -59,6 +61,7 @@ style="margin-top: 10px" v-model="refDevData.id" :options="turnoutList" + :readonly="true" :map-options="true" :emit-value="true" @update:model-value="onUpdate" @@ -70,6 +73,7 @@ style="margin-top: 10px" v-model="refDevData.devicePort" :options="DevicePortOptions" + :readonly="true" :map-options="true" :emit-value="true" @update:model-value="onUpdate" @@ -123,6 +127,10 @@ function initRefData(signal: Signal) { refDevData.id = signalModel.refDev.id; refDevData.devicePort = signalModel.refDev.devicePort; refDevData.deviceType = signalModel.refDev.deviceType; + } else { + refDevData.id = ''; + refDevData.deviceType = graphicData.RelatedRef.DeviceType.Section; + refDevData.devicePort = graphicData.RelatedRef.DevicePort.A; } } function initDeviceList() { diff --git a/src/components/draw-app/properties/StopPositionProperty.vue b/src/components/draw-app/properties/StopPositionProperty.vue index 6317a02..245620e 100644 --- a/src/components/draw-app/properties/StopPositionProperty.vue +++ b/src/components/draw-app/properties/StopPositionProperty.vue @@ -48,6 +48,7 @@ v-model="refDevData.id" :options="sectionList" :map-options="true" + :readonly="true" :emit-value="true" @update:model-value="onUpdate" label="关联设备" @@ -120,6 +121,8 @@ function initRefData(stopPosition: StopPosition) { } if (stopPositionModel.refDev) { refDevData.id = stopPositionModel.refDev.id; + } else { + refDevData.id = ''; } } diff --git a/src/graphics/signal/Signal.ts b/src/graphics/signal/Signal.ts index bb57066..78f9f4c 100644 --- a/src/graphics/signal/Signal.ts +++ b/src/graphics/signal/Signal.ts @@ -1,14 +1,23 @@ import { Graphics, Point } from 'pixi.js'; import { + calculateDistanceFromPointToLine, + calculateFootPointFromPointToLine, GraphicData, GraphicState, + isPointOnLine, JlGraphic, JlGraphicTemplate, } from 'src/jl-graphic'; import { calculateMirrorPoint } from 'src/jl-graphic'; import { LampMainBody } from './LampMainBody'; -import { drawArrow, IRelatedRefData } from '../CommonGraphics'; +import { + drawArrow, + IRelatedRefData, + createRelatedRefProto, +} from '../CommonGraphics'; import { SignalCode } from './SignalCode'; +import { Section, SectionPort } from '../section/Section'; +import { Turnout, TurnoutPort } from '../turnout/Turnout'; export interface KilometerSystem { get coordinateSystem(): string; @@ -197,6 +206,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 = ''; + let deviceType = ''; + let minD = Number.MAX_SAFE_INTEGER; + let port: SectionPort | TurnoutPort = SectionPort.A; + sections.forEach((sec: Section) => { + for (let i = 0; i < sec.datas.points.length - 1; i++) { + const d = calculateDistanceFromPointToLine( + sec.localToCanvasPoint(sec.datas.points[i]), + sec.localToCanvasPoint(sec.datas.points[i + 1]), + this.position + ); + const p = calculateFootPointFromPointToLine( + sec.localToCanvasPoint(sec.datas.points[i]), + sec.localToCanvasPoint(sec.datas.points[i + 1]), + this.position + ); + const onLine = isPointOnLine( + sec.localToCanvasPoint(sec.datas.points[i]), + sec.localToCanvasPoint(sec.datas.points[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.refDev = createRelatedRefProto(deviceType, deviceId, port); + } + } } export class SignalTemplate extends JlGraphicTemplate { diff --git a/src/graphics/stopPosition/StopPosition.ts b/src/graphics/stopPosition/StopPosition.ts index 4900454..c48b3af 100644 --- a/src/graphics/stopPosition/StopPosition.ts +++ b/src/graphics/stopPosition/StopPosition.ts @@ -1,11 +1,15 @@ import { Graphics } from 'pixi.js'; import { + calculateDistanceFromPointToLine, + calculateFootPointFromPointToLine, + isPointOnLine, GraphicData, JlGraphic, JlGraphicTemplate, VectorText, } from 'src/jl-graphic'; -import { IRelatedRefData } from '../CommonGraphics'; +import { IRelatedRefData, createRelatedRefProto } from '../CommonGraphics'; +import { Section, SectionPort } from '../section/Section'; export enum CoachNum { Four = 0, @@ -88,6 +92,41 @@ export class StopPosition extends JlGraphic { } this.signBody.endFill(); } + buildRelation() { + const sections = this.queryStore.queryByType
(Section.Type); + let deviceId = ''; + let deviceType = ''; + let minD = Number.MAX_SAFE_INTEGER; + let port = SectionPort.A; + sections.forEach((sec: Section) => { + for (let i = 0; i < sec.datas.points.length - 1; i++) { + const d = calculateDistanceFromPointToLine( + sec.localToCanvasPoint(sec.datas.points[i]), + sec.localToCanvasPoint(sec.datas.points[i + 1]), + this.position + ); + const p = calculateFootPointFromPointToLine( + sec.localToCanvasPoint(sec.datas.points[i]), + sec.localToCanvasPoint(sec.datas.points[i + 1]), + this.position + ); + const onLine = isPointOnLine( + sec.localToCanvasPoint(sec.datas.points[i]), + sec.localToCanvasPoint(sec.datas.points[i + 1]), + p + ); + if (onLine && d < minD) { + minD = d; + deviceId = sec.id; + deviceType = sec.type; + port = SectionPort.A; + } + } + }); + if (deviceId) { + this.datas.refDev = createRelatedRefProto(deviceType, deviceId, port); + } + } } export class StopPositionTemplate extends JlGraphicTemplate {