@mlightcad/data-model 1.10.1 → 1.10.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.
Files changed (81) hide show
  1. package/README.md +17 -0
  2. package/dist/data-model.cjs +10 -7
  3. package/lib/converter/AcDbFontNameCollector.d.ts +6 -0
  4. package/lib/converter/AcDbFontNameCollector.d.ts.map +1 -1
  5. package/lib/converter/AcDbFontNameCollector.js +101 -37
  6. package/lib/converter/AcDbFontNameCollector.js.map +1 -1
  7. package/lib/converter/index.d.ts +1 -1
  8. package/lib/converter/index.d.ts.map +1 -1
  9. package/lib/converter/worker/AcDbBaseWorker.d.ts +22 -0
  10. package/lib/converter/worker/AcDbBaseWorker.d.ts.map +1 -1
  11. package/lib/converter/worker/AcDbBaseWorker.js +26 -3
  12. package/lib/converter/worker/AcDbBaseWorker.js.map +1 -1
  13. package/lib/converter/worker/AcDbWorkerManager.d.ts +3 -0
  14. package/lib/converter/worker/AcDbWorkerManager.d.ts.map +1 -1
  15. package/lib/converter/worker/AcDbWorkerManager.js +8 -3
  16. package/lib/converter/worker/AcDbWorkerManager.js.map +1 -1
  17. package/lib/converter/worker/index.d.ts +1 -1
  18. package/lib/converter/worker/index.d.ts.map +1 -1
  19. package/lib/database/AcDbBlockTable.d.ts +2 -1
  20. package/lib/database/AcDbBlockTable.d.ts.map +1 -1
  21. package/lib/database/AcDbBlockTable.js +7 -18
  22. package/lib/database/AcDbBlockTable.js.map +1 -1
  23. package/lib/database/AcDbBlockTableRecord.d.ts +7 -1
  24. package/lib/database/AcDbBlockTableRecord.d.ts.map +1 -1
  25. package/lib/database/AcDbBlockTableRecord.js +48 -13
  26. package/lib/database/AcDbBlockTableRecord.js.map +1 -1
  27. package/lib/database/AcDbDatabase.d.ts +92 -12
  28. package/lib/database/AcDbDatabase.d.ts.map +1 -1
  29. package/lib/database/AcDbDatabase.js +322 -198
  30. package/lib/database/AcDbDatabase.js.map +1 -1
  31. package/lib/database/AcDbOpenDatabaseError.d.ts +113 -0
  32. package/lib/database/AcDbOpenDatabaseError.d.ts.map +1 -0
  33. package/lib/database/AcDbOpenDatabaseError.js +156 -0
  34. package/lib/database/AcDbOpenDatabaseError.js.map +1 -0
  35. package/lib/database/AcDbSymbolTable.d.ts +20 -3
  36. package/lib/database/AcDbSymbolTable.d.ts.map +1 -1
  37. package/lib/database/AcDbSymbolTable.js +120 -11
  38. package/lib/database/AcDbSymbolTable.js.map +1 -1
  39. package/lib/database/AcDbTextStyleTable.js +1 -1
  40. package/lib/database/AcDbTextStyleTable.js.map +1 -1
  41. package/lib/database/index.d.ts +3 -1
  42. package/lib/database/index.d.ts.map +1 -1
  43. package/lib/database/index.js +1 -0
  44. package/lib/database/index.js.map +1 -1
  45. package/lib/entity/AcDb3dSolid.d.ts +77 -0
  46. package/lib/entity/AcDb3dSolid.d.ts.map +1 -0
  47. package/lib/entity/AcDb3dSolid.js +232 -0
  48. package/lib/entity/AcDb3dSolid.js.map +1 -0
  49. package/lib/entity/AcDbFcf.d.ts +144 -0
  50. package/lib/entity/AcDbFcf.d.ts.map +1 -0
  51. package/lib/entity/AcDbFcf.js +718 -0
  52. package/lib/entity/AcDbFcf.js.map +1 -0
  53. package/lib/entity/AcDbLeader.d.ts +44 -0
  54. package/lib/entity/AcDbLeader.d.ts.map +1 -1
  55. package/lib/entity/AcDbLeader.js +238 -10
  56. package/lib/entity/AcDbLeader.js.map +1 -1
  57. package/lib/entity/AcDbMText.d.ts +10 -0
  58. package/lib/entity/AcDbMText.d.ts.map +1 -1
  59. package/lib/entity/AcDbMText.js +28 -3
  60. package/lib/entity/AcDbMText.js.map +1 -1
  61. package/lib/entity/AcDbTextExtentsHelpers.d.ts +104 -1
  62. package/lib/entity/AcDbTextExtentsHelpers.d.ts.map +1 -1
  63. package/lib/entity/AcDbTextExtentsHelpers.js +126 -0
  64. package/lib/entity/AcDbTextExtentsHelpers.js.map +1 -1
  65. package/lib/entity/index.d.ts +2 -0
  66. package/lib/entity/index.d.ts.map +1 -1
  67. package/lib/entity/index.js +2 -0
  68. package/lib/entity/index.js.map +1 -1
  69. package/lib/index.d.ts +4 -4
  70. package/lib/index.d.ts.map +1 -1
  71. package/lib/index.js +2 -2
  72. package/lib/index.js.map +1 -1
  73. package/lib/misc/AcDbObjectIterator.d.ts +5 -4
  74. package/lib/misc/AcDbObjectIterator.d.ts.map +1 -1
  75. package/lib/misc/AcDbObjectIterator.js +50 -5
  76. package/lib/misc/AcDbObjectIterator.js.map +1 -1
  77. package/lib/object/AcDbDictionary.d.ts +0 -2
  78. package/lib/object/AcDbDictionary.d.ts.map +1 -1
  79. package/lib/object/AcDbDictionary.js +21 -12
  80. package/lib/object/AcDbDictionary.js.map +1 -1
  81. package/package.json +4 -4
@@ -0,0 +1,718 @@
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 __values = (this && this.__values) || function(o) {
17
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
18
+ if (m) return m.call(o);
19
+ if (o && typeof o.length === "number") return {
20
+ next: function () {
21
+ if (o && i >= o.length) o = void 0;
22
+ return { value: o && o[i++], done: !o };
23
+ }
24
+ };
25
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
26
+ };
27
+ var __read = (this && this.__read) || function (o, n) {
28
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29
+ if (!m) return o;
30
+ var i = m.call(o), r, ar = [], e;
31
+ try {
32
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
33
+ }
34
+ catch (error) { e = { error: error }; }
35
+ finally {
36
+ try {
37
+ if (r && !r.done && (m = i["return"])) m.call(i);
38
+ }
39
+ finally { if (e) throw e.error; }
40
+ }
41
+ return ar;
42
+ };
43
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
45
+ if (ar || !(i in from)) {
46
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
47
+ ar[i] = from[i];
48
+ }
49
+ }
50
+ return to.concat(ar || Array.prototype.slice.call(from));
51
+ };
52
+ import { AcGeBox3d, AcGePoint3d, AcGeVector3d } from '@mlightcad/geometry-engine';
53
+ import { AcGiMTextAttachmentPoint, AcGiMTextFlowDirection } from '@mlightcad/graphic-interface';
54
+ import { AcDbDimStyleTableRecord } from '../database';
55
+ import { AcDbOsnapMode } from '../misc/AcDbOsnapMode';
56
+ import { AcDbEntity } from './AcDbEntity';
57
+ import { acdbMovePrimaryGripPointAt } from './AcDbGripHelpers';
58
+ import { acdbEstimatePlainTextWidth, acdbStripMTextControlCodes } from './AcDbTextExtentsHelpers';
59
+ var TOLERANCE_SLOT_COUNT = 6;
60
+ /**
61
+ * Represents a feature control frame (FCF) entity in AutoCAD.
62
+ *
63
+ * Feature control frames are used for geometric dimensioning and tolerancing
64
+ * (GD&T). They are created by the TOLERANCE command and controlled by dimension
65
+ * styles, mirroring {@link https://help.autodesk.com/view/OARX/2023/ENU/?guid=OARX-RefGuide-AcDbFcf AcDbFcf}
66
+ * in ObjectARX.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const fcf = new AcDbFcf();
71
+ * fcf.location = new AcGePoint3d(10, 20, 0);
72
+ * fcf.text = '{\\Fgdt.shx|b0|i0|c134|p6;j}|0.05|A|';
73
+ * fcf.dimensionStyle = 'Standard';
74
+ * ```
75
+ */
76
+ var AcDbFcf = /** @class */ (function (_super) {
77
+ __extends(AcDbFcf, _super);
78
+ /**
79
+ * Creates a new feature control frame entity at the origin with default orientation.
80
+ */
81
+ function AcDbFcf() {
82
+ var _this = _super.call(this) || this;
83
+ _this._location = new AcGePoint3d();
84
+ _this._text = '';
85
+ _this._dimensionStyle = '';
86
+ _this._normal = new AcGeVector3d(0, 0, 1);
87
+ _this._direction = new AcGeVector3d(1, 0, 0);
88
+ return _this;
89
+ }
90
+ Object.defineProperty(AcDbFcf.prototype, "dxfTypeName", {
91
+ get: function () {
92
+ return 'TOLERANCE';
93
+ },
94
+ enumerable: false,
95
+ configurable: true
96
+ });
97
+ Object.defineProperty(AcDbFcf.prototype, "location", {
98
+ /**
99
+ * Gets the insertion point of this feature control frame.
100
+ *
101
+ * Mirrors `AcDbFcf::location()` in ObjectARX.
102
+ */
103
+ get: function () {
104
+ return this._location;
105
+ },
106
+ /**
107
+ * Sets the insertion point of this feature control frame.
108
+ *
109
+ * Mirrors `AcDbFcf::setLocation()` in ObjectARX.
110
+ */
111
+ set: function (value) {
112
+ var _a;
113
+ this._location.set(value.x, value.y, (_a = value.z) !== null && _a !== void 0 ? _a : 0);
114
+ },
115
+ enumerable: false,
116
+ configurable: true
117
+ });
118
+ Object.defineProperty(AcDbFcf.prototype, "text", {
119
+ /**
120
+ * Gets the encoded tolerance text string.
121
+ *
122
+ * Mirrors `AcDbFcf::text()` in ObjectARX.
123
+ */
124
+ get: function () {
125
+ return this._text;
126
+ },
127
+ /**
128
+ * Sets the encoded tolerance text string.
129
+ *
130
+ * Mirrors `AcDbFcf::setText()` in ObjectARX.
131
+ */
132
+ set: function (value) {
133
+ this._text = value;
134
+ },
135
+ enumerable: false,
136
+ configurable: true
137
+ });
138
+ Object.defineProperty(AcDbFcf.prototype, "dimensionStyle", {
139
+ /**
140
+ * Gets the dimension style name applied to this feature control frame.
141
+ */
142
+ get: function () {
143
+ return this._dimensionStyle;
144
+ },
145
+ /**
146
+ * Sets the dimension style name applied to this feature control frame.
147
+ */
148
+ set: function (value) {
149
+ this._dimensionStyle = value;
150
+ },
151
+ enumerable: false,
152
+ configurable: true
153
+ });
154
+ Object.defineProperty(AcDbFcf.prototype, "normal", {
155
+ /**
156
+ * Gets the plane normal vector in WCS coordinates.
157
+ *
158
+ * Mirrors `AcDbFcf::normal()` in ObjectARX.
159
+ */
160
+ get: function () {
161
+ return this._normal;
162
+ },
163
+ /**
164
+ * Sets the plane normal vector in WCS coordinates.
165
+ */
166
+ set: function (value) {
167
+ var _a;
168
+ this._normal.set(value.x, value.y, (_a = value.z) !== null && _a !== void 0 ? _a : 0);
169
+ if (this._normal.lengthSq() > 0) {
170
+ this._normal.normalize();
171
+ }
172
+ },
173
+ enumerable: false,
174
+ configurable: true
175
+ });
176
+ Object.defineProperty(AcDbFcf.prototype, "direction", {
177
+ /**
178
+ * Gets the X-axis direction vector in WCS coordinates.
179
+ *
180
+ * Mirrors `AcDbFcf::direction()` in ObjectARX.
181
+ */
182
+ get: function () {
183
+ return this._direction;
184
+ },
185
+ /**
186
+ * Sets the X-axis direction vector in WCS coordinates.
187
+ */
188
+ set: function (value) {
189
+ var _a;
190
+ this._direction.set(value.x, value.y, (_a = value.z) !== null && _a !== void 0 ? _a : 0);
191
+ if (this._direction.lengthSq() > 0) {
192
+ this._direction.normalize();
193
+ }
194
+ },
195
+ enumerable: false,
196
+ configurable: true
197
+ });
198
+ /**
199
+ * Sets the plane normal and X-axis direction for this feature control frame.
200
+ *
201
+ * Mirrors `AcDbFcf::setOrientation()` in ObjectARX.
202
+ */
203
+ AcDbFcf.prototype.setOrientation = function (normal, direction) {
204
+ this.normal = normal;
205
+ this.direction = direction;
206
+ return this;
207
+ };
208
+ /**
209
+ * Returns the consecutive distinct corner points of the feature control frame.
210
+ *
211
+ * Mirrors `AcDbFcf::getBoundingPoints()` in ObjectARX.
212
+ */
213
+ AcDbFcf.prototype.getBoundingPoints = function () {
214
+ return this.getBoundingPolyline().slice(0, 4);
215
+ };
216
+ /**
217
+ * Returns the closed bounding polyline of the feature control frame.
218
+ *
219
+ * Mirrors `AcDbFcf::getBoundingPolyline()` in ObjectARX.
220
+ */
221
+ AcDbFcf.prototype.getBoundingPolyline = function () {
222
+ var _this = this;
223
+ var _a = this.resolveFrameLayout(), width = _a.width, rowHeight = _a.rowHeight, rowCount = _a.rowCount;
224
+ var frameTop = rowHeight / 2;
225
+ var frameBottom = frameTop - rowHeight * rowCount;
226
+ var corners = [
227
+ new AcGePoint3d(0, frameTop, 0),
228
+ new AcGePoint3d(width, frameTop, 0),
229
+ new AcGePoint3d(width, frameBottom, 0),
230
+ new AcGePoint3d(0, frameBottom, 0),
231
+ new AcGePoint3d(0, frameTop, 0)
232
+ ];
233
+ return corners.map(function (corner) { return _this.toFrameWcs(corner.x, corner.y); });
234
+ };
235
+ Object.defineProperty(AcDbFcf.prototype, "geometricExtents", {
236
+ get: function () {
237
+ var e_1, _a;
238
+ var box = new AcGeBox3d();
239
+ try {
240
+ for (var _b = __values(this.getBoundingPoints()), _c = _b.next(); !_c.done; _c = _b.next()) {
241
+ var point = _c.value;
242
+ box.expandByPoint(point);
243
+ }
244
+ }
245
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
246
+ finally {
247
+ try {
248
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
249
+ }
250
+ finally { if (e_1) throw e_1.error; }
251
+ }
252
+ if (box.isEmpty()) {
253
+ box.expandByPoint(this._location);
254
+ }
255
+ return box;
256
+ },
257
+ enumerable: false,
258
+ configurable: true
259
+ });
260
+ AcDbFcf.prototype.subGetGripPoints = function () {
261
+ return [this._location];
262
+ };
263
+ /** @inheritdoc */
264
+ AcDbFcf.prototype.subMoveGripPointsAt = function (indices, offset) {
265
+ acdbMovePrimaryGripPointAt(indices, offset, this._location);
266
+ return this;
267
+ };
268
+ AcDbFcf.prototype.subGetOsnapPoints = function (osnapMode, _pickPoint, _lastPoint, snapPoints) {
269
+ if (osnapMode === AcDbOsnapMode.Insertion) {
270
+ snapPoints.push(this._location);
271
+ }
272
+ };
273
+ AcDbFcf.prototype.transformBy = function (matrix) {
274
+ var basis = this.resolveLocalBasis();
275
+ var origin = this._location.clone();
276
+ var xAxisPoint = origin.clone().add(basis.xAxis);
277
+ var yAxisPoint = origin.clone().add(basis.yAxis);
278
+ origin.applyMatrix4(matrix);
279
+ xAxisPoint.applyMatrix4(matrix);
280
+ yAxisPoint.applyMatrix4(matrix);
281
+ var xAxis = new AcGeVector3d(xAxisPoint).sub(origin);
282
+ var yAxis = new AcGeVector3d(yAxisPoint).sub(origin);
283
+ var normal = new AcGeVector3d().crossVectors(xAxis, yAxis);
284
+ if (normal.lengthSq() === 0) {
285
+ normal = this._normal.clone().transformDirection(matrix);
286
+ }
287
+ else {
288
+ normal.normalize();
289
+ }
290
+ var direction = xAxis.clone();
291
+ if (direction.lengthSq() === 0) {
292
+ direction = this._direction.clone().transformDirection(matrix);
293
+ }
294
+ else {
295
+ direction.normalize();
296
+ }
297
+ this._location.copy(origin);
298
+ this._normal.copy(normal);
299
+ this._direction.copy(direction);
300
+ return this;
301
+ };
302
+ Object.defineProperty(AcDbFcf.prototype, "properties", {
303
+ get: function () {
304
+ var _this = this;
305
+ return {
306
+ type: this.type,
307
+ groups: [
308
+ this.getGeneralProperties(),
309
+ {
310
+ groupName: 'tolerance',
311
+ properties: [
312
+ {
313
+ name: 'text',
314
+ type: 'string',
315
+ editable: true,
316
+ accessor: {
317
+ get: function () { return _this.text; },
318
+ set: function (v) {
319
+ _this.text = v;
320
+ }
321
+ }
322
+ },
323
+ {
324
+ name: 'dimensionStyle',
325
+ type: 'string',
326
+ editable: true,
327
+ accessor: {
328
+ get: function () { return _this.dimensionStyle; },
329
+ set: function (v) {
330
+ _this.dimensionStyle = v;
331
+ }
332
+ }
333
+ },
334
+ {
335
+ name: 'textHeight',
336
+ type: 'float',
337
+ editable: false,
338
+ accessor: {
339
+ get: function () { return _this.textHeight; }
340
+ }
341
+ }
342
+ ]
343
+ },
344
+ {
345
+ groupName: 'geometry',
346
+ properties: [
347
+ {
348
+ name: 'locationX',
349
+ type: 'float',
350
+ editable: true,
351
+ accessor: {
352
+ get: function () { return _this.location.x; },
353
+ set: function (v) {
354
+ _this.location.x = v;
355
+ }
356
+ }
357
+ },
358
+ {
359
+ name: 'locationY',
360
+ type: 'float',
361
+ editable: true,
362
+ accessor: {
363
+ get: function () { return _this.location.y; },
364
+ set: function (v) {
365
+ _this.location.y = v;
366
+ }
367
+ }
368
+ },
369
+ {
370
+ name: 'locationZ',
371
+ type: 'float',
372
+ editable: true,
373
+ accessor: {
374
+ get: function () { return _this.location.z; },
375
+ set: function (v) {
376
+ _this.location.z = v;
377
+ }
378
+ }
379
+ }
380
+ ]
381
+ }
382
+ ]
383
+ };
384
+ },
385
+ enumerable: false,
386
+ configurable: true
387
+ });
388
+ AcDbFcf.prototype.subWorldDraw = function (renderer, delay) {
389
+ var frameSegments = this.collectFrameLineSegments();
390
+ var frameEntities = frameSegments.map(function (_a) {
391
+ var _b = __read(_a, 2), start = _b[0], end = _b[1];
392
+ return renderer.lines([start, end]);
393
+ });
394
+ var textEntity = this.drawToleranceText(renderer, delay);
395
+ if (frameEntities.length > 0 && textEntity) {
396
+ return renderer.group(__spreadArray(__spreadArray([], __read(frameEntities), false), [textEntity], false));
397
+ }
398
+ if (frameEntities.length === 1) {
399
+ return frameEntities[0];
400
+ }
401
+ if (frameEntities.length > 1) {
402
+ return renderer.group(frameEntities);
403
+ }
404
+ return textEntity;
405
+ };
406
+ AcDbFcf.prototype.dxfOutFields = function (filer) {
407
+ _super.prototype.dxfOutFields.call(this, filer);
408
+ filer.writeSubclassMarker('AcDbFcf');
409
+ if (this._dimensionStyle) {
410
+ filer.writeString(3, this._dimensionStyle);
411
+ }
412
+ filer.writePoint3d(10, this._location);
413
+ filer.writeString(1, this._text);
414
+ if (!this._normal.equals(AcGeVector3d.Z_AXIS)) {
415
+ filer.writeVector3d(210, this._normal);
416
+ }
417
+ if (!this._direction.equals(AcGeVector3d.X_AXIS)) {
418
+ filer.writeVector3d(11, this._direction);
419
+ }
420
+ return this;
421
+ };
422
+ Object.defineProperty(AcDbFcf.prototype, "textHeight", {
423
+ /**
424
+ * Gets the rendered text height derived from the associated dimension style.
425
+ */
426
+ get: function () {
427
+ var _a, _b;
428
+ var dimStyle = this.resolveDimensionStyle();
429
+ var dimtxt = (_a = dimStyle === null || dimStyle === void 0 ? void 0 : dimStyle.dimtxt) !== null && _a !== void 0 ? _a : AcDbDimStyleTableRecord.DEFAULT_DIM_VALUES.dimtxt;
430
+ var dimscale = (_b = dimStyle === null || dimStyle === void 0 ? void 0 : dimStyle.dimscale) !== null && _b !== void 0 ? _b : AcDbDimStyleTableRecord.DEFAULT_DIM_VALUES.dimscale;
431
+ return dimtxt * dimscale;
432
+ },
433
+ enumerable: false,
434
+ configurable: true
435
+ });
436
+ AcDbFcf.prototype.drawToleranceText = function (renderer, delay) {
437
+ var _a;
438
+ var rows = this.parseToleranceFrame(this._text);
439
+ if (rows.length === 0) {
440
+ return undefined;
441
+ }
442
+ var layout = this.resolveFrameLayout(rows);
443
+ var textStyle = this.getTextStyle();
444
+ var entities = [];
445
+ for (var rowIndex = 0; rowIndex < rows.length; rowIndex++) {
446
+ var row = rows[rowIndex];
447
+ var cellOffset = layout.cellPadding;
448
+ var rowCenterY = -layout.rowHeight * rowIndex;
449
+ for (var columnIndex = 0; columnIndex < row.cells.length; columnIndex++) {
450
+ var cellText = row.cells[columnIndex];
451
+ var cellWidth = (_a = layout.columnWidths[columnIndex]) !== null && _a !== void 0 ? _a : this.textHeight;
452
+ if (cellText.trim()) {
453
+ var position = this.toFrameWcs(cellOffset + cellWidth / 2, rowCenterY);
454
+ var mtextData = {
455
+ text: cellText,
456
+ height: this.textHeight,
457
+ width: Infinity,
458
+ position: position,
459
+ directionVector: this._direction,
460
+ attachmentPoint: AcGiMTextAttachmentPoint.MiddleCenter,
461
+ drawingDirection: AcGiMTextFlowDirection.LEFT_TO_RIGHT
462
+ };
463
+ entities.push(renderer.mtext(mtextData, textStyle, delay));
464
+ }
465
+ cellOffset += cellWidth + layout.columnGap;
466
+ }
467
+ }
468
+ if (entities.length === 0) {
469
+ return undefined;
470
+ }
471
+ if (entities.length === 1) {
472
+ return entities[0];
473
+ }
474
+ return renderer.group(entities);
475
+ };
476
+ AcDbFcf.prototype.collectFrameLineSegments = function () {
477
+ var e_2, _a;
478
+ var rows = this.parseToleranceFrame(this._text);
479
+ var layout = this.resolveFrameLayout(rows);
480
+ var width = layout.width, rowHeight = layout.rowHeight, rowCount = layout.rowCount, columnDivisions = layout.columnDivisions;
481
+ if (width <= 0 || rowHeight <= 0 || rowCount <= 0) {
482
+ return [];
483
+ }
484
+ var frameTop = rowHeight / 2;
485
+ var frameBottom = frameTop - rowHeight * rowCount;
486
+ var segments = [];
487
+ var pushSegment = function (start, end) {
488
+ segments.push([start, end]);
489
+ };
490
+ pushSegment(this.toFrameWcs(0, frameTop), this.toFrameWcs(width, frameTop));
491
+ pushSegment(this.toFrameWcs(width, frameTop), this.toFrameWcs(width, frameBottom));
492
+ pushSegment(this.toFrameWcs(width, frameBottom), this.toFrameWcs(0, frameBottom));
493
+ pushSegment(this.toFrameWcs(0, frameBottom), this.toFrameWcs(0, frameTop));
494
+ try {
495
+ for (var columnDivisions_1 = __values(columnDivisions), columnDivisions_1_1 = columnDivisions_1.next(); !columnDivisions_1_1.done; columnDivisions_1_1 = columnDivisions_1.next()) {
496
+ var division = columnDivisions_1_1.value;
497
+ pushSegment(this.toFrameWcs(division, frameTop), this.toFrameWcs(division, frameBottom));
498
+ }
499
+ }
500
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
501
+ finally {
502
+ try {
503
+ if (columnDivisions_1_1 && !columnDivisions_1_1.done && (_a = columnDivisions_1.return)) _a.call(columnDivisions_1);
504
+ }
505
+ finally { if (e_2) throw e_2.error; }
506
+ }
507
+ for (var rowIndex = 1; rowIndex < rows.length; rowIndex++) {
508
+ var y = frameTop - rowHeight * rowIndex;
509
+ pushSegment(this.toFrameWcs(0, y), this.toFrameWcs(width, y));
510
+ }
511
+ return segments;
512
+ };
513
+ AcDbFcf.prototype.toFrameWcs = function (localX, localY) {
514
+ var basis = this.resolveLocalBasis();
515
+ return this._location
516
+ .clone()
517
+ .addScaledVector(basis.xAxis, localX)
518
+ .addScaledVector(basis.yAxis, localY);
519
+ };
520
+ AcDbFcf.prototype.resolveFrameLayout = function (rows) {
521
+ var e_3, _a;
522
+ var _b, _c;
523
+ var frameRows = rows !== null && rows !== void 0 ? rows : this.parseToleranceFrame(this._text);
524
+ var textHeight = this.textHeight;
525
+ var rowHeight = textHeight * 2;
526
+ var cellPadding = textHeight / 2;
527
+ var columnGap = textHeight;
528
+ if (textHeight <= 0 || frameRows.length === 0) {
529
+ return {
530
+ width: 0,
531
+ totalHeight: 0,
532
+ rowHeight: 0,
533
+ columnWidths: [],
534
+ columnDivisions: [],
535
+ rowCount: 0,
536
+ cellPadding: 0,
537
+ columnGap: 0
538
+ };
539
+ }
540
+ var columnCount = Math.max.apply(Math, __spreadArray(__spreadArray([], __read(frameRows.map(function (row) { return row.cells.length; })), false), [0], false));
541
+ var columnWidths = [];
542
+ for (var columnIndex = 0; columnIndex < columnCount; columnIndex++) {
543
+ var maxWidth = textHeight;
544
+ try {
545
+ for (var frameRows_1 = (e_3 = void 0, __values(frameRows)), frameRows_1_1 = frameRows_1.next(); !frameRows_1_1.done; frameRows_1_1 = frameRows_1.next()) {
546
+ var row = frameRows_1_1.value;
547
+ var cell = (_b = row.cells[columnIndex]) !== null && _b !== void 0 ? _b : '';
548
+ if (!cell.trim()) {
549
+ continue;
550
+ }
551
+ var plainText = acdbStripMTextControlCodes(cell).trim();
552
+ var estimatedWidth = acdbEstimatePlainTextWidth(plainText, textHeight);
553
+ maxWidth = Math.max(maxWidth, estimatedWidth);
554
+ }
555
+ }
556
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
557
+ finally {
558
+ try {
559
+ if (frameRows_1_1 && !frameRows_1_1.done && (_a = frameRows_1.return)) _a.call(frameRows_1);
560
+ }
561
+ finally { if (e_3) throw e_3.error; }
562
+ }
563
+ columnWidths.push(maxWidth);
564
+ }
565
+ var columnDivisions = [0];
566
+ var cursorX = cellPadding;
567
+ for (var columnIndex = 0; columnIndex < columnWidths.length; columnIndex++) {
568
+ cursorX += columnWidths[columnIndex];
569
+ cursorX += columnGap;
570
+ columnDivisions.push(cursorX - cellPadding);
571
+ }
572
+ var width = (_c = columnDivisions[columnDivisions.length - 1]) !== null && _c !== void 0 ? _c : 0;
573
+ return {
574
+ width: width,
575
+ totalHeight: rowHeight * frameRows.length,
576
+ rowHeight: rowHeight,
577
+ columnWidths: columnWidths,
578
+ columnDivisions: columnDivisions,
579
+ rowCount: frameRows.length,
580
+ cellPadding: cellPadding,
581
+ columnGap: columnGap
582
+ };
583
+ };
584
+ AcDbFcf.prototype.parseToleranceFrame = function (text) {
585
+ var _this = this;
586
+ if (!text) {
587
+ return [];
588
+ }
589
+ var rowTexts = this.splitToleranceRows(text);
590
+ if (rowTexts.length === 0) {
591
+ return [];
592
+ }
593
+ if (!text.includes('%%v')) {
594
+ return rowTexts.map(function (row) { return ({
595
+ cells: _this.parsePipeSeparatedCells(row)
596
+ }); });
597
+ }
598
+ var slotRows = rowTexts.map(function (row) {
599
+ var slots = _this.splitToleranceTokens(row, '%%v');
600
+ var padded = slots.slice(0, TOLERANCE_SLOT_COUNT);
601
+ while (padded.length < TOLERANCE_SLOT_COUNT) {
602
+ padded.push('');
603
+ }
604
+ return padded;
605
+ });
606
+ var columnIndices = [0, 1];
607
+ if (slotRows.some(function (slots) { var _a; return (_a = slots[2]) === null || _a === void 0 ? void 0 : _a.trim(); })) {
608
+ columnIndices.push(2);
609
+ }
610
+ var _loop_1 = function (slotIndex) {
611
+ if (slotRows.some(function (slots) { var _a; return (_a = slots[slotIndex]) === null || _a === void 0 ? void 0 : _a.trim(); })) {
612
+ columnIndices.push(slotIndex);
613
+ }
614
+ };
615
+ for (var slotIndex = 3; slotIndex < TOLERANCE_SLOT_COUNT; slotIndex++) {
616
+ _loop_1(slotIndex);
617
+ }
618
+ return slotRows.map(function (slots) { return ({
619
+ cells: columnIndices.map(function (index) { var _a; return (_a = slots[index]) !== null && _a !== void 0 ? _a : ''; })
620
+ }); });
621
+ };
622
+ AcDbFcf.prototype.splitToleranceRows = function (text) {
623
+ var normalized = text.replace(/\^J/g, '\n');
624
+ return normalized
625
+ .split(/\r\n|\r|\n|\\P/i)
626
+ .map(function (row) { return row.trim(); })
627
+ .filter(function (row) { return row.length > 0; });
628
+ };
629
+ AcDbFcf.prototype.splitToleranceTokens = function (text, delimiter) {
630
+ if (!text) {
631
+ return [];
632
+ }
633
+ var tokens = [];
634
+ var current = '';
635
+ var braceDepth = 0;
636
+ for (var index = 0; index < text.length;) {
637
+ if (text.startsWith(delimiter, index) && braceDepth === 0) {
638
+ tokens.push(current);
639
+ current = '';
640
+ index += delimiter.length;
641
+ continue;
642
+ }
643
+ var char = text[index];
644
+ if (char === '{') {
645
+ braceDepth++;
646
+ }
647
+ else if (char === '}') {
648
+ braceDepth = Math.max(0, braceDepth - 1);
649
+ }
650
+ current += char;
651
+ index++;
652
+ }
653
+ tokens.push(current);
654
+ return tokens;
655
+ };
656
+ AcDbFcf.prototype.parsePipeSeparatedCells = function (text) {
657
+ if (!text) {
658
+ return [];
659
+ }
660
+ var cells = this.splitToleranceTokens(text, '|');
661
+ return cells.filter(function (cell) { return cell.length > 0; });
662
+ };
663
+ AcDbFcf.prototype.resolveLocalBasis = function () {
664
+ var zAxis = this._normal.clone();
665
+ if (zAxis.lengthSq() === 0) {
666
+ zAxis.set(0, 0, 1);
667
+ }
668
+ else {
669
+ zAxis.normalize();
670
+ }
671
+ var xAxis = this._direction.clone();
672
+ if (xAxis.lengthSq() === 0) {
673
+ xAxis.set(1, 0, 0);
674
+ }
675
+ else {
676
+ xAxis.normalize();
677
+ }
678
+ var yAxis = new AcGeVector3d().crossVectors(zAxis, xAxis);
679
+ if (yAxis.lengthSq() === 0) {
680
+ xAxis = AcGeVector3d.X_AXIS.clone();
681
+ yAxis = new AcGeVector3d().crossVectors(zAxis, xAxis);
682
+ }
683
+ yAxis.normalize();
684
+ xAxis = new AcGeVector3d().crossVectors(yAxis, zAxis).normalize();
685
+ return { xAxis: xAxis, yAxis: yAxis, zAxis: zAxis };
686
+ };
687
+ AcDbFcf.prototype.resolveDimensionStyle = function () {
688
+ var styleName = this._dimensionStyle.trim();
689
+ var database = this.tryGetDatabase();
690
+ if (!styleName || !database) {
691
+ return undefined;
692
+ }
693
+ return database.tables.dimStyleTable.getAt(styleName);
694
+ };
695
+ AcDbFcf.prototype.tryGetDatabase = function () {
696
+ try {
697
+ return this.database;
698
+ }
699
+ catch (_a) {
700
+ return undefined;
701
+ }
702
+ };
703
+ AcDbFcf.prototype.getTextStyle = function () {
704
+ var _a, _b;
705
+ var dimStyle = this.resolveDimensionStyle();
706
+ var styleName = (_b = (_a = dimStyle === null || dimStyle === void 0 ? void 0 : dimStyle.dimtxsty) !== null && _a !== void 0 ? _a : AcDbDimStyleTableRecord.DEFAULT_DIM_VALUES.dimtxsty) !== null && _b !== void 0 ? _b : 'Standard';
707
+ var style = this.database.tables.textStyleTable.resolveAt(styleName);
708
+ if (!style) {
709
+ throw new Error('No valid text style found in text style table.');
710
+ }
711
+ return style.textStyle;
712
+ };
713
+ /** The entity type name */
714
+ AcDbFcf.typeName = 'Fcf';
715
+ return AcDbFcf;
716
+ }(AcDbEntity));
717
+ export { AcDbFcf };
718
+ //# sourceMappingURL=AcDbFcf.js.map