列车添加公里标转换

This commit is contained in:
dong 2023-11-02 17:08:35 +08:00
parent d742c4c569
commit 04b7391fe1
5 changed files with 79 additions and 22 deletions

View File

@ -24,6 +24,7 @@ import { ContextMenu } from 'src/jl-graphic/ui/ContextMenu';
import { AxleCounting } from 'src/graphics/axleCounting/AxleCounting'; import { AxleCounting } from 'src/graphics/axleCounting/AxleCounting';
import { ApiError } from 'src/boot/axios'; import { ApiError } from 'src/boot/axios';
import { state } from 'src/protos/device_state'; import { state } from 'src/protos/device_state';
import { getKmDistance } from '../lineScene';
export class SectionData extends GraphicDataBase implements ISectionData { export class SectionData extends GraphicDataBase implements ISectionData {
constructor(data?: graphicData.Section) { constructor(data?: graphicData.Section) {
@ -229,21 +230,21 @@ export class SectionOperateInteraction extends GraphicInteractionPlugin<Section>
section, section,
AxleCounting.Type AxleCounting.Type
); );
let A = 0; let AKm;
let B = 0; let BKm;
if (relations.length == 2) { if (relations.length == 2) {
relations.forEach((item) => { relations.forEach((item) => {
const rp = item.getRelationParam(section); const rp = item.getRelationParam(section);
const other = item.getOtherGraphic(section) as AxleCounting; const other = item.getOtherGraphic(section) as AxleCounting;
if (rp.getParam() == 'A') { if (rp.getParam() == 'A') {
A = other.datas.kilometerSystem.kilometer; AKm = other.datas.kilometerSystem;
} }
if (rp.getParam() == 'B') { if (rp.getParam() == 'B') {
B = other.datas.kilometerSystem.kilometer; BKm = other.datas.kilometerSystem;
} }
}); });
} }
const d = Math.abs(B - A); const d = getKmDistance(BKm, AKm);
Dialog.create({ Dialog.create({
title: '创建列车', title: '创建列车',
message: '', message: '',

View File

@ -30,6 +30,7 @@ import { successNotify } from 'src/utils/CommonNotify';
import { AxleCounting } from 'src/graphics/axleCounting/AxleCounting'; import { AxleCounting } from 'src/graphics/axleCounting/AxleCounting';
import { request } from 'src/protos/request'; import { request } from 'src/protos/request';
import { ApiError } from 'src/boot/axios'; import { ApiError } from 'src/boot/axios';
import { getKmDistance } from '../lineScene';
function getDefaultEndPoint() { function getDefaultEndPoint() {
return { return {
@ -122,11 +123,11 @@ export class TurnoutOperationPlugin extends GraphicInteractionPlugin<Turnout> {
const rp = item.getRelationParam(turnout); const rp = item.getRelationParam(turnout);
return rp.getParam() == port; return rp.getParam() == port;
}); });
const o = turnout.datas.kilometerSystem[0].kilometer; const oKm = turnout.datas.kilometerSystem[0];
let p = 0; let pKm;
if (findAc) { if (findAc) {
const other = findAc.getOtherGraphic(turnout) as AxleCounting; const other = findAc.getOtherGraphic(turnout) as AxleCounting;
p = other.datas.kilometerSystem.kilometer; pKm = other.datas.kilometerSystem;
} else { } else {
const relations = const relations =
turnout.relationManage.getRelationsOfGraphicAndOtherType( turnout.relationManage.getRelationsOfGraphicAndOtherType(
@ -139,10 +140,10 @@ export class TurnoutOperationPlugin extends GraphicInteractionPlugin<Turnout> {
}); });
if (findT) { if (findT) {
const other = findT.getOtherGraphic(turnout) as Turnout; const other = findT.getOtherGraphic(turnout) as Turnout;
p = other.datas.kilometerSystem[0].kilometer; pKm = other.datas.kilometerSystem[0];
} }
} }
const d = Math.abs(p - o); const d = getKmDistance(pKm, oKm);
Dialog.create({ Dialog.create({
title: '创建列车', title: '创建列车',
message: '', message: '',

View File

@ -14,7 +14,11 @@ import {
SignalOperateInteraction, SignalOperateInteraction,
SignalState, SignalState,
} from './graphics/SignalInteraction'; } from './graphics/SignalInteraction';
import { SignalTemplate, Signal } from 'src/graphics/signal/Signal'; import {
SignalTemplate,
Signal,
KilometerSystem,
} from 'src/graphics/signal/Signal';
import { import {
PlatformData, PlatformData,
PlatformOperateInteraction, PlatformOperateInteraction,
@ -270,6 +274,9 @@ export function initLineScene(lineApp: IGraphicApp, sceneName: string) {
ControlShowType(lineScene); ControlShowType(lineScene);
handleSubscribe(lineScene); handleSubscribe(lineScene);
}); });
lineApp.on('destroy', () => {
kilometerConvertMap.clear();
});
} }
function handleSubscribe(lineScene: IGraphicScene) { function handleSubscribe(lineScene: IGraphicScene) {
@ -419,6 +426,7 @@ export async function loadLineDatas(): Promise<IGraphicStorage> {
); );
console.log('加载数据', storage); console.log('加载数据', storage);
// app.updateCanvas(storage.canvas); // app.updateCanvas(storage.canvas);
kilometerConvertMap.set(lineStore.sceneName, storage.kilometerConvertList);
const datas: GraphicData[] = []; const datas: GraphicData[] = [];
storage.Platforms.forEach((platform) => { storage.Platforms.forEach((platform) => {
@ -507,3 +515,49 @@ export async function loadLineDatas(): Promise<IGraphicStorage> {
}); });
} }
} }
const kilometerConvertMap: Map<string, graphicData.KilometerConvert[]> =
new Map();
export function getKmDistance(
km1?: KilometerSystem,
km2?: KilometerSystem
): number {
let d = 0;
if (!km1 || !km2) {
return 0;
}
if (km1.coordinateSystem == km2.coordinateSystem) {
d = Math.abs(km1.kilometer - km2.kilometer);
} else {
const lineStore = useLineStore();
const kmSystemList = kilometerConvertMap.get(lineStore.sceneName);
const find = kmSystemList?.find((item) => {
return (
(item.kmA.coordinateSystem == km1.coordinateSystem &&
item.kmB.coordinateSystem == km2.coordinateSystem) ||
(item.kmA.coordinateSystem == km2.coordinateSystem &&
item.kmB.coordinateSystem == km1.coordinateSystem)
);
});
if (find) {
const isA = find.kmA.coordinateSystem == km1.coordinateSystem;
let m1;
let m2;
if (isA) {
m1 = km1.kilometer - find.kmA.kilometer;
m2 = km2.kilometer - find.kmB.kilometer;
} else {
m1 = km1.kilometer - find.kmB.kilometer;
m2 = km2.kilometer - find.kmA.kilometer;
}
if (find.sameTrend) {
d = Math.abs(m1 - m2);
} else {
d = Math.abs(m1 + m2);
}
} else {
console.log('没有找到对应的公里标转换');
}
}
return d;
}

View File

@ -58,7 +58,7 @@ export function initRelayScene(lineApp: IGraphicApp, sceneName: string) {
relay.refDevice.text = map.get(relay.id)?.replace(/_/g, '\n') as string; relay.refDevice.text = map.get(relay.id)?.replace(/_/g, '\n') as string;
}); });
}); });
relayScene.on('destroy', () => { lineApp.on('destroy', () => {
refRelaysList = []; refRelaysList = [];
}); });
} }

View File

@ -13,6 +13,7 @@ import { Turnout, TurnoutPort } from '../turnout/Turnout';
import { Section } from '../section/Section'; import { Section } from '../section/Section';
import { AxleCounting } from '../axleCounting/AxleCounting'; import { AxleCounting } from '../axleCounting/AxleCounting';
import { state } from 'src/protos/device_state'; import { state } from 'src/protos/device_state';
import { getKmDistance } from 'src/drawApp/lineScene';
export interface ITrainData extends GraphicData { export interface ITrainData extends GraphicData {
get code(): string; // 车号 get code(): string; // 车号
@ -346,11 +347,11 @@ export class Train extends JlGraphic {
const rp = item.getRelationParam(dev as Turnout); const rp = item.getRelationParam(dev as Turnout);
return rp.getParam() == this.states.devicePort; return rp.getParam() == this.states.devicePort;
}); });
const o = dev.datas.kilometerSystem[0].kilometer; const oKm = dev.datas.kilometerSystem[0];
let p = 0; let pKm;
if (findAc) { if (findAc) {
const other = findAc.getOtherGraphic(dev) as AxleCounting; const other = findAc.getOtherGraphic(dev) as AxleCounting;
p = other.datas.kilometerSystem.kilometer; pKm = other.datas.kilometerSystem;
} else { } else {
const relations = dev.relationManage.getRelationsOfGraphicAndOtherType( const relations = dev.relationManage.getRelationsOfGraphicAndOtherType(
dev, dev,
@ -362,10 +363,10 @@ export class Train extends JlGraphic {
}); });
if (findT) { if (findT) {
const other = findT.getOtherGraphic(dev) as Turnout; const other = findT.getOtherGraphic(dev) as Turnout;
p = other.datas.kilometerSystem[0].kilometer; pKm = other.datas.kilometerSystem[0];
} }
} }
allLength = Math.abs(p - o); allLength = getKmDistance(pKm, oKm);
const portP = points[points.length - 1]; const portP = points[points.length - 1];
const j = 10; const j = 10;
if (Math.abs(portP.x) < j) { if (Math.abs(portP.x) < j) {
@ -387,8 +388,8 @@ export class Train extends JlGraphic {
dev, dev,
AxleCounting.Type AxleCounting.Type
); );
let A = 0; let AKm;
let B = 0; let BKm;
let hasA = false; let hasA = false;
let hasB = false; let hasB = false;
// 获取区段A、B端的公里标计算区段总度 // 获取区段A、B端的公里标计算区段总度
@ -396,16 +397,16 @@ export class Train extends JlGraphic {
const rp = item.getRelationParam(dev as Section); const rp = item.getRelationParam(dev as Section);
const other = item.getOtherGraphic(dev as Section) as AxleCounting; const other = item.getOtherGraphic(dev as Section) as AxleCounting;
if (rp.getParam() == 'A') { if (rp.getParam() == 'A') {
A = other.datas.kilometerSystem.kilometer; AKm = other.datas.kilometerSystem;
hasA = true; hasA = true;
} }
if (rp.getParam() == 'B') { if (rp.getParam() == 'B') {
B = other.datas.kilometerSystem.kilometer; BKm = other.datas.kilometerSystem;
hasB = true; hasB = true;
} }
}); });
if (hasA && hasB) { if (hasA && hasB) {
allLength = Math.abs(B - A); allLength = getKmDistance(BKm, AKm);
const portS = points[0]; const portS = points[0];
const portE = points[points.length - 1]; const portE = points[points.length - 1];
this.isSyntropy = portE.x > portS.x; this.isSyntropy = portE.x > portS.x;