import * as zrUtil from 'zrender/src/core/util'; import * as matrix from 'zrender/src/core/matrix'; import deviceType from '../constant/deviceType'; import deviceRender from '../constant/deviceRender'; import Vue from 'vue'; import { deepClone } from '@/utils/index'; export function createTransform(opts) { let transform = matrix.create(); transform = matrix.scale(matrix.create(), transform, [opts.scaleRate, opts.scaleRate]); transform = matrix.translate(matrix.create(), transform, [-opts.offsetX, -opts.offsetY]); return transform; } export function createTransform1(opts) { let transform = matrix.create(); transform = matrix.scale(matrix.create(), transform, [opts.scaleRateX, opts.scaleRateY]); transform = matrix.translate(matrix.create(), transform, [-opts.offsetX, -opts.offsetY]); return transform; } export function createBoundingRect(view) { const rect = view.getBoundingRect().clone(); const scale = view.scale[0]; const offsetX = view.position[0]; const offsetY = view.position[1]; rect.x = rect.x * scale + offsetX; rect.y = rect.y * scale + offsetY; rect.width = rect.width * scale; rect.height = rect.height * scale; return rect; } export function calculateDCenter(viewRect, zrbound) { var dx = (zrbound.width - viewRect.width) / 2 - viewRect.x; var dy = 0; return { dx: dx, dy: dy }; } export function deviceFactory(type, elem, showConfig) { return {...deviceRender[type], ...elem, ...showConfig}; } export function createDevice(type, elem, propConvert, showConfig) { const device = deviceFactory(type, Object.assign(elem, { _type: type } ), showConfig); return propConvert ? propConvert.initPrivateProps(device) : device; } export function parser(data, skinCode, showConfig) { var mapDevice = {}; var propConvert = skinCode ? Vue.prototype.$theme.loadPropConvert(skinCode) : null; if (data) { zrUtil.each(data.stationList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Station, elem, propConvert, showConfig); }, this); zrUtil.each(data.sectionList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Section, elem, propConvert, showConfig); elem = propConvert.initPrivateProps(elem); }, this); zrUtil.each(data.sectionList || [], elem => { if (elem.type == '02' || elem.type == '03') { mapDevice[elem.code].parentName = mapDevice[elem.parentCode] ? mapDevice[elem.parentCode].name : ''; } else if (elem.type == '01' && (elem.standTrack || elem.reentryTrack)) { mapDevice[elem.belongStation].sectionCode = elem.code; } }, this); zrUtil.each(data.signalList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Signal, elem, propConvert, showConfig); elem = propConvert.initPrivateProps(elem); }, this); zrUtil.each(data.stationStandList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.StationStand, elem, propConvert, showConfig); }, this); zrUtil.each(data.stationControlList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.StationControl, elem, propConvert, showConfig); }, this); zrUtil.each(data.counterList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.StationCounter, elem, propConvert, showConfig); }, this); zrUtil.each(data.delayShowList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.StationDelayUnlock, elem, propConvert, showConfig); }, this); zrUtil.each(data.lineList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Line, elem, propConvert, showConfig); }, this); zrUtil.each(data.espList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Esp, elem, propConvert, showConfig); }, this); // psd在stand后处理 -便于在stand上挂载关系 zrUtil.each(data.psdList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Psd, elem, propConvert, showConfig); mapDevice[elem.standCode].psdCode = elem.code; }, this); zrUtil.each(data.textList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Text, elem, propConvert, showConfig); }, this); zrUtil.each(data.zcList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.ZcControl, elem, propConvert, showConfig); }, this); zrUtil.each(data.lcList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.LcControl, elem, propConvert, showConfig); }, this); zrUtil.each(data.tempSpeedLimitList || [], elem => { // 全线临时限速列表 mapDevice[elem.code] = createDevice(deviceType.LimitControl, elem, propConvert, showConfig); }, this); zrUtil.each(data.resourceList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Resource, elem, propConvert, showConfig); }, this); zrUtil.each(data.trainList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Train, elem, propConvert, showConfig); }, this); zrUtil.each(data.Line || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Line, elem, propConvert, showConfig); }, this); zrUtil.each(data.Text || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Text, elem, propConvert, showConfig); }, this); zrUtil.each(data.cycleButtonList || [], elem => { // 自动折返列表 mapDevice[elem.code] = createDevice(deviceType.AutoTurnBack, elem, propConvert, showConfig); }, this); zrUtil.each(data.axleCounterResetButtonList || [], elem => { // 计轴复位列表 mapDevice[elem.code] = createDevice(deviceType.AxleReset, elem, propConvert, showConfig); }, this); zrUtil.each(data.totalGuideLockButtonVOList || [], elem => { // 引导总锁列表 mapDevice[elem.code] = createDevice(deviceType.GuideLock, elem, propConvert, showConfig); mapDevice[elem.stationCode].guideLockCode = elem.code; // 保证处理车站列表在处理引导总锁列表之前 }, this); zrUtil.each(data.automaticRouteButtonList || [], elem => { // 自动进路列表 mapDevice[elem.code] = createDevice(deviceType.AutomaticRoute, elem, propConvert, showConfig); }, this); zrUtil.each(data.outerFrameList || [], elem => { // 矩形框列表 mapDevice[elem.code] = createDevice(deviceType.OutFrame, elem, propConvert, showConfig); }, this); zrUtil.each(data.splitStationList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.SplitStation, elem, propConvert, showConfig); }, this); zrUtil.each(data.tbStrategyList || [], elem => { // 站后折返按钮 mapDevice[elem.code] = createDevice(deviceType.StationTurnBack, elem, propConvert, showConfig); }, this); zrUtil.each(data.arrowList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Arrow, elem, propConvert, showConfig); }, this); zrUtil.each(data.powerLineList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Power, elem, propConvert, showConfig); }, this); zrUtil.each(data.switchList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.Switch, elem, propConvert, showConfig); elem = propConvert.initPrivateProps(elem); const cnodeSection = mapDevice[mapDevice[elem.code].sectionACode]; const lnodeSection = mapDevice[mapDevice[elem.code].sectionBCode]; const rnodeSection = mapDevice[mapDevice[elem.code].sectionCCode]; if (cnodeSection && lnodeSection && rnodeSection) { cnodeSection['switch'] = lnodeSection['switch'] = rnodeSection['switch'] = mapDevice[elem.code]; const sectionParent = mapDevice[cnodeSection.parentCode]; if (sectionParent) { sectionParent['switch'] = mapDevice[elem.code]; } if (cnodeSection.points[0].x == lnodeSection.points[lnodeSection.points.length - 1].x && cnodeSection.points[0].y == lnodeSection.points[lnodeSection.points.length - 1].y) { mapDevice[elem.code].intersection = { x: cnodeSection.points[0].x, y: cnodeSection.points[0].y }; mapDevice[elem.code].skew = { x: rnodeSection.points[rnodeSection.points.length - 2].x, y: rnodeSection.points[rnodeSection.points.length - 2].y }; } else if (cnodeSection.points[cnodeSection.points.length - 1].x == lnodeSection.points[0].x && cnodeSection.points[cnodeSection.points.length - 1].y == lnodeSection.points[0].y) { mapDevice[elem.code].intersection = { x: cnodeSection.points[cnodeSection.points.length - 1].x, y: cnodeSection.points[cnodeSection.points.length - 1].y }; mapDevice[elem.code].skew = { x: rnodeSection.points[1].x, y: rnodeSection.points[1].y }; } const section = mapDevice[cnodeSection.parentCode]; if (section) { mapDevice[elem.code].sectionName = section.name; mapDevice[elem.code].sectionParentCode = section.code; section['relSwitchCode'] = elem.code; } rnodeSection['layer'] = -1; } }, this); zrUtil.each(data.indicatorLightList || [], elem => { mapDevice[elem.code] = createDevice(elem.type, elem, propConvert, showConfig); if (elem.type == 'SwitchFault') { mapDevice[elem.switchCode].switchFaultCode = elem.code; // 道岔数据上关联道岔故障表示灯(需保证该数据在switchList之后处理) } }, this); zrUtil.each(data.trainWindowList || [], elem => { mapDevice[elem.code] = createDevice(deviceType.TrainWindow, elem, propConvert, showConfig); if (elem.sectionCode) { const section = mapDevice[elem.sectionCode]; if (section) { section['trainWindowCode'] = elem.code; } } }, this); } return mapDevice; } // 同步绘制数据到原始数据 export function updateForList(model, state, liststr) { const list = state.map[liststr]; if (list && list instanceof Array) { const i = list.findIndex(elem => elem.code == model.code ); if (model._dispose) { i >= 0 && list.splice(i, 1); // 删除 } else if (!list[i]) { list.push(deepClone(model)); // 新增 } else if (i >= 0) { list[i] = deepClone(model); // item map 数据 model 页面表单数据 } } else { state.map[liststr] = [model]; } } export function updateMapData(state, model) { if (state.map && model) { switch (model._type) { case deviceType.Section: updateForList(model, state, 'sectionList'); break; case deviceType.Switch: updateForList(model, state, 'switchList'); break; case deviceType.Signal: updateForList(model, state, 'signalList'); break; case deviceType.Station: updateForList(model, state, 'stationList'); break; case deviceType.StationStand: updateForList(model, state, 'stationStandList'); break; case deviceType.StationControl: updateForList(model, state, 'stationControlList'); break; case deviceType.StationCounter: updateForList(model, state, 'stationCounterList'); break; case deviceType.ZcControl: updateForList(model, state, 'zcList'); break; case deviceType.StationDelayUnlock:updateForList(model, state, 'stationDelayUnlockList'); break; case deviceType.LcControl: updateForList(model, state, 'lcList'); break; case deviceType.LimitControl: updateForList(model, state, 'tempSpeedLimitList'); break; case deviceType.Resource: updateForList(model, state, 'resourceList'); break; case deviceType.Train: updateForList(model, state, 'trainList'); break; case deviceType.TrainWindow: updateForList(model, state, 'trainWindowList'); break; case deviceType.Line: updateForList(model, state, 'lineList'); break; case deviceType.Text: updateForList(model, state, 'textList'); break; case deviceType.Psd: updateForList(model, state, 'psdList'); break; case deviceType.Esp: updateForList(model, state, 'espList'); break; case deviceType.AutoTurnBack: updateForList(model, state, 'cycleButtonList'); break; case deviceType.AxleReset: updateForList(model, state, 'axleCounterResetButtonList'); break; case deviceType.GuideLock: updateForList(model, state, 'totalGuideLockButtonVOList'); break; case deviceType.OutFrame: updateForList(model, state, 'outerFrameList'); break; case deviceType.AutomaticRoute: updateForList(model, state, 'automaticRouteButtonList'); break; case deviceType.AtsControl: updateForList(model, state, 'indicatorLightList'); break; case deviceType.CenterCommunication: updateForList(model, state, 'indicatorLightList'); break; case deviceType.ChainControl: updateForList(model, state, 'indicatorLightList'); break; case deviceType.IntersiteControl: updateForList(model, state, 'indicatorLightList'); break; case deviceType.LeuControl: updateForList(model, state, 'indicatorLightList'); break; case deviceType.LocalControl: updateForList(model, state, 'indicatorLightList'); break; case deviceType.Maintain: updateForList(model, state, 'indicatorLightList'); break; case deviceType.PowerSupply: updateForList(model, state, 'indicatorLightList'); break; case deviceType.NoOneReturn: updateForList(model, state, 'indicatorLightList'); break; case deviceType.MaintenanceLamps: updateForList(model, state, 'indicatorLightList'); break; case deviceType.ZcCommunication: updateForList(model, state, 'indicatorLightList'); break; case deviceType.FaultStatusGroup: updateForList(model, state, 'indicatorLightList'); break; case deviceType.ModeStatusGroup: updateForList(model, state, 'indicatorLightList'); break; case deviceType.LampFilament: updateForList(model, state, 'indicatorLightList'); break; case deviceType.ReturnModeGroup: updateForList(model, state, 'indicatorLightList'); break; case deviceType.ControlSwitch: updateForList(model, state, 'indicatorLightList'); break; case deviceType.Axle: updateForList(model, state, 'indicatorLightList'); break; case deviceType.SplitStation: updateForList(model, state, 'splitStationList'); break; case deviceType.SwitchFault: updateForList(model, state, 'indicatorLightList'); break; case deviceType.Arrow: updateForList(model, state, 'arrowList'); break; case deviceType.Power: updateForList(model, state, 'powerLineList'); break; case deviceType.StationTurnBack : updateForList(model, state, 'tbStrategyList'); break; } } }