构建关联关系调整

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

View File

@ -10,7 +10,6 @@ import {
angleOfIncludedAngle, angleOfIncludedAngle,
distance2, distance2,
getParallelOfPolyline, getParallelOfPolyline,
epsilon,
Vector2, Vector2,
} from 'jl-graphic'; } from 'jl-graphic';
import { Section, SectionPort, SectionType } from '../section/Section'; import { Section, SectionPort, SectionType } from '../section/Section';
@ -22,6 +21,7 @@ import {
import { KilometerSystem } from '../signal/Signal'; import { KilometerSystem } from '../signal/Signal';
import { Station } from '../station/Station'; import { Station } from '../station/Station';
const turnoutEpsilon = 0.1;
export interface ITurnoutData extends GraphicData { export interface ITurnoutData extends GraphicData {
get code(): string; get code(): string;
set code(code: string); set code(code: string);
@ -541,22 +541,20 @@ export class Turnout extends JlGraphic {
buildRelation(): void { buildRelation(): void {
this.relationManage.deleteRelationOfGraphic(this); this.relationManage.deleteRelationOfGraphic(this);
/** 道岔和区段 */ /** 道岔和区段 */
this.queryStore.queryByType<Section>(Section.Type) this.queryStore.queryByType<Section>(Section.Type).forEach((section) => {
.forEach((section) => {
if (section.datas.sectionType === SectionType.TurnoutPhysical) { if (section.datas.sectionType === SectionType.TurnoutPhysical) {
if (section.datas.children.includes(this.datas.id)) { if (section.datas.children.includes(this.datas.id)) {
this.relationManage.addRelation(this, section) this.relationManage.addRelation(this, section);
} }
return return;
} }
this.getPortPoints().forEach((port, i) => { this.getPortPoints().forEach((port, i) => {
if ( if (
distance2( distance2(
section.localToCanvasPoint(section.getStartPoint()), section.localToCanvasPoint(section.getStartPoint()),
this.localToCanvasPoint(port[port.length - 1]) this.localToCanvasPoint(port[port.length - 1])
) <= epsilon ) <= turnoutEpsilon
) { ) {
this.relationManage.addRelation( this.relationManage.addRelation(
new GraphicRelationParam( new GraphicRelationParam(
@ -570,7 +568,7 @@ export class Turnout extends JlGraphic {
distance2( distance2(
section.localToCanvasPoint(section.getEndPoint()), section.localToCanvasPoint(section.getEndPoint()),
this.localToCanvasPoint(port[port.length - 1]) this.localToCanvasPoint(port[port.length - 1])
) <= epsilon ) <= turnoutEpsilon
) { ) {
this.relationManage.addRelation( this.relationManage.addRelation(
new GraphicRelationParam( new GraphicRelationParam(
@ -594,7 +592,7 @@ export class Turnout extends JlGraphic {
distance2( distance2(
this.localToCanvasPoint(thisPort[thisPort.length - 1]), this.localToCanvasPoint(thisPort[thisPort.length - 1]),
turnout.localToCanvasPoint(otherPort[otherPort.length - 1]) turnout.localToCanvasPoint(otherPort[otherPort.length - 1])
) <= epsilon ) <= turnoutEpsilon
) { ) {
const angle = angleOfIncludedAngle( const angle = angleOfIncludedAngle(
this.localToCanvasPoint(thisPort[thisPort.length - 1]) /* 交点 */, this.localToCanvasPoint(thisPort[thisPort.length - 1]) /* 交点 */,
@ -668,9 +666,13 @@ export class Turnout extends JlGraphic {
const pcRelation = this.relationManage const pcRelation = this.relationManage
.getRelationsOfGraphic(this) .getRelationsOfGraphic(this)
.find( .find(
(relation) => relation.getRelationParam(this).param === TurnoutPort.C (relation) =>
&& (!(relation.getOtherGraphic(this) instanceof Section relation.getRelationParam(this).param === TurnoutPort.C &&
&& relation.getOtherGraphic<Section>(this).datas.sectionType !== SectionType.TurnoutPhysical)) !(
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) {