@mlightcad/data-model 1.7.27 → 1.7.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +224 -224
- package/dist/data-model.cjs +4 -3
- package/dist/data-model.js +6601 -3480
- package/dist/dxf-parser-worker.js +1023 -740
- package/lib/converter/AcDbDxfConverter.d.ts +1 -0
- package/lib/converter/AcDbDxfConverter.d.ts.map +1 -1
- package/lib/converter/AcDbDxfConverter.js +48 -1
- package/lib/converter/AcDbDxfConverter.js.map +1 -1
- package/lib/converter/AcDbEntitiyConverter.d.ts +12 -0
- package/lib/converter/AcDbEntitiyConverter.d.ts.map +1 -1
- package/lib/converter/AcDbEntitiyConverter.js +528 -3
- package/lib/converter/AcDbEntitiyConverter.js.map +1 -1
- package/lib/converter/AcDbObjectConverter.d.ts +10 -3
- package/lib/converter/AcDbObjectConverter.d.ts.map +1 -1
- package/lib/converter/AcDbObjectConverter.js +173 -1
- package/lib/converter/AcDbObjectConverter.js.map +1 -1
- package/lib/converter/AcDbRegenerator.d.ts.map +1 -1
- package/lib/converter/AcDbRegenerator.js +22 -4
- package/lib/converter/AcDbRegenerator.js.map +1 -1
- package/lib/database/AcDbBlockTableRecord.d.ts.map +1 -1
- package/lib/database/AcDbBlockTableRecord.js +1 -0
- package/lib/database/AcDbBlockTableRecord.js.map +1 -1
- package/lib/database/AcDbDatabase.d.ts +42 -0
- package/lib/database/AcDbDatabase.d.ts.map +1 -1
- package/lib/database/AcDbDatabase.js +250 -32
- package/lib/database/AcDbDatabase.js.map +1 -1
- package/lib/database/AcDbSysVarManager.d.ts.map +1 -1
- package/lib/database/AcDbSysVarManager.js +28 -1
- package/lib/database/AcDbSysVarManager.js.map +1 -1
- package/lib/database/AcDbSystemVariables.d.ts +7 -1
- package/lib/database/AcDbSystemVariables.d.ts.map +1 -1
- package/lib/database/AcDbSystemVariables.js +6 -0
- package/lib/database/AcDbSystemVariables.js.map +1 -1
- package/lib/entity/AcDbLeader.d.ts +32 -3
- package/lib/entity/AcDbLeader.d.ts.map +1 -1
- package/lib/entity/AcDbLeader.js +140 -10
- package/lib/entity/AcDbLeader.js.map +1 -1
- package/lib/entity/AcDbMLeader.d.ts +1092 -0
- package/lib/entity/AcDbMLeader.d.ts.map +1 -0
- package/lib/entity/AcDbMLeader.js +2553 -0
- package/lib/entity/AcDbMLeader.js.map +1 -0
- package/lib/entity/AcDbMLine.d.ts +670 -0
- package/lib/entity/AcDbMLine.d.ts.map +1 -0
- package/lib/entity/AcDbMLine.js +1510 -0
- package/lib/entity/AcDbMLine.js.map +1 -0
- package/lib/entity/dimension/AcDbDiametricDimension.d.ts +0 -33
- package/lib/entity/dimension/AcDbDiametricDimension.d.ts.map +1 -1
- package/lib/entity/dimension/AcDbDiametricDimension.js +0 -80
- package/lib/entity/dimension/AcDbDiametricDimension.js.map +1 -1
- package/lib/entity/dimension/AcDbDimension.d.ts +1 -9
- package/lib/entity/dimension/AcDbDimension.d.ts.map +1 -1
- package/lib/entity/dimension/AcDbDimension.js +0 -10
- package/lib/entity/dimension/AcDbDimension.js.map +1 -1
- package/lib/entity/dimension/AcDbRadialDimension.d.ts +0 -6
- package/lib/entity/dimension/AcDbRadialDimension.d.ts.map +1 -1
- package/lib/entity/dimension/AcDbRadialDimension.js +0 -8
- package/lib/entity/dimension/AcDbRadialDimension.js.map +1 -1
- package/lib/entity/index.d.ts +2 -0
- package/lib/entity/index.d.ts.map +1 -1
- package/lib/entity/index.js +2 -0
- package/lib/entity/index.js.map +1 -1
- package/lib/misc/AcDbConstants.d.ts +14 -0
- package/lib/misc/AcDbConstants.d.ts.map +1 -1
- package/lib/misc/AcDbConstants.js +14 -0
- package/lib/misc/AcDbConstants.js.map +1 -1
- package/lib/misc/AcDbMLeaderStyleColorCodec.d.ts +59 -0
- package/lib/misc/AcDbMLeaderStyleColorCodec.d.ts.map +1 -0
- package/lib/misc/AcDbMLeaderStyleColorCodec.js +101 -0
- package/lib/misc/AcDbMLeaderStyleColorCodec.js.map +1 -0
- package/lib/misc/index.d.ts +1 -0
- package/lib/misc/index.d.ts.map +1 -1
- package/lib/misc/index.js +1 -0
- package/lib/misc/index.js.map +1 -1
- package/lib/object/AcDbMLeaderStyle.d.ts +405 -0
- package/lib/object/AcDbMLeaderStyle.d.ts.map +1 -0
- package/lib/object/AcDbMLeaderStyle.js +1006 -0
- package/lib/object/AcDbMLeaderStyle.js.map +1 -0
- package/lib/object/AcDbMlineStyle.d.ts +58 -0
- package/lib/object/AcDbMlineStyle.d.ts.map +1 -0
- package/lib/object/AcDbMlineStyle.js +158 -0
- package/lib/object/AcDbMlineStyle.js.map +1 -0
- package/lib/object/index.d.ts +2 -0
- package/lib/object/index.d.ts.map +1 -1
- package/lib/object/index.js +2 -0
- package/lib/object/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,1510 @@
|
|
|
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 __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
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
|
+
var __values = (this && this.__values) || function(o) {
|
|
53
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
54
|
+
if (m) return m.call(o);
|
|
55
|
+
if (o && typeof o.length === "number") return {
|
|
56
|
+
next: function () {
|
|
57
|
+
if (o && i >= o.length) o = void 0;
|
|
58
|
+
return { value: o && o[i++], done: !o };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
62
|
+
};
|
|
63
|
+
import { AcGeArea2d, AcGeBox3d, AcGeCircArc3d, AcGePoint3d, AcGePolyline2d, AcGeVector3d } from '@mlightcad/geometry-engine';
|
|
64
|
+
import { ByBlock, ByLayer, DEFAULT_LINE_TYPE, DEFAULT_MLINE_STYLE } from '../misc';
|
|
65
|
+
import { AcDbEntity } from './AcDbEntity';
|
|
66
|
+
/**
|
|
67
|
+
* Defines MLINE justification relative to the style element offsets.
|
|
68
|
+
*/
|
|
69
|
+
export var AcDbMLineJustification;
|
|
70
|
+
(function (AcDbMLineJustification) {
|
|
71
|
+
/**
|
|
72
|
+
* Places all style elements below or on the reference path.
|
|
73
|
+
*/
|
|
74
|
+
AcDbMLineJustification[AcDbMLineJustification["Top"] = 0] = "Top";
|
|
75
|
+
/**
|
|
76
|
+
* Centers style elements around the reference path.
|
|
77
|
+
*/
|
|
78
|
+
AcDbMLineJustification[AcDbMLineJustification["Zero"] = 1] = "Zero";
|
|
79
|
+
/**
|
|
80
|
+
* Places all style elements above or on the reference path.
|
|
81
|
+
*/
|
|
82
|
+
AcDbMLineJustification[AcDbMLineJustification["Bottom"] = 2] = "Bottom";
|
|
83
|
+
})(AcDbMLineJustification || (AcDbMLineJustification = {}));
|
|
84
|
+
/**
|
|
85
|
+
* Bit flags used by MLINE entities.
|
|
86
|
+
*/
|
|
87
|
+
export var AcDbMLineFlags;
|
|
88
|
+
(function (AcDbMLineFlags) {
|
|
89
|
+
/**
|
|
90
|
+
* Indicates the MLINE currently contains at least one segment vertex.
|
|
91
|
+
*/
|
|
92
|
+
AcDbMLineFlags[AcDbMLineFlags["HasVertex"] = 1] = "HasVertex";
|
|
93
|
+
/**
|
|
94
|
+
* Indicates the MLINE should be treated as a closed loop.
|
|
95
|
+
*/
|
|
96
|
+
AcDbMLineFlags[AcDbMLineFlags["Closed"] = 2] = "Closed";
|
|
97
|
+
/**
|
|
98
|
+
* Suppresses cap geometry at the start of the MLINE.
|
|
99
|
+
*/
|
|
100
|
+
AcDbMLineFlags[AcDbMLineFlags["SuppressStartCaps"] = 4] = "SuppressStartCaps";
|
|
101
|
+
/**
|
|
102
|
+
* Suppresses cap geometry at the end of the MLINE.
|
|
103
|
+
*/
|
|
104
|
+
AcDbMLineFlags[AcDbMLineFlags["SuppressEndCaps"] = 8] = "SuppressEndCaps";
|
|
105
|
+
})(AcDbMLineFlags || (AcDbMLineFlags = {}));
|
|
106
|
+
/**
|
|
107
|
+
* Bit flags used by MLINESTYLE objects.
|
|
108
|
+
*/
|
|
109
|
+
var AcDbMLineStyleFlags;
|
|
110
|
+
(function (AcDbMLineStyleFlags) {
|
|
111
|
+
/**
|
|
112
|
+
* Enables fill rendering between the outer and inner style elements.
|
|
113
|
+
*/
|
|
114
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["FillOn"] = 1] = "FillOn";
|
|
115
|
+
/**
|
|
116
|
+
* Enables drawing miter connector lines at polyline joints.
|
|
117
|
+
*/
|
|
118
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["DisplayMiters"] = 2] = "DisplayMiters";
|
|
119
|
+
/**
|
|
120
|
+
* Enables square-line start cap.
|
|
121
|
+
*/
|
|
122
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["StartSquareCap"] = 16] = "StartSquareCap";
|
|
123
|
+
/**
|
|
124
|
+
* Enables inner-arc start cap pairs.
|
|
125
|
+
*/
|
|
126
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["StartInnerArcs"] = 32] = "StartInnerArcs";
|
|
127
|
+
/**
|
|
128
|
+
* Enables outer-arc start cap.
|
|
129
|
+
*/
|
|
130
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["StartRoundCap"] = 64] = "StartRoundCap";
|
|
131
|
+
/**
|
|
132
|
+
* Enables square-line end cap.
|
|
133
|
+
*/
|
|
134
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["EndSquareCap"] = 256] = "EndSquareCap";
|
|
135
|
+
/**
|
|
136
|
+
* Enables inner-arc end cap pairs.
|
|
137
|
+
*/
|
|
138
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["EndInnerArcs"] = 512] = "EndInnerArcs";
|
|
139
|
+
/**
|
|
140
|
+
* Enables outer-arc end cap.
|
|
141
|
+
*/
|
|
142
|
+
AcDbMLineStyleFlags[AcDbMLineStyleFlags["EndRoundCap"] = 1024] = "EndRoundCap";
|
|
143
|
+
})(AcDbMLineStyleFlags || (AcDbMLineStyleFlags = {}));
|
|
144
|
+
/**
|
|
145
|
+
* Represents the AutoCAD MLINE entity.
|
|
146
|
+
*/
|
|
147
|
+
var AcDbMLine = /** @class */ (function (_super) {
|
|
148
|
+
__extends(AcDbMLine, _super);
|
|
149
|
+
/**
|
|
150
|
+
* Creates a new MLINE entity initialized with AutoCAD-compatible defaults.
|
|
151
|
+
*/
|
|
152
|
+
function AcDbMLine() {
|
|
153
|
+
var _this = _super.call(this) || this;
|
|
154
|
+
_this._styleName = '';
|
|
155
|
+
_this._styleObjectHandle = '';
|
|
156
|
+
_this._scale = 1;
|
|
157
|
+
_this._justification = AcDbMLineJustification.Zero;
|
|
158
|
+
_this._flags = 0;
|
|
159
|
+
_this._styleCount = 0;
|
|
160
|
+
_this._startPosition = new AcGePoint3d();
|
|
161
|
+
_this._normal = new AcGeVector3d(0, 0, 1);
|
|
162
|
+
_this._segments = [];
|
|
163
|
+
return _this;
|
|
164
|
+
}
|
|
165
|
+
Object.defineProperty(AcDbMLine.prototype, "dxfTypeName", {
|
|
166
|
+
/**
|
|
167
|
+
* DXF entity type token written to or read from drawing files.
|
|
168
|
+
*/
|
|
169
|
+
get: function () {
|
|
170
|
+
return 'MLINE';
|
|
171
|
+
},
|
|
172
|
+
enumerable: false,
|
|
173
|
+
configurable: true
|
|
174
|
+
});
|
|
175
|
+
Object.defineProperty(AcDbMLine.prototype, "styleName", {
|
|
176
|
+
/**
|
|
177
|
+
* Gets the style name used to resolve the MLINE style object.
|
|
178
|
+
*
|
|
179
|
+
* @returns Current style name.
|
|
180
|
+
*/
|
|
181
|
+
get: function () {
|
|
182
|
+
return this._styleName || this.getDefaultStyleName();
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* Sets the style name used to resolve the MLINE style object.
|
|
186
|
+
*
|
|
187
|
+
* @param value New style name.
|
|
188
|
+
*/
|
|
189
|
+
set: function (value) {
|
|
190
|
+
this._styleName = value;
|
|
191
|
+
},
|
|
192
|
+
enumerable: false,
|
|
193
|
+
configurable: true
|
|
194
|
+
});
|
|
195
|
+
Object.defineProperty(AcDbMLine.prototype, "styleObjectHandle", {
|
|
196
|
+
/**
|
|
197
|
+
* Gets the handle of the referenced MLINESTYLE object.
|
|
198
|
+
*
|
|
199
|
+
* @returns Style object handle.
|
|
200
|
+
*/
|
|
201
|
+
get: function () {
|
|
202
|
+
return this._styleObjectHandle;
|
|
203
|
+
},
|
|
204
|
+
/**
|
|
205
|
+
* Sets the handle of the referenced MLINESTYLE object.
|
|
206
|
+
*
|
|
207
|
+
* @param value Style object handle.
|
|
208
|
+
*/
|
|
209
|
+
set: function (value) {
|
|
210
|
+
this._styleObjectHandle = value;
|
|
211
|
+
},
|
|
212
|
+
enumerable: false,
|
|
213
|
+
configurable: true
|
|
214
|
+
});
|
|
215
|
+
Object.defineProperty(AcDbMLine.prototype, "scale", {
|
|
216
|
+
/**
|
|
217
|
+
* Gets the global scale factor applied to style offsets.
|
|
218
|
+
*
|
|
219
|
+
* @returns MLINE scale.
|
|
220
|
+
*/
|
|
221
|
+
get: function () {
|
|
222
|
+
return this._scale;
|
|
223
|
+
},
|
|
224
|
+
/**
|
|
225
|
+
* Sets the global scale factor applied to style offsets.
|
|
226
|
+
*
|
|
227
|
+
* @param value MLINE scale.
|
|
228
|
+
*/
|
|
229
|
+
set: function (value) {
|
|
230
|
+
this._scale = value;
|
|
231
|
+
},
|
|
232
|
+
enumerable: false,
|
|
233
|
+
configurable: true
|
|
234
|
+
});
|
|
235
|
+
Object.defineProperty(AcDbMLine.prototype, "justification", {
|
|
236
|
+
/**
|
|
237
|
+
* Gets the current justification mode.
|
|
238
|
+
*
|
|
239
|
+
* @returns Justification enum value.
|
|
240
|
+
*/
|
|
241
|
+
get: function () {
|
|
242
|
+
return this._justification;
|
|
243
|
+
},
|
|
244
|
+
/**
|
|
245
|
+
* Sets the current justification mode.
|
|
246
|
+
*
|
|
247
|
+
* @param value Justification enum value.
|
|
248
|
+
*/
|
|
249
|
+
set: function (value) {
|
|
250
|
+
this._justification = value;
|
|
251
|
+
},
|
|
252
|
+
enumerable: false,
|
|
253
|
+
configurable: true
|
|
254
|
+
});
|
|
255
|
+
Object.defineProperty(AcDbMLine.prototype, "flags", {
|
|
256
|
+
/**
|
|
257
|
+
* Gets the raw MLINE bit flags.
|
|
258
|
+
*
|
|
259
|
+
* @returns Bitwise combination of {@link AcDbMLineFlags}.
|
|
260
|
+
*/
|
|
261
|
+
get: function () {
|
|
262
|
+
return this._flags;
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* Sets the raw MLINE bit flags.
|
|
266
|
+
*
|
|
267
|
+
* @param value Bitwise combination of {@link AcDbMLineFlags}.
|
|
268
|
+
*/
|
|
269
|
+
set: function (value) {
|
|
270
|
+
this._flags = value;
|
|
271
|
+
},
|
|
272
|
+
enumerable: false,
|
|
273
|
+
configurable: true
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperty(AcDbMLine.prototype, "styleCount", {
|
|
276
|
+
/**
|
|
277
|
+
* Gets the number of style elements expected by the entity.
|
|
278
|
+
*
|
|
279
|
+
* @returns Style element count.
|
|
280
|
+
*/
|
|
281
|
+
get: function () {
|
|
282
|
+
return this._styleCount;
|
|
283
|
+
},
|
|
284
|
+
/**
|
|
285
|
+
* Sets the style element count.
|
|
286
|
+
* Negative values are clamped to `0`.
|
|
287
|
+
*
|
|
288
|
+
* @param value Requested style element count.
|
|
289
|
+
*/
|
|
290
|
+
set: function (value) {
|
|
291
|
+
this._styleCount = Math.max(0, value);
|
|
292
|
+
},
|
|
293
|
+
enumerable: false,
|
|
294
|
+
configurable: true
|
|
295
|
+
});
|
|
296
|
+
Object.defineProperty(AcDbMLine.prototype, "startPosition", {
|
|
297
|
+
/**
|
|
298
|
+
* Gets the MLINE start point in world coordinates.
|
|
299
|
+
*
|
|
300
|
+
* @returns Start point instance.
|
|
301
|
+
*/
|
|
302
|
+
get: function () {
|
|
303
|
+
return this._startPosition;
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* Sets the MLINE start point in world coordinates.
|
|
307
|
+
*
|
|
308
|
+
* @param value New start point.
|
|
309
|
+
*/
|
|
310
|
+
set: function (value) {
|
|
311
|
+
this._startPosition.copy(value);
|
|
312
|
+
},
|
|
313
|
+
enumerable: false,
|
|
314
|
+
configurable: true
|
|
315
|
+
});
|
|
316
|
+
Object.defineProperty(AcDbMLine.prototype, "normal", {
|
|
317
|
+
/**
|
|
318
|
+
* Gets the MLINE plane normal.
|
|
319
|
+
*
|
|
320
|
+
* @returns Normal vector instance.
|
|
321
|
+
*/
|
|
322
|
+
get: function () {
|
|
323
|
+
return this._normal;
|
|
324
|
+
},
|
|
325
|
+
/**
|
|
326
|
+
* Sets the MLINE plane normal.
|
|
327
|
+
*
|
|
328
|
+
* @param value New normal vector.
|
|
329
|
+
*/
|
|
330
|
+
set: function (value) {
|
|
331
|
+
this._normal.copy(value);
|
|
332
|
+
},
|
|
333
|
+
enumerable: false,
|
|
334
|
+
configurable: true
|
|
335
|
+
});
|
|
336
|
+
Object.defineProperty(AcDbMLine.prototype, "segments", {
|
|
337
|
+
/**
|
|
338
|
+
* Gets a deep-cloned snapshot of all segments.
|
|
339
|
+
* Mutating the returned array or objects will not affect internal state.
|
|
340
|
+
*
|
|
341
|
+
* @returns Cloned segment collection.
|
|
342
|
+
*/
|
|
343
|
+
get: function () {
|
|
344
|
+
var _this = this;
|
|
345
|
+
return this._segments.map(function (segment) { return _this.cloneSegment(segment); });
|
|
346
|
+
},
|
|
347
|
+
/**
|
|
348
|
+
* Replaces all segments using normalized internal copies.
|
|
349
|
+
* Also updates the internal `HasVertex` flag.
|
|
350
|
+
*
|
|
351
|
+
* @param value Segment list to normalize and store.
|
|
352
|
+
*/
|
|
353
|
+
set: function (value) {
|
|
354
|
+
var _this = this;
|
|
355
|
+
this._segments = value.map(function (segment) { return _this.createSegment(segment); });
|
|
356
|
+
this.updateHasVertexFlag();
|
|
357
|
+
},
|
|
358
|
+
enumerable: false,
|
|
359
|
+
configurable: true
|
|
360
|
+
});
|
|
361
|
+
Object.defineProperty(AcDbMLine.prototype, "vertexCount", {
|
|
362
|
+
/**
|
|
363
|
+
* Gets the number of stored segment vertices.
|
|
364
|
+
*
|
|
365
|
+
* @returns Vertex count.
|
|
366
|
+
*/
|
|
367
|
+
get: function () {
|
|
368
|
+
return this._segments.length;
|
|
369
|
+
},
|
|
370
|
+
enumerable: false,
|
|
371
|
+
configurable: true
|
|
372
|
+
});
|
|
373
|
+
Object.defineProperty(AcDbMLine.prototype, "closed", {
|
|
374
|
+
/**
|
|
375
|
+
* Indicates whether the MLINE is closed.
|
|
376
|
+
*
|
|
377
|
+
* @returns `true` when the `Closed` flag is set.
|
|
378
|
+
*/
|
|
379
|
+
get: function () {
|
|
380
|
+
return (this._flags & AcDbMLineFlags.Closed) !== 0;
|
|
381
|
+
},
|
|
382
|
+
/**
|
|
383
|
+
* Enables or disables closed-loop behavior.
|
|
384
|
+
*
|
|
385
|
+
* @param value `true` to close the path, otherwise `false`.
|
|
386
|
+
*/
|
|
387
|
+
set: function (value) {
|
|
388
|
+
this.setFlag(AcDbMLineFlags.Closed, value);
|
|
389
|
+
},
|
|
390
|
+
enumerable: false,
|
|
391
|
+
configurable: true
|
|
392
|
+
});
|
|
393
|
+
Object.defineProperty(AcDbMLine.prototype, "suppressStartCaps", {
|
|
394
|
+
/**
|
|
395
|
+
* Indicates whether start caps are suppressed during rendering.
|
|
396
|
+
*
|
|
397
|
+
* @returns `true` when the `SuppressStartCaps` flag is set.
|
|
398
|
+
*/
|
|
399
|
+
get: function () {
|
|
400
|
+
return (this._flags & AcDbMLineFlags.SuppressStartCaps) !== 0;
|
|
401
|
+
},
|
|
402
|
+
/**
|
|
403
|
+
* Enables or disables start cap suppression.
|
|
404
|
+
*
|
|
405
|
+
* @param value `true` to suppress start caps.
|
|
406
|
+
*/
|
|
407
|
+
set: function (value) {
|
|
408
|
+
this.setFlag(AcDbMLineFlags.SuppressStartCaps, value);
|
|
409
|
+
},
|
|
410
|
+
enumerable: false,
|
|
411
|
+
configurable: true
|
|
412
|
+
});
|
|
413
|
+
Object.defineProperty(AcDbMLine.prototype, "suppressEndCaps", {
|
|
414
|
+
/**
|
|
415
|
+
* Indicates whether end caps are suppressed during rendering.
|
|
416
|
+
*
|
|
417
|
+
* @returns `true` when the `SuppressEndCaps` flag is set.
|
|
418
|
+
*/
|
|
419
|
+
get: function () {
|
|
420
|
+
return (this._flags & AcDbMLineFlags.SuppressEndCaps) !== 0;
|
|
421
|
+
},
|
|
422
|
+
/**
|
|
423
|
+
* Enables or disables end cap suppression.
|
|
424
|
+
*
|
|
425
|
+
* @param value `true` to suppress end caps.
|
|
426
|
+
*/
|
|
427
|
+
set: function (value) {
|
|
428
|
+
this.setFlag(AcDbMLineFlags.SuppressEndCaps, value);
|
|
429
|
+
},
|
|
430
|
+
enumerable: false,
|
|
431
|
+
configurable: true
|
|
432
|
+
});
|
|
433
|
+
/**
|
|
434
|
+
* Appends one segment to the MLINE.
|
|
435
|
+
* The segment is normalized into internal geometry instances.
|
|
436
|
+
*
|
|
437
|
+
* @param segment Segment payload to append.
|
|
438
|
+
*/
|
|
439
|
+
AcDbMLine.prototype.appendSegment = function (segment) {
|
|
440
|
+
this._segments.push(this.createSegment(segment));
|
|
441
|
+
this.updateHasVertexFlag();
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Removes all segments and clears the `HasVertex` flag.
|
|
445
|
+
*/
|
|
446
|
+
AcDbMLine.prototype.clearSegments = function () {
|
|
447
|
+
this._segments = [];
|
|
448
|
+
this.updateHasVertexFlag();
|
|
449
|
+
};
|
|
450
|
+
Object.defineProperty(AcDbMLine.prototype, "geometricExtents", {
|
|
451
|
+
/**
|
|
452
|
+
* Computes a bounding box from renderable MLINE geometry.
|
|
453
|
+
*
|
|
454
|
+
* @returns Axis-aligned 3D extents box.
|
|
455
|
+
*/
|
|
456
|
+
get: function () {
|
|
457
|
+
var points = this.collectGeometryPoints();
|
|
458
|
+
var box = new AcGeBox3d();
|
|
459
|
+
return box.setFromPoints(points);
|
|
460
|
+
},
|
|
461
|
+
enumerable: false,
|
|
462
|
+
configurable: true
|
|
463
|
+
});
|
|
464
|
+
/**
|
|
465
|
+
* Applies a transformation matrix to the full MLINE geometry.
|
|
466
|
+
* Points are transformed directly, while vectors are transformed without
|
|
467
|
+
* introducing translation components.
|
|
468
|
+
*
|
|
469
|
+
* @param matrix Matrix to apply.
|
|
470
|
+
* @returns The same entity instance for chaining.
|
|
471
|
+
*/
|
|
472
|
+
AcDbMLine.prototype.transformBy = function (matrix) {
|
|
473
|
+
var _this = this;
|
|
474
|
+
this._startPosition.applyMatrix4(matrix);
|
|
475
|
+
this._segments.forEach(function (segment) {
|
|
476
|
+
segment.position.applyMatrix4(matrix);
|
|
477
|
+
_this.transformVector(segment.direction, matrix);
|
|
478
|
+
_this.transformVector(segment.miterDirection, matrix);
|
|
479
|
+
});
|
|
480
|
+
this.transformVector(this._normal, matrix);
|
|
481
|
+
return this;
|
|
482
|
+
};
|
|
483
|
+
Object.defineProperty(AcDbMLine.prototype, "properties", {
|
|
484
|
+
/**
|
|
485
|
+
* Exposes editable property metadata for UI/property panels.
|
|
486
|
+
*
|
|
487
|
+
* @returns Entity property definition grouped by category.
|
|
488
|
+
*/
|
|
489
|
+
get: function () {
|
|
490
|
+
var _this = this;
|
|
491
|
+
return {
|
|
492
|
+
type: this.type,
|
|
493
|
+
groups: [
|
|
494
|
+
this.getGeneralProperties(),
|
|
495
|
+
{
|
|
496
|
+
groupName: 'mline',
|
|
497
|
+
properties: [
|
|
498
|
+
{
|
|
499
|
+
name: 'styleName',
|
|
500
|
+
type: 'string',
|
|
501
|
+
editable: true,
|
|
502
|
+
accessor: {
|
|
503
|
+
get: function () { return _this.styleName; },
|
|
504
|
+
set: function (value) {
|
|
505
|
+
_this.styleName = value;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: 'scale',
|
|
511
|
+
type: 'float',
|
|
512
|
+
editable: true,
|
|
513
|
+
accessor: {
|
|
514
|
+
get: function () { return _this.scale; },
|
|
515
|
+
set: function (value) {
|
|
516
|
+
_this.scale = value;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: 'justification',
|
|
522
|
+
type: 'int',
|
|
523
|
+
editable: true,
|
|
524
|
+
accessor: {
|
|
525
|
+
get: function () { return _this.justification; },
|
|
526
|
+
set: function (value) {
|
|
527
|
+
_this.justification = value;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: 'closed',
|
|
533
|
+
type: 'boolean',
|
|
534
|
+
editable: true,
|
|
535
|
+
accessor: {
|
|
536
|
+
get: function () { return _this.closed; },
|
|
537
|
+
set: function (value) {
|
|
538
|
+
_this.closed = value;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
name: 'vertexCount',
|
|
544
|
+
type: 'int',
|
|
545
|
+
editable: false,
|
|
546
|
+
accessor: {
|
|
547
|
+
get: function () { return _this.vertexCount; }
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
]
|
|
551
|
+
}
|
|
552
|
+
]
|
|
553
|
+
};
|
|
554
|
+
},
|
|
555
|
+
enumerable: false,
|
|
556
|
+
configurable: true
|
|
557
|
+
});
|
|
558
|
+
/**
|
|
559
|
+
* Renders this MLINE into one or more graphic interface entities.
|
|
560
|
+
* It draws optional fill first and then style element lines.
|
|
561
|
+
*
|
|
562
|
+
* @param renderer Active graphics renderer.
|
|
563
|
+
* @returns A single entity, an entity group, or `undefined` when nothing is drawable.
|
|
564
|
+
*/
|
|
565
|
+
AcDbMLine.prototype.subWorldDraw = function (renderer) {
|
|
566
|
+
if (this._segments.length === 0)
|
|
567
|
+
return undefined;
|
|
568
|
+
var entities = [];
|
|
569
|
+
var mlineStyle = this.getMLineStyle();
|
|
570
|
+
var elementCount = this.getRenderableElementCount(mlineStyle);
|
|
571
|
+
var traits = renderer.subEntityTraits;
|
|
572
|
+
var originalColor = traits.color;
|
|
573
|
+
var originalRgbColor = traits.rgbColor;
|
|
574
|
+
var originalLineType = traits.lineType;
|
|
575
|
+
var originalFillType = traits.fillType;
|
|
576
|
+
var originalDrawOrder = traits.drawOrder;
|
|
577
|
+
var fillArea = this.createFillArea(mlineStyle, elementCount);
|
|
578
|
+
if (fillArea) {
|
|
579
|
+
traits.color = originalColor;
|
|
580
|
+
traits.rgbColor = originalRgbColor;
|
|
581
|
+
this.applyFillTraits(mlineStyle, traits);
|
|
582
|
+
traits.fillType = {
|
|
583
|
+
solidFill: true,
|
|
584
|
+
patternAngle: 0,
|
|
585
|
+
definitionLines: []
|
|
586
|
+
};
|
|
587
|
+
traits.drawOrder = -1;
|
|
588
|
+
entities.push(renderer.area(fillArea));
|
|
589
|
+
traits.fillType = originalFillType;
|
|
590
|
+
traits.drawOrder = originalDrawOrder;
|
|
591
|
+
}
|
|
592
|
+
if (elementCount <= 0) {
|
|
593
|
+
var reference = this.getReferencePath();
|
|
594
|
+
if (reference.length >= 2)
|
|
595
|
+
entities.push(renderer.lines(reference));
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
for (var elementIndex = 0; elementIndex < elementCount; elementIndex++) {
|
|
599
|
+
traits.color = originalColor;
|
|
600
|
+
traits.rgbColor = originalRgbColor;
|
|
601
|
+
traits.lineType = originalLineType;
|
|
602
|
+
this.applyStyleElementTraits(mlineStyle, elementIndex, traits);
|
|
603
|
+
var points = this.getElementPath(elementIndex, mlineStyle);
|
|
604
|
+
if (points.length >= 2) {
|
|
605
|
+
entities.push(renderer.lines(points));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
this.appendStyleDrivenJointAndCapEntities(renderer, entities, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType);
|
|
609
|
+
}
|
|
610
|
+
traits.color = originalColor;
|
|
611
|
+
traits.rgbColor = originalRgbColor;
|
|
612
|
+
traits.lineType = originalLineType;
|
|
613
|
+
traits.fillType = originalFillType;
|
|
614
|
+
traits.drawOrder = originalDrawOrder;
|
|
615
|
+
if (entities.length === 0)
|
|
616
|
+
return undefined;
|
|
617
|
+
return entities.length === 1 ? entities[0] : renderer.group(entities);
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Serializes MLINE-specific fields to the DXF filer.
|
|
621
|
+
*
|
|
622
|
+
* @param filer DXF writer context.
|
|
623
|
+
* @returns The current entity instance.
|
|
624
|
+
*/
|
|
625
|
+
AcDbMLine.prototype.dxfOutFields = function (filer) {
|
|
626
|
+
_super.prototype.dxfOutFields.call(this, filer);
|
|
627
|
+
filer.writeSubclassMarker('AcDbMline');
|
|
628
|
+
filer.writeString(2, this.styleName);
|
|
629
|
+
filer.writeHandle(340, this._styleObjectHandle);
|
|
630
|
+
filer.writeDouble(40, this._scale);
|
|
631
|
+
filer.writeInt16(70, this._justification);
|
|
632
|
+
filer.writeInt16(71, this._flags);
|
|
633
|
+
filer.writeInt16(72, this.vertexCount);
|
|
634
|
+
filer.writeInt16(73, this._styleCount);
|
|
635
|
+
filer.writePoint3d(10, this._startPosition);
|
|
636
|
+
filer.writeVector3d(210, this._normal);
|
|
637
|
+
this._segments.forEach(function (segment) {
|
|
638
|
+
filer.writePoint3d(11, segment.position);
|
|
639
|
+
filer.writeVector3d(12, segment.direction);
|
|
640
|
+
filer.writeVector3d(13, segment.miterDirection);
|
|
641
|
+
segment.elements.forEach(function (element) {
|
|
642
|
+
filer.writeInt16(74, element.parameterCount);
|
|
643
|
+
element.parameters.forEach(function (parameter) {
|
|
644
|
+
return filer.writeDouble(41, parameter);
|
|
645
|
+
});
|
|
646
|
+
filer.writeInt16(75, element.fillCount);
|
|
647
|
+
element.fillParameters.forEach(function (parameter) {
|
|
648
|
+
return filer.writeDouble(42, parameter);
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
return this;
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* Sets or clears a single MLINE bit flag.
|
|
656
|
+
*
|
|
657
|
+
* @param flag Flag bit to update.
|
|
658
|
+
* @param enabled Whether the flag should be set.
|
|
659
|
+
*/
|
|
660
|
+
AcDbMLine.prototype.setFlag = function (flag, enabled) {
|
|
661
|
+
if (enabled) {
|
|
662
|
+
this._flags |= flag;
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
this._flags &= ~flag;
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Synchronizes the `HasVertex` flag with current segment count.
|
|
670
|
+
*/
|
|
671
|
+
AcDbMLine.prototype.updateHasVertexFlag = function () {
|
|
672
|
+
this.setFlag(AcDbMLineFlags.HasVertex, this._segments.length > 0);
|
|
673
|
+
};
|
|
674
|
+
/**
|
|
675
|
+
* Normalizes segment-like input into internal segment storage.
|
|
676
|
+
*
|
|
677
|
+
* @param segment Segment-like payload.
|
|
678
|
+
* @returns Normalized segment.
|
|
679
|
+
*/
|
|
680
|
+
AcDbMLine.prototype.createSegment = function (segment) {
|
|
681
|
+
var _this = this;
|
|
682
|
+
var _a, _b;
|
|
683
|
+
return {
|
|
684
|
+
position: new AcGePoint3d().copy(segment.position),
|
|
685
|
+
direction: new AcGeVector3d().copy(segment.direction),
|
|
686
|
+
miterDirection: new AcGeVector3d().copy(segment.miterDirection),
|
|
687
|
+
elements: (_b = (_a = segment.elements) === null || _a === void 0 ? void 0 : _a.map(function (element) { return _this.createElement(element); })) !== null && _b !== void 0 ? _b : []
|
|
688
|
+
};
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* Normalizes element-like input and infers count fields when missing.
|
|
692
|
+
*
|
|
693
|
+
* @param element Element-like payload.
|
|
694
|
+
* @returns Normalized element.
|
|
695
|
+
*/
|
|
696
|
+
AcDbMLine.prototype.createElement = function (element) {
|
|
697
|
+
var _a, _b;
|
|
698
|
+
var parameters = element.parameters ? __spreadArray([], __read(element.parameters), false) : [];
|
|
699
|
+
var fillParameters = element.fillParameters
|
|
700
|
+
? __spreadArray([], __read(element.fillParameters), false) : [];
|
|
701
|
+
return {
|
|
702
|
+
parameterCount: (_a = element.parameterCount) !== null && _a !== void 0 ? _a : parameters.length,
|
|
703
|
+
parameters: parameters,
|
|
704
|
+
fillCount: (_b = element.fillCount) !== null && _b !== void 0 ? _b : fillParameters.length,
|
|
705
|
+
fillParameters: fillParameters
|
|
706
|
+
};
|
|
707
|
+
};
|
|
708
|
+
/**
|
|
709
|
+
* Produces a deep clone of one normalized segment.
|
|
710
|
+
*
|
|
711
|
+
* @param segment Source segment.
|
|
712
|
+
* @returns Deep-cloned segment.
|
|
713
|
+
*/
|
|
714
|
+
AcDbMLine.prototype.cloneSegment = function (segment) {
|
|
715
|
+
return {
|
|
716
|
+
position: segment.position.clone(),
|
|
717
|
+
direction: segment.direction.clone(),
|
|
718
|
+
miterDirection: segment.miterDirection.clone(),
|
|
719
|
+
elements: segment.elements.map(function (element) { return ({
|
|
720
|
+
parameterCount: element.parameterCount,
|
|
721
|
+
parameters: __spreadArray([], __read(element.parameters), false),
|
|
722
|
+
fillCount: element.fillCount,
|
|
723
|
+
fillParameters: __spreadArray([], __read(element.fillParameters), false)
|
|
724
|
+
}); })
|
|
725
|
+
};
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Collects points that represent all drawable geometry for extents calculation.
|
|
729
|
+
*
|
|
730
|
+
* @returns Geometry point list in world coordinates.
|
|
731
|
+
*/
|
|
732
|
+
AcDbMLine.prototype.collectGeometryPoints = function () {
|
|
733
|
+
var points = [this._startPosition];
|
|
734
|
+
if (this._segments.length === 0)
|
|
735
|
+
return points;
|
|
736
|
+
var mlineStyle = this.getMLineStyle();
|
|
737
|
+
var elementCount = this.getRenderableElementCount(mlineStyle);
|
|
738
|
+
if (elementCount <= 0) {
|
|
739
|
+
this._segments.forEach(function (segment) { return points.push(segment.position); });
|
|
740
|
+
return points;
|
|
741
|
+
}
|
|
742
|
+
for (var i = 0; i < elementCount; i++) {
|
|
743
|
+
points.push.apply(points, __spreadArray([], __read(this.getElementPath(i, mlineStyle)), false));
|
|
744
|
+
}
|
|
745
|
+
return points;
|
|
746
|
+
};
|
|
747
|
+
/**
|
|
748
|
+
* Calculates how many element paths should be rendered.
|
|
749
|
+
* Uses the max of entity style count, style definition count, and segment data.
|
|
750
|
+
*
|
|
751
|
+
* @param mlineStyle Resolved style object, if available.
|
|
752
|
+
* @returns Renderable element count.
|
|
753
|
+
*/
|
|
754
|
+
AcDbMLine.prototype.getRenderableElementCount = function (mlineStyle) {
|
|
755
|
+
var _a;
|
|
756
|
+
var styleElementCount = (_a = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elementCount) !== null && _a !== void 0 ? _a : 0;
|
|
757
|
+
return Math.max.apply(Math, __spreadArray(__spreadArray([this._styleCount,
|
|
758
|
+
styleElementCount], __read(this._segments.map(function (segment) { return segment.elements.length; })), false), [0], false));
|
|
759
|
+
};
|
|
760
|
+
/**
|
|
761
|
+
* Builds the un-offset reference polyline path from start point and segments.
|
|
762
|
+
*
|
|
763
|
+
* @returns Reference path points, optionally closed when needed.
|
|
764
|
+
*/
|
|
765
|
+
AcDbMLine.prototype.getReferencePath = function () {
|
|
766
|
+
var points = __spreadArray([
|
|
767
|
+
this._startPosition.clone()
|
|
768
|
+
], __read(this._segments.map(function (segment) { return segment.position.clone(); })), false);
|
|
769
|
+
return this.closePathIfNeeded(points);
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
* Computes one style element path by offsetting every segment along its miter direction.
|
|
773
|
+
*
|
|
774
|
+
* @param elementIndex Style element index to evaluate.
|
|
775
|
+
* @param mlineStyle Resolved style object, if available.
|
|
776
|
+
* @returns Offset path points, optionally closed when needed.
|
|
777
|
+
*/
|
|
778
|
+
AcDbMLine.prototype.getElementPath = function (elementIndex, mlineStyle) {
|
|
779
|
+
var _this = this;
|
|
780
|
+
var points = [];
|
|
781
|
+
var first = this._segments[0];
|
|
782
|
+
points.push(this.getElementBoundaryPoint('start', first, elementIndex, mlineStyle));
|
|
783
|
+
this._segments.forEach(function (segment) {
|
|
784
|
+
points.push(_this.offsetPoint(segment.position, segment.miterDirection, _this.getElementMiterOffset(segment, elementIndex, mlineStyle)));
|
|
785
|
+
});
|
|
786
|
+
points[points.length - 1] = this.getElementBoundaryPoint('end', this._segments[this._segments.length - 1], elementIndex, mlineStyle);
|
|
787
|
+
return this.closePathIfNeeded(points);
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Resolves the offset distance for an element at a specific segment.
|
|
791
|
+
* Prefers segment element parameters and falls back to style offsets.
|
|
792
|
+
*
|
|
793
|
+
* @param segment Segment to evaluate.
|
|
794
|
+
* @param elementIndex Style element index.
|
|
795
|
+
* @param mlineStyle Resolved style object, if available.
|
|
796
|
+
* @returns Miter offset distance.
|
|
797
|
+
*/
|
|
798
|
+
AcDbMLine.prototype.getElementMiterOffset = function (segment, elementIndex, mlineStyle) {
|
|
799
|
+
var _a;
|
|
800
|
+
var element = segment.elements[elementIndex];
|
|
801
|
+
if ((_a = element === null || element === void 0 ? void 0 : element.parameters) === null || _a === void 0 ? void 0 : _a.length)
|
|
802
|
+
return element.parameters[0];
|
|
803
|
+
return this.getStyleElementOffset(elementIndex, mlineStyle);
|
|
804
|
+
};
|
|
805
|
+
/**
|
|
806
|
+
* Resolves one element boundary point at the start/end of open MLINE paths.
|
|
807
|
+
*
|
|
808
|
+
* @param side `start` or `end`.
|
|
809
|
+
* @param segment Segment data used to resolve miter offset.
|
|
810
|
+
* @param elementIndex Style element index.
|
|
811
|
+
* @param mlineStyle Resolved style object, if available.
|
|
812
|
+
* @returns Boundary point after cap-angle cut adjustment.
|
|
813
|
+
*/
|
|
814
|
+
AcDbMLine.prototype.getElementBoundaryPoint = function (side, segment, elementIndex, mlineStyle) {
|
|
815
|
+
var offset = this.getElementMiterOffset(segment, elementIndex, mlineStyle);
|
|
816
|
+
var basePoint = side === 'start' ? this._startPosition : segment.position;
|
|
817
|
+
var point = this.offsetPoint(basePoint, segment.miterDirection, offset);
|
|
818
|
+
if (!this.shouldApplyCapCutAtSide(side, mlineStyle)) {
|
|
819
|
+
return point;
|
|
820
|
+
}
|
|
821
|
+
var capAngle = side === 'start' ? mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.startAngle : mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.endAngle;
|
|
822
|
+
var cutDistance = this.computeCapCutDistance(offset, capAngle, side);
|
|
823
|
+
if (cutDistance === 0)
|
|
824
|
+
return point;
|
|
825
|
+
var direction = side === 'start'
|
|
826
|
+
? this.getStartSegmentDirection()
|
|
827
|
+
: this.getEndSegmentDirection();
|
|
828
|
+
if (direction.lengthSq() === 0)
|
|
829
|
+
return point;
|
|
830
|
+
return point.add(direction.multiplyScalar(cutDistance));
|
|
831
|
+
};
|
|
832
|
+
/**
|
|
833
|
+
* Indicates whether cap-angle cut should be applied at the given side.
|
|
834
|
+
*
|
|
835
|
+
* @param side `start` or `end`.
|
|
836
|
+
* @param mlineStyle Resolved style object, if available.
|
|
837
|
+
* @returns `true` when side has cap components and is not suppressed.
|
|
838
|
+
*/
|
|
839
|
+
AcDbMLine.prototype.shouldApplyCapCutAtSide = function (side, mlineStyle) {
|
|
840
|
+
if (!mlineStyle || this.closed)
|
|
841
|
+
return false;
|
|
842
|
+
if (side === 'start') {
|
|
843
|
+
if (this.suppressStartCaps)
|
|
844
|
+
return false;
|
|
845
|
+
return ((mlineStyle.flags &
|
|
846
|
+
(AcDbMLineStyleFlags.StartSquareCap |
|
|
847
|
+
AcDbMLineStyleFlags.StartInnerArcs |
|
|
848
|
+
AcDbMLineStyleFlags.StartRoundCap)) !==
|
|
849
|
+
0);
|
|
850
|
+
}
|
|
851
|
+
if (this.suppressEndCaps)
|
|
852
|
+
return false;
|
|
853
|
+
return ((mlineStyle.flags &
|
|
854
|
+
(AcDbMLineStyleFlags.EndSquareCap |
|
|
855
|
+
AcDbMLineStyleFlags.EndInnerArcs |
|
|
856
|
+
AcDbMLineStyleFlags.EndRoundCap)) !==
|
|
857
|
+
0);
|
|
858
|
+
};
|
|
859
|
+
/**
|
|
860
|
+
* Computes longitudinal cut distance based on cap angle and style-element offset.
|
|
861
|
+
*
|
|
862
|
+
* @param offset Element offset along miter direction.
|
|
863
|
+
* @param angleDegrees Cap angle in degree units.
|
|
864
|
+
* @param side `start` or `end`.
|
|
865
|
+
* @returns Signed distance to move along segment direction.
|
|
866
|
+
*/
|
|
867
|
+
AcDbMLine.prototype.computeCapCutDistance = function (offset, angleDegrees, side) {
|
|
868
|
+
var angle = this.normalizeCapAngle(angleDegrees);
|
|
869
|
+
var tan = Math.tan(angle);
|
|
870
|
+
if (Math.abs(tan) < 1e-6)
|
|
871
|
+
return 0;
|
|
872
|
+
var distance = offset / tan;
|
|
873
|
+
return side === 'start' ? distance : distance;
|
|
874
|
+
};
|
|
875
|
+
/**
|
|
876
|
+
* Normalizes cap angle from DXF degree units to radians.
|
|
877
|
+
*
|
|
878
|
+
* @param angleDegrees Cap angle in degree units.
|
|
879
|
+
* @returns Safe radian value in `(0, PI)` with 90-degree fallback.
|
|
880
|
+
*/
|
|
881
|
+
AcDbMLine.prototype.normalizeCapAngle = function (angleDegrees) {
|
|
882
|
+
if (angleDegrees == null || !Number.isFinite(angleDegrees)) {
|
|
883
|
+
return Math.PI / 2;
|
|
884
|
+
}
|
|
885
|
+
var degrees = angleDegrees % 180;
|
|
886
|
+
if (degrees < 0)
|
|
887
|
+
degrees += 180;
|
|
888
|
+
if (degrees < 1 || degrees > 179) {
|
|
889
|
+
degrees = 90;
|
|
890
|
+
}
|
|
891
|
+
return (degrees * Math.PI) / 180;
|
|
892
|
+
};
|
|
893
|
+
/**
|
|
894
|
+
* Resolves forward direction at MLINE start.
|
|
895
|
+
*
|
|
896
|
+
* @returns Unit vector along the first segment.
|
|
897
|
+
*/
|
|
898
|
+
AcDbMLine.prototype.getStartSegmentDirection = function () {
|
|
899
|
+
var first = this._segments[0];
|
|
900
|
+
var direction = new AcGeVector3d();
|
|
901
|
+
if (first) {
|
|
902
|
+
// Prefer actual geometry direction. The serialized first segment direction can be noisy
|
|
903
|
+
// in some files and may not match the true start-edge direction.
|
|
904
|
+
direction.subVectors(first.position, this._startPosition);
|
|
905
|
+
if (direction.lengthSq() === 0) {
|
|
906
|
+
direction.copy(first.direction);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
if (direction.lengthSq() > 0)
|
|
910
|
+
direction.normalize();
|
|
911
|
+
return direction;
|
|
912
|
+
};
|
|
913
|
+
/**
|
|
914
|
+
* Resolves forward direction at MLINE end.
|
|
915
|
+
*
|
|
916
|
+
* @returns Unit vector along the last visible segment.
|
|
917
|
+
*/
|
|
918
|
+
AcDbMLine.prototype.getEndSegmentDirection = function () {
|
|
919
|
+
var last = this._segments[this._segments.length - 1];
|
|
920
|
+
if (!last)
|
|
921
|
+
return new AcGeVector3d();
|
|
922
|
+
var direction = new AcGeVector3d();
|
|
923
|
+
var previousPoint = this._segments.length > 1
|
|
924
|
+
? this._segments[this._segments.length - 2].position
|
|
925
|
+
: this._startPosition;
|
|
926
|
+
// Prefer actual geometry direction. Some DXF producers write a final segment direction
|
|
927
|
+
// that does not represent the visible last edge, which flips end caps.
|
|
928
|
+
direction.subVectors(last.position, previousPoint);
|
|
929
|
+
if (direction.lengthSq() === 0) {
|
|
930
|
+
direction.copy(last.direction);
|
|
931
|
+
}
|
|
932
|
+
if (direction.lengthSq() > 0)
|
|
933
|
+
direction.normalize();
|
|
934
|
+
return direction;
|
|
935
|
+
};
|
|
936
|
+
/**
|
|
937
|
+
* Creates a fill area between outermost and innermost element paths when style fill is enabled.
|
|
938
|
+
*
|
|
939
|
+
* @param mlineStyle Resolved style object.
|
|
940
|
+
* @param elementCount Total renderable element count.
|
|
941
|
+
* @returns Fill area polygon(s), or `undefined` when fill cannot be formed.
|
|
942
|
+
*/
|
|
943
|
+
AcDbMLine.prototype.createFillArea = function (mlineStyle, elementCount) {
|
|
944
|
+
if (!mlineStyle ||
|
|
945
|
+
(mlineStyle.flags & AcDbMLineStyleFlags.FillOn) === 0 ||
|
|
946
|
+
elementCount < 2) {
|
|
947
|
+
return undefined;
|
|
948
|
+
}
|
|
949
|
+
var boundary = this.getFillBoundaryElementIndices(elementCount, mlineStyle);
|
|
950
|
+
if (!boundary)
|
|
951
|
+
return undefined;
|
|
952
|
+
var outerPath = this.getElementPath(boundary.outerIndex, mlineStyle);
|
|
953
|
+
var innerPath = this.getElementPath(boundary.innerIndex, mlineStyle);
|
|
954
|
+
var outerPoints = this.stripClosingPoint(outerPath);
|
|
955
|
+
var innerPoints = this.stripClosingPoint(innerPath);
|
|
956
|
+
if (outerPoints.length < 2 || innerPoints.length < 2) {
|
|
957
|
+
return undefined;
|
|
958
|
+
}
|
|
959
|
+
var area = new AcGeArea2d();
|
|
960
|
+
if (this.closed) {
|
|
961
|
+
if (outerPoints.length < 3 || innerPoints.length < 3)
|
|
962
|
+
return undefined;
|
|
963
|
+
area.add(new AcGePolyline2d(outerPoints.map(function (point) { return ({ x: point.x, y: point.y }); }), true));
|
|
964
|
+
area.add(new AcGePolyline2d(innerPoints.map(function (point) { return ({ x: point.x, y: point.y }); }), true));
|
|
965
|
+
}
|
|
966
|
+
else {
|
|
967
|
+
var ringPoints = __spreadArray(__spreadArray([], __read(outerPoints), false), __read(innerPoints.slice().reverse()), false).map(function (point) { return ({ x: point.x, y: point.y }); });
|
|
968
|
+
if (ringPoints.length < 3)
|
|
969
|
+
return undefined;
|
|
970
|
+
area.add(new AcGePolyline2d(ringPoints, true));
|
|
971
|
+
}
|
|
972
|
+
return area;
|
|
973
|
+
};
|
|
974
|
+
/**
|
|
975
|
+
* Finds the element indices that define fill boundaries by minimum and maximum reference offsets.
|
|
976
|
+
*
|
|
977
|
+
* @param elementCount Total renderable element count.
|
|
978
|
+
* @param mlineStyle Resolved style object, if available.
|
|
979
|
+
* @returns Outer/inner boundary indices, or `undefined` when not resolvable.
|
|
980
|
+
*/
|
|
981
|
+
AcDbMLine.prototype.getFillBoundaryElementIndices = function (elementCount, mlineStyle) {
|
|
982
|
+
var minOffset = Number.POSITIVE_INFINITY;
|
|
983
|
+
var maxOffset = Number.NEGATIVE_INFINITY;
|
|
984
|
+
var minIndex = -1;
|
|
985
|
+
var maxIndex = -1;
|
|
986
|
+
for (var i = 0; i < elementCount; i++) {
|
|
987
|
+
var offset = this.getElementReferenceOffset(i, mlineStyle);
|
|
988
|
+
if (offset < minOffset) {
|
|
989
|
+
minOffset = offset;
|
|
990
|
+
minIndex = i;
|
|
991
|
+
}
|
|
992
|
+
if (offset > maxOffset) {
|
|
993
|
+
maxOffset = offset;
|
|
994
|
+
maxIndex = i;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (minIndex < 0 || maxIndex < 0 || minIndex === maxIndex) {
|
|
998
|
+
return undefined;
|
|
999
|
+
}
|
|
1000
|
+
return {
|
|
1001
|
+
outerIndex: maxIndex,
|
|
1002
|
+
innerIndex: minIndex
|
|
1003
|
+
};
|
|
1004
|
+
};
|
|
1005
|
+
/**
|
|
1006
|
+
* Resolves an element's reference offset from first-segment data or style defaults.
|
|
1007
|
+
*
|
|
1008
|
+
* @param elementIndex Style element index.
|
|
1009
|
+
* @param mlineStyle Resolved style object, if available.
|
|
1010
|
+
* @returns Reference offset used for boundary comparison.
|
|
1011
|
+
*/
|
|
1012
|
+
AcDbMLine.prototype.getElementReferenceOffset = function (elementIndex, mlineStyle) {
|
|
1013
|
+
var _a;
|
|
1014
|
+
var firstSegment = this._segments[0];
|
|
1015
|
+
if (firstSegment) {
|
|
1016
|
+
var element = firstSegment.elements[elementIndex];
|
|
1017
|
+
if ((_a = element === null || element === void 0 ? void 0 : element.parameters) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1018
|
+
return element.parameters[0];
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
return this.getStyleElementOffset(elementIndex, mlineStyle);
|
|
1022
|
+
};
|
|
1023
|
+
/**
|
|
1024
|
+
* Resolves style-defined element offset to world offset under current
|
|
1025
|
+
* justification and entity scale.
|
|
1026
|
+
*
|
|
1027
|
+
* @param elementIndex Style element index.
|
|
1028
|
+
* @param mlineStyle Resolved style object, if available.
|
|
1029
|
+
* @returns Final offset distance used for miter displacement.
|
|
1030
|
+
*/
|
|
1031
|
+
AcDbMLine.prototype.getStyleElementOffset = function (elementIndex, mlineStyle) {
|
|
1032
|
+
var styleElement = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elements[elementIndex];
|
|
1033
|
+
if (!styleElement)
|
|
1034
|
+
return 0;
|
|
1035
|
+
var shift = this.getStyleJustificationShift(mlineStyle);
|
|
1036
|
+
return (styleElement.offset + shift) * this._scale;
|
|
1037
|
+
};
|
|
1038
|
+
/**
|
|
1039
|
+
* Calculates justification shift in style-offset space.
|
|
1040
|
+
*
|
|
1041
|
+
* - `Zero`: shift = 0
|
|
1042
|
+
* - `Top`: highest style offset is moved to 0
|
|
1043
|
+
* - `Bottom`: lowest style offset is moved to 0
|
|
1044
|
+
*
|
|
1045
|
+
* @param mlineStyle Resolved style object, if available.
|
|
1046
|
+
* @returns Offset shift before scaling.
|
|
1047
|
+
*/
|
|
1048
|
+
AcDbMLine.prototype.getStyleJustificationShift = function (mlineStyle) {
|
|
1049
|
+
var e_1, _a;
|
|
1050
|
+
var _b;
|
|
1051
|
+
var elements = (_b = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elements) !== null && _b !== void 0 ? _b : [];
|
|
1052
|
+
if (elements.length <= 0)
|
|
1053
|
+
return 0;
|
|
1054
|
+
var minOffset = Number.POSITIVE_INFINITY;
|
|
1055
|
+
var maxOffset = Number.NEGATIVE_INFINITY;
|
|
1056
|
+
try {
|
|
1057
|
+
for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
|
|
1058
|
+
var element = elements_1_1.value;
|
|
1059
|
+
var offset = element.offset;
|
|
1060
|
+
if (offset < minOffset)
|
|
1061
|
+
minOffset = offset;
|
|
1062
|
+
if (offset > maxOffset)
|
|
1063
|
+
maxOffset = offset;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1067
|
+
finally {
|
|
1068
|
+
try {
|
|
1069
|
+
if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
|
|
1070
|
+
}
|
|
1071
|
+
finally { if (e_1) throw e_1.error; }
|
|
1072
|
+
}
|
|
1073
|
+
if (this._justification === AcDbMLineJustification.Top) {
|
|
1074
|
+
return -maxOffset;
|
|
1075
|
+
}
|
|
1076
|
+
if (this._justification === AcDbMLineJustification.Bottom) {
|
|
1077
|
+
return -minOffset;
|
|
1078
|
+
}
|
|
1079
|
+
return 0;
|
|
1080
|
+
};
|
|
1081
|
+
/**
|
|
1082
|
+
* Removes a duplicated closing vertex when the first and last points are numerically equal.
|
|
1083
|
+
*
|
|
1084
|
+
* @param points Candidate closed path.
|
|
1085
|
+
* @returns Path without duplicated terminal point.
|
|
1086
|
+
*/
|
|
1087
|
+
AcDbMLine.prototype.stripClosingPoint = function (points) {
|
|
1088
|
+
if (points.length < 2)
|
|
1089
|
+
return points;
|
|
1090
|
+
var first = points[0];
|
|
1091
|
+
var last = points[points.length - 1];
|
|
1092
|
+
var epsilon = 1e-9;
|
|
1093
|
+
var isClosed = Math.abs(first.x - last.x) <= epsilon &&
|
|
1094
|
+
Math.abs(first.y - last.y) <= epsilon &&
|
|
1095
|
+
Math.abs(first.z - last.z) <= epsilon;
|
|
1096
|
+
return isClosed ? points.slice(0, -1) : points;
|
|
1097
|
+
};
|
|
1098
|
+
/**
|
|
1099
|
+
* Offsets a point along a miter direction by a scalar distance.
|
|
1100
|
+
*
|
|
1101
|
+
* @param point Base point.
|
|
1102
|
+
* @param miterDirection Offset direction.
|
|
1103
|
+
* @param distance Offset distance.
|
|
1104
|
+
* @returns Offset point clone.
|
|
1105
|
+
*/
|
|
1106
|
+
AcDbMLine.prototype.offsetPoint = function (point, miterDirection, distance) {
|
|
1107
|
+
if (distance === 0 || miterDirection.lengthSq() === 0) {
|
|
1108
|
+
return point.clone();
|
|
1109
|
+
}
|
|
1110
|
+
var direction = miterDirection
|
|
1111
|
+
.clone()
|
|
1112
|
+
.normalize()
|
|
1113
|
+
.multiplyScalar(distance);
|
|
1114
|
+
return point.clone().add(direction);
|
|
1115
|
+
};
|
|
1116
|
+
/**
|
|
1117
|
+
* Appends the first point to the end of a path when closed mode requires an explicit closure.
|
|
1118
|
+
*
|
|
1119
|
+
* @param points Path points to inspect.
|
|
1120
|
+
* @returns Original or explicitly closed path array.
|
|
1121
|
+
*/
|
|
1122
|
+
AcDbMLine.prototype.closePathIfNeeded = function (points) {
|
|
1123
|
+
if (!this.closed || points.length < 2)
|
|
1124
|
+
return points;
|
|
1125
|
+
var first = points[0];
|
|
1126
|
+
var last = points[points.length - 1];
|
|
1127
|
+
var epsilon = 1e-9;
|
|
1128
|
+
var isClosed = Math.abs(first.x - last.x) <= epsilon &&
|
|
1129
|
+
Math.abs(first.y - last.y) <= epsilon &&
|
|
1130
|
+
Math.abs(first.z - last.z) <= epsilon;
|
|
1131
|
+
if (!isClosed)
|
|
1132
|
+
points.push(first.clone());
|
|
1133
|
+
return points;
|
|
1134
|
+
};
|
|
1135
|
+
/**
|
|
1136
|
+
* Appends style-driven joint/cap entities after element path rendering.
|
|
1137
|
+
*
|
|
1138
|
+
* @param renderer Active graphics renderer.
|
|
1139
|
+
* @param entities Output entity list to append into.
|
|
1140
|
+
* @param mlineStyle Resolved style object, if available.
|
|
1141
|
+
* @param elementCount Renderable style element count.
|
|
1142
|
+
* @param originalColor Original trait color.
|
|
1143
|
+
* @param originalRgbColor Original trait RGB.
|
|
1144
|
+
* @param originalLineType Original trait linetype.
|
|
1145
|
+
*/
|
|
1146
|
+
AcDbMLine.prototype.appendStyleDrivenJointAndCapEntities = function (renderer, entities, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
|
|
1147
|
+
if (!mlineStyle || elementCount < 2)
|
|
1148
|
+
return;
|
|
1149
|
+
entities.push.apply(entities, __spreadArray([], __read(this.drawMiterJointEntities(renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
|
|
1150
|
+
entities.push.apply(entities, __spreadArray([], __read(this.drawCapEntities(renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
|
|
1151
|
+
};
|
|
1152
|
+
/**
|
|
1153
|
+
* Draws miter connector lines at interior joints when style enables it.
|
|
1154
|
+
*
|
|
1155
|
+
* @param renderer Active graphics renderer.
|
|
1156
|
+
* @param mlineStyle Resolved style object.
|
|
1157
|
+
* @param elementCount Renderable style element count.
|
|
1158
|
+
* @param originalColor Original trait color.
|
|
1159
|
+
* @param originalRgbColor Original trait RGB.
|
|
1160
|
+
* @param originalLineType Original trait linetype.
|
|
1161
|
+
* @returns Drawn joint entities.
|
|
1162
|
+
*/
|
|
1163
|
+
AcDbMLine.prototype.drawMiterJointEntities = function (renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
|
|
1164
|
+
var _this = this;
|
|
1165
|
+
if (this.closed ||
|
|
1166
|
+
this._segments.length < 2 ||
|
|
1167
|
+
(mlineStyle.flags & AcDbMLineStyleFlags.DisplayMiters) === 0) {
|
|
1168
|
+
return [];
|
|
1169
|
+
}
|
|
1170
|
+
var entities = [];
|
|
1171
|
+
var traits = renderer.subEntityTraits;
|
|
1172
|
+
var _loop_1 = function (segmentIndex) {
|
|
1173
|
+
var segment = this_1._segments[segmentIndex];
|
|
1174
|
+
var points = Array.from({ length: elementCount }, function (_, elementIndex) {
|
|
1175
|
+
var offset = _this.getElementMiterOffset(segment, elementIndex, mlineStyle);
|
|
1176
|
+
return {
|
|
1177
|
+
elementIndex: elementIndex,
|
|
1178
|
+
offset: offset,
|
|
1179
|
+
point: _this.offsetPoint(segment.position, segment.miterDirection, offset)
|
|
1180
|
+
};
|
|
1181
|
+
}).sort(function (a, b) { return b.offset - a.offset; });
|
|
1182
|
+
for (var i = 0; i < points.length - 1; i++) {
|
|
1183
|
+
this_1.applyElementDrawTraits(traits, originalColor, originalRgbColor, originalLineType, mlineStyle, points[i].elementIndex);
|
|
1184
|
+
entities.push(renderer.lines([points[i].point, points[i + 1].point]));
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
var this_1 = this;
|
|
1188
|
+
for (var segmentIndex = 0; segmentIndex < this._segments.length - 1; segmentIndex++) {
|
|
1189
|
+
_loop_1(segmentIndex);
|
|
1190
|
+
}
|
|
1191
|
+
return entities;
|
|
1192
|
+
};
|
|
1193
|
+
/**
|
|
1194
|
+
* Draws start/end cap entities according to MLINESTYLE cap flags.
|
|
1195
|
+
*
|
|
1196
|
+
* @param renderer Active graphics renderer.
|
|
1197
|
+
* @param mlineStyle Resolved style object.
|
|
1198
|
+
* @param elementCount Renderable style element count.
|
|
1199
|
+
* @param originalColor Original trait color.
|
|
1200
|
+
* @param originalRgbColor Original trait RGB.
|
|
1201
|
+
* @param originalLineType Original trait linetype.
|
|
1202
|
+
* @returns Drawn cap entities.
|
|
1203
|
+
*/
|
|
1204
|
+
AcDbMLine.prototype.drawCapEntities = function (renderer, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
|
|
1205
|
+
if (this.closed || this._segments.length <= 0)
|
|
1206
|
+
return [];
|
|
1207
|
+
var entities = [];
|
|
1208
|
+
entities.push.apply(entities, __spreadArray([], __read(this.drawCapEntitiesForSide(renderer, 'start', mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
|
|
1209
|
+
entities.push.apply(entities, __spreadArray([], __read(this.drawCapEntitiesForSide(renderer, 'end', mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType)), false));
|
|
1210
|
+
return entities;
|
|
1211
|
+
};
|
|
1212
|
+
/**
|
|
1213
|
+
* Draws one-side cap entities (line/outer-arc/inner-arcs).
|
|
1214
|
+
*
|
|
1215
|
+
* @param renderer Active graphics renderer.
|
|
1216
|
+
* @param side `start` or `end`.
|
|
1217
|
+
* @param mlineStyle Resolved style object.
|
|
1218
|
+
* @param elementCount Renderable style element count.
|
|
1219
|
+
* @param originalColor Original trait color.
|
|
1220
|
+
* @param originalRgbColor Original trait RGB.
|
|
1221
|
+
* @param originalLineType Original trait linetype.
|
|
1222
|
+
* @returns Drawn one-side cap entities.
|
|
1223
|
+
*/
|
|
1224
|
+
AcDbMLine.prototype.drawCapEntitiesForSide = function (renderer, side, mlineStyle, elementCount, originalColor, originalRgbColor, originalLineType) {
|
|
1225
|
+
if (side === 'start' && this.suppressStartCaps)
|
|
1226
|
+
return [];
|
|
1227
|
+
if (side === 'end' && this.suppressEndCaps)
|
|
1228
|
+
return [];
|
|
1229
|
+
var flags = mlineStyle.flags;
|
|
1230
|
+
var isStart = side === 'start';
|
|
1231
|
+
var hasSquare = isStart
|
|
1232
|
+
? (flags & AcDbMLineStyleFlags.StartSquareCap) !== 0
|
|
1233
|
+
: (flags & AcDbMLineStyleFlags.EndSquareCap) !== 0;
|
|
1234
|
+
var hasOuterArc = isStart
|
|
1235
|
+
? (flags & AcDbMLineStyleFlags.StartRoundCap) !== 0
|
|
1236
|
+
: (flags & AcDbMLineStyleFlags.EndRoundCap) !== 0;
|
|
1237
|
+
var hasInnerArcs = isStart
|
|
1238
|
+
? (flags & AcDbMLineStyleFlags.StartInnerArcs) !== 0
|
|
1239
|
+
: (flags & AcDbMLineStyleFlags.EndInnerArcs) !== 0;
|
|
1240
|
+
if (!hasSquare && !hasOuterArc && !hasInnerArcs)
|
|
1241
|
+
return [];
|
|
1242
|
+
var points = this.getCapElementPoints(side, elementCount, mlineStyle);
|
|
1243
|
+
if (points.length < 2)
|
|
1244
|
+
return [];
|
|
1245
|
+
var entities = [];
|
|
1246
|
+
var traits = renderer.subEntityTraits;
|
|
1247
|
+
if (hasSquare) {
|
|
1248
|
+
for (var i = 0; i < points.length - 1; i++) {
|
|
1249
|
+
this.applyElementDrawTraits(traits, originalColor, originalRgbColor, originalLineType, mlineStyle, points[i].elementIndex);
|
|
1250
|
+
entities.push(renderer.lines([points[i].point, points[i + 1].point]));
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
var capDirection = isStart
|
|
1254
|
+
? this.getStartSegmentDirection().multiplyScalar(-1)
|
|
1255
|
+
: this.getEndSegmentDirection().clone();
|
|
1256
|
+
if (hasOuterArc) {
|
|
1257
|
+
var outer = this.drawCapArcBetweenElements(renderer, side, points[0], points[points.length - 1], capDirection, traits, originalColor, originalRgbColor, originalLineType, mlineStyle);
|
|
1258
|
+
if (outer)
|
|
1259
|
+
entities.push(outer);
|
|
1260
|
+
}
|
|
1261
|
+
if (hasInnerArcs) {
|
|
1262
|
+
for (var i = 1; i < Math.floor(points.length / 2); i++) {
|
|
1263
|
+
var left = points[i];
|
|
1264
|
+
var right = points[points.length - 1 - i];
|
|
1265
|
+
if (!left || !right || left === right)
|
|
1266
|
+
continue;
|
|
1267
|
+
var inner = this.drawCapArcBetweenElements(renderer, side, left, right, capDirection, traits, originalColor, originalRgbColor, originalLineType, mlineStyle);
|
|
1268
|
+
if (inner)
|
|
1269
|
+
entities.push(inner);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return entities;
|
|
1273
|
+
};
|
|
1274
|
+
/**
|
|
1275
|
+
* Creates sorted element boundary points for one cap side.
|
|
1276
|
+
*
|
|
1277
|
+
* @param side `start` or `end`.
|
|
1278
|
+
* @param elementCount Renderable style element count.
|
|
1279
|
+
* @param mlineStyle Resolved style object.
|
|
1280
|
+
* @returns Cap points sorted by descending element offset.
|
|
1281
|
+
*/
|
|
1282
|
+
AcDbMLine.prototype.getCapElementPoints = function (side, elementCount, mlineStyle) {
|
|
1283
|
+
var _this = this;
|
|
1284
|
+
var segment = side === 'start'
|
|
1285
|
+
? this._segments[0]
|
|
1286
|
+
: this._segments[this._segments.length - 1];
|
|
1287
|
+
if (!segment)
|
|
1288
|
+
return [];
|
|
1289
|
+
return Array.from({ length: elementCount }, function (_, elementIndex) { return ({
|
|
1290
|
+
elementIndex: elementIndex,
|
|
1291
|
+
offset: _this.getElementMiterOffset(segment, elementIndex, mlineStyle),
|
|
1292
|
+
point: _this.getElementBoundaryPoint(side, segment, elementIndex, mlineStyle)
|
|
1293
|
+
}); }).sort(function (a, b) { return b.offset - a.offset; });
|
|
1294
|
+
};
|
|
1295
|
+
/**
|
|
1296
|
+
* Draws one cap arc between two cap element points.
|
|
1297
|
+
*
|
|
1298
|
+
* @param renderer Active graphics renderer.
|
|
1299
|
+
* @param startPointPair Start element point.
|
|
1300
|
+
* @param endPointPair End element point.
|
|
1301
|
+
* @param capDirection Outward cap direction.
|
|
1302
|
+
* @param traits Mutable renderer traits.
|
|
1303
|
+
* @param originalColor Original trait color.
|
|
1304
|
+
* @param originalRgbColor Original trait RGB.
|
|
1305
|
+
* @param originalLineType Original trait linetype.
|
|
1306
|
+
* @param mlineStyle Resolved style object.
|
|
1307
|
+
* @returns Arc entity, or `undefined` when arc cannot be constructed.
|
|
1308
|
+
*/
|
|
1309
|
+
AcDbMLine.prototype.drawCapArcBetweenElements = function (renderer, side, startPointPair, endPointPair, capDirection, traits, originalColor, originalRgbColor, originalLineType, mlineStyle) {
|
|
1310
|
+
// For 180-degree cap arcs, start/end point order determines whether
|
|
1311
|
+
// the renderer takes the left or right semicircle. End caps need reverse order.
|
|
1312
|
+
var arcStartPoint = side === 'end' ? endPointPair.point : startPointPair.point;
|
|
1313
|
+
var arcEndPoint = side === 'end' ? startPointPair.point : endPointPair.point;
|
|
1314
|
+
var chord = arcStartPoint.distanceTo(arcEndPoint);
|
|
1315
|
+
if (chord <= 1e-9 || capDirection.lengthSq() === 0)
|
|
1316
|
+
return undefined;
|
|
1317
|
+
var midpoint = arcStartPoint
|
|
1318
|
+
.clone()
|
|
1319
|
+
.add(new AcGeVector3d()
|
|
1320
|
+
.subVectors(arcEndPoint, arcStartPoint)
|
|
1321
|
+
.multiplyScalar(0.5));
|
|
1322
|
+
var pointOnArc = midpoint.add(capDirection
|
|
1323
|
+
.clone()
|
|
1324
|
+
.normalize()
|
|
1325
|
+
.multiplyScalar(chord / 2));
|
|
1326
|
+
var arc = AcGeCircArc3d.createByThreePoints(arcStartPoint, arcEndPoint, pointOnArc);
|
|
1327
|
+
if (!arc)
|
|
1328
|
+
return undefined;
|
|
1329
|
+
this.applyElementDrawTraits(traits, originalColor, originalRgbColor, originalLineType, mlineStyle, side === 'end' ? endPointPair.elementIndex : startPointPair.elementIndex);
|
|
1330
|
+
return renderer.circularArc(arc);
|
|
1331
|
+
};
|
|
1332
|
+
/**
|
|
1333
|
+
* Applies per-element traits while restoring baseline traits first.
|
|
1334
|
+
*
|
|
1335
|
+
* @param traits Mutable renderer traits.
|
|
1336
|
+
* @param originalColor Original trait color.
|
|
1337
|
+
* @param originalRgbColor Original trait RGB.
|
|
1338
|
+
* @param originalLineType Original trait linetype.
|
|
1339
|
+
* @param mlineStyle Resolved style object.
|
|
1340
|
+
* @param elementIndex Style element index.
|
|
1341
|
+
*/
|
|
1342
|
+
AcDbMLine.prototype.applyElementDrawTraits = function (traits, originalColor, originalRgbColor, originalLineType, mlineStyle, elementIndex) {
|
|
1343
|
+
traits.color = originalColor;
|
|
1344
|
+
traits.rgbColor = originalRgbColor;
|
|
1345
|
+
traits.lineType = originalLineType;
|
|
1346
|
+
this.applyStyleElementTraits(mlineStyle, elementIndex, traits);
|
|
1347
|
+
};
|
|
1348
|
+
/**
|
|
1349
|
+
* Transforms a vector by matrix rotation/scale only.
|
|
1350
|
+
* Translation is canceled by transforming an origin-endpoint pair.
|
|
1351
|
+
*
|
|
1352
|
+
* @param vector Vector to transform in place.
|
|
1353
|
+
* @param matrix Transformation matrix.
|
|
1354
|
+
*/
|
|
1355
|
+
AcDbMLine.prototype.transformVector = function (vector, matrix) {
|
|
1356
|
+
var origin = new AcGePoint3d();
|
|
1357
|
+
var endpoint = new AcGePoint3d(vector.x, vector.y, vector.z);
|
|
1358
|
+
origin.applyMatrix4(matrix);
|
|
1359
|
+
endpoint.applyMatrix4(matrix);
|
|
1360
|
+
vector.set(endpoint.x - origin.x, endpoint.y - origin.y, endpoint.z - origin.z);
|
|
1361
|
+
};
|
|
1362
|
+
/**
|
|
1363
|
+
* Resolves the effective MLINE style from database dictionary.
|
|
1364
|
+
* Lookup order: handle, exact name, then case-insensitive name match.
|
|
1365
|
+
*
|
|
1366
|
+
* @returns Matching style object, or `undefined` when no style is found.
|
|
1367
|
+
*/
|
|
1368
|
+
AcDbMLine.prototype.getMLineStyle = function () {
|
|
1369
|
+
var e_2, _a;
|
|
1370
|
+
var _b;
|
|
1371
|
+
var dictionary = this.database.objects.mlineStyle;
|
|
1372
|
+
var byHandle = this.styleObjectHandle
|
|
1373
|
+
? dictionary.getIdAt(this.styleObjectHandle)
|
|
1374
|
+
: undefined;
|
|
1375
|
+
if (byHandle)
|
|
1376
|
+
return byHandle;
|
|
1377
|
+
var directByName = this.styleName
|
|
1378
|
+
? dictionary.getAt(this.styleName)
|
|
1379
|
+
: undefined;
|
|
1380
|
+
if (directByName)
|
|
1381
|
+
return directByName;
|
|
1382
|
+
var normalizedStyleName = (_b = this.styleName) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
1383
|
+
if (normalizedStyleName) {
|
|
1384
|
+
try {
|
|
1385
|
+
for (var _c = __values(dictionary.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1386
|
+
var _e = __read(_d.value, 2), name_1 = _e[0], style = _e[1];
|
|
1387
|
+
var styleName = (style.styleName || name_1).toUpperCase();
|
|
1388
|
+
if (name_1.toUpperCase() === normalizedStyleName ||
|
|
1389
|
+
styleName === normalizedStyleName) {
|
|
1390
|
+
return style;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1395
|
+
finally {
|
|
1396
|
+
try {
|
|
1397
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1398
|
+
}
|
|
1399
|
+
finally { if (e_2) throw e_2.error; }
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return undefined;
|
|
1403
|
+
};
|
|
1404
|
+
/**
|
|
1405
|
+
* Applies style-element color and linetype traits to renderer traits.
|
|
1406
|
+
* BYBLOCK and BYLAYER colors are ignored.
|
|
1407
|
+
*
|
|
1408
|
+
* @param mlineStyle Resolved style object.
|
|
1409
|
+
* @param elementIndex Style element index.
|
|
1410
|
+
* @param traits Mutable renderer trait set.
|
|
1411
|
+
*/
|
|
1412
|
+
AcDbMLine.prototype.applyStyleElementTraits = function (mlineStyle, elementIndex, traits) {
|
|
1413
|
+
var _a;
|
|
1414
|
+
var styleElement = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.elements[elementIndex];
|
|
1415
|
+
if (!styleElement)
|
|
1416
|
+
return;
|
|
1417
|
+
var lineType = this.resolveStyleElementLineType(styleElement.lineType);
|
|
1418
|
+
if (lineType) {
|
|
1419
|
+
traits.lineType = lineType;
|
|
1420
|
+
}
|
|
1421
|
+
if (styleElement.color.isByBlock || styleElement.color.isByLayer)
|
|
1422
|
+
return;
|
|
1423
|
+
traits.color = styleElement.color.clone();
|
|
1424
|
+
traits.rgbColor = (_a = styleElement.color.RGB) !== null && _a !== void 0 ? _a : this.rgbColor;
|
|
1425
|
+
};
|
|
1426
|
+
/**
|
|
1427
|
+
* Applies fill color traits from style definition to the renderer traits object.
|
|
1428
|
+
* BYBLOCK and BYLAYER colors are ignored.
|
|
1429
|
+
*
|
|
1430
|
+
* @param mlineStyle Resolved style object.
|
|
1431
|
+
* @param traits Mutable renderer trait set.
|
|
1432
|
+
*/
|
|
1433
|
+
AcDbMLine.prototype.applyFillTraits = function (mlineStyle, traits) {
|
|
1434
|
+
var _a;
|
|
1435
|
+
var fillColor = mlineStyle === null || mlineStyle === void 0 ? void 0 : mlineStyle.fillColor;
|
|
1436
|
+
if (!fillColor || fillColor.isByBlock || fillColor.isByLayer)
|
|
1437
|
+
return;
|
|
1438
|
+
traits.color = fillColor.clone();
|
|
1439
|
+
traits.rgbColor = (_a = fillColor.RGB) !== null && _a !== void 0 ? _a : this.rgbColor;
|
|
1440
|
+
};
|
|
1441
|
+
/**
|
|
1442
|
+
* Resolves a style-element linetype token to concrete renderer linetype traits.
|
|
1443
|
+
*
|
|
1444
|
+
* @param rawLineType Style element linetype token.
|
|
1445
|
+
* @returns Resolved linetype traits, or `undefined` when no override is needed.
|
|
1446
|
+
*/
|
|
1447
|
+
AcDbMLine.prototype.resolveStyleElementLineType = function (rawLineType) {
|
|
1448
|
+
var _a;
|
|
1449
|
+
var lineTypeName = rawLineType === null || rawLineType === void 0 ? void 0 : rawLineType.trim();
|
|
1450
|
+
if (!lineTypeName)
|
|
1451
|
+
return undefined;
|
|
1452
|
+
var normalized = lineTypeName.toUpperCase();
|
|
1453
|
+
var byLayer = ByLayer.toUpperCase();
|
|
1454
|
+
var byBlock = ByBlock.toUpperCase();
|
|
1455
|
+
var type = 'UserSpecified';
|
|
1456
|
+
var resolvedName = lineTypeName;
|
|
1457
|
+
if (normalized === byLayer) {
|
|
1458
|
+
type = 'ByLayer';
|
|
1459
|
+
var layerLineType = (_a = this.database.tables.layerTable.getAt(this.layer)) === null || _a === void 0 ? void 0 : _a.linetype;
|
|
1460
|
+
resolvedName =
|
|
1461
|
+
layerLineType &&
|
|
1462
|
+
layerLineType.toUpperCase() !== byLayer &&
|
|
1463
|
+
layerLineType.toUpperCase() !== byBlock
|
|
1464
|
+
? layerLineType
|
|
1465
|
+
: DEFAULT_LINE_TYPE;
|
|
1466
|
+
}
|
|
1467
|
+
else if (normalized === byBlock) {
|
|
1468
|
+
type = 'ByBlock';
|
|
1469
|
+
resolvedName = DEFAULT_LINE_TYPE;
|
|
1470
|
+
}
|
|
1471
|
+
var lineTypeRecord = this.database.tables.linetypeTable.getAt(resolvedName);
|
|
1472
|
+
if (lineTypeRecord) {
|
|
1473
|
+
return __assign({ type: type }, lineTypeRecord.linetype);
|
|
1474
|
+
}
|
|
1475
|
+
return {
|
|
1476
|
+
type: type,
|
|
1477
|
+
name: resolvedName,
|
|
1478
|
+
standardFlag: 0,
|
|
1479
|
+
description: '',
|
|
1480
|
+
totalPatternLength: 0
|
|
1481
|
+
};
|
|
1482
|
+
};
|
|
1483
|
+
/**
|
|
1484
|
+
* @inheritdoc
|
|
1485
|
+
*/
|
|
1486
|
+
AcDbMLine.prototype.resolveEffectiveProperties = function () {
|
|
1487
|
+
_super.prototype.resolveEffectiveProperties.call(this);
|
|
1488
|
+
if (!this._styleName) {
|
|
1489
|
+
this._styleName = this.getDefaultStyleName();
|
|
1490
|
+
}
|
|
1491
|
+
};
|
|
1492
|
+
/**
|
|
1493
|
+
* Resolves the default style name for newly created MLINE entities.
|
|
1494
|
+
*/
|
|
1495
|
+
AcDbMLine.prototype.getDefaultStyleName = function () {
|
|
1496
|
+
try {
|
|
1497
|
+
return this.database.cmlstyle || DEFAULT_MLINE_STYLE;
|
|
1498
|
+
}
|
|
1499
|
+
catch (_a) {
|
|
1500
|
+
return DEFAULT_MLINE_STYLE;
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
/**
|
|
1504
|
+
* Runtime type name used by the entity factory and RTTI helpers.
|
|
1505
|
+
*/
|
|
1506
|
+
AcDbMLine.typeName = 'MLine';
|
|
1507
|
+
return AcDbMLine;
|
|
1508
|
+
}(AcDbEntity));
|
|
1509
|
+
export { AcDbMLine };
|
|
1510
|
+
//# sourceMappingURL=AcDbMLine.js.map
|