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,178 @@
1
+ import type { ViewportEntity } from './types';
2
+ import * as helpers from '../../ParseHelpers';
3
+ import { parsePoint } from '../../shared/parsePoint';
4
+ import {
5
+ pointToVector2,
6
+ pointToVector3,
7
+ } from '../../../utils';
8
+ import { CommonDxfEntity } from '../shared';
9
+
10
+ export default class ViewportParser {
11
+ static ForEntityName = 'VIEWPORT';
12
+
13
+ parseEntity(scanner: any, curr: any) {
14
+ const entity = {} as ViewportEntity;
15
+
16
+ while (curr !== 'EOF') {
17
+ if (curr.code === 0) {
18
+ scanner.rewind();
19
+ return entity;
20
+ }
21
+
22
+ if (!parseViewport(entity, scanner, curr)) {
23
+ helpers.checkCommonEntityProperties(entity as CommonDxfEntity, curr, scanner);
24
+ }
25
+ curr = scanner.next();
26
+ }
27
+
28
+ return entity;
29
+ }
30
+ }
31
+
32
+ function parseViewport(entity: ViewportEntity, scanner: any, curr: any) {
33
+ if (curr === 'EOF') return false;
34
+
35
+ switch (curr.code) {
36
+ case 0:
37
+ return false;
38
+ case 100:
39
+ entity.subclassMarker = curr.value;
40
+ break;
41
+ case 10:
42
+ entity.viewportCenter = pointToVector3(parsePoint(scanner));
43
+ break;
44
+ case 40:
45
+ entity.width = curr.value;
46
+ break;
47
+ case 41:
48
+ entity.height = curr.value;
49
+ break;
50
+ case 68:
51
+ entity.status = curr.value;
52
+ break;
53
+ case 69:
54
+ entity.viewportId = curr.value;
55
+ break;
56
+ case 12:
57
+ entity.displayCenter = pointToVector2(parsePoint(scanner));
58
+ break;
59
+ case 13:
60
+ entity.snapBase = pointToVector2(parsePoint(scanner));
61
+ break;
62
+ case 14:
63
+ entity.snapSpacing = pointToVector2(parsePoint(scanner));
64
+ break;
65
+ case 15:
66
+ entity.gridSpacing = pointToVector2(parsePoint(scanner));
67
+ break;
68
+ case 16:
69
+ entity.viewDirection = pointToVector3(parsePoint(scanner));
70
+ break;
71
+ case 17:
72
+ entity.targetPoint = pointToVector3(parsePoint(scanner));
73
+ break;
74
+ case 42:
75
+ entity.perspectiveLensLength = curr.value;
76
+ break;
77
+ case 43:
78
+ entity.frontClipZ = curr.value;
79
+ break;
80
+ case 44:
81
+ entity.backClipZ = curr.value;
82
+ break;
83
+ case 45:
84
+ entity.viewHeight = curr.value;
85
+ break;
86
+ case 50:
87
+ entity.snapAngle = curr.value;
88
+ break;
89
+ case 51:
90
+ entity.viewTwistAngle = curr.value;
91
+ break;
92
+ case 72:
93
+ entity.circleZoomPercent = curr.value;
94
+ break;
95
+ case 331:
96
+ entity.frozenLayerIds ??= [];
97
+ entity.frozenLayerIds.push(curr.value);
98
+ break;
99
+ case 90:
100
+ entity.statusBitFlags = curr.value;
101
+ break;
102
+ case 340:
103
+ entity.clippingBoundaryId = curr.value;
104
+ break;
105
+ case 1:
106
+ entity.sheetName = curr.value;
107
+ break;
108
+ case 281:
109
+ entity.renderMode = curr.value;
110
+ break;
111
+ case 71:
112
+ entity.ucsPerViewport = curr.value;
113
+ break;
114
+ case 110:
115
+ entity.ucsOrigin = pointToVector3(parsePoint(scanner));
116
+ break;
117
+ case 111:
118
+ entity.ucsXAxis = pointToVector3(parsePoint(scanner));
119
+ break;
120
+ case 112:
121
+ entity.ucsYAxis = pointToVector3(parsePoint(scanner));
122
+ break;
123
+ case 345:
124
+ entity.ucsId = curr.value;
125
+ break;
126
+ case 346:
127
+ entity.ucsBaseId = curr.value;
128
+ break;
129
+ case 79:
130
+ entity.orthographicType = curr.value;
131
+ break;
132
+ case 146:
133
+ entity.elevation = curr.value;
134
+ break;
135
+ case 170:
136
+ entity.shadePlotMode = curr.value;
137
+ break;
138
+ case 61:
139
+ entity.majorGridFrequency = curr.value;
140
+ break;
141
+ case 332:
142
+ entity.backgroundId = curr.value;
143
+ break;
144
+ case 333:
145
+ entity.shadePlotId = curr.value;
146
+ break;
147
+ case 348:
148
+ entity.visualStyleId = curr.value;
149
+ break;
150
+ case 292:
151
+ entity.isDefaultLighting = !!curr.value;
152
+ break;
153
+ case 282:
154
+ entity.defaultLightingType = curr.value;
155
+ break;
156
+ case 141:
157
+ entity.brightness = curr.value;
158
+ break;
159
+ case 142:
160
+ entity.contrast = curr.value;
161
+ break;
162
+ case 63: // 타입이 조금씩 다름 셋 중 하나로 표현된다는 뜻인듯
163
+ case 421:
164
+ case 431:
165
+ entity.ambientLightColor = curr.value;
166
+ break;
167
+ case 361:
168
+ entity.sunId = curr.value;
169
+ break;
170
+ case 335:
171
+ case 343:
172
+ case 344:
173
+ case 91:
174
+ entity.softPointer = curr.value;
175
+ break;
176
+ }
177
+ return true;
178
+ }
@@ -0,0 +1,58 @@
1
+ import {
2
+ DefaultLightingType,
3
+ OrthographicType,
4
+ RenderMode,
5
+ ShadePlotMode,
6
+ UCSPerViewport,
7
+ } from '../../../consts';
8
+ import type { Vector2, Vector3 } from 'three';
9
+
10
+ export interface ViewportEntity {
11
+ type: 'VIEWPORT';
12
+ subclassMarker: string;
13
+ handle?: string;
14
+ layer?: string;
15
+ viewportCenter: Vector3; // WCS
16
+ width: number; // paper space unit
17
+ height: number; // paper space unit
18
+ status: number; // -1: ON but off scren, 0: OFF, positive: ON and active
19
+ viewportId: string;
20
+ displayCenter: Vector2; // DCS, viewportCenter가 화면 상 displayCenter에 와야된다는 뜻
21
+ snapBase: Vector2;
22
+ snapSpacing: Vector2;
23
+ gridSpacing: Vector2;
24
+ viewDirection: Vector3; // WCS
25
+ targetPoint: Vector3; // WCS
26
+ perspectiveLensLength: number;
27
+ frontClipZ: number;
28
+ backClipZ: number;
29
+ viewHeight: number; // model space unit
30
+ snapAngle: number;
31
+ viewTwistAngle: number;
32
+ circleZoomPercent: number;
33
+ frozenLayerIds?: string[];
34
+ statusBitFlags: number;
35
+ clippingBoundaryId?: string; // viewport가 직사각형 아닌 경우 경계선을 정의하는 entity id
36
+ sheetName: string;
37
+ renderMode: RenderMode;
38
+ ucsPerViewport: UCSPerViewport;
39
+ ucsOrigin?: Vector3;
40
+ ucsXAxis?: Vector3;
41
+ ucsYAxis?: Vector3;
42
+ ucsId?: string; // ID/handle of AcDbUCSTableRecord if UCS is a named UCS. If not present, then UCS is unnamed
43
+ ucsBaseId?: string; // ID/handle of AcDbUCSTableRecord of base UCS if UCS is orthographic. If it's not exists, taken to be WORLD
44
+ orthographicType?: OrthographicType;
45
+ elevation: number;
46
+ shadePlotMode: ShadePlotMode;
47
+ majorGridFrequency: number; // Frequency of major grid lines compared to minor grid lines
48
+ backgroundId?: string;
49
+ shadePlotId?: string;
50
+ visualStyleId?: string;
51
+ isDefaultLighting: boolean;
52
+ defaultLightingType?: DefaultLightingType;
53
+ brightness: number;
54
+ contrast: number;
55
+ ambientLightColor?: string;
56
+ sunId?: string;
57
+ softPointer?: string;
58
+ }
@@ -0,0 +1,49 @@
1
+ import { filter, map } from '@fxts/core';
2
+ import type { ParsedDxf } from './types';
3
+ import type { CommonDxfEntity } from './entities/shared';
4
+ import type { DimensionEntity } from './entities/dimension/types';
5
+ import type { InsertEntity } from './entities/insert';
6
+ import { flooding } from '../utils';
7
+
8
+ export function filterDummyBlocks(dxf: ParsedDxf): ParsedDxf {
9
+ // INSERT/DIMENSION 엔티티가 포함된 블록으로 그래프를 만듦
10
+ const namedBlocks = Object.entries(dxf.blocks);
11
+ const graph: Record<string, string[]> = {};
12
+ const insertBlocks = filter(
13
+ ([_, block]) => block.entities?.some(filterInsertOrDimension),
14
+ namedBlocks,
15
+ );
16
+
17
+ for (const [name, block] of insertBlocks) {
18
+ for (const subEntity of block.entities ?? []) {
19
+ if (!filterInsertOrDimension(subEntity)) continue;
20
+
21
+ graph[name] ??= [];
22
+ graph[name].push(subEntity.name);
23
+ }
24
+ }
25
+
26
+ // 루트 INSERT/DIMENSION 엔티티에서 접근가능한 모든 블록 이름을 수집
27
+ const insertEntities = filter(filterInsertOrDimension, dxf.entities);
28
+ const reachableNames = flooding<string>({
29
+ seeds: [...map(({ name }) => name, insertEntities)],
30
+ serializer: (name) => name,
31
+ spanner: (name) => graph[name] ?? [],
32
+ }).flat();
33
+
34
+ return {
35
+ ...dxf,
36
+ blocks: Object.fromEntries(
37
+ reachableNames.map((name) => [name, dxf.blocks[name]]),
38
+ ),
39
+ };
40
+ }
41
+
42
+ function filterInsertOrDimension(
43
+ entity: CommonDxfEntity,
44
+ ): entity is InsertEntity | DimensionEntity {
45
+ return (
46
+ entity.type === 'INSERT' ||
47
+ (entity.type === 'DIMENSION' && !!(entity as DimensionEntity).name)
48
+ );
49
+ }
@@ -0,0 +1,30 @@
1
+ import type DxfArrayScanner from '../DxfArrayScanner';
2
+ import type { ScannerGroup } from '../DxfArrayScanner';
3
+ import { parsePoint } from '../shared/parsePoint';
4
+ import { isMatched } from '../shared';
5
+
6
+ // scanner 위치는 읽히기 전이어야 함
7
+ export function parseHeader(curr: ScannerGroup, scanner: DxfArrayScanner) {
8
+ // interesting variables:
9
+ // $ACADVER, $VIEWDIR, $VIEWSIZE, $VIEWCTR, $TDCREATE, $TDUPDATE
10
+ // http://www.autodesk.com/techpubs/autocad/acadr14/dxf/header_section_al_u05_c.htm
11
+ // Also see VPORT table entries
12
+ let currVarName = null;
13
+ const header: any = {};
14
+
15
+ while (!isMatched(curr, 0, 'EOF')) {
16
+ if (isMatched(curr, 0, 'ENDSEC')) {
17
+ break;
18
+ }
19
+
20
+ if (curr.code === 9) {
21
+ currVarName = curr.value;
22
+ } else if (curr.code === 10) {
23
+ header[currVarName] = parsePoint(scanner);
24
+ } else {
25
+ header[currVarName] = curr.value;
26
+ }
27
+ curr = scanner.next();
28
+ }
29
+ return header;
30
+ }
@@ -0,0 +1,55 @@
1
+ import { DXFParserSnippet, Identity } from '../shared/parserGenerator';
2
+
3
+ export const CommonObjectSnippets: DXFParserSnippet[] = [
4
+ {
5
+ code: 330,
6
+ name: 'ownerObjectId',
7
+ parser: Identity,
8
+ },
9
+ {
10
+ code: 102,
11
+ // end of ACAD_XDICTIONARY
12
+ },
13
+ {
14
+ code: 360,
15
+ name: 'ownerDictionaryIdHard',
16
+ parser: Identity,
17
+ },
18
+ {
19
+ code: 102,
20
+ // start of ACAD_XDICTIONARY
21
+ },
22
+ {
23
+ code: 102,
24
+ // end of ACAD_REACTOR
25
+ },
26
+ {
27
+ code: 330,
28
+ name: 'ownerDictionaryIdSoft',
29
+ parser: Identity,
30
+ },
31
+ {
32
+ code: 102,
33
+ // start of ACAD_REACTOR
34
+ },
35
+ {
36
+ code: 102,
37
+ // end of application defined
38
+ },
39
+ {
40
+ code: 102,
41
+ // start of application defined
42
+ },
43
+ {
44
+ code: 5,
45
+ name: 'handle',
46
+ parser: Identity,
47
+ },
48
+ ];
49
+
50
+ export interface CommonDXFObject {
51
+ ownerObjectId: string;
52
+ ownerDictionaryIdHard: string;
53
+ ownerDictionaryIdSoft: string;
54
+ handle: string;
55
+ }
@@ -0,0 +1,61 @@
1
+ import {
2
+ DXFParserSnippet,
3
+ Identity,
4
+ ToBoolean,
5
+ } from '../shared/parserGenerator';
6
+ import type { CommonDXFObject } from './common';
7
+
8
+ export const DictionarySnippets: DXFParserSnippet[] = [
9
+ {
10
+ code: 3,
11
+ name: 'entries',
12
+ parser: (curr, scanner) => {
13
+ const entry = {
14
+ name: curr.value,
15
+ } as DictionaryDXFObject['entries'][0];
16
+
17
+ curr = scanner.next();
18
+
19
+ if (curr.code === 350) {
20
+ entry.objectId = curr.value;
21
+ } else {
22
+ // 만약 본인 토큰 아니면 스트림에 되돌려놔야 함
23
+ scanner.rewind();
24
+ }
25
+
26
+ return entry;
27
+ },
28
+ isMultiple: true,
29
+ },
30
+ {
31
+ code: 281,
32
+ name: 'recordCloneFlag',
33
+ parser: Identity,
34
+ },
35
+ {
36
+ code: 280,
37
+ name: 'isHardOwned',
38
+ parser: ToBoolean,
39
+ },
40
+ {
41
+ code: 100,
42
+ name: 'subclassMarker',
43
+ parser: Identity,
44
+ },
45
+ ];
46
+
47
+ export enum RecordCloneFlag {
48
+ NOT_APPLICABLE = 0,
49
+ KEEP_EXISTING = 1,
50
+ USE_CLONE = 2,
51
+ XREF_VALUE_NAME = 3,
52
+ VALUE_NAME = 4,
53
+ UNMANGLE_NAME = 5,
54
+ }
55
+
56
+ export interface DictionaryDXFObject extends CommonDXFObject {
57
+ subclassMarker: 'AcDbDictionary';
58
+ isHardOwned?: boolean;
59
+ recordCloneFlag: RecordCloneFlag;
60
+ entries: { name: string; objectId?: string }[];
61
+ }
@@ -0,0 +1,45 @@
1
+ import type DxfArrayScanner from '../DxfArrayScanner';
2
+ import { ScannerGroup } from '../DxfArrayScanner';
3
+ import { createParser, DXFParserSnippet } from '../shared/parserGenerator';
4
+ import { LayoutSnippets } from './layout';
5
+ import { CommonObjectSnippets } from './common';
6
+ import { PlotSettingsSnippets } from './plotSettings';
7
+ import { DictionarySnippets } from './dictionary';
8
+ import { createObjectTree } from './treefy';
9
+ import { classify } from '../../utils';
10
+
11
+ const ObjectSchemas: Record<string, DXFParserSnippet[]> = {
12
+ LAYOUT: LayoutSnippets,
13
+ PLOTSETTINGS: PlotSettingsSnippets,
14
+ DICTIONARY: DictionarySnippets,
15
+ };
16
+
17
+ export function parseObjects(curr: ScannerGroup, scanner: DxfArrayScanner) {
18
+ const result = [] as any[];
19
+
20
+ while (curr.code !== 0 || !['EOF', 'ENDSEC'].includes(curr.value)) {
21
+ const objectName = curr.value as string;
22
+ const snippets = ObjectSchemas[objectName];
23
+
24
+ if (curr.code === 0 && snippets?.length) {
25
+ const parser = createParser([...CommonObjectSnippets, ...snippets]);
26
+ const parsedObject = { name: objectName } as any;
27
+
28
+ curr = scanner.next();
29
+
30
+ if (parser(curr, scanner, parsedObject)) {
31
+ result.push(parsedObject);
32
+ curr = scanner.peek();
33
+ } else {
34
+ curr = scanner.next();
35
+ }
36
+ } else {
37
+ curr = scanner.next();
38
+ }
39
+ }
40
+
41
+ return {
42
+ byName: classify(result, ({ name }) => name),
43
+ byTree: createObjectTree(result),
44
+ };
45
+ }
@@ -0,0 +1,136 @@
1
+ import type { OrthographicType } from '../../consts';
2
+ import type { Point2D, Point3D } from '../../types';
3
+ import {
4
+ DXFParserSnippet,
5
+ Identity,
6
+ PointParser,
7
+ } from '../shared/parserGenerator';
8
+ import { PlotSettingDXFObject, PlotSettingsSnippets } from './plotSettings';
9
+
10
+ // Snippet이 code별로 스택에 들어가기 때문에 일부로 역순으로 적음
11
+ export const LayoutSnippets: DXFParserSnippet[] = [
12
+ {
13
+ code: 333,
14
+ name: 'shadePlotId',
15
+ parser: Identity,
16
+ },
17
+ {
18
+ code: 346,
19
+ name: 'orthographicUcsId',
20
+ parser: Identity,
21
+ },
22
+ {
23
+ code: 345,
24
+ name: 'namedUcsId',
25
+ parser: Identity,
26
+ },
27
+ {
28
+ code: 331,
29
+ name: 'viewportId',
30
+ parser: Identity,
31
+ },
32
+ {
33
+ code: 330,
34
+ name: 'paperSpaceTableId',
35
+ parser: Identity,
36
+ },
37
+ {
38
+ code: 76,
39
+ name: 'orthographicType',
40
+ parser: Identity,
41
+ },
42
+ {
43
+ code: 17,
44
+ name: 'ucsYAxis',
45
+ parser: PointParser,
46
+ },
47
+ {
48
+ code: 16,
49
+ name: 'ucsXAxis',
50
+ parser: PointParser,
51
+ },
52
+ {
53
+ code: 13,
54
+ name: 'ucsOrigin',
55
+ parser: PointParser,
56
+ },
57
+ {
58
+ code: 146,
59
+ name: 'elevation',
60
+ parser: Identity,
61
+ },
62
+ {
63
+ code: 15,
64
+ name: 'maxExtent',
65
+ parser: PointParser,
66
+ },
67
+ {
68
+ code: 14,
69
+ name: 'minExtent',
70
+ parser: PointParser,
71
+ },
72
+ {
73
+ code: 12,
74
+ name: 'insertionBase',
75
+ parser: PointParser,
76
+ },
77
+ {
78
+ code: 11,
79
+ name: 'maxLimit',
80
+ parser: PointParser,
81
+ },
82
+ {
83
+ code: 10,
84
+ name: 'minLimit',
85
+ parser: PointParser,
86
+ },
87
+ {
88
+ code: 71,
89
+ name: 'tabOrder',
90
+ parser: Identity,
91
+ },
92
+ {
93
+ code: 70,
94
+ name: 'controlFlag',
95
+ parser: Identity,
96
+ },
97
+ {
98
+ code: 1,
99
+ name: 'layoutName',
100
+ parser: Identity,
101
+ },
102
+ {
103
+ code: 100,
104
+ name: 'subclassMarker',
105
+ parser: Identity,
106
+ },
107
+ ...PlotSettingsSnippets,
108
+ ];
109
+
110
+ export enum LayoutControlFlag {
111
+ PSLTSCALE = 1,
112
+ LIMCHECK = 2,
113
+ }
114
+
115
+ export interface LayoutDXFObject
116
+ extends Omit<PlotSettingDXFObject, 'subclassMarker'> {
117
+ subclassMarker: 'AcDbLayout';
118
+ layoutName: string;
119
+ controlFlag: LayoutControlFlag;
120
+ tabOrder: number;
121
+ minLimit: Point2D;
122
+ maxLimit: Point2D;
123
+ insertionPoint: Point3D;
124
+ minExtent: Point3D;
125
+ maxExtent: Point3D;
126
+ elevation: number;
127
+ ucsOrigin: Point3D;
128
+ ucsXAxis: Point3D;
129
+ ucsYAxis: Point3D;
130
+ orthographicType: OrthographicType;
131
+ paperSpaceTableId: string;
132
+ viewportId: string;
133
+ namedUcsId?: string;
134
+ orthographicUcsId?: string;
135
+ shadePlotId: string;
136
+ }