rt-sim-training-client/src/jmapNew/utils/parser.js

368 lines
18 KiB
JavaScript
Raw Normal View History

2019-11-29 12:51:58 +08:00
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;
}
2019-11-29 12:51:58 +08:00
export function createBoundingRect(view) {
2019-12-18 09:49:44 +08:00
const rect = view.getBoundingRect().clone();
2019-11-29 12:51:58 +08:00
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 };
}
2020-03-11 10:53:09 +08:00
export function deviceFactory(type, elem, showConfig) {
return {...deviceRender[type], ...elem, ...showConfig};
2019-11-29 12:51:58 +08:00
}
2020-03-11 15:10:08 +08:00
export function createDevice(type, elem, propConvert, showConfig) {
const device = deviceFactory(type, Object.assign(elem, { _type: type } ), showConfig);
2019-11-29 12:51:58 +08:00
return propConvert ? propConvert.initPrivateProps(device) : device;
}
2020-03-11 15:10:08 +08:00
export function parser(data, skinCode, showConfig) {
2019-11-29 12:51:58 +08:00
var mapDevice = {};
var propConvert = skinCode ? Vue.prototype.$theme.loadPropConvert(skinCode) : null;
if (data) {
2020-07-16 13:35:54 +08:00
zrUtil.each(data.stationList || [], elem => {
mapDevice[elem.code] = createDevice(deviceType.Station, elem, propConvert, showConfig);
}, this);
2019-11-29 12:51:58 +08:00
zrUtil.each(data.sectionList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Section, elem, propConvert, showConfig);
2020-07-02 18:47:39 +08:00
elem = propConvert.initPrivateProps(elem);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.sectionList || [], elem => {
if (elem.type == '02' || elem.type == '03') {
2020-05-15 10:34:15 +08:00
mapDevice[elem.code].parentName = mapDevice[elem.parentCode] ? mapDevice[elem.parentCode].name : '';
} else if (elem.type == '01' && (elem.standTrack || elem.reentryTrack) && elem.belongStation) {
2020-09-28 09:42:20 +08:00
if (mapDevice[elem.belongStation]) {
mapDevice[elem.belongStation].sectionCode = elem.code;
} else {
elem.belongStation = '';
}
}
}, this);
2019-11-29 12:51:58 +08:00
zrUtil.each(data.signalList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Signal, elem, propConvert, showConfig);
2020-07-02 18:47:39 +08:00
elem = propConvert.initPrivateProps(elem);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.stationStandList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.StationStand, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
2020-01-07 10:52:44 +08:00
zrUtil.each(data.stationControlList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.StationControl, elem, propConvert, showConfig);
2020-01-07 10:52:44 +08:00
}, this);
2019-11-29 12:51:58 +08:00
zrUtil.each(data.counterList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.StationCounter, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.delayShowList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.StationDelayUnlock, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.lineList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Line, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.espList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Esp, elem, propConvert, showConfig);
}, this);
2020-07-03 13:55:04 +08:00
// psd在stand后处理 -便于在stand上挂载关系
zrUtil.each(data.psdList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Psd, elem, propConvert, showConfig);
2020-07-03 13:55:04 +08:00
mapDevice[elem.standCode].psdCode = elem.code;
}, this);
2019-11-29 12:51:58 +08:00
zrUtil.each(data.textList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Text, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.zcList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.ZcControl, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.lcList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.LcControl, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
2020-03-17 16:12:15 +08:00
zrUtil.each(data.tempSpeedLimitList || [], elem => { // 全线临时限速列表
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.LimitControl, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.resourceList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Resource, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.trainList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Train, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.Line || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Line, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
zrUtil.each(data.Text || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.Text, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
}, this);
2020-03-17 16:12:15 +08:00
zrUtil.each(data.cycleButtonList || [], elem => { // 自动折返列表
mapDevice[elem.code] = createDevice(deviceType.AutoTurnBack, elem, propConvert, showConfig);
2020-03-05 15:48:51 +08:00
}, this);
2020-03-05 16:43:53 +08:00
2020-03-17 16:12:15 +08:00
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);
2020-03-20 14:12:02 +08:00
mapDevice[elem.stationCode].guideLockCode = elem.code; // 保证处理车站列表在处理引导总锁列表之前
2020-03-17 16:12:15 +08:00
}, this);
zrUtil.each(data.automaticRouteButtonList || [], elem => { // 自动进路列表
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.AutomaticRoute, elem, propConvert, showConfig);
2020-03-05 16:43:53 +08:00
}, this);
2020-03-17 16:12:15 +08:00
zrUtil.each(data.outerFrameList || [], elem => { // 矩形框列表
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.OutFrame, elem, propConvert, showConfig);
2020-03-04 20:59:16 +08:00
}, this);
zrUtil.each(data.splitStationList || [], elem => {
mapDevice[elem.code] = createDevice(deviceType.SplitStation, elem, propConvert, showConfig);
}, this);
2020-06-10 17:02:39 +08:00
zrUtil.each(data.tbStrategyList || [], elem => { // 站后折返按钮
mapDevice[elem.code] = createDevice(deviceType.StationTurnBack, elem, propConvert, showConfig);
}, this);
zrUtil.each(data.arrowList || [], elem => {
2020-04-26 17:16:20 +08:00
mapDevice[elem.code] = createDevice(deviceType.Arrow, elem, propConvert, showConfig);
}, this);
2020-05-28 15:02:15 +08:00
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);
2020-07-02 18:47:39 +08:00
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];
}
2020-12-15 11:10:05 +08:00
let sectionCStar, sectionCEnd;
if (handleResetPoint(rnodeSection.points)) {
2020-12-15 14:41:23 +08:00
sectionCStar = rnodeSection.points[rnodeSection.points.length - 2];
2020-12-15 11:10:05 +08:00
sectionCEnd = rnodeSection.points[1];
} else {
sectionCStar = rnodeSection.points[1];
2020-12-15 14:41:23 +08:00
sectionCEnd = rnodeSection.points[rnodeSection.points.length - 2];
}
let intersectionStar, intersectionEnd;
if (handleResetPoint(cnodeSection.points)) {
intersectionStar = cnodeSection.points[0];
intersectionEnd = cnodeSection.points[cnodeSection.points.length - 1];
} else {
intersectionStar = cnodeSection.points[cnodeSection.points.length - 1];
intersectionEnd = cnodeSection.points[0];
2020-12-15 11:10:05 +08:00
}
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 = {
2020-12-15 14:41:23 +08:00
x: intersectionStar.x,
y: intersectionStar.y
// x: cnodeSection.points[0].x,
// y: cnodeSection.points[0].y
};
mapDevice[elem.code].skew = {
2020-12-15 11:10:05 +08:00
x: sectionCStar.x,
y: sectionCStar.y
2020-12-15 14:41:23 +08:00
// 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 = {
2020-12-15 14:41:23 +08:00
x: intersectionEnd.x,
y: intersectionEnd.y
// x: cnodeSection.points[cnodeSection.points.length - 1].x,
// y: cnodeSection.points[cnodeSection.points.length - 1].y
};
mapDevice[elem.code].skew = {
2020-12-15 11:10:05 +08:00
x: sectionCEnd.x,
y: sectionCEnd.y
2020-12-15 14:41:23 +08:00
// 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);
2020-03-20 11:09:06 +08:00
zrUtil.each(data.indicatorLightList || [], elem => {
mapDevice[elem.code] = createDevice(elem.type, elem, propConvert, showConfig);
2020-12-09 10:38:46 +08:00
if (elem.type == 'SwitchFault' && mapDevice[elem.switchCode]) {
mapDevice[elem.switchCode]['switchFaultCode'] = elem.code; // 道岔数据上关联道岔故障表示灯需保证该数据在switchList之后处理
2020-03-20 11:09:06 +08:00
}
}, this);
2020-03-19 16:17:34 +08:00
2019-11-29 12:51:58 +08:00
zrUtil.each(data.trainWindowList || [], elem => {
2020-03-11 15:10:08 +08:00
mapDevice[elem.code] = createDevice(deviceType.TrainWindow, elem, propConvert, showConfig);
2019-11-29 12:51:58 +08:00
if (elem.sectionCode) {
const section = mapDevice[elem.sectionCode];
if (section) {
section['trainWindowCode'] = elem.code;
}
}
}, this);
2020-08-20 13:17:58 +08:00
zrUtil.each(data.floodGateList || [], elem=> {
mapDevice[elem.code] = createDevice(deviceType.FloodGate, elem, propConvert, showConfig);
}, this);
2020-10-10 17:58:14 +08:00
zrUtil.each(data.directionRodList || [], elem=> {
mapDevice[elem.code] = createDevice(deviceType.DirectionRod, elem, propConvert, showConfig);
}, this);
2021-01-12 10:07:31 +08:00
zrUtil.each(data.responderList || [], elem => {
mapDevice[elem.code] = createDevice(deviceType.Responder, elem, propConvert, showConfig);
}, this);
2020-10-26 15:16:48 +08:00
zrUtil.each(data.signalApproachSectionList || [], elem => {
zrUtil.each(elem.sectionPathList || [], item => {
zrUtil.each(item.sectionList || [], section => {
if (mapDevice[section] && mapDevice[section].parentCode) {
2020-10-27 13:19:31 +08:00
(mapDevice[mapDevice[section].parentCode] || {}).approach = true;
2020-10-26 15:16:48 +08:00
} else if (mapDevice[section]) {
mapDevice[section].approach = true;
}
});
});
});
2020-12-24 15:33:06 +08:00
zrUtil.each(data.overlapList || [], elem => {
mapDevice[elem.code] = createDevice(deviceType.OverAp, elem, propConvert, showConfig);
});
2019-11-29 12:51:58 +08:00
}
return mapDevice;
}
2020-12-15 11:10:05 +08:00
// 重置坐标点
function handleResetPoint(points) {
2020-12-15 14:41:23 +08:00
return (points[points.length - 1].x >= points[0].x);
2020-12-15 11:10:05 +08:00
}
2019-11-29 12:51:58 +08:00
// 同步绘制数据到原始数据
export function updateForList(model, state, lstName) {
const list = state.map[lstName];
2019-11-29 12:51:58 +08:00
if (list && list instanceof Array) {
2020-06-23 11:24:02 +08:00
const i = list.findIndex(elem => elem.code == model.code );
2020-11-23 13:41:19 +08:00
if (i < 0) {
2019-11-29 12:51:58 +08:00
list.push(deepClone(model)); // 新增
} else {
2020-11-23 13:41:19 +08:00
if (model._dispose) {
list.splice(i, 1);
} else {
list.splice(i, 1, deepClone(model));
}
}
state.map[lstName] = [...list];
2019-11-29 12:51:58 +08:00
} else {
state.map[lstName] = [model];
2019-11-29 12:51:58 +08:00
}
}
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;
2019-12-17 19:03:38 +08:00
case deviceType.ZcControl: updateForList(model, state, 'zcList'); break;
2019-11-29 12:51:58 +08:00
case deviceType.StationDelayUnlock:updateForList(model, state, 'stationDelayUnlockList'); break;
case deviceType.LcControl: updateForList(model, state, 'lcList'); break;
2019-11-29 12:51:58 +08:00
case deviceType.LimitControl: updateForList(model, state, 'tempSpeedLimitList'); break;
2019-12-23 10:53:25 +08:00
case deviceType.Resource: updateForList(model, state, 'resourceList'); break;
2019-11-29 12:51:58 +08:00
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;
2020-03-17 16:12:15 +08:00
case deviceType.AxleReset: updateForList(model, state, 'axleCounterResetButtonList'); break;
case deviceType.GuideLock: updateForList(model, state, 'totalGuideLockButtonVOList'); break;
case deviceType.OutFrame: updateForList(model, state, 'outerFrameList'); break;
2020-03-05 16:39:49 +08:00
case deviceType.AutomaticRoute: updateForList(model, state, 'automaticRouteButtonList'); break;
2020-03-20 11:09:06 +08:00
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;
2020-03-24 15:02:14 +08:00
case deviceType.MaintenanceLamps: updateForList(model, state, 'indicatorLightList'); break;
2020-03-24 16:35:09 +08:00
case deviceType.ZcCommunication: updateForList(model, state, 'indicatorLightList'); break;
2020-04-14 15:45:13 +08:00
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;
2020-05-28 15:02:15 +08:00
case deviceType.Power: updateForList(model, state, 'powerLineList'); break;
case deviceType.StationTurnBack : updateForList(model, state, 'tbStrategyList'); break;
2020-08-20 13:17:58 +08:00
case deviceType.FloodGate: updateForList(model, state, 'floodGateList'); break;
2020-10-10 17:58:14 +08:00
case deviceType.DirectionRod: updateForList(model, state, 'directionRodList'); break;
2021-01-12 10:07:31 +08:00
case deviceType.Responder: updateForList(model, state, 'responderList'); break;
2019-11-29 12:51:58 +08:00
}
}
}