道岔及区段关系逻辑修正

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) { set sectionType(type: graphicData.Section.SectionType) {
this.data.sectionType = type; this.data.sectionType = type;
} }
get axleCountings(): string[] { get axleCountings(): number[] {
return this.data.axleCountings; return this.data.axleCountings.map((a) => Number(a));
} }
set axleCountings(axleCountings: string[]) { set axleCountings(axleCountings: number[]) {
this.data.axleCountings = axleCountings; this.data.axleCountings = axleCountings.map((a) => a.toString());
} }
get children(): number[] { get children(): number[] {
return this.data.children; return this.data.children;

View File

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

View File

@ -123,7 +123,7 @@ export class SectionDraw extends GraphicDrawAssistant<
} }
generateTurnoutSection() { generateTurnoutSection() {
const turnoutIds: string[] = []; /* 已遍历的道岔id列表 */ const turnoutIds: number[] = []; /* 已遍历的道岔id列表 */
const dfs = (turnout: Turnout) => { const dfs = (turnout: Turnout) => {
const axleCountings: AxleCounting[] = []; const axleCountings: AxleCounting[] = [];
const turnouts: Turnout[] = []; const turnouts: Turnout[] = [];
@ -173,6 +173,18 @@ export class SectionDraw extends GraphicDrawAssistant<
turnoutPhysicalSectionData.axleCountings = result.axleCountings.map( turnoutPhysicalSectionData.axleCountings = result.axleCountings.map(
(ac) => ac.datas.id (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( turnoutPhysicalSectionData.children = result.turnouts.map(
(t) => t.datas.id (t) => t.datas.id
); );

View File

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