From fa5c16a3373d7c6d7f2f8a90cfb3bb3325a7e1d6 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 10 Jan 2024 17:25:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=AB=99=E5=8F=B0=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/packages/Platform/GPPlatform.d.ts | 3 + components/packages/Platform/GPPlatform.js | 53 ++++++++++++++ components/packages/Platform/THPlatform.d.ts | 3 + components/packages/Platform/THPlatform.js | 53 ++++++++++++++ .../packages/Section/bjrtss/Section.d.ts | 2 +- components/packages/Section/bjrtss/Section.js | 4 +- .../packages/Section/common/Section.d.ts | 8 +-- components/packages/Section/common/Section.js | 22 +++--- src/packages/Platform/GPPlatform.ts | 69 ++++++++++++++++++- src/packages/Platform/THPlatform.ts | 69 ++++++++++++++++++- src/packages/Section/bjrtss/Section.ts | 2 +- src/packages/Section/common/Section.ts | 30 ++++---- 12 files changed, 282 insertions(+), 36 deletions(-) diff --git a/components/packages/Platform/GPPlatform.d.ts b/components/packages/Platform/GPPlatform.d.ts index e079e07..9f28cf3 100644 --- a/components/packages/Platform/GPPlatform.d.ts +++ b/components/packages/Platform/GPPlatform.d.ts @@ -7,4 +7,7 @@ export declare class GPPlatform extends JlPlatform { constructor(); get states(): IGPPlatformState; doRepaint(): void; + buildRelation(): void; + saveRelations(): void; + loadRelations(): void; } diff --git a/components/packages/Platform/GPPlatform.js b/components/packages/Platform/GPPlatform.js index fb789db..b0e6442 100644 --- a/components/packages/Platform/GPPlatform.js +++ b/components/packages/Platform/GPPlatform.js @@ -1,5 +1,8 @@ +import { distance2, getRectangleCenter } from 'jl-graphic'; import { GPConsts } from './PlatformConfig.js'; import { JlPlatform } from './JlPlatform.js'; +import { GPStation } from '../Station/GPStation.js'; +import { JlSection } from '../Section/common/Section.js'; class GPPlatform extends JlPlatform { constructor() { @@ -12,6 +15,56 @@ class GPPlatform extends JlPlatform { this.rectGraphic.stateFillColor = GPConsts.noTrainStop; super.draw(); } + buildRelation() { + const stationas = this.queryStore.queryByType(GPStation.Type); + for (let i = 0; i < stationas.length; i++) { + const sP = stationas[i].localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + this.relationManage.addRelation(this, stationas[i]); + break; + } + } + const sections = this.queryStore.queryByType(JlSection.Type); + const minDistanceRefSections = []; + sections.forEach((section) => { + const sP = section.localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + minDistanceRefSections.push(section); + } + }); + if (minDistanceRefSections) { + const refSection = minDistanceRefSections.reduce((prev, cur) => { + return distance2(prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), this.position) > + distance2(cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), this.position) + ? cur + : prev; + }); + this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type); + this.relationManage.addRelation(this, refSection); + } + } + saveRelations() { + const refStation = this.relationManage + .getRelationsOfGraphicAndOtherType(this, GPStation.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refStation.length) { + this.datas.refStation = refStation[0]; + } + const refSection = this.relationManage + .getRelationsOfGraphicAndOtherType(this, JlSection.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refSection.length) { + this.datas.refSection = refSection[0]; + } + } + loadRelations() { + if (this.datas.refStation) { + this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refStation)); + } + if (this.datas.refSection) { + this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refSection)); + } + } } export { GPPlatform }; diff --git a/components/packages/Platform/THPlatform.d.ts b/components/packages/Platform/THPlatform.d.ts index b03ef32..af8a24b 100644 --- a/components/packages/Platform/THPlatform.d.ts +++ b/components/packages/Platform/THPlatform.d.ts @@ -41,4 +41,7 @@ export declare class THPlatform extends JlPlatform { constructor(); get states(): ITHPlatformState; doRepaint(): void; + buildRelation(): void; + saveRelations(): void; + loadRelations(): void; } diff --git a/components/packages/Platform/THPlatform.js b/components/packages/Platform/THPlatform.js index 758d944..5fcd83e 100644 --- a/components/packages/Platform/THPlatform.js +++ b/components/packages/Platform/THPlatform.js @@ -1,5 +1,8 @@ +import { distance2, getRectangleCenter } from 'jl-graphic'; import { THConsts } from './PlatformConfig.js'; import { JlPlatform, DoorCodeLozenge } from './JlPlatform.js'; +import { JlSection } from '../Section/common/Section.js'; +import { THStation } from '../Station/THStation.js'; class THPlatform extends JlPlatform { doorCodeLozenge; @@ -93,6 +96,56 @@ class THPlatform extends JlPlatform { codeGraphic.stopTime.text = this.states.stopTime; } } + buildRelation() { + const stationas = this.queryStore.queryByType(THStation.Type); + for (let i = 0; i < stationas.length; i++) { + const sP = stationas[i].localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + this.relationManage.addRelation(this, stationas[i]); + break; + } + } + const sections = this.queryStore.queryByType(JlSection.Type); + const minDistanceRefSections = []; + sections.forEach((section) => { + const sP = section.localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + minDistanceRefSections.push(section); + } + }); + if (minDistanceRefSections) { + const refSection = minDistanceRefSections.reduce((prev, cur) => { + return distance2(prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), this.position) > + distance2(cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), this.position) + ? cur + : prev; + }); + this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type); + this.relationManage.addRelation(this, refSection); + } + } + saveRelations() { + const refStation = this.relationManage + .getRelationsOfGraphicAndOtherType(this, THStation.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refStation.length) { + this.datas.refStation = refStation[0]; + } + const refSection = this.relationManage + .getRelationsOfGraphicAndOtherType(this, JlSection.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refSection.length) { + this.datas.refSection = refSection[0]; + } + } + loadRelations() { + if (this.datas.refStation) { + this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refStation)); + } + if (this.datas.refSection) { + this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refSection)); + } + } } export { THPlatform }; diff --git a/components/packages/Section/bjrtss/Section.d.ts b/components/packages/Section/bjrtss/Section.d.ts index 8a9a334..095ddf2 100644 --- a/components/packages/Section/bjrtss/Section.d.ts +++ b/components/packages/Section/bjrtss/Section.d.ts @@ -1,4 +1,4 @@ -import { Section as SectionBase } from '../common/Section'; +import { JlSection as SectionBase } from '../common/Section'; export declare class Section extends SectionBase { constructor(); } diff --git a/components/packages/Section/bjrtss/Section.js b/components/packages/Section/bjrtss/Section.js index 406ca04..c91e867 100644 --- a/components/packages/Section/bjrtss/Section.js +++ b/components/packages/Section/bjrtss/Section.js @@ -1,4 +1,4 @@ -import { Section as Section$1 } from '../common/Section.js'; +import { JlSection } from '../common/Section.js'; export { SectionTemplate } from '../common/Section.js'; const displayConfig = { @@ -6,7 +6,7 @@ const displayConfig = { occupiedColor: '#f00', lineWidth: 5, }; -class Section extends Section$1 { +class Section extends JlSection { constructor() { super(); this.setDisplayConfig(displayConfig); diff --git a/components/packages/Section/common/Section.d.ts b/components/packages/Section/common/Section.d.ts index 7175502..2062dc4 100644 --- a/components/packages/Section/common/Section.d.ts +++ b/components/packages/Section/common/Section.d.ts @@ -35,7 +35,7 @@ export interface SectionDisplayConfig { lineWidth: number; } export declare const defaultDisplayConfig: SectionDisplayConfig; -export declare class Section extends JlGraphic { +export declare class JlSection extends JlGraphic { static Type: string; lineGraphic: SectionGraphic; labelGraphic: VectorText; @@ -51,7 +51,7 @@ export declare class Section extends JlGraphic { get linePoints(): IPointData[]; set linePoints(points: IPointData[]); getConnectElement(port: DevicePort): { - g: Turnout | Section; + g: Turnout | JlSection; port: DevicePort; } | undefined; /** 获取拆分逻辑区段数据 */ @@ -65,9 +65,9 @@ export declare class Section extends JlGraphic { saveRelations(): void; loadRelations(): void; } -export declare class SectionTemplate extends JlGraphicTemplate
{ +export declare class SectionTemplate extends JlGraphicTemplate { isCurve: boolean; segmentsCount: number; constructor(dataTemplate: ISectionData, stateTemplate?: ISectionState); - new(): Section; + new(): JlSection; } diff --git a/components/packages/Section/common/Section.js b/components/packages/Section/common/Section.js index e391e3d..a7493e3 100644 --- a/components/packages/Section/common/Section.js +++ b/components/packages/Section/common/Section.js @@ -18,13 +18,13 @@ const defaultDisplayConfig = { occupiedColor: '#f00', lineWidth: 5, }; -let Section$1 = class Section extends JlGraphic { +class JlSection extends JlGraphic { static Type = 'Section'; lineGraphic; labelGraphic; displayConfig = defaultDisplayConfig; constructor() { - super(Section.Type); + super(JlSection.Type); this.lineGraphic = new SectionGraphic(); this.labelGraphic = new VectorText(''); this.labelGraphic.setVectorFontSize(14); @@ -96,7 +96,7 @@ let Section$1 = class Section extends JlGraphic { const relation = this.relationManage .getRelationsOfGraphic(this) .find((relation) => relation.getRelationParam(this).getParam() === port && - (relation.getOtherGraphic(this) instanceof Section || + (relation.getOtherGraphic(this) instanceof JlSection || relation.getOtherGraphic(this) instanceof Turnout)); if (!relation) { return; @@ -146,9 +146,9 @@ let Section$1 = class Section extends JlGraphic { * */ buildRelation() { - this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type); + this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type); if (this.datas.sectionType === SectionType.Physical) { - this.queryStore.queryByType(Section.Type).forEach((section) => { + this.queryStore.queryByType(JlSection.Type).forEach((section) => { if (section.id === this.id) return; let param = []; @@ -174,7 +174,7 @@ let Section$1 = class Section extends JlGraphic { const paRelation = this.relationManage .getRelationsOfGraphic(this) .find((relation) => relation.getRelationParam(this).param === DevicePort.A && - (relation.getOtherGraphic(this) instanceof Section || + (relation.getOtherGraphic(this) instanceof JlSection || relation.getOtherGraphic(this) instanceof Turnout)); const paDevice = paRelation?.getOtherGraphic(this); if (paDevice) { @@ -186,7 +186,7 @@ let Section$1 = class Section extends JlGraphic { const pbRelation = this.relationManage .getRelationsOfGraphic(this) .find((relation) => relation.getRelationParam(this).param === DevicePort.B && - (relation.getOtherGraphic(this) instanceof Section || + (relation.getOtherGraphic(this) instanceof JlSection || relation.getOtherGraphic(this) instanceof Turnout)); const pbDevice = pbRelation?.getOtherGraphic(this); if (pbDevice) { @@ -217,22 +217,22 @@ let Section$1 = class Section extends JlGraphic { } } } -}; +} class SectionTemplate extends JlGraphicTemplate { isCurve = false; segmentsCount = 10; constructor(dataTemplate, stateTemplate) { - super(Section$1.Type, { + super(JlSection.Type, { dataTemplate, stateTemplate, }); } new() { - const section = new Section$1(); + const section = new JlSection(); section.loadData(this.datas); section.loadState(this.states); return section; } } -export { Section$1 as Section, SectionTemplate, SectionType, defaultDisplayConfig }; +export { JlSection, SectionTemplate, SectionType, defaultDisplayConfig }; diff --git a/src/packages/Platform/GPPlatform.ts b/src/packages/Platform/GPPlatform.ts index 0d1f22f..e19d439 100644 --- a/src/packages/Platform/GPPlatform.ts +++ b/src/packages/Platform/GPPlatform.ts @@ -1,6 +1,8 @@ -import { GraphicState } from 'jl-graphic'; +import { GraphicState, distance2, getRectangleCenter } from 'jl-graphic'; import { GPConsts } from './PlatformConfig'; import { JlPlatform } from './JlPlatform'; +import { GPStation } from '../Station/GPStation'; +import { JlSection } from '../Section/common/Section'; export interface IGPPlatformState extends GraphicState { id?: number; @@ -17,4 +19,69 @@ export class GPPlatform extends JlPlatform { this.rectGraphic.stateFillColor = GPConsts.noTrainStop; super.draw(); } + buildRelation() { + const stationas = this.queryStore.queryByType(GPStation.Type); + for (let i = 0; i < stationas.length; i++) { + const sP = stationas[i].localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + this.relationManage.addRelation(this, stationas[i]); + break; + } + } + const sections = this.queryStore.queryByType(JlSection.Type); + const minDistanceRefSections: JlSection[] = []; + sections.forEach((section) => { + const sP = section.localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + minDistanceRefSections.push(section); + } + }); + if (minDistanceRefSections) { + const refSection = minDistanceRefSections.reduce((prev, cur) => { + return distance2( + prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), + this.position, + ) > + distance2( + cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), + this.position, + ) + ? cur + : prev; + }); + this.relationManage.deleteRelationOfGraphicAndOtherType( + this, + JlSection.Type, + ); + this.relationManage.addRelation(this, refSection); + } + } + saveRelations() { + const refStation = this.relationManage + .getRelationsOfGraphicAndOtherType(this, GPStation.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refStation.length) { + this.datas.refStation = refStation[0]; + } + const refSection = this.relationManage + .getRelationsOfGraphicAndOtherType(this, JlSection.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refSection.length) { + this.datas.refSection = refSection[0]; + } + } + loadRelations() { + if (this.datas.refStation) { + this.relationManage.addRelation( + this, + this.queryStore.queryById(this.datas.refStation), + ); + } + if (this.datas.refSection) { + this.relationManage.addRelation( + this, + this.queryStore.queryById(this.datas.refSection), + ); + } + } } diff --git a/src/packages/Platform/THPlatform.ts b/src/packages/Platform/THPlatform.ts index c203612..3faeb29 100644 --- a/src/packages/Platform/THPlatform.ts +++ b/src/packages/Platform/THPlatform.ts @@ -1,6 +1,8 @@ -import { GraphicState } from 'jl-graphic'; +import { GraphicState, distance2, getRectangleCenter } from 'jl-graphic'; import { THConsts } from './PlatformConfig'; import { JlPlatform, DoorCodeLozenge } from './JlPlatform'; +import { JlSection } from '../Section/common/Section'; +import { THStation } from '../Station/THStation'; export interface ITHPlatformState extends GraphicState { get emergstop(): boolean; //紧急关闭 @@ -134,4 +136,69 @@ export class THPlatform extends JlPlatform { codeGraphic.stopTime.text = this.states.stopTime; } } + buildRelation() { + const stationas = this.queryStore.queryByType(THStation.Type); + for (let i = 0; i < stationas.length; i++) { + const sP = stationas[i].localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + this.relationManage.addRelation(this, stationas[i]); + break; + } + } + const sections = this.queryStore.queryByType(JlSection.Type); + const minDistanceRefSections: JlSection[] = []; + sections.forEach((section) => { + const sP = section.localBoundsToCanvasPoints(); + if (this.x > sP[0].x && this.x < sP[1].x) { + minDistanceRefSections.push(section); + } + }); + if (minDistanceRefSections) { + const refSection = minDistanceRefSections.reduce((prev, cur) => { + return distance2( + prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), + this.position, + ) > + distance2( + cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), + this.position, + ) + ? cur + : prev; + }); + this.relationManage.deleteRelationOfGraphicAndOtherType( + this, + JlSection.Type, + ); + this.relationManage.addRelation(this, refSection); + } + } + saveRelations() { + const refStation = this.relationManage + .getRelationsOfGraphicAndOtherType(this, THStation.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refStation.length) { + this.datas.refStation = refStation[0]; + } + const refSection = this.relationManage + .getRelationsOfGraphicAndOtherType(this, JlSection.Type) + .map((relation) => relation.getOtherGraphic(this).datas.id); + if (refSection.length) { + this.datas.refSection = refSection[0]; + } + } + loadRelations() { + if (this.datas.refStation) { + this.relationManage.addRelation( + this, + this.queryStore.queryById(this.datas.refStation), + ); + } + if (this.datas.refSection) { + this.relationManage.addRelation( + this, + this.queryStore.queryById(this.datas.refSection), + ); + } + } } diff --git a/src/packages/Section/bjrtss/Section.ts b/src/packages/Section/bjrtss/Section.ts index 55c8021..cbff076 100644 --- a/src/packages/Section/bjrtss/Section.ts +++ b/src/packages/Section/bjrtss/Section.ts @@ -1,5 +1,5 @@ import { - Section as SectionBase, + JlSection as SectionBase, SectionDisplayConfig, } from '../common/Section'; diff --git a/src/packages/Section/common/Section.ts b/src/packages/Section/common/Section.ts index 110598d..db1fa09 100644 --- a/src/packages/Section/common/Section.ts +++ b/src/packages/Section/common/Section.ts @@ -59,14 +59,14 @@ export const defaultDisplayConfig: SectionDisplayConfig = { lineWidth: 5, }; -export class Section extends JlGraphic { +export class JlSection extends JlGraphic { static Type = 'Section'; lineGraphic: SectionGraphic; labelGraphic: VectorText; displayConfig = defaultDisplayConfig; constructor() { - super(Section.Type); + super(JlSection.Type); this.lineGraphic = new SectionGraphic(); this.labelGraphic = new VectorText(''); this.labelGraphic.setVectorFontSize(14); @@ -150,14 +150,14 @@ export class Section extends JlGraphic { .find( (relation) => relation.getRelationParam(this).getParam() === port && - (relation.getOtherGraphic(this) instanceof Section || + (relation.getOtherGraphic(this) instanceof JlSection || relation.getOtherGraphic(this) instanceof Turnout), ); if (!relation) { return; } return { - g: relation?.getOtherGraphic(this) as Section | Turnout, + g: relation?.getOtherGraphic(this) as JlSection | Turnout, port: relation?.getOtherRelationParam(this).getParam(), }; } @@ -217,10 +217,10 @@ export class Section extends JlGraphic { */ buildRelation() { - this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type); + this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type); if (this.datas.sectionType === SectionType.Physical) { - this.queryStore.queryByType
(Section.Type).forEach((section) => { + this.queryStore.queryByType(JlSection.Type).forEach((section) => { if (section.id === this.id) return; let param: DevicePort[] = []; @@ -272,10 +272,10 @@ export class Section extends JlGraphic { .find( (relation) => relation.getRelationParam(this).param === DevicePort.A && - (relation.getOtherGraphic(this) instanceof Section || + (relation.getOtherGraphic(this) instanceof JlSection || relation.getOtherGraphic(this) instanceof Turnout), ); - const paDevice = paRelation?.getOtherGraphic
(this); + const paDevice = paRelation?.getOtherGraphic(this); if (paDevice) { this.datas.paRef = IRelatedRef.create( paDevice.type, @@ -290,10 +290,10 @@ export class Section extends JlGraphic { .find( (relation) => relation.getRelationParam(this).param === DevicePort.B && - (relation.getOtherGraphic(this) instanceof Section || + (relation.getOtherGraphic(this) instanceof JlSection || relation.getOtherGraphic(this) instanceof Turnout), ); - const pbDevice = pbRelation?.getOtherGraphic
(this); + const pbDevice = pbRelation?.getOtherGraphic(this); if (pbDevice) { this.datas.pbRef = IRelatedRef.create( pbDevice.type, @@ -330,7 +330,7 @@ export class Section extends JlGraphic { if (this.datas.trackSectionId) { this.relationManage.addRelation( this, - this.queryStore.queryById
(this.datas.trackSectionId), + this.queryStore.queryById(this.datas.trackSectionId), ); } if (this.datas.sectionType === SectionType.TurnoutPhysical) { @@ -346,17 +346,17 @@ export class Section extends JlGraphic { } } -export class SectionTemplate extends JlGraphicTemplate
{ +export class SectionTemplate extends JlGraphicTemplate { isCurve = false; segmentsCount = 10; constructor(dataTemplate: ISectionData, stateTemplate?: ISectionState) { - super(Section.Type, { + super(JlSection.Type, { dataTemplate, stateTemplate, }); } - new(): Section { - const section = new Section(); + new(): JlSection { + const section = new JlSection(); section.loadData(this.datas); section.loadState(this.states); return section;