fl-web-component 2.0.19 → 2.1.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fl-web-component.common.1.js.map +1 -1
- package/dist/fl-web-component.common.2.js.map +1 -1
- package/dist/fl-web-component.common.js +5871 -1872
- package/dist/fl-web-component.common.js.map +1 -1
- package/dist/fl-web-component.css +1 -1
- package/package.json +4 -3
- package/packages/components/com-flcanvas/components/entityFormatting.js +134 -1
- package/packages/components/com-flcanvas/index.vue +335 -239
- package/packages/components/com-graphics/index.vue +433 -35
- package/packages/components/com-graphics/mock.json +115 -0
- package/packages/utils/StreamLoader.js +250 -107
- package/packages/utils/StreamLoaderParser.worker.js +180 -72
- package/src/utils/dxf-parser/AutoCadColorIndex.js +265 -0
- package/src/utils/dxf-parser/DimStyleCodes.js +33 -0
- package/src/utils/dxf-parser/DxfArrayScanner.js +151 -0
- package/src/utils/dxf-parser/DxfParser.js +918 -0
- package/src/utils/dxf-parser/ExtendedDataParser.js +117 -0
- package/src/utils/dxf-parser/LICENSE +21 -0
- package/src/utils/dxf-parser/ParseHelpers.js +140 -0
- package/src/utils/dxf-parser/README.md +8 -0
- package/src/utils/dxf-parser/entities/3dface.js +83 -0
- package/src/utils/dxf-parser/entities/arc.js +38 -0
- package/src/utils/dxf-parser/entities/attdef.js +89 -0
- package/src/utils/dxf-parser/entities/attribute.js +109 -0
- package/src/utils/dxf-parser/entities/circle.js +43 -0
- package/src/utils/dxf-parser/entities/dimension.js +71 -0
- package/src/utils/dxf-parser/entities/ellipse.js +48 -0
- package/src/utils/dxf-parser/entities/hatch.js +348 -0
- package/src/utils/dxf-parser/entities/insert.js +57 -0
- package/src/utils/dxf-parser/entities/line.js +34 -0
- package/src/utils/dxf-parser/entities/lwpolyline.js +103 -0
- package/src/utils/dxf-parser/entities/mtext.js +57 -0
- package/src/utils/dxf-parser/entities/point.js +35 -0
- package/src/utils/dxf-parser/entities/polyline.js +92 -0
- package/src/utils/dxf-parser/entities/solid.js +40 -0
- package/src/utils/dxf-parser/entities/spline.js +70 -0
- package/src/utils/dxf-parser/entities/text.js +50 -0
- package/src/utils/dxf-parser/entities/vertex.js +62 -0
- package/src/utils/flgltf-parser.js +21 -9
- package/src/utils/instance-parser.js +59 -59
- package/src/utils/threejs/measure-clear-distance.js +149 -123
- package/packages/components/com-graphics/box.json +0 -77
|
@@ -35,45 +35,46 @@ function downloadPDF(base64, fileName) {
|
|
|
35
35
|
URL.revokeObjectURL(url); // 释放URL对象
|
|
36
36
|
}
|
|
37
37
|
import Konva from 'konva';
|
|
38
|
+
import { Vector2 } from "three";
|
|
38
39
|
import DxfParser from 'dxf-parser';
|
|
40
|
+
import DxfParser2 from '@/utils/dxf-parser/DxfParser';
|
|
39
41
|
import jsPDF from 'jspdf';
|
|
40
|
-
import { formatEntity, handleFn, centering } from './components/entityFormatting';
|
|
41
|
-
var konvaStage = null,
|
|
42
|
-
konvaLayer = null;
|
|
43
|
-
var recordLayerConfig = {};
|
|
44
|
-
var activedSvgPan = {
|
|
45
|
-
x: 0,
|
|
46
|
-
y: 0,
|
|
47
|
-
zoom: {
|
|
48
|
-
x: 1,
|
|
49
|
-
y: 1,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
42
|
+
import { formatEntity, handleFn, centering, _GenerateArcVertices, _GenerateBulgeVertices } from './components/entityFormatting';
|
|
52
43
|
export default {
|
|
53
44
|
name: 'Fl2dcanvas',
|
|
54
45
|
components: {},
|
|
55
46
|
data() {
|
|
56
47
|
return {
|
|
57
48
|
bounds: null,
|
|
58
|
-
bounds1:null,
|
|
59
|
-
|
|
49
|
+
bounds1: null,
|
|
60
50
|
};
|
|
61
51
|
},
|
|
62
52
|
created() {
|
|
53
|
+
this.konvaStage = null;
|
|
54
|
+
this.konvaLayer = null;
|
|
55
|
+
this.recordLayerConfig = {};
|
|
56
|
+
this.activedSvgPan = {
|
|
57
|
+
x: 0,
|
|
58
|
+
y: 0,
|
|
59
|
+
zoom: {
|
|
60
|
+
x: 1,
|
|
61
|
+
y: 1,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
mounted() {
|
|
63
66
|
//resize方法
|
|
64
67
|
window.addEventListener('resize', () => {
|
|
65
|
-
if (konvaStage) {
|
|
68
|
+
if (this.konvaStage) {
|
|
66
69
|
const obj = document.getElementById('konva-container');
|
|
67
|
-
konvaStage.setWidth(obj.clientWidth);
|
|
68
|
-
konvaStage.setHeight(obj.clientHeight);
|
|
69
|
-
konvaStage._resizeDOM();
|
|
70
|
+
this.konvaStage.setWidth(obj.clientWidth);
|
|
71
|
+
this.konvaStage.setHeight(obj.clientHeight);
|
|
72
|
+
this.konvaStage._resizeDOM();
|
|
70
73
|
}
|
|
71
74
|
});
|
|
72
75
|
|
|
73
76
|
this.$nextTick(() => {
|
|
74
|
-
|
|
75
|
-
console.log(this.$refs.svgDraw);
|
|
76
|
-
konvaStage = new Konva.Stage({
|
|
77
|
+
this.konvaStage = new Konva.Stage({
|
|
77
78
|
className: 'stage',
|
|
78
79
|
container: 'konva-container',
|
|
79
80
|
width: this.$refs.svgDraw.clientWidth,
|
|
@@ -81,25 +82,25 @@ export default {
|
|
|
81
82
|
draggable: true,
|
|
82
83
|
});
|
|
83
84
|
//init layer
|
|
84
|
-
konvaLayer = new Konva.Layer({
|
|
85
|
+
this.konvaLayer = new Konva.Layer({
|
|
85
86
|
name: 'konva-layer',
|
|
86
87
|
x: 0,
|
|
87
88
|
y: 0,
|
|
88
89
|
});
|
|
89
90
|
//设置清晰度
|
|
90
|
-
konvaLayer.getCanvas().setPixelRatio(2);
|
|
91
|
-
konvaStage.add(konvaLayer);
|
|
92
|
-
konvaLayer.draw();
|
|
91
|
+
this.konvaLayer.getCanvas().setPixelRatio(2);
|
|
92
|
+
this.konvaStage.add(this.konvaLayer);
|
|
93
|
+
this.konvaLayer.draw();
|
|
93
94
|
var scaleBy = 1.1;
|
|
94
95
|
//初始化缩放方法
|
|
95
|
-
konvaStage.on('wheel', e => {
|
|
96
|
+
this.konvaStage.on('wheel', e => {
|
|
96
97
|
console.log(e);
|
|
97
98
|
e.evt.preventDefault();
|
|
98
|
-
var oldScale = konvaStage.scaleX();
|
|
99
|
-
var pointer = konvaStage.getPointerPosition();
|
|
99
|
+
var oldScale = this.konvaStage.scaleX();
|
|
100
|
+
var pointer = this.konvaStage.getPointerPosition();
|
|
100
101
|
var mousePointTo = {
|
|
101
|
-
x: (pointer.x - konvaStage.x()) / oldScale,
|
|
102
|
-
y: (pointer.y - konvaStage.y()) / oldScale,
|
|
102
|
+
x: (pointer.x - this.konvaStage.x()) / oldScale,
|
|
103
|
+
y: (pointer.y - this.konvaStage.y()) / oldScale,
|
|
103
104
|
};
|
|
104
105
|
// how to scale? Zoom in? Or zoom out?
|
|
105
106
|
let direction = e.evt.deltaY > 0 ? -1 : 1;
|
|
@@ -108,34 +109,32 @@ export default {
|
|
|
108
109
|
}
|
|
109
110
|
var newScale = direction > 0 ? oldScale * scaleBy : oldScale / scaleBy;
|
|
110
111
|
this.scaleRatio = Math.ceil(newScale);
|
|
111
|
-
console.log(this.scaleRatio);
|
|
112
112
|
// 判断比例尺百分比
|
|
113
|
-
console.log(this.scaleRatio);
|
|
114
113
|
if (this.scaleRatio < 1 || this.scaleRatio >= 100) return;
|
|
115
114
|
// 设置放大缩小多少倍
|
|
116
|
-
konvaStage.scale({ x: newScale, y: newScale });
|
|
115
|
+
this.konvaStage.scale({ x: newScale, y: newScale });
|
|
117
116
|
var newPos = {
|
|
118
117
|
x: pointer.x - mousePointTo.x * newScale,
|
|
119
118
|
y: pointer.y - mousePointTo.y * newScale,
|
|
120
119
|
};
|
|
121
|
-
konvaStage.position(newPos);
|
|
120
|
+
this.konvaStage.position(newPos);
|
|
122
121
|
});
|
|
123
122
|
//双击鼠标滚轮
|
|
124
|
-
konvaStage.on(
|
|
123
|
+
this.konvaStage.on('pointerdblclick', e => {
|
|
125
124
|
/*
|
|
126
|
-
konvaStage.scale({
|
|
125
|
+
this.konvaStage.scale({
|
|
127
126
|
x: 1,
|
|
128
127
|
y: 1,
|
|
129
128
|
});
|
|
130
129
|
let x=-parseFloat(this.bounds.minX);
|
|
131
130
|
let y =-parseFloat(this.bounds.minY);
|
|
132
131
|
|
|
133
|
-
konvaStage.setX(x);
|
|
134
|
-
konvaStage.setY(y); // 750
|
|
132
|
+
this.konvaStage.setX(x);
|
|
133
|
+
this.konvaStage.setY(y); // 750
|
|
135
134
|
|
|
136
135
|
//算一下舞台中点
|
|
137
|
-
let width=konvaStage.width();
|
|
138
|
-
let height=konvaStage.height()
|
|
136
|
+
let width=this.konvaStage.width();
|
|
137
|
+
let height=this.konvaStage.height()
|
|
139
138
|
let x1=width/2;
|
|
140
139
|
let y1=height/2;
|
|
141
140
|
|
|
@@ -149,36 +148,31 @@ export default {
|
|
|
149
148
|
|
|
150
149
|
|
|
151
150
|
|
|
152
|
-
konvaStage.setX(x2);
|
|
153
|
-
konvaStage.setY(y2); // 750
|
|
151
|
+
this.konvaStage.setX(x2);
|
|
152
|
+
this.konvaStage.setY(y2); // 750
|
|
154
153
|
|
|
155
154
|
|
|
156
155
|
|
|
157
156
|
|
|
158
157
|
*/
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
162
159
|
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
this.bounds,
|
|
161
|
+
this.konvaStage.width(),
|
|
162
|
+
this.konvaStage.height(),
|
|
163
|
+
0.05 // 5% 边距
|
|
167
164
|
);
|
|
168
165
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
konvaStage.position({ x: x, y: y });
|
|
174
|
-
konvaStage.scale({ x: scale, y: scale });
|
|
175
|
-
|
|
176
|
-
konvaStage.batchDraw();
|
|
166
|
+
this.konvaStage.position({ x: x, y: y });
|
|
167
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
177
168
|
|
|
169
|
+
this.konvaStage.batchDraw();
|
|
170
|
+
});
|
|
171
|
+
this.konvaStage.on('click', e => {
|
|
172
|
+
let target = this.konvaStage.mouseClickEndShape;
|
|
173
|
+
this.$emit('leftClick', target ? target.attrs : null)
|
|
178
174
|
});
|
|
179
175
|
});
|
|
180
|
-
|
|
181
|
-
//create方法结束
|
|
182
176
|
},
|
|
183
177
|
//销毁方法
|
|
184
178
|
|
|
@@ -193,7 +187,7 @@ export default {
|
|
|
193
187
|
return {
|
|
194
188
|
scale: 1,
|
|
195
189
|
x: stageWidth / 2,
|
|
196
|
-
y: stageHeight / 2
|
|
190
|
+
y: stageHeight / 2,
|
|
197
191
|
};
|
|
198
192
|
}
|
|
199
193
|
|
|
@@ -244,20 +238,19 @@ export default {
|
|
|
244
238
|
},
|
|
245
239
|
updateBounds1(v) {
|
|
246
240
|
if (this.bounds1 === null) {
|
|
247
|
-
this.bounds1 = { minX: v.x, maxX: v.x, minY: v.y, maxY: v.y }
|
|
241
|
+
this.bounds1 = { minX: v.x, maxX: v.x, minY: v.y, maxY: v.y };
|
|
248
242
|
} else {
|
|
249
243
|
if (v.x < this.bounds1.minX) {
|
|
250
|
-
this.bounds1.minX = v.x
|
|
244
|
+
this.bounds1.minX = v.x;
|
|
251
245
|
} else if (v.x > this.bounds1.maxX) {
|
|
252
|
-
this.bounds1.maxX = v.x
|
|
246
|
+
this.bounds1.maxX = v.x;
|
|
253
247
|
}
|
|
254
248
|
if (v.y < this.bounds1.minY) {
|
|
255
|
-
this.bounds1.minY = v.y
|
|
249
|
+
this.bounds1.minY = v.y;
|
|
256
250
|
} else if (v.y > this.bounds1.maxY) {
|
|
257
|
-
this.bounds1.maxY = v.y
|
|
251
|
+
this.bounds1.maxY = v.y;
|
|
258
252
|
}
|
|
259
253
|
}
|
|
260
|
-
|
|
261
254
|
},
|
|
262
255
|
//思路是计算居中包围盒,然后排除脏数据。
|
|
263
256
|
loadDxf(data) {
|
|
@@ -270,21 +263,166 @@ export default {
|
|
|
270
263
|
}
|
|
271
264
|
}*/
|
|
272
265
|
|
|
273
|
-
konvaLayer.destroyChildren();
|
|
266
|
+
this.konvaLayer.destroyChildren();
|
|
274
267
|
const parser = new DxfParser();
|
|
275
268
|
let dxf = parser.parse(data);
|
|
276
|
-
|
|
269
|
+
const parser2 = new DxfParser2();
|
|
270
|
+
let dxf2 = parser2.parseSync(data);
|
|
271
|
+
|
|
272
|
+
let hatchEntitys = dxf2.entities;
|
|
273
|
+
// 处理HATCH部分
|
|
274
|
+
for (let i = 0; i < hatchEntitys.length; i++) {
|
|
275
|
+
let entity = hatchEntitys[i];
|
|
276
|
+
let layerConfig = this.recordLayerConfig[entity.layer];
|
|
277
|
+
let configParams =
|
|
278
|
+
layerConfig && Object.keys(layerConfig).length > 0
|
|
279
|
+
? layerConfig
|
|
280
|
+
: null;
|
|
281
|
+
let color = configParams ? configParams.color : "#000";
|
|
282
|
+
let visible = configParams ? configParams.visible : true;
|
|
283
|
+
let name = entity.layer.replace(/\s*/g, "");
|
|
284
|
+
if (entity.type == "HATCH") {
|
|
285
|
+
let boundaryLoops = entity.boundaryLoops;
|
|
286
|
+
for (let j = 0; j < boundaryLoops.length; j++) {
|
|
287
|
+
let list = [];
|
|
288
|
+
let edges = boundaryLoops[j].edges;
|
|
289
|
+
if (edges != undefined) {
|
|
290
|
+
for (let k = 0; k < edges.length; k++) {
|
|
291
|
+
let entity = edges[k];
|
|
292
|
+
if (entity.type == 3) {
|
|
293
|
+
let majorAxisEndPoint = entity.end;
|
|
294
|
+
let center = entity.start;
|
|
295
|
+
const xR = Math.sqrt(
|
|
296
|
+
majorAxisEndPoint.x * majorAxisEndPoint.x +
|
|
297
|
+
majorAxisEndPoint.y * majorAxisEndPoint.y
|
|
298
|
+
);
|
|
299
|
+
const axisRatio = entity.radius;
|
|
300
|
+
const yR = xR * axisRatio;
|
|
301
|
+
const rotation = Math.atan2(
|
|
302
|
+
majorAxisEndPoint.y,
|
|
303
|
+
majorAxisEndPoint.x
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const arcVertices = _GenerateArcVertices({
|
|
307
|
+
vertices: [],
|
|
308
|
+
center,
|
|
309
|
+
radius: xR,
|
|
310
|
+
startAngle: parseFloat(entity.startAngle),
|
|
311
|
+
endAngle: parseFloat(entity.endAngle),
|
|
312
|
+
yRadius: yR,
|
|
313
|
+
ccwAngleDir: entity.isCcw,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
if (rotation !== 0) {
|
|
317
|
+
//XXX should account angDir?
|
|
318
|
+
const cos = Math.cos(rotation);
|
|
319
|
+
const sin = Math.sin(rotation);
|
|
320
|
+
for (const v of arcVertices) {
|
|
321
|
+
const tx = v.x - center.x;
|
|
322
|
+
const ty = v.y - center.y;
|
|
323
|
+
/* Rotate the vertex around the ellipse center point. */
|
|
324
|
+
v.x = tx * cos - ty * sin + center.x;
|
|
325
|
+
v.y = tx * sin + ty * cos + center.y;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//let list = [];
|
|
329
|
+
for (let i = 0; i < arcVertices.length; i++) {
|
|
330
|
+
list.push(arcVertices[i].x);
|
|
331
|
+
list.push(-parseFloat(arcVertices[i].y));
|
|
332
|
+
}
|
|
277
333
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
334
|
+
}
|
|
335
|
+
if (entity.type == 1) {
|
|
336
|
+
|
|
337
|
+
list.push(entity.start.x);
|
|
338
|
+
list.push(-parseFloat(entity.start.y));
|
|
339
|
+
list.push(entity.end.x);
|
|
340
|
+
list.push(-parseFloat(entity.end.y));
|
|
341
|
+
//konvaLayer.add(line);
|
|
342
|
+
}
|
|
343
|
+
let line = new Konva.Line({
|
|
344
|
+
points: list,
|
|
345
|
+
name: name,
|
|
346
|
+
entityId: entity.layer,
|
|
347
|
+
strokeWidth: 0.2,
|
|
348
|
+
closed: true,
|
|
349
|
+
fill: color,
|
|
350
|
+
stroke: color,
|
|
351
|
+
customColor: color,
|
|
352
|
+
visible: visible,
|
|
353
|
+
shapeType: 'hatch'
|
|
354
|
+
});
|
|
355
|
+
this.konvaLayer.add(line);
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
let boundaryLoops = entity.boundaryLoops;
|
|
359
|
+
let loop = boundaryLoops[0];
|
|
360
|
+
if (loop.type == 7) {
|
|
361
|
+
let vertices = [];
|
|
362
|
+
for (
|
|
363
|
+
let vtxIdx = 0;
|
|
364
|
+
vtxIdx < loop.polyline.vertices.length;
|
|
365
|
+
vtxIdx++
|
|
366
|
+
) {
|
|
367
|
+
const vtx = loop.polyline.vertices[vtxIdx];
|
|
368
|
+
if ((vtx.bulge ?? 0) == 0) {
|
|
369
|
+
vertices.push(new Vector2(vtx.x, vtx.y));
|
|
370
|
+
} else {
|
|
371
|
+
const prevVtx =
|
|
372
|
+
loop.polyline.vertices[
|
|
373
|
+
vtxIdx == 0
|
|
374
|
+
? loop.polyline.vertices.length - 1
|
|
375
|
+
: vtxIdx - 1
|
|
376
|
+
];
|
|
377
|
+
if ((prevVtx.bulge ?? 0) == 0) {
|
|
378
|
+
/* Start vertex is not produced by _GenerateBulgeVertices(). */
|
|
379
|
+
vertices.push(new Vector2(vtx.x, vtx.y));
|
|
380
|
+
}
|
|
381
|
+
const nextVtx =
|
|
382
|
+
loop.polyline.vertices[
|
|
383
|
+
vtxIdx == loop.polyline.vertices.length - 1
|
|
384
|
+
? 0
|
|
385
|
+
: vtxIdx + 1
|
|
386
|
+
];
|
|
387
|
+
vertices = _GenerateBulgeVertices(
|
|
388
|
+
[],
|
|
389
|
+
vtx,
|
|
390
|
+
nextVtx,
|
|
391
|
+
vtx.bulge
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
let list = [];
|
|
396
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
397
|
+
list.push(vertices[i].x);
|
|
398
|
+
list.push(-parseFloat(vertices[i].y));
|
|
399
|
+
}
|
|
282
400
|
|
|
401
|
+
let line = new Konva.Line({
|
|
402
|
+
points: list,
|
|
403
|
+
strokeWidth: 0.2,
|
|
404
|
+
name: name,
|
|
405
|
+
entityId: entity.layer,
|
|
406
|
+
closed: true,
|
|
407
|
+
fill: color,
|
|
408
|
+
stroke: color,
|
|
409
|
+
customColor: color,
|
|
410
|
+
visible: visible,
|
|
411
|
+
shapeType: 'hatch'
|
|
412
|
+
});
|
|
413
|
+
this.konvaLayer.add(line);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
//加载图纸
|
|
420
|
+
let entities = formatEntity(dxf.entities);
|
|
283
421
|
for (let key in entities) {
|
|
284
422
|
if (entities[key]) {
|
|
285
423
|
let group = [];
|
|
286
424
|
let l = entities[key].length;
|
|
287
|
-
let layerConfig = recordLayerConfig[key];
|
|
425
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
288
426
|
let configParams =
|
|
289
427
|
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
290
428
|
for (let i = 0; i < l; i++) {
|
|
@@ -296,15 +434,15 @@ export default {
|
|
|
296
434
|
group,
|
|
297
435
|
key,
|
|
298
436
|
configParams,
|
|
299
|
-
konvaLayer,
|
|
300
|
-
recordLayerConfig
|
|
437
|
+
this.konvaLayer,
|
|
438
|
+
this.recordLayerConfig
|
|
301
439
|
);
|
|
302
440
|
}
|
|
303
|
-
if (!konvaLayer) return;
|
|
441
|
+
if (!this.konvaLayer) return;
|
|
304
442
|
for (let i = 0; i < group.length; i++) {
|
|
305
443
|
let entity = group[i];
|
|
306
444
|
if (entity.type === 'text') {
|
|
307
|
-
if (konvaLayer) konvaLayer.add(entity.obj);
|
|
445
|
+
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
308
446
|
}
|
|
309
447
|
}
|
|
310
448
|
|
|
@@ -383,22 +521,22 @@ export default {
|
|
|
383
521
|
context.fillStrokeShape(shape);
|
|
384
522
|
},
|
|
385
523
|
});
|
|
386
|
-
if (konvaLayer) konvaLayer.add(customShape);
|
|
524
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
387
525
|
}
|
|
388
526
|
}
|
|
389
527
|
//缩放视口
|
|
390
528
|
let scale = 1;
|
|
391
|
-
const boundingRect = konvaLayer.getClientRect();
|
|
529
|
+
const boundingRect = this.konvaLayer.getClientRect();
|
|
392
530
|
let ratio = Number((this.$refs.svgDraw?.clientWidth / boundingRect.width).toFixed(1));
|
|
393
531
|
if (ratio > 2) {
|
|
394
532
|
scale = Number((boundingRect.width / boundingRect.height).toFixed(1));
|
|
395
533
|
scale = scale < 2 ? 2 : scale;
|
|
396
534
|
}
|
|
397
|
-
// konvaStage.scale({
|
|
535
|
+
// this.konvaStage.scale({
|
|
398
536
|
// x: scale,
|
|
399
537
|
// y: scale,
|
|
400
538
|
//})
|
|
401
|
-
const boundingScale = konvaLayer.getClientRect();
|
|
539
|
+
const boundingScale = this.konvaLayer.getClientRect();
|
|
402
540
|
//平移视口
|
|
403
541
|
const x =
|
|
404
542
|
this.$refs.svgDraw?.clientWidth / 2 -
|
|
@@ -407,50 +545,50 @@ export default {
|
|
|
407
545
|
this.$refs.svgDraw.clientHeight / 2 -
|
|
408
546
|
(Math.ceil(boundingScale.height) / 2 + boundingScale.y);
|
|
409
547
|
|
|
410
|
-
konvaStage.scale({
|
|
548
|
+
this.konvaStage.scale({
|
|
411
549
|
x: 2,
|
|
412
550
|
y: 2,
|
|
413
551
|
});
|
|
414
|
-
konvaStage.setX(0);
|
|
415
|
-
konvaStage.setY(750); // 750
|
|
552
|
+
this.konvaStage.setX(0);
|
|
553
|
+
this.konvaStage.setY(750); // 750
|
|
416
554
|
|
|
417
|
-
activedSvgPan.zoom.x = 0;
|
|
418
|
-
activedSvgPan.zoom.y = 750;
|
|
419
|
-
activedSvgPan.x = x;
|
|
420
|
-
activedSvgPan.y = x;
|
|
555
|
+
this.activedSvgPan.zoom.x = 0;
|
|
556
|
+
this.activedSvgPan.zoom.y = 750;
|
|
557
|
+
this.activedSvgPan.x = x;
|
|
558
|
+
this.activedSvgPan.y = x;
|
|
421
559
|
setTimeout(() => {
|
|
422
560
|
this.$emit('loaded');
|
|
423
561
|
}, 100);
|
|
424
562
|
},
|
|
425
563
|
toPdf(name) {
|
|
426
|
-
//konvaStage.scale({
|
|
427
|
-
//x: activedSvgPan.zoom.x,
|
|
428
|
-
//y: activedSvgPan.zoom.y,
|
|
564
|
+
//this.konvaStage.scale({
|
|
565
|
+
//x: this.activedSvgPan.zoom.x,
|
|
566
|
+
//y: this.activedSvgPan.zoom.y,
|
|
429
567
|
//});
|
|
430
|
-
//konvaStage.setX(activedSvgPan.x);
|
|
431
|
-
//konvaStage.setY(activedSvgPan.y);
|
|
568
|
+
//this.konvaStage.setX(this.activedSvgPan.x);
|
|
569
|
+
//this.konvaStage.setY(this.activedSvgPan.y);
|
|
432
570
|
// get data URL with default settings
|
|
433
571
|
|
|
434
572
|
// open in new window
|
|
435
|
-
konvaLayer.getCanvas().setPixelRatio(2);
|
|
436
|
-
const jpegURL = konvaStage.toDataURL({
|
|
573
|
+
this.konvaLayer.getCanvas().setPixelRatio(2);
|
|
574
|
+
const jpegURL = this.konvaStage.toDataURL({
|
|
437
575
|
mimeType: 'image/jpeg',
|
|
438
576
|
quality: 1,
|
|
439
577
|
pixelRatio: 2,
|
|
440
578
|
});
|
|
441
579
|
|
|
442
|
-
let pageData = konvaLayer.canvas.toDataURL('image/jpeg', 2);
|
|
580
|
+
let pageData = this.konvaLayer.canvas.toDataURL('image/jpeg', 2);
|
|
443
581
|
|
|
444
582
|
let img = new Image();
|
|
445
583
|
img.src = jpegURL;
|
|
446
|
-
const pdf = new jsPDF('l', 'px', [konvaStage.width(), konvaStage.height()]);
|
|
584
|
+
const pdf = new jsPDF('l', 'px', [this.konvaStage.width(), this.konvaStage.height()]);
|
|
447
585
|
|
|
448
586
|
pdf.addImage(
|
|
449
|
-
konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
587
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
450
588
|
0,
|
|
451
589
|
0,
|
|
452
|
-
konvaStage.width(),
|
|
453
|
-
konvaStage.height()
|
|
590
|
+
this.konvaStage.width(),
|
|
591
|
+
this.konvaStage.height()
|
|
454
592
|
);
|
|
455
593
|
|
|
456
594
|
pdf.save(name + '.pdf');
|
|
@@ -458,36 +596,40 @@ export default {
|
|
|
458
596
|
//doc.text("Hello world!", 10, 10);
|
|
459
597
|
//doc.save("a4.pdf");
|
|
460
598
|
},
|
|
461
|
-
toPdfs(list){
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
const pdf = new jsPDF('l', 'px', [konvaStage.width(), konvaStage.height()]);
|
|
599
|
+
toPdfs(list) {
|
|
600
|
+
let _this = this;
|
|
601
|
+
const pdf = new jsPDF('l', 'px', [this.konvaStage.width(), this.konvaStage.height()]);
|
|
465
602
|
const exportPixelRatio = 2; // 可以 2/3/4 自己调
|
|
466
603
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
for(let pageIdx =0;pageIdx <list.length;pageIdx++){
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
let data=list[pageIdx];
|
|
604
|
+
for (let pageIdx = 0; pageIdx < list.length; pageIdx++) {
|
|
605
|
+
let data = list[pageIdx];
|
|
474
606
|
//先绘制图面
|
|
475
|
-
konvaLayer.destroyChildren();
|
|
607
|
+
this.konvaLayer.destroyChildren();
|
|
476
608
|
const parser = new DxfParser();
|
|
477
609
|
let dxf = parser.parse(data);
|
|
478
610
|
let entities = formatEntity(dxf.entities);
|
|
479
611
|
let layers = dxf.tables.layer.layers;
|
|
480
612
|
|
|
481
613
|
//先计算包围
|
|
482
|
-
for(let key in entities) {
|
|
614
|
+
for (let key in entities) {
|
|
483
615
|
if (entities[key]) {
|
|
484
616
|
let group = [];
|
|
485
|
-
let l = entities[key].length
|
|
486
|
-
let layerConfig = recordLayerConfig[key]
|
|
487
|
-
let configParams =
|
|
617
|
+
let l = entities[key].length;
|
|
618
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
619
|
+
let configParams =
|
|
620
|
+
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
488
621
|
for (let i = 0; i < l; i++) {
|
|
489
622
|
let type = entities[key][i].type;
|
|
490
|
-
handleFn(
|
|
623
|
+
handleFn(
|
|
624
|
+
type,
|
|
625
|
+
dxf,
|
|
626
|
+
entities[key][i],
|
|
627
|
+
group,
|
|
628
|
+
key,
|
|
629
|
+
configParams,
|
|
630
|
+
this.konvaLayer,
|
|
631
|
+
this.recordLayerConfig
|
|
632
|
+
);
|
|
491
633
|
}
|
|
492
634
|
|
|
493
635
|
for (let i = 0; i < group.length; i++) {
|
|
@@ -506,7 +648,7 @@ export default {
|
|
|
506
648
|
_this.updateBounds1(v1);
|
|
507
649
|
_this.updateBounds1(v2);
|
|
508
650
|
}
|
|
509
|
-
if (entity.type ===
|
|
651
|
+
if (entity.type === 'polyline') {
|
|
510
652
|
let flag = false;
|
|
511
653
|
let points = entity.points;
|
|
512
654
|
let closed = entity.closed;
|
|
@@ -518,112 +660,98 @@ export default {
|
|
|
518
660
|
let y = points[j + 1];
|
|
519
661
|
let point = {};
|
|
520
662
|
point.x = x;
|
|
521
|
-
point.y =
|
|
522
|
-
_this.updateBounds1(
|
|
663
|
+
point.y = y;
|
|
664
|
+
_this.updateBounds1(point);
|
|
523
665
|
}
|
|
524
|
-
|
|
525
666
|
}
|
|
526
667
|
}
|
|
527
668
|
}
|
|
528
669
|
}
|
|
529
670
|
}
|
|
530
671
|
|
|
531
|
-
|
|
532
|
-
console.log("bounds1");
|
|
672
|
+
console.log('bounds1');
|
|
533
673
|
console.log(_this.bounds1);
|
|
534
674
|
|
|
535
675
|
for (let key in entities) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
676
|
if (entities[key]) {
|
|
540
677
|
let group = [];
|
|
541
|
-
let l = entities[key].length
|
|
542
|
-
let layerConfig = recordLayerConfig[key]
|
|
543
|
-
let configParams =
|
|
678
|
+
let l = entities[key].length;
|
|
679
|
+
let layerConfig = this.recordLayerConfig[key];
|
|
680
|
+
let configParams =
|
|
681
|
+
layerConfig && Object.keys(layerConfig).length > 0 ? layerConfig : null;
|
|
544
682
|
for (let i = 0; i < l; i++) {
|
|
545
683
|
let type = entities[key][i].type;
|
|
546
|
-
handleFn(
|
|
684
|
+
handleFn(
|
|
685
|
+
type,
|
|
686
|
+
dxf,
|
|
687
|
+
entities[key][i],
|
|
688
|
+
group,
|
|
689
|
+
key,
|
|
690
|
+
configParams,
|
|
691
|
+
this.konvaLayer,
|
|
692
|
+
this.recordLayerConfig
|
|
693
|
+
);
|
|
547
694
|
}
|
|
548
|
-
if (!konvaLayer) return
|
|
549
|
-
for(let i = 0; i < group.length;i++) {
|
|
695
|
+
if (!this.konvaLayer) return;
|
|
696
|
+
for (let i = 0; i < group.length; i++) {
|
|
550
697
|
let entity = group[i];
|
|
551
698
|
if (entity.type === 'text') {
|
|
552
|
-
|
|
553
|
-
if (konvaLayer) konvaLayer.add(entity.obj);
|
|
699
|
+
if (this.konvaLayer) this.konvaLayer.add(entity.obj);
|
|
554
700
|
}
|
|
555
701
|
}
|
|
556
702
|
|
|
557
|
-
|
|
558
|
-
if( group[0].stroke==undefined){
|
|
703
|
+
if (group[0].stroke == undefined) {
|
|
559
704
|
console.log(group);
|
|
560
|
-
group[0].stroke='#000';
|
|
705
|
+
group[0].stroke = '#000';
|
|
561
706
|
}
|
|
562
707
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
let customShape = new Konva.Shape({
|
|
708
|
+
let customShape = new Konva.Shape({
|
|
568
709
|
x: 0,
|
|
569
710
|
y: 0,
|
|
570
711
|
strokeWidth: 0.2,
|
|
571
|
-
name: key.replace(/\s*/g,
|
|
712
|
+
name: key.replace(/\s*/g, ''),
|
|
572
713
|
entityId: key,
|
|
573
714
|
stroke: group[0].stroke,
|
|
574
|
-
customColor: configParams ? configParams.color :
|
|
715
|
+
customColor: configParams ? configParams.color : '',
|
|
575
716
|
//visible: configParams ? configParams.visible :true,
|
|
576
|
-
sceneFunc
|
|
717
|
+
sceneFunc(context, shape) {
|
|
577
718
|
context.beginPath();
|
|
578
|
-
for(let i = 0; i < group.length;i++){
|
|
719
|
+
for (let i = 0; i < group.length; i++) {
|
|
579
720
|
let entity = group[i];
|
|
580
721
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
let y1=entity.y1;
|
|
589
|
-
let x2=entity.x2;
|
|
590
|
-
let y2=entity.y2;
|
|
591
|
-
if(x1!=undefined&&y1!=undefined&&x2!=undefined&&y2!=undefined) {
|
|
722
|
+
if (entity.type === 'line') {
|
|
723
|
+
context.strokeStyle = entity.stroke;
|
|
724
|
+
let x1 = entity.x1;
|
|
725
|
+
let y1 = entity.y1;
|
|
726
|
+
let x2 = entity.x2;
|
|
727
|
+
let y2 = entity.y2;
|
|
728
|
+
if (x1 != undefined && y1 != undefined && x2 != undefined && y2 != undefined) {
|
|
592
729
|
context.moveTo(x1, -parseFloat(y1));
|
|
593
730
|
context.lineTo(x2, -parseFloat(y2));
|
|
594
731
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
732
|
}
|
|
599
|
-
if(entity.type ===
|
|
600
|
-
context.strokeStyle=entity.stroke;
|
|
733
|
+
if (entity.type === 'polyline') {
|
|
734
|
+
context.strokeStyle = entity.stroke;
|
|
601
735
|
|
|
602
|
-
let flag=false;
|
|
736
|
+
let flag = false;
|
|
603
737
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
let points=entity.points;
|
|
738
|
+
let points = entity.points;
|
|
607
739
|
let closed = entity.closed;
|
|
608
740
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
for(let j = 0; j < points.length; j++){
|
|
741
|
+
for (let j = 0; j < points.length; j++) {
|
|
612
742
|
let index = j % 2;
|
|
613
|
-
if(index === 0){
|
|
743
|
+
if (index === 0) {
|
|
614
744
|
let x = points[j];
|
|
615
|
-
let y = points[j+1];
|
|
616
|
-
|
|
617
|
-
|
|
745
|
+
let y = points[j + 1];
|
|
618
746
|
|
|
619
|
-
if(j === 0){
|
|
747
|
+
if (j === 0) {
|
|
620
748
|
context.moveTo(x, y);
|
|
621
|
-
}else{
|
|
622
|
-
context.lineTo(x,y);
|
|
749
|
+
} else {
|
|
750
|
+
context.lineTo(x, y);
|
|
623
751
|
}
|
|
624
752
|
}
|
|
625
753
|
|
|
626
|
-
if(closed) {
|
|
754
|
+
if (closed) {
|
|
627
755
|
if (j === points.length - 1) {
|
|
628
756
|
context.lineTo(points[0], points[1]);
|
|
629
757
|
}
|
|
@@ -633,94 +761,62 @@ export default {
|
|
|
633
761
|
}
|
|
634
762
|
// context.closePath();
|
|
635
763
|
context.fillStrokeShape(shape);
|
|
636
|
-
}
|
|
764
|
+
},
|
|
637
765
|
});
|
|
638
|
-
if (konvaLayer) konvaLayer.add(customShape);
|
|
766
|
+
if (this.konvaLayer) this.konvaLayer.add(customShape);
|
|
639
767
|
}
|
|
640
768
|
}
|
|
641
769
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
770
|
const { scale, x, y } = this.calculateScaleAndPosition(
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
771
|
+
_this.bounds1,
|
|
772
|
+
this.konvaStage.width(),
|
|
773
|
+
this.konvaStage.height(),
|
|
774
|
+
0.05 // 5% 边距
|
|
651
775
|
);
|
|
652
|
-
console.log(
|
|
776
|
+
console.log('test1:');
|
|
653
777
|
console.log(this.bounds1);
|
|
654
778
|
|
|
655
|
-
_this.bounds1=null;
|
|
656
|
-
|
|
779
|
+
_this.bounds1 = null;
|
|
657
780
|
|
|
781
|
+
this.konvaStage.position({ x: x, y: y });
|
|
782
|
+
this.konvaStage.scale({ x: scale, y: scale });
|
|
658
783
|
|
|
659
|
-
|
|
660
|
-
konvaStage.position({ x: x, y: y });
|
|
661
|
-
konvaStage.scale({ x: scale, y: scale });
|
|
662
|
-
|
|
663
|
-
konvaStage.batchDraw();
|
|
784
|
+
this.konvaStage.batchDraw();
|
|
664
785
|
//添加成功移动视口位置
|
|
665
786
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if(pageIdx==0){
|
|
787
|
+
if (pageIdx == 0) {
|
|
674
788
|
pdf.addImage(
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
789
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
790
|
+
0,
|
|
791
|
+
0,
|
|
792
|
+
this.konvaStage.width(),
|
|
793
|
+
this.konvaStage.height()
|
|
680
794
|
);
|
|
681
|
-
|
|
682
|
-
}else{
|
|
683
|
-
|
|
795
|
+
} else {
|
|
684
796
|
pdf.addPage();
|
|
685
797
|
pdf.addImage(
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
798
|
+
this.konvaStage.toDataURL({ pixelRatio: 2 }),
|
|
799
|
+
0,
|
|
800
|
+
0,
|
|
801
|
+
this.konvaStage.width(),
|
|
802
|
+
this.konvaStage.height()
|
|
691
803
|
);
|
|
692
|
-
|
|
693
804
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
805
|
}
|
|
703
|
-
pdf.save(
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
806
|
+
pdf.save('批量导出.pdf');
|
|
711
807
|
|
|
712
808
|
// var imgData = canvas.toDataURL('image/png');
|
|
713
809
|
//doc.text("Hello world!", 10, 10);
|
|
714
810
|
//doc.save("a4.pdf");
|
|
715
811
|
},
|
|
716
812
|
clearCache() {
|
|
717
|
-
konvaLayer && konvaLayer.destroyChildren();
|
|
718
|
-
konvaLayer && konvaLayer.destroy();
|
|
719
|
-
konvaLayer && konvaLayer.clear();
|
|
720
|
-
konvaStage && konvaStage.destroy();
|
|
721
|
-
konvaStage && konvaStage.clearCache();
|
|
722
|
-
konvaLayer = null;
|
|
723
|
-
konvaStage = null;
|
|
813
|
+
this.konvaLayer && this.konvaLayer.destroyChildren();
|
|
814
|
+
this.konvaLayer && this.konvaLayer.destroy();
|
|
815
|
+
this.konvaLayer && this.konvaLayer.clear();
|
|
816
|
+
this.konvaStage && this.konvaStage.destroy();
|
|
817
|
+
this.konvaStage && this.konvaStage.clearCache();
|
|
818
|
+
this.konvaLayer = null;
|
|
819
|
+
this.konvaStage = null;
|
|
724
820
|
},
|
|
725
821
|
beforeDestroy() {
|
|
726
822
|
this.clearCache();
|