114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
import Line from 'zrender/src/graphic/shape/Line';
|
|
import Arc from 'zrender/src/graphic/shape/Arc';
|
|
import Group from 'zrender/src/container/Group';
|
|
|
|
class ESigLamp extends Group {
|
|
constructor(model) {
|
|
super();
|
|
this.model = model;
|
|
this.create();
|
|
}
|
|
|
|
create() {
|
|
const model = this.model;
|
|
const style = this.model.style;
|
|
|
|
this.lamp = new Arc({
|
|
_subType: 'SignalLamp',
|
|
_val: '3',
|
|
name: model.index,
|
|
zlevel: model.zlevel,
|
|
z: model.z,
|
|
shape: {
|
|
cx: model.x,
|
|
cy: model.y,
|
|
r: style.Signal.lamp.radiusR
|
|
},
|
|
style: {
|
|
lineWidth: style.Signal.lamp.borderWidth,
|
|
fill: style.backgroundColor,
|
|
stroke: style.Signal.lamp.borderColor
|
|
}
|
|
});
|
|
|
|
this.lstop = new Line({
|
|
_subType: 'SignalLamp',
|
|
_val: '3',
|
|
zlevel: model.zlevel,
|
|
z: model.z,
|
|
origin: {
|
|
x: model.originX,
|
|
y: model.originY
|
|
},
|
|
shape: {
|
|
x1: model.x + (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
y1: model.y + (style.Signal.lamp.radiusR + 1) * Math.sin(Math.PI / 4),
|
|
x2: model.x - (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
y2: model.y - (style.Signal.lamp.radiusR + 1) * Math.sin(Math.PI / 4)
|
|
},
|
|
style: {
|
|
lineWidth: style.Signal.lamp.stopWidth,
|
|
stroke: style.backgroundColor
|
|
}
|
|
});
|
|
|
|
this.rstop = new Line({
|
|
_subType: 'SignalLamp',
|
|
_val: '3',
|
|
zlevel: model.zlevel,
|
|
z: model.z,
|
|
origin: {
|
|
x: model.originX,
|
|
y: model.originY
|
|
},
|
|
shape: {
|
|
x1: model.x + (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
y1: model.y + (style.Signal.lamp.radiusR + 1) * (Math.sin(Math.PI / 4) - Math.sqrt(2)),
|
|
x2: model.x - (style.Signal.lamp.radiusR + 1) * Math.cos(Math.PI / 4),
|
|
y2: model.y - (style.Signal.lamp.radiusR + 1) * (Math.sin(Math.PI / 4) - Math.sqrt(2))
|
|
},
|
|
style: {
|
|
lineWidth: style.Signal.lamp.stopWidth,
|
|
stroke: style.backgroundColor
|
|
}
|
|
});
|
|
this.add(this.lamp);
|
|
if (!style.Signal.lamp.logicDisplayNone) {
|
|
this.add(this.lstop);
|
|
this.add(this.rstop);
|
|
}
|
|
}
|
|
|
|
setColor(color) {
|
|
if (this.model.style.Signal.lamp.borderVariable) {
|
|
this.lamp.setStyle({ fill: color, stroke: color });
|
|
} else {
|
|
this.lamp.setStyle({ fill: color });
|
|
}
|
|
}
|
|
|
|
setBorderColor(color) {
|
|
this.lamp.setStyle({ stroke: color });
|
|
}
|
|
|
|
setStyle(data) {
|
|
this.lamp.setStyle(data);
|
|
}
|
|
|
|
setStop(has) {
|
|
if (has) {
|
|
this.lstop.show();
|
|
this.rstop.show();
|
|
} else {
|
|
this.lstop.hide();
|
|
this.rstop.hide();
|
|
}
|
|
}
|
|
|
|
getBoundingRect() {
|
|
return this.lamp.getBoundingRect();
|
|
}
|
|
}
|
|
|
|
export default ESigLamp;
|