dxf-json 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  3. package/.github/ISSUE_TEMPLATE/custom.md +10 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  5. package/.github/pull_request_template.md +23 -0
  6. package/.github/workflows/npm-publish.yml +55 -0
  7. package/.swcrc +8 -0
  8. package/LICENSE +674 -0
  9. package/README.md +567 -0
  10. package/jest.config.js +20 -0
  11. package/package.json +56 -0
  12. package/src/consts/block.ts +22 -0
  13. package/src/consts/color.ts +6 -0
  14. package/src/consts/config.ts +2 -0
  15. package/src/consts/dimension.ts +69 -0
  16. package/src/consts/hatch.ts +52 -0
  17. package/src/consts/header.ts +10 -0
  18. package/src/consts/index.ts +9 -0
  19. package/src/consts/lineweight.ts +5 -0
  20. package/src/consts/measurement.ts +4 -0
  21. package/src/consts/obscuredLineTypes.ts +21 -0
  22. package/src/consts/scene.ts +2 -0
  23. package/src/consts/viewport.ts +62 -0
  24. package/src/index.ts +6 -0
  25. package/src/parser/AutoCadColorIndex.ts +265 -0
  26. package/src/parser/DxfArrayScanner.ts +161 -0
  27. package/src/parser/DxfParser.ts +108 -0
  28. package/src/parser/ParseHelpers.ts +124 -0
  29. package/src/parser/blocks/blocks.test.ts +97 -0
  30. package/src/parser/blocks/index.ts +88 -0
  31. package/src/parser/blocks/types.ts +15 -0
  32. package/src/parser/entities/arc/index.ts +2 -0
  33. package/src/parser/entities/arc/parser.ts +67 -0
  34. package/src/parser/entities/arc/types.ts +13 -0
  35. package/src/parser/entities/attdef/consts.ts +12 -0
  36. package/src/parser/entities/attdef/index.ts +3 -0
  37. package/src/parser/entities/attdef/parser.ts +119 -0
  38. package/src/parser/entities/attdef/types.ts +19 -0
  39. package/src/parser/entities/attribute/consts.ts +6 -0
  40. package/src/parser/entities/attribute/index.ts +3 -0
  41. package/src/parser/entities/attribute/parser.ts +198 -0
  42. package/src/parser/entities/attribute/types.ts +31 -0
  43. package/src/parser/entities/circle/index.ts +2 -0
  44. package/src/parser/entities/circle/parser.ts +58 -0
  45. package/src/parser/entities/circle/types.ts +11 -0
  46. package/src/parser/entities/dimension/common.ts +98 -0
  47. package/src/parser/entities/dimension/index.ts +24 -0
  48. package/src/parser/entities/dimension/types.ts +65 -0
  49. package/src/parser/entities/ellipse/index.ts +2 -0
  50. package/src/parser/entities/ellipse/parser.ts +66 -0
  51. package/src/parser/entities/ellipse/types.ts +13 -0
  52. package/src/parser/entities/entities.test.ts +86 -0
  53. package/src/parser/entities/hatch/boundaryPathData/edge.ts +190 -0
  54. package/src/parser/entities/hatch/boundaryPathData/index.ts +27 -0
  55. package/src/parser/entities/hatch/boundaryPathData/polyline.ts +43 -0
  56. package/src/parser/entities/hatch/boundaryPathData/shared.ts +16 -0
  57. package/src/parser/entities/hatch/index.ts +189 -0
  58. package/src/parser/entities/hatch/patternData.ts +57 -0
  59. package/src/parser/entities/hatch/types/boundaryPath.ts +72 -0
  60. package/src/parser/entities/hatch/types/definitionLine.ts +14 -0
  61. package/src/parser/entities/hatch/types/hatch.ts +47 -0
  62. package/src/parser/entities/hatch/types/index.ts +3 -0
  63. package/src/parser/entities/index.ts +87 -0
  64. package/src/parser/entities/insert/index.ts +2 -0
  65. package/src/parser/entities/insert/parser.ts +106 -0
  66. package/src/parser/entities/insert/types.ts +19 -0
  67. package/src/parser/entities/leader/consts.ts +6 -0
  68. package/src/parser/entities/leader/index.ts +3 -0
  69. package/src/parser/entities/leader/parser.ts +119 -0
  70. package/src/parser/entities/leader/types.ts +24 -0
  71. package/src/parser/entities/line/index.ts +2 -0
  72. package/src/parser/entities/line/parser.ts +55 -0
  73. package/src/parser/entities/line/types.ts +11 -0
  74. package/src/parser/entities/lwpolyline/consts.ts +4 -0
  75. package/src/parser/entities/lwpolyline/index.ts +3 -0
  76. package/src/parser/entities/lwpolyline/parser.ts +122 -0
  77. package/src/parser/entities/lwpolyline/types.ts +21 -0
  78. package/src/parser/entities/mtext/consts.ts +5 -0
  79. package/src/parser/entities/mtext/index.ts +3 -0
  80. package/src/parser/entities/mtext/parser.ts +195 -0
  81. package/src/parser/entities/mtext/types.ts +34 -0
  82. package/src/parser/entities/point/index.ts +2 -0
  83. package/src/parser/entities/point/parser.ts +60 -0
  84. package/src/parser/entities/point/types.ts +10 -0
  85. package/src/parser/entities/polyline/consts.ts +17 -0
  86. package/src/parser/entities/polyline/index.ts +3 -0
  87. package/src/parser/entities/polyline/parser.ts +126 -0
  88. package/src/parser/entities/polyline/types.ts +20 -0
  89. package/src/parser/entities/section/index.ts +2 -0
  90. package/src/parser/entities/section/parser.ts +104 -0
  91. package/src/parser/entities/section/types.ts +20 -0
  92. package/src/parser/entities/shared.ts +166 -0
  93. package/src/parser/entities/solid/index.ts +2 -0
  94. package/src/parser/entities/solid/parser.ts +56 -0
  95. package/src/parser/entities/solid/types.ts +10 -0
  96. package/src/parser/entities/spline/consts.ts +8 -0
  97. package/src/parser/entities/spline/index.ts +3 -0
  98. package/src/parser/entities/spline/parser.ts +121 -0
  99. package/src/parser/entities/spline/types.ts +22 -0
  100. package/src/parser/entities/text/consts.ts +21 -0
  101. package/src/parser/entities/text/index.ts +3 -0
  102. package/src/parser/entities/text/parser.ts +117 -0
  103. package/src/parser/entities/text/types.ts +21 -0
  104. package/src/parser/entities/vertex/consts.ts +10 -0
  105. package/src/parser/entities/vertex/index.ts +3 -0
  106. package/src/parser/entities/vertex/parser.ts +90 -0
  107. package/src/parser/entities/vertex/types.ts +17 -0
  108. package/src/parser/entities/viewport/index.ts +178 -0
  109. package/src/parser/entities/viewport/types.ts +58 -0
  110. package/src/parser/filterDummyBlocks.ts +49 -0
  111. package/src/parser/header/index.ts +30 -0
  112. package/src/parser/objects/common.ts +55 -0
  113. package/src/parser/objects/dictionary.ts +61 -0
  114. package/src/parser/objects/index.ts +45 -0
  115. package/src/parser/objects/layout.ts +136 -0
  116. package/src/parser/objects/plotSettings.ts +231 -0
  117. package/src/parser/objects/treefy.ts +53 -0
  118. package/src/parser/objects/types.ts +17 -0
  119. package/src/parser/shared/index.ts +21 -0
  120. package/src/parser/shared/parsePoint.ts +37 -0
  121. package/src/parser/shared/parserGenerator.test.ts +164 -0
  122. package/src/parser/shared/parserGenerator.ts +180 -0
  123. package/src/parser/shared/xdata/index.ts +3 -0
  124. package/src/parser/shared/xdata/interpreter.test.ts +85 -0
  125. package/src/parser/shared/xdata/interpreter.ts +65 -0
  126. package/src/parser/shared/xdata/parser.test.ts +66 -0
  127. package/src/parser/shared/xdata/parser.ts +140 -0
  128. package/src/parser/shared/xdata/types.ts +22 -0
  129. package/src/parser/tables/blockRecord/index.ts +2 -0
  130. package/src/parser/tables/blockRecord/parser.ts +49 -0
  131. package/src/parser/tables/blockRecord/types.ts +11 -0
  132. package/src/parser/tables/dimStyle/consts.ts +428 -0
  133. package/src/parser/tables/dimStyle/index.ts +3 -0
  134. package/src/parser/tables/dimStyle/parser.ts +37 -0
  135. package/src/parser/tables/dimStyle/types.ts +164 -0
  136. package/src/parser/tables/index.ts +2 -0
  137. package/src/parser/tables/layer/index.ts +2 -0
  138. package/src/parser/tables/layer/parser.ts +58 -0
  139. package/src/parser/tables/layer/types.ts +14 -0
  140. package/src/parser/tables/ltype/consts.ts +6 -0
  141. package/src/parser/tables/ltype/index.ts +3 -0
  142. package/src/parser/tables/ltype/parser.ts +110 -0
  143. package/src/parser/tables/ltype/types.ts +23 -0
  144. package/src/parser/tables/parser.ts +100 -0
  145. package/src/parser/tables/shared.ts +32 -0
  146. package/src/parser/tables/style/index.ts +2 -0
  147. package/src/parser/tables/style/parser.ts +70 -0
  148. package/src/parser/tables/style/types.ts +15 -0
  149. package/src/parser/tables/types.ts +15 -0
  150. package/src/parser/tables/vport/index.ts +2 -0
  151. package/src/parser/tables/vport/parser.ts +205 -0
  152. package/src/parser/tables/vport/types.ts +48 -0
  153. package/src/parser/types.ts +30 -0
  154. package/src/types/color.ts +5 -0
  155. package/src/types/dxfHeader.ts +21 -0
  156. package/src/types/entity.ts +7 -0
  157. package/src/types/index.ts +30 -0
  158. package/src/utils/binarySearch.ts +20 -0
  159. package/src/utils/disjointSet.ts +52 -0
  160. package/src/utils/flooding.ts +37 -0
  161. package/src/utils/functional.ts +124 -0
  162. package/src/utils/graph.ts +53 -0
  163. package/src/utils/index.ts +102 -0
  164. package/src/utils/queue.ts +77 -0
  165. package/src/utils/triangle.ts +28 -0
  166. package/tsconfig.json +34 -0
  167. package/webpack.config.js +46 -0
@@ -0,0 +1,69 @@
1
+ // https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-EDD54EAC-A339-4EBA-AEA6-EC8066505E2B
2
+ export enum DimensionType {
3
+ Rotated = 0,
4
+ Aligned = 1,
5
+ Angular = 2,
6
+ Diameter = 3,
7
+ Radius = 4,
8
+ Angular3Point = 5,
9
+ Ordinate = 6,
10
+ ReferenceIsExclusive = 32,
11
+ IsOrdinateXTypeFlag = 64,
12
+ IsCustomTextPositionFlag = 128,
13
+ }
14
+
15
+ export enum AttachmentPoint {
16
+ TopLeft = 1,
17
+ TopCenter = 2,
18
+ TopRight = 3,
19
+ MiddleLeft = 4,
20
+ MiddleCenter = 5,
21
+ MiddleRight = 6,
22
+ BottomLeft = 7,
23
+ BottomCenter = 8,
24
+ BottomRight = 9,
25
+ }
26
+
27
+ export enum DimensionTextLineSpacing {
28
+ AtLeast = 1,
29
+ Exact = 2,
30
+ }
31
+
32
+ export enum DimensionTextVertical {
33
+ Center = 0,
34
+ Above = 1,
35
+ Outside = 2,
36
+ JIS = 3,
37
+ Below = 4,
38
+ }
39
+
40
+ export enum DimensionZeroSuppression {
41
+ Feet = 0,
42
+ None = 1,
43
+ Inch = 2,
44
+ FeetAndInch = 3,
45
+ Leading = 4,
46
+ Trailing = 8,
47
+ LeadingAndTrailing = 12,
48
+ }
49
+
50
+ export enum DimensionZeroSuppressionAngular {
51
+ None = 0,
52
+ Leading = 1,
53
+ Trailing = 2,
54
+ LeadingAndTrailing = 3,
55
+ }
56
+
57
+ export enum DimensionTextHorizontal {
58
+ Center = 0,
59
+ Left = 1,
60
+ Right = 2,
61
+ OverFirst = 3,
62
+ OverSecond = 4,
63
+ }
64
+
65
+ export enum DimensionToleranceTextVertical {
66
+ Bottom = 0,
67
+ Center = 1,
68
+ Top = 2,
69
+ }
@@ -0,0 +1,52 @@
1
+ export enum HatchSolidFill {
2
+ PatternFill = 0,
3
+ SolidFill = 1,
4
+ }
5
+
6
+ export enum HatchAssociativity {
7
+ NonAssociative = 0, // For MPolygon LacksSolidFill
8
+ Associative = 1, // For MPolygon HasSolidFill
9
+ }
10
+
11
+ export enum HatchStyle {
12
+ Normal = 0, // Odd parity area
13
+ Outer = 1, // Outermost area
14
+ Ignore = 2, // Entire area
15
+ }
16
+
17
+ export enum HatchPatternType {
18
+ UserDefined = 0,
19
+ Predefined = 1,
20
+ Custom = 2, // ?
21
+ }
22
+
23
+ export enum HatchBoundaryAnnotation {
24
+ NotAnnotated = 0,
25
+ Annotated = 1,
26
+ }
27
+
28
+ export enum HatchGradientFlag {
29
+ Solid = 0,
30
+ Gradient = 1,
31
+ }
32
+
33
+ export enum HatchGradientColorFlag {
34
+ TwoColor = 0,
35
+ OneColor = 1,
36
+ }
37
+
38
+ export enum BoundaryPathTypeFlag {
39
+ Default = 0,
40
+ External = 1,
41
+ Polyline = 2,
42
+ Derived = 4,
43
+ Textbox = 8,
44
+ Outermost = 16,
45
+ }
46
+
47
+ export enum BoundaryPathEdgeType {
48
+ Line = 1,
49
+ Circular = 2,
50
+ Elliptic = 3,
51
+ Spline = 4,
52
+ }
@@ -0,0 +1,10 @@
1
+ import { ObscuredLineTypes } from './obscuredLineTypes';
2
+
3
+ export const DefaultDxfHeaderVariables = {
4
+ DRAGVS: 'NULL',
5
+ INTERFERECOLOR: 1,
6
+ INTERFEREOBJVS: 'Conceptual',
7
+ INTERFEREVPVS: '3d Wireframe',
8
+ OBSLTYPE: ObscuredLineTypes.Off,
9
+ SHADEDIF: 70,
10
+ };
@@ -0,0 +1,9 @@
1
+ export * from './color';
2
+ export * from './config';
3
+ export * from './dimension';
4
+ export * from './hatch';
5
+ export * from './measurement';
6
+ export * from './obscuredLineTypes';
7
+ export * from './lineweight';
8
+ export * from './scene';
9
+ export * from './viewport';
@@ -0,0 +1,5 @@
1
+ export enum ReservedLineweight {
2
+ Standard = -3,
3
+ ByLayer = -2,
4
+ ByBlock = -1,
5
+ }
@@ -0,0 +1,4 @@
1
+ export enum Measurement {
2
+ English = 0,
3
+ Metric = 1,
4
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Specifies the linetype of obscured lines.
3
+ * Obscured linetypes are independent of zoom level,
4
+ * unlike standard object linetypes.
5
+ *
6
+ * Value 0 turns off display of obscured lines and is the default
7
+ * */
8
+ export enum ObscuredLineTypes {
9
+ Off = 0,
10
+ Solid = 1,
11
+ Dashed = 2,
12
+ Dotted = 3,
13
+ ShotDash = 4,
14
+ MediumDash = 5,
15
+ LongDash = 6,
16
+ DoubleShortDash = 7,
17
+ DoubleMediumDash = 8,
18
+ DoubleLongDash = 9,
19
+ DoubleMediumLongDash = 10,
20
+ SparseDot = 11,
21
+ }
@@ -0,0 +1,2 @@
1
+ /** Use 16-bit indices for indexed geometry. */
2
+ export const INDEXED_CHUNK_SIZE = 0x10000;
@@ -0,0 +1,62 @@
1
+ export enum ViewportStatusFlag {
2
+ PERSPECTIVE_MODE = 0x1,
3
+ FRONT_CLIPPING = 0x2,
4
+ BACK_CLIPPING = 0x4,
5
+ UCS_FOLLOW = 0x8,
6
+ FRONT_CLIP_NOT_AT_EYE = 0x10,
7
+ UCS_ICON_VISIBILITY = 0x20,
8
+ UCS_ICON_AT_ORIGIN = 0x40,
9
+ FAST_ZOOM = 0x80,
10
+ SNAP_MODE = 0x100,
11
+ GRID_MODE = 0x200,
12
+ ISOMETRIC_SNAP_STYLE = 0x400,
13
+ HIDE_PLOT_MODE = 0x800,
14
+ K_ISO_PAIR_TOP = 0x1000,
15
+ K_ISO_PAIR_RIGHT = 0x2000,
16
+ VIEWPORT_ZOOM_LOCKING = 0x4000,
17
+ UNUSED = 0x8000,
18
+ NON_RECTANGULAR_CLIPPING = 0x10000,
19
+ VIEWPORT_OFF = 0x20000,
20
+ GRID_BEYOND_DRAWING_LIMITS = 0x40000,
21
+ ADAPTIVE_GRID_DISPLAY = 0x80000,
22
+ SUBDIVISION_BELOW_SPACING = 0x100000,
23
+ GRID_FOLLOWS_WORKPLANE = 0x200000,
24
+ }
25
+
26
+ export enum RenderMode {
27
+ OPTIMIZED_2D = 0, // classic 2D
28
+ WIREFRAME = 1,
29
+ HIDDEN_LINE = 2,
30
+ FLAT_SHADED = 3,
31
+ GOURAUD_SHADED = 4,
32
+ FLAT_SHADED_WITH_WIREFRAME = 5,
33
+ GOURAUD_SHADED_WITH_WIREFRAME = 6,
34
+ }
35
+
36
+ // viewport가 개별 ucs를 가지고 있는지 여부
37
+ export enum UCSPerViewport {
38
+ UCS_UNCHANGED = 0,
39
+ HAS_OWN_UCS = 1,
40
+ }
41
+
42
+ export enum OrthographicType {
43
+ NON_ORTHOGRAPHIC = 0,
44
+ TOP = 1,
45
+ BOTTOM = 2,
46
+ FRONT = 3,
47
+ BACK = 4,
48
+ LEFT = 5,
49
+ RIGHT = 6,
50
+ }
51
+
52
+ export enum ShadePlotMode {
53
+ AS_DISPLAYED = 0,
54
+ WIREFRAME = 1,
55
+ HIDDEN = 2,
56
+ RENDERED = 3,
57
+ }
58
+
59
+ export enum DefaultLightingType {
60
+ ONE_DISTANT_LIGHT = 0,
61
+ TWO_DISTANT_LIGHTS = 1,
62
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import DxfParser from './parser/DxfParser'
2
+
3
+
4
+ export {
5
+ DxfParser,
6
+ };
@@ -0,0 +1,265 @@
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
+ ];
@@ -0,0 +1,161 @@
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
+ }