/* * 信号机 */ import ESigPost from './ESigPost'; import ESigLamp from './ESigLamp'; import ESigAuto from './ESigAuto'; import ESigRoute from './ESigRoute'; import ESigButton from './ESigButton'; import ESigDelay from './ESigDelay'; import ESigName from './ESigName'; import Group from 'zrender/src/container/Group'; class Signal extends Group { constructor(model, style) { super(); this._code = model.code; this._type = model._type; this.model = model; this.style = style; this.count = parseInt(model.lampPositionType); this.lamps = new Array(this.count); this.zlevel = model.zlevel; this.z = 7; this.create(); this.transformRotation(this); this.setState(model); } create() { const model = this.model; const style = this.style; const drict = this.model.directionType == '01' ? -1 : 1; // 朝向 左:右 const posit = this.model.positionType == '01' ? -1 : 1; // 位置 上:下 // 信号机高柱矮柱 this.sigPost = new ESigPost({ zlevel: this.zlevel, z: this.z, style: style, drict: drict, type: model.lampPostType, x: model.position.x, y: model.position.y + posit * (style.Signal.signalDistance + style.Section.line.width + style.Signal.lamp.signalR) }); // 信号灯 const endPoint = this.sigPost.getLampPosition(model.lampPostType); this.lamps = []; for (let i = 0; i < this.count; i++) { const lamp = new ESigLamp({ zlevel: this.zlevel, z: this.z, style: style, index: i + 1, drict: drict, x: endPoint.x + i * drict * style.Signal.lamp.signalR * 2, y: endPoint.y, originX: model.position.x, originY: model.position.y }); this.lamps.push(lamp); } // 信号机名称 const sigNameX = model.position.x + model.namePosition.x; const sigNameY = model.position.y + posit * (style.Signal.signalDistance + style.Section.line.width + style.Signal.lamp.signalR * 2 + model.namePosition.y); this.sigName = new ESigName({ zlevel: this.zlevel, z: this.z, silent: false, isNoRotation: style.Signal.text.isNoRotation, style: style, x: sigNameX, y: sigNameY, text: model.name, fontWeight: 'normal', fontSize: style.Signal.text.signalTextFontSize, fontFamily: style.textFontFormat, textFill: style.Signal.text.signalDefaultTextColor, textAlign: 'middle', textVerticalAlign: posit == 1 ? 'top' : 'bottom' }); // 自动进路 const sigRouteH = style.Signal.route.signalRouteDirection ? this.count * style.Signal.lamp.signalR * 2 : -style.Signal.lamp.signalR * 2; const sigRouteX = endPoint.x + (style.Signal.route.signalRouteOffset.x + sigRouteH) * drict; const sigRouteY = endPoint.y + (style.Signal.route.signalRouteOffset.y); this.sigRoute = new ESigRoute({ zlevel: this.zlevel, z: this.z, style: style, x: sigRouteX, y: sigRouteY, drict: drict }); // 自动通过 const sigAutoH = style.Signal.auto.signalAutoDirection ? this.count * style.Signal.lamp.signalR * 2 : -style.Signal.lamp.signalR * 2; const sigAutoX = endPoint.x + (style.Signal.auto.signalAutoOffset.x + sigAutoH) * drict; const sigAutoY = endPoint.y + (style.Signal.auto.signalAutoOffset.y); this.sigAuto = new ESigAuto({ zlevel: this.zlevel, z: this.z, style: style, count: this.count, drict: drict, x: sigAutoX, y: sigAutoY, width: style.Signal.signalAutoWidth, fill: style.Signal.lamp.signalAutoRoute, lineWidth: 0.6, stroke: style.sidelineColor }); // 延迟解锁 const sigDelayH = style.Signal.delay.signalDelayDirection ? this.count * style.Signal.lamp.signalR * 2 : -style.Signal.lamp.signalR * 2; const sigDelayX = endPoint.x + (style.Signal.delay.signalDelayOffset.x + sigDelayH) * drict; const sigDelayY = endPoint.y - (style.Signal.delay.signalDelayOffset.y) * posit; this.sigDelay = new ESigDelay({ zlevel: this.zlevel, z: this.z, style: style, x: sigDelayX, y: sigDelayY, fontWeight: 'bold', fontSize: style.Signal.delay.signalDelayTextFontSize, fontFamily: style.textFontFormat, text: this.model.delayCount || '0', textFill: style.Signal.delay.signalDelayTextColor, textAlign: drict > 0 ? 'right' : 'left', textVerticalAlign: 'middle' }); // 信号灯按钮 this.sigButton = new ESigButton({ zlevel: this.zlevel, z: this.z, style: style, posit: posit, show: model.buttonShow, x: model.buttonPosition.x, y: model.buttonPosition.y - posit * (style.Signal.button.signalButtonDistance + style.Signal.lamp.signalR * 2) }); this.add(this.sigPost); this.lamps.forEach(lamp => { this.add(lamp); }); this.model.nameShow ? this.add(this.sigName) : null; this.add(this.sigAuto); this.add(this.sigRoute); this.add(this.sigDelay); // this.add(this.sigButton); } // 整体旋转信号灯 transformRotation(device) { if (this.model.rotate) { device.eachChild(item => { if (item instanceof Group) { this.transformRotation(item); } else if (item && item.model && item.model.isNoRotation) { item.origin = [this.model.position.x, this.model.position.y]; item.rotation = -Math.PI / 180 * Number(this.model.rotate); item.dirty(); } }); } } // 关闭 close() { if (this.count == 2 && this.model.lightType == '01') { // 双灯 物理点灯 if (this.lamps[0]) { this.lamps[0].setStop(false); this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); } if (this.lamps[1]) { this.lamps[1].setStop(false); this.lamps[1].setColor(this.style.backgroundColor); } } else if (this.count == 2 && this.model.lightType == '02') { // 双灯 逻辑点灯 if (this.lamps[0]) { this.lamps[0].setStop(true); this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); } if (this.lamps[1]) { this.lamps[1].setStop(true); this.lamps[1].setColor(this.style.backgroundColor); } } else if (this.count == 1 && this.model.lightType == '01') { // 单灯 物理点灯 if (this.lamps[0]) { this.lamps[0].setStop(false); if (this.model.useType == '05') { this.lamps[0].setColor(this.style.Signal.lamp.signalLampBlueColor); } else { this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); } } } else if (this.count == 1 && this.model.lightType == '02') { // 单灯 逻辑点灯 if (this.lamps[0]) { this.lamps[0].setStop(true); if (this.model.useType == '05') { this.lamps[0].setColor(this.style.Signal.lamp.signalLampBlueColor); } else { this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); } } } else if (this.count == 1) { if (this.lamps[0]) { if (this.model.useType == '05') { this.lamps[0].setColor(this.style.Signal.lamp.signalLampBlueColor); } else { this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); } } } } // 开放 open() { if (this.count == 2 && this.model.lightType == '01' && this.model.switchLocateType == '01') { // 双灯 物理点灯 道岔定位 if (this.lamps[0]) { this.lamps[0].setStop(false); this.lamps[0].setColor(this.style.Signal.lamp.signalLampGreenColor); } if (this.lamps[1]) { this.lamps[1].setStop(false); this.lamps[1].setColor(this.style.backgroundColor); } } else if (this.count == 2 && this.model.lightType == '02' && this.model.switchLocateType == '01') { // 双灯 逻辑点灯 道岔定位 if (this.lamps[0]) { this.lamps[0].setStop(true); this.lamps[0].setColor(this.style.Signal.lamp.signalLampGreenColor); } if (this.lamps[1]) { this.lamps[1].setStop(true); this.lamps[1].setColor(this.style.backgroundColor); } } else if (this.count == 2 && this.model.lightType == '01' && this.model.switchLocateType == '02') { // 双灯 物理点灯 道岔反位 if (this.lamps[0]) { this.lamps[0].setStop(false); this.lamps[0].setColor(this.style.backgroundColor); } if (this.lamps[1]) { this.lamps[1].setStop(false); this.lamps[1].setColor(this.style.Signal.lamp.signalLampYellowColor); } } else if (this.count == 2 && this.model.lightType == '02' && this.model.switchLocateType == '02') { // 双灯 逻辑点灯 道岔反位 if (this.lamps[0]) { this.lamps[0].setStop(true); this.lamps[0].setColor(this.style.backgroundColor); } if (this.lamps[1]) { this.lamps[1].setStop(true); this.lamps[1].setColor(this.style.Signal.lamp.signalLampYellowColor); } } else if (this.count == 1 && this.model.lightType == '01' && this.model.switchLocateType == '02') { // 单灯 物理点灯 允许调车 if (this.lamps[0]) { this.lamps[0].setStop(false); // 出站信号机/阻隔信号机 if (['02', '06'].includes(this.model.useType)) { this.lamps[0].setColor(this.style.Signal.lamp.signalLampGreenColor); } else { this.lamps[0].setColor(this.style.Signal.lamp.signalLampWhiteColor); } } } else if (this.count == 1 && this.model.lightType == '01' && this.model.switchLocateType == '01') { if (this.lamps[0]) { this.lamps[0].setStop(false); this.lamps[0].setColor(this.style.Signal.lamp.signalLampGreenColor); } } else if (this.count == 1 && this.model.lightType == '02' && this.model.switchLocateType == '02') { if (this.lamps[0]) { this.lamps[0].setStop(true); this.lamps[0].setColor(this.style.Signal.lamp.signalLampGreenColor); } } else if (this.count == 1 && this.model.lightType == '02' && this.model.switchLocateType == '01' ) { if (this.lamps[0]) { this.lamps[0].setStop(true); this.lamps[0].setColor(this.style.Signal.lamp.signalLampGreenColor); } } } // 列车进路 trainRoute() { if (this.count == 1) { /** 单灯 列兼调信号*/ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.lamp.signalLampYellowColor); } } // 调车进路 shuntRoute() { if (this.count == 1) { /** 单灯 列兼调信号*/ /** 单灯 阻挡兼调车信号*/ this.lamps[0] && this.lamps[0].setColor(this.style.Signal.lamp.signalLampWhiteColor); } } // 引导 guid() { if (this.count == 2 && this.model.lightType == '01') { // 双灯 物理点灯 允许引导信号 if (this.lamps[0]) { this.lamps[0].setStop(false); this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); } if (this.lamps[1]) { this.lamps[1].setStop(false); this.lamps[1].setColor(this.style.Signal.lamp.signalLampYellowColor); } } } // 封锁 block() { if (this.count == 1) { this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); // this.siglamp.setNameBorder(1) } this.sigName.setColor(this.style.Signal.signalTextBlockColor); } // 功能封锁 functionBlock() { if (this.count == 1) { this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); // this.siglamp.setRectBlockByIndex(1, true); } } // 信号保护区段监视状态显示 signalblock() { if (this.count == 1) { this.lamps[0].setColor(this.style.Signal.lamp.signalLampRedColor); this.sigName.setColor(this.style.Signal.lamp.signalLampGreenColor); } } // 故障 fault() { if (this.count == 2 && this.model.lightType == '01') { // 双灯 物理点灯 if (this.lamps[0]) { this.lamps[0].setStop(false); this.lamps[0].setColor(this.style.Signal.lamp.signalLampBlueColor); } if (this.lamps[1]) { this.lamps[1].setStop(false); this.lamps[1].setColor(this.style.Signal.lamp.signalLampBlueColor); } } } // 物理点灯 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.sigAuto.setColor(this.style.Signal.auto.signalAutoRoute); } // 信号机进路自动触发模式状态类型 setAutoAccessOpen() { if (this.model.atsAutoTriggerShow) { this.sigAuto.show(); } else { this.sigAuto.hide(); } this.sigAuto.setColor(this.style.Signal.auto.signalAutoTrigger); } // 设置自动信号模式状态类型 setAutoSignalOpen() { this.sigRoute.show(); } // 隐藏自动信号和自动进路 setAutoClose() { this.sigAuto.hide(); this.sigAuto.setColor(this.style.backgroundColor); this.sigRoute.hide(); } // 自动信号和自动进路开始动画 setAutoFlicker() { this.sigAuto.arrowsAnimation(); } // 设置延时解锁 setDelayUnlock() { this.sigDelay.show(); } // 恢复状态 recover() { this.sigDelay.hide(); this.sigAuto.animationRecover(); this.sigName.setColor(this.style.Signal.text.signalDefaultTextColor); } setState(model) { this.recover(); /** 设置状态 (点灯类型)*/ switch (model.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 (model.natureType) { case '01': this.trainRoute(); break; // 列车进路 case '02': this.shuntRoute(); break; // 调车进路 } /** 设置点灯类型*/ switch (model.lightType) { case '01': this.logicalLight(); break; // 设置逻辑点灯 case '02': this.physicsLight(); break; // 设置物理点灯 } /** 设置自动类型*/ switch (model.autoType) { case '01': this.setAutoClose(); break; // 隐藏 隐藏自动信号和自动进路 case '02': this.setAutoSignalOpen(); break; // 显示 设置自动信号模式状态类型 case '03': this.setAutoRouteOpen(); break; // 显示 设置自动进路模式状态类型 case '04': this.setAutoAccessOpen(); break; // 显示 信号机进路自动触发模式状态类型 } /** 延时解锁*/ model.delayType = '02'; switch (model.delayType) { case '01': break; // 未延时解锁 case '02': break; // 人工闭塞延时解锁 case '03': break; // 自动闭塞延时解锁 } /** 信号机进路办理,先停止动画,再判断当前颜色是否闪烁*/ if (model.routeSetting && (model.autoType == '03' || model.autoType == '04')) { this.setAutoFlicker(); } } getBoundingRect() { return this.sigPost.getBoundingRect(); } getShapeTipPoint(val) { if (val == '1' || val == '2') { // return this.sigButton.getShapeTipPoint(val); } else { // return this.siglamp.getShapeTipPoint(val); } } } export default Signal;