From 17fdddb17ea08150c242841687945b3091c462c7 Mon Sep 17 00:00:00 2001 From: Yuan Date: Wed, 27 Dec 2023 16:57:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=B2=94=E5=8F=8A=E5=8C=BA=E6=AE=B5?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E9=80=BB=E8=BE=91=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/graphics/SectionInteraction.ts | 8 +-- src/graphics/section/Section.ts | 7 +- src/graphics/section/SectionDrawAssistant.ts | 14 +++- src/graphics/turnout/Turnout.ts | 73 +++++++++++--------- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/drawApp/graphics/SectionInteraction.ts b/src/drawApp/graphics/SectionInteraction.ts index 2906369..ee63ffb 100644 --- a/src/drawApp/graphics/SectionInteraction.ts +++ b/src/drawApp/graphics/SectionInteraction.ts @@ -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; diff --git a/src/graphics/section/Section.ts b/src/graphics/section/Section.ts index 499121d..3ab5e19 100644 --- a/src/graphics/section/Section.ts +++ b/src/graphics/section/Section.ts @@ -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.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 ) { diff --git a/src/graphics/section/SectionDrawAssistant.ts b/src/graphics/section/SectionDrawAssistant.ts index f6291f7..9b7a126 100644 --- a/src/graphics/section/SectionDrawAssistant.ts +++ b/src/graphics/section/SectionDrawAssistant.ts @@ -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.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 ); diff --git a/src/graphics/turnout/Turnout.ts b/src/graphics/turnout/Turnout.ts index c938cb0..3075798 100644 --- a/src/graphics/turnout/Turnout.ts +++ b/src/graphics/turnout/Turnout.ts @@ -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,39 +541,47 @@ export class Turnout extends JlGraphic { buildRelation(): void { this.relationManage.deleteRelationOfGraphic(this); + /** 道岔和区段 */ - this.queryStore.queryByType
(Section.Type).forEach((section) => { - this.getPortPoints().forEach((port, i) => { - if ( - distance2( - section.localToCanvasPoint(section.getStartPoint()), - this.localToCanvasPoint(port[port.length - 1]) - ) <= epsilon - ) { - this.relationManage.addRelation( - new GraphicRelationParam( - this, - [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] - ), - new GraphicRelationParam(section, SectionPort.A) - ); - } - if ( - distance2( - section.localToCanvasPoint(section.getEndPoint()), - this.localToCanvasPoint(port[port.length - 1]) - ) <= epsilon - ) { - this.relationManage.addRelation( - new GraphicRelationParam( - this, - [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] - ), - new GraphicRelationParam(section, SectionPort.B) - ); + this.queryStore.queryByType
(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( + section.localToCanvasPoint(section.getStartPoint()), + this.localToCanvasPoint(port[port.length - 1]) + ) <= epsilon + ) { + this.relationManage.addRelation( + new GraphicRelationParam( + this, + [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] + ), + new GraphicRelationParam(section, SectionPort.A) + ); + } + if ( + distance2( + section.localToCanvasPoint(section.getEndPoint()), + this.localToCanvasPoint(port[port.length - 1]) + ) <= epsilon + ) { + this.relationManage.addRelation( + new GraphicRelationParam( + this, + [TurnoutPort.A, TurnoutPort.B, TurnoutPort.C][i] + ), + new GraphicRelationParam(section, SectionPort.B) + ); + } + }); }); - }); /** 道岔和道岔 */ this.getPortPoints().forEach((thisPort, i) => { @@ -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
(this).datas.sectionType !== SectionType.TurnoutPhysical)) ); const pcDevice = pcRelation?.getOtherGraphic
(this); if (pcDevice) {