@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.
@@ -1,646 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
52
- var __read = (this && this.__read) || function (o, n) {
53
- var m = typeof Symbol === "function" && o[Symbol.iterator];
54
- if (!m) return o;
55
- var i = m.call(o), r, ar = [], e;
56
- try {
57
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
58
- }
59
- catch (error) { e = { error: error }; }
60
- finally {
61
- try {
62
- if (r && !r.done && (m = i["return"])) m.call(i);
63
- }
64
- finally { if (e) throw e.error; }
65
- }
66
- return ar;
67
- };
68
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
69
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
70
- if (ar || !(i in from)) {
71
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
72
- ar[i] = from[i];
73
- }
74
- }
75
- return to.concat(ar || Array.prototype.slice.call(from));
76
- };
77
- var __values = (this && this.__values) || function(o) {
78
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
79
- if (m) return m.call(o);
80
- if (o && typeof o.length === "number") return {
81
- next: function () {
82
- if (o && i >= o.length) o = void 0;
83
- return { value: o && o[i++], done: !o };
84
- }
85
- };
86
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
87
- };
88
- import { AcCmColor, AcDbBatchProcessing, AcDbBlockTableRecord, AcDbDatabaseConverter, AcDbDimStyleTableRecord, AcDbLayerTableRecord, AcDbLayout, AcDbLinetypeTableRecord, AcDbRasterImageDef, AcDbTextStyleTableRecord, AcDbViewportTableRecord, createWorkerApi } from '@mlightcad/data-model';
89
- import { AcDbEntityConverter } from './AcDbEntitiyConverter';
90
- /**
91
- * Database converter for DWG files based on [libredwg-web](https://github.com/mlight-lee/libredwg-web).
92
- */
93
- var AcDbLibreDwgConverter = /** @class */ (function (_super) {
94
- __extends(AcDbLibreDwgConverter, _super);
95
- function AcDbLibreDwgConverter(config) {
96
- if (config === void 0) { config = {}; }
97
- var _this = _super.call(this, config) || this;
98
- config.useWorker = true;
99
- if (!config.parserWorkerUrl) {
100
- config.parserWorkerUrl = '/assets/libredwg-parser-worker.js';
101
- }
102
- return _this;
103
- }
104
- AcDbLibreDwgConverter.prototype.parse = function (data) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- var api, result;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0:
110
- if (!(this.config.useWorker && this.config.parserWorkerUrl)) return [3 /*break*/, 2];
111
- api = createWorkerApi({
112
- workerUrl: this.config.parserWorkerUrl,
113
- // One concurrent worker needed for parser
114
- maxConcurrentWorkers: 1
115
- });
116
- return [4 /*yield*/, api.execute(data)
117
- // Release worker
118
- ];
119
- case 1:
120
- result = _a.sent();
121
- // Release worker
122
- api.destroy();
123
- return [2 /*return*/, result.data];
124
- case 2: throw new Error('dwg converter can run in web worker only!');
125
- }
126
- });
127
- });
128
- };
129
- /**
130
- * Gets all of fonts used by entities in model space and paper space
131
- * @param dwg dwg database model
132
- * @returns Returns all of fonts used by entities in model space and paper space
133
- */
134
- AcDbLibreDwgConverter.prototype.getFonts = function (dwg) {
135
- // Build block map. The key is block name.
136
- var blockMap = new Map();
137
- dwg.tables.BLOCK_RECORD.entries.forEach(function (btr) {
138
- blockMap.set(btr.name, btr);
139
- });
140
- // Build text style map. The key is text style name, and the value is font name list.
141
- var styleMap = new Map();
142
- var getFontName = function (fontFileName) {
143
- if (fontFileName) {
144
- var lastDotIndex = fontFileName.lastIndexOf('.');
145
- if (lastDotIndex >= 0) {
146
- return fontFileName.substring(0, lastDotIndex).toLowerCase();
147
- }
148
- else {
149
- return fontFileName.toLowerCase();
150
- }
151
- }
152
- };
153
- dwg.tables.STYLE.entries.forEach(function (style) {
154
- var fontNames = [];
155
- var fontName = getFontName(style.font);
156
- if (fontName)
157
- fontNames.push(fontName);
158
- fontName = getFontName(style.bigFont);
159
- if (fontName)
160
- fontNames.push(fontName);
161
- styleMap.set(style.name, fontNames);
162
- });
163
- var fonts = new Set();
164
- this.getFontsInBlock(dwg.entities, blockMap, styleMap, fonts);
165
- return Array.from(fonts);
166
- };
167
- /**
168
- * Iterate entities in model space to get fonts used by text, mtext and insert entities
169
- */
170
- AcDbLibreDwgConverter.prototype.getFontsInBlock = function (entities, blockMap, styleMap, fonts) {
171
- var _this = this;
172
- var regex = /\\f(.*?)\|/g;
173
- entities.forEach(function (entity) {
174
- if (entity.type == 'MTEXT') {
175
- var mtext = entity;
176
- __spreadArray([], __read(mtext.text.matchAll(regex)), false).forEach(function (match) {
177
- fonts.add(match[1].toLowerCase());
178
- });
179
- var fontNames = styleMap.get(mtext.styleName);
180
- fontNames === null || fontNames === void 0 ? void 0 : fontNames.forEach(function (name) { return fonts.add(name); });
181
- }
182
- else if (entity.type == 'TEXT') {
183
- var text = entity;
184
- var fontNames = styleMap.get(text.styleName);
185
- fontNames === null || fontNames === void 0 ? void 0 : fontNames.forEach(function (name) { return fonts.add(name); });
186
- }
187
- else if (entity.type == 'INSERT') {
188
- var insert = entity;
189
- var block = blockMap.get(insert.name);
190
- if (block)
191
- _this.getFontsInBlock(block.entities, blockMap, styleMap, fonts);
192
- }
193
- });
194
- };
195
- AcDbLibreDwgConverter.prototype.processLineTypes = function (model, db) {
196
- var _this = this;
197
- var lineTypes = model.tables.LTYPE.entries;
198
- lineTypes.forEach(function (item) {
199
- var lineType = {
200
- name: item.name,
201
- description: item.description,
202
- standardFlag: item.standardFlag,
203
- totalPatternLength: item.totalPatternLength,
204
- pattern: item.pattern
205
- };
206
- var record = new AcDbLinetypeTableRecord(lineType);
207
- _this.processCommonTableEntryAttrs(item, record);
208
- record.name = item.name;
209
- db.tables.linetypeTable.add(record);
210
- });
211
- };
212
- AcDbLibreDwgConverter.prototype.processTextStyles = function (model, db) {
213
- var _this = this;
214
- var textStyles = model.tables.STYLE.entries;
215
- textStyles.forEach(function (item) {
216
- var record = new AcDbTextStyleTableRecord(item);
217
- _this.processCommonTableEntryAttrs(item, record);
218
- db.tables.textStyleTable.add(record);
219
- });
220
- };
221
- AcDbLibreDwgConverter.prototype.processDimStyles = function (model, db) {
222
- var _this = this;
223
- var dimStyles = model.tables.DIMSTYLE.entries;
224
- dimStyles.forEach(function (item) {
225
- var attrs = {
226
- name: item.name,
227
- ownerId: item.ownerHandle.toString(),
228
- dimpost: item.DIMPOST || '',
229
- dimapost: item.DIMAPOST || '',
230
- dimscale: item.DIMSCALE,
231
- dimasz: item.DIMASZ,
232
- dimexo: item.DIMEXO,
233
- dimdli: item.DIMDLI,
234
- dimexe: item.DIMEXE,
235
- dimrnd: item.DIMRND,
236
- dimdle: item.DIMDLE,
237
- dimtp: item.DIMTP,
238
- dimtm: item.DIMTM,
239
- dimtxt: item.DIMTXT,
240
- dimcen: item.DIMCEN,
241
- dimtsz: item.DIMTSZ,
242
- dimaltf: item.DIMALTF,
243
- dimlfac: item.DIMLFAC,
244
- dimtvp: item.DIMTVP,
245
- dimtfac: item.DIMTFAC,
246
- dimgap: item.DIMGAP,
247
- dimaltrnd: item.DIMALTRND,
248
- dimtol: item.DIMTOL == null || item.DIMTOL == 0 ? 0 : 1,
249
- dimlim: item.DIMLIM == null || item.DIMLIM == 0 ? 0 : 1,
250
- dimtih: item.DIMTIH == null || item.DIMTIH == 0 ? 0 : 1,
251
- dimtoh: item.DIMTOH == null || item.DIMTOH == 0 ? 0 : 1,
252
- dimse1: item.DIMSE1 == null || item.DIMSE1 == 0 ? 0 : 1,
253
- dimse2: item.DIMSE2 == null || item.DIMSE2 == 0 ? 0 : 1,
254
- dimtad: item.DIMTAD,
255
- dimzin: item.DIMZIN,
256
- dimazin: item.DIMAZIN,
257
- dimalt: item.DIMALT,
258
- dimaltd: item.DIMALTD,
259
- dimtofl: item.DIMTOFL,
260
- dimsah: item.DIMSAH,
261
- dimtix: item.DIMTIX,
262
- dimsoxd: item.DIMSOXD,
263
- dimclrd: item.DIMCLRD,
264
- dimclre: item.DIMCLRE,
265
- dimclrt: item.DIMCLRT,
266
- dimadec: item.DIMADEC || 0,
267
- dimunit: item.DIMUNIT || 2,
268
- dimdec: item.DIMDEC,
269
- dimtdec: item.DIMTDEC,
270
- dimaltu: item.DIMALTU,
271
- dimalttd: item.DIMALTTD,
272
- dimaunit: item.DIMAUNIT,
273
- dimfrac: item.DIMFRAC,
274
- dimlunit: item.DIMLUNIT,
275
- dimdsep: item.DIMDSEP,
276
- dimtmove: item.DIMTMOVE || 0,
277
- dimjust: item.DIMJUST,
278
- dimsd1: item.DIMSD1,
279
- dimsd2: item.DIMSD2,
280
- dimtolj: item.DIMTOLJ,
281
- dimtzin: item.DIMTZIN,
282
- dimaltz: item.DIMALTZ,
283
- dimalttz: item.DIMALTTZ,
284
- dimfit: item.DIMFIT || 0,
285
- dimupt: item.DIMUPT,
286
- dimatfit: item.DIMATFIT,
287
- dimtxsty: 'Standard', // TODO: Set correct value
288
- dimldrblk: '', // TODO: Set correct value
289
- dimblk: item.DIMBLK || '', // TODO: Set correct value
290
- dimblk1: item.DIMBLK1 || '', // TODO: Set correct value
291
- dimblk2: item.DIMBLK2 || '', // TODO: Set correct value
292
- dimlwd: item.DIMLWD,
293
- dimlwe: item.DIMLWE
294
- };
295
- var record = new AcDbDimStyleTableRecord(attrs);
296
- _this.processCommonTableEntryAttrs(item, record);
297
- db.tables.dimStyleTable.add(record);
298
- });
299
- };
300
- AcDbLibreDwgConverter.prototype.processLayers = function (model, db) {
301
- var _this = this;
302
- var layers = model.tables.LAYER.entries;
303
- layers.forEach(function (item) {
304
- var color = new AcCmColor();
305
- color.colorIndex = item.colorIndex;
306
- var record = new AcDbLayerTableRecord({
307
- name: item.name,
308
- standardFlags: item.standardFlag,
309
- linetype: item.lineType,
310
- lineWeight: item.lineweight,
311
- isOff: item.off,
312
- color: color,
313
- isPlottable: item.plotFlag != 0
314
- });
315
- _this.processCommonTableEntryAttrs(item, record);
316
- db.tables.layerTable.add(record);
317
- });
318
- };
319
- AcDbLibreDwgConverter.prototype.processViewports = function (model, db) {
320
- var _this = this;
321
- var viewports = model.tables.VPORT.entries;
322
- viewports.forEach(function (item) {
323
- var record = new AcDbViewportTableRecord();
324
- _this.processCommonTableEntryAttrs(item, record);
325
- if (item.circleSides) {
326
- record.circleSides = item.circleSides;
327
- }
328
- record.standardFlag = item.standardFlag;
329
- record.center.copy(item.center);
330
- record.lowerLeftCorner.copy(item.lowerLeftCorner);
331
- record.upperRightCorner.copy(item.upperRightCorner);
332
- if (item.snapBasePoint) {
333
- record.snapBase.copy(item.snapBasePoint);
334
- }
335
- if (item.snapRotationAngle) {
336
- record.snapAngle = item.snapRotationAngle;
337
- }
338
- if (item.snapSpacing) {
339
- record.snapIncrements.copy(item.snapSpacing);
340
- }
341
- if (item.majorGridLines) {
342
- record.gridMajor = item.majorGridLines;
343
- }
344
- if (item.gridSpacing) {
345
- record.gridIncrements.copy(item.gridSpacing);
346
- }
347
- if (item.backgroundObjectId) {
348
- record.backgroundObjectId = item.backgroundObjectId;
349
- }
350
- record.gsView.center.copy(item.center);
351
- record.gsView.viewDirectionFromTarget.copy(item.viewDirectionFromTarget);
352
- record.gsView.viewTarget.copy(item.viewTarget);
353
- if (item.lensLength) {
354
- record.gsView.lensLength = item.lensLength;
355
- }
356
- if (item.frontClippingPlane) {
357
- record.gsView.frontClippingPlane = item.frontClippingPlane;
358
- }
359
- if (item.backClippingPlane) {
360
- record.gsView.backClippingPlane = item.backClippingPlane;
361
- }
362
- if (item.viewHeight) {
363
- record.gsView.viewHeight = item.viewHeight;
364
- }
365
- if (item.viewTwistAngle) {
366
- record.gsView.viewTwistAngle = item.viewTwistAngle;
367
- }
368
- if (item.frozenLayers) {
369
- record.gsView.frozenLayers = item.frozenLayers;
370
- }
371
- if (item.styleSheet) {
372
- record.gsView.styleSheet = item.styleSheet;
373
- }
374
- if (item.renderMode) {
375
- record.gsView.renderMode = item.renderMode;
376
- }
377
- if (item.viewMode) {
378
- record.gsView.viewMode = item.viewMode;
379
- }
380
- if (item.ucsIconSetting) {
381
- record.gsView.ucsIconSetting = item.ucsIconSetting;
382
- }
383
- if (item.ucsOrigin) {
384
- record.gsView.ucsOrigin.copy(item.ucsOrigin);
385
- }
386
- if (item.ucsXAxis) {
387
- record.gsView.ucsXAxis.copy(item.ucsXAxis);
388
- }
389
- if (item.ucsYAxis) {
390
- record.gsView.ucsYAxis.copy(item.ucsYAxis);
391
- }
392
- if (item.orthographicType) {
393
- record.gsView.orthographicType =
394
- item.orthographicType;
395
- }
396
- if (item.shadePlotSetting) {
397
- record.gsView.shadePlotSetting = item.shadePlotSetting;
398
- }
399
- if (item.shadePlotObjectId) {
400
- record.gsView.shadePlotObjectId = item.shadePlotObjectId;
401
- }
402
- if (item.visualStyleObjectId) {
403
- record.gsView.visualStyleObjectId = item.visualStyleObjectId;
404
- }
405
- if (item.isDefaultLightingOn) {
406
- record.gsView.isDefaultLightingOn = item.isDefaultLightingOn;
407
- }
408
- if (item.defaultLightingType) {
409
- record.gsView.defaultLightingType =
410
- item.defaultLightingType;
411
- }
412
- if (item.brightness) {
413
- record.gsView.brightness = item.brightness;
414
- }
415
- if (item.contrast) {
416
- record.gsView.contrast = item.contrast;
417
- }
418
- if (item.ambientColor) {
419
- record.gsView.ambientColor = item.ambientColor;
420
- }
421
- db.tables.viewportTable.add(record);
422
- });
423
- };
424
- AcDbLibreDwgConverter.prototype.processBlockTables = function (model, db) {
425
- var _this = this;
426
- var btrs = model.tables.BLOCK_RECORD.entries;
427
- btrs.forEach(function (btr) {
428
- var dbBlock = db.tables.blockTable.getAt(btr.name);
429
- if (!dbBlock) {
430
- dbBlock = new AcDbBlockTableRecord();
431
- dbBlock.objectId = btr.handle.toString();
432
- dbBlock.name = btr.name;
433
- dbBlock.ownerId = btr.ownerHandle.toString();
434
- dbBlock.origin.copy(btr.basePoint);
435
- dbBlock.layoutId = btr.layout.toString();
436
- db.tables.blockTable.add(dbBlock);
437
- }
438
- // Don't process entities in block space and paper space until other blocks are processed
439
- if (!dbBlock.isModelSapce &&
440
- !dbBlock.isPaperSapce &&
441
- btr.entities &&
442
- btr.entities.length > 0) {
443
- _this.processEntitiesInBlock(btr.entities, dbBlock);
444
- }
445
- });
446
- };
447
- AcDbLibreDwgConverter.prototype.processBlocks = function (_model, _db) {
448
- // Do nothing because entities are already processsed in method processBlockTables
449
- };
450
- AcDbLibreDwgConverter.prototype.processEntitiesInBlock = function (entities, blockTableRecord) {
451
- return __awaiter(this, void 0, void 0, function () {
452
- var converter, entityCount, dbEntities, i, entity, dbEntity;
453
- return __generator(this, function (_a) {
454
- converter = new AcDbEntityConverter();
455
- entityCount = entities.length;
456
- dbEntities = [];
457
- for (i = 0; i < entityCount; i++) {
458
- entity = entities[i];
459
- dbEntity = converter.convert(entity);
460
- if (dbEntity) {
461
- dbEntities.push(dbEntity);
462
- }
463
- }
464
- // Use batch append to improve performance
465
- blockTableRecord.appendEntity(dbEntities);
466
- return [2 /*return*/];
467
- });
468
- });
469
- };
470
- /**
471
- * Breaks up the work into smaller chunks that are executed asynchronously. This is often referred to
472
- * as "batch processing" or "cooperative multitasking," where the time-consuming task is broken into
473
- * smaller pieces and executed in small intervals to allow the UI to remain responsive.
474
- */
475
- AcDbLibreDwgConverter.prototype.processEntities = function (model, db, minimumChunkSize, startPercentage, progress) {
476
- return __awaiter(this, void 0, void 0, function () {
477
- var converter, entities, entityCount, batchProcessor, blockTableRecord;
478
- var _this = this;
479
- return __generator(this, function (_a) {
480
- switch (_a.label) {
481
- case 0:
482
- converter = new AcDbEntityConverter();
483
- entities = model.entities;
484
- entityCount = entities.length;
485
- batchProcessor = new AcDbBatchProcessing(entityCount, 100 - startPercentage.value, minimumChunkSize);
486
- // Groups entities by their `type` property and flattens the result into a single array.
487
- if (this.config.convertByEntityType) {
488
- entities = this.groupAndFlattenByType(entities);
489
- }
490
- blockTableRecord = db.tables.blockTable.modelSpace;
491
- return [4 /*yield*/, batchProcessor.processChunk(function (start, end) { return __awaiter(_this, void 0, void 0, function () {
492
- var dbEntities, i, entity, dbEntity, percentage;
493
- return __generator(this, function (_a) {
494
- switch (_a.label) {
495
- case 0:
496
- dbEntities = [];
497
- for (i = start; i < end; i++) {
498
- entity = entities[i];
499
- dbEntity = converter.convert(entity);
500
- if (dbEntity) {
501
- dbEntities.push(dbEntity);
502
- }
503
- }
504
- // Use batch append to improve performance
505
- blockTableRecord.appendEntity(dbEntities);
506
- if (!progress) return [3 /*break*/, 2];
507
- percentage = startPercentage.value +
508
- (end / entityCount) * (100 - startPercentage.value);
509
- if (percentage > 100)
510
- percentage = 100;
511
- return [4 /*yield*/, progress(percentage, 'ENTITY', 'IN-PROGRESS')];
512
- case 1:
513
- _a.sent();
514
- _a.label = 2;
515
- case 2: return [2 /*return*/];
516
- }
517
- });
518
- }); })];
519
- case 1:
520
- _a.sent();
521
- return [2 /*return*/];
522
- }
523
- });
524
- });
525
- };
526
- AcDbLibreDwgConverter.prototype.processHeader = function (model, db) {
527
- var _a, _b, _c, _d, _e, _f;
528
- var header = model.header;
529
- // Color index 256 is 'ByLayer'
530
- db.cecolor.colorIndex = header.CECOLOR || 256;
531
- db.angBase = (_a = header.ANGBASE) !== null && _a !== void 0 ? _a : 0;
532
- db.angDir = (_b = header.ANGDIR) !== null && _b !== void 0 ? _b : 0;
533
- db.aunits = (_c = header.AUNITS) !== null && _c !== void 0 ? _c : 0;
534
- if (header.EXTMAX)
535
- db.extmax = header.EXTMAX;
536
- if (header.EXTMIN)
537
- db.extmin = header.EXTMIN;
538
- // Initial value of INSUNITS: 1 (imperial) or 4 (metric)
539
- db.insunits = (_d = header.INSUNITS) !== null && _d !== void 0 ? _d : 1;
540
- db.pdmode = (_e = header.PDMODE) !== null && _e !== void 0 ? _e : 0;
541
- db.pdsize = (_f = header.PDSIZE) !== null && _f !== void 0 ? _f : 0.0;
542
- };
543
- AcDbLibreDwgConverter.prototype.processCommonTableEntryAttrs = function (entry, dbEntry) {
544
- dbEntry.name = entry.name;
545
- dbEntry.objectId = entry.handle.toString();
546
- dbEntry.ownerId = entry.ownerHandle.toString();
547
- };
548
- AcDbLibreDwgConverter.prototype.processObjects = function (model, db) {
549
- this.processLayouts(model, db);
550
- this.processImageDefs(model, db);
551
- };
552
- AcDbLibreDwgConverter.prototype.processLayouts = function (model, db) {
553
- var _this = this;
554
- var layoutDict = db.dictionaries.layouts;
555
- var layouts = model.objects.LAYOUT;
556
- layouts.forEach(function (layout) {
557
- var e_1, _a;
558
- var dbLayout = new AcDbLayout();
559
- dbLayout.layoutName = layout.layoutName;
560
- dbLayout.tabOrder = layout.tabOrder;
561
- // layout.paperSpaceTableId doesn't point to the block table record asscicated with
562
- // this layout. So let's get the assocated block table record id from block table.
563
- var btrs = db.tables.blockTable.newIterator();
564
- dbLayout.objectId = layout.handle.toString();
565
- try {
566
- for (var btrs_1 = __values(btrs), btrs_1_1 = btrs_1.next(); !btrs_1_1.done; btrs_1_1 = btrs_1.next()) {
567
- var btr = btrs_1_1.value;
568
- // Because the type of layout id (number) block table record and layout id (BingInt)
569
- // in layout dictionary are different, so the converted data are used to compare.
570
- // In the future, we will use BigInt type for object id.
571
- if (btr.layoutId === dbLayout.objectId) {
572
- dbLayout.blockTableRecordId = btr.objectId;
573
- break;
574
- }
575
- }
576
- }
577
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
578
- finally {
579
- try {
580
- if (btrs_1_1 && !btrs_1_1.done && (_a = btrs_1.return)) _a.call(btrs_1);
581
- }
582
- finally { if (e_1) throw e_1.error; }
583
- }
584
- dbLayout.limits.min.copy(layout.minLimit);
585
- dbLayout.limits.max.copy(layout.maxLimit);
586
- dbLayout.extents.min.copy(layout.minExtent);
587
- dbLayout.extents.max.copy(layout.maxExtent);
588
- _this.processCommonObjectAttrs(layout, dbLayout);
589
- layoutDict.setAt(dbLayout.layoutName, dbLayout);
590
- });
591
- };
592
- AcDbLibreDwgConverter.prototype.processImageDefs = function (model, db) {
593
- var _this = this;
594
- var imageDefDict = db.dictionaries.imageDefs;
595
- var imageDefs = model.objects.IMAGEDEF;
596
- imageDefs.forEach(function (imageDef) {
597
- var dbImageDef = new AcDbRasterImageDef();
598
- dbImageDef.sourceFileName = imageDef.fileName;
599
- _this.processCommonObjectAttrs(imageDef, dbImageDef);
600
- imageDefDict.setAt(dbImageDef.objectId, dbImageDef);
601
- });
602
- };
603
- AcDbLibreDwgConverter.prototype.processCommonObjectAttrs = function (object, dbObject) {
604
- dbObject.objectId = object.handle.toString();
605
- dbObject.ownerId = object.ownerHandle.toString();
606
- };
607
- /**
608
- * Groups entities by their `type` property and flattens the result into a single array.
609
- *
610
- * The order of `type` groups follows the order in which they first appear in the input array.
611
- * Items within each group preserve their original order.
612
- *
613
- * This runs in O(n) time, which is generally faster than sorting when you
614
- * don't care about alphabetical order of types.
615
- *
616
- * @param entities - The array of entities to group and flatten.
617
- *
618
- * @returns A new array of entities grouped by their `type` property.
619
- */
620
- AcDbLibreDwgConverter.prototype.groupAndFlattenByType = function (entities) {
621
- var e_2, _a;
622
- var groups = {};
623
- var order = [];
624
- try {
625
- for (var entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
626
- var entity = entities_1_1.value;
627
- if (!groups[entity.type]) {
628
- groups[entity.type] = [];
629
- order.push(entity.type);
630
- }
631
- groups[entity.type].push(entity);
632
- }
633
- }
634
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
635
- finally {
636
- try {
637
- if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
638
- }
639
- finally { if (e_2) throw e_2.error; }
640
- }
641
- return order.flatMap(function (type) { return groups[type]; });
642
- };
643
- return AcDbLibreDwgConverter;
644
- }(AcDbDatabaseConverter));
645
- export { AcDbLibreDwgConverter };
646
- //# sourceMappingURL=AcDbLibreDwgConverter.js.map