计轴区段一键生成逻辑修改--按搜索路径
This commit is contained in:
parent
0be7df6558
commit
d23b57ec9a
@ -1,4 +1,4 @@
|
||||
import { FederatedPointerEvent, IHitArea, IPointData, Point } from 'pixi.js';
|
||||
import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js';
|
||||
import {
|
||||
GraphicDrawAssistant,
|
||||
GraphicIdGenerator,
|
||||
@ -16,32 +16,19 @@ import {
|
||||
ITurnoutPosRefData,
|
||||
} from './AxleCountingSection';
|
||||
import { AxleCounting } from '../axleCounting/AxleCounting';
|
||||
import { Turnout, TurnoutPort } from '../turnout/Turnout';
|
||||
import { Section } from '../section/Section';
|
||||
import { Turnout } from '../turnout/Turnout';
|
||||
import { createRelatedRefProto } from '../CommonGraphics';
|
||||
|
||||
function hasCommonElements(arr1: string[], arr2: string[]) {
|
||||
for (let i = 0; i < arr1.length; i++) {
|
||||
if (arr2.includes(arr1[i])) {
|
||||
return arr1[i];
|
||||
}
|
||||
function removePortBC<T>(a: T, b: T): boolean {
|
||||
if ((a == 'B' && b == 'C') || (a == 'C' && b == 'B')) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function hasSamePosition(point1: IPointData, point2: IPointData): boolean {
|
||||
if (
|
||||
Math.abs(point1.x - point2.x) < 20 &&
|
||||
Math.abs(point1.y - point2.y) < 20
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export interface IAxleCountingSectionDrawOptions {
|
||||
newData: () => IAxleCountingSectionData;
|
||||
}
|
||||
|
||||
export class AxleCountingSectionDraw extends GraphicDrawAssistant<
|
||||
AxleCountingSectionTemplate,
|
||||
IAxleCountingSectionData
|
||||
@ -79,13 +66,14 @@ export class AxleCountingSectionDraw extends GraphicDrawAssistant<
|
||||
graphics: AxleCounting[],
|
||||
commonElement: JlGraphic[],
|
||||
map: Map<string, number>,
|
||||
turoutPos?: number
|
||||
turoutPos?: number[]
|
||||
) {
|
||||
if (
|
||||
map.has(`${graphics[0].id}+${graphics[1].id}`) ||
|
||||
map.has(`${graphics[1].id}+${graphics[0].id}`)
|
||||
)
|
||||
return;
|
||||
map.set(`${graphics[0].id}+${graphics[1].id}`, 1);
|
||||
const axleCountingSection = new AxleCountingSection();
|
||||
axleCountingSection.loadData(this.graphicTemplate.datas);
|
||||
axleCountingSection.datas.points = [
|
||||
@ -98,37 +86,10 @@ export class AxleCountingSectionDraw extends GraphicDrawAssistant<
|
||||
const turnoutPosData: ITurnoutPosRefData[] = [];
|
||||
if (commonElement[0].type == 'Turnout') {
|
||||
commonElement.forEach((Turnout, i) => {
|
||||
if (commonElement.length == 2) {
|
||||
if (turoutPos == -1) {
|
||||
if (i == 1) {
|
||||
turnoutPosData.push({
|
||||
id: Turnout.id,
|
||||
position: 1,
|
||||
});
|
||||
} else {
|
||||
turnoutPosData.push({
|
||||
id: Turnout.id,
|
||||
position: 0,
|
||||
});
|
||||
}
|
||||
} else
|
||||
turnoutPosData.push({
|
||||
id: Turnout.id,
|
||||
position: 0,
|
||||
});
|
||||
} else {
|
||||
if (turoutPos == 0) {
|
||||
turnoutPosData.push({
|
||||
id: Turnout.id,
|
||||
position: 0,
|
||||
});
|
||||
} else {
|
||||
turnoutPosData.push({
|
||||
id: Turnout.id,
|
||||
position: 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
turnoutPosData.push({
|
||||
id: Turnout.id,
|
||||
position: (turoutPos as number[])[i],
|
||||
});
|
||||
});
|
||||
}
|
||||
axleCountingSection.datas.paRef = paRef;
|
||||
@ -137,7 +98,6 @@ export class AxleCountingSectionDraw extends GraphicDrawAssistant<
|
||||
this.storeGraphic(axleCountingSection);
|
||||
axleCountingSection.loadRelations();
|
||||
}
|
||||
|
||||
oneGenerates() {
|
||||
const map = new Map();
|
||||
const axleCountingSections =
|
||||
@ -153,188 +113,136 @@ export class AxleCountingSectionDraw extends GraphicDrawAssistant<
|
||||
const axleCountings = this.app.queryStore.queryByType<AxleCounting>(
|
||||
AxleCounting.Type
|
||||
);
|
||||
const hasfourTurnout: AxleCounting[][] = [];
|
||||
axleCountings.forEach((axleCounting) => {
|
||||
const refDeviceTarget = axleCounting.datas.axleCountingRef.map(
|
||||
(ref) => ref.id
|
||||
);
|
||||
for (let i = 0; i < axleCountings.length - 1; i++) {
|
||||
if (axleCountings[i].id == axleCounting.id) return;
|
||||
const refDevice = axleCountings[i].datas.axleCountingRef.map(
|
||||
(ref) => ref.id
|
||||
);
|
||||
const commonElementId = hasCommonElements(refDeviceTarget, refDevice);
|
||||
if (commonElementId) {
|
||||
const commonElement = this.app.queryStore.queryById(commonElementId);
|
||||
let draw = true;
|
||||
let turoutPos = 0;
|
||||
//道岔BC端处的计轴不构成计轴区段
|
||||
if (commonElement.type == 'Turnout') {
|
||||
let targetPort, port;
|
||||
axleCounting.datas.axleCountingRef.forEach((ref) => {
|
||||
if (ref.id == commonElementId) {
|
||||
targetPort = ref.devicePort;
|
||||
}
|
||||
});
|
||||
axleCountings[i].datas.axleCountingRef.forEach((ref) => {
|
||||
if (ref.id == commonElementId) {
|
||||
port = ref.devicePort;
|
||||
}
|
||||
});
|
||||
if (
|
||||
(targetPort == 1 && port == 2) ||
|
||||
(targetPort == 2 && port == 1)
|
||||
) {
|
||||
draw = false;
|
||||
}
|
||||
if (targetPort == 2 || port == 2) {
|
||||
turoutPos = 1;
|
||||
}
|
||||
}
|
||||
if (draw) {
|
||||
this.draw(
|
||||
[axleCounting, axleCountings[i]],
|
||||
[commonElement],
|
||||
map,
|
||||
turoutPos
|
||||
);
|
||||
}
|
||||
}
|
||||
if (hasSamePosition(axleCounting, axleCountings[i])) {
|
||||
hasfourTurnout.push([axleCounting, axleCountings[i]]);
|
||||
}
|
||||
}
|
||||
});
|
||||
//补4个道岔处的BB连接处的计轴区段
|
||||
const fourAxleCounting: {
|
||||
axleCounting: AxleCounting;
|
||||
refTurout: Turnout;
|
||||
}[] = [];
|
||||
hasfourTurnout.forEach((axleCountings) => {
|
||||
axleCountings.forEach((axleCounting) => {
|
||||
//计轴关联的道岔
|
||||
const axleCountingRelations =
|
||||
axleCounting.relationManage.getRelationsOfGraphicAndOtherType(
|
||||
axleCounting,
|
||||
Turnout.Type
|
||||
);
|
||||
axleCountingRelations.forEach((relation) => {
|
||||
const refTurnout = relation.getOtherGraphic<Turnout>(axleCounting);
|
||||
//道岔关联的计轴
|
||||
const turnoutRelations =
|
||||
refTurnout.relationManage.getRelationsOfGraphicAndOtherType(
|
||||
refTurnout,
|
||||
AxleCounting.Type
|
||||
);
|
||||
turnoutRelations.forEach((relation) => {
|
||||
const refAxleCounting =
|
||||
relation.getOtherGraphic<AxleCounting>(refTurnout);
|
||||
if (
|
||||
refAxleCounting.id !== axleCountings[0].id &&
|
||||
refAxleCounting.id !== axleCountings[1].id
|
||||
) {
|
||||
fourAxleCounting.push({
|
||||
axleCounting: refAxleCounting,
|
||||
refTurout: refTurnout,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
for (let x = 0; x < fourAxleCounting.length; x += 4) {
|
||||
const AxleCountings = fourAxleCounting.slice(x, x + 4);
|
||||
for (let y = 0; y < 4; y++) {
|
||||
if (
|
||||
fourAxleCounting[x].axleCounting.id ==
|
||||
AxleCountings[y].axleCounting.id
|
||||
)
|
||||
continue;
|
||||
if (
|
||||
fourAxleCounting[x].axleCounting.y == AxleCountings[y].axleCounting.y
|
||||
) {
|
||||
this.draw(
|
||||
[fourAxleCounting[x].axleCounting, AxleCountings[y].axleCounting],
|
||||
[fourAxleCounting[x].refTurout, AxleCountings[y].refTurout],
|
||||
map
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let y = 0; y < 4; y++) {
|
||||
if (
|
||||
fourAxleCounting[x + 1].axleCounting.id ==
|
||||
AxleCountings[y].axleCounting.id
|
||||
)
|
||||
continue;
|
||||
if (
|
||||
fourAxleCounting[x + 1].axleCounting.y ==
|
||||
AxleCountings[y].axleCounting.y
|
||||
) {
|
||||
this.draw(
|
||||
[
|
||||
fourAxleCounting[x + 1].axleCounting,
|
||||
AxleCountings[y].axleCounting,
|
||||
],
|
||||
[fourAxleCounting[x + 1].refTurout, AxleCountings[y].refTurout],
|
||||
map
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//补删除计轴后的区段
|
||||
const axleCountingAll = this.app.queryStore.queryByType<AxleCounting>(
|
||||
AxleCounting.Type
|
||||
);
|
||||
const deleteRefTurout: string[] = [];
|
||||
const redawAxleCounting: AxleCounting[] = [];
|
||||
axleCountingAll.forEach((axleCounting) => {
|
||||
const axleCountingRelations =
|
||||
//计轴关联的区段
|
||||
const axleCountingRefSection =
|
||||
axleCounting.relationManage.getRelationsOfGraphicAndOtherType(
|
||||
axleCounting,
|
||||
AxleCountingSection.Type
|
||||
Section.Type
|
||||
);
|
||||
if (
|
||||
axleCounting.datas.axleCountingRef.length == 2 &&
|
||||
axleCountingRelations.length < 2
|
||||
) {
|
||||
axleCounting.datas.axleCountingRef.forEach((ref) => {
|
||||
if (ref.deviceType == 1) {
|
||||
redawAxleCounting.push(axleCounting);
|
||||
}
|
||||
if (ref.deviceType == 1 && !deleteRefTurout.includes(ref.id)) {
|
||||
deleteRefTurout.push(ref.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
deleteRefTurout.forEach((id) => {
|
||||
const turout = this.app.queryStore.queryById(id);
|
||||
const turoutRelations =
|
||||
turout.relationManage.getRelationsOfGraphicAndOtherType(
|
||||
turout,
|
||||
axleCountingRefSection.forEach((ref) => {
|
||||
const refDevice = ref.getOtherGraphic<Section>(axleCounting);
|
||||
const refDevicePort = ref.getOtherRelationParam(axleCounting).param;
|
||||
const refDeviceOtherPort = refDevicePort == 'A' ? 'B' : 'A';
|
||||
const otherPortRefAxle = refDevice.relationManage
|
||||
.getRelationsOfGraphicAndOtherType(refDevice, AxleCounting.Type)
|
||||
.find(
|
||||
(relation) =>
|
||||
relation.getRelationParam(refDevice).param == refDeviceOtherPort
|
||||
)
|
||||
?.getOtherGraphic(refDevice);
|
||||
if (otherPortRefAxle !== undefined) {
|
||||
this.draw(
|
||||
[axleCounting, otherPortRefAxle as AxleCounting],
|
||||
[refDevice],
|
||||
map
|
||||
);
|
||||
}
|
||||
});
|
||||
//计轴关联的道岔
|
||||
const axleCountingRefTurnout =
|
||||
axleCounting.relationManage.getRelationsOfGraphicAndOtherType(
|
||||
axleCounting,
|
||||
Turnout.Type
|
||||
);
|
||||
const refTurout = turoutRelations[0].getOtherGraphic(turout);
|
||||
const refs = refTurout.relationManage
|
||||
.getRelationsOfGraphicAndOtherType(refTurout, AxleCounting.Type)
|
||||
.find(
|
||||
(relation) =>
|
||||
relation.getRelationParam(refTurout).param !== TurnoutPort.C
|
||||
);
|
||||
const refAxleCountin = refs?.getOtherGraphic(refTurout) as AxleCounting;
|
||||
this.draw(
|
||||
[refAxleCountin, redawAxleCounting[0]],
|
||||
[refTurout, turout],
|
||||
map
|
||||
);
|
||||
this.draw(
|
||||
[refAxleCountin, redawAxleCounting[1]],
|
||||
[refTurout, turout],
|
||||
map,
|
||||
-1
|
||||
);
|
||||
axleCountingRefTurnout.forEach((ref) => {
|
||||
const refDevice = ref.getOtherGraphic<Turnout>(axleCounting);
|
||||
const refDevicePort = ref.getOtherRelationParam(axleCounting).param;
|
||||
let refDeviceOtherPort: string[] = [];
|
||||
switch (refDevicePort) {
|
||||
case 'A':
|
||||
refDeviceOtherPort = ['B', 'C'];
|
||||
break;
|
||||
case 'B':
|
||||
refDeviceOtherPort = ['A', 'C'];
|
||||
break;
|
||||
case 'C':
|
||||
refDeviceOtherPort = ['A', 'B'];
|
||||
break;
|
||||
}
|
||||
//关联道岔的其它端点--需要找路径
|
||||
refDeviceOtherPort.forEach((port) => {
|
||||
const otherPortRefAxle = refDevice.relationManage
|
||||
.getRelationsOfGraphicAndOtherType(refDevice, AxleCounting.Type)
|
||||
.find(
|
||||
(relation) => relation.getRelationParam(refDevice).param == port
|
||||
)
|
||||
?.getOtherGraphic(refDevice);
|
||||
if (
|
||||
otherPortRefAxle !== undefined &&
|
||||
removePortBC(refDevicePort, port)
|
||||
) {
|
||||
let turoutPos = 0;
|
||||
if (refDevicePort == 'C' || port == 'C') {
|
||||
turoutPos = 1;
|
||||
}
|
||||
this.draw(
|
||||
[axleCounting, otherPortRefAxle as AxleCounting],
|
||||
[refDevice],
|
||||
map,
|
||||
[turoutPos]
|
||||
);
|
||||
} else if (otherPortRefAxle == undefined) {
|
||||
const refDeviceRefTurnoutRelation = refDevice.relationManage
|
||||
.getRelationsOfGraphicAndOtherType(refDevice, Turnout.Type)
|
||||
.find(
|
||||
(relation) => relation.getRelationParam(refDevice).param == port
|
||||
);
|
||||
const refDeviceRefTurnout =
|
||||
refDeviceRefTurnoutRelation?.getOtherGraphic(refDevice);
|
||||
const refDeviceRefTurnoutPort =
|
||||
refDeviceRefTurnoutRelation?.getRelationParam(
|
||||
refDeviceRefTurnout as JlGraphic
|
||||
).param;
|
||||
const otherPortRefAxleInfo: {
|
||||
axle: AxleCounting;
|
||||
turoutPort: string;
|
||||
}[] = [];
|
||||
const otherPortRefAxleRelation = refDeviceRefTurnout?.relationManage
|
||||
.getRelationsOfGraphicAndOtherType(
|
||||
refDeviceRefTurnout,
|
||||
AxleCounting.Type
|
||||
)
|
||||
.filter((relation) => {
|
||||
return (
|
||||
relation.getRelationParam(refDeviceRefTurnout).param !==
|
||||
refDeviceRefTurnoutPort
|
||||
);
|
||||
})
|
||||
.forEach((ref) => {
|
||||
otherPortRefAxleInfo.push({
|
||||
axle: ref.getOtherGraphic(refDeviceRefTurnout),
|
||||
turoutPort: ref.getRelationParam(refDeviceRefTurnout).param,
|
||||
});
|
||||
});
|
||||
const bbConnect =
|
||||
port == 'B' && refDeviceRefTurnoutPort == 'B' ? true : false;
|
||||
otherPortRefAxleInfo?.forEach((info) => {
|
||||
if (
|
||||
(refDevicePort !== 'C' && info.turoutPort !== 'C') ||
|
||||
(refDevicePort == 'A' && info.turoutPort == 'C' && !bbConnect)
|
||||
) {
|
||||
let turoutPos: number[] = [];
|
||||
if (
|
||||
refDevicePort == 'A' &&
|
||||
info.turoutPort == 'C' &&
|
||||
!bbConnect
|
||||
) {
|
||||
turoutPos = [0, 1];
|
||||
} else {
|
||||
turoutPos = [0, 0];
|
||||
}
|
||||
this.draw(
|
||||
[axleCounting, info.axle as AxleCounting],
|
||||
[refDevice, refDeviceRefTurnout as JlGraphic],
|
||||
map,
|
||||
turoutPos
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user