From 832513c750c99a8a336b3170c287a9769e06e9bd Mon Sep 17 00:00:00 2001 From: ival <160568032@qq.com> Date: Thu, 1 Apr 2021 23:15:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=A9=E6=94=BE=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iscs_new/factory/compose.js | 65 ++++++++++++++++++--------------- src/iscs_new/factory/element.js | 3 +- src/iscs_new/map.js | 1 + src/iscs_new/painter.js | 1 - src/iscs_new/transformHandle.js | 6 ++- src/views/test/index.vue | 9 +++-- 6 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/iscs_new/factory/compose.js b/src/iscs_new/factory/compose.js index e042f40c9..c6e3d8bb6 100644 --- a/src/iscs_new/factory/compose.js +++ b/src/iscs_new/factory/compose.js @@ -20,7 +20,6 @@ class Compose extends AbstractShape { shapeInstance: this, }); - // this.instance.transform = utils.createTransform({scale: this.model.scale, position: this.model.position, rotation: this.model.rotation}); this.model.elementCodes.forEach(code => { const el = this.shapeFactory.getShapeByCode(code); if (el.instance) { @@ -29,17 +28,23 @@ class Compose extends AbstractShape { } }) - this.instance.dirty(); + this.instance.transform = utils.createTransform({scale: this.model.scale, position: this.model.position, rotation: this.model.rotation}); + this.instance.decomposeTransform(); } // 拖动 drift({dx, dy}) { - this.model.elementCodes.forEach(code => { - const el = this.shapeFactory.getShapeByCode(code); - if (el) { - el.drift({dx, dy}); - } - }) + this.model.position[0] = this.model.position[0] + dx; + this.model.position[1] = this.model.position[1] + dy; + this.instance.transform = utils.createTransform({scale: this.model.scale, position: this.model.position, rotation: this.model.rotation}); + this.instance.decomposeTransform(); + console.log(this.model.position, this.instance.transform); + // this.model.elementCodes.forEach(code => { + // const el = this.shapeFactory.getShapeByCode(code); + // if (el) { + // el.drift({dx, dy}); + // } + // }) } // 设置高亮 @@ -69,9 +74,9 @@ class Compose extends AbstractShape { const el = this.shapeFactory.getShapeByCode(code); if (el && el.model) { - el.model.composeCode = this.model.code; this.shapeFactory.removeFromLayer(el.model.type, el.instance); this.instance.add(el.instance); + el.model.composeCode = this.model.code; el.attr(el.model); } }) @@ -86,9 +91,9 @@ class Compose extends AbstractShape { if (el && el.model && el.model.composeCode) { - el.model.composeCode = ''; - this.remove(el.instance); + this.instance.remove(el.instance); this.shapeFactory.addToLayer(el.model.type, el.instance); + el.model.composeCode = ''; el.attr(el.model); } }) @@ -97,13 +102,14 @@ class Compose extends AbstractShape { // 修改属性 attr(attrs) { - this.model.elementCodes.forEach(code => { - const el = this.shapeFactory.getShapeByCode(code); - if (el && - el) { - el.attr(attrs); - } - }) + // this.model.elementCodes.forEach(code => { + // const el = this.shapeFactory.getShapeByCode(code); + // if (el && + // el) { + // el.attr(attrs); + // } + // }) + this.instance.attr(attrs); } // 获取依赖图形 @@ -113,17 +119,18 @@ class Compose extends AbstractShape { // 获取包围框 getBoundingRect() { - let unionRect = null; - this.model.elementCodes.forEach(code => { - const el = this.shapeFactory.getShapeByCode(code) - const rect = el.getBoundingRect().clone(); - rect - ? unionRect - ? unionRect.union(rect) - : (unionRect = rect) - : null; - }) - return unionRect; + return this.instance.getBoundingRect(); + // let unionRect = null; + // this.model.elementCodes.forEach(code => { + // const el = this.shapeFactory.getShapeByCode(code) + // const rect = el.getBoundingRect().clone(); + // rect + // ? unionRect + // ? unionRect.union(rect) + // : (unionRect = rect) + // : null; + // }) + // return unionRect; } } diff --git a/src/iscs_new/factory/element.js b/src/iscs_new/factory/element.js index a4eebe0b8..cb632e0ea 100644 --- a/src/iscs_new/factory/element.js +++ b/src/iscs_new/factory/element.js @@ -51,7 +51,8 @@ class Element extends AbstractShape { // dx = (dx + position[0]) / scale[0]; // dy = (dy + position[1]) / scale[1]; - [dx, dy] = utils.createTransformPosition(this.instance, dx, dy); + // [dx, dy] = utils.createTransformPosition(this.instance, dx, dy); + if (this.model.shape.hasOwnProperty('x')) { this.model.shape.x += dx; } diff --git a/src/iscs_new/map.js b/src/iscs_new/map.js index d720d5492..9e9c6237b 100644 --- a/src/iscs_new/map.js +++ b/src/iscs_new/map.js @@ -150,6 +150,7 @@ class JMap { const updateModel = this.isDrawing() ? this.$shapeFactory.updateSource(model, action): model; const shape = this.$shapeFactory.getShapeByCode(updateModel.code); const deps = shape.getDepShapes(); + let oldShape = null let newShape = null; diff --git a/src/iscs_new/painter.js b/src/iscs_new/painter.js index c6d7e71f0..8c0198afd 100644 --- a/src/iscs_new/painter.js +++ b/src/iscs_new/painter.js @@ -75,7 +75,6 @@ class Painter extends Group { return (view) => { this.mapShapeLayer[name].add(view); this.$transformHandle.transformView(view); - this.dirty(); } } diff --git a/src/iscs_new/transformHandle.js b/src/iscs_new/transformHandle.js index c180d0618..9c81449d4 100644 --- a/src/iscs_new/transformHandle.js +++ b/src/iscs_new/transformHandle.js @@ -33,8 +33,8 @@ export default class TransformHandle { // 视图进行缩放/平移 transformView(view) { if (view) { - view.transform = this.transform; - view.decomposeTransform(); + // view.transform = this.transform; + // view.decomposeTransform(); this.visibleView(view); } } @@ -67,6 +67,8 @@ export default class TransformHandle { layer.eachChild((view) => { cb.call(context, view); }, context); + layer.transform = this.transform; + layer.decomposeTransform(); }, context); } } diff --git a/src/views/test/index.vue b/src/views/test/index.vue index 5c7b36884..444bde692 100644 --- a/src/views/test/index.vue +++ b/src/views/test/index.vue @@ -172,7 +172,7 @@ export default { fill: 'red', stroke: 'black' }, - composeCode: '100' + composeCode: '101' }, { code: '4', @@ -187,7 +187,7 @@ export default { fill: 'red', stroke: 'black' }, - composeCode: '100' + composeCode: '101' }, { code: '5', @@ -227,13 +227,16 @@ export default { code: '100', type: 'Device', elementCodes: ['1', '2'], - // scale: [0.5, 0.5] + scale: [0.5, 0.5], + position: [0, 0], // composeCode: '1000', }, { code: '101', type: 'Device', elementCodes: ['3', '4'], + scale: [1, 1], + position: [0, 0], // composeCode: '1000' }, // {