rt-sim-training-client/src/jmapNew/shape/StationStand/index.js
2020-06-11 17:06:29 +08:00

634 lines
24 KiB
JavaScript

/**/
import Group from 'zrender/src/container/Group';
import ETime from './ETime';
import ELevel from './ELevel';
import EReentry from './EReentry';
import EDetain from './EDetain';
import ESafeStand from './ESafeStand';
import ESafeEmergent from './ESafeEmergent';
import EMouse from './EMouse';
import EJump from './EJump';
import EHighlight from '../element/EHighlight';
import ETrainStop from './ETrainStop';
import ETrainDepart from './ETrainDepart';
import EControl from '../element/EControl';
import EDetainCircle from './EDetainCircle';
import EPatternFilter from './EPatternFilter';
import {isShowThePrdType} from '../../utils/handlePath';
class StationStand extends Group {
constructor(model, style) {
super();
this._code = model.code;
this._type = model._type;
this.model = model;
this.style = style;
this.zlevel = model.zlevel;
this.z = 1;
this.isShowShape = true;
this.doors = new Group();
this.create();
this.createMouseEvent();
if (isShowThePrdType(model.prdType, style.StationStand.common.functionButtonShow) || model.previewOrMapDraw) {
this.createFunctionButton();
}
if (model.previewOrMapDraw) {
this.setShowMode();
}
this.setVisible(model.visible);
this.setState(model);
this.checkIsDrawMap();
}
create() {
const model = this.model;
const style = this.style;
// const drict = 1;
/** 列车站台*/
const standX = model.position.x - model.width / 2;
const standY = model.position.y - model.height / 2;
this.safeStand = new ESafeStand({
zlevel: this.zlevel,
z: this.z,
style: style,
x: standX,
y: standY,
name: model.name,
inside: model.inside,
right: model.right,
width: model.width,
height: model.height
});
this.add(this.safeStand);
// 模式筛选标识(西安二号线特殊的情况)
if (style.StationStand.patternFilter) {
const direction = model.right ? 1 : -1;
this.patternFilter = new EPatternFilter({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
x: model.position.x,
y: model.position.y,
width: model.width,
height:model.height,
direction:direction
});
this.add(this.patternFilter);
}
/** 站台紧急关闭*/
const emergentOffset = model.inside ? style.StationStand.standEmergent.insideOffset : style.StationStand.standEmergent.outsideOffset;
const emergentH = model.right ? 1 : -1;
const emergentX = model.position.x + emergentH * emergentOffset.x;
const emergentY = model.position.y + emergentH * emergentOffset.y;
this.emergent = new ESafeEmergent({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
inside: model.inside,
right: model.right,
width: model.width,
x: emergentX,
y: emergentY,
r: style.StationStand.standEmergent.mergentR,
n: style.StationStand.standEmergent.mergentN
});
this.add(this.emergent);
// 列车停站
if (style.StationStand.trainStop.insideOffset) {
const stopTrainOffset = model.inside ? style.StationStand.trainStop.insideOffset : style.StationStand.trainStop.outsideOffset;
const stopTrainH = model.right ? 1 : -1;
const stopX = model.position.x + stopTrainH * stopTrainOffset.x;
const stopY = model.position.y + stopTrainH * stopTrainOffset.y;
if (style.StationStand.trainStop.insideOffset) {
this.trainStop = new ETrainStop({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
x: stopX,
y: stopY
});
this.add(this.trainStop);
}
}
// 列车出发
if (style.StationStand.trainDepart.insideOffset) {
const trainDepartOffset = model.inside ? style.StationStand.trainDepart.insideOffset : style.StationStand.trainDepart.outsideOffset;
const trainDepartH = model.right ? 1 : -1;
const departX = model.position.x + trainDepartH * trainDepartOffset.x;
const departY = model.position.y + trainDepartH * trainDepartOffset.y;
this.trainDepart = new ETrainDepart({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
width: model.width,
x: departX,
y: departY
});
this.add(this.trainDepart);
}
/** 站台折返策略*/
if (style.StationStand.reentry.offset) {
const reentryH = style.StationStand.standEmergent.mergentR;
const isRight = model.right ? -1 : 1;
const reentryX = model.position.x - (style.StationStand.reentry.position || isRight) * (style.StationStand.reentry.offset.x - model.width / 2);
const reentryY = model.position.y + (style.StationStand.reentry.position || isRight) * (style.StationStand.reentry.offset.y) + isRight * reentryH;
this.reentry = new EReentry({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
drict: isRight,
x: reentryX,
y: reentryY,
lineWidth: 0,
fill: style.StationStand.reentry.noHumanColor
});
this.add(this.reentry);
}
if (style.StationStand.detainCar.special) {
const detainD = model.right ? 1 : -1;
this.detainCircle = new EDetainCircle({
zlevel: this.zlevel,
z: this.z,
style: style,
x: model.position.x + (model.width / 2) * detainD + detainD * style.StationStand.detainCar.offset.x + detainD * style.StationStand.detainCar.circleWidth / 2,
y: model.position.y,
radius:style.StationStand.detainCar.circleWidth / 2
});
this.add(this.detainCircle);
} else {
/** 站台扣车*/
const detainD = model.right ? 1 : -1;
const detainX = model.position.x - style.StationStand.detainCar.position * detainD * (style.StationStand.detainCar.offset.x - model.width / 2);
const detainY = model.position.y + detainD * (style.StationStand.detainCar.offset.y - model.height / 2);
this.detain = new EDetain({
zlevel: this.zlevel,
z: this.z,
style: style,
x: detainX,
y: detainY,
width: model.width,
inside: model.inside,
right: model.right
});
this.add(this.detain);
}
/** 停站时间*/
if (style.StationStand.stopTime.offset) {
const timeDrict = model.right ? 1 : -1;
const timeX = model.position.x + style.StationStand.stopTime.position * timeDrict * (style.StationStand.stopTime.offset.x - model.width / 2);
const timeY = model.position.y + timeDrict * (style.StationStand.stopTime.offset.y - model.height / 2);
this.time = new ETime({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
x: timeX,
y: timeY,
name: model.parkingTime || '30'
});
this.add(this.time);
}
/** 运行等级*/
const levelDrict = model.right ? 1 : -1;
const levelX = model.position.x - levelDrict * (style.StationStand.level.offset.x - model.width / 2);
const levelY = model.position.y + levelDrict * (style.StationStand.level.offset.y);
this.level = new ELevel({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
x: levelX,
y: levelY,
name: model.runLevelTime || '5'
});
this.add(this.level);
/** 列车停跳 */
if (style.StationStand.common.haveJumpShow) {
const jumpDirct = model.right ? -1 : 1;
const jumpX = model.position.x - jumpDirct * style.StationStand.jump.position * (style.StationStand.jump.offset.x - model.width / 2);
const jumpY = model.position.y + jumpDirct * style.StationStand.jump.offset.y;
const jumpCX = model.position.x - jumpDirct * style.StationStand.jump.position * (style.StationStand.jump.offset.x - model.width / 2);
const jumpCY = model.position.y + jumpDirct * style.StationStand.jump.offset.y;
this.jump = new EJump({
zlevel: this.zlevel,
z: this.z + 1,
style: style,
x: jumpX,
y: jumpY,
cx: jumpCX,
cy: jumpCY,
width: model.width,
inside: model.inside,
right: model.right
});
this.add(this.jump);
}
}
createMouseEvent() {
if (this.style.StationStand.mouseOverStyle) {
this.mouseEvent = new EMouse(this);
this.add(this.mouseEvent);
this.on('mouseout', (e) => { this.mouseEvent.mouseout(e); });
this.on('mouseover', (e) => { this.mouseEvent.mouseover(e); });
}
}
createFunctionButton() {
const model = this.model;
const style = this.style;
if (model.stopJumpLamp) {
this.stopJumpLampButton = new EControl({
zlevel: this.zlevel,
z: this.z,
arc: {
shape: {
cx: model.stopJumpLampPoint.x,
cy: model.stopJumpLampPoint.y,
r: style.Station.lamp.radiusR
},
subType: 'StopJumpLamp',
lineWidth: 0,
fill: style.StationStand.lamp.lampColor
},
text: {
position: [0, 0],
x: model.stopJumpLampPoint.x,
y: model.stopJumpLampPoint.y + style.StationStand.lamp.radiusR + style.StationStand.text.distance,
fontWeight: style.StationStand.text.fontWeight,
fontSize: style.StationStand.text.fontSize,
fontFamily: style.fontFamily,
text: '跳停',
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
},
style: this.style
});
this.add(this.stopJumpLampButton);
}
if (model.cancelStopJumpLamp) {
this.cancelStopJumpLampButton = new EControl({
zlevel: this.zlevel,
z: this.z,
arc: {
shape: {
cx: model.cancelStopJumpLampPoint.x,
cy: model.cancelStopJumpLampPoint.y,
r: style.Station.lamp.radiusR
},
subType: 'CancelStopJumpLamp',
lineWidth: 0,
fill: style.StationStand.lamp.lampColor
},
text: {
position: [0, 0],
x: model.cancelStopJumpLampPoint.x,
y: model.cancelStopJumpLampPoint.y + style.StationStand.lamp.radiusR + style.StationStand.text.distance,
fontWeight: style.StationStand.text.fontWeight,
fontSize: style.StationStand.text.fontSize,
fontFamily: style.fontFamily,
text: '取消跳停',
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
},
style: this.style
});
this.add(this.cancelStopJumpLampButton);
}
if (model.upDetainLamp) {
this.upDetainLampButton = new EControl({
zlevel: this.zlevel,
z: this.z,
arc: {
shape: {
cx: model.upDetainLampPoint.x,
cy: model.upDetainLampPoint.y,
r: style.Station.lamp.radiusR
},
subType: 'UpDetainLamp',
lineWidth: 0,
fill: style.StationStand.lamp.lampColor
},
text: {
position: [0, 0],
x: model.upDetainLampPoint.x,
y: model.upDetainLampPoint.y + style.StationStand.lamp.radiusR + style.StationStand.text.distance,
fontWeight: style.StationStand.text.fontWeight,
fontSize: style.StationStand.text.fontSize,
fontFamily: style.fontFamily,
text: '上行扣车',
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
},
style: this.style
});
this.add(this.upDetainLampButton);
}
if (model.downDetainLamp) {
this.downDetainLampButton = new EControl({
zlevel: this.zlevel,
z: this.z,
arc: {
shape: {
cx: model.downDetainLampPoint.x,
cy: model.downDetainLampPoint.y,
r: style.Station.lamp.radiusR
},
subType: 'DownDetainLamp',
lineWidth: 0,
fill: style.StationStand.lamp.lampColor
},
text: {
position: [0, 0],
x: model.downDetainLampPoint.x,
y: model.downDetainLampPoint.y + style.StationStand.lamp.radiusR + style.StationStand.text.distance,
fontWeight: style.StationStand.text.fontWeight,
fontSize: style.StationStand.text.fontSize,
fontFamily: style.fontFamily,
text: '下行扣车',
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
},
style: this.style
});
this.add(this.downDetainLampButton);
}
}
setVisible(visible) {
if (visible) {
this.eachChild(elem => { elem.show(); });
} else {
this.eachChild(elem => { elem.hide(); });
}
}
/** 恢复初始状态*/
recover() {
this.time && this.time.hideMode();
this.level && this.level.hideMode();
this.detain && this.detain.hideMode();
this.emergent && this.emergent.hideMode();
this.trainStop && this.trainStop.hideMode(); // 列车停站
this.trainDepart && this.trainDepart.hideMode();
this.reentry && this.reentry.hideMode();
this.jump && this.jump.hideMode();
this.detainCircle && this.detainCircle.setColor(this.style.StationStand.detainCar.defaultColor);
}
/** 空闲*/
spare() {
if (!this.style.StationStand.common.special) {
this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.spareColor);
}
}
/** 列车停站*/
stop() {
if (!this.style.StationStand.common.special) {
this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.stopColor);
} else {
this.trainStop && this.trainStop.showMode();
this.trainDepart && this.trainDepart.showMode();
}
}
/** 车门开启 */
doorOpen() {
if (this.style.StationStand.common.standType && this.style.StationStand.common.standType == 'notFill') {
this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.doorOpenColor);
}
}
/** 站台紧急关闭*/
emergentClose() {
if (!this.style.StationStand.common.special) {
this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.spareColor);
}
this.emergent && this.emergent.showMode();
if (this.style.StationStand.standEmergent.flicker) {
this.emergent.getElement().animateStyle(true)
.when(0, { fill: this.style.backgroundColor })
.when(1000, { fill: this.style.StationStand.standEmergent.closeColor })
.when(2000, { fill: this.style.backgroundColor })
.start();
}
}
/** 指定列车跳站*/
designatedJumpStop() {
this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.designatedJumpStopColor);
this.jump && this.jump.showMode(0);
}
/** 站台跳停*/
jumpStop() {
this.safeStand && this.safeStand.setColor(this.style.StationStand.stand.jumpStopColor);
this.jump && this.jump.showMode(1);
}
/** 车站扣车*/
standDetainTrain() {
this.detain && this.detain.showMode();
this.detain && this.detain.setColor(this.style.StationStand.detainCar.detainTrainTextColor);
this.detainCircle && this.detainCircle.setColor(this.style.StationStand.detainCar.centerTrainColor);
}
/** 中心扣车*/
centerDetainTrain() {
this.detain && this.detain.showMode();
this.detain && this.detain.setColor(this.style.StationStand.detainCar.centerTrainColor);
this.detainCircle && this.detainCircle.setColor(this.style.StationStand.detainCar.centerTrainColor);
}
/** 中心+车站扣车*/
standAndCenterDetainTrain() {
this.detain && this.detain.showMode();
this.detain && this.detain.setColor(this.style.StationStand.detainCar.andCenterTrainColor);
this.detainCircle && this.detainCircle.setColor(this.style.StationStand.detainCar.centerTrainColor);
}
/** 人工设置停战时间*/
setManuallyArmisticeTime(val) {
this.time && this.time.showMode();
this.time && this.time.setName(val);
}
/** 人工设置运行等级*/
setManuallyOperationLevel(val) {
this.level && this.level.showMode();
this.level && this.level.setName(val);
}
/** 无折返(默认)*/
noReentry() {
this.reentry && this.reentry.hideMode();
}
/** 无人折返*/
noHumanReentry() {
this.reentry && this.reentry.showMode();
this.reentry && this.reentry.setColor(this.style.StationStand.reentry.noHumanColor);
}
/** 自动换端*/
autoChangeEnds() {
this.reentry && this.reentry.showMode();
this.reentry && this.reentry.setColor(this.style.StationStand.reentry.autoChangeEndsColor);
}
setState(model) {
if (!this.isShowShape) return;
// 新版地图使用新版状态变更方式
this.recover();
!model.trainParking && this.spare(); /** 空闲*/
model.trainParking && this.stop(); /** 列车停站*/
model.emergencyClosed && this.emergentClose(); /** 站台紧急关闭*/
model.trainParking && this.doorOpen(); /** 车门开启 (西安二号线样式)*/
if (Number(model.parkingTime) > 0) {
this.setManuallyArmisticeTime(model.parkingTime); // 设置站台停车时间
}
if (Number(model.runLevelTime) > 0) {
this.setManuallyOperationLevel(model.runLevelTime); // 设置站台间运行等级
}
/** 设置跳停*/
model.assignSkip && this.designatedJumpStop(); // 指定列车跳停
model.allSkip && this.jumpStop(); // 站台全部跳停
/** 设置扣车*/
if (model.stationHoldTrain && model.centerHoldTrain) {
this.standAndCenterDetainTrain(); // 中心+车站扣车
} else if (model.stationHoldTrain) {
this.standDetainTrain(); // 车站扣车
} else if (model.centerHoldTrain) {
this.centerDetainTrain(); // 中心扣车
}
/** 设置折返策略*/
let reentryStrategy = '';
if (model.reentryStrategy !== '04') {
reentryStrategy = model.reentryStrategy;
} else {
reentryStrategy = model.defaultReentryStrategy;
}
switch (reentryStrategy) {
case '04': /** 默认*/
case '01':
this.noReentry(); /** 无折返策略*/
break;
case '02':
this.noHumanReentry(); /** 无人折返*/
break;
case '03':
this.autoChangeEnds(); /** 自动换端*/
break;
}
}
getBoundingRect() {
const rect = this.safeStand.getBoundingRect().clone();
return rect;
}
getShapeTipPoint(opts) {
let rect;
if (opts.subDeviceType == 'DetainLamp') {
if (this.model.right) {
opts.subDeviceType = 'UpDetainLamp';
} else {
opts.subDeviceType = 'DownDetainLamp';
}
}
switch (opts.subDeviceType) {
case 'StopJumpLamp': {
rect = this.stopJumpLampButton.getBoundingRect();
break;
}
case 'CancelStopJumpLamp': {
rect = this.cancelStopJumpLampButton.getBoundingRect();
break;
}
case 'UpDetainLamp': {
rect = this.upDetainLampButton.getBoundingRect();
break;
}
case 'DownDetainLamp': {
rect = this.downDetainLampButton.getBoundingRect();
break;
}
default: {
rect = this.getBoundingRect();
break;
}
}
if (rect) {
return {
x: rect.x + rect.width / 2,
y: rect.y
};
}
return null;
}
drawSelected(selected) {
this.highlight && this.highlight.drawSelected(selected);
}
checkIsDrawMap() {
const path = window.location.href;
if (path.includes('/map/draw')) {
this.highlight = new EHighlight(this);
this.add(this.highlight);
this.on('mouseout', () => { this.highlight.mouseout(); });
this.on('mouseover', () => { this.highlight.mouseover(); });
}
}
// 设置显示模式
setShowMode() {
const showMode = this.model.showMode;
const showConditions = this.style.StationStand.common.functionButtonShow;
if (!showConditions || showConditions === '01' || showMode === showConditions) {
this.stopJumpLampButton && this.stopJumpLampButton.show();
this.cancelStopJumpLampButton && this.cancelStopJumpLampButton.show();
this.upDetainLampButton && this.upDetainLampButton.show();
this.downDetainLampButton && this.downDetainLampButton.show();
this.upDetainLamp && this.upDetainLamp.show();
this.downDetainLamp && this.downDetainLamp.show();
} else {
this.stopJumpLampButton && this.stopJumpLampButton.hide();
this.cancelStopJumpLampButton && this.cancelStopJumpLampButton.hide();
this.upDetainLampButton && this.upDetainLampButton.hide();
this.downDetainLampButton && this.downDetainLampButton.hide();
this.upDetainLamp && this.upDetainLamp.hide();
this.downDetainLamp && this.downDetainLamp.hide();
}
}
setShowStation(stationCode) {
if ((!stationCode || this.model.deviceStationCode === stationCode) && this.model.visible) {
this.eachChild(item => {
item.show();
});
this.isShowShape = true;
this.setState(this.model);
} else {
this.eachChild(item => {
item.hide();
});
this.isShowShape = false;
}
}
}
export default StationStand;