@mlightcad/libredwg-converter 3.5.21 → 3.5.22
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/LICENSE +21 -21
- package/README.md +52 -52
- package/dist/libredwg-converter.js +154 -152
- package/dist/libredwg-converter.umd.cjs +1 -1
- package/dist/libredwg-parser-worker.js +102 -102
- package/lib/AcDbEntitiyConverter.d.ts.map +1 -1
- package/lib/AcDbEntitiyConverter.js +4 -1
- package/lib/AcDbEntitiyConverter.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AcDbFace as v, AcDbArc as O, AcGeVector3d as D, AcDbCircle as m, AcDbEllipse as k, AcDbLine as F, AcGePoint3d as w, AcDbSpline as T, AcDbPoint as R, AcDbTrace as V, AcDbPolyline as N, AcGePoint2d as b, AcDbPolygonMesh as B, AcDbPolyFaceMesh as z, AcDbPoly2dType as A, AcDb2dPolyline as j, AcDbPoly3dType as y, AcDb3dPolyline as W, AcDbHatch as H, AcGePolyline2d as X, AcGeLine2d as U, AcGeCircArc2d as G, AcGeVector2d as Y, AcGeEllipseArc2d as _, AcGeSpline3d as P, AcGeLoop2d as E, AcDbTable as Z, AcDbText as K, AcDbMText as q, AcDbLeader as J, AcDbAlignedDimension as Q, AcDb3PointAngularDimension as $, AcDbOrdinateDimension as ee, AcDbRadialDimension as ne, AcDbDiametricDimension as oe, AcDbRasterImage as te, AcDbWipeout as se, AcDbViewport as re, AcDbRay as ie, AcDbXline as ce, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as M, AcDbAttribute as
|
|
1
|
+
import { AcDbFace as v, AcDbArc as O, AcGeVector3d as D, AcDbCircle as m, AcDbEllipse as k, AcDbLine as F, AcGePoint3d as w, AcDbSpline as T, AcDbPoint as R, AcDbTrace as V, AcDbPolyline as N, AcGePoint2d as b, AcDbPolygonMesh as B, AcDbPolyFaceMesh as z, AcDbPoly2dType as A, AcDb2dPolyline as j, AcDbPoly3dType as y, AcDb3dPolyline as W, AcDbHatch as H, AcGePolyline2d as X, AcGeLine2d as U, AcGeCircArc2d as G, AcGeVector2d as Y, AcGeEllipseArc2d as _, AcGeSpline3d as P, AcGeLoop2d as E, AcDbTable as Z, AcDbText as K, AcDbMText as q, AcDbLeader as J, AcDbAlignedDimension as Q, AcDb3PointAngularDimension as $, AcDbOrdinateDimension as ee, AcDbRadialDimension as ne, AcDbDiametricDimension as oe, AcDbRasterImage as te, AcDbWipeout as se, AcDbViewport as re, AcDbRay as ie, AcDbXline as ce, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as M, AcDbAttribute as ae, AcDbAttributeDefinition as le, AcDbBlockReference as de, AcCmTransparency as pe, AcDbDatabaseConverter as ue, createWorkerApi as fe, AcDbLinetypeTableRecord as he, AcDbTextStyleTableRecord as ge, DEFAULT_TEXT_STYLE as L, AcDbDimStyleTableRecord as De, AcCmColor as Ae, AcDbLayerTableRecord as Ie, AcDbViewportTableRecord as ye, AcDbBlockTableRecord as we, AcDbBatchProcessing as Te, ByLayer as be, AcDbLayout as Pe, AcDbRasterImageDef as Ee } from "@mlightcad/data-model";
|
|
2
2
|
class C {
|
|
3
3
|
convert(e) {
|
|
4
4
|
const n = this.createEntity(e);
|
|
@@ -28,22 +28,22 @@ class C {
|
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
convertEllipse(e) {
|
|
31
|
-
const n = new D(e.majorAxisEndPoint),
|
|
31
|
+
const n = new D(e.majorAxisEndPoint), s = n.length();
|
|
32
32
|
return new k(
|
|
33
33
|
e.center,
|
|
34
34
|
e.extrusionDirection ?? D.Z_AXIS,
|
|
35
35
|
n,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
s,
|
|
37
|
+
s * e.axisRatio,
|
|
38
38
|
e.startAngle,
|
|
39
39
|
e.endAngle
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
convertLine(e) {
|
|
43
|
-
const n = e.startPoint,
|
|
43
|
+
const n = e.startPoint, s = e.endPoint;
|
|
44
44
|
return new F(
|
|
45
45
|
new w(n.x, n.y, n.z),
|
|
46
|
-
new w(
|
|
46
|
+
new w(s.x, s.y, s.z)
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
convertSpline(e) {
|
|
@@ -80,18 +80,20 @@ class C {
|
|
|
80
80
|
}
|
|
81
81
|
convertLWPolyline(e) {
|
|
82
82
|
const n = new N();
|
|
83
|
-
|
|
83
|
+
n.closed = !!(e.flag & 512);
|
|
84
|
+
const s = e.constantWidth ?? -1;
|
|
85
|
+
return e.vertices.forEach((o, t) => {
|
|
84
86
|
n.addVertexAt(
|
|
85
|
-
|
|
86
|
-
new b(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
t,
|
|
88
|
+
new b(o.x, o.y),
|
|
89
|
+
o.bulge,
|
|
90
|
+
o.startWidth ?? s,
|
|
91
|
+
o.endWidth ?? s
|
|
90
92
|
);
|
|
91
93
|
}), n;
|
|
92
94
|
}
|
|
93
95
|
convertPolyline2d(e) {
|
|
94
|
-
const n = !!(e.flag & 1),
|
|
96
|
+
const n = !!(e.flag & 1), s = !!(e.flag & 16), o = !!(e.flag & 64), t = !!(e.flag & 32), r = [], l = [], c = [];
|
|
95
97
|
if (e.vertices.map((i) => {
|
|
96
98
|
if (!(i.flag & 16))
|
|
97
99
|
if (o && i.flag & 128)
|
|
@@ -100,7 +102,7 @@ class C {
|
|
|
100
102
|
x: i.x,
|
|
101
103
|
y: i.y,
|
|
102
104
|
z: i.z
|
|
103
|
-
}),
|
|
105
|
+
}), l.push(i.bulge ?? 0);
|
|
104
106
|
else {
|
|
105
107
|
const d = [];
|
|
106
108
|
i.polyfaceIndex0 != null && i.polyfaceIndex0 != 0 && d.push(Math.abs(i.polyfaceIndex0) - 1), i.polyfaceIndex1 != null && i.polyfaceIndex1 != 0 && d.push(Math.abs(i.polyfaceIndex1) - 1), i.polyfaceIndex2 != null && i.polyfaceIndex2 != 0 && d.push(Math.abs(i.polyfaceIndex2) - 1), i.polyfaceIndex3 != null && i.polyfaceIndex3 != 0 && d.push(Math.abs(i.polyfaceIndex3) - 1), d.length >= 3 && c.push(d);
|
|
@@ -110,10 +112,10 @@ class C {
|
|
|
110
112
|
x: i.x,
|
|
111
113
|
y: i.y,
|
|
112
114
|
z: i.z
|
|
113
|
-
}),
|
|
114
|
-
}),
|
|
115
|
+
}), l.push(i.bulge ?? 0);
|
|
116
|
+
}), s) {
|
|
115
117
|
const i = e.meshMVertexCount ?? 2, d = e.meshNVertexCount ?? 2;
|
|
116
|
-
return new B(i, d, r, n,
|
|
118
|
+
return new B(i, d, r, n, t);
|
|
117
119
|
} else {
|
|
118
120
|
if (o)
|
|
119
121
|
return new z(r, c);
|
|
@@ -126,37 +128,37 @@ class C {
|
|
|
126
128
|
n,
|
|
127
129
|
e.startWidth,
|
|
128
130
|
e.endWidth,
|
|
129
|
-
|
|
131
|
+
l
|
|
130
132
|
);
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
convertPolyline3d(e) {
|
|
135
|
-
const n = !!(e.flag & 1),
|
|
136
|
-
e.vertices.map((
|
|
137
|
-
|
|
138
|
-
x:
|
|
139
|
-
y:
|
|
140
|
-
z:
|
|
137
|
+
const n = !!(e.flag & 1), s = [];
|
|
138
|
+
e.vertices.map((t) => {
|
|
139
|
+
t.flag & 16 || s.push({
|
|
140
|
+
x: t.x,
|
|
141
|
+
y: t.y,
|
|
142
|
+
z: t.z
|
|
141
143
|
});
|
|
142
144
|
});
|
|
143
145
|
let o = y.SimplePoly;
|
|
144
|
-
return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new W(o,
|
|
146
|
+
return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new W(o, s, n);
|
|
145
147
|
}
|
|
146
148
|
convertHatch(e) {
|
|
147
149
|
var o;
|
|
148
150
|
const n = new H();
|
|
149
|
-
return (o = e.definitionLines) == null || o.forEach((
|
|
151
|
+
return (o = e.definitionLines) == null || o.forEach((t) => {
|
|
150
152
|
n.definitionLines.push({
|
|
151
|
-
angle:
|
|
152
|
-
base:
|
|
153
|
-
offset:
|
|
154
|
-
dashLengths:
|
|
153
|
+
angle: t.angle,
|
|
154
|
+
base: t.base,
|
|
155
|
+
offset: t.offset,
|
|
156
|
+
dashLengths: t.numberOfDashLengths > 0 ? t.dashLengths : []
|
|
155
157
|
});
|
|
156
|
-
}), n.isSolidFill = e.solidFill == 1, n.hatchStyle = e.hatchStyle, n.patternName = e.patternName, n.patternType = e.patternType, n.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, n.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
c.closed =
|
|
158
|
+
}), n.isSolidFill = e.solidFill == 1, n.hatchStyle = e.hatchStyle, n.patternName = e.patternName, n.patternType = e.patternType, n.patternAngle = e.patternAngle == null ? 0 : e.patternAngle, n.patternScale = e.patternScale == null ? 0 : e.patternScale, e.boundaryPaths.forEach((t) => {
|
|
159
|
+
if (t.boundaryPathTypeFlag & 2) {
|
|
160
|
+
const l = t, c = new X();
|
|
161
|
+
c.closed = l.isClosed, l.vertices.forEach((i, d) => {
|
|
160
162
|
c.addVertexAt(d, {
|
|
161
163
|
x: i.x,
|
|
162
164
|
y: i.y,
|
|
@@ -164,46 +166,46 @@ class C {
|
|
|
164
166
|
});
|
|
165
167
|
}), n.add(c);
|
|
166
168
|
} else {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
+
const l = t, c = [];
|
|
170
|
+
l.edges.forEach((d) => {
|
|
169
171
|
if (d != null) {
|
|
170
172
|
if (d.type == 1) {
|
|
171
|
-
const
|
|
172
|
-
c.push(new U(
|
|
173
|
+
const a = d;
|
|
174
|
+
c.push(new U(a.start, a.end));
|
|
173
175
|
} else if (d.type == 2) {
|
|
174
|
-
const
|
|
176
|
+
const a = d;
|
|
175
177
|
c.push(
|
|
176
178
|
new G(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
!
|
|
179
|
+
a.center,
|
|
180
|
+
a.radius,
|
|
181
|
+
a.startAngle,
|
|
182
|
+
a.endAngle,
|
|
183
|
+
!a.isCCW
|
|
182
184
|
)
|
|
183
185
|
);
|
|
184
186
|
} else if (d.type == 3) {
|
|
185
|
-
const
|
|
186
|
-
new Y().subVectors(
|
|
187
|
+
const a = d;
|
|
188
|
+
new Y().subVectors(a.end, a.center);
|
|
187
189
|
const p = Math.sqrt(
|
|
188
|
-
Math.pow(
|
|
189
|
-
), u = p *
|
|
190
|
-
let f =
|
|
191
|
-
const x = Math.atan2(
|
|
192
|
-
|
|
190
|
+
Math.pow(a.end.x, 2) + Math.pow(a.end.y, 2)
|
|
191
|
+
), u = p * a.lengthOfMinorAxis;
|
|
192
|
+
let f = a.startAngle, g = a.endAngle;
|
|
193
|
+
const x = Math.atan2(a.end.y, a.end.x);
|
|
194
|
+
a.isCCW || (f = Math.PI * 2 - f, g = Math.PI * 2 - g), c.push(
|
|
193
195
|
new _(
|
|
194
|
-
{ ...
|
|
196
|
+
{ ...a.center, z: 0 },
|
|
195
197
|
p,
|
|
196
198
|
u,
|
|
197
199
|
f,
|
|
198
200
|
g,
|
|
199
|
-
!
|
|
201
|
+
!a.isCCW,
|
|
200
202
|
x
|
|
201
203
|
)
|
|
202
204
|
);
|
|
203
205
|
} else if (d.type == 4) {
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
206
|
-
const h =
|
|
206
|
+
const a = d;
|
|
207
|
+
if (a.numberOfControlPoints > 0 && a.numberOfKnots > 0) {
|
|
208
|
+
const h = a.controlPoints.map(
|
|
207
209
|
(f) => ({
|
|
208
210
|
x: f.x,
|
|
209
211
|
y: f.y,
|
|
@@ -211,16 +213,16 @@ class C {
|
|
|
211
213
|
})
|
|
212
214
|
);
|
|
213
215
|
let p = !0;
|
|
214
|
-
const u =
|
|
216
|
+
const u = a.controlPoints.map((f) => (f.weight == null && (p = !1), f.weight || 1));
|
|
215
217
|
c.push(
|
|
216
218
|
new P(
|
|
217
219
|
h,
|
|
218
|
-
|
|
220
|
+
a.knots,
|
|
219
221
|
p ? u : void 0
|
|
220
222
|
)
|
|
221
223
|
);
|
|
222
|
-
} else if (
|
|
223
|
-
const h =
|
|
224
|
+
} else if (a.numberOfFitData > 0) {
|
|
225
|
+
const h = a.fitDatum.map((p) => ({
|
|
224
226
|
x: p.x,
|
|
225
227
|
y: p.y,
|
|
226
228
|
z: 0
|
|
@@ -242,11 +244,11 @@ class C {
|
|
|
242
244
|
e.columnCount
|
|
243
245
|
);
|
|
244
246
|
return n.tableStyleId = e.tableStyleId, n.owningBlockRecordId = e.blockRecordHandle, e.directionVector && (n.horizontalDirection = new D(e.directionVector)), n.attachmentPoint = e.attachmentPoint, n.position.copy(e.startPoint), n.tableValueFlag = e.tableValue, n.tableOverrideFlag = e.overrideFlag, n.borderColorOverrideFlag = e.borderColorOverrideFlag, n.borderLineweightOverrideFlag = e.borderLineWeightOverrideFlag, n.borderVisibilityOverrideFlag = e.borderVisibilityOverrideFlag, e.columnWidthArr.forEach(
|
|
245
|
-
(
|
|
247
|
+
(s, o) => n.setColumnWidth(o, s)
|
|
246
248
|
), e.rowHeightArr.forEach(
|
|
247
|
-
(
|
|
248
|
-
), e.cells.forEach((
|
|
249
|
-
n.setCell(o,
|
|
249
|
+
(s, o) => n.setRowHeight(o, s)
|
|
250
|
+
), e.cells.forEach((s, o) => {
|
|
251
|
+
n.setCell(o, s);
|
|
250
252
|
}), n;
|
|
251
253
|
}
|
|
252
254
|
convertText(e) {
|
|
@@ -259,56 +261,56 @@ class C {
|
|
|
259
261
|
}
|
|
260
262
|
convertLeader(e) {
|
|
261
263
|
const n = new J();
|
|
262
|
-
return e.vertices.forEach((
|
|
263
|
-
n.appendVertex(
|
|
264
|
+
return e.vertices.forEach((s) => {
|
|
265
|
+
n.appendVertex(s);
|
|
264
266
|
}), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
|
|
265
267
|
}
|
|
266
268
|
convertDimension(e) {
|
|
267
269
|
if (e.subclassMarker == "AcDbAlignedDimension" || e.subclassMarker == "AcDbRotatedDimension") {
|
|
268
|
-
const n = e,
|
|
270
|
+
const n = e, s = new Q(
|
|
269
271
|
n.subDefinitionPoint1,
|
|
270
272
|
n.subDefinitionPoint2,
|
|
271
273
|
n.definitionPoint
|
|
272
274
|
);
|
|
273
|
-
return n.insertionPoint && (
|
|
275
|
+
return n.insertionPoint && (s.dimBlockPosition = {
|
|
274
276
|
x: n.insertionPoint.x,
|
|
275
277
|
y: n.insertionPoint.y,
|
|
276
278
|
z: 0
|
|
277
|
-
}),
|
|
279
|
+
}), s.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, s), s;
|
|
278
280
|
} else if (e.subclassMarker == "AcDb3PointAngularDimension") {
|
|
279
|
-
const n = e,
|
|
281
|
+
const n = e, s = new $(
|
|
280
282
|
n.centerPoint,
|
|
281
283
|
n.subDefinitionPoint1,
|
|
282
284
|
n.subDefinitionPoint2,
|
|
283
285
|
n.definitionPoint
|
|
284
286
|
);
|
|
285
|
-
return this.processDimensionCommonAttrs(e,
|
|
287
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
286
288
|
} else if (e.subclassMarker == "AcDbOrdinateDimension") {
|
|
287
|
-
const n = e,
|
|
289
|
+
const n = e, s = new ee(
|
|
288
290
|
n.subDefinitionPoint1,
|
|
289
291
|
n.subDefinitionPoint2
|
|
290
292
|
);
|
|
291
|
-
return this.processDimensionCommonAttrs(e,
|
|
293
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
292
294
|
} else if (e.subclassMarker == "AcDbRadialDimension") {
|
|
293
|
-
const n = e,
|
|
295
|
+
const n = e, s = new ne(
|
|
294
296
|
n.definitionPoint,
|
|
295
297
|
n.centerPoint,
|
|
296
298
|
n.leaderLength
|
|
297
299
|
);
|
|
298
|
-
return this.processDimensionCommonAttrs(e,
|
|
300
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
299
301
|
} else if (e.subclassMarker == "AcDbDiametricDimension") {
|
|
300
|
-
const n = e,
|
|
302
|
+
const n = e, s = new oe(
|
|
301
303
|
n.definitionPoint,
|
|
302
304
|
n.centerPoint,
|
|
303
305
|
n.leaderLength
|
|
304
306
|
);
|
|
305
|
-
return this.processDimensionCommonAttrs(e,
|
|
307
|
+
return this.processDimensionCommonAttrs(e, s), s;
|
|
306
308
|
}
|
|
307
309
|
return null;
|
|
308
310
|
}
|
|
309
311
|
processImage(e, n) {
|
|
310
|
-
n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageSize.copy(e.imageSize), n.imageDefId = e.imageDefHandle, n.isClipped = e.clipping > 0, n.isShownClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((
|
|
311
|
-
n.clipBoundary.push(new b(
|
|
312
|
+
n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageSize.copy(e.imageSize), n.imageDefId = e.imageDefHandle, n.isClipped = e.clipping > 0, n.isShownClipped = (e.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((s) => {
|
|
313
|
+
n.clipBoundary.push(new b(s));
|
|
312
314
|
}), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
|
|
313
315
|
e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
|
|
314
316
|
) * e.imageSize.x, n.height = Math.sqrt(
|
|
@@ -336,21 +338,21 @@ class C {
|
|
|
336
338
|
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
337
339
|
}
|
|
338
340
|
convertAttributeCommon(e, n) {
|
|
339
|
-
const
|
|
340
|
-
n.textString =
|
|
341
|
+
const s = e.text;
|
|
342
|
+
n.textString = s.text, n.styleName = s.styleName, n.height = s.textHeight, n.position.copy(s.startPoint), n.rotation = s.rotation, n.oblique = s.obliqueAngle ?? 0, n.thickness = s.thickness, n.horizontalMode = s.halign, n.verticalMode = s.valign, n.widthFactor = s.xScale ?? 1, n.tag = e.tag, n.fieldLength = e.fieldLength, n.isInvisible = (e.flags & I.Invisible) !== 0, n.isConst = (e.flags & I.Const) !== 0, n.isVerifiable = (e.flags & I.Verifiable) !== 0, n.isPreset = (e.flags & I.Preset) !== 0, n.lockPositionInBlock = e.lockPositionFlag, n.isReallyLocked = e.isReallyLocked, n.isMTextAttribute = (e.mtextFlag & M.MultiLine) !== 0, n.isConstMTextAttribute = (e.mtextFlag & M.ConstMultiLine) !== 0;
|
|
341
343
|
}
|
|
342
344
|
convertAttribute(e) {
|
|
343
|
-
const n = new
|
|
345
|
+
const n = new ae();
|
|
344
346
|
return this.convertAttributeCommon(e, n), n;
|
|
345
347
|
}
|
|
346
348
|
convertAttributeDefinition(e) {
|
|
347
|
-
const n = new
|
|
349
|
+
const n = new le();
|
|
348
350
|
return this.convertAttributeCommon(e, n), n.prompt = e.prompt, n;
|
|
349
351
|
}
|
|
350
352
|
convertBlockReference(e) {
|
|
351
353
|
const n = new de(e.name);
|
|
352
|
-
return e.insertionPoint && n.position.copy(e.insertionPoint), n.scaleFactors.x = e.xScale, n.scaleFactors.y = e.yScale, n.scaleFactors.z = e.zScale, n.rotation = e.rotation, n.normal.copy(e.extrusionDirection), e.attribs && e.attribs.forEach((
|
|
353
|
-
const o = this.convertAttribute(
|
|
354
|
+
return e.insertionPoint && n.position.copy(e.insertionPoint), n.scaleFactors.x = e.xScale, n.scaleFactors.y = e.yScale, n.scaleFactors.z = e.zScale, n.rotation = e.rotation, n.normal.copy(e.extrusionDirection), e.attribs && e.attribs.forEach((s) => {
|
|
355
|
+
const o = this.convertAttribute(s);
|
|
354
356
|
n.appendAttributes(o);
|
|
355
357
|
}), n;
|
|
356
358
|
}
|
|
@@ -359,8 +361,8 @@ class C {
|
|
|
359
361
|
}
|
|
360
362
|
processCommonAttrs(e, n) {
|
|
361
363
|
if (n.layer = e.layer || "0", n.objectId = e.handle, n.ownerId = e.ownerBlockRecordSoftId, e.lineType != null && (n.lineType = e.lineType), e.lineweight != null && (n.lineWeight = e.lineweight), e.lineTypeScale != null && (n.linetypeScale = e.lineTypeScale), e.color != null && n.color.setRGBValue(e.color), e.colorIndex != null && (n.color.colorIndex = e.colorIndex), e.colorName && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null) {
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
+
const s = new pe();
|
|
365
|
+
s.method = e.transparencyType, (s.isByBlock || s.isByBlock) && (s.alpha = e.transparency), n.transparency = s;
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
368
|
}
|
|
@@ -370,14 +372,14 @@ class Ce extends ue {
|
|
|
370
372
|
super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
|
|
371
373
|
}
|
|
372
374
|
async parse(e, n) {
|
|
373
|
-
const
|
|
374
|
-
if (
|
|
375
|
-
const
|
|
376
|
-
workerUrl:
|
|
375
|
+
const s = this.config, o = this.getParserWorkerTimeout(e, n);
|
|
376
|
+
if (s.useWorker && s.parserWorkerUrl) {
|
|
377
|
+
const t = fe({
|
|
378
|
+
workerUrl: s.parserWorkerUrl,
|
|
377
379
|
timeout: o,
|
|
378
380
|
maxConcurrentWorkers: 1
|
|
379
|
-
}), r = await
|
|
380
|
-
if (
|
|
381
|
+
}), r = await t.execute(e);
|
|
382
|
+
if (t.destroy(), r.success)
|
|
381
383
|
return r.data;
|
|
382
384
|
throw new Error(
|
|
383
385
|
`Failed to parse drawing due to error: '${r.error}'`
|
|
@@ -390,60 +392,60 @@ class Ce extends ue {
|
|
|
390
392
|
e.tables.BLOCK_RECORD.entries.forEach((r) => {
|
|
391
393
|
n.set(r.name, r);
|
|
392
394
|
});
|
|
393
|
-
const
|
|
395
|
+
const s = /* @__PURE__ */ new Map(), o = (r) => {
|
|
394
396
|
if (r) {
|
|
395
|
-
const
|
|
396
|
-
return
|
|
397
|
+
const l = r.lastIndexOf(".");
|
|
398
|
+
return l >= 0 ? r.substring(0, l).toLowerCase() : r.toLowerCase();
|
|
397
399
|
}
|
|
398
400
|
};
|
|
399
401
|
e.tables.STYLE.entries.forEach((r) => {
|
|
400
|
-
const
|
|
402
|
+
const l = [];
|
|
401
403
|
let c = o(r.font);
|
|
402
|
-
c &&
|
|
404
|
+
c && l.push(c), c = o(r.bigFont), c && l.push(c), s.set(r.name, l);
|
|
403
405
|
});
|
|
404
|
-
const
|
|
405
|
-
return this.getFontsInBlock(e.entities, n,
|
|
406
|
+
const t = /* @__PURE__ */ new Set();
|
|
407
|
+
return this.getFontsInBlock(e.entities, n, s, t), Array.from(t);
|
|
406
408
|
}
|
|
407
|
-
getFontsInBlock(e, n,
|
|
408
|
-
const
|
|
409
|
+
getFontsInBlock(e, n, s, o) {
|
|
410
|
+
const t = /\\f(.*?)\|/g;
|
|
409
411
|
e.forEach((r) => {
|
|
410
412
|
if (r.type == "MTEXT") {
|
|
411
|
-
const
|
|
412
|
-
[...
|
|
413
|
+
const l = r;
|
|
414
|
+
[...l.text.matchAll(t)].forEach((i) => {
|
|
413
415
|
o.add(i[1].toLowerCase());
|
|
414
416
|
});
|
|
415
|
-
const c =
|
|
417
|
+
const c = s.get(l.styleName);
|
|
416
418
|
c == null || c.forEach((i) => o.add(i));
|
|
417
419
|
} else if (r.type == "TEXT") {
|
|
418
|
-
const
|
|
420
|
+
const l = r, c = s.get(l.styleName);
|
|
419
421
|
c == null || c.forEach((i) => o.add(i));
|
|
420
422
|
} else if (r.type == "INSERT") {
|
|
421
|
-
const
|
|
422
|
-
c && this.getFontsInBlock(c.entities, n,
|
|
423
|
+
const l = r, c = n.get(l.name);
|
|
424
|
+
c && this.getFontsInBlock(c.entities, n, s, o);
|
|
423
425
|
}
|
|
424
426
|
});
|
|
425
427
|
}
|
|
426
428
|
processLineTypes(e, n) {
|
|
427
429
|
e.tables.LTYPE.entries.forEach((o) => {
|
|
428
|
-
const
|
|
430
|
+
const t = {
|
|
429
431
|
name: o.name,
|
|
430
432
|
description: o.description,
|
|
431
433
|
standardFlag: o.standardFlag,
|
|
432
434
|
totalPatternLength: o.totalPatternLength,
|
|
433
435
|
pattern: o.pattern
|
|
434
|
-
}, r = new he(
|
|
436
|
+
}, r = new he(t);
|
|
435
437
|
this.processCommonTableEntryAttrs(o, r), r.name = o.name, n.tables.linetypeTable.add(r);
|
|
436
438
|
});
|
|
437
439
|
}
|
|
438
440
|
processTextStyles(e, n) {
|
|
439
441
|
e.tables.STYLE.entries.forEach((o) => {
|
|
440
|
-
const
|
|
441
|
-
this.processCommonTableEntryAttrs(o,
|
|
442
|
+
const t = new ge(o);
|
|
443
|
+
this.processCommonTableEntryAttrs(o, t), n.tables.textStyleTable.add(t);
|
|
442
444
|
});
|
|
443
445
|
}
|
|
444
446
|
processDimStyles(e, n) {
|
|
445
447
|
e.tables.DIMSTYLE.entries.forEach((o) => {
|
|
446
|
-
const
|
|
448
|
+
const t = {
|
|
447
449
|
name: o.name,
|
|
448
450
|
ownerId: o.ownerHandle,
|
|
449
451
|
dimpost: o.DIMPOST || "",
|
|
@@ -512,21 +514,21 @@ class Ce extends ue {
|
|
|
512
514
|
dimblk2: o.DIMBLK2 || "",
|
|
513
515
|
dimlwd: o.DIMLWD,
|
|
514
516
|
dimlwe: o.DIMLWE
|
|
515
|
-
}, r = new De(
|
|
517
|
+
}, r = new De(t);
|
|
516
518
|
this.processCommonTableEntryAttrs(o, r), n.tables.dimStyleTable.add(r);
|
|
517
519
|
});
|
|
518
520
|
}
|
|
519
521
|
processLayers(e, n) {
|
|
520
522
|
e.tables.LAYER.entries.forEach((o) => {
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
+
const t = new Ae();
|
|
524
|
+
t.colorIndex = o.colorIndex;
|
|
523
525
|
const r = new Ie({
|
|
524
526
|
name: o.name,
|
|
525
527
|
standardFlags: o.standardFlag,
|
|
526
528
|
linetype: o.lineType,
|
|
527
529
|
lineWeight: o.lineweight,
|
|
528
530
|
isOff: o.off,
|
|
529
|
-
color:
|
|
531
|
+
color: t,
|
|
530
532
|
isPlottable: o.plotFlag != 0
|
|
531
533
|
});
|
|
532
534
|
this.processCommonTableEntryAttrs(o, r), n.tables.layerTable.add(r);
|
|
@@ -534,54 +536,54 @@ class Ce extends ue {
|
|
|
534
536
|
}
|
|
535
537
|
processViewports(e, n) {
|
|
536
538
|
e.tables.VPORT.entries.forEach((o) => {
|
|
537
|
-
const
|
|
538
|
-
this.processCommonTableEntryAttrs(o,
|
|
539
|
+
const t = new ye();
|
|
540
|
+
this.processCommonTableEntryAttrs(o, t), o.circleSides && (t.circleSides = o.circleSides), t.standardFlag = o.standardFlag, t.center.copy(o.center), t.lowerLeftCorner.copy(o.lowerLeftCorner), t.upperRightCorner.copy(o.upperRightCorner), o.snapBasePoint && t.snapBase.copy(o.snapBasePoint), o.snapRotationAngle && (t.snapAngle = o.snapRotationAngle), o.snapSpacing && t.snapIncrements.copy(o.snapSpacing), o.majorGridLines && (t.gridMajor = o.majorGridLines), o.gridSpacing && t.gridIncrements.copy(o.gridSpacing), o.backgroundObjectId && (t.backgroundObjectId = o.backgroundObjectId), t.gsView.center.copy(o.center), t.gsView.viewDirectionFromTarget.copy(o.viewDirectionFromTarget), t.gsView.viewTarget.copy(o.viewTarget), o.lensLength && (t.gsView.lensLength = o.lensLength), o.frontClippingPlane && (t.gsView.frontClippingPlane = o.frontClippingPlane), o.backClippingPlane && (t.gsView.backClippingPlane = o.backClippingPlane), o.viewHeight && (t.gsView.viewHeight = o.viewHeight), o.viewTwistAngle && (t.gsView.viewTwistAngle = o.viewTwistAngle), o.frozenLayers && (t.gsView.frozenLayers = o.frozenLayers), o.styleSheet && (t.gsView.styleSheet = o.styleSheet), o.renderMode && (t.gsView.renderMode = o.renderMode), o.viewMode && (t.gsView.viewMode = o.viewMode), o.ucsIconSetting && (t.gsView.ucsIconSetting = o.ucsIconSetting), o.ucsOrigin && t.gsView.ucsOrigin.copy(o.ucsOrigin), o.ucsXAxis && t.gsView.ucsXAxis.copy(o.ucsXAxis), o.ucsYAxis && t.gsView.ucsYAxis.copy(o.ucsYAxis), o.orthographicType && (t.gsView.orthographicType = o.orthographicType), o.shadePlotSetting && (t.gsView.shadePlotSetting = o.shadePlotSetting), o.shadePlotObjectId && (t.gsView.shadePlotObjectId = o.shadePlotObjectId), o.visualStyleObjectId && (t.gsView.visualStyleObjectId = o.visualStyleObjectId), o.isDefaultLightingOn && (t.gsView.isDefaultLightingOn = o.isDefaultLightingOn), o.defaultLightingType && (t.gsView.defaultLightingType = o.defaultLightingType), o.brightness && (t.gsView.brightness = o.brightness), o.contrast && (t.gsView.contrast = o.contrast), o.ambientColor && (t.gsView.ambientColor = o.ambientColor), n.tables.viewportTable.add(t);
|
|
539
541
|
});
|
|
540
542
|
}
|
|
541
543
|
processBlockTables(e, n) {
|
|
542
544
|
e.tables.BLOCK_RECORD.entries.forEach((o) => {
|
|
543
|
-
let
|
|
544
|
-
|
|
545
|
+
let t = n.tables.blockTable.getAt(o.name);
|
|
546
|
+
t || (t = new we(), t.objectId = o.handle, t.name = o.name, t.ownerId = o.ownerHandle, t.origin.copy(o.basePoint), t.layoutId = o.layout, t.blockInsertUnits = o.insertionUnits, t.explodability = o.explodability, t.blockScaling = o.scalability, o.bmpPreview && (t.bmpPreview = o.bmpPreview), n.tables.blockTable.add(t)), !t.isModelSapce && o.entities && o.entities.length > 0 && this.processEntitiesInBlock(o.entities, t);
|
|
545
547
|
});
|
|
546
548
|
}
|
|
547
549
|
processBlocks(e, n) {
|
|
548
550
|
}
|
|
549
551
|
async processEntitiesInBlock(e, n) {
|
|
550
|
-
const
|
|
552
|
+
const s = new C(), o = e.length, t = [];
|
|
551
553
|
for (let r = 0; r < o; r++) {
|
|
552
|
-
const
|
|
553
|
-
c &&
|
|
554
|
+
const l = e[r], c = s.convert(l);
|
|
555
|
+
c && t.push(c);
|
|
554
556
|
}
|
|
555
|
-
n.appendEntity(
|
|
557
|
+
n.appendEntity(t);
|
|
556
558
|
}
|
|
557
|
-
async processEntities(e, n,
|
|
559
|
+
async processEntities(e, n, s, o, t) {
|
|
558
560
|
const r = new C();
|
|
559
|
-
let
|
|
560
|
-
e.tables.BLOCK_RECORD.entries.forEach((
|
|
561
|
-
this.isModelSpace(
|
|
561
|
+
let l = [];
|
|
562
|
+
e.tables.BLOCK_RECORD.entries.forEach((a) => {
|
|
563
|
+
this.isModelSpace(a.name) && (l = a.entities);
|
|
562
564
|
});
|
|
563
|
-
const c =
|
|
565
|
+
const c = l.length, i = new Te(
|
|
564
566
|
c,
|
|
565
567
|
100 - o.value,
|
|
566
|
-
|
|
568
|
+
s
|
|
567
569
|
);
|
|
568
|
-
this.config.convertByEntityType && (
|
|
570
|
+
this.config.convertByEntityType && (l = this.groupAndFlattenByType(l));
|
|
569
571
|
const d = n.tables.blockTable.modelSpace;
|
|
570
|
-
await i.processChunk(async (
|
|
572
|
+
await i.processChunk(async (a, h) => {
|
|
571
573
|
const p = [];
|
|
572
|
-
for (let u =
|
|
573
|
-
const f =
|
|
574
|
+
for (let u = a; u < h; u++) {
|
|
575
|
+
const f = l[u], g = r.convert(f);
|
|
574
576
|
g && p.push(g);
|
|
575
577
|
}
|
|
576
|
-
if (d.appendEntity(p),
|
|
578
|
+
if (d.appendEntity(p), t) {
|
|
577
579
|
let u = o.value + h / c * (100 - o.value);
|
|
578
|
-
u > 100 && (u = 100), await
|
|
580
|
+
u > 100 && (u = 100), await t(u, "ENTITY", "IN-PROGRESS");
|
|
579
581
|
}
|
|
580
582
|
});
|
|
581
583
|
}
|
|
582
584
|
processHeader(e, n) {
|
|
583
|
-
const
|
|
584
|
-
|
|
585
|
+
const s = e.header;
|
|
586
|
+
s.CECOLOR && (s.CECOLOR.index >= 0 && s.CECOLOR.index <= 256 ? n.cecolor.colorIndex = s.CECOLOR.index : n.cecolor.setRGBValue(s.CECOLOR.rgb)), n.angBase = s.ANGBASE ?? 0, n.angDir = s.ANGDIR ?? 0, n.aunits = s.AUNITS ?? 0, n.celtype = s.CELTYPE ?? be, n.celtscale = s.CELTSCALE ?? 1, n.ltscale = s.LTSCALE ?? 1, s.EXTMAX && (n.extmax = s.EXTMAX), s.EXTMIN && (n.extmin = s.EXTMIN), n.insunits = s.INSUNITS ?? 1, n.pdmode = s.PDMODE ?? 0, n.pdsize = s.PDSIZE ?? 0, n.textstyle = s.TEXTSTYLE ?? L;
|
|
585
587
|
}
|
|
586
588
|
processCommonTableEntryAttrs(e, n) {
|
|
587
589
|
n.name = e.name, n.objectId = e.handle, n.ownerId = e.ownerHandle;
|
|
@@ -590,35 +592,35 @@ class Ce extends ue {
|
|
|
590
592
|
this.processLayouts(e, n), this.processImageDefs(e, n);
|
|
591
593
|
}
|
|
592
594
|
processLayouts(e, n) {
|
|
593
|
-
const
|
|
594
|
-
e.objects.LAYOUT.forEach((
|
|
595
|
+
const s = n.objects.layout;
|
|
596
|
+
e.objects.LAYOUT.forEach((t) => {
|
|
595
597
|
const r = new Pe();
|
|
596
|
-
r.layoutName =
|
|
597
|
-
const
|
|
598
|
-
r.objectId =
|
|
599
|
-
for (const c of
|
|
598
|
+
r.layoutName = t.layoutName, r.tabOrder = t.tabOrder;
|
|
599
|
+
const l = n.tables.blockTable.newIterator();
|
|
600
|
+
r.objectId = t.handle;
|
|
601
|
+
for (const c of l)
|
|
600
602
|
if (c.layoutId === r.objectId) {
|
|
601
603
|
r.blockTableRecordId = c.objectId;
|
|
602
604
|
break;
|
|
603
605
|
}
|
|
604
|
-
r.blockTableRecordId ||
|
|
606
|
+
r.blockTableRecordId || t.layoutName === "Model" && (r.blockTableRecordId = n.tables.blockTable.modelSpace.objectId), r.limits.min.copy(t.minLimit), r.limits.max.copy(t.maxLimit), r.extents.min.copy(t.minExtent), r.extents.max.copy(t.maxExtent), t.viewportId && r.viewportArray.push(t.viewportId), this.processCommonObjectAttrs(t, r), s.setAt(r.layoutName, r);
|
|
605
607
|
});
|
|
606
608
|
}
|
|
607
609
|
processImageDefs(e, n) {
|
|
608
|
-
const
|
|
609
|
-
e.objects.IMAGEDEF.forEach((
|
|
610
|
+
const s = n.objects.imageDefinition;
|
|
611
|
+
e.objects.IMAGEDEF.forEach((t) => {
|
|
610
612
|
const r = new Ee();
|
|
611
|
-
r.sourceFileName =
|
|
613
|
+
r.sourceFileName = t.fileName, this.processCommonObjectAttrs(t, r), s.setAt(r.objectId, r);
|
|
612
614
|
});
|
|
613
615
|
}
|
|
614
616
|
processCommonObjectAttrs(e, n) {
|
|
615
617
|
n.objectId = e.handle, n.ownerId = e.ownerHandle;
|
|
616
618
|
}
|
|
617
619
|
groupAndFlattenByType(e) {
|
|
618
|
-
const n = {},
|
|
620
|
+
const n = {}, s = [];
|
|
619
621
|
for (const o of e)
|
|
620
|
-
n[o.type] || (n[o.type] = [],
|
|
621
|
-
return
|
|
622
|
+
n[o.type] || (n[o.type] = [], s.push(o.type)), n[o.type].push(o);
|
|
623
|
+
return s.flatMap((o) => n[o]);
|
|
622
624
|
}
|
|
623
625
|
isModelSpace(e) {
|
|
624
626
|
return e && e.toUpperCase() == Me;
|