dxf-json 0.0.20 → 0.0.22
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/package.json +5 -2
- package/.github/FUNDING.yml +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/custom.md +0 -10
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/pull_request_template.md +0 -23
- package/.github/workflows/npm-publish.yml +0 -55
- package/.swcrc +0 -8
- package/jest.config.js +0 -20
- package/src/consts/block.ts +0 -22
- package/src/consts/color.ts +0 -6
- package/src/consts/config.ts +0 -2
- package/src/consts/dimension.ts +0 -69
- package/src/consts/hatch.ts +0 -52
- package/src/consts/header.ts +0 -10
- package/src/consts/index.ts +0 -9
- package/src/consts/lineweight.ts +0 -5
- package/src/consts/measurement.ts +0 -4
- package/src/consts/obscuredLineTypes.ts +0 -21
- package/src/consts/scene.ts +0 -2
- package/src/consts/viewport.ts +0 -62
- package/src/index.ts +0 -3
- package/src/parser/AutoCadColorIndex.ts +0 -265
- package/src/parser/DxfArrayScanner.ts +0 -161
- package/src/parser/DxfParser.ts +0 -109
- package/src/parser/ParseHelpers.ts +0 -124
- package/src/parser/blocks/blocks.test.ts +0 -97
- package/src/parser/blocks/index.ts +0 -88
- package/src/parser/blocks/types.ts +0 -15
- package/src/parser/entities/arc/index.ts +0 -2
- package/src/parser/entities/arc/parser.ts +0 -67
- package/src/parser/entities/arc/types.ts +0 -13
- package/src/parser/entities/attdef/consts.ts +0 -12
- package/src/parser/entities/attdef/index.ts +0 -3
- package/src/parser/entities/attdef/parser.ts +0 -119
- package/src/parser/entities/attdef/types.ts +0 -19
- package/src/parser/entities/attribute/consts.ts +0 -6
- package/src/parser/entities/attribute/index.ts +0 -3
- package/src/parser/entities/attribute/parser.ts +0 -198
- package/src/parser/entities/attribute/types.ts +0 -31
- package/src/parser/entities/circle/index.ts +0 -2
- package/src/parser/entities/circle/parser.ts +0 -58
- package/src/parser/entities/circle/types.ts +0 -11
- package/src/parser/entities/dimension/common.ts +0 -98
- package/src/parser/entities/dimension/index.ts +0 -24
- package/src/parser/entities/dimension/types.ts +0 -65
- package/src/parser/entities/ellipse/index.ts +0 -2
- package/src/parser/entities/ellipse/parser.ts +0 -66
- package/src/parser/entities/ellipse/types.ts +0 -13
- package/src/parser/entities/entities.test.ts +0 -86
- package/src/parser/entities/hatch/boundaryPathData/edge.ts +0 -190
- package/src/parser/entities/hatch/boundaryPathData/index.ts +0 -27
- package/src/parser/entities/hatch/boundaryPathData/polyline.ts +0 -43
- package/src/parser/entities/hatch/boundaryPathData/shared.ts +0 -16
- package/src/parser/entities/hatch/index.ts +0 -189
- package/src/parser/entities/hatch/patternData.ts +0 -57
- package/src/parser/entities/hatch/types/boundaryPath.ts +0 -72
- package/src/parser/entities/hatch/types/definitionLine.ts +0 -14
- package/src/parser/entities/hatch/types/hatch.ts +0 -47
- package/src/parser/entities/hatch/types/index.ts +0 -3
- package/src/parser/entities/index.ts +0 -87
- package/src/parser/entities/insert/index.ts +0 -2
- package/src/parser/entities/insert/parser.ts +0 -106
- package/src/parser/entities/insert/types.ts +0 -19
- package/src/parser/entities/leader/consts.ts +0 -6
- package/src/parser/entities/leader/index.ts +0 -3
- package/src/parser/entities/leader/parser.ts +0 -119
- package/src/parser/entities/leader/types.ts +0 -24
- package/src/parser/entities/line/index.ts +0 -2
- package/src/parser/entities/line/parser.ts +0 -55
- package/src/parser/entities/line/types.ts +0 -11
- package/src/parser/entities/lwpolyline/consts.ts +0 -4
- package/src/parser/entities/lwpolyline/index.ts +0 -3
- package/src/parser/entities/lwpolyline/parser.ts +0 -122
- package/src/parser/entities/lwpolyline/types.ts +0 -21
- package/src/parser/entities/mtext/consts.ts +0 -5
- package/src/parser/entities/mtext/index.ts +0 -3
- package/src/parser/entities/mtext/parser.ts +0 -195
- package/src/parser/entities/mtext/types.ts +0 -34
- package/src/parser/entities/point/index.ts +0 -2
- package/src/parser/entities/point/parser.ts +0 -60
- package/src/parser/entities/point/types.ts +0 -10
- package/src/parser/entities/polyline/consts.ts +0 -17
- package/src/parser/entities/polyline/index.ts +0 -3
- package/src/parser/entities/polyline/parser.ts +0 -126
- package/src/parser/entities/polyline/types.ts +0 -20
- package/src/parser/entities/section/index.ts +0 -2
- package/src/parser/entities/section/parser.ts +0 -104
- package/src/parser/entities/section/types.ts +0 -20
- package/src/parser/entities/shared.ts +0 -166
- package/src/parser/entities/solid/index.ts +0 -2
- package/src/parser/entities/solid/parser.ts +0 -56
- package/src/parser/entities/solid/types.ts +0 -10
- package/src/parser/entities/spline/consts.ts +0 -8
- package/src/parser/entities/spline/index.ts +0 -3
- package/src/parser/entities/spline/parser.ts +0 -121
- package/src/parser/entities/spline/types.ts +0 -22
- package/src/parser/entities/text/consts.ts +0 -21
- package/src/parser/entities/text/index.ts +0 -3
- package/src/parser/entities/text/parser.ts +0 -117
- package/src/parser/entities/text/types.ts +0 -21
- package/src/parser/entities/vertex/consts.ts +0 -10
- package/src/parser/entities/vertex/index.ts +0 -3
- package/src/parser/entities/vertex/parser.ts +0 -90
- package/src/parser/entities/vertex/types.ts +0 -17
- package/src/parser/entities/viewport/index.ts +0 -178
- package/src/parser/entities/viewport/types.ts +0 -58
- package/src/parser/filterDummyBlocks.ts +0 -49
- package/src/parser/header/index.ts +0 -30
- package/src/parser/objects/common.ts +0 -55
- package/src/parser/objects/dictionary.ts +0 -61
- package/src/parser/objects/index.ts +0 -45
- package/src/parser/objects/layout.ts +0 -136
- package/src/parser/objects/plotSettings.ts +0 -231
- package/src/parser/objects/treefy.ts +0 -53
- package/src/parser/objects/types.ts +0 -17
- package/src/parser/shared/index.ts +0 -21
- package/src/parser/shared/parsePoint.ts +0 -37
- package/src/parser/shared/parserGenerator.test.ts +0 -164
- package/src/parser/shared/parserGenerator.ts +0 -180
- package/src/parser/shared/xdata/index.ts +0 -3
- package/src/parser/shared/xdata/interpreter.test.ts +0 -85
- package/src/parser/shared/xdata/interpreter.ts +0 -65
- package/src/parser/shared/xdata/parser.test.ts +0 -66
- package/src/parser/shared/xdata/parser.ts +0 -140
- package/src/parser/shared/xdata/types.ts +0 -22
- package/src/parser/tables/blockRecord/index.ts +0 -2
- package/src/parser/tables/blockRecord/parser.ts +0 -49
- package/src/parser/tables/blockRecord/types.ts +0 -11
- package/src/parser/tables/dimStyle/consts.ts +0 -428
- package/src/parser/tables/dimStyle/index.ts +0 -3
- package/src/parser/tables/dimStyle/parser.ts +0 -37
- package/src/parser/tables/dimStyle/types.ts +0 -164
- package/src/parser/tables/index.ts +0 -2
- package/src/parser/tables/layer/index.ts +0 -2
- package/src/parser/tables/layer/parser.ts +0 -58
- package/src/parser/tables/layer/types.ts +0 -14
- package/src/parser/tables/ltype/consts.ts +0 -6
- package/src/parser/tables/ltype/index.ts +0 -3
- package/src/parser/tables/ltype/parser.ts +0 -110
- package/src/parser/tables/ltype/types.ts +0 -23
- package/src/parser/tables/parser.ts +0 -100
- package/src/parser/tables/shared.ts +0 -32
- package/src/parser/tables/style/index.ts +0 -2
- package/src/parser/tables/style/parser.ts +0 -70
- package/src/parser/tables/style/types.ts +0 -15
- package/src/parser/tables/types.ts +0 -15
- package/src/parser/tables/vport/index.ts +0 -2
- package/src/parser/tables/vport/parser.ts +0 -205
- package/src/parser/tables/vport/types.ts +0 -48
- package/src/parser/types.ts +0 -30
- package/src/types/color.ts +0 -5
- package/src/types/dxfHeader.ts +0 -21
- package/src/types/entity.ts +0 -7
- package/src/types/index.ts +0 -30
- package/src/utils/binarySearch.ts +0 -20
- package/src/utils/disjointSet.ts +0 -52
- package/src/utils/flooding.ts +0 -37
- package/src/utils/functional.ts +0 -124
- package/src/utils/graph.ts +0 -53
- package/src/utils/index.ts +0 -102
- package/src/utils/queue.ts +0 -77
- package/src/utils/triangle.ts +0 -28
- package/tsconfig.json +0 -37
- package/webpack.config.js +0 -53
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AutoCad files sometimes use an indexed color value between 1 and 255 inclusive.
|
|
3
|
-
* Each value corresponds to a color. index 1 is red, that is 16711680 or 0xFF0000.
|
|
4
|
-
* index 0 and 256, while included in this array, are actually reserved for inheritance
|
|
5
|
-
* values in AutoCad so they should not be used for index color lookups.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export default [
|
|
9
|
-
0,
|
|
10
|
-
16711680,
|
|
11
|
-
16776960,
|
|
12
|
-
65280,
|
|
13
|
-
65535,
|
|
14
|
-
255,
|
|
15
|
-
16711935,
|
|
16
|
-
16777215,
|
|
17
|
-
8421504,
|
|
18
|
-
12632256,
|
|
19
|
-
16711680,
|
|
20
|
-
16744319,
|
|
21
|
-
13369344,
|
|
22
|
-
13395558,
|
|
23
|
-
10027008,
|
|
24
|
-
10046540,
|
|
25
|
-
8323072,
|
|
26
|
-
8339263,
|
|
27
|
-
4980736,
|
|
28
|
-
4990502,
|
|
29
|
-
16727808,
|
|
30
|
-
16752511,
|
|
31
|
-
13382400,
|
|
32
|
-
13401958,
|
|
33
|
-
10036736,
|
|
34
|
-
10051404,
|
|
35
|
-
8331008,
|
|
36
|
-
8343359,
|
|
37
|
-
4985600,
|
|
38
|
-
4992806,
|
|
39
|
-
16744192,
|
|
40
|
-
16760703,
|
|
41
|
-
13395456,
|
|
42
|
-
13408614,
|
|
43
|
-
10046464,
|
|
44
|
-
10056268,
|
|
45
|
-
8339200,
|
|
46
|
-
8347455,
|
|
47
|
-
4990464,
|
|
48
|
-
4995366,
|
|
49
|
-
16760576,
|
|
50
|
-
16768895,
|
|
51
|
-
13408512,
|
|
52
|
-
13415014,
|
|
53
|
-
10056192,
|
|
54
|
-
10061132,
|
|
55
|
-
8347392,
|
|
56
|
-
8351551,
|
|
57
|
-
4995328,
|
|
58
|
-
4997670,
|
|
59
|
-
16776960,
|
|
60
|
-
16777087,
|
|
61
|
-
13421568,
|
|
62
|
-
13421670,
|
|
63
|
-
10000384,
|
|
64
|
-
10000460,
|
|
65
|
-
8355584,
|
|
66
|
-
8355647,
|
|
67
|
-
5000192,
|
|
68
|
-
5000230,
|
|
69
|
-
12582656,
|
|
70
|
-
14679935,
|
|
71
|
-
10079232,
|
|
72
|
-
11717734,
|
|
73
|
-
7510016,
|
|
74
|
-
8755276,
|
|
75
|
-
6258432,
|
|
76
|
-
7307071,
|
|
77
|
-
3755008,
|
|
78
|
-
4344870,
|
|
79
|
-
8388352,
|
|
80
|
-
12582783,
|
|
81
|
-
6736896,
|
|
82
|
-
10079334,
|
|
83
|
-
5019648,
|
|
84
|
-
7510092,
|
|
85
|
-
4161280,
|
|
86
|
-
6258495,
|
|
87
|
-
2509824,
|
|
88
|
-
3755046,
|
|
89
|
-
4194048,
|
|
90
|
-
10485631,
|
|
91
|
-
3394560,
|
|
92
|
-
8375398,
|
|
93
|
-
2529280,
|
|
94
|
-
6264908,
|
|
95
|
-
2064128,
|
|
96
|
-
5209919,
|
|
97
|
-
1264640,
|
|
98
|
-
3099686,
|
|
99
|
-
65280,
|
|
100
|
-
8388479,
|
|
101
|
-
52224,
|
|
102
|
-
6736998,
|
|
103
|
-
38912,
|
|
104
|
-
5019724,
|
|
105
|
-
32512,
|
|
106
|
-
4161343,
|
|
107
|
-
19456,
|
|
108
|
-
2509862,
|
|
109
|
-
65343,
|
|
110
|
-
8388511,
|
|
111
|
-
52275,
|
|
112
|
-
6737023,
|
|
113
|
-
38950,
|
|
114
|
-
5019743,
|
|
115
|
-
32543,
|
|
116
|
-
4161359,
|
|
117
|
-
19475,
|
|
118
|
-
2509871,
|
|
119
|
-
65407,
|
|
120
|
-
8388543,
|
|
121
|
-
52326,
|
|
122
|
-
6737049,
|
|
123
|
-
38988,
|
|
124
|
-
5019762,
|
|
125
|
-
32575,
|
|
126
|
-
4161375,
|
|
127
|
-
19494,
|
|
128
|
-
2509881,
|
|
129
|
-
65471,
|
|
130
|
-
8388575,
|
|
131
|
-
52377,
|
|
132
|
-
6737074,
|
|
133
|
-
39026,
|
|
134
|
-
5019781,
|
|
135
|
-
32607,
|
|
136
|
-
4161391,
|
|
137
|
-
19513,
|
|
138
|
-
2509890,
|
|
139
|
-
65535,
|
|
140
|
-
8388607,
|
|
141
|
-
52428,
|
|
142
|
-
6737100,
|
|
143
|
-
39064,
|
|
144
|
-
5019800,
|
|
145
|
-
32639,
|
|
146
|
-
4161407,
|
|
147
|
-
19532,
|
|
148
|
-
2509900,
|
|
149
|
-
49151,
|
|
150
|
-
8380415,
|
|
151
|
-
39372,
|
|
152
|
-
6730444,
|
|
153
|
-
29336,
|
|
154
|
-
5014936,
|
|
155
|
-
24447,
|
|
156
|
-
4157311,
|
|
157
|
-
14668,
|
|
158
|
-
2507340,
|
|
159
|
-
32767,
|
|
160
|
-
8372223,
|
|
161
|
-
26316,
|
|
162
|
-
6724044,
|
|
163
|
-
19608,
|
|
164
|
-
5010072,
|
|
165
|
-
16255,
|
|
166
|
-
4153215,
|
|
167
|
-
9804,
|
|
168
|
-
2505036,
|
|
169
|
-
16383,
|
|
170
|
-
8364031,
|
|
171
|
-
13260,
|
|
172
|
-
6717388,
|
|
173
|
-
9880,
|
|
174
|
-
5005208,
|
|
175
|
-
8063,
|
|
176
|
-
4149119,
|
|
177
|
-
4940,
|
|
178
|
-
2502476,
|
|
179
|
-
255,
|
|
180
|
-
8355839,
|
|
181
|
-
204,
|
|
182
|
-
6710988,
|
|
183
|
-
152,
|
|
184
|
-
5000344,
|
|
185
|
-
127,
|
|
186
|
-
4145023,
|
|
187
|
-
76,
|
|
188
|
-
2500172,
|
|
189
|
-
4129023,
|
|
190
|
-
10452991,
|
|
191
|
-
3342540,
|
|
192
|
-
8349388,
|
|
193
|
-
2490520,
|
|
194
|
-
6245528,
|
|
195
|
-
2031743,
|
|
196
|
-
5193599,
|
|
197
|
-
1245260,
|
|
198
|
-
3089996,
|
|
199
|
-
8323327,
|
|
200
|
-
12550143,
|
|
201
|
-
6684876,
|
|
202
|
-
10053324,
|
|
203
|
-
4980888,
|
|
204
|
-
7490712,
|
|
205
|
-
4128895,
|
|
206
|
-
6242175,
|
|
207
|
-
2490444,
|
|
208
|
-
3745356,
|
|
209
|
-
12517631,
|
|
210
|
-
14647295,
|
|
211
|
-
10027212,
|
|
212
|
-
11691724,
|
|
213
|
-
7471256,
|
|
214
|
-
8735896,
|
|
215
|
-
6226047,
|
|
216
|
-
7290751,
|
|
217
|
-
3735628,
|
|
218
|
-
4335180,
|
|
219
|
-
16711935,
|
|
220
|
-
16744447,
|
|
221
|
-
13369548,
|
|
222
|
-
13395660,
|
|
223
|
-
9961624,
|
|
224
|
-
9981080,
|
|
225
|
-
8323199,
|
|
226
|
-
8339327,
|
|
227
|
-
4980812,
|
|
228
|
-
4990540,
|
|
229
|
-
16711871,
|
|
230
|
-
16744415,
|
|
231
|
-
13369497,
|
|
232
|
-
13395634,
|
|
233
|
-
9961586,
|
|
234
|
-
9981061,
|
|
235
|
-
8323167,
|
|
236
|
-
8339311,
|
|
237
|
-
4980793,
|
|
238
|
-
4990530,
|
|
239
|
-
16711807,
|
|
240
|
-
16744383,
|
|
241
|
-
13369446,
|
|
242
|
-
13395609,
|
|
243
|
-
9961548,
|
|
244
|
-
9981042,
|
|
245
|
-
8323135,
|
|
246
|
-
8339295,
|
|
247
|
-
4980774,
|
|
248
|
-
4990521,
|
|
249
|
-
16711743,
|
|
250
|
-
16744351,
|
|
251
|
-
13369395,
|
|
252
|
-
13395583,
|
|
253
|
-
9961510,
|
|
254
|
-
9981023,
|
|
255
|
-
8323103,
|
|
256
|
-
8339279,
|
|
257
|
-
4980755,
|
|
258
|
-
4990511,
|
|
259
|
-
3355443,
|
|
260
|
-
5987163,
|
|
261
|
-
8684676,
|
|
262
|
-
11382189,
|
|
263
|
-
14079702,
|
|
264
|
-
16777215
|
|
265
|
-
];
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { isMatched } from './shared';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface ScannerGroup {
|
|
6
|
-
code: number;
|
|
7
|
-
value: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* DxfArrayScanner
|
|
12
|
-
*
|
|
13
|
-
* Based off the AutoCad 2012 DXF Reference
|
|
14
|
-
* http://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf
|
|
15
|
-
*
|
|
16
|
-
* Reads through an array representing lines of a dxf file. Takes an array and
|
|
17
|
-
* provides an easy interface to extract group code and value pairs.
|
|
18
|
-
* @param data - an array where each element represents a line in the dxf file
|
|
19
|
-
* @constructor
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export default class DxfArrayScanner {
|
|
23
|
-
private _pointer: number;
|
|
24
|
-
private _data: string[];
|
|
25
|
-
private _eof: boolean;
|
|
26
|
-
|
|
27
|
-
lastReadGroup: ScannerGroup = { code: 0, value: 0 }
|
|
28
|
-
|
|
29
|
-
constructor(data: string[]) {
|
|
30
|
-
this._pointer = 0;
|
|
31
|
-
this._data = data;
|
|
32
|
-
this._eof = false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
next() {
|
|
36
|
-
if (!this.hasNext()) {
|
|
37
|
-
if (!this._eof) {
|
|
38
|
-
console.warn(
|
|
39
|
-
'Unexpected end of input: EOF group not read before end of file. Ended on code ' +
|
|
40
|
-
this._data[this._pointer],
|
|
41
|
-
);
|
|
42
|
-
} else {
|
|
43
|
-
console.warn(
|
|
44
|
-
"Cannot call 'next' after EOF group has been read",
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
code: 0,
|
|
49
|
-
value: 'EOF',
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const code = parseInt(this._data[this._pointer++], 10);
|
|
54
|
-
const value = parseGroupValue(code, this._data[this._pointer++]);
|
|
55
|
-
const group = { code, value };
|
|
56
|
-
|
|
57
|
-
if (isMatched(group, 0, 'EOF')) {
|
|
58
|
-
this._eof = true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.lastReadGroup = group;
|
|
62
|
-
return group;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
peek() {
|
|
66
|
-
if (!this.hasNext()) {
|
|
67
|
-
if (!this._eof)
|
|
68
|
-
throw new Error(
|
|
69
|
-
'Unexpected end of input: EOF group not read before end of file. Ended on code ' +
|
|
70
|
-
this._data[this._pointer],
|
|
71
|
-
);
|
|
72
|
-
else
|
|
73
|
-
throw new Error("Cannot call 'next' after EOF group has been read");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let group: ScannerGroup = {
|
|
77
|
-
code: parseInt(this._data[this._pointer]),
|
|
78
|
-
value: 0
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
group.value = parseGroupValue(group.code, this._data[this._pointer + 1]);
|
|
82
|
-
|
|
83
|
-
return group;
|
|
84
|
-
}
|
|
85
|
-
rewind(numberOfGroups?: number | undefined) {
|
|
86
|
-
numberOfGroups = numberOfGroups || 1;
|
|
87
|
-
this._pointer = this._pointer - numberOfGroups * 2;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Returns true if there is another code/value pair (2 elements in the array).
|
|
92
|
-
* @returns {boolean}
|
|
93
|
-
*/
|
|
94
|
-
hasNext() {
|
|
95
|
-
if (this._eof) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
if (this._pointer > this._data.length - 2) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Returns true if the scanner is at the end of the array
|
|
105
|
-
* @returns {boolean}
|
|
106
|
-
*/
|
|
107
|
-
isEOF() {
|
|
108
|
-
return this._eof;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Parse a value to its proper type.
|
|
114
|
-
* See pages 3 - 10 of the AutoCad DXF 2012 reference given at the top of this file
|
|
115
|
-
*
|
|
116
|
-
* @param code
|
|
117
|
-
* @param value
|
|
118
|
-
* @returns {*}
|
|
119
|
-
*/
|
|
120
|
-
function parseGroupValue(code: number, value: string) {
|
|
121
|
-
if (code <= 9) return value;
|
|
122
|
-
if (code >= 10 && code <= 59) return parseFloat(value.trim());
|
|
123
|
-
if (code >= 60 && code <= 99) return parseInt(value.trim());
|
|
124
|
-
if (code >= 100 && code <= 109) return value;
|
|
125
|
-
if (code >= 110 && code <= 149) return parseFloat(value.trim());
|
|
126
|
-
if (code >= 160 && code <= 179) return parseInt(value.trim());
|
|
127
|
-
if (code >= 210 && code <= 239) return parseFloat(value.trim());
|
|
128
|
-
if (code >= 270 && code <= 289) return parseInt(value.trim());
|
|
129
|
-
if (code >= 290 && code <= 299) return parseBoolean(value.trim());
|
|
130
|
-
if (code >= 300 && code <= 369) return value;
|
|
131
|
-
if (code >= 370 && code <= 389) return parseInt(value.trim());
|
|
132
|
-
if (code >= 390 && code <= 399) return value;
|
|
133
|
-
if (code >= 400 && code <= 409) return parseInt(value.trim());
|
|
134
|
-
if (code >= 410 && code <= 419) return value;
|
|
135
|
-
if (code >= 420 && code <= 429) return parseInt(value.trim());
|
|
136
|
-
if (code >= 430 && code <= 439) return value;
|
|
137
|
-
if (code >= 440 && code <= 459) return parseInt(value.trim());
|
|
138
|
-
if (code >= 460 && code <= 469) return parseFloat(value.trim());
|
|
139
|
-
if (code >= 470 && code <= 481) return value;
|
|
140
|
-
if (code === 999) return value;
|
|
141
|
-
if (code >= 1000 && code <= 1009) return value;
|
|
142
|
-
if (code >= 1010 && code <= 1059) return parseFloat(value.trim());
|
|
143
|
-
if (code >= 1060 && code <= 1071) return parseInt(value.trim());
|
|
144
|
-
|
|
145
|
-
console.log('WARNING: Group code does not have a defined type: %j', {
|
|
146
|
-
code: code,
|
|
147
|
-
value: value,
|
|
148
|
-
});
|
|
149
|
-
return value;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Parse a boolean according to a 1 or 0 value
|
|
154
|
-
* @param str
|
|
155
|
-
* @returns {boolean}
|
|
156
|
-
*/
|
|
157
|
-
function parseBoolean(str: string) {
|
|
158
|
-
if (str === '0') return false;
|
|
159
|
-
if (str === '1') return true;
|
|
160
|
-
throw TypeError("String '" + str + "' cannot be cast to Boolean type");
|
|
161
|
-
}
|
package/src/parser/DxfParser.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import DxfArrayScanner from './DxfArrayScanner';
|
|
3
|
-
import { parseHeader } from './header';
|
|
4
|
-
import { parseTables } from './tables';
|
|
5
|
-
import { parseBlocks } from './blocks';
|
|
6
|
-
import { parseEntities } from './entities';
|
|
7
|
-
import { parseObjects } from './objects';
|
|
8
|
-
import { isMatched } from './shared';
|
|
9
|
-
import { filterDummyBlocks } from './filterDummyBlocks';
|
|
10
|
-
import type { ParsedDxf } from './types';
|
|
11
|
-
import { Readable } from 'readable-stream';
|
|
12
|
-
export default class DxfParser {
|
|
13
|
-
parseSync(dxfString: string) {
|
|
14
|
-
const dxfLinesArray = dxfString.split(/\r\n|\r|\n/g);
|
|
15
|
-
const scanner = new DxfArrayScanner(dxfLinesArray);
|
|
16
|
-
if (!scanner.hasNext()) {
|
|
17
|
-
throw Error('Empty file');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return this.parseAll(scanner);
|
|
21
|
-
}
|
|
22
|
-
parseStream(stream: Readable | fs.ReadStream) {
|
|
23
|
-
let dxfString = "";
|
|
24
|
-
const self = this;
|
|
25
|
-
return new Promise<ParsedDxf>((res, rej) => {
|
|
26
|
-
stream.on('data', (chunk) => {
|
|
27
|
-
dxfString += chunk;
|
|
28
|
-
});
|
|
29
|
-
stream.on('end', () => {
|
|
30
|
-
try {
|
|
31
|
-
const dxfLinesArray = dxfString.split(/\r\n|\r|\n/g);
|
|
32
|
-
const scanner = new DxfArrayScanner(dxfLinesArray);
|
|
33
|
-
if (!scanner.hasNext()) {
|
|
34
|
-
throw Error('Empty file');
|
|
35
|
-
}
|
|
36
|
-
res(self.parseAll(scanner));
|
|
37
|
-
} catch (err) {
|
|
38
|
-
rej(err);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
stream.on('error', (err) => {
|
|
42
|
-
rej(err);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async parseFromUrl(url: string, encoding = "utf-8", init?: RequestInit | undefined) {
|
|
48
|
-
const response = await fetch(url, init)
|
|
49
|
-
|
|
50
|
-
if (!response.body) return null;
|
|
51
|
-
|
|
52
|
-
const reader = response.body.getReader()
|
|
53
|
-
let buffer = ""
|
|
54
|
-
let decoder = new TextDecoder(encoding)
|
|
55
|
-
|
|
56
|
-
while (true) {
|
|
57
|
-
const { done, value } = await reader.read()
|
|
58
|
-
if (done) {
|
|
59
|
-
buffer += decoder.decode(new ArrayBuffer(0), { stream: false })
|
|
60
|
-
break
|
|
61
|
-
}
|
|
62
|
-
buffer += decoder.decode(value, { stream: true })
|
|
63
|
-
}
|
|
64
|
-
return this.parseSync(buffer)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
parseAll(scanner: DxfArrayScanner) {
|
|
69
|
-
const dxf: ParsedDxf = {
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
header: {},
|
|
72
|
-
blocks: {},
|
|
73
|
-
entities: [],
|
|
74
|
-
tables: {},
|
|
75
|
-
objects: {
|
|
76
|
-
byName: {},
|
|
77
|
-
byTree: undefined,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
let curr = scanner.next();
|
|
81
|
-
|
|
82
|
-
while (!isMatched(curr, 0, 'EOF')) {
|
|
83
|
-
if (isMatched(curr, 0, 'SECTION')) {
|
|
84
|
-
curr = scanner.next();
|
|
85
|
-
|
|
86
|
-
if (isMatched(curr, 2, 'HEADER')) {
|
|
87
|
-
curr = scanner.next();
|
|
88
|
-
dxf.header = parseHeader(curr, scanner);
|
|
89
|
-
} else if (isMatched(curr, 2, 'BLOCKS')) {
|
|
90
|
-
curr = scanner.next();
|
|
91
|
-
dxf.blocks = parseBlocks(curr, scanner);
|
|
92
|
-
}
|
|
93
|
-
else if (isMatched(curr, 2, 'ENTITIES')) {
|
|
94
|
-
curr = scanner.next();
|
|
95
|
-
dxf.entities = parseEntities(curr, scanner);
|
|
96
|
-
}
|
|
97
|
-
else if (isMatched(curr, 2, 'TABLES')) {
|
|
98
|
-
curr = scanner.next();
|
|
99
|
-
dxf.tables = parseTables(curr, scanner);
|
|
100
|
-
} else if (isMatched(curr, 2, 'OBJECTS')) {
|
|
101
|
-
curr = scanner.next();
|
|
102
|
-
dxf.objects = parseObjects(curr, scanner);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
curr = scanner.next();
|
|
106
|
-
}
|
|
107
|
-
return filterDummyBlocks(dxf);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import AUTO_CAD_COLOR_INDEX from './AutoCadColorIndex';
|
|
2
|
-
import DxfArrayScanner, { ScannerGroup } from './DxfArrayScanner';
|
|
3
|
-
import { CommonDxfEntity, skipApplicationGroups } from './entities/shared';
|
|
4
|
-
import { ViewportEntity } from './entities/viewport/types';
|
|
5
|
-
import { isMatched } from './shared';
|
|
6
|
-
import { parseXData } from './shared/xdata';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Returns the truecolor value of the given AutoCad color index value
|
|
10
|
-
* @param {import('../types').ColorIndex} index
|
|
11
|
-
* @return {import('../types').ColorInstance} truecolor value as a number
|
|
12
|
-
*/
|
|
13
|
-
export function getAcadColor(index: number) {
|
|
14
|
-
return AUTO_CAD_COLOR_INDEX[index];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Some entities may contain embedded object which is started by group 101. All the rest data until
|
|
18
|
-
* end of entity should not be interpreted as entity attributes. There is no documentation for this
|
|
19
|
-
* feature.
|
|
20
|
-
* @param scanner
|
|
21
|
-
*/
|
|
22
|
-
export function skipEmbeddedObject(scanner: DxfArrayScanner) {
|
|
23
|
-
/* Ensure proper start group. */
|
|
24
|
-
scanner.rewind();
|
|
25
|
-
let curr = scanner.next();
|
|
26
|
-
if (curr.code !== 101) {
|
|
27
|
-
throw new Error('Bad call for skipEmbeddedObject()');
|
|
28
|
-
}
|
|
29
|
-
do {
|
|
30
|
-
curr = scanner.next();
|
|
31
|
-
} while (curr.code !== 0);
|
|
32
|
-
scanner.rewind();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Attempts to parse codes common to all entities. Returns true if the group
|
|
37
|
-
* was handled by this function.
|
|
38
|
-
* @param {*} entity - the entity currently being parsed
|
|
39
|
-
* @param {*} curr - the current group being parsed
|
|
40
|
-
*/
|
|
41
|
-
export function checkCommonEntityProperties(entity: CommonDxfEntity, curr: ScannerGroup, scanner: DxfArrayScanner) {
|
|
42
|
-
if (isMatched(curr, 102)) {
|
|
43
|
-
skipApplicationGroups(curr, scanner);
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
switch (curr.code) {
|
|
48
|
-
case 0:
|
|
49
|
-
entity.type = curr.value as string;
|
|
50
|
-
break;
|
|
51
|
-
case 5:
|
|
52
|
-
entity.handle = curr.value as string;
|
|
53
|
-
break;
|
|
54
|
-
case 330:
|
|
55
|
-
if (!entity.ownerDictionarySoftId) {
|
|
56
|
-
entity.ownerDictionarySoftId = curr.value;
|
|
57
|
-
} else {
|
|
58
|
-
entity.ownerBlockRecordSoftId = curr.value;
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
case 360:
|
|
62
|
-
entity.ownerdictionaryHardId = curr.value;
|
|
63
|
-
break;
|
|
64
|
-
case 67:
|
|
65
|
-
entity.isInPaperSpace = !!curr.value;
|
|
66
|
-
break;
|
|
67
|
-
case 8:
|
|
68
|
-
entity.layer = curr.value;
|
|
69
|
-
break;
|
|
70
|
-
// Code 6 of an entity indicates inheritance of properties (eg. color).
|
|
71
|
-
// BYBLOCK means inherits from block
|
|
72
|
-
// BYLAYER (default) mean inherits from layer
|
|
73
|
-
case 6:
|
|
74
|
-
entity.lineType = curr.value;
|
|
75
|
-
break;
|
|
76
|
-
case 347:
|
|
77
|
-
entity.materialObjectHardId = curr.value;
|
|
78
|
-
break;
|
|
79
|
-
case 62: // Acad Index Color. 0 inherits ByBlock. 256 inherits ByLayer. Default is bylayer
|
|
80
|
-
entity.colorIndex = curr.value;
|
|
81
|
-
entity.color = getAcadColor(Math.abs(curr.value));
|
|
82
|
-
break;
|
|
83
|
-
case 370:
|
|
84
|
-
//From https://www.woutware.com/Forum/Topic/955/lineweight?returnUrl=%2FForum%2FUserPosts%3FuserId%3D478262319
|
|
85
|
-
// An integer representing 100th of mm, must be one of the following values:
|
|
86
|
-
// 0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60, 70, 80, 90, 100, 106, 120, 140, 158, 200, 211.
|
|
87
|
-
// -3 = STANDARD, -2 = BYLAYER, -1 = BYBLOCK
|
|
88
|
-
entity.lineweight = curr.value;
|
|
89
|
-
break;
|
|
90
|
-
case 48:
|
|
91
|
-
entity.lineTypeScale = curr.value;
|
|
92
|
-
break;
|
|
93
|
-
case 60:
|
|
94
|
-
entity.isVisible = !!curr.value;
|
|
95
|
-
break;
|
|
96
|
-
case 92:
|
|
97
|
-
entity.proxyByte = curr.value;
|
|
98
|
-
break;
|
|
99
|
-
case 310:
|
|
100
|
-
entity.proxyEntity = curr.value;
|
|
101
|
-
break;
|
|
102
|
-
case 100:
|
|
103
|
-
// general한 목적으로는 현 구조로 여기서 처리 불가
|
|
104
|
-
break;
|
|
105
|
-
case 420:
|
|
106
|
-
entity.color = curr.value;
|
|
107
|
-
break;
|
|
108
|
-
case 430:
|
|
109
|
-
entity.transparency = curr.value;
|
|
110
|
-
break;
|
|
111
|
-
case 390:
|
|
112
|
-
entity.plotStyleHardId = curr.value;
|
|
113
|
-
break;
|
|
114
|
-
case 284:
|
|
115
|
-
entity.shadowMode = curr.value;
|
|
116
|
-
break;
|
|
117
|
-
case 1001:
|
|
118
|
-
entity.xdata = parseXData(curr, scanner);
|
|
119
|
-
break;
|
|
120
|
-
default:
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|