@mlightcad/libredwg-converter 3.0.3 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/libredwg-converter.js +44 -49
- package/dist/libredwg-converter.umd.cjs +1 -1
- package/dist/libredwg-parser-worker.js +15161 -0
- package/lib/AcDbLibreDwgConverter.d.ts +3 -6
- package/lib/AcDbLibreDwgConverter.d.ts.map +1 -1
- package/lib/AcDbLibreDwgConverter.js +23 -15
- package/lib/AcDbLibreDwgConverter.js.map +1 -1
- package/lib/AcDbLibreDwgConverterUtil.d.ts +3 -0
- package/lib/AcDbLibreDwgConverterUtil.d.ts.map +1 -0
- package/lib/AcDbLibreDwgConverterUtil.js +60 -0
- package/lib/AcDbLibreDwgConverterUtil.js.map +1 -0
- package/lib/AcDbLibreDwgParserWorker.d.ts +2 -0
- package/lib/AcDbLibreDwgParserWorker.d.ts.map +1 -0
- package/lib/AcDbLibreDwgParserWorker.js +74 -0
- package/lib/AcDbLibreDwgParserWorker.js.map +1 -0
- package/package.json +5 -3
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AcDbArc as S, AcDbCircle as P, AcGeVector3d as h, AcDbEllipse as E, AcDbLine as L, AcGePoint3d as A, AcDbSpline as w, AcDbPoint as C, AcDbTrace as x, AcDbPolyline as I, AcGePoint2d as
|
|
2
|
-
import { LibreDwg as ae, Dwg_File_Type as le } from "@mlightcad/libredwg-web";
|
|
1
|
+
import { AcDbArc as S, AcDbCircle as P, AcGeVector3d as h, AcDbEllipse as E, AcDbLine as L, AcGePoint3d as A, AcDbSpline as w, AcDbPoint as C, AcDbTrace as x, AcDbPolyline as I, AcGePoint2d as g, AcDbHatch as v, AcGePolyline2d as O, AcGeLoop2d as k, AcGeLine2d as R, AcGeCircArc2d as N, AcGeVector2d as V, AcGeEllipseArc2d as m, AcGeSpline3d as b, AcDbTable as F, AcDbText as B, AcDbMText as j, AcDbLeader as z, AcDbAlignedDimension as H, AcDb3PointAngularDimension as W, AcDbOrdinateDimension as X, AcDbRadialDimension as G, AcDbDiametricDimension as U, AcDbRasterImage as Y, AcDbViewport as Z, AcDbRay as K, AcDbXline as _, AcDbBlockReference as q, AcDbDatabaseConverter as J, createWorkerApi as Q, AcDbLinetypeTableRecord as $, AcDbTextStyleTableRecord as ee, AcDbDimStyleTableRecord as ne, AcCmColor as te, AcDbLayerTableRecord as oe, AcDbViewportTableRecord as se, AcDbBlockTableRecord as re, AcDbBatchProcessing as ie, AcDbLayout as ce, AcDbRasterImageDef as ae } from "@mlightcad/data-model";
|
|
3
2
|
class T {
|
|
4
3
|
convert(e) {
|
|
5
4
|
const n = this.createEntity(e);
|
|
@@ -73,7 +72,7 @@ class T {
|
|
|
73
72
|
return n.closed = !!(e.flag & 512), e.vertices.forEach((s, t) => {
|
|
74
73
|
n.addVertexAt(
|
|
75
74
|
t,
|
|
76
|
-
new
|
|
75
|
+
new g(s.x, s.y),
|
|
77
76
|
s.bulge,
|
|
78
77
|
s.startWidth,
|
|
79
78
|
s.endWidth
|
|
@@ -85,7 +84,7 @@ class T {
|
|
|
85
84
|
return n.closed = !!(e.flag & 1), e.vertices.forEach((s, t) => {
|
|
86
85
|
n.addVertexAt(
|
|
87
86
|
t,
|
|
88
|
-
new
|
|
87
|
+
new g(s.x, s.y),
|
|
89
88
|
s.bulge,
|
|
90
89
|
s.startWidth,
|
|
91
90
|
s.endWidth
|
|
@@ -113,15 +112,15 @@ class T {
|
|
|
113
112
|
});
|
|
114
113
|
}), n.add(c);
|
|
115
114
|
} else {
|
|
116
|
-
const a = o, c = new
|
|
115
|
+
const a = o, c = new k();
|
|
117
116
|
a.edges.forEach((l) => {
|
|
118
117
|
if (l.type == 1) {
|
|
119
118
|
const i = l;
|
|
120
|
-
c.add(new
|
|
119
|
+
c.add(new R(i.start, i.end));
|
|
121
120
|
} else if (l.type == 2) {
|
|
122
121
|
const i = l;
|
|
123
122
|
c.add(
|
|
124
|
-
new
|
|
123
|
+
new N(
|
|
125
124
|
i.center,
|
|
126
125
|
i.radius,
|
|
127
126
|
i.startAngle,
|
|
@@ -131,19 +130,19 @@ class T {
|
|
|
131
130
|
);
|
|
132
131
|
} else if (l.type == 3) {
|
|
133
132
|
const i = l;
|
|
134
|
-
new
|
|
133
|
+
new V().subVectors(i.end, i.center);
|
|
135
134
|
const d = Math.sqrt(
|
|
136
135
|
Math.pow(i.end.x, 2) + Math.pow(i.end.y, 2)
|
|
137
136
|
), p = d * i.lengthOfMinorAxis;
|
|
138
|
-
let D = i.startAngle,
|
|
137
|
+
let D = i.startAngle, u = i.endAngle;
|
|
139
138
|
const M = Math.atan2(i.end.y, i.end.x);
|
|
140
|
-
i.isCCW || (D = Math.PI * 2 - D,
|
|
141
|
-
new
|
|
139
|
+
i.isCCW || (D = Math.PI * 2 - D, u = Math.PI * 2 - u), c.add(
|
|
140
|
+
new m(
|
|
142
141
|
{ ...i.center, z: 0 },
|
|
143
142
|
d,
|
|
144
143
|
p,
|
|
145
144
|
D,
|
|
146
|
-
|
|
145
|
+
u,
|
|
147
146
|
!i.isCCW,
|
|
148
147
|
M
|
|
149
148
|
)
|
|
@@ -151,7 +150,7 @@ class T {
|
|
|
151
150
|
} else if (l.type == 4) {
|
|
152
151
|
const i = l;
|
|
153
152
|
if (i.numberOfControlPoints > 0 && i.numberOfKnots > 0) {
|
|
154
|
-
const
|
|
153
|
+
const f = i.controlPoints.map(
|
|
155
154
|
(D) => ({
|
|
156
155
|
x: D.x,
|
|
157
156
|
y: D.y,
|
|
@@ -162,18 +161,18 @@ class T {
|
|
|
162
161
|
const p = i.controlPoints.map((D) => (D.weight == null && (d = !1), D.weight || 1));
|
|
163
162
|
c.add(
|
|
164
163
|
new b(
|
|
165
|
-
|
|
164
|
+
f,
|
|
166
165
|
i.knots,
|
|
167
166
|
d ? p : void 0
|
|
168
167
|
)
|
|
169
168
|
);
|
|
170
169
|
} else if (i.numberOfFitData > 0) {
|
|
171
|
-
const
|
|
170
|
+
const f = i.fitDatum.map((d) => ({
|
|
172
171
|
x: d.x,
|
|
173
172
|
y: d.y,
|
|
174
173
|
z: 0
|
|
175
174
|
}));
|
|
176
|
-
c.add(new b(
|
|
175
|
+
c.add(new b(f, "Uniform"));
|
|
177
176
|
}
|
|
178
177
|
}
|
|
179
178
|
}), n.add(c);
|
|
@@ -238,7 +237,7 @@ class T {
|
|
|
238
237
|
);
|
|
239
238
|
return this.processDimensionCommonAttrs(e, s), s;
|
|
240
239
|
} else if (e.subclassMarker == "AcDbDiametricDimension") {
|
|
241
|
-
const n = e, s = new
|
|
240
|
+
const n = e, s = new U(
|
|
242
241
|
n.definitionPoint,
|
|
243
242
|
n.centerPoint,
|
|
244
243
|
n.leaderLength
|
|
@@ -249,7 +248,7 @@ class T {
|
|
|
249
248
|
}
|
|
250
249
|
processImage(e, n) {
|
|
251
250
|
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.flags | 4) > 0, n.isImageShown = (e.flags | 3) > 0, n.isImageTransparent = (e.flags | 8) > 0, e.clippingBoundaryPath.forEach((s) => {
|
|
252
|
-
n.clipBoundary.push(new
|
|
251
|
+
n.clipBoundary.push(new g(s));
|
|
253
252
|
}), n.clipBoundaryType = e.clippingBoundaryType, n.width = Math.sqrt(
|
|
254
253
|
e.uPixel.x ** 2 + e.uPixel.y ** 2 + e.uPixel.z ** 2
|
|
255
254
|
) * e.imageSize.x, n.height = Math.sqrt(
|
|
@@ -257,7 +256,7 @@ class T {
|
|
|
257
256
|
) * e.imageSize.y, n.rotation = Math.atan2(e.uPixel.y, e.uPixel.x);
|
|
258
257
|
}
|
|
259
258
|
convertImage(e) {
|
|
260
|
-
const n = new
|
|
259
|
+
const n = new Y();
|
|
261
260
|
return this.processImage(e, n), n;
|
|
262
261
|
}
|
|
263
262
|
// private convertWipeout(wipeout: WipeoutEntity) {
|
|
@@ -266,15 +265,15 @@ class T {
|
|
|
266
265
|
// return dbWipeout
|
|
267
266
|
// }
|
|
268
267
|
convertViewport(e) {
|
|
269
|
-
const n = new
|
|
268
|
+
const n = new Z();
|
|
270
269
|
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;
|
|
271
270
|
}
|
|
272
271
|
convertRay(e) {
|
|
273
|
-
const n = new
|
|
272
|
+
const n = new K();
|
|
274
273
|
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
275
274
|
}
|
|
276
275
|
convertXline(e) {
|
|
277
|
-
const n = new
|
|
276
|
+
const n = new _();
|
|
278
277
|
return n.basePoint.copy(e.firstPoint), n.unitDir.copy(e.unitDirection), n;
|
|
279
278
|
}
|
|
280
279
|
convertBlockReference(e) {
|
|
@@ -288,18 +287,14 @@ class T {
|
|
|
288
287
|
n.layer = e.layer, 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);
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
|
-
class
|
|
292
|
-
constructor(e) {
|
|
293
|
-
super(),
|
|
294
|
-
}
|
|
295
|
-
parse(e) {
|
|
296
|
-
if (this.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (n == null)
|
|
300
|
-
throw new Error("Failed to read dwg data!");
|
|
301
|
-
const s = this.libredwg.convert(n);
|
|
302
|
-
return this.libredwg.dwg_free(n), s;
|
|
290
|
+
class de extends J {
|
|
291
|
+
constructor(e = {}) {
|
|
292
|
+
super(e), e.useWorker = !0, e.parserWorkerUrl || (e.parserWorkerUrl = "/assets/libredwg-parser-worker.js");
|
|
293
|
+
}
|
|
294
|
+
async parse(e) {
|
|
295
|
+
if (this.config.useWorker && this.config.parserWorkerUrl)
|
|
296
|
+
return (await Q({ workerUrl: this.config.parserWorkerUrl }).execute(e)).data;
|
|
297
|
+
throw new Error("dwg converter can run in web worker only!");
|
|
303
298
|
}
|
|
304
299
|
/**
|
|
305
300
|
* Gets all of fonts used by entities in model space and paper space
|
|
@@ -355,13 +350,13 @@ class De extends J {
|
|
|
355
350
|
standardFlag: t.standardFlag,
|
|
356
351
|
totalPatternLength: t.totalPatternLength,
|
|
357
352
|
pattern: t.pattern
|
|
358
|
-
}, r = new
|
|
353
|
+
}, r = new $(o);
|
|
359
354
|
this.processCommonTableEntryAttrs(t, r), r.name = t.name, n.tables.linetypeTable.add(r);
|
|
360
355
|
});
|
|
361
356
|
}
|
|
362
357
|
processTextStyles(e, n) {
|
|
363
358
|
e.tables.STYLE.entries.forEach((t) => {
|
|
364
|
-
const o = new
|
|
359
|
+
const o = new ee(t);
|
|
365
360
|
this.processCommonTableEntryAttrs(t, o), n.tables.textStyleTable.add(o);
|
|
366
361
|
});
|
|
367
362
|
}
|
|
@@ -441,15 +436,15 @@ class De extends J {
|
|
|
441
436
|
// TODO: Set correct value
|
|
442
437
|
dimlwd: t.DIMLWD,
|
|
443
438
|
dimlwe: t.DIMLWE
|
|
444
|
-
}, r = new
|
|
439
|
+
}, r = new ne(o);
|
|
445
440
|
this.processCommonTableEntryAttrs(t, r), n.tables.dimStyleTable.add(r);
|
|
446
441
|
});
|
|
447
442
|
}
|
|
448
443
|
processLayers(e, n) {
|
|
449
444
|
e.tables.LAYER.entries.forEach((t) => {
|
|
450
|
-
const o = new
|
|
445
|
+
const o = new te();
|
|
451
446
|
o.colorIndex = t.colorIndex;
|
|
452
|
-
const r = new
|
|
447
|
+
const r = new oe({
|
|
453
448
|
name: t.name,
|
|
454
449
|
standardFlags: t.standardFlag,
|
|
455
450
|
linetype: t.lineType,
|
|
@@ -463,14 +458,14 @@ class De extends J {
|
|
|
463
458
|
}
|
|
464
459
|
processViewports(e, n) {
|
|
465
460
|
e.tables.VPORT.entries.forEach((t) => {
|
|
466
|
-
const o = new
|
|
461
|
+
const o = new se();
|
|
467
462
|
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);
|
|
468
463
|
});
|
|
469
464
|
}
|
|
470
465
|
processBlockTables(e, n) {
|
|
471
466
|
e.tables.BLOCK_RECORD.entries.forEach((t) => {
|
|
472
467
|
let o = n.tables.blockTable.getAt(t.name);
|
|
473
|
-
o || (o = new
|
|
468
|
+
o || (o = new re(), o.objectId = t.handle.toString(), o.name = t.name, n.tables.blockTable.add(o)), !o.isModelSapce && !o.isPaperSapce && t.entities && t.entities.length > 0 && this.processEntitiesInBlock(t.entities, o);
|
|
474
469
|
});
|
|
475
470
|
}
|
|
476
471
|
processBlocks(e, n) {
|
|
@@ -488,15 +483,15 @@ class De extends J {
|
|
|
488
483
|
* smaller pieces and executed in small intervals to allow the UI to remain responsive.
|
|
489
484
|
*/
|
|
490
485
|
async processEntities(e, n, s, t, o) {
|
|
491
|
-
const r = new T(), a = e.entities, c = a.length, l = new
|
|
486
|
+
const r = new T(), a = e.entities, c = a.length, l = new ie(
|
|
492
487
|
c,
|
|
493
488
|
100 - t.value,
|
|
494
489
|
s
|
|
495
490
|
), i = n.tables.blockTable.modelSpace;
|
|
496
|
-
await l.processChunk(async (
|
|
497
|
-
for (let p =
|
|
498
|
-
const D = a[p],
|
|
499
|
-
|
|
491
|
+
await l.processChunk(async (f, d) => {
|
|
492
|
+
for (let p = f; p < d; p++) {
|
|
493
|
+
const D = a[p], u = r.convert(D);
|
|
494
|
+
u && i.appendEntity(u);
|
|
500
495
|
}
|
|
501
496
|
if (o) {
|
|
502
497
|
let p = t.value + d / c * (100 - t.value);
|
|
@@ -517,14 +512,14 @@ class De extends J {
|
|
|
517
512
|
processLayouts(e, n) {
|
|
518
513
|
const s = n.dictionaries.layouts;
|
|
519
514
|
e.objects.LAYOUT.forEach((o) => {
|
|
520
|
-
const r = new
|
|
515
|
+
const r = new ce();
|
|
521
516
|
r.layoutName = o.layoutName, r.tabOrder = o.tabOrder, r.blockTableRecordId = o.ownerHandle.toString(), r.limits.min.copy(o.minLimit), r.limits.max.copy(o.maxLimit), r.extents.min.copy(o.minExtent), r.extents.max.copy(o.maxExtent), this.processCommonObjectAttrs(o, r), s.setAt(r.layoutName, r);
|
|
522
517
|
});
|
|
523
518
|
}
|
|
524
519
|
processImageDefs(e, n) {
|
|
525
520
|
const s = n.dictionaries.imageDefs;
|
|
526
521
|
e.objects.IMAGEDEF.forEach((o) => {
|
|
527
|
-
const r = new
|
|
522
|
+
const r = new ae();
|
|
528
523
|
r.sourceFileName = o.fileName, this.processCommonObjectAttrs(o, r), s.setAt(r.objectId, r);
|
|
529
524
|
});
|
|
530
525
|
}
|
|
@@ -533,5 +528,5 @@ class De extends J {
|
|
|
533
528
|
}
|
|
534
529
|
}
|
|
535
530
|
export {
|
|
536
|
-
|
|
531
|
+
de as AcDbLibreDwgConverter
|
|
537
532
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(D,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@mlightcad/data-model"),require("@mlightcad/libredwg-web")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model","@mlightcad/libredwg-web"],r):(D=typeof globalThis<"u"?globalThis:D||self,r(D["libredwg-converter"]={},D.dataModel,D.libredwgWeb))})(this,function(D,r,A){"use strict";class w{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return 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=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertArc(e){return new r.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new r.AcDbCircle(e.center,e.radius)}convertEllipse(e){const n=new r.AcGeVector3d(e.majorAxisEndPoint),o=n.length();return new r.AcDbEllipse(e.center,r.AcGeVector3d.Z_AXIS,n,o,o*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,o=e.endPoint;return new r.AcDbLine(new r.AcGePoint3d(n.x,n.y,n.z),new r.AcGePoint3d(o.x,o.y,o.z))}convertSpline(e){return e.numberOfControlPoints>0&&e.numberOfKnots>0?new r.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1)):e.numberOfFitPoints>0?new r.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1)):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;return n.closed=!!(e.flag&512),e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertPolyline(e){const n=new r.AcDbPolyline;return n.closed=!!(e.flag&1),e.vertices.forEach((o,t)=>{n.addVertexAt(t,new r.AcGePoint2d(o.x,o.y),o.bulge,o.startWidth,o.endWidth)}),n}convertHatch(e){var t;const n=new r.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,origin:s.base,delta:s.offset,dashPattern:s.numberOfDashLengths>0?s.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(s=>{if(s.boundaryPathTypeFlag&2){const a=s,l=new r.AcGePolyline2d;l.closed=a.isClosed,a.vertices.forEach((d,c)=>{l.addVertexAt(c,{x:d.x,y:d.y,bulge:d.bulge})}),n.add(l)}else{const a=s,l=new r.AcGeLoop2d;a.edges.forEach(d=>{if(d.type==1){const c=d;l.add(new r.AcGeLine2d(c.start,c.end))}else if(d.type==2){const c=d;l.add(new r.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(d.type==3){const c=d;new r.AcGeVector2d().subVectors(c.end,c.center);const p=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),f=p*c.lengthOfMinorAxis;let g=c.startAngle,u=c.endAngle;const T=Math.atan2(c.end.y,c.end.x);c.isCCW||(g=Math.PI*2-g,u=Math.PI*2-u),l.add(new r.AcGeEllipseArc2d({...c.center,z:0},p,f,g,u,!c.isCCW,T))}else if(d.type==4){const c=d;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(g=>({x:g.x,y:g.y,z:0}));let p=!0;const f=c.controlPoints.map(g=>(g.weight==null&&(p=!1),g.weight||1));l.add(new r.AcGeSpline3d(h,c.knots,p?f:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(p=>({x:p.x,y:p.y,z:0}));l.add(new r.AcGeSpline3d(h,"Uniform"))}}}),n.add(l)}}),n}convertTable(e){const n=new r.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 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(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 r.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 r.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 r.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,o=new r.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,o),o}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,o=new r.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.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(o=>{n.clipBoundary.push(new r.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 r.AcDbRasterImage;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}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),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,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 b extends r.AcDbDatabaseConverter{constructor(e){super(),this.libredwg=A.LibreDwg.createByWasmInstance(e)}parse(e){if(this.libredwg==null)throw new Error("libredwg is not loaded!");const n=this.libredwg.dwg_read_data(e,A.Dwg_File_Type.DWG);if(n==null)throw new Error("Failed to read dwg data!");const o=this.libredwg.convert(n);return this.libredwg.dwg_free(n),o}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 l=t(i.font);l&&a.push(l),l=t(i.bigFont),l&&a.push(l),o.set(i.name,a)});const s=new Set;return this.getFontsInBlock(e.entities,n,o,s),Array.from(s)}getFontsInBlock(e,n,o,t){const s=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const a=i;[...a.text.matchAll(s)].forEach(d=>{t.add(d[1].toLowerCase())});const l=o.get(a.styleName);l==null||l.forEach(d=>t.add(d))}else if(i.type=="TEXT"){const a=i,l=o.get(a.styleName);l==null||l.forEach(d=>t.add(d))}else if(i.type=="INSERT"){const a=i,l=n.get(a.name);l&&this.getFontsInBlock(l.entities,n,o,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const s={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new r.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const s=new r.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,s),n.tables.textStyleTable.add(s)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const s={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 r.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const s=new r.AcCmColor;s.colorIndex=t.colorIndex;const i=new r.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:s,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const s=new r.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,s),t.circleSides&&(s.circleSides=t.circleSides),s.standardFlag=t.standardFlag,s.center.copy(t.center),s.lowerLeftCorner.copy(t.lowerLeftCorner),s.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&s.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(s.snapAngle=t.snapRotationAngle),t.snapSpacing&&s.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(s.gridMajor=t.majorGridLines),t.gridSpacing&&s.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(s.backgroundObjectId=t.backgroundObjectId),s.gsView.center.copy(t.center),s.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),s.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(s.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(s.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(s.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(s.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(s.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(s.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(s.gsView.styleSheet=t.styleSheet),t.renderMode&&(s.gsView.renderMode=t.renderMode),t.viewMode&&(s.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(s.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&s.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&s.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&s.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(s.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(s.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(s.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(s.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(s.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(s.gsView.brightness=t.brightness),t.contrast&&(s.gsView.contrast=t.contrast),t.ambientColor&&(s.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(s)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let s=n.tables.blockTable.getAt(t.name);s||(s=new r.AcDbBlockTableRecord,s.objectId=t.handle.toString(),s.name=t.name,n.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,s)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const o=new w,t=e.length;for(let s=0;s<t;s++){const i=e[s],a=o.convert(i);a&&n.appendEntity(a)}}async processEntities(e,n,o,t,s){const i=new w,a=e.entities,l=a.length,d=new r.AcDbBatchProcessing(l,100-t.value,o),c=n.tables.blockTable.modelSpace;await d.processChunk(async(h,p)=>{for(let f=h;f<p;f++){const g=a[f],u=i.convert(g);u&&c.appendEntity(u)}if(s){let f=t.value+p/l*(100-t.value);f>100&&(f=100),await s(f,"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,n.extmax=o.EXTMAX,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(s=>{const i=new r.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder,i.blockTableRecordId=s.ownerHandle.toString(),i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),this.processCommonObjectAttrs(s,i),o.setAt(i.layoutName,i)})}processImageDefs(e,n){const o=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new r.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),o.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}}D.AcDbLibreDwgConverter=b,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@mlightcad/data-model")):typeof define=="function"&&define.amd?define(["exports","@mlightcad/data-model"],o):(D=typeof globalThis<"u"?globalThis:D||self,o(D["libredwg-converter"]={},D.dataModel))})(this,function(D,o){"use strict";class A{convert(e){const n=this.createEntity(e);return n&&this.processCommonAttrs(e,n),n}createEntity(e){return 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=="XLINE"?this.convertXline(e):e.type=="INSERT"?this.convertBlockReference(e):null}convertArc(e){return new o.AcDbArc(e.center,e.radius,e.startAngle,e.endAngle)}convertCirle(e){return new o.AcDbCircle(e.center,e.radius)}convertEllipse(e){const n=new o.AcGeVector3d(e.majorAxisEndPoint),r=n.length();return new o.AcDbEllipse(e.center,o.AcGeVector3d.Z_AXIS,n,r,r*e.axisRatio,e.startAngle,e.endAngle)}convertLine(e){const n=e.startPoint,r=e.endPoint;return new o.AcDbLine(new o.AcGePoint3d(n.x,n.y,n.z),new o.AcGePoint3d(r.x,r.y,r.z))}convertSpline(e){return e.numberOfControlPoints>0&&e.numberOfKnots>0?new o.AcDbSpline(e.controlPoints,e.knots,e.weights,e.degree,!!(e.flag&1)):e.numberOfFitPoints>0?new o.AcDbSpline(e.fitPoints,"Uniform",e.degree,!!(e.flag&1)):null}convertPoint(e){const n=new o.AcDbPoint;return n.position=e.position,n}convertSolid(e){const n=new o.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 o.AcDbPolyline;return n.closed=!!(e.flag&512),e.vertices.forEach((r,t)=>{n.addVertexAt(t,new o.AcGePoint2d(r.x,r.y),r.bulge,r.startWidth,r.endWidth)}),n}convertPolyline(e){const n=new o.AcDbPolyline;return n.closed=!!(e.flag&1),e.vertices.forEach((r,t)=>{n.addVertexAt(t,new o.AcGePoint2d(r.x,r.y),r.bulge,r.startWidth,r.endWidth)}),n}convertHatch(e){var t;const n=new o.AcDbHatch;return(t=e.definitionLines)==null||t.forEach(s=>{n.definitionLines.push({angle:s.angle,origin:s.base,delta:s.offset,dashPattern:s.numberOfDashLengths>0?s.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(s=>{if(s.boundaryPathTypeFlag&2){const l=s,a=new o.AcGePolyline2d;a.closed=l.isClosed,l.vertices.forEach((p,c)=>{a.addVertexAt(c,{x:p.x,y:p.y,bulge:p.bulge})}),n.add(a)}else{const l=s,a=new o.AcGeLoop2d;l.edges.forEach(p=>{if(p.type==1){const c=p;a.add(new o.AcGeLine2d(c.start,c.end))}else if(p.type==2){const c=p;a.add(new o.AcGeCircArc2d(c.center,c.radius,c.startAngle,c.endAngle,!c.isCCW))}else if(p.type==3){const c=p;new o.AcGeVector2d().subVectors(c.end,c.center);const d=Math.sqrt(Math.pow(c.end.x,2)+Math.pow(c.end.y,2)),f=d*c.lengthOfMinorAxis;let u=c.startAngle,g=c.endAngle;const b=Math.atan2(c.end.y,c.end.x);c.isCCW||(u=Math.PI*2-u,g=Math.PI*2-g),a.add(new o.AcGeEllipseArc2d({...c.center,z:0},d,f,u,g,!c.isCCW,b))}else if(p.type==4){const c=p;if(c.numberOfControlPoints>0&&c.numberOfKnots>0){const h=c.controlPoints.map(u=>({x:u.x,y:u.y,z:0}));let d=!0;const f=c.controlPoints.map(u=>(u.weight==null&&(d=!1),u.weight||1));a.add(new o.AcGeSpline3d(h,c.knots,d?f:void 0))}else if(c.numberOfFitData>0){const h=c.fitDatum.map(d=>({x:d.x,y:d.y,z:0}));a.add(new o.AcGeSpline3d(h,"Uniform"))}}}),n.add(a)}}),n}convertTable(e){const n=new o.AcDbTable(e.name,e.rowCount,e.columnCount);return n.attachmentPoint=e.attachmentPoint,n.position.copy(e.startPoint),e.columnWidthArr.forEach((r,t)=>n.setColumnWidth(t,r)),e.rowHeightArr.forEach((r,t)=>n.setRowHeight(t,r)),e.cells.forEach((r,t)=>{n.setCell(t,r)}),n}convertText(e){const n=new o.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 o.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 o.AcGeVector3d(e.direction)),n.drawingDirection=e.drawingDirection,n}convertLeader(e){const n=new o.AcDbLeader;return e.vertices.forEach(r=>{n.appendVertex(r)}),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,r=new o.AcDbAlignedDimension(n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return r.rotation=n.rotationAngle,this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDb3PointAngularDimension"){const n=e,r=new o.AcDb3PointAngularDimension(n.centerPoint,n.subDefinitionPoint1,n.subDefinitionPoint2,n.definitionPoint);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbOrdinateDimension"){const n=e,r=new o.AcDbOrdinateDimension(n.subDefinitionPoint1,n.subDefinitionPoint2);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbRadialDimension"){const n=e,r=new o.AcDbRadialDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}else if(e.subclassMarker=="AcDbDiametricDimension"){const n=e,r=new o.AcDbDiametricDimension(n.definitionPoint,n.centerPoint,n.leaderLength);return this.processDimensionCommonAttrs(e,r),r}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.flags|4)>0,n.isImageShown=(e.flags|3)>0,n.isImageTransparent=(e.flags|8)>0,e.clippingBoundaryPath.forEach(r=>{n.clipBoundary.push(new o.AcGePoint2d(r))}),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 o.AcDbRasterImage;return this.processImage(e,n),n}convertViewport(e){const n=new o.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 o.AcDbRay;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertXline(e){const n=new o.AcDbXline;return n.basePoint.copy(e.firstPoint),n.unitDir.copy(e.unitDirection),n}convertBlockReference(e){const n=new o.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,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 w extends o.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)return(await o.createWorkerApi({workerUrl:this.config.parserWorkerUrl}).execute(e)).data;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 r=new Map,t=i=>{if(i){const l=i.lastIndexOf(".");return l>=0?i.substring(0,l).toLowerCase():i.toLowerCase()}};e.tables.STYLE.entries.forEach(i=>{const l=[];let a=t(i.font);a&&l.push(a),a=t(i.bigFont),a&&l.push(a),r.set(i.name,l)});const s=new Set;return this.getFontsInBlock(e.entities,n,r,s),Array.from(s)}getFontsInBlock(e,n,r,t){const s=/\\f(.*?)\|/g;e.forEach(i=>{if(i.type=="MTEXT"){const l=i;[...l.text.matchAll(s)].forEach(p=>{t.add(p[1].toLowerCase())});const a=r.get(l.styleName);a==null||a.forEach(p=>t.add(p))}else if(i.type=="TEXT"){const l=i,a=r.get(l.styleName);a==null||a.forEach(p=>t.add(p))}else if(i.type=="INSERT"){const l=i,a=n.get(l.name);a&&this.getFontsInBlock(a.entities,n,r,t)}})}processLineTypes(e,n){e.tables.LTYPE.entries.forEach(t=>{const s={name:t.name,description:t.description,standardFlag:t.standardFlag,totalPatternLength:t.totalPatternLength,pattern:t.pattern},i=new o.AcDbLinetypeTableRecord(s);this.processCommonTableEntryAttrs(t,i),i.name=t.name,n.tables.linetypeTable.add(i)})}processTextStyles(e,n){e.tables.STYLE.entries.forEach(t=>{const s=new o.AcDbTextStyleTableRecord(t);this.processCommonTableEntryAttrs(t,s),n.tables.textStyleTable.add(s)})}processDimStyles(e,n){e.tables.DIMSTYLE.entries.forEach(t=>{const s={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 o.AcDbDimStyleTableRecord(s);this.processCommonTableEntryAttrs(t,i),n.tables.dimStyleTable.add(i)})}processLayers(e,n){e.tables.LAYER.entries.forEach(t=>{const s=new o.AcCmColor;s.colorIndex=t.colorIndex;const i=new o.AcDbLayerTableRecord({name:t.name,standardFlags:t.standardFlag,linetype:t.lineType,lineWeight:t.lineweight,isOff:t.off,color:s,isPlottable:t.plotFlag!=0});this.processCommonTableEntryAttrs(t,i),n.tables.layerTable.add(i)})}processViewports(e,n){e.tables.VPORT.entries.forEach(t=>{const s=new o.AcDbViewportTableRecord;this.processCommonTableEntryAttrs(t,s),t.circleSides&&(s.circleSides=t.circleSides),s.standardFlag=t.standardFlag,s.center.copy(t.center),s.lowerLeftCorner.copy(t.lowerLeftCorner),s.upperRightCorner.copy(t.upperRightCorner),t.snapBasePoint&&s.snapBase.copy(t.snapBasePoint),t.snapRotationAngle&&(s.snapAngle=t.snapRotationAngle),t.snapSpacing&&s.snapIncrements.copy(t.snapSpacing),t.majorGridLines&&(s.gridMajor=t.majorGridLines),t.gridSpacing&&s.gridIncrements.copy(t.gridSpacing),t.backgroundObjectId&&(s.backgroundObjectId=t.backgroundObjectId),s.gsView.center.copy(t.center),s.gsView.viewDirectionFromTarget.copy(t.viewDirectionFromTarget),s.gsView.viewTarget.copy(t.viewTarget),t.lensLength&&(s.gsView.lensLength=t.lensLength),t.frontClippingPlane&&(s.gsView.frontClippingPlane=t.frontClippingPlane),t.backClippingPlane&&(s.gsView.backClippingPlane=t.backClippingPlane),t.viewHeight&&(s.gsView.viewHeight=t.viewHeight),t.viewTwistAngle&&(s.gsView.viewTwistAngle=t.viewTwistAngle),t.frozenLayers&&(s.gsView.frozenLayers=t.frozenLayers),t.styleSheet&&(s.gsView.styleSheet=t.styleSheet),t.renderMode&&(s.gsView.renderMode=t.renderMode),t.viewMode&&(s.gsView.viewMode=t.viewMode),t.ucsIconSetting&&(s.gsView.ucsIconSetting=t.ucsIconSetting),t.ucsOrigin&&s.gsView.ucsOrigin.copy(t.ucsOrigin),t.ucsXAxis&&s.gsView.ucsXAxis.copy(t.ucsXAxis),t.ucsYAxis&&s.gsView.ucsYAxis.copy(t.ucsYAxis),t.orthographicType&&(s.gsView.orthographicType=t.orthographicType),t.shadePlotSetting&&(s.gsView.shadePlotSetting=t.shadePlotSetting),t.shadePlotObjectId&&(s.gsView.shadePlotObjectId=t.shadePlotObjectId),t.visualStyleObjectId&&(s.gsView.visualStyleObjectId=t.visualStyleObjectId),t.isDefaultLightingOn&&(s.gsView.isDefaultLightingOn=t.isDefaultLightingOn),t.defaultLightingType&&(s.gsView.defaultLightingType=t.defaultLightingType),t.brightness&&(s.gsView.brightness=t.brightness),t.contrast&&(s.gsView.contrast=t.contrast),t.ambientColor&&(s.gsView.ambientColor=t.ambientColor),n.tables.viewportTable.add(s)})}processBlockTables(e,n){e.tables.BLOCK_RECORD.entries.forEach(t=>{let s=n.tables.blockTable.getAt(t.name);s||(s=new o.AcDbBlockTableRecord,s.objectId=t.handle.toString(),s.name=t.name,n.tables.blockTable.add(s)),!s.isModelSapce&&!s.isPaperSapce&&t.entities&&t.entities.length>0&&this.processEntitiesInBlock(t.entities,s)})}processBlocks(e,n){}async processEntitiesInBlock(e,n){const r=new A,t=e.length;for(let s=0;s<t;s++){const i=e[s],l=r.convert(i);l&&n.appendEntity(l)}}async processEntities(e,n,r,t,s){const i=new A,l=e.entities,a=l.length,p=new o.AcDbBatchProcessing(a,100-t.value,r),c=n.tables.blockTable.modelSpace;await p.processChunk(async(h,d)=>{for(let f=h;f<d;f++){const u=l[f],g=i.convert(u);g&&c.appendEntity(g)}if(s){let f=t.value+d/a*(100-t.value);f>100&&(f=100),await s(f,"ENTITY","IN-PROGRESS")}})}processHeader(e,n){const r=e.header;n.cecolor.colorIndex=r.CECOLOR||256,n.angBase=r.ANGBASE??0,n.angDir=r.ANGDIR??0,n.aunits=r.AUNITS??0,n.extmax=r.EXTMAX,n.extmin=r.EXTMIN,n.insunits=r.INSUNITS??1,n.pdmode=r.PDMODE??0,n.pdsize=r.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 r=n.dictionaries.layouts;e.objects.LAYOUT.forEach(s=>{const i=new o.AcDbLayout;i.layoutName=s.layoutName,i.tabOrder=s.tabOrder,i.blockTableRecordId=s.ownerHandle.toString(),i.limits.min.copy(s.minLimit),i.limits.max.copy(s.maxLimit),i.extents.min.copy(s.minExtent),i.extents.max.copy(s.maxExtent),this.processCommonObjectAttrs(s,i),r.setAt(i.layoutName,i)})}processImageDefs(e,n){const r=n.dictionaries.imageDefs;e.objects.IMAGEDEF.forEach(s=>{const i=new o.AcDbRasterImageDef;i.sourceFileName=s.fileName,this.processCommonObjectAttrs(s,i),r.setAt(i.objectId,i)})}processCommonObjectAttrs(e,n){n.objectId=e.handle.toString(),n.ownerId=e.ownerHandle.toString()}}D.AcDbLibreDwgConverter=w,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|