@mlightcad/libredwg-converter 3.5.24 → 3.5.25
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 +91 -89
- package/dist/libredwg-converter.umd.cjs +1 -1
- package/dist/libredwg-parser-worker.js +644 -629
- package/lib/AcDbEntitiyConverter.d.ts.map +1 -1
- package/lib/AcDbEntitiyConverter.js +8 -4
- package/lib/AcDbEntitiyConverter.js.map +1 -1
- package/lib/AcDbLibreDwgConverter.d.ts.map +1 -1
- package/lib/AcDbLibreDwgConverter.js +6 -2
- package/lib/AcDbLibreDwgConverter.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AcDbFace as
|
|
2
|
-
class
|
|
1
|
+
import { AcDbFace as O, AcGeVector3d as D, AcDbArc as m, transformOcsPointToWcs as w, AcDbCircle as k, AcDbEllipse as R, AcDbLine as F, AcGePoint3d as T, AcDbSpline as b, AcDbPoint as V, AcDbTrace as N, AcDbPolyline as B, AcGePoint2d as P, AcDbPolygonMesh as z, AcDbPolyFaceMesh as W, AcDbPoly2dType as A, AcDb2dPolyline as j, AcDbPoly3dType as y, AcDb3dPolyline as H, AcDbHatch as X, AcGePolyline2d as U, AcGeLine2d as G, AcGeCircArc2d as Y, AcGeVector2d as _, AcGeEllipseArc2d as Z, AcGeSpline3d as E, AcGeLoop2d as M, AcDbTable as K, AcDbText as q, AcDbMText as J, AcDbLeader as Q, AcDbAlignedDimension as $, AcDbRotatedDimension as ee, AcDb3PointAngularDimension as ne, AcDbOrdinateDimension as oe, AcDbRadialDimension as te, AcDbDiametricDimension as se, AcDbRasterImage as re, AcDbWipeout as ie, AcDbViewport as ce, AcDbRay as le, AcDbXline as ae, AcDbAttributeFlags as I, AcDbAttributeMTextFlag as L, AcDbAttribute as de, AcDbAttributeDefinition as pe, AcDbBlockReference as fe, AcCmTransparency as ue, AcDbDatabaseConverter as he, createWorkerApi as ge, AcDbLinetypeTableRecord as De, AcDbTextStyleTableRecord as Ae, DEFAULT_TEXT_STYLE as C, AcDbDimStyleTableRecord as Ie, AcCmColor as ye, AcDbLayerTableRecord as we, AcDbViewportTableRecord as Te, AcDbBlockTableRecord as be, AcDbBatchProcessing as Pe, ByLayer as Ee, AcDbLayout as Me, AcDbRasterImageDef as Le } from "@mlightcad/data-model";
|
|
2
|
+
class S {
|
|
3
3
|
convert(e) {
|
|
4
4
|
const n = this.createEntity(e);
|
|
5
5
|
return n && this.processCommonAttrs(e, n), n;
|
|
@@ -8,28 +8,30 @@ class C {
|
|
|
8
8
|
return e.type == "3DFACE" ? this.convertFace(e) : e.type == "ARC" ? this.convertArc(e) : e.type == "ATTDEF" ? this.convertAttributeDefinition(e) : e.type == "CIRCLE" ? this.convertCirle(e) : e.type == "DIMENSION" ? this.convertDimension(e) : e.type == "ELLIPSE" ? this.convertEllipse(e) : e.type == "HATCH" ? this.convertHatch(e) : e.type == "IMAGE" ? this.convertImage(e) : e.type == "LEADER" ? this.convertLeader(e) : e.type == "LINE" ? this.convertLine(e) : e.type == "LWPOLYLINE" ? this.convertLWPolyline(e) : e.type == "MTEXT" ? this.convertMText(e) : e.type == "POINT" ? this.convertPoint(e) : e.type == "POLYLINE2D" ? this.convertPolyline2d(e) : e.type == "POLYLINE3D" ? this.convertPolyline3d(e) : e.type == "RAY" ? this.convertRay(e) : e.type == "SPLINE" ? this.convertSpline(e) : e.type == "ACAD_TABLE" ? this.convertTable(e) : e.type == "TEXT" ? this.convertText(e) : e.type == "SOLID" ? this.convertSolid(e) : e.type == "VIEWPORT" ? this.convertViewport(e) : e.type == "WIPEOUT" ? this.convertWipeout(e) : e.type == "XLINE" ? this.convertXline(e) : e.type == "INSERT" ? this.convertBlockReference(e) : null;
|
|
9
9
|
}
|
|
10
10
|
convertFace(e) {
|
|
11
|
-
const n = new
|
|
11
|
+
const n = new O();
|
|
12
12
|
return e.corner1 && n.setVertexAt(0, e.corner1), e.corner2 && n.setVertexAt(1, e.corner2), e.corner3 && n.setVertexAt(2, e.corner3), e.corner4 && n.setVertexAt(3, e.corner4), n.setEdgeInvisibilities(e.flag), n;
|
|
13
13
|
}
|
|
14
14
|
convertArc(e) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const n = e.extrusionDirection ?? D.Z_AXIS;
|
|
16
|
+
return new m(
|
|
17
|
+
w(e.center, n),
|
|
17
18
|
e.radius,
|
|
18
19
|
e.startAngle,
|
|
19
20
|
e.endAngle,
|
|
20
|
-
|
|
21
|
+
n
|
|
21
22
|
);
|
|
22
23
|
}
|
|
23
24
|
convertCirle(e) {
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
const n = e.extrusionDirection ?? D.Z_AXIS;
|
|
26
|
+
return new k(
|
|
27
|
+
w(e.center, n),
|
|
26
28
|
e.radius,
|
|
27
|
-
|
|
29
|
+
n
|
|
28
30
|
);
|
|
29
31
|
}
|
|
30
32
|
convertEllipse(e) {
|
|
31
33
|
const n = new D(e.majorAxisEndPoint), t = n.length();
|
|
32
|
-
return new
|
|
34
|
+
return new R(
|
|
33
35
|
e.center,
|
|
34
36
|
e.extrusionDirection ?? D.Z_AXIS,
|
|
35
37
|
n,
|
|
@@ -41,15 +43,15 @@ class C {
|
|
|
41
43
|
}
|
|
42
44
|
convertLine(e) {
|
|
43
45
|
const n = e.startPoint, t = e.endPoint;
|
|
44
|
-
return new
|
|
45
|
-
new
|
|
46
|
-
new
|
|
46
|
+
return new F(
|
|
47
|
+
new T(n.x, n.y, n.z),
|
|
48
|
+
new T(t.x, t.y, t.z)
|
|
47
49
|
);
|
|
48
50
|
}
|
|
49
51
|
convertSpline(e) {
|
|
50
52
|
try {
|
|
51
53
|
if (e.numberOfControlPoints > 0 && e.numberOfKnots > 0)
|
|
52
|
-
return new
|
|
54
|
+
return new b(
|
|
53
55
|
e.controlPoints,
|
|
54
56
|
e.knots,
|
|
55
57
|
e.weights,
|
|
@@ -57,7 +59,7 @@ class C {
|
|
|
57
59
|
!!(e.flag & 1)
|
|
58
60
|
);
|
|
59
61
|
if (e.numberOfFitPoints > 0)
|
|
60
|
-
return new
|
|
62
|
+
return new b(
|
|
61
63
|
e.fitPoints,
|
|
62
64
|
"Uniform",
|
|
63
65
|
e.degree,
|
|
@@ -68,24 +70,24 @@ class C {
|
|
|
68
70
|
return null;
|
|
69
71
|
}
|
|
70
72
|
convertPoint(e) {
|
|
71
|
-
const n = new
|
|
73
|
+
const n = new V();
|
|
72
74
|
return n.position = e.position, n;
|
|
73
75
|
}
|
|
74
76
|
convertSolid(e) {
|
|
75
|
-
const n = new
|
|
77
|
+
const n = new N();
|
|
76
78
|
return n.setPointAt(0, { ...e.corner1, z: 0 }), n.setPointAt(1, { ...e.corner2, z: 0 }), n.setPointAt(2, { ...e.corner3, z: 0 }), n.setPointAt(
|
|
77
79
|
3,
|
|
78
80
|
e.corner4 ? { ...e.corner4, z: 0 } : { ...e.corner3, z: 0 }
|
|
79
81
|
), n.thickness = e.thickness, n;
|
|
80
82
|
}
|
|
81
83
|
convertLWPolyline(e) {
|
|
82
|
-
const n = new
|
|
84
|
+
const n = new B();
|
|
83
85
|
n.closed = !!(e.flag & 512);
|
|
84
86
|
const t = e.constantWidth ?? -1;
|
|
85
87
|
return e.vertices.forEach((o, s) => {
|
|
86
88
|
n.addVertexAt(
|
|
87
89
|
s,
|
|
88
|
-
new
|
|
90
|
+
new P(o.x, o.y),
|
|
89
91
|
o.bulge,
|
|
90
92
|
o.startWidth ?? t,
|
|
91
93
|
o.endWidth ?? t
|
|
@@ -115,10 +117,10 @@ class C {
|
|
|
115
117
|
}), a.push(i.bulge ?? 0);
|
|
116
118
|
}), t) {
|
|
117
119
|
const i = e.meshMVertexCount ?? 2, d = e.meshNVertexCount ?? 2;
|
|
118
|
-
return new
|
|
120
|
+
return new z(i, d, r, n, s);
|
|
119
121
|
} else {
|
|
120
122
|
if (o)
|
|
121
|
-
return new
|
|
123
|
+
return new W(r, c);
|
|
122
124
|
{
|
|
123
125
|
let i = A.SimplePoly;
|
|
124
126
|
return e.flag & 2 ? i = A.FitCurvePoly : e.flag & 4 && (e.smoothType == 6 ? i = A.CubicSplinePoly : e.smoothType == 5 && (i = A.QuadSplinePoly)), new j(
|
|
@@ -143,11 +145,11 @@ class C {
|
|
|
143
145
|
});
|
|
144
146
|
});
|
|
145
147
|
let o = y.SimplePoly;
|
|
146
|
-
return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new
|
|
148
|
+
return e.flag & 4 && (e.smoothType == 6 ? o = y.CubicSplinePoly : e.smoothType == 5 && (o = y.QuadSplinePoly)), new H(o, t, n);
|
|
147
149
|
}
|
|
148
150
|
convertHatch(e) {
|
|
149
151
|
var o;
|
|
150
|
-
const n = new
|
|
152
|
+
const n = new X();
|
|
151
153
|
return (o = e.definitionLines) == null || o.forEach((s) => {
|
|
152
154
|
n.definitionLines.push({
|
|
153
155
|
angle: s.angle,
|
|
@@ -157,7 +159,7 @@ class C {
|
|
|
157
159
|
});
|
|
158
160
|
}), 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((s) => {
|
|
159
161
|
if (s.boundaryPathTypeFlag & 2) {
|
|
160
|
-
const a = s, c = new
|
|
162
|
+
const a = s, c = new U();
|
|
161
163
|
c.closed = a.isClosed, a.vertices.forEach((i, d) => {
|
|
162
164
|
c.addVertexAt(d, {
|
|
163
165
|
x: i.x,
|
|
@@ -171,11 +173,11 @@ class C {
|
|
|
171
173
|
if (d != null) {
|
|
172
174
|
if (d.type == 1) {
|
|
173
175
|
const l = d;
|
|
174
|
-
c.push(new
|
|
176
|
+
c.push(new G(l.start, l.end));
|
|
175
177
|
} else if (d.type == 2) {
|
|
176
178
|
const l = d;
|
|
177
179
|
c.push(
|
|
178
|
-
new
|
|
180
|
+
new Y(
|
|
179
181
|
l.center,
|
|
180
182
|
l.radius,
|
|
181
183
|
l.startAngle,
|
|
@@ -185,40 +187,40 @@ class C {
|
|
|
185
187
|
);
|
|
186
188
|
} else if (d.type == 3) {
|
|
187
189
|
const l = d;
|
|
188
|
-
new
|
|
190
|
+
new _().subVectors(l.end, l.center);
|
|
189
191
|
const p = Math.sqrt(
|
|
190
192
|
Math.pow(l.end.x, 2) + Math.pow(l.end.y, 2)
|
|
191
|
-
),
|
|
192
|
-
let
|
|
193
|
-
const
|
|
194
|
-
l.isCCW || (
|
|
195
|
-
new
|
|
193
|
+
), f = p * l.lengthOfMinorAxis;
|
|
194
|
+
let u = l.startAngle, g = l.endAngle;
|
|
195
|
+
const v = Math.atan2(l.end.y, l.end.x);
|
|
196
|
+
l.isCCW || (u = Math.PI * 2 - u, g = Math.PI * 2 - g), c.push(
|
|
197
|
+
new Z(
|
|
196
198
|
{ ...l.center, z: 0 },
|
|
197
199
|
p,
|
|
198
|
-
u,
|
|
199
200
|
f,
|
|
201
|
+
u,
|
|
200
202
|
g,
|
|
201
203
|
!l.isCCW,
|
|
202
|
-
|
|
204
|
+
v
|
|
203
205
|
)
|
|
204
206
|
);
|
|
205
207
|
} else if (d.type == 4) {
|
|
206
208
|
const l = d;
|
|
207
209
|
if (l.numberOfControlPoints > 0 && l.numberOfKnots > 0) {
|
|
208
210
|
const h = l.controlPoints.map(
|
|
209
|
-
(
|
|
210
|
-
x:
|
|
211
|
-
y:
|
|
211
|
+
(u) => ({
|
|
212
|
+
x: u.x,
|
|
213
|
+
y: u.y,
|
|
212
214
|
z: 0
|
|
213
215
|
})
|
|
214
216
|
);
|
|
215
217
|
let p = !0;
|
|
216
|
-
const
|
|
218
|
+
const f = l.controlPoints.map((u) => (u.weight == null && (p = !1), u.weight || 1));
|
|
217
219
|
c.push(
|
|
218
|
-
new
|
|
220
|
+
new E(
|
|
219
221
|
h,
|
|
220
222
|
l.knots,
|
|
221
|
-
p ?
|
|
223
|
+
p ? f : void 0
|
|
222
224
|
)
|
|
223
225
|
);
|
|
224
226
|
} else if (l.numberOfFitData > 0) {
|
|
@@ -227,18 +229,18 @@ class C {
|
|
|
227
229
|
y: p.y,
|
|
228
230
|
z: 0
|
|
229
231
|
}));
|
|
230
|
-
c.push(new
|
|
232
|
+
c.push(new E(h, "Uniform"));
|
|
231
233
|
}
|
|
232
234
|
}
|
|
233
235
|
}
|
|
234
236
|
});
|
|
235
|
-
const i =
|
|
236
|
-
i.length == 0 && c.length > 0 ? n.add(new
|
|
237
|
+
const i = M.buildFromEdges(c);
|
|
238
|
+
i.length == 0 && c.length > 0 ? n.add(new M(c)) : i.forEach((d) => n.add(d));
|
|
237
239
|
}
|
|
238
240
|
}), n;
|
|
239
241
|
}
|
|
240
242
|
convertTable(e) {
|
|
241
|
-
const n = new
|
|
243
|
+
const n = new K(
|
|
242
244
|
e.name,
|
|
243
245
|
e.rowCount,
|
|
244
246
|
e.columnCount
|
|
@@ -252,22 +254,22 @@ class C {
|
|
|
252
254
|
}), n;
|
|
253
255
|
}
|
|
254
256
|
convertText(e) {
|
|
255
|
-
const n = new
|
|
257
|
+
const n = new q();
|
|
256
258
|
return n.textString = e.text, n.styleName = e.styleName, n.height = e.textHeight, n.position.copy(e.startPoint), n.rotation = e.rotation, n.oblique = e.obliqueAngle ?? 0, n.thickness = e.thickness, n.horizontalMode = e.halign, n.verticalMode = e.valign, n.widthFactor = e.xScale ?? 1, n;
|
|
257
259
|
}
|
|
258
260
|
convertMText(e) {
|
|
259
|
-
const n = new
|
|
261
|
+
const n = new J();
|
|
260
262
|
return n.contents = e.text, e.styleName != null && (n.styleName = e.styleName), n.height = e.textHeight, n.width = e.rectWidth, n.rotation = e.rotation || 0, n.location = e.insertionPoint, n.attachmentPoint = e.attachmentPoint, e.direction && (n.direction = new D(e.direction)), n.drawingDirection = e.drawingDirection, n;
|
|
261
263
|
}
|
|
262
264
|
convertLeader(e) {
|
|
263
|
-
const n = new
|
|
265
|
+
const n = new Q();
|
|
264
266
|
return e.vertices.forEach((t) => {
|
|
265
267
|
n.appendVertex(t);
|
|
266
268
|
}), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
|
|
267
269
|
}
|
|
268
270
|
convertDimension(e) {
|
|
269
271
|
if (e.subclassMarker == "AcDbAlignedDimension") {
|
|
270
|
-
const n = e, t = new
|
|
272
|
+
const n = e, t = new $(
|
|
271
273
|
n.subDefinitionPoint1,
|
|
272
274
|
n.subDefinitionPoint2,
|
|
273
275
|
n.definitionPoint
|
|
@@ -278,7 +280,7 @@ class C {
|
|
|
278
280
|
z: 0
|
|
279
281
|
}), t.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, t), t;
|
|
280
282
|
} else if (e.subclassMarker == "AcDbRotatedDimension") {
|
|
281
|
-
const n = e, t = new
|
|
283
|
+
const n = e, t = new ee(
|
|
282
284
|
n.subDefinitionPoint1,
|
|
283
285
|
n.subDefinitionPoint2,
|
|
284
286
|
n.definitionPoint
|
|
@@ -289,7 +291,7 @@ class C {
|
|
|
289
291
|
z: 0
|
|
290
292
|
}), t.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, t), t;
|
|
291
293
|
} else if (e.subclassMarker == "AcDb3PointAngularDimension") {
|
|
292
|
-
const n = e, t = new
|
|
294
|
+
const n = e, t = new ne(
|
|
293
295
|
n.centerPoint,
|
|
294
296
|
n.subDefinitionPoint1,
|
|
295
297
|
n.subDefinitionPoint2,
|
|
@@ -297,20 +299,20 @@ class C {
|
|
|
297
299
|
);
|
|
298
300
|
return this.processDimensionCommonAttrs(e, t), t;
|
|
299
301
|
} else if (e.subclassMarker == "AcDbOrdinateDimension") {
|
|
300
|
-
const n = e, t = new
|
|
302
|
+
const n = e, t = new oe(
|
|
301
303
|
n.subDefinitionPoint1,
|
|
302
304
|
n.subDefinitionPoint2
|
|
303
305
|
);
|
|
304
306
|
return this.processDimensionCommonAttrs(e, t), t;
|
|
305
307
|
} else if (e.subclassMarker == "AcDbRadialDimension") {
|
|
306
|
-
const n = e, t = new
|
|
308
|
+
const n = e, t = new te(
|
|
307
309
|
n.definitionPoint,
|
|
308
310
|
n.centerPoint,
|
|
309
311
|
n.leaderLength
|
|
310
312
|
);
|
|
311
313
|
return this.processDimensionCommonAttrs(e, t), t;
|
|
312
314
|
} else if (e.subclassMarker == "AcDbDiametricDimension") {
|
|
313
|
-
const n = e, t = new
|
|
315
|
+
const n = e, t = new se(
|
|
314
316
|
n.definitionPoint,
|
|
315
317
|
n.centerPoint,
|
|
316
318
|
n.leaderLength
|
|
@@ -321,7 +323,7 @@ class C {
|
|
|
321
323
|
}
|
|
322
324
|
processImage(e, n) {
|
|
323
325
|
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((t) => {
|
|
324
|
-
n.clipBoundary.push(new
|
|
326
|
+
n.clipBoundary.push(new P(t));
|
|
325
327
|
}), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
|
|
326
328
|
e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
|
|
327
329
|
) * e.imageSize.x, n.height = Math.sqrt(
|
|
@@ -329,39 +331,39 @@ class C {
|
|
|
329
331
|
) * e.imageSize.y, n.rotation = Math.atan2(e.uPixel.y, e.uPixel.x);
|
|
330
332
|
}
|
|
331
333
|
convertImage(e) {
|
|
332
|
-
const n = new
|
|
334
|
+
const n = new re();
|
|
333
335
|
return this.processImage(e, n), n;
|
|
334
336
|
}
|
|
335
337
|
convertWipeout(e) {
|
|
336
|
-
const n = new
|
|
338
|
+
const n = new ie();
|
|
337
339
|
return this.processImage(e, n), n;
|
|
338
340
|
}
|
|
339
341
|
convertViewport(e) {
|
|
340
|
-
const n = new
|
|
342
|
+
const n = new ce();
|
|
341
343
|
return n.number = e.viewportId, n.centerPoint.copy(e.viewportCenter), n.height = e.height, n.width = e.width, n.viewCenter.copy(e.displayCenter), n.viewHeight = e.viewHeight, n;
|
|
342
344
|
}
|
|
343
345
|
convertRay(e) {
|
|
344
|
-
const n = new
|
|
346
|
+
const n = new le();
|
|
345
347
|
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
346
348
|
}
|
|
347
349
|
convertXline(e) {
|
|
348
|
-
const n = new
|
|
350
|
+
const n = new ae();
|
|
349
351
|
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
350
352
|
}
|
|
351
353
|
convertAttributeCommon(e, n) {
|
|
352
354
|
const t = e.text;
|
|
353
|
-
n.textString = t.text, n.styleName = t.styleName, n.height = t.textHeight, n.position.copy(t.startPoint), n.rotation = t.rotation, n.oblique = t.obliqueAngle ?? 0, n.thickness = t.thickness, n.horizontalMode = t.halign, n.verticalMode = t.valign, n.widthFactor = t.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 &
|
|
355
|
+
n.textString = t.text, n.styleName = t.styleName, n.height = t.textHeight, n.position.copy(t.startPoint), n.rotation = t.rotation, n.oblique = t.obliqueAngle ?? 0, n.thickness = t.thickness, n.horizontalMode = t.halign, n.verticalMode = t.valign, n.widthFactor = t.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 & L.MultiLine) !== 0, n.isConstMTextAttribute = (e.mtextFlag & L.ConstMultiLine) !== 0;
|
|
354
356
|
}
|
|
355
357
|
convertAttribute(e) {
|
|
356
|
-
const n = new
|
|
358
|
+
const n = new de();
|
|
357
359
|
return this.convertAttributeCommon(e, n), n;
|
|
358
360
|
}
|
|
359
361
|
convertAttributeDefinition(e) {
|
|
360
|
-
const n = new
|
|
362
|
+
const n = new pe();
|
|
361
363
|
return this.convertAttributeCommon(e, n), n.prompt = e.prompt, n;
|
|
362
364
|
}
|
|
363
365
|
convertBlockReference(e) {
|
|
364
|
-
const n = new
|
|
366
|
+
const n = new fe(e.name);
|
|
365
367
|
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((t) => {
|
|
366
368
|
const o = this.convertAttribute(t);
|
|
367
369
|
n.appendAttributes(o);
|
|
@@ -371,21 +373,21 @@ class C {
|
|
|
371
373
|
n.dimBlockId = e.name, n.textPosition.copy(e.textPoint), n.textRotation = e.textRotation || 0, e.textLineSpacingFactor && (n.textLineSpacingFactor = e.textLineSpacingFactor), e.textLineSpacingStyle && (n.textLineSpacingStyle = e.textLineSpacingStyle), n.dimensionStyleName = e.styleName, n.dimensionText = e.text || "", n.measurement = e.measurement;
|
|
372
374
|
}
|
|
373
375
|
processCommonAttrs(e, n) {
|
|
374
|
-
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 && (e.color == null || e.colorIndex === 7) && (n.color.colorIndex = e.colorIndex), e.colorName && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null) {
|
|
376
|
+
if (n.layer = e.layer || "0", n.objectId = e.handle, e.ownerBlockRecordSoftId != null && (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 && (e.color == null || e.colorIndex === 7) && (n.color.colorIndex = e.colorIndex), e.colorName && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null) {
|
|
375
377
|
const t = new ue();
|
|
376
378
|
t.method = e.transparencyType, (t.isByBlock || t.isByBlock) && (t.alpha = e.transparency), n.transparency = t;
|
|
377
379
|
}
|
|
378
380
|
}
|
|
379
381
|
}
|
|
380
|
-
const
|
|
381
|
-
class
|
|
382
|
+
const Ce = "*MODEL_SPACE";
|
|
383
|
+
class xe extends he {
|
|
382
384
|
constructor(e = {}) {
|
|
383
385
|
super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
|
|
384
386
|
}
|
|
385
387
|
async parse(e, n) {
|
|
386
388
|
const t = this.config, o = this.getParserWorkerTimeout(e, n);
|
|
387
389
|
if (t.useWorker && t.parserWorkerUrl) {
|
|
388
|
-
const s =
|
|
390
|
+
const s = ge({
|
|
389
391
|
workerUrl: t.parserWorkerUrl,
|
|
390
392
|
timeout: o,
|
|
391
393
|
maxConcurrentWorkers: 1
|
|
@@ -444,13 +446,13 @@ class Se extends fe {
|
|
|
444
446
|
standardFlag: o.standardFlag,
|
|
445
447
|
totalPatternLength: o.totalPatternLength,
|
|
446
448
|
pattern: o.pattern
|
|
447
|
-
}, r = new
|
|
449
|
+
}, r = new De(s);
|
|
448
450
|
this.processCommonTableEntryAttrs(o, r), r.name = o.name, n.tables.linetypeTable.add(r);
|
|
449
451
|
});
|
|
450
452
|
}
|
|
451
453
|
processTextStyles(e, n) {
|
|
452
454
|
e.tables.STYLE.entries.forEach((o) => {
|
|
453
|
-
const s = new
|
|
455
|
+
const s = new Ae(o);
|
|
454
456
|
this.processCommonTableEntryAttrs(o, s), n.tables.textStyleTable.add(s);
|
|
455
457
|
});
|
|
456
458
|
}
|
|
@@ -518,22 +520,22 @@ class Se extends fe {
|
|
|
518
520
|
dimfit: o.DIMFIT || 0,
|
|
519
521
|
dimupt: o.DIMUPT,
|
|
520
522
|
dimatfit: o.DIMATFIT,
|
|
521
|
-
dimtxsty:
|
|
523
|
+
dimtxsty: C,
|
|
522
524
|
dimldrblk: "",
|
|
523
525
|
dimblk: o.DIMBLK || "",
|
|
524
526
|
dimblk1: o.DIMBLK1 || "",
|
|
525
527
|
dimblk2: o.DIMBLK2 || "",
|
|
526
528
|
dimlwd: o.DIMLWD,
|
|
527
529
|
dimlwe: o.DIMLWE
|
|
528
|
-
}, r = new
|
|
530
|
+
}, r = new Ie(s);
|
|
529
531
|
this.processCommonTableEntryAttrs(o, r), n.tables.dimStyleTable.add(r);
|
|
530
532
|
});
|
|
531
533
|
}
|
|
532
534
|
processLayers(e, n) {
|
|
533
535
|
e.tables.LAYER.entries.forEach((o) => {
|
|
534
|
-
const s = new
|
|
536
|
+
const s = new ye();
|
|
535
537
|
s.colorIndex = o.colorIndex;
|
|
536
|
-
const r = new
|
|
538
|
+
const r = new we({
|
|
537
539
|
name: o.name,
|
|
538
540
|
standardFlags: o.standardFlag,
|
|
539
541
|
linetype: o.lineType,
|
|
@@ -547,20 +549,20 @@ class Se extends fe {
|
|
|
547
549
|
}
|
|
548
550
|
processViewports(e, n) {
|
|
549
551
|
e.tables.VPORT.entries.forEach((o) => {
|
|
550
|
-
const s = new
|
|
552
|
+
const s = new Te();
|
|
551
553
|
this.processCommonTableEntryAttrs(o, s), o.circleSides && (s.circleSides = o.circleSides), s.standardFlag = o.standardFlag, s.center.copy(o.center), s.lowerLeftCorner.copy(o.lowerLeftCorner), s.upperRightCorner.copy(o.upperRightCorner), o.snapBasePoint && s.snapBase.copy(o.snapBasePoint), o.snapRotationAngle && (s.snapAngle = o.snapRotationAngle), o.snapSpacing && s.snapIncrements.copy(o.snapSpacing), o.majorGridLines && (s.gridMajor = o.majorGridLines), o.gridSpacing && s.gridIncrements.copy(o.gridSpacing), o.backgroundObjectId && (s.backgroundObjectId = o.backgroundObjectId), s.gsView.center.copy(o.center), s.gsView.viewDirectionFromTarget.copy(o.viewDirectionFromTarget), s.gsView.viewTarget.copy(o.viewTarget), o.lensLength && (s.gsView.lensLength = o.lensLength), o.frontClippingPlane && (s.gsView.frontClippingPlane = o.frontClippingPlane), o.backClippingPlane && (s.gsView.backClippingPlane = o.backClippingPlane), o.viewHeight && (s.gsView.viewHeight = o.viewHeight), o.viewTwistAngle && (s.gsView.viewTwistAngle = o.viewTwistAngle), o.frozenLayers && (s.gsView.frozenLayers = o.frozenLayers), o.styleSheet && (s.gsView.styleSheet = o.styleSheet), o.renderMode && (s.gsView.renderMode = o.renderMode), o.viewMode && (s.gsView.viewMode = o.viewMode), o.ucsIconSetting && (s.gsView.ucsIconSetting = o.ucsIconSetting), o.ucsOrigin && s.gsView.ucsOrigin.copy(o.ucsOrigin), o.ucsXAxis && s.gsView.ucsXAxis.copy(o.ucsXAxis), o.ucsYAxis && s.gsView.ucsYAxis.copy(o.ucsYAxis), o.orthographicType && (s.gsView.orthographicType = o.orthographicType), o.shadePlotSetting && (s.gsView.shadePlotSetting = o.shadePlotSetting), o.shadePlotObjectId && (s.gsView.shadePlotObjectId = o.shadePlotObjectId), o.visualStyleObjectId && (s.gsView.visualStyleObjectId = o.visualStyleObjectId), o.isDefaultLightingOn && (s.gsView.isDefaultLightingOn = o.isDefaultLightingOn), o.defaultLightingType && (s.gsView.defaultLightingType = o.defaultLightingType), o.brightness && (s.gsView.brightness = o.brightness), o.contrast && (s.gsView.contrast = o.contrast), o.ambientColor && (s.gsView.ambientColor = o.ambientColor), n.tables.viewportTable.add(s);
|
|
552
554
|
});
|
|
553
555
|
}
|
|
554
556
|
processBlockTables(e, n) {
|
|
555
557
|
e.tables.BLOCK_RECORD.entries.forEach((o) => {
|
|
556
558
|
let s = n.tables.blockTable.getAt(o.name);
|
|
557
|
-
s || (s = new
|
|
559
|
+
s || (s = new be(), s.objectId = o.handle, s.name = o.name, s.ownerId = o.ownerHandle, s.origin.copy(o.basePoint), s.layoutId = o.layout, s.blockInsertUnits = o.insertionUnits, s.explodability = o.explodability, s.blockScaling = o.scalability, o.bmpPreview && (s.bmpPreview = o.bmpPreview), n.tables.blockTable.add(s)), !s.isModelSapce && o.entities && o.entities.length > 0 && this.processEntitiesInBlock(o.entities, s);
|
|
558
560
|
});
|
|
559
561
|
}
|
|
560
562
|
processBlocks(e, n) {
|
|
561
563
|
}
|
|
562
564
|
async processEntitiesInBlock(e, n) {
|
|
563
|
-
const t = new
|
|
565
|
+
const t = new S(), o = e.length, s = [];
|
|
564
566
|
for (let r = 0; r < o; r++) {
|
|
565
567
|
const a = e[r], c = t.convert(a);
|
|
566
568
|
c && s.push(c);
|
|
@@ -568,12 +570,12 @@ class Se extends fe {
|
|
|
568
570
|
n.appendEntity(s);
|
|
569
571
|
}
|
|
570
572
|
async processEntities(e, n, t, o, s) {
|
|
571
|
-
const r = new
|
|
573
|
+
const r = new S();
|
|
572
574
|
let a = [];
|
|
573
575
|
e.tables.BLOCK_RECORD.entries.forEach((l) => {
|
|
574
576
|
this.isModelSpace(l.name) && (a = l.entities);
|
|
575
577
|
});
|
|
576
|
-
const c = a.length, i = new
|
|
578
|
+
const c = a.length, i = new Pe(
|
|
577
579
|
c,
|
|
578
580
|
100 - o.value,
|
|
579
581
|
t
|
|
@@ -582,22 +584,22 @@ class Se extends fe {
|
|
|
582
584
|
const d = n.tables.blockTable.modelSpace;
|
|
583
585
|
await i.processChunk(async (l, h) => {
|
|
584
586
|
const p = [];
|
|
585
|
-
for (let
|
|
586
|
-
const
|
|
587
|
+
for (let f = l; f < h; f++) {
|
|
588
|
+
const u = a[f], g = r.convert(u);
|
|
587
589
|
g && p.push(g);
|
|
588
590
|
}
|
|
589
591
|
if (d.appendEntity(p), s) {
|
|
590
|
-
let
|
|
591
|
-
|
|
592
|
+
let f = o.value + h / c * (100 - o.value);
|
|
593
|
+
f > 100 && (f = 100), await s(f, "ENTITY", "IN-PROGRESS");
|
|
592
594
|
}
|
|
593
595
|
});
|
|
594
596
|
}
|
|
595
597
|
processHeader(e, n) {
|
|
596
598
|
const t = e.header;
|
|
597
|
-
t.CECOLOR && (t.CECOLOR.index >= 0 && t.CECOLOR.index <= 256 ? n.cecolor.colorIndex = t.CECOLOR.index : n.cecolor.setRGBValue(t.CECOLOR.rgb)), n.angBase = t.ANGBASE ?? 0, n.angDir = t.ANGDIR ?? 0, n.aunits = t.AUNITS ?? 0, n.celtype = t.CELTYPE ??
|
|
599
|
+
t.CECOLOR && (t.CECOLOR.index >= 0 && t.CECOLOR.index <= 256 ? n.cecolor.colorIndex = t.CECOLOR.index : n.cecolor.setRGBValue(t.CECOLOR.rgb)), n.angBase = t.ANGBASE ?? 0, n.angDir = t.ANGDIR ?? 0, n.aunits = t.AUNITS ?? 0, n.celtype = t.CELTYPE ?? Ee, n.celtscale = t.CELTSCALE ?? 1, n.ltscale = t.LTSCALE ?? 1, t.EXTMAX && (n.extmax = t.EXTMAX), t.EXTMIN && (n.extmin = t.EXTMIN), n.insunits = t.INSUNITS ?? 1, n.pdmode = t.PDMODE ?? 0, n.pdsize = t.PDSIZE ?? 0, n.textstyle = t.TEXTSTYLE ?? C;
|
|
598
600
|
}
|
|
599
601
|
processCommonTableEntryAttrs(e, n) {
|
|
600
|
-
n.name = e.name, n.objectId = e.handle, n.ownerId = e.ownerHandle;
|
|
602
|
+
n.name = e.name, n.objectId = e.handle, e.ownerHandle != null && (n.ownerId = e.ownerHandle);
|
|
601
603
|
}
|
|
602
604
|
processObjects(e, n) {
|
|
603
605
|
this.processLayouts(e, n), this.processImageDefs(e, n);
|
|
@@ -605,7 +607,7 @@ class Se extends fe {
|
|
|
605
607
|
processLayouts(e, n) {
|
|
606
608
|
const t = n.objects.layout;
|
|
607
609
|
e.objects.LAYOUT.forEach((s) => {
|
|
608
|
-
const r = new
|
|
610
|
+
const r = new Me();
|
|
609
611
|
r.layoutName = s.layoutName, r.tabOrder = s.tabOrder;
|
|
610
612
|
const a = n.tables.blockTable.newIterator();
|
|
611
613
|
r.objectId = s.handle;
|
|
@@ -620,12 +622,12 @@ class Se extends fe {
|
|
|
620
622
|
processImageDefs(e, n) {
|
|
621
623
|
const t = n.objects.imageDefinition;
|
|
622
624
|
e.objects.IMAGEDEF.forEach((s) => {
|
|
623
|
-
const r = new
|
|
625
|
+
const r = new Le();
|
|
624
626
|
r.sourceFileName = s.fileName, this.processCommonObjectAttrs(s, r), t.setAt(r.objectId, r);
|
|
625
627
|
});
|
|
626
628
|
}
|
|
627
629
|
processCommonObjectAttrs(e, n) {
|
|
628
|
-
n.objectId = e.handle, n.ownerId = e.ownerHandle;
|
|
630
|
+
n.objectId = e.handle, e.ownerHandle != null && (n.ownerId = e.ownerHandle);
|
|
629
631
|
}
|
|
630
632
|
groupAndFlattenByType(e) {
|
|
631
633
|
const n = {}, t = [];
|
|
@@ -634,9 +636,9 @@ class Se extends fe {
|
|
|
634
636
|
return t.flatMap((o) => n[o]);
|
|
635
637
|
}
|
|
636
638
|
isModelSpace(e) {
|
|
637
|
-
return e && e.toUpperCase() ==
|
|
639
|
+
return e && e.toUpperCase() == Ce;
|
|
638
640
|
}
|
|
639
641
|
}
|
|
640
642
|
export {
|
|
641
|
-
|
|
643
|
+
xe as AcDbLibreDwgConverter
|
|
642
644
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel))})(this,function(D,r){"use strict";class y{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MTEXT"?this.convertMText(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const n=new r.AcDbFace;return e.corner1&&n.setVertexAt(0,e.corner1),e.corner2&&n.setVertexAt(1,e.corner2),e.corner3&&n.setVertexAt(2,e.corner3),e.corner4&&n.setVertexAt(3,e.corner4),n.setEdgeInvisibilities(e.flag),n}convertArc(e){return new r.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle,e.extrusionDirection??r.AcGeVector3d.Z_AXIS)}convertCirle(e){return new r.AcDbCircle(e.center,e.radius,e.extrusionDirection??r.AcGeVector3d.Z_AXIS)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),s=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,s,s*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,s=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(s.x,s.y,s.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;n.closed=!!(e.flag&512);const s=e.constantWidth??-1;return e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth??s,o.endWidth??s)}),n}convertPolyline2d(e){const n=!!(e.flag&1),s=!!(e.flag&16),o=!!(e.flag&64),t=!!(e.flag&32),i=[],p=[],l=[];if(e.vertices.map(c=>{if(!(c.flag&16))if(o&&c.flag&128)if(c.flag&64)i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0);else{const u=[];c.polyfaceIndex0!=null&&c.polyfaceIndex0!=0&&u.push(Math.abs(c.polyfaceIndex0)-1),c.polyfaceIndex1!=null&&c.polyfaceIndex1!=0&&u.push(Math.abs(c.polyfaceIndex1)-1),c.polyfaceIndex2!=null&&c.polyfaceIndex2!=0&&u.push(Math.abs(c.polyfaceIndex2)-1),c.polyfaceIndex3!=null&&c.polyfaceIndex3!=0&&u.push(Math.abs(c.polyfaceIndex3)-1),u.length>=3&&l.push(u)}else i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0)}),s){const c=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(c,u,i,n,t)}else{if(o)return new r.AcDbPolyFaceMesh(i,l);{let c=r.AcDbPoly2dType.SimplePoly;return e.flag&2?c=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?c=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(c=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(c,i,0,n,e.startWidth,e.endWidth,p)}}}convertPolyline3d(e){const n=!!(e.flag&1),s=[];e.vertices.map(t=>{t.flag&16||s.push({x:t.x,y:t.y,z:t.z})});let o=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?o=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(o=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(o,s,n)}convertHatch(e){var o;const n=new r.AcDbHatch;return(o=e.definitionLines)==null||o.forEach(t=>{n.definitionLines.push({angle:t.angle,base:t.base,offset:t.offset,dashLengths:t.numberOfDashLengths>0?t.dashLengths:[]})}),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=>{if(t.boundaryPathTypeFlag&2){const p=t,l=new r.AcGePolyline2d;l.closed=p.isClosed,p.vertices.forEach((c,u)=>{l.addVertexAt(u,{x:c.x,y:c.y,bulge:c.bulge})}),n.add(l)}else{const p=t,l=[];p.edges.forEach(u=>{if(u!=null){if(u.type==1){const a=u;l.push(new r.AcGeLine2d(a.start,a.end))}else if(u.type==2){const a=u;l.push(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(u.type==3){const a=u;new r.AcGeVector2d().subVectors(a.end,a.center);const f=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),h=f*a.lengthOfMinorAxis;let g=a.startAngle,A=a.endAngle;const w=Math.atan2(a.end.y,a.end.x);a.isCCW||(g=Math.PI*2-g,A=Math.PI*2-A),l.push(new r.AcGeEllipseArc2d({...a.center,z:0},f,h,g,A,!a.isCCW,w))}else if(u.type==4){const a=u;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const d=a.controlPoints.map(g=>({x:g.x,y:g.y,z:0}));let f=!0;const h=a.controlPoints.map(g=>(g.weight==null&&(f=!1),g.weight||1));l.push(new r.AcGeSpline3d(d,a.knots,f?h:void 0))}else if(a.numberOfFitData>0){const d=a.fitDatum.map(f=>({x:f.x,y:f.y,z:0}));l.push(new r.AcGeSpline3d(d,"Uniform"))}}}});const c=r.AcGeLoop2d.buildFromEdges(l);c.length==0&&l.length>0?n.add(new r.AcGeLoop2d(l)):c.forEach(u=>n.add(u))}}),n}convertTable(e){const n=new r.AcDbTable(e.name,e.rowCount,e.columnCount);return n.tableStyleId=e.tableStyleId,n.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(n.horizontalDirection=new r.AcGeVector3d(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((s,o)=>n.setColumnWidth(o,s)),e.rowHeightArr.forEach((s,o)=>n.setRowHeight(o,s)),e.cells.forEach((s,o)=>{n.setCell(o,s)}),n}convertText(e){const n=new r.AcDbText;return n.textString=e.text,n.styleName=e.styleName,n.height=e.textHeight,n.position.copy(e.startPoint),n.rotation=e.rotation,n.oblique=e.obliqueAngle??0,n.thickness=e.thickness,n.horizontalMode=e.halign,n.verticalMode=e.valign,n.widthFactor=e.xScale??1,n}convertMText(e){const n=new r.AcDbMText;return n.contents=e.text,e.styleName!=null&&(n.styleName=e.styleName),n.height=e.textHeight,n.width=e.rectWidth,n.rotation=e.rotation||0,n.location=e.insertionPoint,n.attachmentPoint=e.attachmentPoint,e.direction&&(n.direction=new r.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new r.AcDbLeader;return e.vertices.forEach(s=>{n.appendVertex(s)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"){const n=e,s=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRotatedDimension"){const n=e,s=new r.AcDbRotatedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,s=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,s=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,s=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,s=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}return null}processImage(e,n){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=>{n.clipBoundary.push(new r.AcGePoint2d(s))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new r.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new r.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new r.AcDbViewport;return n.number=e.viewportId,n.centerPoint.copy(e.viewportCenter),n.height=e.height,n.width=e.width,n.viewCenter.copy(e.displayCenter),n.viewHeight=e.viewHeight,n}convertRay(e){const n=new r.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new r.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertAttributeCommon(e,n){const s=e.text;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&r.AcDbAttributeFlags.Invisible)!==0,n.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,n.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,n.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,n.lockPositionInBlock=e.lockPositionFlag,n.isReallyLocked=e.isReallyLocked,n.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,n.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const n=new r.AcDbAttribute;return this.convertAttributeCommon(e,n),n}convertAttributeDefinition(e){const n=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,n),n.prompt=e.prompt,n}convertBlockReference(e){const n=new r.AcDbBlockReference(e.name);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=>{const o=this.convertAttribute(s);n.appendAttributes(o)}),n}processDimensionCommonAttrs(e,n){n.dimBlockId=e.name,n.textPosition.copy(e.textPoint),n.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(n.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(n.textLineSpacingStyle=e.textLineSpacingStyle),n.dimensionStyleName=e.styleName,n.dimensionText=e.text||"",n.measurement=e.measurement}processCommonAttrs(e,n){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&&(e.color==null||e.colorIndex===7)&&(n.color.colorIndex=e.colorIndex),e.colorName&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null){const s=new r.AcCmTransparency;s.method=e.transparencyType,(s.isByBlock||s.isByBlock)&&(s.alpha=e.transparency),n.transparency=s}}}const b="*MODEL_SPACE";class I extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const s=this.config,o=this.getParserWorkerTimeout(e,n);if(s.useWorker&&s.parserWorkerUrl){const t=r.createWorkerApi({workerUrl:s.parserWorkerUrl,timeout:o,maxConcurrentWorkers:1}),i=await t.execute(e);if(t.destroy(),i.success)return i.data;throw new Error(`Failed to parse drawing due to error: '${i.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(i=>{n.set(i.name,i)});const s=new Map,o=i=>{if(i){const p=i.lastIndexOf(".");return p>=0?i.substring(0,p).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const p=[];let l=o(i.font);l&&p.push(l),l=o(i.bigFont),l&&p.push(l),s.set(i.name,p)});const t=new Set;return this.getFontsInBlock(e.entities,n,s,t),Array.from(t)}getFontsInBlock(e,n,s,o){const t=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const p=i;[...p.text.matchAll(t)].forEach(c=>{o.add(c[1].toLowerCase())});const l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="TEXT"){const p=i,l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="INSERT"){const p=i,l=n.get(p.name);l&&this.getFontsInBlock(l.entities,n,s,o)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(o=>{const t={name:o.name,description:o.description,standardFlag:o.standardFlag,totalPatternLength:o.totalPatternLength,pattern:o.pattern},i=new r.AcDbLinetypeTableRecord(t);this.processCommonTableEntryAttrs(o,i),i.name=o.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(o=>{const t=new r.AcDbTextStyleTableRecord(o);this.processCommonTableEntryAttrs(o,t),n.tables.textStyleTable.add(t)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(o=>{const t={name:o.name,ownerId:o.ownerHandle,dimpost:o.DIMPOST||"",dimapost:o.DIMAPOST||"",dimscale:o.DIMSCALE,dimasz:o.DIMASZ,dimexo:o.DIMEXO,dimdli:o.DIMDLI,dimexe:o.DIMEXE,dimrnd:o.DIMRND,dimdle:o.DIMDLE,dimtp:o.DIMTP,dimtm:o.DIMTM,dimtxt:o.DIMTXT,dimcen:o.DIMCEN,dimtsz:o.DIMTSZ,dimaltf:o.DIMALTF,dimlfac:o.DIMLFAC,dimtvp:o.DIMTVP,dimtfac:o.DIMTFAC,dimgap:o.DIMGAP,dimaltrnd:o.DIMALTRND,dimtol:o.DIMTOL==null||o.DIMTOL==0?0:1,dimlim:o.DIMLIM==null||o.DIMLIM==0?0:1,dimtih:o.DIMTIH==null||o.DIMTIH==0?0:1,dimtoh:o.DIMTOH==null||o.DIMTOH==0?0:1,dimse1:o.DIMSE1==null||o.DIMSE1==0?0:1,dimse2:o.DIMSE2==null||o.DIMSE2==0?0:1,dimtad:o.DIMTAD,dimzin:o.DIMZIN,dimazin:o.DIMAZIN,dimalt:o.DIMALT,dimaltd:o.DIMALTD,dimtofl:o.DIMTOFL,dimsah:o.DIMSAH,dimtix:o.DIMTIX,dimsoxd:o.DIMSOXD,dimclrd:o.DIMCLRD,dimclre:o.DIMCLRE,dimclrt:o.DIMCLRT,dimadec:o.DIMADEC||0,dimunit:o.DIMUNIT||2,dimdec:o.DIMDEC,dimtdec:o.DIMTDEC,dimaltu:o.DIMALTU,dimalttd:o.DIMALTTD,dimaunit:o.DIMAUNIT,dimfrac:o.DIMFRAC,dimlunit:o.DIMLUNIT,dimdsep:o.DIMDSEP||".",dimtmove:o.DIMTMOVE||0,dimjust:o.DIMJUST,dimsd1:o.DIMSD1,dimsd2:o.DIMSD2,dimtolj:o.DIMTOLJ,dimtzin:o.DIMTZIN,dimaltz:o.DIMALTZ,dimalttz:o.DIMALTTZ,dimfit:o.DIMFIT||0,dimupt:o.DIMUPT,dimatfit:o.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:o.DIMBLK||"",dimblk1:o.DIMBLK1||"",dimblk2:o.DIMBLK2||"",dimlwd:o.DIMLWD,dimlwe:o.DIMLWE},i=new r.AcDbDimStyleTableRecord(t);this.processCommonTableEntryAttrs(o,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(o=>{const t=new r.AcCmColor;t.colorIndex=o.colorIndex;const i=new r.AcDbLayerTableRecord({name:o.name,standardFlags:o.standardFlag,linetype:o.lineType,lineWeight:o.lineweight,isOff:o.off,color:t,isPlottable:o.plotFlag!=0});this.processCommonTableEntryAttrs(o,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(o=>{const t=new r.AcDbViewportTableRecord;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)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(o=>{let t=n.tables.blockTable.getAt(o.name);t||(t=new r.AcDbBlockTableRecord,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)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const s=new y,o=e.length,t=[];for(let i=0;i<o;i++){const p=e[i],l=s.convert(p);l&&t.push(l)}n.appendEntity(t)}async processEntities(e,n,s,o,t){const i=new y;let p=[];e.tables.BLOCK_RECORD.entries.forEach(a=>{this.isModelSpace(a.name)&&(p=a.entities)});const l=p.length,c=new r.AcDbBatchProcessing(l,100-o.value,s);this.config.convertByEntityType&&(p=this.groupAndFlattenByType(p));const u=n.tables.blockTable.modelSpace;await c.processChunk(async(a,d)=>{const f=[];for(let h=a;h<d;h++){const g=p[h],A=i.convert(g);A&&f.push(A)}if(u.appendEntity(f),t){let h=o.value+d/l*(100-o.value);h>100&&(h=100),await t(h,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const s=e.header;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??r.ByLayer,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??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,n.ownerId=e.ownerHandle}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const s=n.objects.layout;e.objects.LAYOUT.forEach(t=>{const i=new r.AcDbLayout;i.layoutName=t.layoutName,i.tabOrder=t.tabOrder;const p=n.tables.blockTable.newIterator();i.objectId=t.handle;for(const l of p)if(l.layoutId===i.objectId){i.blockTableRecordId=l.objectId;break}i.blockTableRecordId||t.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(t.minLimit),i.limits.max.copy(t.maxLimit),i.extents.min.copy(t.minExtent),i.extents.max.copy(t.maxExtent),t.viewportId&&i.viewportArray.push(t.viewportId),this.processCommonObjectAttrs(t,i),s.setAt(i.layoutName,i)})}processImageDefs(e,n){const s=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(t=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=t.fileName,this.processCommonObjectAttrs(t,i),s.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,n.ownerId=e.ownerHandle}groupAndFlattenByType(e){const n={},s=[];for(const o of e)n[o.type]||(n[o.type]=[],s.push(o.type)),n[o.type].push(o);return s.flatMap(o=>n[o])}isModelSpace(e){return e&&e.toUpperCase()==b}}D.AcDbLibreDwgConverter=I,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel))})(this,function(D,r){"use strict";class y{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return e.type=="3DFACE"?this.convertFace(e):e.type=="ARC"?this.convertArc(e):e.type=="ATTDEF"?this.convertAttributeDefinition(e):e.type=="CIRCLE"?this.convertCirle(e):e.type=="DIMENSION"?this.convertDimension(e):e.type=="ELLIPSE"?this.convertEllipse(e):e.type=="HATCH"?this.convertHatch(e):e.type=="IMAGE"?this.convertImage(e):e.type=="LEADER"?this.convertLeader(e):e.type=="LINE"?this.convertLine(e):e.type=="LWPOLYLINE"?this.convertLWPolyline(e):e.type=="MTEXT"?this.convertMText(e):e.type=="POINT"?this.convertPoint(e):e.type=="POLYLINE2D"?this.convertPolyline2d(e):e.type=="POLYLINE3D"?this.convertPolyline3d(e):e.type=="RAY"?this.convertRay(e):e.type=="SPLINE"?this.convertSpline(e):e.type=="ACAD_TABLE"?this.convertTable(e):e.type=="TEXT"?this.convertText(e):e.type=="SOLID"?this.convertSolid(e):e.type=="VIEWPORT"?this.convertViewport(e):e.type=="WIPEOUT"?this.convertWipeout(e):e.type=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertFace(e){const n=new r.AcDbFace;return e.corner1&&n.setVertexAt(0,e.corner1),e.corner2&&n.setVertexAt(1,e.corner2),e.corner3&&n.setVertexAt(2,e.corner3),e.corner4&&n.setVertexAt(3,e.corner4),n.setEdgeInvisibilities(e.flag),n}convertArc(e){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbArc(r.transformOcsPointToWcs(e.center,n),e.radius,e.startAngle,e.endAngle,n)}convertCirle(e){const n=e.extrusionDirection??r.AcGeVector3d.Z_AXIS;return new r.AcDbCircle(r.transformOcsPointToWcs(e.center,n),e.radius,n)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),s=n.length();return new r.AcDbEllipse(e.center,e.extrusionDirection??r.AcGeVector3d.Z_AXIS,n,s,s*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,s=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(s.x,s.y,s.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch{}return null}convertPoint(e){const n=new r.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new r.AcDbTrace;return n.setPointAt(0,{...e.corner1,z:0}),n.setPointAt(1,{...e.corner2,z:0}),n.setPointAt(2,{...e.corner3,z:0}),n.setPointAt(3,e.corner4?{...e.corner4,z:0}:{...e.corner3,z:0}),n.thickness=e.thickness,n}convertLWPolyline(e){const n=new r.AcDbPolyline;n.closed=!!(e.flag&512);const s=e.constantWidth??-1;return e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth??s,o.endWidth??s)}),n}convertPolyline2d(e){const n=!!(e.flag&1),s=!!(e.flag&16),o=!!(e.flag&64),t=!!(e.flag&32),i=[],p=[],l=[];if(e.vertices.map(c=>{if(!(c.flag&16))if(o&&c.flag&128)if(c.flag&64)i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0);else{const u=[];c.polyfaceIndex0!=null&&c.polyfaceIndex0!=0&&u.push(Math.abs(c.polyfaceIndex0)-1),c.polyfaceIndex1!=null&&c.polyfaceIndex1!=0&&u.push(Math.abs(c.polyfaceIndex1)-1),c.polyfaceIndex2!=null&&c.polyfaceIndex2!=0&&u.push(Math.abs(c.polyfaceIndex2)-1),c.polyfaceIndex3!=null&&c.polyfaceIndex3!=0&&u.push(Math.abs(c.polyfaceIndex3)-1),u.length>=3&&l.push(u)}else i.push({x:c.x,y:c.y,z:c.z}),p.push(c.bulge??0)}),s){const c=e.meshMVertexCount??2,u=e.meshNVertexCount??2;return new r.AcDbPolygonMesh(c,u,i,n,t)}else{if(o)return new r.AcDbPolyFaceMesh(i,l);{let c=r.AcDbPoly2dType.SimplePoly;return e.flag&2?c=r.AcDbPoly2dType.FitCurvePoly:e.flag&4&&(e.smoothType==6?c=r.AcDbPoly2dType.CubicSplinePoly:e.smoothType==5&&(c=r.AcDbPoly2dType.QuadSplinePoly)),new r.AcDb2dPolyline(c,i,0,n,e.startWidth,e.endWidth,p)}}}convertPolyline3d(e){const n=!!(e.flag&1),s=[];e.vertices.map(t=>{t.flag&16||s.push({x:t.x,y:t.y,z:t.z})});let o=r.AcDbPoly3dType.SimplePoly;return e.flag&4&&(e.smoothType==6?o=r.AcDbPoly3dType.CubicSplinePoly:e.smoothType==5&&(o=r.AcDbPoly3dType.QuadSplinePoly)),new r.AcDb3dPolyline(o,s,n)}convertHatch(e){var o;const n=new r.AcDbHatch;return(o=e.definitionLines)==null||o.forEach(t=>{n.definitionLines.push({angle:t.angle,base:t.base,offset:t.offset,dashLengths:t.numberOfDashLengths>0?t.dashLengths:[]})}),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=>{if(t.boundaryPathTypeFlag&2){const p=t,l=new r.AcGePolyline2d;l.closed=p.isClosed,p.vertices.forEach((c,u)=>{l.addVertexAt(u,{x:c.x,y:c.y,bulge:c.bulge})}),n.add(l)}else{const p=t,l=[];p.edges.forEach(u=>{if(u!=null){if(u.type==1){const a=u;l.push(new r.AcGeLine2d(a.start,a.end))}else if(u.type==2){const a=u;l.push(new r.AcGeCircArc2d(a.center,a.radius,a.startAngle,a.endAngle,!a.isCCW))}else if(u.type==3){const a=u;new r.AcGeVector2d().subVectors(a.end,a.center);const f=Math.sqrt(Math.pow(a.end.x,2)+Math.pow(a.end.y,2)),h=f*a.lengthOfMinorAxis;let g=a.startAngle,A=a.endAngle;const w=Math.atan2(a.end.y,a.end.x);a.isCCW||(g=Math.PI*2-g,A=Math.PI*2-A),l.push(new r.AcGeEllipseArc2d({...a.center,z:0},f,h,g,A,!a.isCCW,w))}else if(u.type==4){const a=u;if(a.numberOfControlPoints>0&&a.numberOfKnots>0){const d=a.controlPoints.map(g=>({x:g.x,y:g.y,z:0}));let f=!0;const h=a.controlPoints.map(g=>(g.weight==null&&(f=!1),g.weight||1));l.push(new r.AcGeSpline3d(d,a.knots,f?h:void 0))}else if(a.numberOfFitData>0){const d=a.fitDatum.map(f=>({x:f.x,y:f.y,z:0}));l.push(new r.AcGeSpline3d(d,"Uniform"))}}}});const c=r.AcGeLoop2d.buildFromEdges(l);c.length==0&&l.length>0?n.add(new r.AcGeLoop2d(l)):c.forEach(u=>n.add(u))}}),n}convertTable(e){const n=new r.AcDbTable(e.name,e.rowCount,e.columnCount);return n.tableStyleId=e.tableStyleId,n.owningBlockRecordId=e.blockRecordHandle,e.directionVector&&(n.horizontalDirection=new r.AcGeVector3d(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((s,o)=>n.setColumnWidth(o,s)),e.rowHeightArr.forEach((s,o)=>n.setRowHeight(o,s)),e.cells.forEach((s,o)=>{n.setCell(o,s)}),n}convertText(e){const n=new r.AcDbText;return n.textString=e.text,n.styleName=e.styleName,n.height=e.textHeight,n.position.copy(e.startPoint),n.rotation=e.rotation,n.oblique=e.obliqueAngle??0,n.thickness=e.thickness,n.horizontalMode=e.halign,n.verticalMode=e.valign,n.widthFactor=e.xScale??1,n}convertMText(e){const n=new r.AcDbMText;return n.contents=e.text,e.styleName!=null&&(n.styleName=e.styleName),n.height=e.textHeight,n.width=e.rectWidth,n.rotation=e.rotation||0,n.location=e.insertionPoint,n.attachmentPoint=e.attachmentPoint,e.direction&&(n.direction=new r.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new r.AcDbLeader;return e.vertices.forEach(s=>{n.appendVertex(s)}),n.hasArrowHead=e.isArrowheadEnabled,n.hasHookLine=e.isHooklineExists,n.isSplined=e.isSpline,n.dimensionStyle=e.styleName,n.annoType=e.leaderCreationFlag,n}convertDimension(e){if(e.subclassMarker=="AcDbAlignedDimension"){const n=e,s=new r.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRotatedDimension"){const n=e,s=new r.AcDbRotatedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return n.insertionPoint&&(s.dimBlockPosition={x:n.insertionPoint.x,y:n.insertionPoint.y,z:0}),s.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,s=new r.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,s=new r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,s=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,s=new r.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,s),s}return null}processImage(e,n){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=>{n.clipBoundary.push(new r.AcGePoint2d(s))}),n.clipBoundaryType=e.clippingBoundaryType,n.width=Math.sqrt(e.uPixel.x**2+e.uPixel.y**2+e.uPixel.z**2)*e.imageSize.x,n.height=Math.sqrt(e.vPixel.x**2+e.vPixel.y**2+e.vPixel.z**2)*e.imageSize.y,n.rotation=Math.atan2(e.uPixel.y,e.uPixel.x)}convertImage(e){const n=new r.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new r.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new r.AcDbViewport;return n.number=e.viewportId,n.centerPoint.copy(e.viewportCenter),n.height=e.height,n.width=e.width,n.viewCenter.copy(e.displayCenter),n.viewHeight=e.viewHeight,n}convertRay(e){const n=new r.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new r.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertAttributeCommon(e,n){const s=e.text;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&r.AcDbAttributeFlags.Invisible)!==0,n.isConst=(e.flags&r.AcDbAttributeFlags.Const)!==0,n.isVerifiable=(e.flags&r.AcDbAttributeFlags.Verifiable)!==0,n.isPreset=(e.flags&r.AcDbAttributeFlags.Preset)!==0,n.lockPositionInBlock=e.lockPositionFlag,n.isReallyLocked=e.isReallyLocked,n.isMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.MultiLine)!==0,n.isConstMTextAttribute=(e.mtextFlag&r.AcDbAttributeMTextFlag.ConstMultiLine)!==0}convertAttribute(e){const n=new r.AcDbAttribute;return this.convertAttributeCommon(e,n),n}convertAttributeDefinition(e){const n=new r.AcDbAttributeDefinition;return this.convertAttributeCommon(e,n),n.prompt=e.prompt,n}convertBlockReference(e){const n=new r.AcDbBlockReference(e.name);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=>{const o=this.convertAttribute(s);n.appendAttributes(o)}),n}processDimensionCommonAttrs(e,n){n.dimBlockId=e.name,n.textPosition.copy(e.textPoint),n.textRotation=e.textRotation||0,e.textLineSpacingFactor&&(n.textLineSpacingFactor=e.textLineSpacingFactor),e.textLineSpacingStyle&&(n.textLineSpacingStyle=e.textLineSpacingStyle),n.dimensionStyleName=e.styleName,n.dimensionText=e.text||"",n.measurement=e.measurement}processCommonAttrs(e,n){if(n.layer=e.layer||"0",n.objectId=e.handle,e.ownerBlockRecordSoftId!=null&&(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&&(e.color==null||e.colorIndex===7)&&(n.color.colorIndex=e.colorIndex),e.colorName&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null){const s=new r.AcCmTransparency;s.method=e.transparencyType,(s.isByBlock||s.isByBlock)&&(s.alpha=e.transparency),n.transparency=s}}}const I="*MODEL_SPACE";class b extends r.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e,n){const s=this.config,o=this.getParserWorkerTimeout(e,n);if(s.useWorker&&s.parserWorkerUrl){const t=r.createWorkerApi({workerUrl:s.parserWorkerUrl,timeout:o,maxConcurrentWorkers:1}),i=await t.execute(e);if(t.destroy(),i.success)return i.data;throw new Error(`Failed to parse drawing due to error: '${i.error}'`)}else throw new Error("dwg converter can run in web worker only!")}getFonts(e){const n=new Map;e.tables.BLOCK_RECORD.entries.forEach(i=>{n.set(i.name,i)});const s=new Map,o=i=>{if(i){const p=i.lastIndexOf(".");return p>=0?i.substring(0,p).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const p=[];let l=o(i.font);l&&p.push(l),l=o(i.bigFont),l&&p.push(l),s.set(i.name,p)});const t=new Set;return this.getFontsInBlock(e.entities,n,s,t),Array.from(t)}getFontsInBlock(e,n,s,o){const t=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const p=i;[...p.text.matchAll(t)].forEach(c=>{o.add(c[1].toLowerCase())});const l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="TEXT"){const p=i,l=s.get(p.styleName);l==null||l.forEach(c=>o.add(c))}else if(i.type=="INSERT"){const p=i,l=n.get(p.name);l&&this.getFontsInBlock(l.entities,n,s,o)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(o=>{const t={name:o.name,description:o.description,standardFlag:o.standardFlag,totalPatternLength:o.totalPatternLength,pattern:o.pattern},i=new r.AcDbLinetypeTableRecord(t);this.processCommonTableEntryAttrs(o,i),i.name=o.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(o=>{const t=new r.AcDbTextStyleTableRecord(o);this.processCommonTableEntryAttrs(o,t),n.tables.textStyleTable.add(t)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(o=>{const t={name:o.name,ownerId:o.ownerHandle,dimpost:o.DIMPOST||"",dimapost:o.DIMAPOST||"",dimscale:o.DIMSCALE,dimasz:o.DIMASZ,dimexo:o.DIMEXO,dimdli:o.DIMDLI,dimexe:o.DIMEXE,dimrnd:o.DIMRND,dimdle:o.DIMDLE,dimtp:o.DIMTP,dimtm:o.DIMTM,dimtxt:o.DIMTXT,dimcen:o.DIMCEN,dimtsz:o.DIMTSZ,dimaltf:o.DIMALTF,dimlfac:o.DIMLFAC,dimtvp:o.DIMTVP,dimtfac:o.DIMTFAC,dimgap:o.DIMGAP,dimaltrnd:o.DIMALTRND,dimtol:o.DIMTOL==null||o.DIMTOL==0?0:1,dimlim:o.DIMLIM==null||o.DIMLIM==0?0:1,dimtih:o.DIMTIH==null||o.DIMTIH==0?0:1,dimtoh:o.DIMTOH==null||o.DIMTOH==0?0:1,dimse1:o.DIMSE1==null||o.DIMSE1==0?0:1,dimse2:o.DIMSE2==null||o.DIMSE2==0?0:1,dimtad:o.DIMTAD,dimzin:o.DIMZIN,dimazin:o.DIMAZIN,dimalt:o.DIMALT,dimaltd:o.DIMALTD,dimtofl:o.DIMTOFL,dimsah:o.DIMSAH,dimtix:o.DIMTIX,dimsoxd:o.DIMSOXD,dimclrd:o.DIMCLRD,dimclre:o.DIMCLRE,dimclrt:o.DIMCLRT,dimadec:o.DIMADEC||0,dimunit:o.DIMUNIT||2,dimdec:o.DIMDEC,dimtdec:o.DIMTDEC,dimaltu:o.DIMALTU,dimalttd:o.DIMALTTD,dimaunit:o.DIMAUNIT,dimfrac:o.DIMFRAC,dimlunit:o.DIMLUNIT,dimdsep:o.DIMDSEP||".",dimtmove:o.DIMTMOVE||0,dimjust:o.DIMJUST,dimsd1:o.DIMSD1,dimsd2:o.DIMSD2,dimtolj:o.DIMTOLJ,dimtzin:o.DIMTZIN,dimaltz:o.DIMALTZ,dimalttz:o.DIMALTTZ,dimfit:o.DIMFIT||0,dimupt:o.DIMUPT,dimatfit:o.DIMATFIT,dimtxsty:r.DEFAULT_TEXT_STYLE,dimldrblk:"",dimblk:o.DIMBLK||"",dimblk1:o.DIMBLK1||"",dimblk2:o.DIMBLK2||"",dimlwd:o.DIMLWD,dimlwe:o.DIMLWE},i=new r.AcDbDimStyleTableRecord(t);this.processCommonTableEntryAttrs(o,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(o=>{const t=new r.AcCmColor;t.colorIndex=o.colorIndex;const i=new r.AcDbLayerTableRecord({name:o.name,standardFlags:o.standardFlag,linetype:o.lineType,lineWeight:o.lineweight,isOff:o.off,color:t,isPlottable:o.plotFlag!=0});this.processCommonTableEntryAttrs(o,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(o=>{const t=new r.AcDbViewportTableRecord;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)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(o=>{let t=n.tables.blockTable.getAt(o.name);t||(t=new r.AcDbBlockTableRecord,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)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const s=new y,o=e.length,t=[];for(let i=0;i<o;i++){const p=e[i],l=s.convert(p);l&&t.push(l)}n.appendEntity(t)}async processEntities(e,n,s,o,t){const i=new y;let p=[];e.tables.BLOCK_RECORD.entries.forEach(a=>{this.isModelSpace(a.name)&&(p=a.entities)});const l=p.length,c=new r.AcDbBatchProcessing(l,100-o.value,s);this.config.convertByEntityType&&(p=this.groupAndFlattenByType(p));const u=n.tables.blockTable.modelSpace;await c.processChunk(async(a,d)=>{const f=[];for(let h=a;h<d;h++){const g=p[h],A=i.convert(g);A&&f.push(A)}if(u.appendEntity(f),t){let h=o.value+d/l*(100-o.value);h>100&&(h=100),await t(h,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const s=e.header;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??r.ByLayer,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??r.DEFAULT_TEXT_STYLE}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const s=n.objects.layout;e.objects.LAYOUT.forEach(t=>{const i=new r.AcDbLayout;i.layoutName=t.layoutName,i.tabOrder=t.tabOrder;const p=n.tables.blockTable.newIterator();i.objectId=t.handle;for(const l of p)if(l.layoutId===i.objectId){i.blockTableRecordId=l.objectId;break}i.blockTableRecordId||t.layoutName==="Model"&&(i.blockTableRecordId=n.tables.blockTable.modelSpace.objectId),i.limits.min.copy(t.minLimit),i.limits.max.copy(t.maxLimit),i.extents.min.copy(t.minExtent),i.extents.max.copy(t.maxExtent),t.viewportId&&i.viewportArray.push(t.viewportId),this.processCommonObjectAttrs(t,i),s.setAt(i.layoutName,i)})}processImageDefs(e,n){const s=n.objects.imageDefinition;e.objects.IMAGEDEF.forEach(t=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=t.fileName,this.processCommonObjectAttrs(t,i),s.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle,e.ownerHandle!=null&&(n.ownerId=e.ownerHandle)}groupAndFlattenByType(e){const n={},s=[];for(const o of e)n[o.type]||(n[o.type]=[],s.push(o.type)),n[o.type].push(o);return s.flatMap(o=>n[o])}isModelSpace(e){return e&&e.toUpperCase()==I}}D.AcDbLibreDwgConverter=b,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|