@mlightcad/libredwg-converter 3.1.1 → 3.1.3
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/package.json +2 -2
- package/dist/libredwg-converter.js +0 -584
- package/dist/libredwg-converter.umd.cjs +0 -1
- package/dist/libredwg-parser-worker.js +0 -15411
- package/lib/AcDbEntitiyConverter.d.ts +0 -37
- package/lib/AcDbEntitiyConverter.d.ts.map +0 -1
- package/lib/AcDbEntitiyConverter.js +0 -502
- package/lib/AcDbEntitiyConverter.js.map +0 -1
- package/lib/AcDbLibreDwgConverter.d.ts +0 -56
- package/lib/AcDbLibreDwgConverter.d.ts.map +0 -1
- package/lib/AcDbLibreDwgConverter.js +0 -646
- package/lib/AcDbLibreDwgConverter.js.map +0 -1
- package/lib/AcDbLibreDwgConverterUtil.d.ts +0 -7
- package/lib/AcDbLibreDwgConverterUtil.d.ts.map +0 -1
- package/lib/AcDbLibreDwgConverterUtil.js +0 -60
- package/lib/AcDbLibreDwgConverterUtil.js.map +0 -1
- package/lib/AcDbLibreDwgParserWorker.d.ts +0 -2
- package/lib/AcDbLibreDwgParserWorker.d.ts.map +0 -1
- package/lib/AcDbLibreDwgParserWorker.js +0 -83
- package/lib/AcDbLibreDwgParserWorker.js.map +0 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/libredwg-converter",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"vite": "^5.2.10"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@mlightcad/data-model": "1.3.
|
|
42
|
+
"@mlightcad/data-model": "1.3.3"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|
|
@@ -1,584 +0,0 @@
|
|
|
1
|
-
import { AcDbFace as M, AcDbArc as S, AcDbCircle as P, AcGeVector3d as g, AcDbEllipse as L, AcDbLine as C, AcGePoint3d as I, AcDbSpline as w, AcDbPoint as x, AcDbTrace as v, AcDbPolyline as b, AcGePoint2d as A, AcDbHatch as O, AcGePolyline2d as k, AcGeLoop2d as R, AcGeLine2d as V, AcGeCircArc2d as N, AcGeVector2d as m, AcGeEllipseArc2d as F, AcGeSpline3d as T, AcDbTable as B, AcDbText as j, AcDbMText as W, AcDbLeader as z, AcDbAlignedDimension as H, AcDb3PointAngularDimension as X, AcDbOrdinateDimension as G, AcDbRadialDimension as U, AcDbDiametricDimension as Y, AcDbRasterImage as Z, AcDbWipeout as K, AcDbViewport as _, AcDbRay as q, AcDbXline as J, AcDbBlockReference as $, AcDbDatabaseConverter as Q, createWorkerApi as ee, AcDbLinetypeTableRecord as ne, AcDbTextStyleTableRecord as te, AcDbDimStyleTableRecord as oe, AcCmColor as re, AcDbLayerTableRecord as se, AcDbViewportTableRecord as ie, AcDbBlockTableRecord as ce, AcDbBatchProcessing as ae, AcDbLayout as le, AcDbRasterImageDef as de } from "@mlightcad/data-model";
|
|
2
|
-
class y {
|
|
3
|
-
convert(e) {
|
|
4
|
-
const n = this.createEntity(e);
|
|
5
|
-
return n && this.processCommonAttrs(e, n), n;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Create the corresponding drawing database entity from data in dxf format
|
|
9
|
-
* @param entity Input entity data in dxf format
|
|
10
|
-
* @returns Return the converted drawing database entity
|
|
11
|
-
*/
|
|
12
|
-
createEntity(e) {
|
|
13
|
-
return e.type == "3DFACE" ? this.convertFace(e) : e.type == "ARC" ? this.convertArc(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 == "POLYLINE" ? this.convertPolyline(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;
|
|
14
|
-
}
|
|
15
|
-
convertFace(e) {
|
|
16
|
-
const n = new M();
|
|
17
|
-
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;
|
|
18
|
-
}
|
|
19
|
-
convertArc(e) {
|
|
20
|
-
return new S(
|
|
21
|
-
e.center,
|
|
22
|
-
e.radius,
|
|
23
|
-
e.startAngle,
|
|
24
|
-
e.endAngle
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
convertCirle(e) {
|
|
28
|
-
return new P(e.center, e.radius);
|
|
29
|
-
}
|
|
30
|
-
convertEllipse(e) {
|
|
31
|
-
const n = new g(e.majorAxisEndPoint), r = n.length();
|
|
32
|
-
return new L(
|
|
33
|
-
e.center,
|
|
34
|
-
e.extrusionDirection ?? g.Z_AXIS,
|
|
35
|
-
n,
|
|
36
|
-
r,
|
|
37
|
-
r * e.axisRatio,
|
|
38
|
-
e.startAngle,
|
|
39
|
-
e.endAngle
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
convertLine(e) {
|
|
43
|
-
const n = e.startPoint, r = e.endPoint;
|
|
44
|
-
return new C(
|
|
45
|
-
new I(n.x, n.y, n.z),
|
|
46
|
-
new I(r.x, r.y, r.z)
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
convertSpline(e) {
|
|
50
|
-
try {
|
|
51
|
-
if (e.numberOfControlPoints > 0 && e.numberOfKnots > 0)
|
|
52
|
-
return new w(
|
|
53
|
-
e.controlPoints,
|
|
54
|
-
e.knots,
|
|
55
|
-
e.weights,
|
|
56
|
-
e.degree,
|
|
57
|
-
!!(e.flag & 1)
|
|
58
|
-
);
|
|
59
|
-
if (e.numberOfFitPoints > 0)
|
|
60
|
-
return new w(
|
|
61
|
-
e.fitPoints,
|
|
62
|
-
"Uniform",
|
|
63
|
-
e.degree,
|
|
64
|
-
!!(e.flag & 1)
|
|
65
|
-
);
|
|
66
|
-
} catch (n) {
|
|
67
|
-
console.log(`Failed to convert spline with error: ${n}`);
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
convertPoint(e) {
|
|
72
|
-
const n = new x();
|
|
73
|
-
return n.position = e.position, n;
|
|
74
|
-
}
|
|
75
|
-
convertSolid(e) {
|
|
76
|
-
const n = new v();
|
|
77
|
-
return n.setPointAt(0, { ...e.corner1, z: 0 }), n.setPointAt(1, { ...e.corner2, z: 0 }), n.setPointAt(2, { ...e.corner3, z: 0 }), n.setPointAt(
|
|
78
|
-
3,
|
|
79
|
-
e.corner4 ? { ...e.corner4, z: 0 } : { ...e.corner3, z: 0 }
|
|
80
|
-
), n.thickness = e.thickness, n;
|
|
81
|
-
}
|
|
82
|
-
convertLWPolyline(e) {
|
|
83
|
-
const n = new b();
|
|
84
|
-
return n.closed = !!(e.flag & 512), e.vertices.forEach((r, t) => {
|
|
85
|
-
n.addVertexAt(
|
|
86
|
-
t,
|
|
87
|
-
new A(r.x, r.y),
|
|
88
|
-
r.bulge,
|
|
89
|
-
r.startWidth,
|
|
90
|
-
r.endWidth
|
|
91
|
-
);
|
|
92
|
-
}), n;
|
|
93
|
-
}
|
|
94
|
-
convertPolyline(e) {
|
|
95
|
-
const n = new b();
|
|
96
|
-
return n.closed = !!(e.flag & 1), e.vertices.forEach((r, t) => {
|
|
97
|
-
n.addVertexAt(
|
|
98
|
-
t,
|
|
99
|
-
new A(r.x, r.y),
|
|
100
|
-
r.bulge,
|
|
101
|
-
r.startWidth,
|
|
102
|
-
r.endWidth
|
|
103
|
-
);
|
|
104
|
-
}), n;
|
|
105
|
-
}
|
|
106
|
-
convertHatch(e) {
|
|
107
|
-
var t;
|
|
108
|
-
const n = new O();
|
|
109
|
-
return (t = e.definitionLines) == null || t.forEach((o) => {
|
|
110
|
-
n.definitionLines.push({
|
|
111
|
-
angle: o.angle,
|
|
112
|
-
origin: o.base,
|
|
113
|
-
delta: o.offset,
|
|
114
|
-
dashPattern: o.numberOfDashLengths > 0 ? o.dashLengths : []
|
|
115
|
-
});
|
|
116
|
-
}), 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((o) => {
|
|
117
|
-
if (o.boundaryPathTypeFlag & 2) {
|
|
118
|
-
const a = o, i = new k();
|
|
119
|
-
i.closed = a.isClosed, a.vertices.forEach((l, c) => {
|
|
120
|
-
i.addVertexAt(c, {
|
|
121
|
-
x: l.x,
|
|
122
|
-
y: l.y,
|
|
123
|
-
bulge: l.bulge
|
|
124
|
-
});
|
|
125
|
-
}), n.add(i);
|
|
126
|
-
} else {
|
|
127
|
-
const a = o, i = new R();
|
|
128
|
-
a.edges.forEach((l) => {
|
|
129
|
-
if (l != null) {
|
|
130
|
-
if (l.type == 1) {
|
|
131
|
-
const c = l;
|
|
132
|
-
i.add(new V(c.start, c.end));
|
|
133
|
-
} else if (l.type == 2) {
|
|
134
|
-
const c = l;
|
|
135
|
-
i.add(
|
|
136
|
-
new N(
|
|
137
|
-
c.center,
|
|
138
|
-
c.radius,
|
|
139
|
-
c.startAngle,
|
|
140
|
-
c.endAngle,
|
|
141
|
-
!c.isCCW
|
|
142
|
-
)
|
|
143
|
-
);
|
|
144
|
-
} else if (l.type == 3) {
|
|
145
|
-
const c = l;
|
|
146
|
-
new m().subVectors(c.end, c.center);
|
|
147
|
-
const p = Math.sqrt(
|
|
148
|
-
Math.pow(c.end.x, 2) + Math.pow(c.end.y, 2)
|
|
149
|
-
), f = p * c.lengthOfMinorAxis;
|
|
150
|
-
let d = c.startAngle, h = c.endAngle;
|
|
151
|
-
const D = Math.atan2(c.end.y, c.end.x);
|
|
152
|
-
c.isCCW || (d = Math.PI * 2 - d, h = Math.PI * 2 - h), i.add(
|
|
153
|
-
new F(
|
|
154
|
-
{ ...c.center, z: 0 },
|
|
155
|
-
p,
|
|
156
|
-
f,
|
|
157
|
-
d,
|
|
158
|
-
h,
|
|
159
|
-
!c.isCCW,
|
|
160
|
-
D
|
|
161
|
-
)
|
|
162
|
-
);
|
|
163
|
-
} else if (l.type == 4) {
|
|
164
|
-
const c = l;
|
|
165
|
-
if (c.numberOfControlPoints > 0 && c.numberOfKnots > 0) {
|
|
166
|
-
const u = c.controlPoints.map(
|
|
167
|
-
(d) => ({
|
|
168
|
-
x: d.x,
|
|
169
|
-
y: d.y,
|
|
170
|
-
z: 0
|
|
171
|
-
})
|
|
172
|
-
);
|
|
173
|
-
let p = !0;
|
|
174
|
-
const f = c.controlPoints.map((d) => (d.weight == null && (p = !1), d.weight || 1));
|
|
175
|
-
i.add(
|
|
176
|
-
new T(
|
|
177
|
-
u,
|
|
178
|
-
c.knots,
|
|
179
|
-
p ? f : void 0
|
|
180
|
-
)
|
|
181
|
-
);
|
|
182
|
-
} else if (c.numberOfFitData > 0) {
|
|
183
|
-
const u = c.fitDatum.map((p) => ({
|
|
184
|
-
x: p.x,
|
|
185
|
-
y: p.y,
|
|
186
|
-
z: 0
|
|
187
|
-
}));
|
|
188
|
-
i.add(new T(u, "Uniform"));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}), n.add(i);
|
|
193
|
-
}
|
|
194
|
-
}), n;
|
|
195
|
-
}
|
|
196
|
-
convertTable(e) {
|
|
197
|
-
const n = new B(
|
|
198
|
-
e.name,
|
|
199
|
-
e.rowCount,
|
|
200
|
-
e.columnCount
|
|
201
|
-
);
|
|
202
|
-
return n.attachmentPoint = e.attachmentPoint, n.position.copy(e.startPoint), e.columnWidthArr.forEach(
|
|
203
|
-
(r, t) => n.setColumnWidth(t, r)
|
|
204
|
-
), e.rowHeightArr.forEach(
|
|
205
|
-
(r, t) => n.setRowHeight(t, r)
|
|
206
|
-
), e.cells.forEach((r, t) => {
|
|
207
|
-
n.setCell(t, r);
|
|
208
|
-
}), n;
|
|
209
|
-
}
|
|
210
|
-
convertText(e) {
|
|
211
|
-
const n = new j();
|
|
212
|
-
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;
|
|
213
|
-
}
|
|
214
|
-
convertMText(e) {
|
|
215
|
-
const n = new W();
|
|
216
|
-
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 g(e.direction)), n.drawingDirection = e.drawingDirection, n;
|
|
217
|
-
}
|
|
218
|
-
convertLeader(e) {
|
|
219
|
-
const n = new z();
|
|
220
|
-
return e.vertices.forEach((r) => {
|
|
221
|
-
n.appendVertex(r);
|
|
222
|
-
}), n.hasArrowHead = e.isArrowheadEnabled, n.hasHookLine = e.isHooklineExists, n.isSplined = e.isSpline, n.dimensionStyle = e.styleName, n.annoType = e.leaderCreationFlag, n;
|
|
223
|
-
}
|
|
224
|
-
convertDimension(e) {
|
|
225
|
-
if (e.subclassMarker == "AcDbAlignedDimension" || e.subclassMarker == "AcDbRotatedDimension") {
|
|
226
|
-
const n = e, r = new H(
|
|
227
|
-
n.subDefinitionPoint1,
|
|
228
|
-
n.subDefinitionPoint2,
|
|
229
|
-
n.definitionPoint
|
|
230
|
-
);
|
|
231
|
-
return r.rotation = n.rotationAngle, this.processDimensionCommonAttrs(e, r), r;
|
|
232
|
-
} else if (e.subclassMarker == "AcDb3PointAngularDimension") {
|
|
233
|
-
const n = e, r = new X(
|
|
234
|
-
n.centerPoint,
|
|
235
|
-
n.subDefinitionPoint1,
|
|
236
|
-
n.subDefinitionPoint2,
|
|
237
|
-
n.definitionPoint
|
|
238
|
-
);
|
|
239
|
-
return this.processDimensionCommonAttrs(e, r), r;
|
|
240
|
-
} else if (e.subclassMarker == "AcDbOrdinateDimension") {
|
|
241
|
-
const n = e, r = new G(
|
|
242
|
-
n.subDefinitionPoint1,
|
|
243
|
-
n.subDefinitionPoint2
|
|
244
|
-
);
|
|
245
|
-
return this.processDimensionCommonAttrs(e, r), r;
|
|
246
|
-
} else if (e.subclassMarker == "AcDbRadialDimension") {
|
|
247
|
-
const n = e, r = new U(
|
|
248
|
-
n.definitionPoint,
|
|
249
|
-
n.centerPoint,
|
|
250
|
-
n.leaderLength
|
|
251
|
-
);
|
|
252
|
-
return this.processDimensionCommonAttrs(e, r), r;
|
|
253
|
-
} else if (e.subclassMarker == "AcDbDiametricDimension") {
|
|
254
|
-
const n = e, r = new Y(
|
|
255
|
-
n.definitionPoint,
|
|
256
|
-
n.centerPoint,
|
|
257
|
-
n.leaderLength
|
|
258
|
-
);
|
|
259
|
-
return this.processDimensionCommonAttrs(e, r), r;
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
processImage(e, n) {
|
|
264
|
-
n.position.copy(e.position), n.brightness = e.brightness, n.contrast = e.contrast, n.fade = e.fade, n.imageDefId = e.imageDefHandle.toString(), 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((r) => {
|
|
265
|
-
n.clipBoundary.push(new A(r));
|
|
266
|
-
}), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
|
|
267
|
-
e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
|
|
268
|
-
) * e.imageSize.x, n.height = Math.sqrt(
|
|
269
|
-
e.vPixel.x ** 2 + e.vPixel.y ** 2 + e.vPixel.z ** 2
|
|
270
|
-
) * e.imageSize.y, n.rotation = Math.atan2(e.uPixel.y, e.uPixel.x);
|
|
271
|
-
}
|
|
272
|
-
convertImage(e) {
|
|
273
|
-
const n = new Z();
|
|
274
|
-
return this.processImage(e, n), n;
|
|
275
|
-
}
|
|
276
|
-
convertWipeout(e) {
|
|
277
|
-
const n = new K();
|
|
278
|
-
return this.processImage(e, n), n;
|
|
279
|
-
}
|
|
280
|
-
convertViewport(e) {
|
|
281
|
-
const n = new _();
|
|
282
|
-
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;
|
|
283
|
-
}
|
|
284
|
-
convertRay(e) {
|
|
285
|
-
const n = new q();
|
|
286
|
-
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
287
|
-
}
|
|
288
|
-
convertXline(e) {
|
|
289
|
-
const n = new J();
|
|
290
|
-
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
291
|
-
}
|
|
292
|
-
convertBlockReference(e) {
|
|
293
|
-
const n = new $(e.name);
|
|
294
|
-
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), n;
|
|
295
|
-
}
|
|
296
|
-
processDimensionCommonAttrs(e, n) {
|
|
297
|
-
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;
|
|
298
|
-
}
|
|
299
|
-
processCommonAttrs(e, n) {
|
|
300
|
-
n.layer = e.layer || "0", n.objectId = e.handle.toString(), n.ownerId = e.ownerBlockRecordSoftId.toString(), 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.color = e.color), e.colorIndex != null && (n.color.colorIndex = e.colorIndex), e.colorName != null && (n.color.colorName = e.colorName), e.isVisible != null && (n.visibility = e.isVisible), e.transparency != null && (n.transparency = e.transparency);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
class ue extends Q {
|
|
304
|
-
constructor(e = {}) {
|
|
305
|
-
super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
|
|
306
|
-
}
|
|
307
|
-
async parse(e) {
|
|
308
|
-
if (this.config.useWorker && this.config.parserWorkerUrl) {
|
|
309
|
-
const n = ee({
|
|
310
|
-
workerUrl: this.config.parserWorkerUrl,
|
|
311
|
-
// One concurrent worker needed for parser
|
|
312
|
-
maxConcurrentWorkers: 1
|
|
313
|
-
}), r = await n.execute(e);
|
|
314
|
-
return n.destroy(), r.data;
|
|
315
|
-
} else
|
|
316
|
-
throw new Error("dwg converter can run in web worker only!");
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Gets all of fonts used by entities in model space and paper space
|
|
320
|
-
* @param dwg dwg database model
|
|
321
|
-
* @returns Returns all of fonts used by entities in model space and paper space
|
|
322
|
-
*/
|
|
323
|
-
getFonts(e) {
|
|
324
|
-
const n = /* @__PURE__ */ new Map();
|
|
325
|
-
e.tables.BLOCK_RECORD.entries.forEach((s) => {
|
|
326
|
-
n.set(s.name, s);
|
|
327
|
-
});
|
|
328
|
-
const r = /* @__PURE__ */ new Map(), t = (s) => {
|
|
329
|
-
if (s) {
|
|
330
|
-
const a = s.lastIndexOf(".");
|
|
331
|
-
return a >= 0 ? s.substring(0, a).toLowerCase() : s.toLowerCase();
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
e.tables.STYLE.entries.forEach((s) => {
|
|
335
|
-
const a = [];
|
|
336
|
-
let i = t(s.font);
|
|
337
|
-
i && a.push(i), i = t(s.bigFont), i && a.push(i), r.set(s.name, a);
|
|
338
|
-
});
|
|
339
|
-
const o = /* @__PURE__ */ new Set();
|
|
340
|
-
return this.getFontsInBlock(e.entities, n, r, o), Array.from(o);
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Iterate entities in model space to get fonts used by text, mtext and insert entities
|
|
344
|
-
*/
|
|
345
|
-
getFontsInBlock(e, n, r, t) {
|
|
346
|
-
const o = /\\f(.*?)\|/g;
|
|
347
|
-
e.forEach((s) => {
|
|
348
|
-
if (s.type == "MTEXT") {
|
|
349
|
-
const a = s;
|
|
350
|
-
[...a.text.matchAll(o)].forEach((l) => {
|
|
351
|
-
t.add(l[1].toLowerCase());
|
|
352
|
-
});
|
|
353
|
-
const i = r.get(a.styleName);
|
|
354
|
-
i == null || i.forEach((l) => t.add(l));
|
|
355
|
-
} else if (s.type == "TEXT") {
|
|
356
|
-
const a = s, i = r.get(a.styleName);
|
|
357
|
-
i == null || i.forEach((l) => t.add(l));
|
|
358
|
-
} else if (s.type == "INSERT") {
|
|
359
|
-
const a = s, i = n.get(a.name);
|
|
360
|
-
i && this.getFontsInBlock(i.entities, n, r, t);
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
processLineTypes(e, n) {
|
|
365
|
-
e.tables.LTYPE.entries.forEach((t) => {
|
|
366
|
-
const o = {
|
|
367
|
-
name: t.name,
|
|
368
|
-
description: t.description,
|
|
369
|
-
standardFlag: t.standardFlag,
|
|
370
|
-
totalPatternLength: t.totalPatternLength,
|
|
371
|
-
pattern: t.pattern
|
|
372
|
-
}, s = new ne(o);
|
|
373
|
-
this.processCommonTableEntryAttrs(t, s), s.name = t.name, n.tables.linetypeTable.add(s);
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
processTextStyles(e, n) {
|
|
377
|
-
e.tables.STYLE.entries.forEach((t) => {
|
|
378
|
-
const o = new te(t);
|
|
379
|
-
this.processCommonTableEntryAttrs(t, o), n.tables.textStyleTable.add(o);
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
processDimStyles(e, n) {
|
|
383
|
-
e.tables.DIMSTYLE.entries.forEach((t) => {
|
|
384
|
-
const o = {
|
|
385
|
-
name: t.name,
|
|
386
|
-
ownerId: t.ownerHandle.toString(),
|
|
387
|
-
dimpost: t.DIMPOST || "",
|
|
388
|
-
dimapost: t.DIMAPOST || "",
|
|
389
|
-
dimscale: t.DIMSCALE,
|
|
390
|
-
dimasz: t.DIMASZ,
|
|
391
|
-
dimexo: t.DIMEXO,
|
|
392
|
-
dimdli: t.DIMDLI,
|
|
393
|
-
dimexe: t.DIMEXE,
|
|
394
|
-
dimrnd: t.DIMRND,
|
|
395
|
-
dimdle: t.DIMDLE,
|
|
396
|
-
dimtp: t.DIMTP,
|
|
397
|
-
dimtm: t.DIMTM,
|
|
398
|
-
dimtxt: t.DIMTXT,
|
|
399
|
-
dimcen: t.DIMCEN,
|
|
400
|
-
dimtsz: t.DIMTSZ,
|
|
401
|
-
dimaltf: t.DIMALTF,
|
|
402
|
-
dimlfac: t.DIMLFAC,
|
|
403
|
-
dimtvp: t.DIMTVP,
|
|
404
|
-
dimtfac: t.DIMTFAC,
|
|
405
|
-
dimgap: t.DIMGAP,
|
|
406
|
-
dimaltrnd: t.DIMALTRND,
|
|
407
|
-
dimtol: t.DIMTOL == null || t.DIMTOL == 0 ? 0 : 1,
|
|
408
|
-
dimlim: t.DIMLIM == null || t.DIMLIM == 0 ? 0 : 1,
|
|
409
|
-
dimtih: t.DIMTIH == null || t.DIMTIH == 0 ? 0 : 1,
|
|
410
|
-
dimtoh: t.DIMTOH == null || t.DIMTOH == 0 ? 0 : 1,
|
|
411
|
-
dimse1: t.DIMSE1 == null || t.DIMSE1 == 0 ? 0 : 1,
|
|
412
|
-
dimse2: t.DIMSE2 == null || t.DIMSE2 == 0 ? 0 : 1,
|
|
413
|
-
dimtad: t.DIMTAD,
|
|
414
|
-
dimzin: t.DIMZIN,
|
|
415
|
-
dimazin: t.DIMAZIN,
|
|
416
|
-
dimalt: t.DIMALT,
|
|
417
|
-
dimaltd: t.DIMALTD,
|
|
418
|
-
dimtofl: t.DIMTOFL,
|
|
419
|
-
dimsah: t.DIMSAH,
|
|
420
|
-
dimtix: t.DIMTIX,
|
|
421
|
-
dimsoxd: t.DIMSOXD,
|
|
422
|
-
dimclrd: t.DIMCLRD,
|
|
423
|
-
dimclre: t.DIMCLRE,
|
|
424
|
-
dimclrt: t.DIMCLRT,
|
|
425
|
-
dimadec: t.DIMADEC || 0,
|
|
426
|
-
dimunit: t.DIMUNIT || 2,
|
|
427
|
-
dimdec: t.DIMDEC,
|
|
428
|
-
dimtdec: t.DIMTDEC,
|
|
429
|
-
dimaltu: t.DIMALTU,
|
|
430
|
-
dimalttd: t.DIMALTTD,
|
|
431
|
-
dimaunit: t.DIMAUNIT,
|
|
432
|
-
dimfrac: t.DIMFRAC,
|
|
433
|
-
dimlunit: t.DIMLUNIT,
|
|
434
|
-
dimdsep: t.DIMDSEP,
|
|
435
|
-
dimtmove: t.DIMTMOVE || 0,
|
|
436
|
-
dimjust: t.DIMJUST,
|
|
437
|
-
dimsd1: t.DIMSD1,
|
|
438
|
-
dimsd2: t.DIMSD2,
|
|
439
|
-
dimtolj: t.DIMTOLJ,
|
|
440
|
-
dimtzin: t.DIMTZIN,
|
|
441
|
-
dimaltz: t.DIMALTZ,
|
|
442
|
-
dimalttz: t.DIMALTTZ,
|
|
443
|
-
dimfit: t.DIMFIT || 0,
|
|
444
|
-
dimupt: t.DIMUPT,
|
|
445
|
-
dimatfit: t.DIMATFIT,
|
|
446
|
-
dimtxsty: "Standard",
|
|
447
|
-
// TODO: Set correct value
|
|
448
|
-
dimldrblk: "",
|
|
449
|
-
// TODO: Set correct value
|
|
450
|
-
dimblk: t.DIMBLK || "",
|
|
451
|
-
// TODO: Set correct value
|
|
452
|
-
dimblk1: t.DIMBLK1 || "",
|
|
453
|
-
// TODO: Set correct value
|
|
454
|
-
dimblk2: t.DIMBLK2 || "",
|
|
455
|
-
// TODO: Set correct value
|
|
456
|
-
dimlwd: t.DIMLWD,
|
|
457
|
-
dimlwe: t.DIMLWE
|
|
458
|
-
}, s = new oe(o);
|
|
459
|
-
this.processCommonTableEntryAttrs(t, s), n.tables.dimStyleTable.add(s);
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
processLayers(e, n) {
|
|
463
|
-
e.tables.LAYER.entries.forEach((t) => {
|
|
464
|
-
const o = new re();
|
|
465
|
-
o.colorIndex = t.colorIndex;
|
|
466
|
-
const s = new se({
|
|
467
|
-
name: t.name,
|
|
468
|
-
standardFlags: t.standardFlag,
|
|
469
|
-
linetype: t.lineType,
|
|
470
|
-
lineWeight: t.lineweight,
|
|
471
|
-
isOff: t.off,
|
|
472
|
-
color: o,
|
|
473
|
-
isPlottable: t.plotFlag != 0
|
|
474
|
-
});
|
|
475
|
-
this.processCommonTableEntryAttrs(t, s), n.tables.layerTable.add(s);
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
processViewports(e, n) {
|
|
479
|
-
e.tables.VPORT.entries.forEach((t) => {
|
|
480
|
-
const o = new ie();
|
|
481
|
-
this.processCommonTableEntryAttrs(t, o), t.circleSides && (o.circleSides = t.circleSides), o.standardFlag = t.standardFlag, o.center.copy(t.center), o.lowerLeftCorner.copy(t.lowerLeftCorner), o.upperRightCorner.copy(t.upperRightCorner), t.snapBasePoint && o.snapBase.copy(t.snapBasePoint), t.snapRotationAngle && (o.snapAngle = t.snapRotationAngle), t.snapSpacing && o.snapIncrements.copy(t.snapSpacing), t.majorGridLines && (o.gridMajor = t.majorGridLines), t.gridSpacing && o.gridIncrements.copy(t.gridSpacing), t.backgroundObjectId && (o.backgroundObjectId = t.backgroundObjectId), o.gsView.center.copy(t.center), o.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget), o.gsView.viewTarget.copy(t.viewTarget), t.lensLength && (o.gsView.lensLength = t.lensLength), t.frontClippingPlane && (o.gsView.frontClippingPlane = t.frontClippingPlane), t.backClippingPlane && (o.gsView.backClippingPlane = t.backClippingPlane), t.viewHeight && (o.gsView.viewHeight = t.viewHeight), t.viewTwistAngle && (o.gsView.viewTwistAngle = t.viewTwistAngle), t.frozenLayers && (o.gsView.frozenLayers = t.frozenLayers), t.styleSheet && (o.gsView.styleSheet = t.styleSheet), t.renderMode && (o.gsView.renderMode = t.renderMode), t.viewMode && (o.gsView.viewMode = t.viewMode), t.ucsIconSetting && (o.gsView.ucsIconSetting = t.ucsIconSetting), t.ucsOrigin && o.gsView.ucsOrigin.copy(t.ucsOrigin), t.ucsXAxis && o.gsView.ucsXAxis.copy(t.ucsXAxis), t.ucsYAxis && o.gsView.ucsYAxis.copy(t.ucsYAxis), t.orthographicType && (o.gsView.orthographicType = t.orthographicType), t.shadePlotSetting && (o.gsView.shadePlotSetting = t.shadePlotSetting), t.shadePlotObjectId && (o.gsView.shadePlotObjectId = t.shadePlotObjectId), t.visualStyleObjectId && (o.gsView.visualStyleObjectId = t.visualStyleObjectId), t.isDefaultLightingOn && (o.gsView.isDefaultLightingOn = t.isDefaultLightingOn), t.defaultLightingType && (o.gsView.defaultLightingType = t.defaultLightingType), t.brightness && (o.gsView.brightness = t.brightness), t.contrast && (o.gsView.contrast = t.contrast), t.ambientColor && (o.gsView.ambientColor = t.ambientColor), n.tables.viewportTable.add(o);
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
processBlockTables(e, n) {
|
|
485
|
-
e.tables.BLOCK_RECORD.entries.forEach((t) => {
|
|
486
|
-
let o = n.tables.blockTable.getAt(t.name);
|
|
487
|
-
o || (o = new ce(), o.objectId = t.handle.toString(), o.name = t.name, o.ownerId = t.ownerHandle.toString(), o.origin.copy(t.basePoint), o.layoutId = t.layout.toString(), n.tables.blockTable.add(o)), !o.isModelSapce && !o.isPaperSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, o);
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
processBlocks(e, n) {
|
|
491
|
-
}
|
|
492
|
-
async processEntitiesInBlock(e, n) {
|
|
493
|
-
const r = new y(), t = e.length, o = [];
|
|
494
|
-
for (let s = 0; s < t; s++) {
|
|
495
|
-
const a = e[s], i = r.convert(a);
|
|
496
|
-
i && o.push(i);
|
|
497
|
-
}
|
|
498
|
-
n.appendEntity(o);
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Breaks up the work into smaller chunks that are executed asynchronously. This is often referred to
|
|
502
|
-
* as "batch processing" or "cooperative multitasking," where the time-consuming task is broken into
|
|
503
|
-
* smaller pieces and executed in small intervals to allow the UI to remain responsive.
|
|
504
|
-
*/
|
|
505
|
-
async processEntities(e, n, r, t, o) {
|
|
506
|
-
const s = new y();
|
|
507
|
-
let a = e.entities;
|
|
508
|
-
const i = a.length, l = new ae(
|
|
509
|
-
i,
|
|
510
|
-
100 - t.value,
|
|
511
|
-
r
|
|
512
|
-
);
|
|
513
|
-
this.config.convertByEntityType && (a = this.groupAndFlattenByType(a));
|
|
514
|
-
const c = n.tables.blockTable.modelSpace;
|
|
515
|
-
await l.processChunk(async (u, p) => {
|
|
516
|
-
const f = [];
|
|
517
|
-
for (let d = u; d < p; d++) {
|
|
518
|
-
const h = a[d], D = s.convert(h);
|
|
519
|
-
D && f.push(D);
|
|
520
|
-
}
|
|
521
|
-
if (c.appendEntity(f), o) {
|
|
522
|
-
let d = t.value + p / i * (100 - t.value);
|
|
523
|
-
d > 100 && (d = 100), await o(d, "ENTITY", "IN-PROGRESS");
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
processHeader(e, n) {
|
|
528
|
-
const r = e.header;
|
|
529
|
-
n.cecolor.colorIndex = r.CECOLOR || 256, n.angBase = r.ANGBASE ?? 0, n.angDir = r.ANGDIR ?? 0, n.aunits = r.AUNITS ?? 0, r.EXTMAX && (n.extmax = r.EXTMAX), r.EXTMIN && (n.extmin = r.EXTMIN), n.insunits = r.INSUNITS ?? 1, n.pdmode = r.PDMODE ?? 0, n.pdsize = r.PDSIZE ?? 0;
|
|
530
|
-
}
|
|
531
|
-
processCommonTableEntryAttrs(e, n) {
|
|
532
|
-
n.name = e.name, n.objectId = e.handle.toString(), n.ownerId = e.ownerHandle.toString();
|
|
533
|
-
}
|
|
534
|
-
processObjects(e, n) {
|
|
535
|
-
this.processLayouts(e, n), this.processImageDefs(e, n);
|
|
536
|
-
}
|
|
537
|
-
processLayouts(e, n) {
|
|
538
|
-
const r = n.dictionaries.layouts;
|
|
539
|
-
e.objects.LAYOUT.forEach((o) => {
|
|
540
|
-
const s = new le();
|
|
541
|
-
s.layoutName = o.layoutName, s.tabOrder = o.tabOrder;
|
|
542
|
-
const a = n.tables.blockTable.newIterator();
|
|
543
|
-
s.objectId = o.handle.toString();
|
|
544
|
-
for (const i of a)
|
|
545
|
-
if (i.layoutId === s.objectId) {
|
|
546
|
-
s.blockTableRecordId = i.objectId;
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
s.limits.min.copy(o.minLimit), s.limits.max.copy(o.maxLimit), s.extents.min.copy(o.minExtent), s.extents.max.copy(o.maxExtent), this.processCommonObjectAttrs(o, s), r.setAt(s.layoutName, s);
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
processImageDefs(e, n) {
|
|
553
|
-
const r = n.dictionaries.imageDefs;
|
|
554
|
-
e.objects.IMAGEDEF.forEach((o) => {
|
|
555
|
-
const s = new de();
|
|
556
|
-
s.sourceFileName = o.fileName, this.processCommonObjectAttrs(o, s), r.setAt(s.objectId, s);
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
processCommonObjectAttrs(e, n) {
|
|
560
|
-
n.objectId = e.handle.toString(), n.ownerId = e.ownerHandle.toString();
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Groups entities by their `type` property and flattens the result into a single array.
|
|
564
|
-
*
|
|
565
|
-
* The order of `type` groups follows the order in which they first appear in the input array.
|
|
566
|
-
* Items within each group preserve their original order.
|
|
567
|
-
*
|
|
568
|
-
* This runs in O(n) time, which is generally faster than sorting when you
|
|
569
|
-
* don't care about alphabetical order of types.
|
|
570
|
-
*
|
|
571
|
-
* @param entities - The array of entities to group and flatten.
|
|
572
|
-
*
|
|
573
|
-
* @returns A new array of entities grouped by their `type` property.
|
|
574
|
-
*/
|
|
575
|
-
groupAndFlattenByType(e) {
|
|
576
|
-
const n = {}, r = [];
|
|
577
|
-
for (const t of e)
|
|
578
|
-
n[t.type] || (n[t.type] = [], r.push(t.type)), n[t.type].push(t);
|
|
579
|
-
return r.flatMap((t) => n[t]);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
export {
|
|
583
|
-
ue as AcDbLibreDwgConverter
|
|
584
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(f,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],s):(f=typeof globalThis<"u"?globalThis:f||self,s(f["libredwg-converter"]={},f.dataModel))})(this,function(f,s){"use strict";class b{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=="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=="POLYLINE"?this.convertPolyline(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 s.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 s.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new s.AcDbCircle(e.center,e.radius)}convertEllipse(e){const n=new s.AcGeVector3d(e.majorAxisEndPoint),o=n.length();return new s.AcDbEllipse(e.center,e.extrusionDirection??s.AcGeVector3d.Z_AXIS,n,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,o=e.endPoint;return new s.AcDbLine(new s.AcGePoint3d(n.x,n.y,n.z),new s.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){try{if(e.numberOfControlPoints>0&&e.numberOfKnots>0)return new s.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1));if(e.numberOfFitPoints>0)return new s.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1))}catch(n){console.log(`Failed to convert spline with error: ${n}`)}return null}convertPoint(e){const n=new s.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new s.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 s.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((o,t)=>{n.addVertexAt(t,new s.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline(e){const n=new s.AcDbPolyline;return n.closed=!!(e.flag&1),e.vertices.forEach((o,t)=>{n.addVertexAt(t,new s.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertHatch(e){var t;const n=new s.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(r=>{n.definitionLines.push({angle:r.angle,origin:r.base,delta:r.offset,dashPattern:r.numberOfDashLengths>0?r.dashLengths:[]})}),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(r=>{if(r.boundaryPathTypeFlag&2){const a=r,c=new s.AcGePolyline2d;c.closed=a.isClosed,a.vertices.forEach((p,l)=>{c.addVertexAt(l,{x:p.x,y:p.y,bulge:p.bulge})}),n.add(c)}else{const a=r,c=new s.AcGeLoop2d;a.edges.forEach(p=>{if(p!=null){if(p.type==1){const l=p;c.add(new s.AcGeLine2d(l.start,l.end))}else if(p.type==2){const l=p;c.add(new s.AcGeCircArc2d(l.center,l.radius,l.startAngle,l.endAngle,!l.isCCW))}else if(p.type==3){const l=p;new s.AcGeVector2d().subVectors(l.end,l.center);const u=Math.sqrt(Math.pow(l.end.x,2)+Math.pow(l.end.y,2)),D=u*l.lengthOfMinorAxis;let d=l.startAngle,g=l.endAngle;const A=Math.atan2(l.end.y,l.end.x);l.isCCW||(d=Math.PI*2-d,g=Math.PI*2-g),c.add(new s.AcGeEllipseArc2d({...l.center,z:0},u,D,d,g,!l.isCCW,A))}else if(p.type==4){const l=p;if(l.numberOfControlPoints>0&&l.numberOfKnots>0){const h=l.controlPoints.map(d=>({x:d.x,y:d.y,z:0}));let u=!0;const D=l.controlPoints.map(d=>(d.weight==null&&(u=!1),d.weight||1));c.add(new s.AcGeSpline3d(h,l.knots,u?D:void 0))}else if(l.numberOfFitData>0){const h=l.fitDatum.map(u=>({x:u.x,y:u.y,z:0}));c.add(new s.AcGeSpline3d(h,"Uniform"))}}}}),n.add(c)}}),n}convertTable(e){const n=new s.AcDbTable(e.name,e.rowCount,e.columnCount);return n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),e.columnWidthArr.forEach((o,t)=>n.setColumnWidth(t,o)),e.rowHeightArr.forEach((o,t)=>n.setRowHeight(t,o)),e.cells.forEach((o,t)=>{n.setCell(t,o)}),n}convertText(e){const n=new s.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 s.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 s.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new s.AcDbLeader;return e.vertices.forEach(o=>{n.appendVertex(o)}),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"||e.subclassMarker=="AcDbRotatedDimension"){const n=e,o=new s.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return o.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,o=new s.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,o=new s.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,o=new s.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,o=new s.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}return null}processImage(e,n){n.position.copy(e.position),n.brightness=e.brightness,n.contrast=e.contrast,n.fade=e.fade,n.imageDefId=e.imageDefHandle.toString(),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(o=>{n.clipBoundary.push(new s.AcGePoint2d(o))}),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 s.AcDbRasterImage;return this.processImage(e,n),n}convertWipeout(e){const n=new s.AcDbWipeout;return this.processImage(e,n),n}convertViewport(e){const n=new s.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 s.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new s.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertBlockReference(e){const n=new s.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),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){n.layer=e.layer||"0",n.objectId=e.handle.toString(),n.ownerId=e.ownerBlockRecordSoftId.toString(),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.color=e.color),e.colorIndex!=null&&(n.color.colorIndex=e.colorIndex),e.colorName!=null&&(n.color.colorName=e.colorName),e.isVisible!=null&&(n.visibility=e.isVisible),e.transparency!=null&&(n.transparency=e.transparency)}}class I extends s.AcDbDatabaseConverter{constructor(e={}){super(e),e.useWorker=!0,e.parserWorkerUrl||(e.parserWorkerUrl="/assets/libredwg-parser-worker.js")}async parse(e){if(this.config.useWorker&&this.config.parserWorkerUrl){const n=s.createWorkerApi({workerUrl:this.config.parserWorkerUrl,maxConcurrentWorkers:1}),o=await n.execute(e);return n.destroy(),o.data}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 o=new Map,t=i=>{if(i){const a=i.lastIndexOf(".");return a>=0?i.substring(0,a).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const a=[];let c=t(i.font);c&&a.push(c),c=t(i.bigFont),c&&a.push(c),o.set(i.name,a)});const r=new Set;return this.getFontsInBlock(e.entities,n,o,r),Array.from(r)}getFontsInBlock(e,n,o,t){const r=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const a=i;[...a.text.matchAll(r)].forEach(p=>{t.add(p[1].toLowerCase())});const c=o.get(a.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const a=i,c=o.get(a.styleName);c==null||c.forEach(p=>t.add(p))}else if(i.type=="INSERT"){const a=i,c=n.get(a.name);c&&this.getFontsInBlock(c.entities,n,o,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const r={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new s.AcDbLinetypeTableRecord(r);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const r=new s.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,r),n.tables.textStyleTable.add(r)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const r={name:t.name,ownerId:t.ownerHandle.toString(),dimpost:t.DIMPOST||"",dimapost:t.DIMAPOST||"",dimscale:t.DIMSCALE,dimasz:t.DIMASZ,dimexo:t.DIMEXO,dimdli:t.DIMDLI,dimexe:t.DIMEXE,dimrnd:t.DIMRND,dimdle:t.DIMDLE,dimtp:t.DIMTP,dimtm:t.DIMTM,dimtxt:t.DIMTXT,dimcen:t.DIMCEN,dimtsz:t.DIMTSZ,dimaltf:t.DIMALTF,dimlfac:t.DIMLFAC,dimtvp:t.DIMTVP,dimtfac:t.DIMTFAC,dimgap:t.DIMGAP,dimaltrnd:t.DIMALTRND,dimtol:t.DIMTOL==null||t.DIMTOL==0?0:1,dimlim:t.DIMLIM==null||t.DIMLIM==0?0:1,dimtih:t.DIMTIH==null||t.DIMTIH==0?0:1,dimtoh:t.DIMTOH==null||t.DIMTOH==0?0:1,dimse1:t.DIMSE1==null||t.DIMSE1==0?0:1,dimse2:t.DIMSE2==null||t.DIMSE2==0?0:1,dimtad:t.DIMTAD,dimzin:t.DIMZIN,dimazin:t.DIMAZIN,dimalt:t.DIMALT,dimaltd:t.DIMALTD,dimtofl:t.DIMTOFL,dimsah:t.DIMSAH,dimtix:t.DIMTIX,dimsoxd:t.DIMSOXD,dimclrd:t.DIMCLRD,dimclre:t.DIMCLRE,dimclrt:t.DIMCLRT,dimadec:t.DIMADEC||0,dimunit:t.DIMUNIT||2,dimdec:t.DIMDEC,dimtdec:t.DIMTDEC,dimaltu:t.DIMALTU,dimalttd:t.DIMALTTD,dimaunit:t.DIMAUNIT,dimfrac:t.DIMFRAC,dimlunit:t.DIMLUNIT,dimdsep:t.DIMDSEP,dimtmove:t.DIMTMOVE||0,dimjust:t.DIMJUST,dimsd1:t.DIMSD1,dimsd2:t.DIMSD2,dimtolj:t.DIMTOLJ,dimtzin:t.DIMTZIN,dimaltz:t.DIMALTZ,dimalttz:t.DIMALTTZ,dimfit:t.DIMFIT||0,dimupt:t.DIMUPT,dimatfit:t.DIMATFIT,dimtxsty:"Standard",dimldrblk:"",dimblk:t.DIMBLK||"",dimblk1:t.DIMBLK1||"",dimblk2:t.DIMBLK2||"",dimlwd:t.DIMLWD,dimlwe:t.DIMLWE},i=new s.AcDbDimStyleTableRecord(r);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const r=new s.AcCmColor;r.colorIndex=t.colorIndex;const i=new s.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:r,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const r=new s.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,r),t.circleSides&&(r.circleSides=t.circleSides),r.standardFlag=t.standardFlag,r.center.copy(t.center),r.lowerLeftCorner.copy(t.lowerLeftCorner),r.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&r.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(r.snapAngle=t.snapRotationAngle),t.snapSpacing&&r.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(r.gridMajor=t.majorGridLines),t.gridSpacing&&r.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(r.backgroundObjectId=t.backgroundObjectId),r.gsView.center.copy(t.center),r.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),r.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(r.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(r.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(r.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(r.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(r.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(r.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(r.gsView.styleSheet=t.styleSheet),t.renderMode&&(r.gsView.renderMode=t.renderMode),t.viewMode&&(r.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(r.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&r.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&r.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&r.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(r.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(r.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(r.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(r.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(r.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(r.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(r.gsView.brightness=t.brightness),t.contrast&&(r.gsView.contrast=t.contrast),t.ambientColor&&(r.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(r)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let r=n.tables.blockTable.getAt(t.name);r||(r=new s.AcDbBlockTableRecord,r.objectId=t.handle.toString(),r.name=t.name,r.ownerId=t.ownerHandle.toString(),r.origin.copy(t.basePoint),r.layoutId=t.layout.toString(),n.tables.blockTable.add(r)),!r.isModelSapce&&!r.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,r)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new b,t=e.length,r=[];for(let i=0;i<t;i++){const a=e[i],c=o.convert(a);c&&r.push(c)}n.appendEntity(r)}async processEntities(e,n,o,t,r){const i=new b;let a=e.entities;const c=a.length,p=new s.AcDbBatchProcessing(c,100-t.value,o);this.config.convertByEntityType&&(a=this.groupAndFlattenByType(a));const l=n.tables.blockTable.modelSpace;await p.processChunk(async(h,u)=>{const D=[];for(let d=h;d<u;d++){const g=a[d],A=i.convert(g);A&&D.push(A)}if(l.appendEntity(D),r){let d=t.value+u/c*(100-t.value);d>100&&(d=100),await r(d,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const o=e.header;n.cecolor.colorIndex=o.CECOLOR||256,n.angBase=o.ANGBASE??0,n.angDir=o.ANGDIR??0,n.aunits=o.AUNITS??0,o.EXTMAX&&(n.extmax=o.EXTMAX),o.EXTMIN&&(n.extmin=o.EXTMIN),n.insunits=o.INSUNITS??1,n.pdmode=o.PDMODE??0,n.pdsize=o.PDSIZE??0}processCommonTableEntryAttrs(e,n){n.name=e.name,n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}processObjects(e,n){this.processLayouts(e,n),this.processImageDefs(e,n)}processLayouts(e,n){const o=n.dictionaries.layouts;e.objects.LAYOUT.forEach(r=>{const i=new s.AcDbLayout;i.layoutName=r.layoutName,i.tabOrder=r.tabOrder;const a=n.tables.blockTable.newIterator();i.objectId=r.handle.toString();for(const c of a)if(c.layoutId===i.objectId){i.blockTableRecordId=c.objectId;break}i.limits.min.copy(r.minLimit),i.limits.max.copy(r.maxLimit),i.extents.min.copy(r.minExtent),i.extents.max.copy(r.maxExtent),this.processCommonObjectAttrs(r,i),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(r=>{const i=new s.AcDbRasterImageDef;i.sourceFileName=r.fileName,this.processCommonObjectAttrs(r,i),o.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}groupAndFlattenByType(e){const n={},o=[];for(const t of e)n[t.type]||(n[t.type]=[],o.push(t.type)),n[t.type].push(t);return o.flatMap(t=>n[t])}}f.AcDbLibreDwgConverter=I,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|