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; constructor() { super(THConsts); this.doorCodeLozenge = new DoorCodeLozenge(THConsts); this.addChild(this.doorCodeLozenge); } get states() { return this.getStates(); } doRepaint() { this.rectGraphic.stateFillColor = THConsts.noTrainStop; if (this.states.trainberth) { this.rectGraphic.stateFillColor = THConsts.trainStop; } 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 doorGraphic = this.doorCodeLozenge.doorGraphic; doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen; /* if (!!station?.states.ipRtuStusDown) { doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue; } */ if (this.states.psdCut) { doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed; } super.draw(); this.doorCodeLozenge.draw(this.datas.hasdoor, this.datas.direction); //门的状态 if (this.datas.hasdoor) { if (this.states.psdOpen) { doorGraphic.doorCloseGraphic.visible = false; } else { doorGraphic.doorCloseGraphic.visible = true; } } if (this.states.emergstop) { this.doorCodeLozenge.lozengeGraphic.lozenge.visible = true; } else { this.doorCodeLozenge.lozengeGraphic.lozenge.visible = false; } //扣车 const codeGraphic = this.doorCodeLozenge.codeGraphic; if (this.states.upHold || this.states.upOccHold || this.states.downHold || this.states.downOccHold) { codeGraphic.character.text = 'H'; codeGraphic.character.visible = true; codeGraphic.circle.visible = true; //上行扣车 if (this.states.upHold) { codeGraphic.character.style.fill = THConsts.codeGraphic.HCharYellow; } if (this.states.upOccHold) { codeGraphic.character.style.fill = THConsts.codeGraphic.HCharWhite; } if (this.states.upHold && this.states.upOccHold) { codeGraphic.character.style.fill = THConsts.codeGraphic.HCharRed; } //下行扣车 if (this.states.downHold) { codeGraphic.character.style.fill = THConsts.codeGraphic.HCharYellow; } if (this.states.downOccHold) { codeGraphic.character.style.fill = THConsts.codeGraphic.HCharWhite; } if (this.states.downHold && this.states.downOccHold) { codeGraphic.character.style.fill = THConsts.codeGraphic.HCharRed; } } //运行等级 if (this.states.nextSectionRunLevel) { codeGraphic.runLevel.visible = false; codeGraphic.runLevel.text = this.states.nextSectionRunLevel; } //运行时间 if (this.states.nextSectionRunTime) { codeGraphic.runTime.visible = true; codeGraphic.runTime.text = this.states.nextSectionRunTime; } //停站时间 if (this.states.stopTime) { codeGraphic.stopTime.visible = true; 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 };