道岔及区段关系逻辑修正

This commit is contained in:
Yuan 2023-12-27 16:57:37 +08:00
parent 91d290abf1
commit 17fdddb17e
4 changed files with 63 additions and 39 deletions

View File

@ -53,11 +53,11 @@ export class SectionData extends GraphicDataBase implements ISectionData {
set sectionType(type: graphicData.Section.SectionType) {
this.data.sectionType = type;
}
get axleCountings(): string[] {
return this.data.axleCountings;
get axleCountings(): number[] {
return this.data.axleCountings.map((a) => Number(a));
}
set axleCountings(axleCountings: string[]) {
this.data.axleCountings = axleCountings;
set axleCountings(axleCountings: number[]) {
this.data.axleCountings = axleCountings.map((a) => a.toString());
}
get children(): number[] {
return this.data.children;

View File

@ -40,8 +40,8 @@ export interface ISectionData extends GraphicData {
set pbRef(ref: IRelatedRefData | undefined);
get sectionType(): SectionType;
set sectionType(type: SectionType);
get axleCountings(): string[];
set axleCountings(axleCountings: string[]);
get axleCountings(): number[];
set axleCountings(axleCountings: number[]);
get children(): number[];
set children(children: number[]);
get destinationCode(): string;
@ -233,9 +233,11 @@ export class Section extends JlGraphic implements ILineGraphic {
buildRelation() {
this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type);
if (this.datas.sectionType === SectionType.TurnoutPhysical) return;
/** 区段与区段 */
this.queryStore.queryByType<Section>(Section.Type).forEach((section) => {
if (section.id === this.id) return;
if (section.datas.sectionType === SectionType.TurnoutPhysical) return;
let param: SectionPort[] = [];
if (
@ -346,7 +348,6 @@ export class Section extends JlGraphic implements ILineGraphic {
});
}
if (
this.datas.children &&
this.datas.children &&
this.datas.sectionType === SectionType.TurnoutPhysical
) {

View File

@ -123,7 +123,7 @@ export class SectionDraw extends GraphicDrawAssistant<
}
generateTurnoutSection() {
const turnoutIds: string[] = []; /* 已遍历的道岔id列表 */
const turnoutIds: number[] = []; /* 已遍历的道岔id列表 */
const dfs = (turnout: Turnout) => {
const axleCountings: AxleCounting[] = [];
const turnouts: Turnout[] = [];
@ -173,6 +173,18 @@ export class SectionDraw extends GraphicDrawAssistant<
turnoutPhysicalSectionData.axleCountings = result.axleCountings.map(
(ac) => ac.datas.id
);
const exsit = this.app.queryStore
.queryByType<Section>(Section.Type)
.filter((g) => g.datas.sectionType === SectionType.TurnoutPhysical)
.some(
(ts) =>
ts.datas.axleCountings.every((id) =>
turnoutPhysicalSectionData.axleCountings.includes(id)
) &&
ts.datas.axleCountings.length ===
turnoutPhysicalSectionData.axleCountings.length
);
if (exsit) return;
turnoutPhysicalSectionData.children = result.turnouts.map(
(t) => t.datas.id
);

View File

@ -13,7 +13,7 @@ import {
epsilon,
Vector2,
} from 'jl-graphic';
import { Section, SectionPort } from '../section/Section';
import { Section, SectionPort, SectionType } from '../section/Section';
import {
IRelatedRefData,
createRelatedRefProto,
@ -541,8 +541,16 @@ export class Turnout extends JlGraphic {
buildRelation(): void {
this.relationManage.deleteRelationOfGraphic(this);
/** 道岔和区段 */
this.queryStore.queryByType<Section>(Section.Type).forEach((section) => {
this.queryStore.queryByType<Section>(Section.Type)
.forEach((section) => {
if (section.datas.sectionType === SectionType.TurnoutPhysical) {
if (section.datas.children.includes(this.datas.id)) {
this.relationManage.addRelation(this, section)
}
return
}
this.getPortPoints().forEach((port, i) => {
if (
distance2(
@ -656,10 +664,13 @@ export class Turnout extends JlGraphic {
} else {
this.datas.pbRef = undefined;
}
const pcRelation = this.relationManage
.getRelationsOfGraphic(this)
.find(
(relation) => relation.getRelationParam(this).param === TurnoutPort.C
&& (!(relation.getOtherGraphic(this) instanceof Section
&& relation.getOtherGraphic<Section>(this).datas.sectionType !== SectionType.TurnoutPhysical))
);
const pcDevice = pcRelation?.getOtherGraphic<Section | Turnout>(this);
if (pcDevice) {