rt-sim-training-client/src/jmapNew/shape/AxleReset/index.js

160 lines
5.0 KiB
JavaScript
Raw Normal View History

2020-03-17 16:12:15 +08:00
/*
* 计轴复位 控制器
*/
import Group from 'zrender/src/container/Group';
import Arc from 'zrender/src/graphic/shape/Arc';
import Text from 'zrender/src/graphic/Text';
import EMouse from './EMouse';
2020-03-18 10:20:49 +08:00
import BoundingRect from 'zrender/src/core/BoundingRect';
2020-03-17 16:12:15 +08:00
import {isShowThePrdType} from '../../utils/handlePath';
export default class AxleReset extends Group {
constructor(model, style) {
super();
this.z = 20;
this._code = model.code;
this._type = model._type;
this.zlevel = model.zlevel;
this.model = model;
this.style = style;
this.isShowShape = true;
if (isShowThePrdType(model.prdType, style.AxleReset.displayCondition) || model.previewOrMapDraw) {
this.create();
this.createMouseEvent();
this.setState(model);
}
if (model.previewOrMapDraw) {
this.setShowMode();
}
}
create() {
const model = this.model;
this.control = new Arc({
_subType: 'Control',
zlevel: this.zlevel,
z: this.z,
shape: {
cx: model.position.x,
cy: model.position.y,
r: this.style.AxleReset.lamp.radiusR
},
style: {
stroke: '##b5b3b3',
lineWidth: 1.5,
2020-03-17 16:12:15 +08:00
fill: this.style.AxleReset.lamp.controlColor
}
});
this.text = new Text({
_subType: 'Text',
zlevel: this.zlevel,
z: this.z,
position: [0, 0],
style: {
x: model.position.x,
y: model.position.y + this.style.AxleReset.lamp.radiusR + this.style.AxleReset.text.distance,
fontWeight: this.style.AxleReset.text.fontWeight,
fontSize: this.style.AxleReset.text.fontSize,
fontFamily: this.style.fontFamily,
text: model.name,
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
}
});
if (this.model.subtitleName) {
this.subtitleText = new Text({
_subType: 'Text',
zlevel: this.zlevel,
z: this.z,
position: [0, 0],
style: {
x: model.position.x,
y: model.position.y + this.style.AxleReset.lamp.radiusR + this.style.AxleReset.subtitleText.distance,
fontWeight: this.style.AxleReset.subtitleText.fontWeight,
fontSize: this.style.AxleReset.subtitleText.fontSize,
fontFamily: this.style.fontFamily,
text: model.subtitleName,
textFill: '#fff',
textAlign: 'middle',
textVerticalAlign: 'top'
}
});
this.add(this.subtitleText);
}
this.add(this.control);
this.add(this.text);
}
// 设置状态
setState(model) {
if (!this.isShowShape) return;
}
createMouseEvent() {
if (this.style.LcControl.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); });
}
}
getShapeTipPoint() {
if (this.control) {
var distance = 2;
var rect = this.control.getBoundingRect();
return {
x: rect.x + rect.width / 2,
y: rect.y - distance
};
}
return null;
}
2020-03-18 10:20:49 +08:00
getBoundingRect() { // 计算自动折返包围框
if (this.control) {
const rect = this.control.getBoundingRect().clone();
if (this.text) {
const text = this.text.getBoundingRect().clone();
rect.union(text);
return rect;
} else {
return rect;
}
} else {
return new BoundingRect(0, 0, 0, 0);
}
}
2020-03-17 16:12:15 +08:00
setShowMode() {
const showMode = this.model.showMode;
const showConditions = this.style.AxleReset.displayCondition;
if (!showConditions || showConditions === '01' || showMode === showConditions) {
2020-03-25 15:22:52 +08:00
this.showMode();
2020-03-17 16:12:15 +08:00
} else {
2020-03-25 15:22:52 +08:00
this.hideMode();
2020-03-17 16:12:15 +08:00
}
}
setShowStation(stationCode) {
if (!stationCode || this.model.stationCode === stationCode) {
this.isShowShape = true;
2020-03-25 15:22:52 +08:00
this.showMode();
2020-03-17 16:12:15 +08:00
} else {
this.isShowShape = false;
2020-03-25 15:22:52 +08:00
this.hideMode();
2020-03-17 16:12:15 +08:00
}
}
2020-03-25 15:22:52 +08:00
showMode() {
2020-03-17 16:12:15 +08:00
this.control && this.control.show();
this.text && this.text.show();
this.subtitleText && this.subtitleText.show();
this.setState(this.model);
}
2020-03-25 15:22:52 +08:00
hideMode() {
2020-03-17 16:12:15 +08:00
this.control && this.control.hide();
this.text && this.text.hide();
this.subtitleText && this.subtitleText.hide();
}
}