/* * 信号机 */ import ESigPost from './element/ESigPost'; import ESigLmap from './element/ESigLmap'; import ESigAuto from './element/ESigAuto'; import ESigDrict from './element/ESigDrict'; import ESigButton from './element/ESigButton'; import ETextName from './element/ETextName'; import Group from 'zrender/src/container/Group'; import { arrows } from './libs/ShapePoints'; class Signal extends Group { constructor({ _code, _type, zlevel, model, state }, style) { super(); this._code = _code; this._type = _type; this.zlevel = zlevel; this.model = model; this.state = state; this.style = style; this.count = parseInt(model.lampPositionType); this.lamps = new Array(this.count); this.create(); this.setState(state); } create() { const drict = this.model.directionType == '01' ? -1 : 1; // 朝向 左:右 const posit = this.model.positionType == '01' ? -1 : 1; // 位置 上:下 // 信号机高柱矮柱 this.sigPost = new ESigPost({ zlevel: this.zlevel, z: 1, style: this.style, drict: drict, type: this.model.lampPostType, x: this.model.position.x, y: this.model.position.y + posit * (this.style.Signal.signalDistance + this.style.Section.sectionWidth + this.style.Signal.signalR) }); // 信号灯 const nextPosition = this.sigPost.getLampPosition(this.model.lampPostType); this.lamps = []; for (let i = 0; i < this.count; i++) { const lamp = new ESigLmap({ zlevel: this.zlevel, z: 1, style: this.style, index: i + 1, drict: drict, x: nextPosition.x + i * drict * this.style.Signal.signalR * 2, y: nextPosition.y, originX: this.model.position.x, originY: this.model.position.y }); this.lamps.push(lamp); } // 信号机名称 this.sigName = new ETextName({ zlevel: this.zlevel, z: 1, style: this.style, x: this.model.position.x + this.model.namePosition.x, y: this.model.position.y + posit * (this.style.Signal.signalDistance + this.style.Section.sectionWidth + this.style.Signal.signalR * 2 + this.model.namePosition.y), text: this.model.name, textFont: `bold ${this.style.Signal.signalTextFontSize} px ${this.style.textFontFormat}`, textFill: this.style.Signal.sigTextGreen, textAlign: 'middle', textVerticalAlign: posit == 1 ? 'top' : 'bottom' }); // 三角方向 this.sigDrict = new ESigDrict({ zlevel: this.zlevel, z: 1, style: this.style, x: nextPosition.x - drict * (this.count * this.style.Signal.signalR * 2), y: nextPosition.y, drict: drict }); // 自动进路 const x = nextPosition.x + drict * this.count * this.style.Signal.signalR * 0.8 + drict * (this.count * this.style.Signal.signalR + this.style.Signal.signalLampStandardWidth) * 2; const y =nextPosition.y - this.style.Signal.signalLampStandardWidth; const point = arrows(x, y, this.style.Signal.signalSigAutoWidt, this.style.Signal.signalR * 0.8); this.sigAuto = new ESigAuto({ zlevel: this.zlevel, z: 1, style: this.style, count: this.count, drict: drict, point: point, x: nextPosition.x + drict * this.count * this.style.Signal.signalR * 0.8, y: nextPosition.y, width: this.style.Signal.signalSigAutoWidth, fill: this.style.Signal.signalLampGreenColor, lineWidth: 0.6, stroke: this.style.sidelineColor }); // 延迟解锁 this.sigDelay = new ETextName({ zlevel: this.zlevel, z: 1, style: this.style, x: nextPosition.x + drict * this.count * this.style.Signal.signalR * 3, y: nextPosition.y, text: this.state.delayCount || '0', textFont: `bold ${this.style.Signal.signalDelayTextFontSize} px ${this.style.textFontFormat}`, textFill: this.style.Signal.signalTextRed, textAlign: drict > 0 ? 'right' : 'left', textVerticalAlign: 'middle' }); // 信号灯按钮 this.sigButton = new ESigButton({ zlevel: this.zlevel, z: 1, style: this.style, posit: posit, show: this.model.buttonShow, x: this.model.buttonPosition.x, y: this.model.buttonPosition.y - posit * (this.style.Signal.signalButtonDistance + this.style.Signal.signalR * 2) }); this.add(this.sigPost); this.lamps.forEach(lamp => { this.add(lamp); }); this.add(this.sigName); this.add(this.sigAuto); this.add(this.sigDrict); this.add(this.sigDelay); // this.add(this.sigButton); } // 关闭 close() { if (this.count === 1) { if (this.model.useType === '05') { /** 单灯 调车信号机*/ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampBlueColor); } else { /** 单灯 出站信号机 */ /** 单灯 阻挡信号机*/ /** 单灯 阻挡兼调车信号 */ /** 单灯 列兼调信号机 */ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampRedColor); } } } // 开放 open() { if (this.count === 1) { /** 单灯 出站信号机*/ /** 单灯 阻隔信号机*/ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampGreenColor); } } // 列车进路 trainRoute() { if (this.count === 1) { /** 单灯 列兼调信号*/ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampYellowColor); } } // 调车进路 shuntRoute() { if (this.count === 1) { /** 单灯 列兼调信号*/ /** 单灯 阻挡兼调车信号*/ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampWhiteColor); } } // 引导 guid() { } // 封锁 block() { this.lamps[0] && this.lamps[0].setColor(this.style.Signal.signalLampRedColor); this.sigName.setColor(this.style.Signal.sectionBlockTextColor); } // 功能封锁 functionBlock() { } // 信号保护区段监视状态显示 signalblock() { } // 故障 fault() { } // 物理点灯 logicalLight() { this.lamps.forEach(lamp => { lamp.setStop(false); }); } // 逻辑点灯 physicsLight() { this.lamps.forEach(lamp => { lamp.setStop(true); }); } // 设置自动进路模式状态类型 setAutoRouteOpen() { if (this.model.linkageAutoRouteShow) { this.sigAuto.show(); } else { this.sigAuto.hide(); } this.recover(); this.sigAuto.setColor(this.style.Signal.signalLampGreenColor); } // 信号机进路自动触发模式状态类型 setAutoAccessOpen() { if (this.model.atsAutoTriggerShow) { this.sigAuto.show(); } else { this.sigAuto.hide(); } this.recover(); this.sigAuto.setColor(this.style.Signal.signalLampYellowColor); } // 设置自动信号模式状态类型 setAutoSignalOpen() { this.sigDrict.show(); } // 隐藏自动信号和自动进路 setAutoClose() { this.sigAuto.hide(); this.sigAuto.setColor(this.style.backgroundColor); this.sigDrict.hide(); } // 自动信号和自动进路开始动画 setAutoFlicker() { this.sigAuto.arrowsAnimation(); } // 设置延时解锁 setDelayUnlock() { this.sigDelay.show(); } // 恢复状态 recover() { this.sigDelay.hide(); this.sigAuto.animationRecover(); this.sigName.setColor(this.style.Signal.signalTextGreen); } setState(state) { this.recover(); /** 设置状态 (点灯类型)*/ switch (state.status) { case '01': this.close(); break; // 关闭 case '02': this.open(); break; // 开放 case '03': this.guid(); break; // 引导 case '04': this.block(); break; // 封锁 case '05': this.fault(); break; // 故障 case '06': this.block(); break; // 功能封锁 case '07': this.signalblock(); break; // 信号保护区段检测 } /** 进路性质类型*/ switch (state.natureType) { case '01': this.trainRoute(); break; // 列车进路 case '02': this.shuntRoute(); break; // 调车进路 } /** 设置点灯类型*/ switch (state.lightType) { case '01': this.logicalLight(); break; // 设置逻辑点灯 case '02': this.physicsLight(); break; // 设置物理点灯 } /** 设置自动类型*/ switch (state.autoType) { case '01': this.setAutoClose(); break; // 隐藏 隐藏自动信号和自动进路 case '02': this.setAutoSignalOpen(); break; // 显示 设置自动信号模式状态类型 case '03': this.setAutoRouteOpen(); break; // 显示 设置自动进路模式状态类型 case '04': this.setAutoAccessOpen(); break; // 显示 信号机进路自动触发模式状态类型 } /** 延时解锁*/ state.delayType = '02'; switch (state.delayType) { case '01': break; // 未延时解锁 case '02': break; // 人工闭塞延时解锁 case '03': break; // 自动闭塞延时解锁 } /** 信号机进路办理,先停止动画,再判断当前颜色是否闪烁*/ if (state.routeSetting && (state.autoType == '03' || state.autoType == '04')) { this.setAutoFlicker(); } } getShapeTipPoint(val) { if (val === '1' || val === '2') { // return this.sigButton.getShapeTipPoint(val); } else { // return this.siglamp.getShapeTipPoint(val); } } } export default Signal;