import { calculateMirrorPoint, JlGraphic, distance2, getRectangleCenter, VectorText } from 'jl-graphic'; import { Container, Point, Graphics, Color, Rectangle } from 'pixi.js'; import { JlSection } from '../../Section/common/Section.js'; import { JlStation } from '../../Station/common/JlStation.js'; //子元素--矩形 class RectGraphic extends Container { rect; stateFillColor; constructor() { super(); this.rect = new Graphics(); this.addChild(this.rect); } draw(platformConsts) { const rect = this.rect; const fillColor = this.stateFillColor || platformConsts.noTrainStop; rect .clear() .lineStyle(platformConsts.lineWidth, new Color(fillColor)) .beginFill(fillColor, 1) .drawRect(0, 0, platformConsts.width, platformConsts.height).endFill; rect.pivot = getRectangleCenter(new Rectangle(0, 0, platformConsts.width, platformConsts.height)); } clear() { this.rect.clear(); } } //子元素--门 class DoorGraphic extends Container { doorGraphic; doorCloseGraphic; stateFillColor; constructor() { super(); this.doorGraphic = new Graphics(); this.doorCloseGraphic = new Graphics(); this.addChild(this.doorGraphic); this.addChild(this.doorCloseGraphic); } draw(platformConsts) { const doorConsts = platformConsts.doorGraphic; const doorGraphic = this.doorGraphic; const doorCloseGraphic = this.doorCloseGraphic; const lineColor = this.stateFillColor || doorConsts.doorGreen; doorGraphic .clear() .lineStyle(platformConsts.lineWidth, new Color(lineColor)) .moveTo(-platformConsts.width / 2 - platformConsts.lineWidth / 2, 0) .lineTo(-doorConsts.doorOpenSpacing, 0) .moveTo(doorConsts.doorOpenSpacing, 0) .lineTo(platformConsts.width / 2 + platformConsts.lineWidth / 2, 0); //屏蔽门闭合 doorCloseGraphic .clear() .lineStyle(platformConsts.lineWidth, new Color(lineColor)) .moveTo(-doorConsts.doorOpenSpacing, 0) .lineTo(doorConsts.doorOpenSpacing, 0); } clear() { this.doorGraphic.clear(); this.doorCloseGraphic.clear(); } } //子元素--字符 class CodeGraphic extends Container { character = new VectorText(''); //扣车H runLevel = new VectorText(''); //运行等级 runTime = new VectorText(''); //运行时间 stopTime = new VectorText(''); //停站时间 circle = new Graphics(); constructor(platformConsts) { super(); this.addChild(this.character); this.addChild(this.runLevel); this.addChild(this.circle); this.addChild(this.stopTime); this.addChild(this.runTime); const codeConsts = platformConsts.codeGraphic; this.character.setVectorFontSize(codeConsts.besideFontSize); this.runLevel.setVectorFontSize(codeConsts.besideFontSize); this.stopTime.setVectorFontSize(codeConsts.besideFontSize); this.runTime.setVectorFontSize(codeConsts.besideFontSize); } draw(platformConsts) { const codeConsts = platformConsts.codeGraphic; //扣车 const character = this.character; character.text = 'H'; character.anchor.set(0.5); character.position.set(-platformConsts.width / 2 - platformConsts.lineWidth / 2 - (codeConsts.besideSpacing * 2) / 3, (platformConsts.height * 3) / 4); character.style.fill = codeConsts.whiteNumbers; const circle = this.circle; circle .clear() .lineStyle(0.5, codeConsts.whiteCircle) .drawCircle(0, 0, codeConsts.circleRadius); circle.position.set(-platformConsts.width / 2 - platformConsts.lineWidth / 2 - (codeConsts.besideSpacing * 4) / 3, (platformConsts.height * 3) / 5); //区间运行等级状态 const runLevel = this.runLevel; runLevel.anchor.set(0.5); runLevel.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + 3 * codeConsts.besideSpacing, -codeConsts.besideSpacing); runLevel.style.fill = codeConsts.whiteNumbers; //区间运行时间 const runTime = this.runTime; runTime.anchor.set(0.5); runTime.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + codeConsts.besideSpacing, -codeConsts.besideSpacing); runTime.style.fill = codeConsts.whiteNumbers; //停站时间 const stopTime = this.stopTime; stopTime.anchor.set(0.5); stopTime.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + codeConsts.besideSpacing, codeConsts.besideSpacing); stopTime.style.fill = codeConsts.whiteNumbers; character.visible = false; circle.visible = false; runLevel.visible = false; stopTime.visible = false; runTime.visible = false; } clear() { this.character.destroy(); } } //子元素--站台旁菱形图标 class LozengeGraphic extends Container { lozenge; constructor() { super(); this.lozenge = new Graphics(); this.addChild(this.lozenge); } draw(platformConsts) { const LozengeConsts = platformConsts.lozengeGraphic; const lozenge = this.lozenge; lozenge .clear() .lineStyle(1, new Color(LozengeConsts.lozengeRed)) .beginFill(LozengeConsts.lozengeRed, 1) .drawRect(0, 0, platformConsts.height / 4, platformConsts.height / 4) .endFill(); const rect = new Rectangle(0, 0, platformConsts.height / 4, platformConsts.height / 4); lozenge.pivot = getRectangleCenter(rect); lozenge.rotation = Math.PI / 4; lozenge.visible = false; } clear() { this.lozenge.clear(); } } class DoorCodeLozenge extends Container { platformConsts; doorGraphic; lozengeGraphic; codeGraphic; constructor(platformConsts) { super(); this.platformConsts = platformConsts; this.doorGraphic = new DoorGraphic(); this.addChild(this.doorGraphic); this.lozengeGraphic = new LozengeGraphic(); this.addChild(this.lozengeGraphic); this.codeGraphic = new CodeGraphic(this.platformConsts); this.addChild(this.codeGraphic); } draw(hasDoor, direction) { const platformConsts = this.platformConsts; this.doorGraphic.clear(); if (hasDoor) { const doorConsts = platformConsts.doorGraphic; this.doorGraphic.draw(platformConsts); this.doorGraphic.position.set(0, -platformConsts.height / 2 - doorConsts.doorPlatformSpacing); } const codeConsts = platformConsts.codeGraphic; this.codeGraphic.draw(platformConsts); this.codeGraphic.position.set(0, 0); const LozengeConsts = platformConsts.lozengeGraphic; this.lozengeGraphic.draw(platformConsts); this.lozengeGraphic.position.set(0, -platformConsts.height / 2 - LozengeConsts.doorPlatformSpacing - platformConsts.height / 3); if (direction == 'down') { this.doorGraphic.position.copyFrom(calculateMirrorPoint(new Point(0, 0), this.doorGraphic.position)); this.lozengeGraphic.position.copyFrom(calculateMirrorPoint(new Point(0, 0), this.lozengeGraphic.position)); const psChange = [ this.codeGraphic.character, this.codeGraphic.runLevel, this.codeGraphic.stopTime, this.codeGraphic.runTime, ]; psChange.forEach((g) => { if (g) { g.position.copyFrom(calculateMirrorPoint(new Point(0, 0), g.position)); } }); this.codeGraphic.circle.position.set(platformConsts.width / 2 + platformConsts.lineWidth / 2 + (codeConsts.besideSpacing * 4) / 3, (-platformConsts.height * 10) / 11); } } } class JlPlatform extends JlGraphic { static Type = 'Platform'; platformConsts; rectGraphic; constructor(platformConsts) { super(JlPlatform.Type); this.platformConsts = platformConsts; this.rectGraphic = new RectGraphic(); this.addChild(this.rectGraphic); } get datas() { return this.getDatas(); } get code() { return this.datas.code; } 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 };