diff --git a/components/packages/Platform/GPPlatform.d.ts b/components/packages/Platform/GPPlatform.d.ts index 15b6d2c..05f9d08 100644 --- a/components/packages/Platform/GPPlatform.d.ts +++ b/components/packages/Platform/GPPlatform.d.ts @@ -1,10 +1,13 @@ import { GraphicState } from 'jl-graphic'; -import { JlPlatform } from './JlPlatform'; -export interface IBeiJingPlatformState extends GraphicState { +import { JlPlatform } from './common/JlPlatform'; +export interface IGPPlatformState extends GraphicState { id?: number; } export declare class GPPlatform extends JlPlatform { constructor(); - get states(): IBeiJingPlatformState; + 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..c0231d7 100644 --- a/components/packages/Platform/GPPlatform.js +++ b/components/packages/Platform/GPPlatform.js @@ -1,5 +1,5 @@ -import { GPConsts } from './PlatformConfig.js'; -import { JlPlatform } from './JlPlatform.js'; +import { GPConsts } from './common/PlatformConfig.js'; +import { JlPlatform } from './common/JlPlatform.js'; class GPPlatform extends JlPlatform { constructor() { @@ -12,6 +12,15 @@ class GPPlatform extends JlPlatform { this.rectGraphic.stateFillColor = GPConsts.noTrainStop; super.draw(); } + buildRelation() { + super.buildCommonRelation(); + } + saveRelations() { + super.saveCommonRelations(); + } + loadRelations() { + super.loadCommonRelations(); + } } export { GPPlatform }; diff --git a/components/packages/Platform/THPlatform.d.ts b/components/packages/Platform/THPlatform.d.ts index b03ef32..2a03871 100644 --- a/components/packages/Platform/THPlatform.d.ts +++ b/components/packages/Platform/THPlatform.d.ts @@ -1,5 +1,5 @@ import { GraphicState } from 'jl-graphic'; -import { JlPlatform, DoorCodeLozenge } from './JlPlatform'; +import { JlPlatform, DoorCodeLozenge } from './common/JlPlatform'; export interface ITHPlatformState extends GraphicState { get emergstop(): boolean; set emergstop(v: boolean); @@ -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 268e421..3e79d9d 100644 --- a/components/packages/Platform/THPlatform.js +++ b/components/packages/Platform/THPlatform.js @@ -1,12 +1,12 @@ -import { THConsts } from './PlatformConfig.js'; -import { JlPlatform, DoorCodeLozenge } from './JlPlatform.js'; -import { StyleType } from '../../common/common.js'; +import { THConsts } from './common/PlatformConfig.js'; +import { JlPlatform, DoorCodeLozenge } from './common/JlPlatform.js'; +import { THStation } from '../Station/THStation.js'; class THPlatform extends JlPlatform { doorCodeLozenge; constructor() { super(THConsts); - this.doorCodeLozenge = new DoorCodeLozenge(StyleType.TH); + this.doorCodeLozenge = new DoorCodeLozenge(THConsts); this.addChild(this.doorCodeLozenge); } get states() { @@ -20,15 +20,15 @@ class THPlatform extends JlPlatform { if (this.states.upSkipstop || this.states.downSkipstop) { this.rectGraphic.stateFillColor = THConsts.trainJump; } - /* const station = this.getGraphicApp().queryStore.queryByCodeAndType( - this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, - Station.Type - ); */ + const station = this.getGraphicApp().queryStore.queryByCodeAndType(this.states.rtuId > 9 + ? '' + this.states.rtuId + : '0' + this.states.rtuId, THStation.Type); const doorGraphic = this.doorCodeLozenge.doorGraphic; doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen; - /* if (!!station?.states.ipRtuStusDown) { + if (!!station?.states.ipRtuStusDown) { doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue; - } */ if (this.states.psdCut) { + } + else if (this.states.psdCut) { doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed; } super.draw(); @@ -94,6 +94,15 @@ class THPlatform extends JlPlatform { codeGraphic.stopTime.text = this.states.stopTime; } } + buildRelation() { + super.buildCommonRelation(); + } + saveRelations() { + super.saveCommonRelations(); + } + loadRelations() { + super.loadCommonRelations(); + } } export { THPlatform }; diff --git a/components/packages/Platform/JlPlatform.d.ts b/components/packages/Platform/common/JlPlatform.d.ts similarity index 91% rename from components/packages/Platform/JlPlatform.d.ts rename to components/packages/Platform/common/JlPlatform.d.ts index 9645709..97cce0f 100644 --- a/components/packages/Platform/JlPlatform.d.ts +++ b/components/packages/Platform/common/JlPlatform.d.ts @@ -1,7 +1,6 @@ import { JlGraphic, VectorText } from 'jl-graphic'; import { Container, Graphics } from 'pixi.js'; import { IPlatformData, PlatformConstsConfig } from './PlatformConfig'; -import { StyleType } from 'common/common'; declare class RectGraphic extends Container { rect: Graphics; stateFillColor?: string; @@ -34,12 +33,11 @@ declare class LozengeGraphic extends Container { clear(): void; } export declare class DoorCodeLozenge extends Container { - private styleType; private platformConsts; doorGraphic: DoorGraphic; lozengeGraphic: LozengeGraphic; codeGraphic: CodeGraphic; - constructor(styleType: StyleType); + constructor(platformConsts: PlatformConstsConfig); draw(hasDoor: boolean, direction: string): void; } export declare abstract class JlPlatform extends JlGraphic { @@ -50,5 +48,8 @@ export declare abstract class JlPlatform extends JlGraphic { get datas(): IPlatformData; get code(): string; draw(): void; + buildCommonRelation(): void; + saveCommonRelations(): void; + loadCommonRelations(): void; } export {}; diff --git a/components/packages/Platform/JlPlatform.js b/components/packages/Platform/common/JlPlatform.js similarity index 76% rename from components/packages/Platform/JlPlatform.js rename to components/packages/Platform/common/JlPlatform.js index 7bb920f..6e19071 100644 --- a/components/packages/Platform/JlPlatform.js +++ b/components/packages/Platform/common/JlPlatform.js @@ -1,6 +1,7 @@ -import { calculateMirrorPoint, JlGraphic, getRectangleCenter, VectorText } from 'jl-graphic'; +import { calculateMirrorPoint, JlGraphic, distance2, getRectangleCenter, VectorText } from 'jl-graphic'; import { Container, Point, Graphics, Color, Rectangle } from 'pixi.js'; -import { platformConstsMap } from './PlatformConfig.js'; +import { JlSection } from '../../Section/common/Section.js'; +import { JlStation } from '../../Station/common/JlStation.js'; //子元素--矩形 class RectGraphic extends Container { @@ -157,15 +158,13 @@ class LozengeGraphic extends Container { } } class DoorCodeLozenge extends Container { - styleType; platformConsts; doorGraphic; lozengeGraphic; codeGraphic; - constructor(styleType) { + constructor(platformConsts) { super(); - this.styleType = styleType; - this.platformConsts = platformConstsMap.get(this.styleType); + this.platformConsts = platformConsts; this.doorGraphic = new DoorGraphic(); this.addChild(this.doorGraphic); this.lozengeGraphic = new LozengeGraphic(); @@ -228,6 +227,56 @@ class JlPlatform extends JlGraphic { draw() { this.rectGraphic.draw(this.platformConsts); } + buildCommonRelation() { + const stationas = this.queryStore.queryByType(JlStation.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); + } + } + saveCommonRelations() { + const refStation = this.relationManage + .getRelationsOfGraphicAndOtherType(this, JlStation.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]; + } + } + loadCommonRelations() { + 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 { DoorCodeLozenge, JlPlatform }; diff --git a/components/packages/Platform/PlatformConfig.d.ts b/components/packages/Platform/common/PlatformConfig.d.ts similarity index 94% rename from components/packages/Platform/PlatformConfig.d.ts rename to components/packages/Platform/common/PlatformConfig.d.ts index 7f1856e..c00b971 100644 --- a/components/packages/Platform/PlatformConfig.d.ts +++ b/components/packages/Platform/common/PlatformConfig.d.ts @@ -1,4 +1,3 @@ -import { StyleType } from 'common/common'; import { GraphicData } from 'jl-graphic'; export interface PlatformConstsConfig { width: number; @@ -69,7 +68,6 @@ export declare const THConsts: { doorPlatformSpacing: number; }; }; -export declare const platformConstsMap: Map; declare enum TypeOfPlatform { Unknown = 0, up = 1, diff --git a/components/packages/Platform/PlatformConfig.js b/components/packages/Platform/common/PlatformConfig.js similarity index 84% rename from components/packages/Platform/PlatformConfig.js rename to components/packages/Platform/common/PlatformConfig.js index 1fbd07f..29aeeca 100644 --- a/components/packages/Platform/PlatformConfig.js +++ b/components/packages/Platform/common/PlatformConfig.js @@ -1,5 +1,3 @@ -import { StyleType } from '../../common/common.js'; - const GPConsts = { width: 90, height: 20, @@ -37,10 +35,6 @@ const THConsts = { doorPlatformSpacing: 10, }, }; -const platformConstsMap = new Map([ - [StyleType.GP, GPConsts], - [StyleType.TH, THConsts], -]); var TypeOfPlatform; (function (TypeOfPlatform) { TypeOfPlatform[TypeOfPlatform["Unknown"] = 0] = "Unknown"; @@ -48,4 +42,4 @@ var TypeOfPlatform; TypeOfPlatform[TypeOfPlatform["down"] = 2] = "down"; })(TypeOfPlatform || (TypeOfPlatform = {})); -export { GPConsts, THConsts, platformConstsMap }; +export { GPConsts, THConsts }; diff --git a/components/packages/Platform/PlatformDrawAssistant.d.ts b/components/packages/Platform/common/PlatformDrawAssistant.d.ts similarity index 100% rename from components/packages/Platform/PlatformDrawAssistant.d.ts rename to components/packages/Platform/common/PlatformDrawAssistant.d.ts diff --git a/components/packages/Platform/PlatformDrawAssistant.js b/components/packages/Platform/common/PlatformDrawAssistant.js similarity index 98% rename from components/packages/Platform/PlatformDrawAssistant.js rename to components/packages/Platform/common/PlatformDrawAssistant.js index 6350078..fa420b2 100644 --- a/components/packages/Platform/PlatformDrawAssistant.js +++ b/components/packages/Platform/common/PlatformDrawAssistant.js @@ -1,6 +1,6 @@ import { GraphicDrawAssistant, GraphicInteractionPlugin, AbsorbableLine } from 'jl-graphic'; import { JlPlatform } from './JlPlatform.js'; -import { StyleType } from '../../common/common.js'; +import { StyleType } from '../../../common/common.js'; class PlatformDraw extends GraphicDrawAssistant { platformGraphic; diff --git a/components/packages/Platform/PlatformTemplate.d.ts b/components/packages/Platform/common/PlatformTemplate.d.ts similarity index 72% rename from components/packages/Platform/PlatformTemplate.d.ts rename to components/packages/Platform/common/PlatformTemplate.d.ts index 62cfa74..a083894 100644 --- a/components/packages/Platform/PlatformTemplate.d.ts +++ b/components/packages/Platform/common/PlatformTemplate.d.ts @@ -1,13 +1,13 @@ import { JlGraphicTemplate } from 'jl-graphic'; import { JlPlatform } from './JlPlatform'; import { IPlatformData } from './PlatformConfig'; -import { ITHPlatformState } from './THPlatform'; -import { IBeiJingPlatformState } from './GPPlatform'; +import { ITHPlatformState } from '../THPlatform'; +import { IGPPlatformState } from '../GPPlatform'; import { StyleType } from 'common/common'; export declare class PlatformTemplate extends JlGraphicTemplate { hasdoor?: boolean; direction?: string; styleType: StyleType; - constructor(dataTemplate: IPlatformData, stateTemplate: ITHPlatformState | IBeiJingPlatformState, styleType: StyleType); + constructor(dataTemplate: IPlatformData, stateTemplate: ITHPlatformState | IGPPlatformState, styleType: StyleType); new(): JlPlatform; } diff --git a/components/packages/Platform/PlatformTemplate.js b/components/packages/Platform/common/PlatformTemplate.js similarity index 86% rename from components/packages/Platform/PlatformTemplate.js rename to components/packages/Platform/common/PlatformTemplate.js index 5527872..67e8f66 100644 --- a/components/packages/Platform/PlatformTemplate.js +++ b/components/packages/Platform/common/PlatformTemplate.js @@ -1,8 +1,8 @@ import { JlGraphicTemplate } from 'jl-graphic'; import { JlPlatform } from './JlPlatform.js'; -import { THPlatform } from './THPlatform.js'; -import { GPPlatform } from './GPPlatform.js'; -import { StyleType } from '../../common/common.js'; +import { THPlatform } from '../THPlatform.js'; +import { GPPlatform } from '../GPPlatform.js'; +import { StyleType } from '../../../common/common.js'; class PlatformTemplate extends JlGraphicTemplate { hasdoor; diff --git a/components/packages/Section/GPSection.d.ts b/components/packages/Section/GPSection.d.ts new file mode 100644 index 0000000..42beef4 --- /dev/null +++ b/components/packages/Section/GPSection.d.ts @@ -0,0 +1,5 @@ +import { JlSection as SectionBase } from './common/Section'; +export declare class Section extends SectionBase { + constructor(); +} +export { SectionTemplate } from './common/Section'; diff --git a/components/packages/Section/bjrtss/Section.js b/components/packages/Section/GPSection.js similarity index 58% rename from components/packages/Section/bjrtss/Section.js rename to components/packages/Section/GPSection.js index 406ca04..acbab2d 100644 --- a/components/packages/Section/bjrtss/Section.js +++ b/components/packages/Section/GPSection.js @@ -1,12 +1,12 @@ -import { Section as Section$1 } from '../common/Section.js'; -export { SectionTemplate } from '../common/Section.js'; +import { JlSection } from './common/Section.js'; +export { SectionTemplate } from './common/Section.js'; const displayConfig = { lineColor: '#5578b6', occupiedColor: '#f00', lineWidth: 5, }; -class Section extends Section$1 { +class Section extends JlSection { constructor() { super(); this.setDisplayConfig(displayConfig); diff --git a/components/packages/Section/bjrtss/Section.d.ts b/components/packages/Section/bjrtss/Section.d.ts deleted file mode 100644 index 8a9a334..0000000 --- a/components/packages/Section/bjrtss/Section.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Section as SectionBase } from '../common/Section'; -export declare class Section extends SectionBase { - constructor(); -} -export { SectionTemplate } from '../common/Section'; 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/components/packages/Section/common/SectionDrawAssistant.d.ts b/components/packages/Section/common/SectionDrawAssistant.d.ts index 0ad1ca6..42ca07a 100644 --- a/components/packages/Section/common/SectionDrawAssistant.d.ts +++ b/components/packages/Section/common/SectionDrawAssistant.d.ts @@ -1,7 +1,7 @@ import { GraphicDrawAssistant, GraphicInteractionPlugin, IDrawApp, IGraphicApp, JlGraphic, KeyListener, MenuItemOptions } from 'jl-graphic'; import { ISectionData, SectionTemplate } from './Section'; import { Point, Graphics, type FederatedMouseEvent, type IHitArea, type DisplayObject } from 'pixi.js'; -import { Section } from '../bjrtss/Section'; +import { Section } from '../GPSection'; export declare class SectionDraw extends GraphicDrawAssistant { points: Point[]; graphic: Graphics; diff --git a/components/packages/Section/common/SectionDrawAssistant.js b/components/packages/Section/common/SectionDrawAssistant.js index 175dbf4..df5515d 100644 --- a/components/packages/Section/common/SectionDrawAssistant.js +++ b/components/packages/Section/common/SectionDrawAssistant.js @@ -2,7 +2,7 @@ import { ContextMenu, GraphicDrawAssistant, KeyListener, calculateMirrorPoint, c import { SectionType, defaultDisplayConfig } from './Section.js'; import { Graphics, Point } from 'pixi.js'; import { Turnout } from '../../Turnout/Turnout.js'; -import { Section } from '../bjrtss/Section.js'; +import { Section } from '../GPSection.js'; class SectionDraw extends GraphicDrawAssistant { points = []; diff --git a/components/packages/Station/GPStation.d.ts b/components/packages/Station/GPStation.d.ts index a9644fa..918e7c5 100644 --- a/components/packages/Station/GPStation.d.ts +++ b/components/packages/Station/GPStation.d.ts @@ -1,5 +1,5 @@ import { GraphicState } from 'jl-graphic'; -import { JlStation } from './JlStation'; +import { JlStation } from './common/JlStation'; export interface IGPStationState extends GraphicState { id: number; } diff --git a/components/packages/Station/GPStation.js b/components/packages/Station/GPStation.js index 8b6de09..5967a67 100644 --- a/components/packages/Station/GPStation.js +++ b/components/packages/Station/GPStation.js @@ -1,4 +1,4 @@ -import { JlStation } from './JlStation.js'; +import { JlStation } from './common/JlStation.js'; import { StyleType } from '../../common/common.js'; class GPStation extends JlStation { diff --git a/components/packages/Station/THStation.d.ts b/components/packages/Station/THStation.d.ts index 0547bda..86ac0d1 100644 --- a/components/packages/Station/THStation.d.ts +++ b/components/packages/Station/THStation.d.ts @@ -1,5 +1,5 @@ import { GraphicState } from 'jl-graphic'; -import { ConstrolGraphic, JlStation } from './JlStation'; +import { ConstrolGraphic, JlStation } from './common/JlStation'; export interface ITHStationState extends GraphicState { get ipRtuStusDown(): boolean; set ipRtuStusDown(v: boolean); diff --git a/components/packages/Station/THStation.js b/components/packages/Station/THStation.js index 4331893..5c36728 100644 --- a/components/packages/Station/THStation.js +++ b/components/packages/Station/THStation.js @@ -1,5 +1,5 @@ -import { JlStation, ConstrolGraphic } from './JlStation.js'; -import { THConsts } from './StationConfig.js'; +import { JlStation, ConstrolGraphic } from './common/JlStation.js'; +import { THConsts } from './common/StationConfig.js'; import { StyleType } from '../../common/common.js'; class THStation extends JlStation { diff --git a/components/packages/Station/JlStation.d.ts b/components/packages/Station/common/JlStation.d.ts similarity index 100% rename from components/packages/Station/JlStation.d.ts rename to components/packages/Station/common/JlStation.d.ts diff --git a/components/packages/Station/JlStation.js b/components/packages/Station/common/JlStation.js similarity index 99% rename from components/packages/Station/JlStation.js rename to components/packages/Station/common/JlStation.js index 19d9877..67ad6d4 100644 --- a/components/packages/Station/JlStation.js +++ b/components/packages/Station/common/JlStation.js @@ -1,7 +1,7 @@ import { Container, Point, Graphics, Color } from 'pixi.js'; import { VectorText, JlGraphic } from 'jl-graphic'; import { stationConstsMap } from './StationConfig.js'; -import { StyleType } from '../../common/common.js'; +import { StyleType } from '../../../common/common.js'; class ConstrolGraphic extends Container { constrolConfig; diff --git a/components/packages/Station/StationConfig.d.ts b/components/packages/Station/common/StationConfig.d.ts similarity index 100% rename from components/packages/Station/StationConfig.d.ts rename to components/packages/Station/common/StationConfig.d.ts diff --git a/components/packages/Station/StationConfig.js b/components/packages/Station/common/StationConfig.js similarity index 97% rename from components/packages/Station/StationConfig.js rename to components/packages/Station/common/StationConfig.js index aa1e19c..3860192 100644 --- a/components/packages/Station/StationConfig.js +++ b/components/packages/Station/common/StationConfig.js @@ -1,4 +1,4 @@ -import { StyleType } from '../../common/common.js'; +import { StyleType } from '../../../common/common.js'; const GPConsts = { codeColor: '0xF48815', diff --git a/components/packages/Station/StationDrawAssistant.d.ts b/components/packages/Station/common/StationDrawAssistant.d.ts similarity index 100% rename from components/packages/Station/StationDrawAssistant.d.ts rename to components/packages/Station/common/StationDrawAssistant.d.ts diff --git a/components/packages/Station/StationDrawAssistant.js b/components/packages/Station/common/StationDrawAssistant.js similarity index 97% rename from components/packages/Station/StationDrawAssistant.js rename to components/packages/Station/common/StationDrawAssistant.js index 891d9aa..edb7b18 100644 --- a/components/packages/Station/StationDrawAssistant.js +++ b/components/packages/Station/common/StationDrawAssistant.js @@ -1,6 +1,6 @@ import { GraphicDrawAssistant, GraphicInteractionPlugin, AbsorbableLine } from 'jl-graphic'; import { JlStation } from './JlStation.js'; -import { StyleType } from '../../common/common.js'; +import { StyleType } from '../../../common/common.js'; class StationDraw extends GraphicDrawAssistant { codeGraph; diff --git a/components/packages/Station/StationTemplate.d.ts b/components/packages/Station/common/StationTemplate.d.ts similarity index 82% rename from components/packages/Station/StationTemplate.d.ts rename to components/packages/Station/common/StationTemplate.d.ts index ca66bf1..5594f8a 100644 --- a/components/packages/Station/StationTemplate.d.ts +++ b/components/packages/Station/common/StationTemplate.d.ts @@ -1,8 +1,8 @@ import { JlGraphicTemplate } from 'jl-graphic'; import { JlStation } from './JlStation'; import { IStationData } from './StationConfig'; -import { ITHStationState } from './THStation'; -import { IGPStationState } from './GPStation'; +import { ITHStationState } from '../THStation'; +import { IGPStationState } from '../GPStation'; import { StyleType } from 'common/common'; export declare class StationTemplate extends JlGraphicTemplate { hasControl?: boolean; diff --git a/components/packages/Station/StationTemplate.js b/components/packages/Station/common/StationTemplate.js similarity index 86% rename from components/packages/Station/StationTemplate.js rename to components/packages/Station/common/StationTemplate.js index edf9980..3077126 100644 --- a/components/packages/Station/StationTemplate.js +++ b/components/packages/Station/common/StationTemplate.js @@ -1,8 +1,8 @@ import { JlGraphicTemplate } from 'jl-graphic'; import { JlStation } from './JlStation.js'; -import { THStation } from './THStation.js'; -import { GPStation } from './GPStation.js'; -import { StyleType } from '../../common/common.js'; +import { THStation } from '../THStation.js'; +import { GPStation } from '../GPStation.js'; +import { StyleType } from '../../../common/common.js'; class StationTemplate extends JlGraphicTemplate { hasControl; diff --git a/src/packages/Platform/GPPlatform.ts b/src/packages/Platform/GPPlatform.ts index 76785fa..05a76a9 100644 --- a/src/packages/Platform/GPPlatform.ts +++ b/src/packages/Platform/GPPlatform.ts @@ -1,8 +1,8 @@ import { GraphicState } from 'jl-graphic'; -import { GPConsts } from './PlatformConfig'; -import { JlPlatform } from './JlPlatform'; +import { GPConsts } from './common/PlatformConfig'; +import { JlPlatform } from './common/JlPlatform'; -export interface IBeiJingPlatformState extends GraphicState { +export interface IGPPlatformState extends GraphicState { id?: number; } @@ -10,11 +10,20 @@ export class GPPlatform extends JlPlatform { constructor() { super(GPConsts); } - get states(): IBeiJingPlatformState { - return this.getStates(); + get states(): IGPPlatformState { + return this.getStates(); } doRepaint(): void { this.rectGraphic.stateFillColor = GPConsts.noTrainStop; super.draw(); } + buildRelation() { + super.buildCommonRelation(); + } + saveRelations() { + super.saveCommonRelations(); + } + loadRelations() { + super.loadCommonRelations(); + } } diff --git a/src/packages/Platform/THPlatform.ts b/src/packages/Platform/THPlatform.ts index 222d962..834fd42 100644 --- a/src/packages/Platform/THPlatform.ts +++ b/src/packages/Platform/THPlatform.ts @@ -1,7 +1,7 @@ import { GraphicState } from 'jl-graphic'; -import { THConsts } from './PlatformConfig'; -import { JlPlatform, DoorCodeLozenge } from './JlPlatform'; -import { StyleType } from 'common/common'; +import { THConsts } from './common/PlatformConfig'; +import { JlPlatform, DoorCodeLozenge } from './common/JlPlatform'; +import { THStation } from '../Station/THStation'; export interface ITHPlatformState extends GraphicState { get emergstop(): boolean; //紧急关闭 @@ -44,7 +44,7 @@ export class THPlatform extends JlPlatform { doorCodeLozenge: DoorCodeLozenge; constructor() { super(THConsts); - this.doorCodeLozenge = new DoorCodeLozenge(StyleType.TH); + this.doorCodeLozenge = new DoorCodeLozenge(THConsts); this.addChild(this.doorCodeLozenge); } get states(): ITHPlatformState { @@ -58,15 +58,18 @@ export class THPlatform extends JlPlatform { if (this.states.upSkipstop || this.states.downSkipstop) { this.rectGraphic.stateFillColor = THConsts.trainJump; } - /* const station = this.getGraphicApp().queryStore.queryByCodeAndType( - this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, - Station.Type - ); */ + const station = + this.getGraphicApp().queryStore.queryByCodeAndType( + this.states.rtuId > 9 + ? '' + this.states.rtuId + : '0' + this.states.rtuId, + THStation.Type, + ); const doorGraphic = this.doorCodeLozenge.doorGraphic; doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen; - /* if (!!station?.states.ipRtuStusDown) { - doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue; - } */ if (this.states.psdCut) { + if (!!station?.states.ipRtuStusDown) { + doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue; + } else if (this.states.psdCut) { doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed; } super.draw(); @@ -135,4 +138,13 @@ export class THPlatform extends JlPlatform { codeGraphic.stopTime.text = this.states.stopTime; } } + buildRelation() { + super.buildCommonRelation(); + } + saveRelations() { + super.saveCommonRelations(); + } + loadRelations() { + super.loadCommonRelations(); + } } diff --git a/src/packages/Platform/JlPlatform.ts b/src/packages/Platform/common/JlPlatform.ts similarity index 78% rename from src/packages/Platform/JlPlatform.ts rename to src/packages/Platform/common/JlPlatform.ts index 9e7ba95..301d05c 100644 --- a/src/packages/Platform/JlPlatform.ts +++ b/src/packages/Platform/common/JlPlatform.ts @@ -2,6 +2,7 @@ import { JlGraphic, VectorText, calculateMirrorPoint, + distance2, getRectangleCenter, } from 'jl-graphic'; import { Container, Graphics, Rectangle, Color, Point } from 'pixi.js'; @@ -11,9 +12,9 @@ import { IPlatformData, LozengeConstsConfig, PlatformConstsConfig, - platformConstsMap, } from './PlatformConfig'; -import { StyleType } from 'common/common'; +import { JlSection } from '../../Section/common/Section'; +import { JlStation } from '../../Station/common/JlStation'; //子元素--矩形 class RectGraphic extends Container { @@ -193,17 +194,13 @@ class LozengeGraphic extends Container { } export class DoorCodeLozenge extends Container { - private styleType: StyleType; private platformConsts: PlatformConstsConfig; doorGraphic: DoorGraphic; lozengeGraphic: LozengeGraphic; codeGraphic: CodeGraphic; - constructor(styleType: StyleType) { + constructor(platformConsts: PlatformConstsConfig) { super(); - this.styleType = styleType; - this.platformConsts = platformConstsMap.get( - this.styleType, - ) as PlatformConstsConfig; + this.platformConsts = platformConsts; this.doorGraphic = new DoorGraphic(); this.addChild(this.doorGraphic); this.lozengeGraphic = new LozengeGraphic(); @@ -282,4 +279,69 @@ export abstract class JlPlatform extends JlGraphic { draw(): void { this.rectGraphic.draw(this.platformConsts); } + buildCommonRelation() { + const stationas = this.queryStore.queryByType(JlStation.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); + } + } + saveCommonRelations() { + const refStation = this.relationManage + .getRelationsOfGraphicAndOtherType(this, JlStation.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]; + } + } + loadCommonRelations() { + 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/PlatformConfig.ts b/src/packages/Platform/common/PlatformConfig.ts similarity index 93% rename from src/packages/Platform/PlatformConfig.ts rename to src/packages/Platform/common/PlatformConfig.ts index 574d3fc..f775d59 100644 --- a/src/packages/Platform/PlatformConfig.ts +++ b/src/packages/Platform/common/PlatformConfig.ts @@ -1,4 +1,3 @@ -import { StyleType } from 'common/common'; import { GraphicData } from 'jl-graphic'; export interface PlatformConstsConfig { @@ -76,11 +75,6 @@ export const THConsts = { }, }; -export const platformConstsMap = new Map([ - [StyleType.GP, GPConsts], - [StyleType.TH, THConsts], -]); - enum TypeOfPlatform { Unknown = 0, up = 1, diff --git a/src/packages/Platform/PlatformDrawAssistant.ts b/src/packages/Platform/common/PlatformDrawAssistant.ts similarity index 100% rename from src/packages/Platform/PlatformDrawAssistant.ts rename to src/packages/Platform/common/PlatformDrawAssistant.ts diff --git a/src/packages/Platform/PlatformTemplate.ts b/src/packages/Platform/common/PlatformTemplate.ts similarity index 84% rename from src/packages/Platform/PlatformTemplate.ts rename to src/packages/Platform/common/PlatformTemplate.ts index adde8e5..bc1e96a 100644 --- a/src/packages/Platform/PlatformTemplate.ts +++ b/src/packages/Platform/common/PlatformTemplate.ts @@ -1,8 +1,8 @@ import { JlGraphicTemplate } from 'jl-graphic'; import { JlPlatform } from './JlPlatform'; import { IPlatformData } from './PlatformConfig'; -import { ITHPlatformState, THPlatform } from './THPlatform'; -import { GPPlatform, IBeiJingPlatformState } from './GPPlatform'; +import { ITHPlatformState, THPlatform } from '../THPlatform'; +import { GPPlatform, IGPPlatformState } from '../GPPlatform'; import { StyleType } from 'common/common'; export class PlatformTemplate extends JlGraphicTemplate { @@ -11,7 +11,7 @@ export class PlatformTemplate extends JlGraphicTemplate { styleType: StyleType; constructor( dataTemplate: IPlatformData, - stateTemplate: ITHPlatformState | IBeiJingPlatformState, + stateTemplate: ITHPlatformState | IGPPlatformState, styleType: StyleType, ) { super(JlPlatform.Type, { dataTemplate, stateTemplate }); diff --git a/src/packages/Section/bjrtss/Section.ts b/src/packages/Section/GPSection.ts similarity index 71% rename from src/packages/Section/bjrtss/Section.ts rename to src/packages/Section/GPSection.ts index 55c8021..e706754 100644 --- a/src/packages/Section/bjrtss/Section.ts +++ b/src/packages/Section/GPSection.ts @@ -1,7 +1,7 @@ import { - Section as SectionBase, + JlSection as SectionBase, SectionDisplayConfig, -} from '../common/Section'; +} from './common/Section'; const displayConfig: SectionDisplayConfig = { lineColor: '#5578b6', @@ -16,4 +16,4 @@ export class Section extends SectionBase { } } -export { SectionTemplate } from '../common/Section'; +export { SectionTemplate } 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; diff --git a/src/packages/Section/common/SectionDrawAssistant.ts b/src/packages/Section/common/SectionDrawAssistant.ts index bb0a1aa..a10aa0f 100644 --- a/src/packages/Section/common/SectionDrawAssistant.ts +++ b/src/packages/Section/common/SectionDrawAssistant.ts @@ -46,7 +46,7 @@ import { import { Turnout } from 'src/packages/Turnout/Turnout'; import { AxleCounting } from 'src/packages/AxleCounting/AxleCounting'; import { DevicePort } from 'common/common'; -import { Section } from '../bjrtss/Section'; +import { Section } from '../GPSection'; export class SectionDraw extends GraphicDrawAssistant< SectionTemplate, diff --git a/src/packages/Station/GPStation.ts b/src/packages/Station/GPStation.ts index 196d4a2..bc3c0e6 100644 --- a/src/packages/Station/GPStation.ts +++ b/src/packages/Station/GPStation.ts @@ -1,5 +1,5 @@ import { GraphicState } from 'jl-graphic'; -import { JlStation } from './JlStation'; +import { JlStation } from './common/JlStation'; import { StyleType } from 'common/common'; export interface IGPStationState extends GraphicState { diff --git a/src/packages/Station/THStation.ts b/src/packages/Station/THStation.ts index d4c7716..9d0c88e 100644 --- a/src/packages/Station/THStation.ts +++ b/src/packages/Station/THStation.ts @@ -1,6 +1,6 @@ import { GraphicState } from 'jl-graphic'; -import { ConstrolGraphic, JlStation } from './JlStation'; -import { THConsts } from './StationConfig'; +import { ConstrolGraphic, JlStation } from './common/JlStation'; +import { THConsts } from './common/StationConfig'; import { StyleType } from 'common/common'; export interface ITHStationState extends GraphicState { diff --git a/src/packages/Station/JlStation.ts b/src/packages/Station/common/JlStation.ts similarity index 100% rename from src/packages/Station/JlStation.ts rename to src/packages/Station/common/JlStation.ts diff --git a/src/packages/Station/StationConfig.ts b/src/packages/Station/common/StationConfig.ts similarity index 100% rename from src/packages/Station/StationConfig.ts rename to src/packages/Station/common/StationConfig.ts diff --git a/src/packages/Station/StationDrawAssistant.ts b/src/packages/Station/common/StationDrawAssistant.ts similarity index 100% rename from src/packages/Station/StationDrawAssistant.ts rename to src/packages/Station/common/StationDrawAssistant.ts diff --git a/src/packages/Station/StationTemplate.ts b/src/packages/Station/common/StationTemplate.ts similarity index 89% rename from src/packages/Station/StationTemplate.ts rename to src/packages/Station/common/StationTemplate.ts index 18530cc..56f0e9c 100644 --- a/src/packages/Station/StationTemplate.ts +++ b/src/packages/Station/common/StationTemplate.ts @@ -1,8 +1,8 @@ import { JlGraphicTemplate } from 'jl-graphic'; import { JlStation } from './JlStation'; import { IStationData } from './StationConfig'; -import { THStation, ITHStationState } from './THStation'; -import { GPStation, IGPStationState } from './GPStation'; +import { THStation, ITHStationState } from '../THStation'; +import { GPStation, IGPStationState } from '../GPStation'; import { StyleType } from 'common/common'; export class StationTemplate extends JlGraphicTemplate {