一键生成信号机停车标的设备关联关系

This commit is contained in:
fan 2023-08-07 11:23:08 +08:00
parent ed4a2d2751
commit 2bb166abbe
5 changed files with 147 additions and 3 deletions

@ -1 +1 @@
Subproject commit 86bf1f0c76ade5866afd8063e8f263ca9eda55a5
Subproject commit 1db196077c6293a757d3462b0aa0c7a62d219035

View File

@ -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() {

View File

@ -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 = '';
}
}

View File

@ -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>(Section.Type);
const turnouts = this.queryStore.queryByType<Turnout>(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<Signal> {

View File

@ -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>(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<StopPosition> {