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.
- package/.github/FUNDING.yml +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/custom.md +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/pull_request_template.md +23 -0
- package/.github/workflows/npm-publish.yml +55 -0
- package/.swcrc +8 -0
- package/LICENSE +674 -0
- package/README.md +567 -0
- package/jest.config.js +20 -0
- package/package.json +56 -0
- package/src/consts/block.ts +22 -0
- package/src/consts/color.ts +6 -0
- package/src/consts/config.ts +2 -0
- package/src/consts/dimension.ts +69 -0
- package/src/consts/hatch.ts +52 -0
- package/src/consts/header.ts +10 -0
- package/src/consts/index.ts +9 -0
- package/src/consts/lineweight.ts +5 -0
- package/src/consts/measurement.ts +4 -0
- package/src/consts/obscuredLineTypes.ts +21 -0
- package/src/consts/scene.ts +2 -0
- package/src/consts/viewport.ts +62 -0
- package/src/index.ts +6 -0
- package/src/parser/AutoCadColorIndex.ts +265 -0
- package/src/parser/DxfArrayScanner.ts +161 -0
- package/src/parser/DxfParser.ts +108 -0
- package/src/parser/ParseHelpers.ts +124 -0
- package/src/parser/blocks/blocks.test.ts +97 -0
- package/src/parser/blocks/index.ts +88 -0
- package/src/parser/blocks/types.ts +15 -0
- package/src/parser/entities/arc/index.ts +2 -0
- package/src/parser/entities/arc/parser.ts +67 -0
- package/src/parser/entities/arc/types.ts +13 -0
- package/src/parser/entities/attdef/consts.ts +12 -0
- package/src/parser/entities/attdef/index.ts +3 -0
- package/src/parser/entities/attdef/parser.ts +119 -0
- package/src/parser/entities/attdef/types.ts +19 -0
- package/src/parser/entities/attribute/consts.ts +6 -0
- package/src/parser/entities/attribute/index.ts +3 -0
- package/src/parser/entities/attribute/parser.ts +198 -0
- package/src/parser/entities/attribute/types.ts +31 -0
- package/src/parser/entities/circle/index.ts +2 -0
- package/src/parser/entities/circle/parser.ts +58 -0
- package/src/parser/entities/circle/types.ts +11 -0
- package/src/parser/entities/dimension/common.ts +98 -0
- package/src/parser/entities/dimension/index.ts +24 -0
- package/src/parser/entities/dimension/types.ts +65 -0
- package/src/parser/entities/ellipse/index.ts +2 -0
- package/src/parser/entities/ellipse/parser.ts +66 -0
- package/src/parser/entities/ellipse/types.ts +13 -0
- package/src/parser/entities/entities.test.ts +86 -0
- package/src/parser/entities/hatch/boundaryPathData/edge.ts +190 -0
- package/src/parser/entities/hatch/boundaryPathData/index.ts +27 -0
- package/src/parser/entities/hatch/boundaryPathData/polyline.ts +43 -0
- package/src/parser/entities/hatch/boundaryPathData/shared.ts +16 -0
- package/src/parser/entities/hatch/index.ts +189 -0
- package/src/parser/entities/hatch/patternData.ts +57 -0
- package/src/parser/entities/hatch/types/boundaryPath.ts +72 -0
- package/src/parser/entities/hatch/types/definitionLine.ts +14 -0
- package/src/parser/entities/hatch/types/hatch.ts +47 -0
- package/src/parser/entities/hatch/types/index.ts +3 -0
- package/src/parser/entities/index.ts +87 -0
- package/src/parser/entities/insert/index.ts +2 -0
- package/src/parser/entities/insert/parser.ts +106 -0
- package/src/parser/entities/insert/types.ts +19 -0
- package/src/parser/entities/leader/consts.ts +6 -0
- package/src/parser/entities/leader/index.ts +3 -0
- package/src/parser/entities/leader/parser.ts +119 -0
- package/src/parser/entities/leader/types.ts +24 -0
- package/src/parser/entities/line/index.ts +2 -0
- package/src/parser/entities/line/parser.ts +55 -0
- package/src/parser/entities/line/types.ts +11 -0
- package/src/parser/entities/lwpolyline/consts.ts +4 -0
- package/src/parser/entities/lwpolyline/index.ts +3 -0
- package/src/parser/entities/lwpolyline/parser.ts +122 -0
- package/src/parser/entities/lwpolyline/types.ts +21 -0
- package/src/parser/entities/mtext/consts.ts +5 -0
- package/src/parser/entities/mtext/index.ts +3 -0
- package/src/parser/entities/mtext/parser.ts +195 -0
- package/src/parser/entities/mtext/types.ts +34 -0
- package/src/parser/entities/point/index.ts +2 -0
- package/src/parser/entities/point/parser.ts +60 -0
- package/src/parser/entities/point/types.ts +10 -0
- package/src/parser/entities/polyline/consts.ts +17 -0
- package/src/parser/entities/polyline/index.ts +3 -0
- package/src/parser/entities/polyline/parser.ts +126 -0
- package/src/parser/entities/polyline/types.ts +20 -0
- package/src/parser/entities/section/index.ts +2 -0
- package/src/parser/entities/section/parser.ts +104 -0
- package/src/parser/entities/section/types.ts +20 -0
- package/src/parser/entities/shared.ts +166 -0
- package/src/parser/entities/solid/index.ts +2 -0
- package/src/parser/entities/solid/parser.ts +56 -0
- package/src/parser/entities/solid/types.ts +10 -0
- package/src/parser/entities/spline/consts.ts +8 -0
- package/src/parser/entities/spline/index.ts +3 -0
- package/src/parser/entities/spline/parser.ts +121 -0
- package/src/parser/entities/spline/types.ts +22 -0
- package/src/parser/entities/text/consts.ts +21 -0
- package/src/parser/entities/text/index.ts +3 -0
- package/src/parser/entities/text/parser.ts +117 -0
- package/src/parser/entities/text/types.ts +21 -0
- package/src/parser/entities/vertex/consts.ts +10 -0
- package/src/parser/entities/vertex/index.ts +3 -0
- package/src/parser/entities/vertex/parser.ts +90 -0
- package/src/parser/entities/vertex/types.ts +17 -0
- package/src/parser/entities/viewport/index.ts +178 -0
- package/src/parser/entities/viewport/types.ts +58 -0
- package/src/parser/filterDummyBlocks.ts +49 -0
- package/src/parser/header/index.ts +30 -0
- package/src/parser/objects/common.ts +55 -0
- package/src/parser/objects/dictionary.ts +61 -0
- package/src/parser/objects/index.ts +45 -0
- package/src/parser/objects/layout.ts +136 -0
- package/src/parser/objects/plotSettings.ts +231 -0
- package/src/parser/objects/treefy.ts +53 -0
- package/src/parser/objects/types.ts +17 -0
- package/src/parser/shared/index.ts +21 -0
- package/src/parser/shared/parsePoint.ts +37 -0
- package/src/parser/shared/parserGenerator.test.ts +164 -0
- package/src/parser/shared/parserGenerator.ts +180 -0
- package/src/parser/shared/xdata/index.ts +3 -0
- package/src/parser/shared/xdata/interpreter.test.ts +85 -0
- package/src/parser/shared/xdata/interpreter.ts +65 -0
- package/src/parser/shared/xdata/parser.test.ts +66 -0
- package/src/parser/shared/xdata/parser.ts +140 -0
- package/src/parser/shared/xdata/types.ts +22 -0
- package/src/parser/tables/blockRecord/index.ts +2 -0
- package/src/parser/tables/blockRecord/parser.ts +49 -0
- package/src/parser/tables/blockRecord/types.ts +11 -0
- package/src/parser/tables/dimStyle/consts.ts +428 -0
- package/src/parser/tables/dimStyle/index.ts +3 -0
- package/src/parser/tables/dimStyle/parser.ts +37 -0
- package/src/parser/tables/dimStyle/types.ts +164 -0
- package/src/parser/tables/index.ts +2 -0
- package/src/parser/tables/layer/index.ts +2 -0
- package/src/parser/tables/layer/parser.ts +58 -0
- package/src/parser/tables/layer/types.ts +14 -0
- package/src/parser/tables/ltype/consts.ts +6 -0
- package/src/parser/tables/ltype/index.ts +3 -0
- package/src/parser/tables/ltype/parser.ts +110 -0
- package/src/parser/tables/ltype/types.ts +23 -0
- package/src/parser/tables/parser.ts +100 -0
- package/src/parser/tables/shared.ts +32 -0
- package/src/parser/tables/style/index.ts +2 -0
- package/src/parser/tables/style/parser.ts +70 -0
- package/src/parser/tables/style/types.ts +15 -0
- package/src/parser/tables/types.ts +15 -0
- package/src/parser/tables/vport/index.ts +2 -0
- package/src/parser/tables/vport/parser.ts +205 -0
- package/src/parser/tables/vport/types.ts +48 -0
- package/src/parser/types.ts +30 -0
- package/src/types/color.ts +5 -0
- package/src/types/dxfHeader.ts +21 -0
- package/src/types/entity.ts +7 -0
- package/src/types/index.ts +30 -0
- package/src/utils/binarySearch.ts +20 -0
- package/src/utils/disjointSet.ts +52 -0
- package/src/utils/flooding.ts +37 -0
- package/src/utils/functional.ts +124 -0
- package/src/utils/graph.ts +53 -0
- package/src/utils/index.ts +102 -0
- package/src/utils/queue.ts +77 -0
- package/src/utils/triangle.ts +28 -0
- package/tsconfig.json +34 -0
- package/webpack.config.js +46 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { BoundaryPathEdgeType } from '../../../../consts';
|
|
2
|
+
import { parsePoint } from '../../../shared/parsePoint';
|
|
3
|
+
import {
|
|
4
|
+
createParser,
|
|
5
|
+
DXFParserSnippet,
|
|
6
|
+
Identity,
|
|
7
|
+
PointParser,
|
|
8
|
+
ToBoolean,
|
|
9
|
+
} from '../../../shared/parserGenerator';
|
|
10
|
+
import { CommonBoundaryPathDataSnippets } from './shared';
|
|
11
|
+
|
|
12
|
+
export const LineEdgeSnippets: DXFParserSnippet[] = [
|
|
13
|
+
{
|
|
14
|
+
code: 11,
|
|
15
|
+
name: 'end',
|
|
16
|
+
parser: PointParser,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
code: 10,
|
|
20
|
+
name: 'start',
|
|
21
|
+
parser: PointParser,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export const CircularEdgeSnippets: DXFParserSnippet[] = [
|
|
26
|
+
{
|
|
27
|
+
code: 73,
|
|
28
|
+
name: 'isCCW',
|
|
29
|
+
parser: ToBoolean,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
code: 51,
|
|
33
|
+
name: 'endAngle',
|
|
34
|
+
parser: Identity,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
code: 50,
|
|
38
|
+
name: 'startAngle',
|
|
39
|
+
parser: Identity,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
code: 40,
|
|
43
|
+
name: 'radius',
|
|
44
|
+
parser: Identity,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
code: 10,
|
|
48
|
+
name: 'center',
|
|
49
|
+
parser: PointParser,
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
export const EllipseEdgeSnippets: DXFParserSnippet[] = [
|
|
54
|
+
{
|
|
55
|
+
code: 73,
|
|
56
|
+
name: 'isCCW',
|
|
57
|
+
parser: ToBoolean,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
code: 51,
|
|
61
|
+
name: 'endAngle',
|
|
62
|
+
parser: Identity,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
code: 50,
|
|
66
|
+
name: 'startAngle',
|
|
67
|
+
parser: Identity,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
code: 40,
|
|
71
|
+
name: 'lengthOfMinorAxis',
|
|
72
|
+
parser: Identity,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
code: 11,
|
|
76
|
+
name: 'end',
|
|
77
|
+
parser: PointParser,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
code: 10,
|
|
81
|
+
name: 'center',
|
|
82
|
+
parser: PointParser,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
export const SplineEdgeSnippets: DXFParserSnippet[] = [
|
|
87
|
+
{
|
|
88
|
+
code: 13,
|
|
89
|
+
name: 'endTangent',
|
|
90
|
+
parser: PointParser,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
code: 12,
|
|
94
|
+
name: 'startTangent',
|
|
95
|
+
parser: PointParser,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
code: 11,
|
|
99
|
+
name: 'fitDatum',
|
|
100
|
+
isMultiple: true,
|
|
101
|
+
parser: PointParser,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
code: 97,
|
|
105
|
+
name: 'numberOfFitData',
|
|
106
|
+
parser: Identity,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
code: 10,
|
|
110
|
+
name: 'controlPoints',
|
|
111
|
+
isMultiple: true,
|
|
112
|
+
parser(curr, scanner) {
|
|
113
|
+
const controlPoint = { ...parsePoint(scanner), weight: 1 };
|
|
114
|
+
curr = scanner.next();
|
|
115
|
+
|
|
116
|
+
if (curr.code === 42) {
|
|
117
|
+
controlPoint.weight = curr.value;
|
|
118
|
+
} else {
|
|
119
|
+
scanner.rewind();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return controlPoint;
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
code: 40,
|
|
127
|
+
name: 'knots',
|
|
128
|
+
isMultiple: true,
|
|
129
|
+
parser: Identity,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
code: 96,
|
|
133
|
+
name: 'numberOfControlPoints',
|
|
134
|
+
parser: Identity,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
code: 95,
|
|
138
|
+
name: 'numberOfKnots',
|
|
139
|
+
parser: Identity,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
code: 74,
|
|
143
|
+
name: 'isPeriodic',
|
|
144
|
+
parser: ToBoolean,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
code: 73,
|
|
148
|
+
name: 'splineFlag',
|
|
149
|
+
parser: Identity,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
code: 94,
|
|
153
|
+
name: 'degree',
|
|
154
|
+
parser: Identity,
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
const EdgeSnippetMap = {
|
|
159
|
+
[BoundaryPathEdgeType.Line]: LineEdgeSnippets,
|
|
160
|
+
[BoundaryPathEdgeType.Circular]: CircularEdgeSnippets,
|
|
161
|
+
[BoundaryPathEdgeType.Elliptic]: EllipseEdgeSnippets,
|
|
162
|
+
[BoundaryPathEdgeType.Spline]: SplineEdgeSnippets,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export const EdgeBoundaryPathDataSnippets: DXFParserSnippet[] = [
|
|
166
|
+
...CommonBoundaryPathDataSnippets,
|
|
167
|
+
{
|
|
168
|
+
code: 72,
|
|
169
|
+
name: 'edges',
|
|
170
|
+
parser(curr, scanner) {
|
|
171
|
+
const edge = { type: curr.value };
|
|
172
|
+
const parser = createParser(
|
|
173
|
+
EdgeSnippetMap[edge.type as BoundaryPathEdgeType],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (!parser) {
|
|
177
|
+
throw new Error(`Invalid edge type ${edge.type}`);
|
|
178
|
+
}
|
|
179
|
+
curr = scanner.next();
|
|
180
|
+
parser(curr, scanner, edge);
|
|
181
|
+
return edge;
|
|
182
|
+
},
|
|
183
|
+
isMultiple: true,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
code: 93,
|
|
187
|
+
name: 'numberOfEdges',
|
|
188
|
+
parser: Identity,
|
|
189
|
+
},
|
|
190
|
+
];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BoundaryPathTypeFlag } from '../../../../consts';
|
|
2
|
+
import type DxfArrayScanner from '../../../DxfArrayScanner';
|
|
3
|
+
import type { ScannerGroup } from '../../../DxfArrayScanner';
|
|
4
|
+
import { createParser } from '../../../shared/parserGenerator';
|
|
5
|
+
import { EdgeBoundaryPathDataSnippets } from './edge';
|
|
6
|
+
import { PolylineSnippets } from './polyline';
|
|
7
|
+
|
|
8
|
+
export function parseBoundaryPathData(
|
|
9
|
+
curr: ScannerGroup,
|
|
10
|
+
scanner: DxfArrayScanner,
|
|
11
|
+
) {
|
|
12
|
+
// assume start with 92
|
|
13
|
+
const boundaryPathData = {
|
|
14
|
+
boundaryPathTypeFlag: curr.value,
|
|
15
|
+
};
|
|
16
|
+
const isPolyline =
|
|
17
|
+
boundaryPathData.boundaryPathTypeFlag & BoundaryPathTypeFlag.Polyline;
|
|
18
|
+
|
|
19
|
+
curr = scanner.next();
|
|
20
|
+
|
|
21
|
+
if (isPolyline) {
|
|
22
|
+
createParser(PolylineSnippets)(curr, scanner, boundaryPathData);
|
|
23
|
+
return boundaryPathData;
|
|
24
|
+
}
|
|
25
|
+
createParser(EdgeBoundaryPathDataSnippets)(curr, scanner, boundaryPathData);
|
|
26
|
+
return boundaryPathData;
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parsePoint } from '../../../shared/parsePoint';
|
|
2
|
+
import {
|
|
3
|
+
DXFParserSnippet,
|
|
4
|
+
Identity,
|
|
5
|
+
ToBoolean,
|
|
6
|
+
} from '../../../shared/parserGenerator';
|
|
7
|
+
import { CommonBoundaryPathDataSnippets } from './shared';
|
|
8
|
+
|
|
9
|
+
export const PolylineSnippets: DXFParserSnippet[] = [
|
|
10
|
+
...CommonBoundaryPathDataSnippets,
|
|
11
|
+
{
|
|
12
|
+
code: 10,
|
|
13
|
+
name: 'vertices',
|
|
14
|
+
parser(curr, scanner) {
|
|
15
|
+
const vertex = { ...parsePoint(scanner), bulge: 0 };
|
|
16
|
+
|
|
17
|
+
curr = scanner.next();
|
|
18
|
+
if (curr.code === 42) {
|
|
19
|
+
vertex.bulge = curr.value;
|
|
20
|
+
} else {
|
|
21
|
+
scanner.rewind();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return vertex;
|
|
25
|
+
},
|
|
26
|
+
isMultiple: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: 93,
|
|
30
|
+
name: 'numberOfVertices',
|
|
31
|
+
parser: Identity,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
code: 73,
|
|
35
|
+
name: 'isClosed',
|
|
36
|
+
parser: ToBoolean,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: 72,
|
|
40
|
+
name: 'hasBulge',
|
|
41
|
+
parser: ToBoolean,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DXFParserSnippet, Identity } from '../../../shared/parserGenerator';
|
|
2
|
+
|
|
3
|
+
export const CommonBoundaryPathDataSnippets: DXFParserSnippet[] = [
|
|
4
|
+
{
|
|
5
|
+
code: 330,
|
|
6
|
+
name: 'sourceBoundaryObjects',
|
|
7
|
+
parser: Identity,
|
|
8
|
+
isMultiple: true,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
code: 97,
|
|
12
|
+
name: 'numberOfSourceBoundaryObjects',
|
|
13
|
+
parser: Identity,
|
|
14
|
+
},
|
|
15
|
+
// 92는 분기에 써야해서 외부에서 주입함
|
|
16
|
+
];
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type DxfArrayScanner from '../../DxfArrayScanner';
|
|
2
|
+
import type { ScannerGroup } from '../../DxfArrayScanner';
|
|
3
|
+
import {
|
|
4
|
+
createParser,
|
|
5
|
+
DXFParserSnippet,
|
|
6
|
+
Identity,
|
|
7
|
+
PointParser,
|
|
8
|
+
ToBoolean,
|
|
9
|
+
} from '../../shared/parserGenerator';
|
|
10
|
+
import { CommonEntitySnippets } from '../shared';
|
|
11
|
+
import { parseBoundaryPathData } from './boundaryPathData';
|
|
12
|
+
import { parsePatternData } from './patternData';
|
|
13
|
+
import type { HatchEntity } from './types';
|
|
14
|
+
|
|
15
|
+
const DefaultHathEntity = {
|
|
16
|
+
extrusionDirection: { x: 0, y: 0, z: 1 },
|
|
17
|
+
gradientRotation: 0,
|
|
18
|
+
colorTint: 0,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const HatchSnippet: DXFParserSnippet[] = [
|
|
22
|
+
{
|
|
23
|
+
// Unused - String (default = LINEAR)
|
|
24
|
+
code: 470,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
// Unused - Reserved for future use:
|
|
28
|
+
code: 463,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
code: 462,
|
|
32
|
+
name: 'colorTint',
|
|
33
|
+
parser: Identity,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
code: 461,
|
|
37
|
+
name: 'gradientDefinition',
|
|
38
|
+
parser: Identity,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: 460,
|
|
42
|
+
name: 'gradientRotation', // radian
|
|
43
|
+
parser: Identity,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
code: 453,
|
|
47
|
+
name: 'numberOfColors',
|
|
48
|
+
parser: Identity,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
code: 452,
|
|
52
|
+
name: 'gradientColorFlag',
|
|
53
|
+
parser: Identity,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
// Unused - Zero is reserved for future use
|
|
57
|
+
code: 451,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
code: 450,
|
|
61
|
+
name: 'gradientFlag',
|
|
62
|
+
parser: Identity,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
code: 10,
|
|
66
|
+
name: 'seedPoints',
|
|
67
|
+
parser: PointParser,
|
|
68
|
+
isMultiple: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
// Unused - Number of degenerate boundary paths
|
|
72
|
+
code: 99,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
code: 11,
|
|
76
|
+
name: 'offsetVector',
|
|
77
|
+
parser: PointParser,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
code: 98,
|
|
81
|
+
name: 'numberOfSeedPoints',
|
|
82
|
+
parser: Identity,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
code: 47,
|
|
86
|
+
name: 'pixelSize',
|
|
87
|
+
parser: Identity,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
code: 53,
|
|
91
|
+
name: 'definitionLines',
|
|
92
|
+
parser: parsePatternData,
|
|
93
|
+
isMultiple: true,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
code: 78,
|
|
97
|
+
name: 'numberOfDefinitionLines',
|
|
98
|
+
parser: Identity,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
code: 77,
|
|
102
|
+
name: 'isDouble',
|
|
103
|
+
parser: ToBoolean,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
code: 73,
|
|
107
|
+
name: 'isAnnotated',
|
|
108
|
+
parser: ToBoolean,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
code: 41,
|
|
112
|
+
name: 'patternScale',
|
|
113
|
+
parser: Identity,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
code: 52,
|
|
117
|
+
name: 'patternAngle',
|
|
118
|
+
parser: Identity,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
code: 76,
|
|
122
|
+
name: 'patternType',
|
|
123
|
+
parser: Identity,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
code: 75,
|
|
127
|
+
name: 'hatchStyle',
|
|
128
|
+
parser: Identity,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
code: 92,
|
|
132
|
+
name: 'boundaryPaths',
|
|
133
|
+
parser: parseBoundaryPathData,
|
|
134
|
+
isMultiple: true,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
code: 91,
|
|
138
|
+
name: 'numberOfBoundaryPaths',
|
|
139
|
+
parser: Identity,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
code: 71,
|
|
143
|
+
name: 'associativity',
|
|
144
|
+
parser: Identity,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
code: 63,
|
|
148
|
+
name: 'patternFillColor',
|
|
149
|
+
parser: Identity,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
code: 70,
|
|
153
|
+
name: 'solidFill',
|
|
154
|
+
parser: Identity,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
code: 2,
|
|
158
|
+
name: 'patternName',
|
|
159
|
+
parser: Identity,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
code: 210,
|
|
163
|
+
name: 'extrusionDirection',
|
|
164
|
+
parser: PointParser,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
code: 10,
|
|
168
|
+
name: 'elevationPoint',
|
|
169
|
+
parser: PointParser,
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
code: 100,
|
|
173
|
+
name: 'subclassMarker',
|
|
174
|
+
parser: Identity,
|
|
175
|
+
pushContext: true,
|
|
176
|
+
},
|
|
177
|
+
...CommonEntitySnippets,
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
export class HatchEntityParser {
|
|
181
|
+
static ForEntityName = 'HATCH';
|
|
182
|
+
private parser = createParser(HatchSnippet, DefaultHathEntity);
|
|
183
|
+
|
|
184
|
+
parseEntity(scanner: DxfArrayScanner, curr: ScannerGroup) {
|
|
185
|
+
const entity = {} as any;
|
|
186
|
+
this.parser(curr, scanner, entity);
|
|
187
|
+
return entity as HatchEntity;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type DxfArrayScanner from '../../DxfArrayScanner';
|
|
2
|
+
import type { ScannerGroup } from '../../DxfArrayScanner';
|
|
3
|
+
import {
|
|
4
|
+
createParser,
|
|
5
|
+
DXFParserSnippet,
|
|
6
|
+
Identity,
|
|
7
|
+
} from '../../shared/parserGenerator';
|
|
8
|
+
|
|
9
|
+
const PatternDataSnippets: DXFParserSnippet[] = [
|
|
10
|
+
{
|
|
11
|
+
code: 49,
|
|
12
|
+
name: 'dashLengths',
|
|
13
|
+
parser: Identity,
|
|
14
|
+
isMultiple: true,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
code: 79,
|
|
18
|
+
name: 'numberOfDashLengths',
|
|
19
|
+
parser: Identity,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
code: 45,
|
|
23
|
+
name: 'offset',
|
|
24
|
+
parser: pseudoPointParser,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: 43,
|
|
28
|
+
name: 'base',
|
|
29
|
+
parser: pseudoPointParser,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
code: 53,
|
|
33
|
+
name: 'angle',
|
|
34
|
+
parser: Identity,
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
function pseudoPointParser(curr: ScannerGroup, scanner: DxfArrayScanner) {
|
|
39
|
+
const nextCode = curr.code + 1;
|
|
40
|
+
const offset = {
|
|
41
|
+
x: curr.value,
|
|
42
|
+
y: 1,
|
|
43
|
+
};
|
|
44
|
+
curr = scanner.next();
|
|
45
|
+
if (curr.code === nextCode) {
|
|
46
|
+
offset.y = curr.value;
|
|
47
|
+
} else {
|
|
48
|
+
scanner.rewind();
|
|
49
|
+
}
|
|
50
|
+
return offset;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function parsePatternData(curr: ScannerGroup, scanner: DxfArrayScanner) {
|
|
54
|
+
const patternData: any = {};
|
|
55
|
+
createParser(PatternDataSnippets)(curr, scanner, patternData);
|
|
56
|
+
return patternData;
|
|
57
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { BoundaryPathEdgeType } from '../../../../consts/hatch';
|
|
2
|
+
import type { Point2D } from '../../../../types';
|
|
3
|
+
|
|
4
|
+
interface BoundaryPathBase {
|
|
5
|
+
boundaryPathTypeFlag: number; // bit combination of BoundaryPathTypeFlag
|
|
6
|
+
numberOfSourceBoundaryObjects: number;
|
|
7
|
+
sourceBoundaryObjects: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface PolylineBoundaryPath extends BoundaryPathBase {
|
|
11
|
+
hasBulge: boolean;
|
|
12
|
+
isClosed: boolean;
|
|
13
|
+
numberOfVertices: number;
|
|
14
|
+
vertices: (Point2D & {
|
|
15
|
+
bulge: number;
|
|
16
|
+
})[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface EdgeBoundaryPath<EdgeType extends BoundaryPathEdge>
|
|
20
|
+
extends BoundaryPathBase {
|
|
21
|
+
numberOfEdges: number;
|
|
22
|
+
edges: EdgeType[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface BoundaryPathEdgeCommon {
|
|
26
|
+
type: BoundaryPathEdgeType;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type BoundaryPath =
|
|
30
|
+
| PolylineBoundaryPath
|
|
31
|
+
| EdgeBoundaryPath<BoundaryPathEdge>;
|
|
32
|
+
|
|
33
|
+
export interface LineEdge extends BoundaryPathEdgeCommon {
|
|
34
|
+
start: Point2D;
|
|
35
|
+
end: Point2D;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ArcEdge extends BoundaryPathEdgeCommon {
|
|
39
|
+
center: Point2D;
|
|
40
|
+
radius: number;
|
|
41
|
+
startAngle: number;
|
|
42
|
+
endAngle: number;
|
|
43
|
+
isCCW?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface EllipseEdge extends BoundaryPathEdgeCommon {
|
|
47
|
+
center: Point2D;
|
|
48
|
+
// end point of major axis relative to center
|
|
49
|
+
end: Point2D;
|
|
50
|
+
lengthOfMinorAxis: number;
|
|
51
|
+
startAngle: number;
|
|
52
|
+
endAngle: number;
|
|
53
|
+
isCCW?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SplineEdge extends BoundaryPathEdgeCommon {
|
|
57
|
+
degree: number;
|
|
58
|
+
splineFlag: number;
|
|
59
|
+
isPeriodic?: boolean;
|
|
60
|
+
numberOfKnots: number;
|
|
61
|
+
numberOfControlPoints: number;
|
|
62
|
+
knots: number[];
|
|
63
|
+
controlPoints: (Point2D & {
|
|
64
|
+
weight?: number; // default = 1
|
|
65
|
+
})[];
|
|
66
|
+
numberOfFitData: number;
|
|
67
|
+
fitDatum: Point2D[];
|
|
68
|
+
startTangent: Point2D;
|
|
69
|
+
endTangent: Point2D;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type BoundaryPathEdge = LineEdge | ArcEdge | EllipseEdge | SplineEdge;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Point2D } from '../../../../types';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* offset이란 선과 선 사이의 간격을 만드는 벡터이다.
|
|
5
|
+
* 그런데 이게 무조건 y축과 평행하다는 보장은 없다.
|
|
6
|
+
* (angle과도 무관하다)
|
|
7
|
+
*/
|
|
8
|
+
export interface HatchDefinitionLine {
|
|
9
|
+
angle: number; // degree
|
|
10
|
+
base: Point2D;
|
|
11
|
+
offset: Point2D;
|
|
12
|
+
numberOfDashLengths: number;
|
|
13
|
+
dashLengths: number[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HatchAssociativity,
|
|
3
|
+
HatchGradientColorFlag,
|
|
4
|
+
HatchGradientFlag,
|
|
5
|
+
HatchPatternType,
|
|
6
|
+
HatchSolidFill,
|
|
7
|
+
HatchStyle,
|
|
8
|
+
} from '../../../../consts/hatch';
|
|
9
|
+
import type { Point3D } from '../../../../types';
|
|
10
|
+
import type { CommonDxfEntity } from '../../shared';
|
|
11
|
+
import type { BoundaryPath } from './boundaryPath';
|
|
12
|
+
import type { HatchDefinitionLine } from './definitionLine';
|
|
13
|
+
|
|
14
|
+
interface HatchEntityBase extends CommonDxfEntity {
|
|
15
|
+
type: 'HATCH';
|
|
16
|
+
subclassMarker: 'AcDbHatch';
|
|
17
|
+
elevationPoint: Point3D;
|
|
18
|
+
extrusionDirection?: Point3D;
|
|
19
|
+
patternName: string;
|
|
20
|
+
solidFill: HatchSolidFill;
|
|
21
|
+
patternFillColor: any; // ?
|
|
22
|
+
associativity: HatchAssociativity;
|
|
23
|
+
numberOfBoundaryPaths: number;
|
|
24
|
+
boundaryPaths: BoundaryPath[];
|
|
25
|
+
hatchStyle: HatchStyle;
|
|
26
|
+
patternType: HatchPatternType;
|
|
27
|
+
patternAngle?: number; // Pattern Fill Only
|
|
28
|
+
patternScale?: number; // Pattern Fill Only
|
|
29
|
+
numberOfDefinitionLines: number;
|
|
30
|
+
definitionLines: HatchDefinitionLine[];
|
|
31
|
+
pixelSize: number;
|
|
32
|
+
numberOfSeedPoints: number;
|
|
33
|
+
offsetVector?: Point3D;
|
|
34
|
+
seedPoints?: Point3D[];
|
|
35
|
+
gradientFlag?: HatchGradientFlag;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface GradientHatchEntity extends HatchEntityBase {
|
|
39
|
+
gradientFlag: HatchGradientFlag.Gradient;
|
|
40
|
+
gradientColorFlag: HatchGradientColorFlag;
|
|
41
|
+
numberOfColors: 0 | 2;
|
|
42
|
+
gradientRotation?: number; // radian, default = 0
|
|
43
|
+
gradientDefinition: number; // 0 ~ 1
|
|
44
|
+
colorTint?: number; // 0 ~ 1, default = 0
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type HatchEntity = GradientHatchEntity | HatchEntityBase;
|