列车显示调整

This commit is contained in:
fan 2023-07-19 13:53:46 +08:00
parent 253f7fb780
commit f3b83793c8
5 changed files with 60 additions and 25 deletions

@ -1 +1 @@
Subproject commit 0e8a73e1028177059ac306ca0c5abb8c52c2b3e2
Subproject commit c538cad92ad51bae8d2ca0bcc147a8a5a26cff5f

View File

@ -1,16 +1,15 @@
<!-- eslint-disable vue/no-mutating-props -->
<template>
<q-dialog ref="dialogRef">
<q-card>
<q-card style="width: 250px">
<q-card-section> <div class="text-h6">添加列车</div> </q-card-section>
<q-card-section class="q-pt-none">
<q-input
type="number"
dense
outlined
:disable="true"
label="Link"
v-model="props.linkIndex"
v-model="props.link.code"
/>
</q-card-section>
<q-card-section class="q-pt-none">
@ -18,9 +17,8 @@
type="number"
dense
outlined
label="列车偏移"
:label="`列车偏移(mm)[Link长度为${props.link.linkLength}]`"
:min="0"
:max="1"
v-model.number="offset"
/>
</q-card-section>
@ -50,11 +48,12 @@
<script setup lang="ts">
import { useDialogPluginComponent } from 'quasar';
import { SectionLink } from 'src/graphics/sectionLink/SectionLink';
import { ref } from 'vue';
const props = defineProps({
linkIndex: {
type: Number,
link: {
type: SectionLink,
required: true,
},
});

View File

@ -152,7 +152,7 @@ export class SectionLinkOperateInteraction extends GraphicInteractionPlugin<Sect
title: '创建列车',
message: '',
component: AddTrainDialog,
componentProps: { linkIndex: link.datas.index },
componentProps: { link: link },
cancel: true,
persistent: true,
}).onOk((data: { offset: number; dir: 1 | 0 }) => {

View File

@ -10,11 +10,13 @@ import {
movePointAlongNormal,
} from 'src/jl-graphic';
import { ILineGraphic } from 'src/jl-graphic/plugins/GraphicEditPlugin';
import { AxleCounting } from '../axleCounting/AxleCounting';
import {
IRelatedRefData,
ISimpleRefData,
protoPort2Data,
} from '../CommonGraphics';
import { Turnout } from '../turnout/Turnout';
export interface ISectionLinkData extends GraphicData {
get code(): string; // 编号
@ -50,6 +52,7 @@ export class SectionLink extends JlGraphic implements ILineGraphic {
lineGraphic: Graphics;
labelGraphic: VectorText;
divisionGraphic: Graphics = new Graphics();
_linkLength = 0;
constructor() {
super(SectionLink.Type);
@ -148,6 +151,43 @@ export class SectionLink extends JlGraphic implements ILineGraphic {
old.points = points;
this.updateData(old);
}
get linkLength(): number {
if (!this._linkLength) {
const queryStore = this.getGraphicApp().queryStore;
const aSimDevice = queryStore.queryById(this.datas.aSimRef.id);
const bSimDevice = queryStore.queryById(this.datas.bSimRef.id);
if (!aSimDevice || !bSimDevice) {
throw new Error('未获取到link两侧简单关联设备');
}
let k1 = 0;
let k2 = 0;
if (aSimDevice.type === AxleCounting.Type) {
k1 = (aSimDevice as AxleCounting).datas.kilometerSystem.kilometer;
} else if (aSimDevice.type === Turnout.Type) {
const ks = (aSimDevice as Turnout).datas.kilometerSystem.find(
(item) => item.coordinateSystem === 'MAIN_LINE'
);
if (ks) {
k1 = ks.kilometer;
}
}
if (bSimDevice.type === AxleCounting.Type) {
k2 = (bSimDevice as AxleCounting).datas.kilometerSystem.kilometer;
} else if (bSimDevice.type === Turnout.Type) {
const ks = (bSimDevice as Turnout).datas.kilometerSystem.find(
(item) => item.coordinateSystem === 'MAIN_LINE'
);
if (ks) {
k2 = ks.kilometer;
}
}
if (!k2 || !k1) {
throw new Error('未获取到link两侧公里标');
}
this._linkLength = k2 - k1;
}
return this._linkLength;
}
loadRelations(): void {
if (this.datas.aSimRef) {

View File

@ -9,7 +9,9 @@ import {
calculateMirrorPoint,
distance,
} from 'src/jl-graphic';
import { AxleCounting } from '../axleCounting/AxleCounting';
import { SectionLink } from '../sectionLink/SectionLink';
import { Turnout } from '../turnout/Turnout';
export interface ITrainData extends GraphicData {
get code(): string; // 车号
@ -290,7 +292,6 @@ export class Train extends JlGraphic {
this.trainbody.doRepaint(this.states);
const bodyWH = this.trainbody.getBodyWH();
this.trainHead.doRepaint(this.states, bodyWH);
// this.position.set(0, 0);
const link =
this.getGraphicApp().queryStore.queryByCodeAndType<SectionLink>(
this.states.headLinkId,
@ -299,6 +300,11 @@ export class Train extends JlGraphic {
if (!link) {
return;
}
const linkLength = link.linkLength;
if (this.states.headLinkOffset > linkLength) {
console.error('偏移长度超出link长度');
return;
}
const lengths = [];
let totalLength = 0;
const points = [...link.datas.points];
@ -312,27 +318,17 @@ export class Train extends JlGraphic {
lengths.push(l);
totalLength += l;
}
let offsetL = totalLength * this.states.headLinkOffset;
if (this.states.up) {
lengths.reverse();
points.reverse();
}
const offset = this.states.headLinkOffset / linkLength; // 百分比偏移
let offsetL = totalLength * offset;
const indexP = lengths.findIndex((l) => {
offsetL -= l;
return offsetL <= 0;
});
const startP = points[indexP];
const endP = points[indexP + 1];
const px =
startP.x + Math.round(this.states.headLinkOffset * (endP.x - startP.x));
const py =
startP.y + Math.round(this.states.headLinkOffset * (endP.y - startP.y));
let angle = 0;
if (this.states.up) {
angle = Math.atan2(startP.y - endP.y, startP.x - endP.x);
} else {
angle = Math.atan2(endP.y - startP.y, endP.x - startP.x);
}
const px = startP.x + Math.round(offset * (endP.x - startP.x));
const py = startP.y + Math.round(offset * (endP.y - startP.y));
const angle = Math.atan2(endP.y - startP.y, endP.x - startP.x);
this.position.set(px, py);
this.rotation = angle;
}