构建关联关系调整

This commit is contained in:
joylink_fanyuhong 2024-09-23 13:55:11 +08:00
parent aaf8b932a5
commit 7b06dee5be
2 changed files with 51 additions and 48 deletions

View File

@ -8,7 +8,6 @@ import {
distance2,
splitLineEvenly,
ILineGraphic,
epsilon,
Vector2,
} from 'jl-graphic';
import {
@ -29,6 +28,8 @@ export enum SectionPort {
B = 'B',
}
const sectionEpsilon = 0.1;
export interface ISectionData extends GraphicData {
get code(): string; // 编号
set code(v: string);
@ -244,7 +245,7 @@ export class Section extends JlGraphic implements ILineGraphic {
distance2(
this.localToCanvasPoint(this.getStartPoint()),
section.localToCanvasPoint(section.getStartPoint())
) <= epsilon
) <= sectionEpsilon
) {
param = [SectionPort.A, SectionPort.A];
}
@ -252,7 +253,7 @@ export class Section extends JlGraphic implements ILineGraphic {
distance2(
this.localToCanvasPoint(this.getEndPoint()),
section.localToCanvasPoint(section.getStartPoint())
) <= epsilon
) <= sectionEpsilon
) {
param = [SectionPort.B, SectionPort.A];
}
@ -260,7 +261,7 @@ export class Section extends JlGraphic implements ILineGraphic {
distance2(
this.localToCanvasPoint(this.getStartPoint()),
section.localToCanvasPoint(section.getEndPoint())
) <= epsilon
) <= sectionEpsilon
) {
param = [SectionPort.A, SectionPort.B];
}
@ -268,7 +269,7 @@ export class Section extends JlGraphic implements ILineGraphic {
distance2(
this.localToCanvasPoint(this.getEndPoint()),
section.localToCanvasPoint(section.getEndPoint())
) <= epsilon
) <= sectionEpsilon
) {
param = [SectionPort.B, SectionPort.B];
}

View File

@ -10,7 +10,6 @@ import {
angleOfIncludedAngle,
distance2,
getParallelOfPolyline,
epsilon,
Vector2,
} from 'jl-graphic';
import { Section, SectionPort, SectionType } from '../section/Section';
@ -22,6 +21,7 @@ import {
import { KilometerSystem } from '../signal/Signal';
import { Station } from '../station/Station';
const turnoutEpsilon = 0.1;
export interface ITurnoutData extends GraphicData {
get code(): string;
set code(code: string);
@ -541,47 +541,45 @@ export class Turnout extends JlGraphic {
buildRelation(): void {
this.relationManage.deleteRelationOfGraphic(this);
/** 道岔和区段 */
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.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(
section.localToCanvasPoint(section.getStartPoint()),
this.localToCanvasPoint(port[port.length - 1])
) <= turnoutEpsilon
) {
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])
) <= turnoutEpsilon
) {
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) => {
@ -594,7 +592,7 @@ export class Turnout extends JlGraphic {
distance2(
this.localToCanvasPoint(thisPort[thisPort.length - 1]),
turnout.localToCanvasPoint(otherPort[otherPort.length - 1])
) <= epsilon
) <= turnoutEpsilon
) {
const angle = angleOfIncludedAngle(
this.localToCanvasPoint(thisPort[thisPort.length - 1]) /* 交点 */,
@ -668,9 +666,13 @@ export class Turnout extends JlGraphic {
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))
(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) {