2019-11-29 12:51:58 +08:00
|
|
|
import * as zrUtil from 'zrender/src/core/util';
|
2021-05-19 15:07:59 +08:00
|
|
|
// import * as vector from 'zrender/src/core/vector';
|
2019-11-29 12:51:58 +08:00
|
|
|
import Group from 'zrender/src/container/Group';
|
|
|
|
import deviceType from './constant/deviceType';
|
2021-05-20 15:13:37 +08:00
|
|
|
import systemGraphType from './constant/systemGraphType';
|
2020-02-11 16:16:04 +08:00
|
|
|
import transitionDeviceStatus from './constant/stateTransition';
|
2021-05-19 15:07:59 +08:00
|
|
|
// import shapefactory from './shape/factory';
|
|
|
|
import Graphic from './shape';
|
2019-11-29 12:51:58 +08:00
|
|
|
import TransformHandle from './transformHandle';
|
2020-05-06 16:57:07 +08:00
|
|
|
import TransformHandleScreen from './transformHandleScreen';
|
2021-05-14 15:05:57 +08:00
|
|
|
import deviceRender from './constant/deviceRender';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
|
|
|
class Painter {
|
|
|
|
constructor(jmap) {
|
|
|
|
// 父级实例
|
|
|
|
this.$jmap = jmap;
|
|
|
|
this.$zr = jmap.getZr();
|
|
|
|
|
|
|
|
// 图层数据
|
|
|
|
this.mapInstanceLevel = {};
|
|
|
|
|
2020-05-12 18:23:56 +08:00
|
|
|
this.screenFlag = false;
|
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
// 初始图层
|
|
|
|
this.initLevels();
|
|
|
|
|
|
|
|
// 视图控制器
|
|
|
|
this.$transformHandle = new TransformHandle(this);
|
2020-05-06 16:57:07 +08:00
|
|
|
this.$transformHandleScreen = new TransformHandleScreen(this);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始绘图实例
|
|
|
|
* @param {*} dom
|
|
|
|
* @param {*} config
|
|
|
|
*/
|
|
|
|
initLevels() {
|
|
|
|
|
|
|
|
// 添加父级图层
|
|
|
|
this.parentLevel = new Group({ name: '__parent__' });
|
|
|
|
this.$zr.add(this.parentLevel);
|
|
|
|
|
|
|
|
// 添加子级图层
|
2021-05-20 15:13:37 +08:00
|
|
|
zrUtil.each([
|
|
|
|
...Object.values(deviceType),
|
|
|
|
...Object.values(systemGraphType)], (type) => {
|
2019-11-29 12:51:58 +08:00
|
|
|
const level = new Group({ name: `__${type}__` });
|
|
|
|
this.mapInstanceLevel[type] = level;
|
|
|
|
this.parentLevel.add(level);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-19 15:07:59 +08:00
|
|
|
newGraph(device) {
|
|
|
|
const type = device._type;
|
|
|
|
// const state = this.$map.getState(); // 获取 默认状态
|
|
|
|
const builder = Graphic.getBuilder(type); // 根据 type 绘制 面板,资源,画面对应的 instance
|
|
|
|
return builder(device, this.$jmap);
|
|
|
|
}
|
|
|
|
|
2019-11-29 12:51:58 +08:00
|
|
|
/**
|
|
|
|
* 重绘视图
|
|
|
|
* @param {*} mapDevice
|
|
|
|
*/
|
|
|
|
repaint(mapDevice) {
|
|
|
|
// 清空视图
|
|
|
|
this.clear();
|
|
|
|
|
|
|
|
// 创建视图
|
|
|
|
Object.values(mapDevice).forEach(device => {
|
|
|
|
this.add(device);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加视图
|
|
|
|
* @param {*} device
|
|
|
|
*/
|
|
|
|
add(device) {
|
|
|
|
try {
|
2021-05-31 14:15:09 +08:00
|
|
|
const instance = device.instance || this.newGraph(device);
|
2019-11-29 12:51:58 +08:00
|
|
|
if (instance) {
|
|
|
|
device.instance = instance;
|
|
|
|
this.$transformHandle.transformView(instance);
|
|
|
|
this.mapInstanceLevel[device._type].add(instance);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除视图
|
|
|
|
* @param {*} device
|
|
|
|
*/
|
|
|
|
delete(device) {
|
|
|
|
const instance = device.instance;
|
|
|
|
if (instance) {
|
|
|
|
this.mapInstanceLevel[device._type].remove(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-13 10:13:05 +08:00
|
|
|
checkTrainOverlap(device) { // 检查重叠列车
|
|
|
|
const trainWindowCode = device.trainWindowCode;
|
|
|
|
const overlapTrainList = [device.code];
|
2019-11-29 12:51:58 +08:00
|
|
|
this.mapInstanceLevel[deviceType.Train].eachChild(elem => {
|
2020-11-13 10:13:05 +08:00
|
|
|
if (elem.model.code !== device.code && elem.model.trainWindowCode === trainWindowCode) {
|
|
|
|
overlapTrainList.push(elem.model.code);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (overlapTrainList.length > 1) {
|
|
|
|
this.sortOverLapTrain(overlapTrainList);
|
|
|
|
}
|
|
|
|
return overlapTrainList;
|
|
|
|
}
|
|
|
|
sortOverLapTrain(overlapTrainList) { // 对重叠列车按照区段上的位置进行排序
|
|
|
|
overlapTrainList.sort((a, b) => {
|
|
|
|
const trainA = this.$jmap.getDeviceByCode(a);
|
|
|
|
const trainB = this.$jmap.getDeviceByCode(b);
|
|
|
|
if (trainA.right) {
|
|
|
|
return trainA.offsetp - trainB.offsetp;
|
|
|
|
} else {
|
|
|
|
return trainB.offsetp - trainA.offsetp;
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 更新列车
|
|
|
|
* @param {*} device
|
|
|
|
*/
|
|
|
|
updateTrain(device) {
|
2020-11-13 10:13:05 +08:00
|
|
|
const curModel = device;
|
2019-11-29 12:51:58 +08:00
|
|
|
if (curModel.sectionCode) {
|
|
|
|
curModel.sectionModel = this.$jmap.getDeviceByCode(curModel.sectionCode);
|
2020-02-13 13:12:22 +08:00
|
|
|
if (curModel.sectionModel.trainWindowCode) {
|
|
|
|
curModel.trainWindowCode = curModel.sectionModel.trainWindowCode;
|
|
|
|
} else if (curModel.right && curModel.sectionModel.logicSectionCodeList && curModel.sectionModel.logicSectionCodeList.length) {
|
|
|
|
const sec = this.$jmap.getDeviceByCode(curModel.sectionModel.logicSectionCodeList[curModel.sectionModel.logicSectionCodeList.length - 1]);
|
|
|
|
curModel.trainWindowCode = sec.trainWindowCode;
|
|
|
|
} else if (!curModel.right && curModel.sectionModel.logicSectionCodeList && curModel.sectionModel.logicSectionCodeList.length) {
|
|
|
|
const sec = this.$jmap.getDeviceByCode(curModel.sectionModel.logicSectionCodeList[0]);
|
|
|
|
curModel.trainWindowCode = sec.trainWindowCode;
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curModel.trainWindowCode) {
|
|
|
|
curModel.trainWindowModel = this.$jmap.getDeviceByCode(curModel.trainWindowCode);
|
|
|
|
}
|
2020-11-13 10:13:05 +08:00
|
|
|
const overlapTrainList = this.checkTrainOverlap(device);
|
|
|
|
overlapTrainList.forEach((item, index) => {
|
|
|
|
const trainDevice = this.$jmap.getDeviceByCode(item);
|
2021-06-08 14:44:23 +08:00
|
|
|
trainDevice._type = deviceRender['Train']._type;
|
|
|
|
trainDevice.zlevel = deviceRender['Train'].zlevel;
|
2020-11-13 10:13:05 +08:00
|
|
|
trainDevice.overLapIndex = index;
|
|
|
|
trainDevice.instance && this.mapInstanceLevel[deviceType.Train].remove(trainDevice.instance);
|
2021-05-31 14:15:09 +08:00
|
|
|
trainDevice.instance = null;
|
2020-11-13 10:13:05 +08:00
|
|
|
this.add(trainDevice);
|
|
|
|
});
|
2020-05-12 18:23:56 +08:00
|
|
|
|
|
|
|
if (this.screenFlag) {
|
|
|
|
this.$transformHandleScreen.transformView(device.instance);
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新视图
|
|
|
|
* @param {*} device
|
|
|
|
*/
|
|
|
|
update(device) {
|
|
|
|
if (device) {
|
|
|
|
try {
|
|
|
|
if (device._dispose) {
|
|
|
|
this.delete(device);
|
2020-03-06 15:27:31 +08:00
|
|
|
} else if (deviceType.Train.toUpperCase() == device.deviceType) {
|
2019-11-29 12:51:58 +08:00
|
|
|
this.updateTrain(device);
|
|
|
|
} else {
|
|
|
|
const instance = device.instance;
|
|
|
|
if (instance) {
|
2020-09-15 17:08:28 +08:00
|
|
|
instance.setState(transitionDeviceStatus(device)); // 改变视图状态
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-11 15:10:08 +08:00
|
|
|
/**
|
|
|
|
* 更新显示模式
|
|
|
|
*/
|
|
|
|
updateShowMode(device) {
|
|
|
|
if (device && device.instance) {
|
|
|
|
device.instance.setShowMode();
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 13:01:58 +08:00
|
|
|
/**
|
|
|
|
* 更新现地显示单独集中站
|
|
|
|
* */
|
|
|
|
updateShowStation(device, stationCode) {
|
|
|
|
if (device && device.instance) {
|
|
|
|
device.instance.setShowStation(stationCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateSpecialShowStation(device, flag) {
|
|
|
|
if (device && device.instance) {
|
|
|
|
device.instance.setShowStation(flag);
|
|
|
|
}
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
/**
|
|
|
|
* 更新transform变化
|
|
|
|
* @param {*} opt
|
|
|
|
*/
|
|
|
|
updateTransform(opt) {
|
2020-06-10 16:56:52 +08:00
|
|
|
this.screenFlag = false;
|
2019-11-29 12:51:58 +08:00
|
|
|
this.$transformHandle.updateTransform(opt);
|
|
|
|
}
|
|
|
|
|
2020-07-06 17:02:13 +08:00
|
|
|
updateScreen(opt) {
|
|
|
|
this.$transformHandleScreen.updataOffset(opt);
|
|
|
|
}
|
|
|
|
updateScreenNum(opts) {
|
|
|
|
this.$transformHandleScreen.updataOffsetNum(opts);
|
|
|
|
}
|
2020-05-07 09:04:28 +08:00
|
|
|
updateTransform1(list, opts) {
|
2020-05-12 18:23:56 +08:00
|
|
|
this.screenFlag = true;
|
2020-05-07 09:04:28 +08:00
|
|
|
this.$transformHandleScreen.updateTransform(list, opts);
|
2020-05-06 16:57:07 +08:00
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
/**
|
|
|
|
* 更新zrender尺寸
|
|
|
|
* @param {*} opt
|
|
|
|
*/
|
|
|
|
updateZrSize(opt) {
|
|
|
|
this.$transformHandle.updateZrSize(opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 过去坐标提示位置
|
|
|
|
* @param {*} opts
|
|
|
|
*/
|
|
|
|
getShapeTipPoint(instance, opts) {
|
|
|
|
if (instance) {
|
|
|
|
var point = instance.getShapeTipPoint(opts);
|
2021-05-14 15:05:57 +08:00
|
|
|
if (point) {
|
2019-11-29 12:51:58 +08:00
|
|
|
// 矩阵变换
|
2021-02-24 18:52:38 +08:00
|
|
|
var transPoint = instance.transformCoordToGlobal(point.x, point.y);
|
2019-11-29 12:51:58 +08:00
|
|
|
return {
|
|
|
|
x: transPoint[0],
|
|
|
|
y: transPoint[1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置图层可见
|
|
|
|
* @param {*} code
|
|
|
|
*/
|
|
|
|
setLevelVisible(list) {
|
|
|
|
zrUtil.each(Object.values(deviceType), type => {
|
|
|
|
const level = this.mapInstanceLevel[type];
|
|
|
|
if (list.includes(type)) {
|
|
|
|
level.hide();
|
2020-04-10 17:23:53 +08:00
|
|
|
} else {
|
|
|
|
level.show();
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 刷新图层
|
|
|
|
*/
|
|
|
|
refresh() {
|
|
|
|
this.$zr.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 清除图层
|
|
|
|
*/
|
|
|
|
clearLevel(type) {
|
|
|
|
const level = this.mapInstanceLevel[type];
|
|
|
|
if (level) {
|
|
|
|
level.removeAll();
|
2020-07-29 11:14:45 +08:00
|
|
|
this.screenFlag && this.$transformHandleScreen.removeType(type);
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 清除canvas
|
|
|
|
*/
|
|
|
|
clear() {
|
|
|
|
zrUtil.each(Object.values(this.mapInstanceLevel), (level) => {
|
|
|
|
level && level.removeAll();
|
|
|
|
}, this);
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 销毁图层
|
|
|
|
*/
|
|
|
|
dispose() {
|
|
|
|
this.mapInstanceLevel = {};
|
|
|
|
this.parentLevel = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 父级图层
|
|
|
|
*/
|
|
|
|
getParentLevel() {
|
|
|
|
return this.parentLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Painter;
|