@mlightcad/dxf-json-converter 1.9.0
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 -0
- package/README.md +56 -0
- package/dist/dxf-json-converter.umd.cjs +1 -0
- package/dist/dxf-parser-worker.js +1887 -0
- package/lib/AcDbDxfConverter.d.ts +276 -0
- package/lib/AcDbDxfConverter.d.ts.map +1 -0
- package/lib/AcDbDxfConverter.js +1062 -0
- package/lib/AcDbDxfConverter.js.map +1 -0
- package/lib/AcDbDxfParser.d.ts +23 -0
- package/lib/AcDbDxfParser.d.ts.map +1 -0
- package/lib/AcDbDxfParser.js +82 -0
- package/lib/AcDbDxfParser.js.map +1 -0
- package/lib/AcDbDxfParserWorker.d.ts +2 -0
- package/lib/AcDbDxfParserWorker.d.ts.map +1 -0
- package/lib/AcDbDxfParserWorker.js +76 -0
- package/lib/AcDbDxfParserWorker.js.map +1 -0
- package/lib/AcDbEntitiyConverter.d.ts +156 -0
- package/lib/AcDbEntitiyConverter.d.ts.map +1 -0
- package/lib/AcDbEntitiyConverter.js +1424 -0
- package/lib/AcDbEntitiyConverter.js.map +1 -0
- package/lib/AcDbObjectConverter.d.ts +68 -0
- package/lib/AcDbObjectConverter.d.ts.map +1 -0
- package/lib/AcDbObjectConverter.js +374 -0
- package/lib/AcDbObjectConverter.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,1424 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
var __values = (this && this.__values) || function(o) {
|
|
38
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
39
|
+
if (m) return m.call(o);
|
|
40
|
+
if (o && typeof o.length === "number") return {
|
|
41
|
+
next: function () {
|
|
42
|
+
if (o && i >= o.length) o = void 0;
|
|
43
|
+
return { value: o && o[i++], done: !o };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
|
+
};
|
|
48
|
+
import { AcCmColor, AcCmTransparency, AcDb2dPolyline, AcDb3dPolyline, AcDb3PointAngularDimension, AcDbAlignedDimension, AcDbArc, AcDbAttribute, AcDbAttributeDefinition, AcDbAttributeFlags, AcDbAttributeMTextFlag, AcDbBlockReference, AcDbCircle, AcDbDiametricDimension, AcDbEllipse, AcDbFace, AcDbHatch, AcDbHatchObjectType, AcDbLeader, AcDbLine, AcDbMLeader, AcDbMLeaderContentType, AcDbMLeaderLineType, AcDbMLine, AcDbMText, AcDbOrdinateDimension, AcDbPoint, AcDbPoly2dType, AcDbPoly3dType, AcDbPolyFaceMesh, AcDbPolygonMesh, AcDbPolyline, AcDbRadialDimension, AcDbRasterImage, AcDbRay, AcDbRotatedDimension, AcDbShape, AcDbSpline, AcDbTable, AcDbText, AcDbTrace, AcDbViewport, AcDbWipeout, AcDbXline, AcGeCircArc2d, AcGeEllipseArc2d, AcGeLine2d, AcGeLoop2d, AcGeMathUtil, AcGePoint2d, AcGePoint3d, AcGePolyline2d, AcGeSpline3d, AcGeVector2d, AcGeVector3d, transformOcsPointToWcs } from '@mlightcad/data-model';
|
|
49
|
+
import { HatchSolidFill, SmoothType, VertexFlag } from '@mlightcad/dxf-json/types';
|
|
50
|
+
/**
|
|
51
|
+
* Converts DXF entities to AcDbEntity objects.
|
|
52
|
+
*
|
|
53
|
+
* This class provides functionality to convert various DXF entity types
|
|
54
|
+
* (such as lines, circles, arcs, text, etc.) into their corresponding
|
|
55
|
+
* AcDbEntity objects. It handles the conversion of geometric data,
|
|
56
|
+
* properties, and attributes from DXF format to the internal database format.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const converter = new AcDbEntityConverter();
|
|
61
|
+
* const dxfEntity = { type: 'LINE', startPoint: [0, 0, 0], endPoint: [10, 10, 0] };
|
|
62
|
+
* const acDbEntity = converter.convert(dxfEntity);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
var AcDbEntityConverter = /** @class */ (function () {
|
|
66
|
+
function AcDbEntityConverter() {
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts a DXF entity to an AcDbEntity.
|
|
70
|
+
*
|
|
71
|
+
* This method takes a DXF entity and converts it to the corresponding
|
|
72
|
+
* AcDbEntity type. It first creates the entity using createEntity(),
|
|
73
|
+
* then processes common attributes using processCommonAttrs().
|
|
74
|
+
*
|
|
75
|
+
* @param entity - The DXF entity to convert
|
|
76
|
+
* @returns The converted AcDbEntity, or null if conversion fails
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const dxfLine = { type: 'LINE', startPoint: [0, 0, 0], endPoint: [10, 10, 0] };
|
|
81
|
+
* const acDbLine = converter.convert(dxfLine);
|
|
82
|
+
* if (acDbLine) {
|
|
83
|
+
* console.log('Converted to:', acDbLine.type);
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
AcDbEntityConverter.prototype.convert = function (entity) {
|
|
88
|
+
var dbEntity = this.createEntity(entity);
|
|
89
|
+
if (dbEntity) {
|
|
90
|
+
this.processCommonAttrs(entity, dbEntity);
|
|
91
|
+
}
|
|
92
|
+
return dbEntity;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Creates the corresponding drawing database entity from DXF format data.
|
|
96
|
+
*
|
|
97
|
+
* This method acts as a factory that routes DXF entities to their specific
|
|
98
|
+
* conversion methods based on the entity type. It handles all supported
|
|
99
|
+
* DXF entity types including geometric entities, text entities, and special entities.
|
|
100
|
+
*
|
|
101
|
+
* @param entity - Input entity data in DXF format
|
|
102
|
+
* @returns The converted drawing database entity, or null if the entity type is not supported
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const dxfEntity = { type: 'CIRCLE', center: [0, 0, 0], radius: 5 };
|
|
107
|
+
* const acDbEntity = converter.createEntity(dxfEntity);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
AcDbEntityConverter.prototype.createEntity = function (entity) {
|
|
111
|
+
if (entity.type == '3DFACE') {
|
|
112
|
+
return this.convertFace(entity);
|
|
113
|
+
}
|
|
114
|
+
else if (entity.type == 'ARC') {
|
|
115
|
+
return this.convertArc(entity);
|
|
116
|
+
}
|
|
117
|
+
else if (entity.type == 'ATTDEF') {
|
|
118
|
+
return this.convertAttributeDefinition(entity);
|
|
119
|
+
}
|
|
120
|
+
else if (entity.type == 'ATTRIB') {
|
|
121
|
+
return this.convertAttribute(entity);
|
|
122
|
+
}
|
|
123
|
+
else if (entity.type == 'CIRCLE') {
|
|
124
|
+
return this.convertCirle(entity);
|
|
125
|
+
}
|
|
126
|
+
else if (entity.type == 'DIMENSION') {
|
|
127
|
+
return this.convertDimension(entity);
|
|
128
|
+
}
|
|
129
|
+
else if (entity.type == 'ELLIPSE') {
|
|
130
|
+
return this.convertEllipse(entity);
|
|
131
|
+
}
|
|
132
|
+
else if (entity.type == 'HATCH') {
|
|
133
|
+
return this.convertHatch(entity);
|
|
134
|
+
}
|
|
135
|
+
else if (entity.type == 'IMAGE') {
|
|
136
|
+
return this.convertImage(entity);
|
|
137
|
+
}
|
|
138
|
+
else if (entity.type == 'LEADER') {
|
|
139
|
+
return this.convertLeader(entity);
|
|
140
|
+
}
|
|
141
|
+
else if (entity.type == 'LINE') {
|
|
142
|
+
return this.convertLine(entity);
|
|
143
|
+
}
|
|
144
|
+
else if (entity.type == 'LWPOLYLINE') {
|
|
145
|
+
return this.convertLWPolyline(entity);
|
|
146
|
+
}
|
|
147
|
+
else if (entity.type == 'MTEXT') {
|
|
148
|
+
return this.convertMText(entity);
|
|
149
|
+
}
|
|
150
|
+
else if (entity.type == 'MLINE') {
|
|
151
|
+
return this.convertMLine(entity);
|
|
152
|
+
}
|
|
153
|
+
else if (entity.type == 'MULTILEADER' || entity.type == 'MLEADER') {
|
|
154
|
+
return this.convertMLeader(entity);
|
|
155
|
+
}
|
|
156
|
+
else if (entity.type == 'POLYLINE') {
|
|
157
|
+
return this.convertPolyline(entity);
|
|
158
|
+
}
|
|
159
|
+
else if (entity.type == 'POINT') {
|
|
160
|
+
return this.convertPoint(entity);
|
|
161
|
+
}
|
|
162
|
+
else if (entity.type == 'RAY') {
|
|
163
|
+
return this.convertRay(entity);
|
|
164
|
+
}
|
|
165
|
+
else if (entity.type == 'SPLINE') {
|
|
166
|
+
return this.convertSpline(entity);
|
|
167
|
+
}
|
|
168
|
+
else if (entity.type == 'ACAD_TABLE') {
|
|
169
|
+
return this.convertTable(entity);
|
|
170
|
+
}
|
|
171
|
+
else if (entity.type == 'TEXT') {
|
|
172
|
+
return this.convertText(entity);
|
|
173
|
+
}
|
|
174
|
+
else if (entity.type == 'SHAPE') {
|
|
175
|
+
return this.convertShape(entity);
|
|
176
|
+
}
|
|
177
|
+
else if (entity.type == 'SOLID') {
|
|
178
|
+
return this.convertSolid(entity);
|
|
179
|
+
}
|
|
180
|
+
else if (entity.type == 'VIEWPORT') {
|
|
181
|
+
return this.convertViewport(entity);
|
|
182
|
+
}
|
|
183
|
+
else if (entity.type == 'WIPEOUT') {
|
|
184
|
+
return this.convertWipeout(entity);
|
|
185
|
+
}
|
|
186
|
+
else if (entity.type == 'XLINE') {
|
|
187
|
+
return this.convertXline(entity);
|
|
188
|
+
}
|
|
189
|
+
else if (entity.type == 'INSERT') {
|
|
190
|
+
return this.convertBlockReference(entity);
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Converts a DXF 3DFACE entity to an AcDbFace.
|
|
196
|
+
*
|
|
197
|
+
* @param face - The DXF 3DFace entity to convert
|
|
198
|
+
* @returns The converted AcDbFace entity
|
|
199
|
+
*/
|
|
200
|
+
AcDbEntityConverter.prototype.convertFace = function (face) {
|
|
201
|
+
var dbEntity = new AcDbFace();
|
|
202
|
+
face.vertices.forEach(function (vertex, index) {
|
|
203
|
+
return dbEntity.setVertexAt(index, vertex);
|
|
204
|
+
});
|
|
205
|
+
return dbEntity;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Converts a DXF arc entity to an AcDbArc.
|
|
209
|
+
*
|
|
210
|
+
* @param arc - The DXF arc entity to convert
|
|
211
|
+
* @returns The converted AcDbArc entity
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const dxfArc = { type: 'ARC', center: [0, 0, 0], radius: 5, startAngle: 0, endAngle: 90 };
|
|
216
|
+
* const acDbArc = converter.convertArc(dxfArc);
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
AcDbEntityConverter.prototype.convertArc = function (arc) {
|
|
220
|
+
var _a;
|
|
221
|
+
var normal = (_a = arc.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS;
|
|
222
|
+
var dbEntity = new AcDbArc(transformOcsPointToWcs(arc.center, normal), arc.radius, AcGeMathUtil.degToRad(arc.startAngle), AcGeMathUtil.degToRad(arc.endAngle), normal);
|
|
223
|
+
return dbEntity;
|
|
224
|
+
};
|
|
225
|
+
AcDbEntityConverter.prototype.convertAttributeCommon = function (attrib, dbAttrib) {
|
|
226
|
+
var _a, _b;
|
|
227
|
+
dbAttrib.textString = attrib.text;
|
|
228
|
+
dbAttrib.height = attrib.textHeight;
|
|
229
|
+
dbAttrib.position.copy(attrib.startPoint);
|
|
230
|
+
// Propagate DXF group 11 (alignment point) used when halign/valign are
|
|
231
|
+
// non-default. Falls back to startPoint when missing or zero so the
|
|
232
|
+
// alignment anchor never collapses to the world origin — see notes in
|
|
233
|
+
// `libredwg-converter` for the same defensive handling.
|
|
234
|
+
var ap = attrib.alignmentPoint;
|
|
235
|
+
var isApZero = !ap || (ap.x === 0 && ap.y === 0 && ((_a = ap.z) !== null && _a !== void 0 ? _a : 0) === 0);
|
|
236
|
+
if (ap && !isApZero) {
|
|
237
|
+
dbAttrib.alignmentPoint.copy(ap);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
dbAttrib.alignmentPoint.copy(attrib.startPoint);
|
|
241
|
+
}
|
|
242
|
+
dbAttrib.rotation = attrib.rotation;
|
|
243
|
+
dbAttrib.oblique = (_b = attrib.obliqueAngle) !== null && _b !== void 0 ? _b : 0;
|
|
244
|
+
dbAttrib.thickness = attrib.thickness;
|
|
245
|
+
dbAttrib.tag = attrib.tag;
|
|
246
|
+
dbAttrib.fieldLength = 0; // dxf-json doesn't have this field
|
|
247
|
+
dbAttrib.isInvisible =
|
|
248
|
+
(attrib.attributeFlag & AcDbAttributeFlags.Invisible) !== 0;
|
|
249
|
+
dbAttrib.isConst = (attrib.attributeFlag & AcDbAttributeFlags.Const) !== 0;
|
|
250
|
+
dbAttrib.isVerifiable =
|
|
251
|
+
(attrib.attributeFlag & AcDbAttributeFlags.Verifiable) !== 0;
|
|
252
|
+
dbAttrib.isPreset = (attrib.attributeFlag & AcDbAttributeFlags.Preset) !== 0;
|
|
253
|
+
dbAttrib.isReallyLocked = !!attrib.isReallyLocked;
|
|
254
|
+
dbAttrib.isMTextAttribute =
|
|
255
|
+
(attrib.mtextFlag & AcDbAttributeMTextFlag.MultiLine) !== 0;
|
|
256
|
+
dbAttrib.isConstMTextAttribute =
|
|
257
|
+
(attrib.mtextFlag & AcDbAttributeMTextFlag.ConstMultiLine) !== 0;
|
|
258
|
+
};
|
|
259
|
+
AcDbEntityConverter.prototype.convertAttribute = function (attrib) {
|
|
260
|
+
var _a;
|
|
261
|
+
var dbAttrib = new AcDbAttribute();
|
|
262
|
+
this.convertAttributeCommon(attrib, dbAttrib);
|
|
263
|
+
dbAttrib.styleName = attrib.textStyle;
|
|
264
|
+
dbAttrib.horizontalMode =
|
|
265
|
+
attrib.horizontalJustification;
|
|
266
|
+
dbAttrib.verticalMode = attrib.verticalJustification;
|
|
267
|
+
dbAttrib.widthFactor = (_a = attrib.scale) !== null && _a !== void 0 ? _a : 1;
|
|
268
|
+
dbAttrib.lockPositionInBlock = attrib.lockPositionFlag;
|
|
269
|
+
return dbAttrib;
|
|
270
|
+
};
|
|
271
|
+
AcDbEntityConverter.prototype.convertAttributeDefinition = function (attrib) {
|
|
272
|
+
var _a;
|
|
273
|
+
var dbAttDef = new AcDbAttributeDefinition();
|
|
274
|
+
this.convertAttributeCommon(attrib, dbAttDef);
|
|
275
|
+
dbAttDef.styleName = attrib.styleName;
|
|
276
|
+
dbAttDef.horizontalMode = attrib.halign;
|
|
277
|
+
dbAttDef.verticalMode = attrib.valign;
|
|
278
|
+
dbAttDef.widthFactor = (_a = attrib.xScale) !== null && _a !== void 0 ? _a : 1;
|
|
279
|
+
dbAttDef.prompt = attrib.prompt;
|
|
280
|
+
return dbAttDef;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Converts a DXF circle entity to an AcDbCircle.
|
|
284
|
+
*
|
|
285
|
+
* @param circle - The DXF circle entity to convert
|
|
286
|
+
* @returns The converted AcDbCircle entity
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* const dxfCircle = { type: 'CIRCLE', center: [0, 0, 0], radius: 5 };
|
|
291
|
+
* const acDbCircle = converter.convertCirle(dxfCircle);
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
AcDbEntityConverter.prototype.convertCirle = function (circle) {
|
|
295
|
+
var _a;
|
|
296
|
+
var normal = (_a = circle.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS;
|
|
297
|
+
var dbEntity = new AcDbCircle(transformOcsPointToWcs(circle.center, normal), circle.radius, normal);
|
|
298
|
+
return dbEntity;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Converts a DXF ellipse entity to an AcDbEllipse.
|
|
302
|
+
*
|
|
303
|
+
* @param ellipse - The DXF ellipse entity to convert
|
|
304
|
+
* @returns The converted AcDbEllipse entity
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const dxfEllipse = { type: 'ELLIPSE', center: [0, 0, 0], majorAxisEndPoint: [5, 0, 0] };
|
|
309
|
+
* const acDbEllipse = converter.convertEllipse(dxfEllipse);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
AcDbEntityConverter.prototype.convertEllipse = function (ellipse) {
|
|
313
|
+
var _a;
|
|
314
|
+
var majorAxis = new AcGeVector3d(ellipse.majorAxisEndPoint);
|
|
315
|
+
var majorAxisRadius = majorAxis.length();
|
|
316
|
+
var dbEntity = new AcDbEllipse(ellipse.center, (_a = ellipse.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS, majorAxis, majorAxisRadius, majorAxisRadius * ellipse.axisRatio, ellipse.startAngle, ellipse.endAngle);
|
|
317
|
+
return dbEntity;
|
|
318
|
+
};
|
|
319
|
+
AcDbEntityConverter.prototype.convertLine = function (line) {
|
|
320
|
+
var start = line.startPoint;
|
|
321
|
+
var end = line.endPoint;
|
|
322
|
+
var dbEntity = new AcDbLine(new AcGePoint3d(start.x, start.y, start.z || 0), new AcGePoint3d(end.x, end.y, end.z || 0));
|
|
323
|
+
return dbEntity;
|
|
324
|
+
};
|
|
325
|
+
AcDbEntityConverter.prototype.convertSpline = function (spline) {
|
|
326
|
+
// Catch error to construct spline because it maybe one spline in one block.
|
|
327
|
+
// If don't catch the error, the block conversion may be interruptted.
|
|
328
|
+
try {
|
|
329
|
+
if (spline.numberOfControlPoints > 0 && spline.numberOfKnots > 0) {
|
|
330
|
+
return new AcDbSpline(spline.controlPoints, spline.knots, spline.weights, spline.degree, !!(spline.flag & 0x01));
|
|
331
|
+
}
|
|
332
|
+
else if (spline.numberOfFitPoints > 0) {
|
|
333
|
+
return new AcDbSpline(spline.fitPoints, 'Uniform', spline.degree, !!(spline.flag & 0x01));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
console.log("Failed to convert spline with error: ".concat(error));
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
};
|
|
341
|
+
AcDbEntityConverter.prototype.convertPoint = function (point) {
|
|
342
|
+
var dbEntity = new AcDbPoint();
|
|
343
|
+
dbEntity.position = point.position;
|
|
344
|
+
return dbEntity;
|
|
345
|
+
};
|
|
346
|
+
AcDbEntityConverter.prototype.convertShape = function (shape) {
|
|
347
|
+
var _a, _b, _c;
|
|
348
|
+
var dbEntity = new AcDbShape();
|
|
349
|
+
dbEntity.position.copy(shape.insertionPoint);
|
|
350
|
+
dbEntity.size = shape.size;
|
|
351
|
+
dbEntity.name = shape.shapeName;
|
|
352
|
+
dbEntity.rotation = AcGeMathUtil.degToRad(shape.rotation || 0);
|
|
353
|
+
dbEntity.widthFactor = (_a = shape.xScale) !== null && _a !== void 0 ? _a : 1;
|
|
354
|
+
dbEntity.oblique = AcGeMathUtil.degToRad(shape.obliqueAngle || 0);
|
|
355
|
+
dbEntity.thickness = (_b = shape.thickness) !== null && _b !== void 0 ? _b : 0;
|
|
356
|
+
dbEntity.normal.copy((_c = shape.extrusionDirection) !== null && _c !== void 0 ? _c : { x: 0, y: 0, z: 1 });
|
|
357
|
+
return dbEntity;
|
|
358
|
+
};
|
|
359
|
+
AcDbEntityConverter.prototype.convertSolid = function (solid) {
|
|
360
|
+
var dbEntity = new AcDbTrace();
|
|
361
|
+
solid.points.forEach(function (point, index) { return dbEntity.setPointAt(index, point); });
|
|
362
|
+
dbEntity.thickness = solid.thickness;
|
|
363
|
+
return dbEntity;
|
|
364
|
+
};
|
|
365
|
+
AcDbEntityConverter.prototype.convertPolyline = function (polyline) {
|
|
366
|
+
var _a;
|
|
367
|
+
// Polyline flag (bit-coded; default = 0):
|
|
368
|
+
// https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-ABF6B778-BE20-4B49-9B58-A94E64CEFFF3
|
|
369
|
+
//
|
|
370
|
+
// 1 = This is a closed polyline (or a polygon mesh closed in the M direction)
|
|
371
|
+
// 2 = Curve-fit vertices have been added
|
|
372
|
+
// 4 = Spline-fit vertices have been added
|
|
373
|
+
// 8 = This is a 3D polyline
|
|
374
|
+
// 16 = This is a 3D polygon mesh
|
|
375
|
+
// 32 = The polygon mesh is closed in the N direction
|
|
376
|
+
// 64 = The polyline is a polyface mesh
|
|
377
|
+
// 128 = The linetype pattern is generated continuously around the vertices of this polyline
|
|
378
|
+
var isClosed = !!(polyline.flag & 0x01);
|
|
379
|
+
var is3dPolyline = !!(polyline.flag & 0x08);
|
|
380
|
+
var isPolygonMesh = !!(polyline.flag & 0x10); // 16
|
|
381
|
+
var isPolyfaceMesh = !!(polyline.flag & 0x40); // 64
|
|
382
|
+
var isClosedN = !!(polyline.flag & 0x20); // 32
|
|
383
|
+
// Filter out spline control points
|
|
384
|
+
var vertices = [];
|
|
385
|
+
var bulges = [];
|
|
386
|
+
var faces = [];
|
|
387
|
+
(_a = polyline.vertices) === null || _a === void 0 ? void 0 : _a.map(function (vertex) {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
if (!(vertex.flag & VertexFlag.SPLINE_CONTROL_POINT)) {
|
|
390
|
+
// For polyface mesh, vertex flag 128 bit is set for all vertices
|
|
391
|
+
if (isPolyfaceMesh && vertex.flag & 0x80) {
|
|
392
|
+
// 128 bit set
|
|
393
|
+
// Check if this is a face vertex (64 bit not set)
|
|
394
|
+
if (!(vertex.flag & 0x40)) {
|
|
395
|
+
// 64 bit not set
|
|
396
|
+
if (vertex.faces && vertex.faces.length >= 3) {
|
|
397
|
+
faces.push(__spreadArray([], __read(vertex.faces), false));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
// This is a regular vertex (64 bit set)
|
|
402
|
+
vertices.push({
|
|
403
|
+
x: vertex.x,
|
|
404
|
+
y: vertex.y,
|
|
405
|
+
z: vertex.z
|
|
406
|
+
});
|
|
407
|
+
bulges.push((_a = vertex.bulge) !== null && _a !== void 0 ? _a : 0);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
// This is a regular vertex
|
|
412
|
+
vertices.push({
|
|
413
|
+
x: vertex.x,
|
|
414
|
+
y: vertex.y,
|
|
415
|
+
z: vertex.z
|
|
416
|
+
});
|
|
417
|
+
bulges.push((_b = vertex.bulge) !== null && _b !== void 0 ? _b : 0);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
if (isPolygonMesh) {
|
|
422
|
+
// For polygon mesh, we need M and N counts
|
|
423
|
+
// In DXF, these are stored in the polyline entity as 71 and 72 group codes
|
|
424
|
+
var mCount = polyline.meshMVertexCount;
|
|
425
|
+
var nCount = polyline.meshNVertexCount;
|
|
426
|
+
return new AcDbPolygonMesh(mCount, nCount, vertices, isClosed, isClosedN);
|
|
427
|
+
}
|
|
428
|
+
else if (isPolyfaceMesh) {
|
|
429
|
+
return new AcDbPolyFaceMesh(vertices, faces);
|
|
430
|
+
}
|
|
431
|
+
else if (is3dPolyline) {
|
|
432
|
+
var polyType = AcDbPoly3dType.SimplePoly;
|
|
433
|
+
if (polyline.flag & 0x04) {
|
|
434
|
+
if (polyline.smoothType == SmoothType.CUBIC) {
|
|
435
|
+
polyType = AcDbPoly3dType.CubicSplinePoly;
|
|
436
|
+
}
|
|
437
|
+
else if (polyline.smoothType == SmoothType.QUADRATIC) {
|
|
438
|
+
polyType = AcDbPoly3dType.QuadSplinePoly;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return new AcDb3dPolyline(polyType, vertices, isClosed);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
var polyType = AcDbPoly2dType.SimplePoly;
|
|
445
|
+
if (polyline.flag & 0x02) {
|
|
446
|
+
polyType = AcDbPoly2dType.FitCurvePoly;
|
|
447
|
+
}
|
|
448
|
+
else if (polyline.flag & 0x04) {
|
|
449
|
+
if (polyline.smoothType == SmoothType.CUBIC) {
|
|
450
|
+
polyType = AcDbPoly2dType.CubicSplinePoly;
|
|
451
|
+
}
|
|
452
|
+
else if (polyline.smoothType == SmoothType.QUADRATIC) {
|
|
453
|
+
polyType = AcDbPoly2dType.QuadSplinePoly;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return new AcDb2dPolyline(polyType, vertices, 0, isClosed, polyline.startWidth, polyline.endWidth, bulges);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
AcDbEntityConverter.prototype.convertLWPolyline = function (polyline) {
|
|
460
|
+
var _a, _b;
|
|
461
|
+
var dbEntity = new AcDbPolyline();
|
|
462
|
+
dbEntity.closed = !!(polyline.flag & 0x01);
|
|
463
|
+
var defaultWidth = (_a = polyline.constantWidth) !== null && _a !== void 0 ? _a : -1;
|
|
464
|
+
(_b = polyline.vertices) === null || _b === void 0 ? void 0 : _b.forEach(function (vertex, index) {
|
|
465
|
+
var _a, _b;
|
|
466
|
+
dbEntity.addVertexAt(index, new AcGePoint2d(vertex.x, vertex.y), vertex.bulge, (_a = vertex.startWidth) !== null && _a !== void 0 ? _a : defaultWidth, (_b = vertex.endWidth) !== null && _b !== void 0 ? _b : defaultWidth);
|
|
467
|
+
});
|
|
468
|
+
return dbEntity;
|
|
469
|
+
};
|
|
470
|
+
AcDbEntityConverter.prototype.convertHatch = function (hatch) {
|
|
471
|
+
var _a, _b, _c, _d;
|
|
472
|
+
var dbEntity = new AcDbHatch();
|
|
473
|
+
(_a = hatch.definitionLines) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
|
|
474
|
+
dbEntity.definitionLines.push({
|
|
475
|
+
angle: AcGeMathUtil.degToRad(item.angle || 0),
|
|
476
|
+
base: item.base,
|
|
477
|
+
offset: item.offset,
|
|
478
|
+
dashLengths: item.numberOfDashLengths > 0 ? item.dashLengths : []
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
dbEntity.isSolidFill = hatch.solidFill == HatchSolidFill.SolidFill;
|
|
482
|
+
dbEntity.hatchStyle = hatch.hatchStyle;
|
|
483
|
+
dbEntity.patternName = hatch.patternName;
|
|
484
|
+
dbEntity.patternType = hatch.patternType;
|
|
485
|
+
dbEntity.patternAngle =
|
|
486
|
+
hatch.patternAngle == null ? 0 : AcGeMathUtil.degToRad(hatch.patternAngle);
|
|
487
|
+
dbEntity.patternScale = hatch.patternScale == null ? 0 : hatch.patternScale;
|
|
488
|
+
var paths = hatch.boundaryPaths;
|
|
489
|
+
paths.forEach(function (path) {
|
|
490
|
+
var flag = path.boundaryPathTypeFlag;
|
|
491
|
+
// Check whether it is a polyline
|
|
492
|
+
if (flag & 0x02) {
|
|
493
|
+
var polylinePath = path;
|
|
494
|
+
var polyline_1 = new AcGePolyline2d();
|
|
495
|
+
polyline_1.closed = polylinePath.isClosed;
|
|
496
|
+
polylinePath.vertices.forEach(function (vertex, index) {
|
|
497
|
+
polyline_1.addVertexAt(index, {
|
|
498
|
+
x: vertex.x,
|
|
499
|
+
y: vertex.y,
|
|
500
|
+
bulge: vertex.bulge
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
dbEntity.add(polyline_1);
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
var edgePath = path;
|
|
507
|
+
var edges_1 = [];
|
|
508
|
+
edgePath.edges.forEach(function (edge) {
|
|
509
|
+
if (edge.type == 1) {
|
|
510
|
+
var line = edge;
|
|
511
|
+
edges_1.push(new AcGeLine2d(line.start, line.end));
|
|
512
|
+
}
|
|
513
|
+
else if (edge.type == 2) {
|
|
514
|
+
var arc = edge;
|
|
515
|
+
edges_1.push(new AcGeCircArc2d(arc.center, arc.radius, AcGeMathUtil.degToRad(arc.startAngle || 0), AcGeMathUtil.degToRad(arc.endAngle || 0), !arc.isCCW));
|
|
516
|
+
}
|
|
517
|
+
else if (edge.type == 3) {
|
|
518
|
+
var ellipse = edge;
|
|
519
|
+
var majorAxis = new AcGeVector2d();
|
|
520
|
+
majorAxis.subVectors(ellipse.end, ellipse.center);
|
|
521
|
+
var majorAxisRadius = Math.sqrt(Math.pow(ellipse.end.x, 2) + Math.pow(ellipse.end.y, 2));
|
|
522
|
+
// Property name 'lengthOfMinorAxis' is really confusing.
|
|
523
|
+
// Actually length of minor axis means percentage of major axis length.
|
|
524
|
+
var minorAxisRadius = majorAxisRadius * ellipse.lengthOfMinorAxis;
|
|
525
|
+
var startAngle = AcGeMathUtil.degToRad(ellipse.startAngle || 0);
|
|
526
|
+
var endAngle = AcGeMathUtil.degToRad(ellipse.endAngle || 0);
|
|
527
|
+
var rotation = Math.atan2(ellipse.end.y, ellipse.end.x);
|
|
528
|
+
if (!ellipse.isCCW) {
|
|
529
|
+
// when clockwise, need to handle start/end angles
|
|
530
|
+
startAngle = Math.PI * 2 - startAngle;
|
|
531
|
+
endAngle = Math.PI * 2 - endAngle;
|
|
532
|
+
}
|
|
533
|
+
edges_1.push(new AcGeEllipseArc2d(__assign(__assign({}, ellipse.center), { z: 0 }), majorAxisRadius, minorAxisRadius, startAngle, endAngle, !ellipse.isCCW, rotation));
|
|
534
|
+
}
|
|
535
|
+
else if (edge.type == 4) {
|
|
536
|
+
var spline = edge;
|
|
537
|
+
if (spline.numberOfControlPoints > 0 && spline.numberOfKnots > 0) {
|
|
538
|
+
var controlPoints = spline.controlPoints.map(function (item) {
|
|
539
|
+
return {
|
|
540
|
+
x: item.x,
|
|
541
|
+
y: item.y,
|
|
542
|
+
z: 0
|
|
543
|
+
};
|
|
544
|
+
});
|
|
545
|
+
var hasWeights_1 = true;
|
|
546
|
+
var weights = spline.controlPoints.map(function (item) {
|
|
547
|
+
if (item.weight == null)
|
|
548
|
+
hasWeights_1 = false;
|
|
549
|
+
return item.weight || 1;
|
|
550
|
+
});
|
|
551
|
+
edges_1.push(new AcGeSpline3d(controlPoints, spline.knots, hasWeights_1 ? weights : undefined));
|
|
552
|
+
}
|
|
553
|
+
else if (spline.numberOfFitData > 0) {
|
|
554
|
+
var fitPoints = spline.fitDatum.map(function (item) {
|
|
555
|
+
return {
|
|
556
|
+
x: item.x,
|
|
557
|
+
y: item.y,
|
|
558
|
+
z: 0
|
|
559
|
+
};
|
|
560
|
+
});
|
|
561
|
+
edges_1.push(new AcGeSpline3d(fitPoints, 'Uniform'));
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
var loops = AcGeLoop2d.buildFromEdges(edges_1);
|
|
566
|
+
if (loops.length == 0 && edges_1.length > 0) {
|
|
567
|
+
// Fallback: keep original order if we failed to build any loop.
|
|
568
|
+
dbEntity.add(new AcGeLoop2d(edges_1));
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
loops.forEach(function (loop) { return dbEntity.add(loop); });
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
// Handle gradient fill properties
|
|
576
|
+
// The meaning of gradientFlag is as follows.
|
|
577
|
+
// - 0: Solid hatch
|
|
578
|
+
// - 1: Gradient
|
|
579
|
+
if (hatch.gradientFlag) {
|
|
580
|
+
var gradientHatch = hatch;
|
|
581
|
+
dbEntity.hatchObjectType = AcDbHatchObjectType.GradientObject;
|
|
582
|
+
dbEntity.gradientName = gradientHatch.gradientName;
|
|
583
|
+
dbEntity.gradientAngle = (_b = gradientHatch.gradientRotation) !== null && _b !== void 0 ? _b : 0;
|
|
584
|
+
dbEntity.gradientShift = (_c = gradientHatch.gradientDefinition) !== null && _c !== void 0 ? _c : 0;
|
|
585
|
+
dbEntity.gradientOneColorMode = gradientHatch.gradientColorFlag == 1;
|
|
586
|
+
dbEntity.shadeTintValue = (_d = gradientHatch.colorTint) !== null && _d !== void 0 ? _d : 0;
|
|
587
|
+
if (gradientHatch.gradientColors) {
|
|
588
|
+
var length_1 = gradientHatch.gradientColors.length;
|
|
589
|
+
if (length_1 > 1) {
|
|
590
|
+
dbEntity.gradientStartColor = gradientHatch.gradientColors[0].rgb;
|
|
591
|
+
dbEntity.gradientEndColor = gradientHatch.gradientColors[1].rgb;
|
|
592
|
+
}
|
|
593
|
+
else if (length_1 > 0) {
|
|
594
|
+
dbEntity.gradientStartColor = gradientHatch.gradientColors[0].rgb;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return dbEntity;
|
|
599
|
+
};
|
|
600
|
+
AcDbEntityConverter.prototype.convertTable = function (table) {
|
|
601
|
+
var dbEntity = new AcDbTable(table.name, table.rowCount, table.columnCount);
|
|
602
|
+
dbEntity.tableDataVersion = table.version;
|
|
603
|
+
dbEntity.tableStyleId = table.tableStyleId;
|
|
604
|
+
dbEntity.owningBlockRecordId = table.blockRecordHandle;
|
|
605
|
+
if (table.directionVector) {
|
|
606
|
+
dbEntity.horizontalDirection = new AcGeVector3d(table.directionVector);
|
|
607
|
+
}
|
|
608
|
+
dbEntity.attachmentPoint =
|
|
609
|
+
table.attachmentPoint;
|
|
610
|
+
dbEntity.position.copy(table.startPoint);
|
|
611
|
+
dbEntity.tableValueFlag = table.tableValue;
|
|
612
|
+
dbEntity.tableOverrideFlag = table.overrideFlag;
|
|
613
|
+
dbEntity.borderColorOverrideFlag = table.borderColorOverrideFlag;
|
|
614
|
+
dbEntity.borderLineweightOverrideFlag = table.borderLineWeightOverrideFlag;
|
|
615
|
+
dbEntity.borderVisibilityOverrideFlag = table.borderVisibilityOverrideFlag;
|
|
616
|
+
table.columnWidthArr.forEach(function (width, index) {
|
|
617
|
+
return dbEntity.setColumnWidth(index, width);
|
|
618
|
+
});
|
|
619
|
+
table.rowHeightArr.forEach(function (height, index) {
|
|
620
|
+
return dbEntity.setRowHeight(index, height);
|
|
621
|
+
});
|
|
622
|
+
table.cells.forEach(function (cell, index) {
|
|
623
|
+
dbEntity.setCell(index, cell);
|
|
624
|
+
});
|
|
625
|
+
return dbEntity;
|
|
626
|
+
};
|
|
627
|
+
AcDbEntityConverter.prototype.convertText = function (text) {
|
|
628
|
+
var _a, _b, _c;
|
|
629
|
+
var dbEntity = new AcDbText();
|
|
630
|
+
dbEntity.textString = text.text;
|
|
631
|
+
dbEntity.styleName = text.styleName;
|
|
632
|
+
dbEntity.height = text.textHeight;
|
|
633
|
+
dbEntity.position.copy(text.startPoint);
|
|
634
|
+
// dxf-json calls DXF group 11 `endPoint` on TEXT; this is the alignment
|
|
635
|
+
// point used when halign/valign deviate from Left/Baseline. Fall back to
|
|
636
|
+
// startPoint when missing or zero — same defensive handling as in
|
|
637
|
+
// `convertAttributeCommon`.
|
|
638
|
+
var ep = text.endPoint;
|
|
639
|
+
var isEpZero = !ep || (ep.x === 0 && ep.y === 0 && ((_a = ep.z) !== null && _a !== void 0 ? _a : 0) === 0);
|
|
640
|
+
if (ep && !isEpZero) {
|
|
641
|
+
dbEntity.alignmentPoint.copy(ep);
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
dbEntity.alignmentPoint.copy(text.startPoint);
|
|
645
|
+
}
|
|
646
|
+
dbEntity.rotation = AcGeMathUtil.degToRad(text.rotation || 0);
|
|
647
|
+
dbEntity.oblique = (_b = text.obliqueAngle) !== null && _b !== void 0 ? _b : 0;
|
|
648
|
+
dbEntity.thickness = text.thickness;
|
|
649
|
+
dbEntity.horizontalMode = text.halign;
|
|
650
|
+
dbEntity.verticalMode = text.valign;
|
|
651
|
+
dbEntity.widthFactor = (_c = text.xScale) !== null && _c !== void 0 ? _c : 1;
|
|
652
|
+
return dbEntity;
|
|
653
|
+
};
|
|
654
|
+
AcDbEntityConverter.prototype.convertMText = function (mtext) {
|
|
655
|
+
var dbEntity = new AcDbMText();
|
|
656
|
+
dbEntity.contents = mtext.text;
|
|
657
|
+
if (mtext.styleName != null) {
|
|
658
|
+
dbEntity.styleName = mtext.styleName;
|
|
659
|
+
}
|
|
660
|
+
dbEntity.height = mtext.height;
|
|
661
|
+
dbEntity.width = mtext.width;
|
|
662
|
+
dbEntity.rotation = AcGeMathUtil.degToRad(mtext.rotation || 0);
|
|
663
|
+
dbEntity.location = mtext.insertionPoint;
|
|
664
|
+
dbEntity.attachmentPoint =
|
|
665
|
+
mtext.attachmentPoint;
|
|
666
|
+
if (mtext.direction) {
|
|
667
|
+
dbEntity.direction = new AcGeVector3d(mtext.direction);
|
|
668
|
+
}
|
|
669
|
+
dbEntity.drawingDirection =
|
|
670
|
+
mtext.drawingDirection;
|
|
671
|
+
return dbEntity;
|
|
672
|
+
};
|
|
673
|
+
AcDbEntityConverter.prototype.convertLeader = function (leader) {
|
|
674
|
+
var _a, _b, _c, _d, _e;
|
|
675
|
+
var dbEntity = new AcDbLeader();
|
|
676
|
+
(_a = leader.vertices) === null || _a === void 0 ? void 0 : _a.forEach(function (point) {
|
|
677
|
+
dbEntity.appendVertex(point);
|
|
678
|
+
});
|
|
679
|
+
dbEntity.hasArrowHead = leader.isArrowheadEnabled;
|
|
680
|
+
dbEntity.hasHookLine = leader.isHooklineExists;
|
|
681
|
+
dbEntity.isHookLineSameDirection = leader.isHooklineSameDirection;
|
|
682
|
+
dbEntity.isSplined = leader.isSpline;
|
|
683
|
+
dbEntity.dimensionStyle = (_b = leader.styleName) !== null && _b !== void 0 ? _b : '';
|
|
684
|
+
dbEntity.annoType =
|
|
685
|
+
leader.leaderCreationFlag;
|
|
686
|
+
dbEntity.textHeight = (_c = leader.textHeight) !== null && _c !== void 0 ? _c : 0;
|
|
687
|
+
dbEntity.textWidth = (_d = leader.textWidth) !== null && _d !== void 0 ? _d : 0;
|
|
688
|
+
dbEntity.byBlockColor = leader.byBlockColor;
|
|
689
|
+
dbEntity.associatedAnnotation = (_e = leader.associatedAnnotation) !== null && _e !== void 0 ? _e : '';
|
|
690
|
+
if (leader.normal)
|
|
691
|
+
dbEntity.normal = leader.normal;
|
|
692
|
+
if (leader.horizontalDirection) {
|
|
693
|
+
dbEntity.horizontalDirection = leader.horizontalDirection;
|
|
694
|
+
}
|
|
695
|
+
if (leader.offsetFromBlock)
|
|
696
|
+
dbEntity.offsetFromBlock = leader.offsetFromBlock;
|
|
697
|
+
if (leader.offsetFromAnnotation) {
|
|
698
|
+
dbEntity.offsetFromAnnotation = leader.offsetFromAnnotation;
|
|
699
|
+
}
|
|
700
|
+
return dbEntity;
|
|
701
|
+
};
|
|
702
|
+
AcDbEntityConverter.prototype.convertMLine = function (mline) {
|
|
703
|
+
var _a, _b;
|
|
704
|
+
var dbEntity = new AcDbMLine();
|
|
705
|
+
dbEntity.styleName = mline.name || 'STANDARD';
|
|
706
|
+
dbEntity.styleObjectHandle = mline.styleObjectHandle;
|
|
707
|
+
dbEntity.scale = mline.scale;
|
|
708
|
+
dbEntity.justification =
|
|
709
|
+
mline.justification;
|
|
710
|
+
dbEntity.flags = mline.flags;
|
|
711
|
+
dbEntity.styleCount = mline.styleCount;
|
|
712
|
+
dbEntity.startPosition = mline.startPosition;
|
|
713
|
+
dbEntity.normal = (_a = mline.extrusionDirection) !== null && _a !== void 0 ? _a : AcGeVector3d.Z_AXIS;
|
|
714
|
+
dbEntity.segments = ((_b = mline.segments) !== null && _b !== void 0 ? _b : []).map(function (segment) {
|
|
715
|
+
var _a, _b;
|
|
716
|
+
return ({
|
|
717
|
+
position: segment.position,
|
|
718
|
+
direction: segment.direction,
|
|
719
|
+
miterDirection: segment.miterDirection,
|
|
720
|
+
elements: (_b = (_a = segment.elements) === null || _a === void 0 ? void 0 : _a.map(function (element) {
|
|
721
|
+
var _a, _b;
|
|
722
|
+
return ({
|
|
723
|
+
parameterCount: element.parameterCount,
|
|
724
|
+
parameters: (_a = element.parameters) !== null && _a !== void 0 ? _a : [],
|
|
725
|
+
fillCount: element.fillCount,
|
|
726
|
+
fillParameters: (_b = element.fillParameters) !== null && _b !== void 0 ? _b : []
|
|
727
|
+
});
|
|
728
|
+
})) !== null && _b !== void 0 ? _b : []
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
return dbEntity;
|
|
732
|
+
};
|
|
733
|
+
AcDbEntityConverter.prototype.convertMLeader = function (mleader) {
|
|
734
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
735
|
+
var dbEntity = new AcDbMLeader();
|
|
736
|
+
var raw = mleader;
|
|
737
|
+
dbEntity.version = mleader.version;
|
|
738
|
+
dbEntity.leaderStyleId = mleader.leaderStyleId;
|
|
739
|
+
if (mleader.leaderStyleId)
|
|
740
|
+
dbEntity.mleaderStyleId = mleader.leaderStyleId;
|
|
741
|
+
dbEntity.propertyOverrideFlag = mleader.propertyOverrideFlag;
|
|
742
|
+
dbEntity.leaderLineType = ((_a = mleader.leaderLineType) !== null && _a !== void 0 ? _a : AcDbMLeaderLineType.StraightLeader);
|
|
743
|
+
dbEntity.leaderLineColor = mleader.leaderLineColor;
|
|
744
|
+
dbEntity.leaderLineTypeId = mleader.leaderLineTypeId;
|
|
745
|
+
dbEntity.leaderLineWeight = mleader.leaderLineWeight;
|
|
746
|
+
dbEntity.landingEnabled = mleader.landingEnabled;
|
|
747
|
+
dbEntity.doglegEnabled = (_b = mleader.doglegEnabled) !== null && _b !== void 0 ? _b : false;
|
|
748
|
+
dbEntity.doglegLength = (_c = mleader.doglegLength) !== null && _c !== void 0 ? _c : 0;
|
|
749
|
+
dbEntity.arrowheadId = mleader.arrowheadId;
|
|
750
|
+
dbEntity.arrowheadSize = mleader.arrowheadSize;
|
|
751
|
+
dbEntity.textStyleId = mleader.textStyleId;
|
|
752
|
+
dbEntity.textLeftAttachmentType = mleader.textLeftAttachmentType;
|
|
753
|
+
dbEntity.textRightAttachmentType = mleader.textRightAttachmentType;
|
|
754
|
+
dbEntity.textAngleType = mleader.textAngleType;
|
|
755
|
+
dbEntity.textAlignmentType = mleader.textAlignmentType;
|
|
756
|
+
dbEntity.textColor = mleader.textColor;
|
|
757
|
+
dbEntity.textFrameEnabled = mleader.textFrameEnabled;
|
|
758
|
+
dbEntity.landingGap = mleader.landingGap;
|
|
759
|
+
dbEntity.textAttachment = mleader.textAttachment;
|
|
760
|
+
dbEntity.textFlowDirection = mleader.textFlowDirection;
|
|
761
|
+
dbEntity.blockContentId = mleader.blockContentId;
|
|
762
|
+
dbEntity.blockContentColor = mleader.blockContentColor;
|
|
763
|
+
dbEntity.blockContentRotation = mleader.blockContentRotation;
|
|
764
|
+
dbEntity.blockContentConnectionType = mleader.blockContentConnectionType;
|
|
765
|
+
dbEntity.annotativeScaleEnabled = mleader.annotativeScaleEnabled;
|
|
766
|
+
dbEntity.arrowheadOverrides = mleader.arrowheadOverrides
|
|
767
|
+
? mleader.arrowheadOverrides.map(function (item) { return (__assign({}, item)); })
|
|
768
|
+
: [];
|
|
769
|
+
dbEntity.blockAttributes = mleader.blockAttributes
|
|
770
|
+
? mleader.blockAttributes.map(function (item) { return (__assign({}, item)); })
|
|
771
|
+
: [];
|
|
772
|
+
dbEntity.textDirectionNegative = mleader.textDirectionNegative;
|
|
773
|
+
dbEntity.textAlignInIPE = mleader.textAlignInIPE;
|
|
774
|
+
dbEntity.bottomTextAttachmentDirection =
|
|
775
|
+
mleader.bottomTextAttachmentDirection;
|
|
776
|
+
dbEntity.topTextAttachmentDirection = mleader.topTextAttachmentDirection;
|
|
777
|
+
dbEntity.contentScale = mleader.contentScale;
|
|
778
|
+
dbEntity.textLineSpacingStyle = mleader.textLineSpacingStyle;
|
|
779
|
+
dbEntity.textBackgroundColor = mleader.textBackgroundColor;
|
|
780
|
+
dbEntity.textBackgroundScaleFactor = mleader.textBackgroundScaleFactor;
|
|
781
|
+
dbEntity.textBackgroundTransparency = mleader.textBackgroundTransparency;
|
|
782
|
+
dbEntity.textBackgroundColorOn = mleader.textBackgroundColorOn;
|
|
783
|
+
dbEntity.textFillOn = mleader.textFillOn;
|
|
784
|
+
dbEntity.textColumnType = mleader.textColumnType;
|
|
785
|
+
dbEntity.textUseAutoHeight = mleader.textUseAutoHeight;
|
|
786
|
+
dbEntity.textColumnWidth = mleader.textColumnWidth;
|
|
787
|
+
dbEntity.textColumnGutterWidth = mleader.textColumnGutterWidth;
|
|
788
|
+
dbEntity.textColumnFlowReversed = mleader.textColumnFlowReversed;
|
|
789
|
+
dbEntity.textColumnHeight = mleader.textColumnHeight;
|
|
790
|
+
dbEntity.textUseWordBreak = mleader.textUseWordBreak;
|
|
791
|
+
dbEntity.hasMText = mleader.hasMText;
|
|
792
|
+
dbEntity.hasBlock = mleader.hasBlock;
|
|
793
|
+
dbEntity.planeNormalReversed = mleader.planeNormalReversed;
|
|
794
|
+
if (mleader.blockContentScale) {
|
|
795
|
+
dbEntity.blockContentScale = new AcGeVector3d(mleader.blockContentScale);
|
|
796
|
+
}
|
|
797
|
+
if (mleader.contentBasePosition) {
|
|
798
|
+
dbEntity.contentBasePosition = new AcGePoint3d().copy(mleader.contentBasePosition);
|
|
799
|
+
}
|
|
800
|
+
if (mleader.textAnchor) {
|
|
801
|
+
dbEntity.textAnchor = new AcGePoint3d().copy(mleader.textAnchor);
|
|
802
|
+
}
|
|
803
|
+
if (mleader.planeOrigin) {
|
|
804
|
+
dbEntity.planeOrigin = new AcGePoint3d().copy(mleader.planeOrigin);
|
|
805
|
+
}
|
|
806
|
+
if (mleader.planeXAxisDirection) {
|
|
807
|
+
dbEntity.planeXAxisDirection = new AcGeVector3d(mleader.planeXAxisDirection);
|
|
808
|
+
}
|
|
809
|
+
if (mleader.planeYAxisDirection) {
|
|
810
|
+
dbEntity.planeYAxisDirection = new AcGeVector3d(mleader.planeYAxisDirection);
|
|
811
|
+
}
|
|
812
|
+
var rawTextContent = raw.textContent;
|
|
813
|
+
var rawTextContentRecord = rawTextContent && typeof rawTextContent === 'object'
|
|
814
|
+
? rawTextContent
|
|
815
|
+
: undefined;
|
|
816
|
+
var hasMTextContent = (typeof rawTextContent === 'string' && rawTextContent.length > 0) ||
|
|
817
|
+
this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents']) !=
|
|
818
|
+
null ||
|
|
819
|
+
this.readString(raw, ['text', 'contents', 'mtext']) != null;
|
|
820
|
+
var contentType = (_d = mleader.contentType) !== null && _d !== void 0 ? _d : (hasMTextContent
|
|
821
|
+
? AcDbMLeaderContentType.MTextContent
|
|
822
|
+
: mleader.blockContent
|
|
823
|
+
? AcDbMLeaderContentType.BlockContent
|
|
824
|
+
: AcDbMLeaderContentType.NoneContent);
|
|
825
|
+
dbEntity.contentType = contentType;
|
|
826
|
+
var normal = this.readPoint(raw, ['normal', 'extrusionDirection']);
|
|
827
|
+
if (normal)
|
|
828
|
+
dbEntity.normal = normal;
|
|
829
|
+
var textStyleName = (_e = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
|
|
830
|
+
'styleName',
|
|
831
|
+
'textStyleName',
|
|
832
|
+
'textStyle'
|
|
833
|
+
])) !== null && _e !== void 0 ? _e : this.readString(raw, [
|
|
834
|
+
'textStyleName',
|
|
835
|
+
'textStyle',
|
|
836
|
+
'styleName',
|
|
837
|
+
'textStyleId'
|
|
838
|
+
]);
|
|
839
|
+
if (textStyleName)
|
|
840
|
+
dbEntity.textStyleName = textStyleName;
|
|
841
|
+
var textHeight = (_g = (_f = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
|
|
842
|
+
'textHeight',
|
|
843
|
+
'height'
|
|
844
|
+
])) !== null && _f !== void 0 ? _f : this.readPositiveNumber(raw, [
|
|
845
|
+
'textHeight',
|
|
846
|
+
'mtextHeight',
|
|
847
|
+
'textContentHeight'
|
|
848
|
+
])) !== null && _g !== void 0 ? _g : this.readPositiveNumber(raw, ['arrowheadSize', 'contentScale']);
|
|
849
|
+
if (textHeight != null)
|
|
850
|
+
dbEntity.textHeight = textHeight;
|
|
851
|
+
var textWidth = (_h = this.readPositiveNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
|
|
852
|
+
'textWidth',
|
|
853
|
+
'width'
|
|
854
|
+
])) !== null && _h !== void 0 ? _h : this.readPositiveNumber(raw, [
|
|
855
|
+
'textWidth',
|
|
856
|
+
'mtextWidth',
|
|
857
|
+
'textContentWidth'
|
|
858
|
+
]);
|
|
859
|
+
if (textWidth != null)
|
|
860
|
+
dbEntity.textWidth = textWidth;
|
|
861
|
+
dbEntity.textLineSpacingFactor =
|
|
862
|
+
(_k = (_j = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
|
|
863
|
+
'lineSpacingFactor',
|
|
864
|
+
'textLineSpacingFactor'
|
|
865
|
+
])) !== null && _j !== void 0 ? _j : this.readNumber(raw, ['textLineSpacingFactor'])) !== null && _k !== void 0 ? _k : dbEntity.textLineSpacingFactor;
|
|
866
|
+
var textRotation = (_l = this.readNumber(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
|
|
867
|
+
'textRotation',
|
|
868
|
+
'rotation'
|
|
869
|
+
])) !== null && _l !== void 0 ? _l : this.readNumber(raw, [
|
|
870
|
+
'textRotation',
|
|
871
|
+
'mtextRotation',
|
|
872
|
+
'textContentRotation'
|
|
873
|
+
]);
|
|
874
|
+
if (textRotation != null) {
|
|
875
|
+
dbEntity.textRotation = AcGeMathUtil.degToRad(textRotation);
|
|
876
|
+
}
|
|
877
|
+
var textDirection = this.readPoint(raw, [
|
|
878
|
+
'textDirection',
|
|
879
|
+
'mtextDirection',
|
|
880
|
+
'textDirectionVector'
|
|
881
|
+
]);
|
|
882
|
+
if (textDirection)
|
|
883
|
+
dbEntity.textDirection = textDirection;
|
|
884
|
+
var textAttachmentPoint = this.readNumber(raw, [
|
|
885
|
+
'textAttachmentPoint',
|
|
886
|
+
'attachmentPoint'
|
|
887
|
+
]);
|
|
888
|
+
if (textAttachmentPoint != null) {
|
|
889
|
+
dbEntity.textAttachmentPoint =
|
|
890
|
+
textAttachmentPoint;
|
|
891
|
+
}
|
|
892
|
+
var textAttachmentDirection = mleader.textAttachmentDirection;
|
|
893
|
+
if (textAttachmentDirection != null) {
|
|
894
|
+
dbEntity.textAttachmentDirection =
|
|
895
|
+
textAttachmentDirection;
|
|
896
|
+
}
|
|
897
|
+
var textDrawingDirection = this.readNumber(raw, [
|
|
898
|
+
'textDrawingDirection',
|
|
899
|
+
'drawingDirection'
|
|
900
|
+
]);
|
|
901
|
+
if (textDrawingDirection != null) {
|
|
902
|
+
dbEntity.textDrawingDirection =
|
|
903
|
+
textDrawingDirection;
|
|
904
|
+
}
|
|
905
|
+
var text = typeof rawTextContent === 'string'
|
|
906
|
+
? rawTextContent
|
|
907
|
+
: ((_m = this.readString(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, ['text', 'contents'])) !== null && _m !== void 0 ? _m : this.readString(raw, ['text', 'contents', 'mtext']));
|
|
908
|
+
var anchorPoint = (_o = this.readPoint(rawTextContentRecord !== null && rawTextContentRecord !== void 0 ? rawTextContentRecord : {}, [
|
|
909
|
+
'anchorPoint',
|
|
910
|
+
'textAnchor',
|
|
911
|
+
'textLocation',
|
|
912
|
+
'textPosition',
|
|
913
|
+
'textAnchorPoint'
|
|
914
|
+
])) !== null && _o !== void 0 ? _o : this.readPoint(raw, [
|
|
915
|
+
'textAnchor',
|
|
916
|
+
'textLocation',
|
|
917
|
+
'textPosition',
|
|
918
|
+
'textAnchorPoint',
|
|
919
|
+
'contentBasePosition'
|
|
920
|
+
]);
|
|
921
|
+
if (text != null && anchorPoint) {
|
|
922
|
+
dbEntity.mtextContent = { text: text, anchorPoint: anchorPoint };
|
|
923
|
+
}
|
|
924
|
+
if (mleader.blockContent) {
|
|
925
|
+
var blockRecord = mleader.blockContent;
|
|
926
|
+
dbEntity.blockContent = {
|
|
927
|
+
blockContentId: mleader.blockContent.blockContentId,
|
|
928
|
+
normal: this.readPoint(blockRecord, ['normal']),
|
|
929
|
+
position: mleader.blockContent.position,
|
|
930
|
+
scale: this.readPoint(blockRecord, ['scale']),
|
|
931
|
+
rotation: this.readNumber(blockRecord, ['rotation']),
|
|
932
|
+
color: this.readNumber(blockRecord, ['color']),
|
|
933
|
+
transformationMatrix: Array.isArray(mleader.blockContent.transformationMatrix)
|
|
934
|
+
? mleader.blockContent.transformationMatrix
|
|
935
|
+
: []
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
else if (mleader.blockContentId) {
|
|
939
|
+
dbEntity.blockContent = {
|
|
940
|
+
blockContentId: mleader.blockContentId,
|
|
941
|
+
scale: mleader.blockContentScale,
|
|
942
|
+
rotation: mleader.blockContentRotation,
|
|
943
|
+
color: mleader.blockContentColor,
|
|
944
|
+
transformationMatrix: []
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
(_p = this.readMLeaderLeaders(raw)) === null || _p === void 0 ? void 0 : _p.forEach(function (leader) {
|
|
948
|
+
var _a;
|
|
949
|
+
dbEntity.addLeader({
|
|
950
|
+
lastLeaderLinePoint: leader.lastLeaderLinePoint,
|
|
951
|
+
lastLeaderLinePointSet: leader.lastLeaderLinePointSet,
|
|
952
|
+
doglegVector: leader.doglegVector,
|
|
953
|
+
doglegVectorSet: leader.doglegVectorSet,
|
|
954
|
+
doglegLength: (_a = leader.doglegLength) !== null && _a !== void 0 ? _a : mleader.doglegLength,
|
|
955
|
+
breaks: leader.breaks,
|
|
956
|
+
leaderBranchIndex: leader.leaderBranchIndex,
|
|
957
|
+
leaderLines: leader.leaderLines
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
if (dbEntity.numberOfLeaders === 0) {
|
|
961
|
+
(_q = this.readLeaderLineArray(raw)) === null || _q === void 0 ? void 0 : _q.forEach(function (line) {
|
|
962
|
+
dbEntity.addLeader({
|
|
963
|
+
doglegLength: mleader.doglegLength
|
|
964
|
+
});
|
|
965
|
+
dbEntity.addLeaderLine(dbEntity.numberOfLeaders - 1, line);
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
if (dbEntity.numberOfLeaders === 0 && mleader.contentBasePosition) {
|
|
969
|
+
dbEntity.addLeader({
|
|
970
|
+
lastLeaderLinePoint: mleader.contentBasePosition,
|
|
971
|
+
lastLeaderLinePointSet: true,
|
|
972
|
+
doglegLength: mleader.doglegLength
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
return dbEntity;
|
|
976
|
+
};
|
|
977
|
+
AcDbEntityConverter.prototype.convertDimension = function (dimension) {
|
|
978
|
+
if (dimension.subclassMarker == 'AcDbAlignedDimension') {
|
|
979
|
+
var entity = dimension;
|
|
980
|
+
var dbEntity = new AcDbAlignedDimension(entity.subDefinitionPoint1, entity.subDefinitionPoint2, entity.definitionPoint);
|
|
981
|
+
if (entity.insertionPoint) {
|
|
982
|
+
dbEntity.dimBlockPosition = __assign(__assign({}, entity.insertionPoint), { z: 0 });
|
|
983
|
+
}
|
|
984
|
+
dbEntity.rotation = AcGeMathUtil.degToRad(entity.rotationAngle || 0);
|
|
985
|
+
this.processDimensionCommonAttrs(dimension, dbEntity);
|
|
986
|
+
return dbEntity;
|
|
987
|
+
}
|
|
988
|
+
else if (dimension.subclassMarker == 'AcDbRotatedDimension') {
|
|
989
|
+
var entity = dimension;
|
|
990
|
+
var dbEntity = new AcDbRotatedDimension(entity.subDefinitionPoint1, entity.subDefinitionPoint2, entity.definitionPoint);
|
|
991
|
+
if (entity.insertionPoint) {
|
|
992
|
+
dbEntity.dimBlockPosition = __assign(__assign({}, entity.insertionPoint), { z: 0 });
|
|
993
|
+
}
|
|
994
|
+
dbEntity.rotation = AcGeMathUtil.degToRad(entity.rotationAngle || 0);
|
|
995
|
+
this.processDimensionCommonAttrs(dimension, dbEntity);
|
|
996
|
+
return dbEntity;
|
|
997
|
+
}
|
|
998
|
+
else if (dimension.subclassMarker == 'AcDb3PointAngularDimension') {
|
|
999
|
+
var entity = dimension;
|
|
1000
|
+
var dbEntity = new AcDb3PointAngularDimension(entity.centerPoint, entity.subDefinitionPoint1, entity.subDefinitionPoint2, entity.definitionPoint);
|
|
1001
|
+
this.processDimensionCommonAttrs(dimension, dbEntity);
|
|
1002
|
+
return dbEntity;
|
|
1003
|
+
}
|
|
1004
|
+
else if (dimension.subclassMarker == 'AcDbOrdinateDimension') {
|
|
1005
|
+
var entity = dimension;
|
|
1006
|
+
var dbEntity = new AcDbOrdinateDimension(entity.subDefinitionPoint1, entity.subDefinitionPoint2);
|
|
1007
|
+
this.processDimensionCommonAttrs(dimension, dbEntity);
|
|
1008
|
+
return dbEntity;
|
|
1009
|
+
}
|
|
1010
|
+
else if (dimension.subclassMarker == 'AcDbRadialDimension') {
|
|
1011
|
+
var entity = dimension;
|
|
1012
|
+
var dbEntity = new AcDbRadialDimension(entity.definitionPoint, entity.subDefinitionPoint, entity.leaderLength);
|
|
1013
|
+
this.processDimensionCommonAttrs(dimension, dbEntity);
|
|
1014
|
+
return dbEntity;
|
|
1015
|
+
}
|
|
1016
|
+
else if (dimension.subclassMarker == 'AcDbDiametricDimension') {
|
|
1017
|
+
var entity = dimension;
|
|
1018
|
+
var dbEntity = new AcDbDiametricDimension(entity.definitionPoint, entity.subDefinitionPoint, entity.leaderLength);
|
|
1019
|
+
this.processDimensionCommonAttrs(dimension, dbEntity);
|
|
1020
|
+
return dbEntity;
|
|
1021
|
+
}
|
|
1022
|
+
return null;
|
|
1023
|
+
};
|
|
1024
|
+
AcDbEntityConverter.prototype.processImage = function (image, dbImage) {
|
|
1025
|
+
dbImage.position.copy(image.position);
|
|
1026
|
+
dbImage.brightness = image.brightness;
|
|
1027
|
+
dbImage.contrast = image.contrast;
|
|
1028
|
+
dbImage.fade = image.fade;
|
|
1029
|
+
dbImage.imageSize.copy(image.imageSize);
|
|
1030
|
+
dbImage.isShownClipped = (image.flags | 0x0004) > 0;
|
|
1031
|
+
dbImage.isImageShown = (image.flags | 0x0003) > 0;
|
|
1032
|
+
dbImage.isImageTransparent = (image.flags | 0x0008) > 0;
|
|
1033
|
+
dbImage.imageDefId = image.imageDefHandle;
|
|
1034
|
+
dbImage.isClipped = image.isClipped;
|
|
1035
|
+
image.clippingBoundaryPath.forEach(function (point) {
|
|
1036
|
+
dbImage.clipBoundary.push(new AcGePoint2d(point));
|
|
1037
|
+
});
|
|
1038
|
+
// Calculate the scale factors
|
|
1039
|
+
dbImage.width =
|
|
1040
|
+
Math.sqrt(Math.pow(image.uPixel.x, 2) + Math.pow(image.uPixel.y, 2) + Math.pow(image.uPixel.z, 2)) * image.imageSize.x;
|
|
1041
|
+
dbImage.height =
|
|
1042
|
+
Math.sqrt(Math.pow(image.vPixel.x, 2) + Math.pow(image.vPixel.y, 2) + Math.pow(image.vPixel.z, 2)) * image.imageSize.y;
|
|
1043
|
+
// Calculate the rotation angle
|
|
1044
|
+
// Rotation is determined by the angle of the U-vector relative to the X-axis
|
|
1045
|
+
dbImage.rotation = Math.atan2(image.uPixel.y, image.uPixel.x);
|
|
1046
|
+
};
|
|
1047
|
+
AcDbEntityConverter.prototype.convertImage = function (image) {
|
|
1048
|
+
var dbImage = new AcDbRasterImage();
|
|
1049
|
+
this.processImage(image, dbImage);
|
|
1050
|
+
dbImage.clipBoundaryType =
|
|
1051
|
+
image.clippingBoundaryType;
|
|
1052
|
+
return dbImage;
|
|
1053
|
+
};
|
|
1054
|
+
AcDbEntityConverter.prototype.processWipeout = function (wipeout, dbWipeout) {
|
|
1055
|
+
dbWipeout.position.copy(wipeout.position);
|
|
1056
|
+
dbWipeout.brightness = wipeout.brightness;
|
|
1057
|
+
dbWipeout.contrast = wipeout.contrast;
|
|
1058
|
+
dbWipeout.fade = wipeout.fade;
|
|
1059
|
+
dbWipeout.imageSize.copy(wipeout.imageSize);
|
|
1060
|
+
dbWipeout.isShownClipped = (wipeout.displayFlag | 0x0004) > 0;
|
|
1061
|
+
dbWipeout.isImageShown = (wipeout.displayFlag | 0x0003) > 0;
|
|
1062
|
+
dbWipeout.isImageTransparent = (wipeout.displayFlag | 0x0008) > 0;
|
|
1063
|
+
dbWipeout.imageDefId = wipeout.imageDefHardId;
|
|
1064
|
+
dbWipeout.isClipped = wipeout.isClipping;
|
|
1065
|
+
wipeout.boundary.forEach(function (point) {
|
|
1066
|
+
dbWipeout.clipBoundary.push(new AcGePoint2d(point));
|
|
1067
|
+
});
|
|
1068
|
+
dbWipeout.clipBoundaryType =
|
|
1069
|
+
wipeout.boundaryType;
|
|
1070
|
+
// Calculate the scale factors
|
|
1071
|
+
dbWipeout.width =
|
|
1072
|
+
Math.sqrt(Math.pow(wipeout.uDirection.x, 2) +
|
|
1073
|
+
Math.pow(wipeout.uDirection.y, 2) +
|
|
1074
|
+
Math.pow(wipeout.uDirection.z, 2)) * wipeout.imageSize.x;
|
|
1075
|
+
dbWipeout.height =
|
|
1076
|
+
Math.sqrt(Math.pow(wipeout.vDirection.x, 2) +
|
|
1077
|
+
Math.pow(wipeout.vDirection.y, 2) +
|
|
1078
|
+
Math.pow(wipeout.vDirection.z, 2)) * wipeout.imageSize.y;
|
|
1079
|
+
// Calculate the rotation angle
|
|
1080
|
+
// Rotation is determined by the angle of the U-vector relative to the X-axis
|
|
1081
|
+
dbWipeout.rotation = Math.atan2(wipeout.uDirection.y, wipeout.uDirection.x);
|
|
1082
|
+
};
|
|
1083
|
+
AcDbEntityConverter.prototype.convertWipeout = function (wipeout) {
|
|
1084
|
+
var dbWipeout = new AcDbWipeout();
|
|
1085
|
+
this.processWipeout(wipeout, dbWipeout);
|
|
1086
|
+
return dbWipeout;
|
|
1087
|
+
};
|
|
1088
|
+
AcDbEntityConverter.prototype.convertViewport = function (viewport) {
|
|
1089
|
+
var dbViewport = new AcDbViewport();
|
|
1090
|
+
dbViewport.number = viewport.viewportId;
|
|
1091
|
+
dbViewport.centerPoint.copy(viewport.viewportCenter);
|
|
1092
|
+
dbViewport.height = viewport.height;
|
|
1093
|
+
dbViewport.width = viewport.width;
|
|
1094
|
+
dbViewport.viewCenter.copy(viewport.displayCenter);
|
|
1095
|
+
dbViewport.viewHeight = viewport.viewHeight;
|
|
1096
|
+
return dbViewport;
|
|
1097
|
+
};
|
|
1098
|
+
AcDbEntityConverter.prototype.convertRay = function (ray) {
|
|
1099
|
+
var dbRay = new AcDbRay();
|
|
1100
|
+
dbRay.basePoint.copy(ray.position);
|
|
1101
|
+
dbRay.unitDir.copy(ray.direction);
|
|
1102
|
+
return dbRay;
|
|
1103
|
+
};
|
|
1104
|
+
AcDbEntityConverter.prototype.convertXline = function (xline) {
|
|
1105
|
+
var dbXline = new AcDbXline();
|
|
1106
|
+
dbXline.basePoint.copy(xline.position);
|
|
1107
|
+
dbXline.unitDir.copy(xline.direction);
|
|
1108
|
+
return dbXline;
|
|
1109
|
+
};
|
|
1110
|
+
AcDbEntityConverter.prototype.convertBlockReference = function (blockReference) {
|
|
1111
|
+
var _a;
|
|
1112
|
+
var dbBlockReference = new AcDbBlockReference(blockReference.name);
|
|
1113
|
+
if (blockReference.insertionPoint)
|
|
1114
|
+
dbBlockReference.position.copy(blockReference.insertionPoint);
|
|
1115
|
+
dbBlockReference.scaleFactors.x = blockReference.xScale || 1;
|
|
1116
|
+
dbBlockReference.scaleFactors.y = blockReference.yScale || 1;
|
|
1117
|
+
dbBlockReference.scaleFactors.z = blockReference.zScale || 1;
|
|
1118
|
+
dbBlockReference.rotation =
|
|
1119
|
+
blockReference.rotation != null
|
|
1120
|
+
? AcGeMathUtil.degToRad(blockReference.rotation)
|
|
1121
|
+
: 0;
|
|
1122
|
+
dbBlockReference.normal.copy((_a = blockReference.extrusionDirection) !== null && _a !== void 0 ? _a : { x: 0, y: 0, z: 1 });
|
|
1123
|
+
return dbBlockReference;
|
|
1124
|
+
};
|
|
1125
|
+
AcDbEntityConverter.prototype.processDimensionCommonAttrs = function (entity, dbEntity) {
|
|
1126
|
+
var _a;
|
|
1127
|
+
dbEntity.dimBlockId = entity.name;
|
|
1128
|
+
dbEntity.textPosition.copy(entity.textPoint);
|
|
1129
|
+
dbEntity.textRotation = entity.textRotation || 0;
|
|
1130
|
+
if (entity.textLineSpacingFactor) {
|
|
1131
|
+
dbEntity.textLineSpacingFactor = entity.textLineSpacingFactor;
|
|
1132
|
+
}
|
|
1133
|
+
if (entity.textLineSpacingStyle) {
|
|
1134
|
+
dbEntity.textLineSpacingStyle =
|
|
1135
|
+
entity.textLineSpacingStyle;
|
|
1136
|
+
}
|
|
1137
|
+
dbEntity.dimensionStyleName = entity.styleName;
|
|
1138
|
+
dbEntity.dimensionText = entity.text || '';
|
|
1139
|
+
dbEntity.measurement = entity.measurement;
|
|
1140
|
+
dbEntity.normal.copy((_a = entity.extrusionDirection) !== null && _a !== void 0 ? _a : { x: 0, y: 0, z: 1 });
|
|
1141
|
+
};
|
|
1142
|
+
/**
|
|
1143
|
+
* Processes common attributes from a DXF entity to an AcDbEntity.
|
|
1144
|
+
*
|
|
1145
|
+
* This method copies common properties like layer, object ID, owner ID,
|
|
1146
|
+
* linetype, lineweight, color, visibility, and transparency from the
|
|
1147
|
+
* DXF entity to the corresponding AcDbEntity.
|
|
1148
|
+
*
|
|
1149
|
+
* @param entity - The source DXF entity
|
|
1150
|
+
* @param dbEntity - The target AcDbEntity to populate
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* ```typescript
|
|
1154
|
+
* converter.processCommonAttrs(dxfEntity, acDbEntity);
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
1157
|
+
AcDbEntityConverter.prototype.processCommonAttrs = function (entity, dbEntity) {
|
|
1158
|
+
dbEntity.layer = entity.layer || '0';
|
|
1159
|
+
// I found some dxf file may have entity without handle. If so, let's use objectId
|
|
1160
|
+
// created by AcDbObject constructor instead.
|
|
1161
|
+
if (entity.handle)
|
|
1162
|
+
dbEntity.objectId = entity.handle.toString();
|
|
1163
|
+
dbEntity.ownerId = entity.ownerBlockRecordSoftId || '';
|
|
1164
|
+
if (entity.lineType != null) {
|
|
1165
|
+
dbEntity.lineType = entity.lineType;
|
|
1166
|
+
}
|
|
1167
|
+
if (entity.lineweight != null) {
|
|
1168
|
+
dbEntity.lineWeight = entity.lineweight;
|
|
1169
|
+
}
|
|
1170
|
+
if (entity.lineTypeScale != null) {
|
|
1171
|
+
dbEntity.linetypeScale = entity.lineTypeScale;
|
|
1172
|
+
}
|
|
1173
|
+
// Build the entity color in a fresh AcCmColor and assign it via the
|
|
1174
|
+
// setter. The previous pattern (`dbEntity.color.<prop> = …`) read the
|
|
1175
|
+
// getter and mutated the result, which works for entities whose getter
|
|
1176
|
+
// returns the cached `_color` field but breaks for entities like
|
|
1177
|
+
// AcDbHatch that override the getter to return a clone of an HPCOLOR /
|
|
1178
|
+
// CECOLOR fallback (PR #78). Mutations on a clone are dropped, leaving
|
|
1179
|
+
// the entity stuck on the sysvar default and losing the DXF's RGB.
|
|
1180
|
+
if (entity.color != null || entity.colorIndex != null || entity.colorName) {
|
|
1181
|
+
var color = new AcCmColor();
|
|
1182
|
+
if (entity.color != null) {
|
|
1183
|
+
color.setRGBValue(entity.color);
|
|
1184
|
+
}
|
|
1185
|
+
if (entity.colorIndex != null) {
|
|
1186
|
+
color.colorIndex = entity.colorIndex;
|
|
1187
|
+
}
|
|
1188
|
+
if (entity.colorName) {
|
|
1189
|
+
color.colorName = entity.colorName;
|
|
1190
|
+
}
|
|
1191
|
+
dbEntity.color = color;
|
|
1192
|
+
}
|
|
1193
|
+
if (entity.isVisible != null) {
|
|
1194
|
+
// DXF group code 60 uses 0 => visible, 1 => invisible.
|
|
1195
|
+
// dxf-json parses it with a generic boolean converter, so here:
|
|
1196
|
+
// - false means 0 (visible)
|
|
1197
|
+
// - true means 1 (invisible)
|
|
1198
|
+
dbEntity.visibility = !entity.isVisible;
|
|
1199
|
+
}
|
|
1200
|
+
if (entity.transparency != null) {
|
|
1201
|
+
dbEntity.transparency = AcCmTransparency.deserialize(entity.transparency);
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
AcDbEntityConverter.prototype.readNumber = function (source, names) {
|
|
1205
|
+
var e_1, _a;
|
|
1206
|
+
try {
|
|
1207
|
+
for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
|
|
1208
|
+
var name_1 = names_1_1.value;
|
|
1209
|
+
var value = source[name_1];
|
|
1210
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
1211
|
+
return value;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1215
|
+
finally {
|
|
1216
|
+
try {
|
|
1217
|
+
if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1);
|
|
1218
|
+
}
|
|
1219
|
+
finally { if (e_1) throw e_1.error; }
|
|
1220
|
+
}
|
|
1221
|
+
return undefined;
|
|
1222
|
+
};
|
|
1223
|
+
AcDbEntityConverter.prototype.readPositiveNumber = function (source, names) {
|
|
1224
|
+
var value = this.readNumber(source, names);
|
|
1225
|
+
return value != null && value > 0 ? value : undefined;
|
|
1226
|
+
};
|
|
1227
|
+
AcDbEntityConverter.prototype.readString = function (source, names) {
|
|
1228
|
+
var e_2, _a;
|
|
1229
|
+
try {
|
|
1230
|
+
for (var names_2 = __values(names), names_2_1 = names_2.next(); !names_2_1.done; names_2_1 = names_2.next()) {
|
|
1231
|
+
var name_2 = names_2_1.value;
|
|
1232
|
+
var value = source[name_2];
|
|
1233
|
+
if (typeof value === 'string')
|
|
1234
|
+
return value;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1238
|
+
finally {
|
|
1239
|
+
try {
|
|
1240
|
+
if (names_2_1 && !names_2_1.done && (_a = names_2.return)) _a.call(names_2);
|
|
1241
|
+
}
|
|
1242
|
+
finally { if (e_2) throw e_2.error; }
|
|
1243
|
+
}
|
|
1244
|
+
return undefined;
|
|
1245
|
+
};
|
|
1246
|
+
AcDbEntityConverter.prototype.readBoolean = function (source, names) {
|
|
1247
|
+
var e_3, _a;
|
|
1248
|
+
try {
|
|
1249
|
+
for (var names_3 = __values(names), names_3_1 = names_3.next(); !names_3_1.done; names_3_1 = names_3.next()) {
|
|
1250
|
+
var name_3 = names_3_1.value;
|
|
1251
|
+
var value = source[name_3];
|
|
1252
|
+
if (typeof value === 'boolean')
|
|
1253
|
+
return value;
|
|
1254
|
+
if (typeof value === 'number')
|
|
1255
|
+
return value !== 0;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1259
|
+
finally {
|
|
1260
|
+
try {
|
|
1261
|
+
if (names_3_1 && !names_3_1.done && (_a = names_3.return)) _a.call(names_3);
|
|
1262
|
+
}
|
|
1263
|
+
finally { if (e_3) throw e_3.error; }
|
|
1264
|
+
}
|
|
1265
|
+
return undefined;
|
|
1266
|
+
};
|
|
1267
|
+
AcDbEntityConverter.prototype.readPoint = function (source, names) {
|
|
1268
|
+
var e_4, _a;
|
|
1269
|
+
var _b;
|
|
1270
|
+
try {
|
|
1271
|
+
for (var names_4 = __values(names), names_4_1 = names_4.next(); !names_4_1.done; names_4_1 = names_4.next()) {
|
|
1272
|
+
var name_4 = names_4_1.value;
|
|
1273
|
+
var value = source[name_4];
|
|
1274
|
+
if (this.isPointLike(value))
|
|
1275
|
+
return value;
|
|
1276
|
+
if (Array.isArray(value) &&
|
|
1277
|
+
typeof value[0] === 'number' &&
|
|
1278
|
+
typeof value[1] === 'number') {
|
|
1279
|
+
return { x: value[0], y: value[1], z: (_b = value[2]) !== null && _b !== void 0 ? _b : 0 };
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1284
|
+
finally {
|
|
1285
|
+
try {
|
|
1286
|
+
if (names_4_1 && !names_4_1.done && (_a = names_4.return)) _a.call(names_4);
|
|
1287
|
+
}
|
|
1288
|
+
finally { if (e_4) throw e_4.error; }
|
|
1289
|
+
}
|
|
1290
|
+
return undefined;
|
|
1291
|
+
};
|
|
1292
|
+
AcDbEntityConverter.prototype.readLeaderLineArray = function (source) {
|
|
1293
|
+
var _this = this;
|
|
1294
|
+
var leaderLines = source.leaderLines;
|
|
1295
|
+
if (Array.isArray(leaderLines)) {
|
|
1296
|
+
return leaderLines
|
|
1297
|
+
.map(function (line) {
|
|
1298
|
+
if (!line || typeof line !== 'object')
|
|
1299
|
+
return undefined;
|
|
1300
|
+
var vertices = line.vertices;
|
|
1301
|
+
return Array.isArray(vertices)
|
|
1302
|
+
? vertices.filter(function (point) { return _this.isPointLike(point); })
|
|
1303
|
+
: undefined;
|
|
1304
|
+
})
|
|
1305
|
+
.filter(function (line) { return !!line && line.length > 0; });
|
|
1306
|
+
}
|
|
1307
|
+
var vertices = source.vertices;
|
|
1308
|
+
if (Array.isArray(vertices)) {
|
|
1309
|
+
var line = vertices.filter(function (point) { return _this.isPointLike(point); });
|
|
1310
|
+
return line.length > 0 ? [line] : undefined;
|
|
1311
|
+
}
|
|
1312
|
+
return undefined;
|
|
1313
|
+
};
|
|
1314
|
+
AcDbEntityConverter.prototype.readMLeaderLeaders = function (source) {
|
|
1315
|
+
var _this = this;
|
|
1316
|
+
var leaders = source.leaderSections;
|
|
1317
|
+
if (!Array.isArray(leaders))
|
|
1318
|
+
return undefined;
|
|
1319
|
+
var dbLeaders = [];
|
|
1320
|
+
leaders.forEach(function (leader) {
|
|
1321
|
+
if (!leader || typeof leader !== 'object')
|
|
1322
|
+
return;
|
|
1323
|
+
var leaderRecord = leader;
|
|
1324
|
+
var leaderLines = leaderRecord.leaderLines;
|
|
1325
|
+
var lines = Array.isArray(leaderLines)
|
|
1326
|
+
? leaderLines.reduce(function (result, line) {
|
|
1327
|
+
var dbLine = _this.readMLeaderLine(line);
|
|
1328
|
+
if (dbLine)
|
|
1329
|
+
result.push(dbLine);
|
|
1330
|
+
return result;
|
|
1331
|
+
}, [])
|
|
1332
|
+
: undefined;
|
|
1333
|
+
var dbLeader = {};
|
|
1334
|
+
var lastLeaderLinePoint = _this.readPoint(leaderRecord, [
|
|
1335
|
+
'lastLeaderLinePoint'
|
|
1336
|
+
]);
|
|
1337
|
+
var doglegVector = _this.readPoint(leaderRecord, ['doglegVector']);
|
|
1338
|
+
var doglegLength = _this.readNumber(leaderRecord, ['doglegLength']);
|
|
1339
|
+
var leaderBreaks = _this.readMLeaderBreaks(leaderRecord.breaks);
|
|
1340
|
+
var leaderBranchIndex = _this.readNumber(leaderRecord, [
|
|
1341
|
+
'leaderBranchIndex'
|
|
1342
|
+
]);
|
|
1343
|
+
if (lastLeaderLinePoint)
|
|
1344
|
+
dbLeader.lastLeaderLinePoint = lastLeaderLinePoint;
|
|
1345
|
+
if (leaderRecord.lastLeaderLinePointSet != null) {
|
|
1346
|
+
dbLeader.lastLeaderLinePointSet = _this.readBoolean(leaderRecord, [
|
|
1347
|
+
'lastLeaderLinePointSet'
|
|
1348
|
+
]);
|
|
1349
|
+
}
|
|
1350
|
+
if (doglegVector)
|
|
1351
|
+
dbLeader.doglegVector = doglegVector;
|
|
1352
|
+
if (leaderRecord.doglegVectorSet != null) {
|
|
1353
|
+
dbLeader.doglegVectorSet = _this.readBoolean(leaderRecord, [
|
|
1354
|
+
'doglegVectorSet'
|
|
1355
|
+
]);
|
|
1356
|
+
}
|
|
1357
|
+
if (doglegLength != null)
|
|
1358
|
+
dbLeader.doglegLength = doglegLength;
|
|
1359
|
+
if (leaderBreaks)
|
|
1360
|
+
dbLeader.breaks = leaderBreaks;
|
|
1361
|
+
if (leaderBranchIndex != null) {
|
|
1362
|
+
dbLeader.leaderBranchIndex = leaderBranchIndex;
|
|
1363
|
+
}
|
|
1364
|
+
if (lines)
|
|
1365
|
+
dbLeader.leaderLines = lines;
|
|
1366
|
+
dbLeaders.push(dbLeader);
|
|
1367
|
+
});
|
|
1368
|
+
return dbLeaders;
|
|
1369
|
+
};
|
|
1370
|
+
AcDbEntityConverter.prototype.readMLeaderLine = function (value) {
|
|
1371
|
+
var _this = this;
|
|
1372
|
+
if (!value || typeof value !== 'object')
|
|
1373
|
+
return undefined;
|
|
1374
|
+
var lineRecord = value;
|
|
1375
|
+
var vertices = lineRecord.vertices;
|
|
1376
|
+
var dbVertices = Array.isArray(vertices)
|
|
1377
|
+
? vertices.filter(function (point) { return _this.isPointLike(point); })
|
|
1378
|
+
: [];
|
|
1379
|
+
var dbBreaks = this.readMLeaderBreaks(lineRecord.breaks);
|
|
1380
|
+
var breakPointIndexes = Array.isArray(lineRecord.breakPointIndexes)
|
|
1381
|
+
? lineRecord.breakPointIndexes.filter(function (item) { return typeof item === 'number'; })
|
|
1382
|
+
: undefined;
|
|
1383
|
+
var leaderLineIndex = this.readNumber(lineRecord, ['leaderLineIndex']);
|
|
1384
|
+
return dbVertices.length > 0 || (dbBreaks && dbBreaks.length > 0)
|
|
1385
|
+
? {
|
|
1386
|
+
vertices: dbVertices,
|
|
1387
|
+
breakPointIndexes: breakPointIndexes,
|
|
1388
|
+
leaderLineIndex: leaderLineIndex,
|
|
1389
|
+
breaks: dbBreaks
|
|
1390
|
+
}
|
|
1391
|
+
: undefined;
|
|
1392
|
+
};
|
|
1393
|
+
AcDbEntityConverter.prototype.readMLeaderBreaks = function (value) {
|
|
1394
|
+
var _this = this;
|
|
1395
|
+
if (!Array.isArray(value))
|
|
1396
|
+
return undefined;
|
|
1397
|
+
var breaks = value
|
|
1398
|
+
.map(function (item) {
|
|
1399
|
+
if (!item || typeof item !== 'object')
|
|
1400
|
+
return undefined;
|
|
1401
|
+
var breakRecord = item;
|
|
1402
|
+
var start = _this.readPoint(breakRecord, ['start']);
|
|
1403
|
+
var end = _this.readPoint(breakRecord, ['end']);
|
|
1404
|
+
var index = _this.readNumber(breakRecord, ['index']);
|
|
1405
|
+
if (!start || !end)
|
|
1406
|
+
return undefined;
|
|
1407
|
+
var parsed = { start: start, end: end };
|
|
1408
|
+
if (index != null)
|
|
1409
|
+
parsed.index = index;
|
|
1410
|
+
return parsed;
|
|
1411
|
+
})
|
|
1412
|
+
.filter(function (item) { return !!item; });
|
|
1413
|
+
return breaks.length > 0 ? breaks : undefined;
|
|
1414
|
+
};
|
|
1415
|
+
AcDbEntityConverter.prototype.isPointLike = function (value) {
|
|
1416
|
+
return (!!value &&
|
|
1417
|
+
typeof value === 'object' &&
|
|
1418
|
+
typeof value.x === 'number' &&
|
|
1419
|
+
typeof value.y === 'number');
|
|
1420
|
+
};
|
|
1421
|
+
return AcDbEntityConverter;
|
|
1422
|
+
}());
|
|
1423
|
+
export { AcDbEntityConverter };
|
|
1424
|
+
//# sourceMappingURL=AcDbEntitiyConverter.js.map
|