rt-sim-training-client/src/jmapNew/transformHandleScreen.js

145 lines
4.1 KiB
JavaScript
Raw Normal View History

2020-05-06 16:57:07 +08:00
import {createTransform1, createBoundingRect} from './utils/parser';
2020-05-06 16:57:07 +08:00
class TransformHandle {
constructor(painter) {
this.$painter = painter;
this.parentLevel = painter.getParentLevel();
2020-05-07 09:04:28 +08:00
this.rect = { x: 0, y: 0, width: 0, height: 0 };
2020-05-11 15:29:25 +08:00
this.rectList = [];
this.transformInit = [];
this.transform = [createTransform1({ scaleRateX: 1, scaleRateY: 1, offsetX: 0, offsetY: 0 })];
}
revisibleView(view) {
view.show();
view.dirty();
2020-05-06 16:57:07 +08:00
}
2020-05-11 15:29:25 +08:00
checkVisible(view, rect) {
// return createBoundingRect(view).intersect(this.rect); // 判断是否相交
2020-05-11 17:36:21 +08:00
// return createBoundingRect(view).intersect(rect); // 判断是否相交
const rectCopy = createBoundingRect(view);
const x = rectCopy.x + rectCopy.width;
if (x <= rect.width) {
return true;
} else {
return false;
}
2020-05-06 16:57:07 +08:00
}
2020-07-10 10:52:31 +08:00
// 视图进行初始化
2020-05-06 16:57:07 +08:00
transformView(view) {
if (view) {
for (let i = 0; i < this.transform.length; i++) {
2020-05-11 15:29:25 +08:00
const rect = this.rectList[i];
if (this.checkVisible(view, rect)) {
view.transform = this.transform[i];
view.transformIndex = i;
2020-05-11 15:29:25 +08:00
view.decomposeTransform(); // 修改 transform 后同步位置
if (view.screenShow) {
view.screenShow();
} else {
view.show();
2020-05-11 15:29:25 +08:00
}
return;
2020-05-07 13:35:25 +08:00
}
2020-05-06 16:57:07 +08:00
}
2020-05-07 13:35:25 +08:00
view.dirty(); // 更新
2020-05-06 16:57:07 +08:00
}
}
2020-07-10 10:52:31 +08:00
// 视图进行平移
transformView1(view) {
if (view) {
view.transform = this.transform[view.transformIndex];
view.decomposeTransform();
if (view.screenShow) {
view.screenShow();
} else {
view.show();
}
view.dirty();
}
}
// 处理所有视图缩放/平移
transformAll1() {
this.traverse(this.transformView1, this);
}
2020-05-06 16:57:07 +08:00
// 处理所有视图缩放/平移
transformAll() {
this.traverse(this.transformView, this);
}
// 重新计算显示图形
revisibleAll() {
this.traverse(this.transformView, this);
2020-05-06 16:57:07 +08:00
}
// 更新偏移量
2020-05-11 15:29:25 +08:00
updateTransform(list, rectList) {
this.rectList = rectList;
2020-05-06 16:57:07 +08:00
this.transform = [];
list.forEach(item => {
this.transform.push(createTransform1(item));
2020-05-06 16:57:07 +08:00
});
this.transformInit = JSON.parse(JSON.stringify(this.transform));
2020-05-06 16:57:07 +08:00
this.transformAll();
}
updataOffset(opt) {
this.transform.forEach(item => {
item[4] = item[4] + opt.dx;
item[5] = item[5] + opt.dy;
});
this.transformAll1();
}
updataOffsetNum(opts) {
this.transform = JSON.parse(JSON.stringify(this.transformInit));
this.transform.forEach(item => {
item[4] = item[4] - opts.dx;
item[5] = item[5] - opts.dy;
});
this.transformAll1();
}
2020-05-06 16:57:07 +08:00
2020-07-10 10:52:31 +08:00
removeType(type) {
this.parentLevel.eachChild(level => {
level.eachChild((view) => {
if (view) {
view.transform = this.transform[view.transformIndex];
view.decomposeTransform();
if (view._type == type) {
view.hide();
} else {
if (view.screenShow) {
view.screenShow();
} else {
view.show();
}
}
view.dirty();
}
});
});
}
2020-05-06 16:57:07 +08:00
// 更新画布尺寸
updateZrSize(opts) {
this.rect = { x: 0, y: 0, width: opts.width, height: opts.height };
this.revisibleAll();
}
// 遍历group执行回调
traverse(cb, context) {
this.parentLevel.eachChild(level => {
level.eachChild((view) => {
cb.call(context, view);
}, context);
}, context);
}
}
export default TransformHandle;