@bitbybit-dev/base 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +24 -0
- package/README.md +3 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +20 -0
- package/lib/api/inputs/base-inputs.js +22 -0
- package/lib/api/inputs/io-inputs.d.ts +408 -8
- package/lib/api/inputs/io-inputs.js +344 -7
- package/lib/api/inputs/mesh-inputs.d.ts +20 -1
- package/lib/api/inputs/mesh-inputs.js +23 -0
- package/lib/api/inputs/recipes-inputs.d.ts +13 -5
- package/lib/api/inputs/recipes-inputs.js +10 -5
- package/lib/api/kernel-calls/index.d.ts +1 -0
- package/lib/api/kernel-calls/index.js +1 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +3 -1
- package/lib/api/kernel-calls/resolve-dto.js +7 -2
- package/lib/api/kernel-calls/settings.d.ts +19 -0
- package/lib/api/kernel-calls/up-axis-aliases.d.ts +25 -0
- package/lib/api/kernel-calls/up-axis-aliases.js +70 -0
- package/lib/api/models/simplex.d.ts +2 -0
- package/lib/api/models/simplex.js +10 -1
- package/lib/api/resolved-inputs/index.d.ts +11 -2
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +3 -1
- package/lib/api/services/helpers/curves/conic-arcs.js +4 -2
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +16 -6
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.js +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.d.ts +4 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.js +271 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +28 -11
- package/lib/api/services/helpers/files/drawing/drawing-hatch.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.js +123 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.js +91 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +6 -1
- package/lib/api/services/helpers/files/drawing/drawing-model.js +97 -13
- package/lib/api/services/helpers/files/drawing/drawing-scale.d.ts +2 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.js +47 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.d.ts +9 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.js +25 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +57 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +13 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.js +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +5 -1
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +5 -2
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +26 -10
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.js +312 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +37 -3
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.js +151 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +63 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +1 -1
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +71 -181
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +5 -4
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +25 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +13 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +1 -1
- package/lib/api/services/helpers/files/svg/svg-strokes.js +47 -23
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +100 -23
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +2 -1
- package/lib/api/services/helpers/files/svg/svg.constants.js +2 -1
- package/lib/api/services/helpers/geometry/loop-fill.d.ts +2 -0
- package/lib/api/services/helpers/geometry/loop-fill.js +37 -0
- package/lib/api/services/helpers/helper-types.d.ts +33 -0
- package/lib/api/services/helpers/text/stroke-font.d.ts +6 -0
- package/lib/api/services/helpers/text/stroke-font.js +177 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.d.ts +2 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.js +18 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.d.ts +14 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.js +34 -0
- package/lib/api/services/io/drawing.d.ts +198 -0
- package/lib/api/services/io/drawing.js +242 -0
- package/lib/api/services/io/dxf.d.ts +3 -3
- package/lib/api/services/io/dxf.js +4 -4
- package/lib/api/services/io/svg.d.ts +13 -11
- package/lib/api/services/io/svg.js +15 -12
- package/lib/api/services/mesh.d.ts +19 -0
- package/lib/api/services/mesh.js +40 -0
- package/lib/api/services/recipes.js +3 -2
- package/lib/api/services/text.d.ts +3 -3
- package/lib/api/services/text.js +7 -25
- package/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { angleWithinTurn } from "../../curves/conic-arcs";
|
|
2
|
+
import { pointToWorld, unitOf } from "../../geometry/frame-axes";
|
|
3
|
+
import { radiansOf } from "../../geometry/scalars";
|
|
4
|
+
import { cross3, length3, scale3 } from "../../geometry/vectors";
|
|
5
|
+
import { ocsAxesOf } from "../drawing/drawing-geometry";
|
|
6
|
+
import { DEFAULT_SPLINE_DEGREE } from "../drawing/drawing.constants";
|
|
7
|
+
import { CONIC_WORK, DEGREES_PER_TURN, GROUP, LINE_WORK, MAX_FIT_POINTS, MAX_SPLINE_DEGREE, MESH_FLAG, PERIODIC_FLAG, POLYFACE_FLAG, SPLINE_FRAME_VERTEX_FLAG, Y_OFFSET, Z_OFFSET, } from "./dxf-reader.constants";
|
|
8
|
+
import { DXF_CLOSED_FLAG, DXF_EXTRUSION_CODES, DXF_OTHER_POINT_CODES, DXF_POINT_CODES, DXF_POLYLINE_3D_FLAG, DXF_RATIONAL_FLAG } from "./dxf.constants";
|
|
9
|
+
import { numberIn, numberOf, numbersOf } from "./dxf-tokens";
|
|
10
|
+
const FULL_TURN = 2 * Math.PI;
|
|
11
|
+
export const segmentWork = (segment) => {
|
|
12
|
+
switch (segment.kind) {
|
|
13
|
+
case "line":
|
|
14
|
+
return LINE_WORK;
|
|
15
|
+
case "conic":
|
|
16
|
+
return CONIC_WORK;
|
|
17
|
+
case "spline":
|
|
18
|
+
return segment.curve.points.length;
|
|
19
|
+
case "fit":
|
|
20
|
+
return segment.points.length;
|
|
21
|
+
default:
|
|
22
|
+
return segment.points.length + segment.bulges.filter(bulge => bulge !== 0).length;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const drawn = (segments) => ({ segments, work: segments.reduce((total, segment) => total + segmentWork(segment), 0), flaw: undefined, skipped: undefined });
|
|
26
|
+
const flawOf = (type, reason) => ({ segments: [], work: 0, flaw: `${type}\n${reason}`, skipped: undefined });
|
|
27
|
+
export const recordPointOf = (record, codes, fallback = [0, 0, 0]) => [numberOf(record, codes[0], fallback[0]), numberOf(record, codes[1], fallback[1]), numberOf(record, codes[2], fallback[2])];
|
|
28
|
+
export const recordNormalOf = (record) => { var _a; return (_a = unitOf(recordPointOf(record, DXF_EXTRUSION_CODES, [0, 0, 1]))) !== null && _a !== void 0 ? _a : [0, 0, 1]; };
|
|
29
|
+
const pointsOf = (record, xCode) => {
|
|
30
|
+
const points = [];
|
|
31
|
+
for (const group of record.groups) {
|
|
32
|
+
if (group.code === xCode) {
|
|
33
|
+
points.push([numberIn(group), 0, 0]);
|
|
34
|
+
}
|
|
35
|
+
else if (group.code === xCode + Y_OFFSET && points.length > 0) {
|
|
36
|
+
points[points.length - 1][1] = numberIn(group);
|
|
37
|
+
}
|
|
38
|
+
else if (group.code === xCode + Z_OFFSET && points.length > 0) {
|
|
39
|
+
points[points.length - 1][2] = numberIn(group);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return points;
|
|
43
|
+
};
|
|
44
|
+
const circleOf = (record) => {
|
|
45
|
+
const axes = ocsAxesOf(recordNormalOf(record));
|
|
46
|
+
const radius = numberOf(record, GROUP.radius, 0);
|
|
47
|
+
const angleOf = (code) => radiansOf(angleWithinTurn(numberOf(record, code, 0), DEGREES_PER_TURN));
|
|
48
|
+
const start = record.type === "ARC" ? angleOf(GROUP.startAngle) : 0;
|
|
49
|
+
const end = record.type === "ARC" ? angleOf(GROUP.endAngle) : FULL_TURN;
|
|
50
|
+
const turn = angleWithinTurn(end - start, FULL_TURN);
|
|
51
|
+
return {
|
|
52
|
+
kind: "conic",
|
|
53
|
+
center: pointToWorld(axes, recordPointOf(record, DXF_POINT_CODES)),
|
|
54
|
+
xAxis: scale3(axes.x, radius),
|
|
55
|
+
yAxis: scale3(axes.y, radius),
|
|
56
|
+
start,
|
|
57
|
+
sweep: turn === 0 ? FULL_TURN : turn,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const ellipseOf = (record) => {
|
|
61
|
+
const major = recordPointOf(record, DXF_OTHER_POINT_CODES);
|
|
62
|
+
const minor = unitOf(cross3(recordNormalOf(record), major));
|
|
63
|
+
if (minor === undefined || length3(major) === 0) {
|
|
64
|
+
return flawOf("ELLIPSE", "its major axis has no length or runs along its extrusion");
|
|
65
|
+
}
|
|
66
|
+
const start = angleWithinTurn(numberOf(record, GROUP.startParameter, 0), FULL_TURN);
|
|
67
|
+
const end = numberOf(record, GROUP.endParameter, FULL_TURN);
|
|
68
|
+
const turn = angleWithinTurn(end - start, FULL_TURN);
|
|
69
|
+
return drawn([{ kind: "conic", center: recordPointOf(record, DXF_POINT_CODES), xAxis: major, yAxis: scale3(minor, length3(major) * numberOf(record, GROUP.ratio, 1)), start, sweep: turn === 0 ? FULL_TURN : turn }]);
|
|
70
|
+
};
|
|
71
|
+
const polylineOf = (type, points, bulges, closed, normal) => {
|
|
72
|
+
if (points.length < 2) {
|
|
73
|
+
return flawOf(type, "it has fewer than two points");
|
|
74
|
+
}
|
|
75
|
+
return drawn([{ kind: "polyline", points, bulges, closed, normal }]);
|
|
76
|
+
};
|
|
77
|
+
const lightPolylineOf = (record) => {
|
|
78
|
+
const axes = ocsAxesOf(recordNormalOf(record));
|
|
79
|
+
const elevation = numberOf(record, GROUP.elevation, 0);
|
|
80
|
+
const points = [];
|
|
81
|
+
const bulges = [];
|
|
82
|
+
for (const group of record.groups) {
|
|
83
|
+
if (group.code === GROUP.x) {
|
|
84
|
+
points.push([numberIn(group), 0, elevation]);
|
|
85
|
+
bulges.push(0);
|
|
86
|
+
}
|
|
87
|
+
else if (group.code === GROUP.y && points.length > 0) {
|
|
88
|
+
points[points.length - 1][1] = numberIn(group);
|
|
89
|
+
}
|
|
90
|
+
else if (group.code === GROUP.bulge && bulges.length > 0) {
|
|
91
|
+
bulges[bulges.length - 1] = numberIn(group);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return polylineOf(record.type, points.map(point => pointToWorld(axes, point)), bulges, (numberOf(record, GROUP.flags, 0) & DXF_CLOSED_FLAG) !== 0, recordNormalOf(record));
|
|
95
|
+
};
|
|
96
|
+
const heavyPolylineOf = (record) => {
|
|
97
|
+
const flags = numberOf(record, GROUP.flags, 0);
|
|
98
|
+
if ((flags & (POLYFACE_FLAG | MESH_FLAG)) !== 0) {
|
|
99
|
+
return { segments: [], work: 0, flaw: undefined, skipped: "POLYLINE mesh" };
|
|
100
|
+
}
|
|
101
|
+
const vertices = record.vertices.filter(vertex => (numberOf(vertex, GROUP.flags, 0) & SPLINE_FRAME_VERTEX_FLAG) === 0);
|
|
102
|
+
const closed = (flags & DXF_CLOSED_FLAG) !== 0;
|
|
103
|
+
if ((flags & DXF_POLYLINE_3D_FLAG) !== 0) {
|
|
104
|
+
return polylineOf(record.type, vertices.map(vertex => recordPointOf(vertex, DXF_POINT_CODES)), vertices.map(() => 0), closed, [0, 0, 1]);
|
|
105
|
+
}
|
|
106
|
+
const axes = ocsAxesOf(recordNormalOf(record));
|
|
107
|
+
const elevation = numberOf(record, GROUP.elevationZ, 0);
|
|
108
|
+
const points = vertices.map(vertex => pointToWorld(axes, [numberOf(vertex, GROUP.x, 0), numberOf(vertex, GROUP.y, 0), elevation]));
|
|
109
|
+
return polylineOf(record.type, points, vertices.map(vertex => numberOf(vertex, GROUP.bulge, 0)), closed, recordNormalOf(record));
|
|
110
|
+
};
|
|
111
|
+
const splineOf = (record) => {
|
|
112
|
+
const flags = numberOf(record, GROUP.flags, 0);
|
|
113
|
+
const degree = numberOf(record, GROUP.degree, DEFAULT_SPLINE_DEGREE);
|
|
114
|
+
if (degree > MAX_SPLINE_DEGREE) {
|
|
115
|
+
return flawOf("SPLINE", `its degree is above ${MAX_SPLINE_DEGREE}, the highest a kernel curve takes`);
|
|
116
|
+
}
|
|
117
|
+
const controls = pointsOf(record, GROUP.controlX);
|
|
118
|
+
const knots = numbersOf(record, GROUP.knot);
|
|
119
|
+
if (controls.length > degree && knots.length === controls.length + degree + 1 && degree >= 1 && Number.isInteger(degree)) {
|
|
120
|
+
const weights = numbersOf(record, GROUP.weight);
|
|
121
|
+
const rational = (flags & DXF_RATIONAL_FLAG) !== 0 && weights.length === controls.length && weights.every(weight => weight > 0);
|
|
122
|
+
return drawn([{ kind: "spline", curve: { degree, points: controls, weights: rational ? weights : controls.map(() => 1), knots } }]);
|
|
123
|
+
}
|
|
124
|
+
const fits = pointsOf(record, GROUP.fitX);
|
|
125
|
+
if (fits.length > MAX_FIT_POINTS) {
|
|
126
|
+
return flawOf("SPLINE", `it has more than ${MAX_FIT_POINTS} fit points, more than one spline is interpolated through`);
|
|
127
|
+
}
|
|
128
|
+
if (fits.length >= 2) {
|
|
129
|
+
const start = pointsOf(record, GROUP.startTangentX)[0];
|
|
130
|
+
const end = pointsOf(record, GROUP.endTangentX)[0];
|
|
131
|
+
return drawn([{ kind: "fit", points: fits, startTangent: start, endTangent: end, closed: (flags & (DXF_CLOSED_FLAG | PERIODIC_FLAG)) !== 0 }]);
|
|
132
|
+
}
|
|
133
|
+
return flawOf("SPLINE", "it holds neither control points with knots to match nor two fit points");
|
|
134
|
+
};
|
|
135
|
+
export const readSegmentsOf = (record) => {
|
|
136
|
+
switch (record.type) {
|
|
137
|
+
case "LINE":
|
|
138
|
+
return drawn([{ kind: "line", start: recordPointOf(record, DXF_POINT_CODES), end: recordPointOf(record, DXF_OTHER_POINT_CODES) }]);
|
|
139
|
+
case "CIRCLE":
|
|
140
|
+
case "ARC":
|
|
141
|
+
return drawn([circleOf(record)]);
|
|
142
|
+
case "ELLIPSE":
|
|
143
|
+
return ellipseOf(record);
|
|
144
|
+
case "LWPOLYLINE":
|
|
145
|
+
return lightPolylineOf(record);
|
|
146
|
+
case "POLYLINE":
|
|
147
|
+
return heavyPolylineOf(record);
|
|
148
|
+
default:
|
|
149
|
+
return splineOf(record);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
@@ -44,14 +44,41 @@ export interface ReadFitSpline {
|
|
|
44
44
|
readonly closed: boolean;
|
|
45
45
|
}
|
|
46
46
|
export type ReadSegment = ReadLine | ReadConic | ReadPolyline | ReadSpline | ReadFitSpline;
|
|
47
|
+
export interface OwnSegments {
|
|
48
|
+
readonly segments: readonly ReadSegment[];
|
|
49
|
+
readonly work: number;
|
|
50
|
+
readonly flaw: string | undefined;
|
|
51
|
+
readonly skipped: string | undefined;
|
|
52
|
+
}
|
|
47
53
|
export interface ReadStyle {
|
|
48
54
|
readonly layer: string;
|
|
49
55
|
readonly color: string;
|
|
50
56
|
readonly lineType: Inputs.IO.lineTypeEnum;
|
|
51
57
|
}
|
|
58
|
+
export interface PlanarTurn {
|
|
59
|
+
readonly scale: number;
|
|
60
|
+
readonly rotation: number;
|
|
61
|
+
}
|
|
62
|
+
export interface ReadText {
|
|
63
|
+
readonly value: string;
|
|
64
|
+
readonly position: Point3;
|
|
65
|
+
readonly height: number;
|
|
66
|
+
readonly anchor: "start" | "middle" | "end";
|
|
67
|
+
readonly rotation: number;
|
|
68
|
+
readonly widthFactor: number;
|
|
69
|
+
}
|
|
70
|
+
export interface ReadHatch {
|
|
71
|
+
readonly boundaries: readonly (readonly ReadSegment[])[];
|
|
72
|
+
readonly pattern: Inputs.IO.hatchPatternEnum;
|
|
73
|
+
readonly angle: number;
|
|
74
|
+
readonly spacing: number;
|
|
75
|
+
readonly simplified: boolean;
|
|
76
|
+
}
|
|
52
77
|
export interface ReadEntity {
|
|
53
78
|
readonly style: ReadStyle;
|
|
54
79
|
readonly segments: readonly ReadSegment[];
|
|
80
|
+
readonly text?: ReadText;
|
|
81
|
+
readonly hatch?: ReadHatch;
|
|
55
82
|
}
|
|
56
83
|
export interface ReadLayer {
|
|
57
84
|
readonly name: string;
|
|
@@ -28,6 +28,7 @@ export declare const GREEN_SHIFT = 8;
|
|
|
28
28
|
export declare const DEGREES_PER_TURN = 360;
|
|
29
29
|
export declare const SAME_SCALE = 1e-9;
|
|
30
30
|
export declare const UNIT_CODES: ReadonlyMap<number, Inputs.Base.unitOfLengthEnum>;
|
|
31
|
+
export declare const IMPERIAL_UNIT_CODES: ReadonlySet<number>;
|
|
31
32
|
export declare const UNIT_NAMES: ReadonlyMap<number, string>;
|
|
32
33
|
export declare const DRAWN_ENTITIES: Set<string>;
|
|
33
34
|
export declare const Y_OFFSET = 10;
|
|
@@ -69,3 +70,65 @@ export declare const GROUP: {
|
|
|
69
70
|
readonly elevation: 38;
|
|
70
71
|
readonly space: 67;
|
|
71
72
|
};
|
|
73
|
+
export declare const ANNOTATED_ENTITIES: Set<string>;
|
|
74
|
+
export declare const ANNOTATION_GROUP: {
|
|
75
|
+
readonly text: 1;
|
|
76
|
+
readonly otherY: 21;
|
|
77
|
+
readonly height: 40;
|
|
78
|
+
readonly widthFactor: 41;
|
|
79
|
+
readonly patternScale: 41;
|
|
80
|
+
readonly edgeWeight: 42;
|
|
81
|
+
readonly baseX: 43;
|
|
82
|
+
readonly baseY: 44;
|
|
83
|
+
readonly offsetX: 45;
|
|
84
|
+
readonly offsetY: 46;
|
|
85
|
+
readonly dash: 49;
|
|
86
|
+
readonly patternAngle: 52;
|
|
87
|
+
readonly lineAngle: 53;
|
|
88
|
+
readonly solid: 70;
|
|
89
|
+
readonly justified: 72;
|
|
90
|
+
readonly edgeType: 72;
|
|
91
|
+
readonly hasBulge: 72;
|
|
92
|
+
readonly verticalJustified: 73;
|
|
93
|
+
readonly counterclockwise: 73;
|
|
94
|
+
readonly rational: 73;
|
|
95
|
+
readonly closedLoop: 73;
|
|
96
|
+
readonly periodic: 74;
|
|
97
|
+
readonly lineCount: 78;
|
|
98
|
+
readonly dashCount: 79;
|
|
99
|
+
readonly loopCount: 91;
|
|
100
|
+
readonly loopFlags: 92;
|
|
101
|
+
readonly vertexCount: 93;
|
|
102
|
+
readonly edgeDegree: 94;
|
|
103
|
+
readonly knotCount: 95;
|
|
104
|
+
readonly pointCount: 96;
|
|
105
|
+
readonly sources: 97;
|
|
106
|
+
readonly fitCount: 97;
|
|
107
|
+
readonly owner: 330;
|
|
108
|
+
};
|
|
109
|
+
export declare const TEXT_JUSTIFIED: {
|
|
110
|
+
readonly left: 0;
|
|
111
|
+
readonly center: 1;
|
|
112
|
+
readonly right: 2;
|
|
113
|
+
readonly aligned: 3;
|
|
114
|
+
readonly middle: 4;
|
|
115
|
+
readonly fit: 5;
|
|
116
|
+
};
|
|
117
|
+
export declare const TEXT_VERTICAL: {
|
|
118
|
+
readonly baseline: 0;
|
|
119
|
+
readonly bottom: 1;
|
|
120
|
+
readonly middle: 2;
|
|
121
|
+
readonly top: 3;
|
|
122
|
+
};
|
|
123
|
+
export declare const MIDDLE_DROP_SHARE = 0.5;
|
|
124
|
+
export declare const HATCH_EDGE: {
|
|
125
|
+
readonly line: 1;
|
|
126
|
+
readonly arc: 2;
|
|
127
|
+
readonly ellipse: 3;
|
|
128
|
+
readonly spline: 4;
|
|
129
|
+
};
|
|
130
|
+
export declare const HATCH_POLYLINE_FLAG = 2;
|
|
131
|
+
export declare const TEXT_CODES: RegExp;
|
|
132
|
+
export declare const TEXT_CONTROLS: RegExp;
|
|
133
|
+
export declare const SAME_TURN = 1e-9;
|
|
134
|
+
export declare const SAME_ANGLE_DEGREES = 0.000001;
|
|
@@ -33,6 +33,7 @@ export const UNIT_CODES = new Map([
|
|
|
33
33
|
[5, Inputs.Base.unitOfLengthEnum.centimetre],
|
|
34
34
|
[6, Inputs.Base.unitOfLengthEnum.metre],
|
|
35
35
|
]);
|
|
36
|
+
export const IMPERIAL_UNIT_CODES = new Set([1, 2, 3, 8, 9, 10]);
|
|
36
37
|
export const UNIT_NAMES = new Map([
|
|
37
38
|
[2, "feet"], [3, "miles"], [7, "kilometres"], [8, "microinches"], [9, "mils"], [10, "yards"], [11, "angstroms"], [12, "nanometres"], [13, "microns"], [14, "decimetres"],
|
|
38
39
|
]);
|
|
@@ -76,3 +77,19 @@ export const GROUP = {
|
|
|
76
77
|
elevation: 38,
|
|
77
78
|
space: 67,
|
|
78
79
|
};
|
|
80
|
+
export const ANNOTATED_ENTITIES = new Set(["TEXT", "HATCH"]);
|
|
81
|
+
export const ANNOTATION_GROUP = {
|
|
82
|
+
text: 1, otherY: 21, height: 40, widthFactor: 41, patternScale: 41, edgeWeight: 42, baseX: 43, baseY: 44, offsetX: 45, offsetY: 46, dash: 49,
|
|
83
|
+
patternAngle: 52, lineAngle: 53, solid: 70, justified: 72, edgeType: 72, hasBulge: 72, verticalJustified: 73, counterclockwise: 73, rational: 73, closedLoop: 73,
|
|
84
|
+
periodic: 74, lineCount: 78, dashCount: 79, loopCount: 91, loopFlags: 92, vertexCount: 93, edgeDegree: 94, knotCount: 95, pointCount: 96, sources: 97, fitCount: 97,
|
|
85
|
+
owner: 330,
|
|
86
|
+
};
|
|
87
|
+
export const TEXT_JUSTIFIED = { left: 0, center: 1, right: 2, aligned: 3, middle: 4, fit: 5 };
|
|
88
|
+
export const TEXT_VERTICAL = { baseline: 0, bottom: 1, middle: 2, top: 3 };
|
|
89
|
+
export const MIDDLE_DROP_SHARE = 0.5;
|
|
90
|
+
export const HATCH_EDGE = { line: 1, arc: 2, ellipse: 3, spline: 4 };
|
|
91
|
+
export const HATCH_POLYLINE_FLAG = 2;
|
|
92
|
+
export const TEXT_CODES = /%%(%|[cdpuokCDPUOK]|\d{3})|\^(.?)/g;
|
|
93
|
+
export const TEXT_CONTROLS = /\p{Cc}/gu;
|
|
94
|
+
export const SAME_TURN = 1e-9;
|
|
95
|
+
export const SAME_ANGLE_DEGREES = 1e-6;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ReadDrawing } from "./dxf-reader-types";
|
|
2
|
-
export declare const readDxfDrawing: (text: string, includeHidden: boolean) => ReadDrawing;
|
|
2
|
+
export declare const readDxfDrawing: (text: string, includeHidden: boolean, annotated?: boolean) => ReadDrawing;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import * as Inputs from "../../../../inputs";
|
|
2
2
|
import { InputError } from "../../../../kernel-calls";
|
|
3
3
|
import { hexOfChannels } from "../../color/color-forms";
|
|
4
|
-
import {
|
|
5
|
-
import { composeAxes, pointToWorld, unitOf, WORLD_AXES } from "../../geometry/frame-axes";
|
|
4
|
+
import { composeAxes, WORLD_AXES } from "../../geometry/frame-axes";
|
|
6
5
|
import { radiansOf } from "../../geometry/scalars";
|
|
7
|
-
import {
|
|
6
|
+
import { scale3 } from "../../geometry/vectors";
|
|
8
7
|
import { ocsAxesOf } from "../drawing/drawing-geometry";
|
|
9
|
-
import { DEFAULT_SPLINE_DEGREE } from "../drawing/drawing.constants";
|
|
10
8
|
import { WorkBudget } from "../work-budget";
|
|
11
9
|
import { ACI_PALETTE } from "./dxf-colors";
|
|
10
|
+
import { placedHatch, placedText, planarTurnOf, readHatchOf, readTextOf } from "./dxf-reader-annotations";
|
|
12
11
|
import { mappedSegments, rotationAboutZ, scaling, translation } from "./dxf-reader-geometry";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
12
|
+
import { readSegmentsOf, recordNormalOf, recordPointOf, segmentWork } from "./dxf-reader-segments";
|
|
13
|
+
import { ANNOTATED_ENTITIES, BLACK, BY_BLOCK, BY_LAYER, BYTE, COPY_WORK, DRAWN_ENTITIES, ENTITY_WORK, FROZEN_FLAG, GREEN_SHIFT, GROUP, IMPERIAL_UNIT_CODES, INSERT_WORK_CEILING, INSERT_WORK_FLOOR, INSERT_WORK_PER_CHARACTER, MAX_INSERT_DEPTH, MAX_LISTED_NAMES, PAPER_SPACE, RED_SHIFT, UNIT_CODES, UNIT_NAMES, XREF_FLAGS, } from "./dxf-reader.constants";
|
|
14
|
+
import { DXF_IMPERIAL_MEASUREMENT, DXF_MAX_NAME_LENGTH, DXF_POINT_CODES, DXF_WHITE_OR_BLACK } from "./dxf.constants";
|
|
15
|
+
import { decodedText, dxfGroupsOf, headerGroupOf, numberIn, numberOf, recordsOf, sectionsOf, textOf } from "./dxf-tokens";
|
|
17
16
|
const HIGH_SURROGATES = /[\uD800-\uDBFF]$/;
|
|
18
17
|
const DEEP_INSERTS_NOTE = `Block inserts nested deeper than ${MAX_INSERT_DEPTH} were left out.`;
|
|
19
18
|
const hexOfRgb = (rgb) => hexOfChannels([(rgb >> RED_SHIFT) & BYTE, (rgb >> GREEN_SHIFT) & BYTE, rgb & BYTE]);
|
|
@@ -28,22 +27,16 @@ const hexOfAci = (index) => {
|
|
|
28
27
|
const byteOf = (channel) => Math.min(BYTE, Math.round(channel));
|
|
29
28
|
return hexOfChannels([byteOf(rgb[0]), byteOf(rgb[1]), byteOf(rgb[2])]);
|
|
30
29
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
case "conic":
|
|
36
|
-
return CONIC_WORK;
|
|
37
|
-
case "spline":
|
|
38
|
-
return segment.curve.points.length;
|
|
39
|
-
case "fit":
|
|
40
|
-
return segment.points.length;
|
|
41
|
-
default:
|
|
42
|
-
return segment.points.length + segment.bulges.filter(bulge => bulge !== 0).length;
|
|
30
|
+
const hatchWork = (hatch) => hatch.boundaries.reduce((total, loop) => loop.reduce((sum, segment) => sum + segmentWork(segment), total), 0);
|
|
31
|
+
const ownAnnotation = (type, read) => {
|
|
32
|
+
if (typeof read === "string") {
|
|
33
|
+
return { text: undefined, hatch: undefined, work: 0, flaw: `${type}\n${read}` };
|
|
43
34
|
}
|
|
35
|
+
if (read === undefined) {
|
|
36
|
+
return { text: undefined, hatch: undefined, work: 0, flaw: undefined };
|
|
37
|
+
}
|
|
38
|
+
return "value" in read ? { text: read, hatch: undefined, work: read.value.length, flaw: undefined } : { text: undefined, hatch: read, work: hatchWork(read), flaw: undefined };
|
|
44
39
|
};
|
|
45
|
-
const drawn = (segments) => ({ segments, work: segments.reduce((total, segment) => total + segmentWork(segment), 0), flaw: undefined, skipped: undefined });
|
|
46
|
-
const flawOf = (type, reason) => ({ segments: [], work: 0, flaw: `${type}\n${reason}`, skipped: undefined });
|
|
47
40
|
const lineTypeOf = (name) => {
|
|
48
41
|
const upper = name.toUpperCase();
|
|
49
42
|
if (upper.startsWith("HIDDEN")) {
|
|
@@ -60,52 +53,18 @@ const lineTypeOf = (name) => {
|
|
|
60
53
|
}
|
|
61
54
|
return Inputs.IO.lineTypeEnum.continuous;
|
|
62
55
|
};
|
|
63
|
-
const pointOf = (record, codes, fallback = [0, 0, 0]) => [numberOf(record, codes[0], fallback[0]), numberOf(record, codes[1], fallback[1]), numberOf(record, codes[2], fallback[2])];
|
|
64
|
-
const normalOf = (record) => { var _a; return (_a = unitOf(pointOf(record, DXF_EXTRUSION_CODES, [0, 0, 1]))) !== null && _a !== void 0 ? _a : [0, 0, 1]; };
|
|
65
|
-
const pointsOf = (record, xCode) => {
|
|
66
|
-
const points = [];
|
|
67
|
-
for (const group of record.groups) {
|
|
68
|
-
if (group.code === xCode) {
|
|
69
|
-
points.push([numberIn(group), 0, 0]);
|
|
70
|
-
}
|
|
71
|
-
else if (group.code === xCode + Y_OFFSET && points.length > 0) {
|
|
72
|
-
points[points.length - 1][1] = numberIn(group);
|
|
73
|
-
}
|
|
74
|
-
else if (group.code === xCode + Z_OFFSET && points.length > 0) {
|
|
75
|
-
points[points.length - 1][2] = numberIn(group);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return points;
|
|
79
|
-
};
|
|
80
|
-
const sectionsOf = (groups) => {
|
|
81
|
-
var _a, _b;
|
|
82
|
-
const sections = new Map();
|
|
83
|
-
let current;
|
|
84
|
-
for (let at = 0; at < groups.length; at++) {
|
|
85
|
-
const group = groups[at];
|
|
86
|
-
if (group.code === 0 && group.value.trim() === "SECTION") {
|
|
87
|
-
current = [];
|
|
88
|
-
sections.set((_b = (_a = groups[at + 1]) === null || _a === void 0 ? void 0 : _a.value.trim()) !== null && _b !== void 0 ? _b : "", current);
|
|
89
|
-
at++;
|
|
90
|
-
}
|
|
91
|
-
else if (group.code === 0 && group.value.trim() === "ENDSEC") {
|
|
92
|
-
current = undefined;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
current === null || current === void 0 ? void 0 : current.push(group);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return sections;
|
|
99
|
-
};
|
|
100
|
-
const headerGroupOf = (header, name) => {
|
|
101
|
-
const at = header.findIndex(group => group.code === GROUP.variable && group.value.trim() === name);
|
|
102
|
-
return at < 0 ? undefined : header[at + 1];
|
|
103
|
-
};
|
|
104
56
|
const shownName = (name) => name.slice(0, DXF_MAX_NAME_LENGTH);
|
|
105
57
|
const plural = (count, one, many) => (count === 1 ? one : many);
|
|
58
|
+
const measurementOf = (stated, unitCode) => {
|
|
59
|
+
if (stated !== undefined) {
|
|
60
|
+
return numberIn(stated) === Number(DXF_IMPERIAL_MEASUREMENT) ? "imperial" : "metric";
|
|
61
|
+
}
|
|
62
|
+
return IMPERIAL_UNIT_CODES.has(unitCode) ? "imperial" : "metric";
|
|
63
|
+
};
|
|
106
64
|
class DxfReading {
|
|
107
|
-
constructor(includeHidden, inputSize) {
|
|
65
|
+
constructor(includeHidden, inputSize, annotated) {
|
|
108
66
|
this.includeHidden = includeHidden;
|
|
67
|
+
this.annotated = annotated;
|
|
109
68
|
this.layers = new Map();
|
|
110
69
|
this.blocks = new Map();
|
|
111
70
|
this.entities = [];
|
|
@@ -117,17 +76,22 @@ class DxfReading {
|
|
|
117
76
|
this.ownStyles = new Map();
|
|
118
77
|
this.styles = new Map();
|
|
119
78
|
this.ownSegments = new Map();
|
|
79
|
+
this.ownAnnotations = new Map();
|
|
120
80
|
this.inserts = new Map();
|
|
121
81
|
this.contentWork = new Map();
|
|
122
82
|
this.hiddenCount = 0;
|
|
123
83
|
this.leftOutInserts = 0;
|
|
124
84
|
this.cutNames = 0;
|
|
85
|
+
this.measurement = "metric";
|
|
125
86
|
this.budget = WorkBudget.forInput(inputSize, INSERT_WORK_PER_CHARACTER, INSERT_WORK_FLOOR, INSERT_WORK_CEILING);
|
|
126
87
|
}
|
|
127
88
|
read(text) {
|
|
128
89
|
var _a, _b, _c, _d, _e;
|
|
129
90
|
const sections = sectionsOf(dxfGroupsOf(text));
|
|
130
91
|
const header = (_a = sections.get("HEADER")) !== null && _a !== void 0 ? _a : [];
|
|
92
|
+
const unitGroup = headerGroupOf(header, "$INSUNITS");
|
|
93
|
+
const unitCode = unitGroup === undefined ? 0 : numberIn(unitGroup);
|
|
94
|
+
this.measurement = measurementOf(headerGroupOf(header, "$MEASUREMENT"), unitCode);
|
|
131
95
|
this.readLayers((_b = sections.get("TABLES")) !== null && _b !== void 0 ? _b : []);
|
|
132
96
|
this.readBlocks((_c = sections.get("BLOCKS")) !== null && _c !== void 0 ? _c : []);
|
|
133
97
|
if (!sections.has("ENTITIES")) {
|
|
@@ -139,8 +103,6 @@ class DxfReading {
|
|
|
139
103
|
for (const record of modelSpace) {
|
|
140
104
|
this.readEntity(record, { map: WORLD_AXES, inherited: undefined, depth: 0 });
|
|
141
105
|
}
|
|
142
|
-
const unitGroup = headerGroupOf(header, "$INSUNITS");
|
|
143
|
-
const unitCode = unitGroup === undefined ? 0 : numberIn(unitGroup);
|
|
144
106
|
const unit = UNIT_CODES.get(unitCode);
|
|
145
107
|
const unitName = UNIT_NAMES.get(unitCode);
|
|
146
108
|
if (unit === undefined && unitName !== undefined) {
|
|
@@ -169,7 +131,7 @@ class DxfReading {
|
|
|
169
131
|
}
|
|
170
132
|
skippedWarnings() {
|
|
171
133
|
const kinds = [...this.skipped];
|
|
172
|
-
const listed = kinds.slice(0, MAX_LISTED_NAMES).map(([type, count]) => `${count} ${shownName(type)} ${plural(count, "entity was", "entities were")} left out: only lines, arcs, circles, ellipses, polylines, splines and block inserts are drawn.`);
|
|
134
|
+
const listed = kinds.slice(0, MAX_LISTED_NAMES).map(([type, count]) => `${count} ${shownName(type)} ${plural(count, "entity was", "entities were")} left out: only lines, arcs, circles, ellipses, polylines, splines${this.annotated ? ", texts, hatches" : ""} and block inserts are drawn.`);
|
|
173
135
|
const rest = kinds.slice(MAX_LISTED_NAMES);
|
|
174
136
|
if (rest.length === 0) {
|
|
175
137
|
return listed;
|
|
@@ -219,7 +181,7 @@ class DxfReading {
|
|
|
219
181
|
let open;
|
|
220
182
|
for (const record of recordsOf(blocks)) {
|
|
221
183
|
if (record.type === "BLOCK") {
|
|
222
|
-
open = { name: this.nameOf(decodedText(textOf(record, GROUP.name))), base:
|
|
184
|
+
open = { name: this.nameOf(decodedText(textOf(record, GROUP.name))), base: recordPointOf(record, DXF_POINT_CODES), entities: [], external: (numberOf(record, GROUP.flags, 0) & XREF_FLAGS) !== 0 };
|
|
223
185
|
}
|
|
224
186
|
else if (record.type === "ENDBLK") {
|
|
225
187
|
if (open !== undefined) {
|
|
@@ -306,8 +268,40 @@ class DxfReading {
|
|
|
306
268
|
var _a;
|
|
307
269
|
this.skipped.set(type, ((_a = this.skipped.get(type)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
308
270
|
}
|
|
309
|
-
|
|
271
|
+
flaw(flaw) {
|
|
310
272
|
var _a;
|
|
273
|
+
this.flawed.set(flaw, ((_a = this.flawed.get(flaw)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
274
|
+
}
|
|
275
|
+
ownAnnotationOf(record, keep) {
|
|
276
|
+
return this.remembered(this.ownAnnotations, record, keep, () => ownAnnotation(record.type, record.type === "TEXT" ? readTextOf(record) : readHatchOf(record, this.measurement)));
|
|
277
|
+
}
|
|
278
|
+
readAnnotation(record, context) {
|
|
279
|
+
const style = this.styleOf(record, context);
|
|
280
|
+
if (style === undefined) {
|
|
281
|
+
this.hiddenCount++;
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const turn = planarTurnOf(context.map);
|
|
285
|
+
if (turn === undefined) {
|
|
286
|
+
this.flaw(`${record.type}\nit sits in a mirrored or unevenly scaled block insert`);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const own = this.ownAnnotationOf(record, context.depth > 0);
|
|
290
|
+
if (own.flaw !== undefined) {
|
|
291
|
+
this.flaw(own.flaw);
|
|
292
|
+
}
|
|
293
|
+
else if (own.text !== undefined) {
|
|
294
|
+
this.entities.push({ style, segments: [], text: placedText(own.text, turn, context.map) });
|
|
295
|
+
}
|
|
296
|
+
else if (own.hatch !== undefined) {
|
|
297
|
+
this.entities.push({ style, segments: [], hatch: placedHatch(own.hatch, turn, context.map, context.map !== WORLD_AXES) });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
readEntity(record, context) {
|
|
301
|
+
if (this.annotated && ANNOTATED_ENTITIES.has(record.type)) {
|
|
302
|
+
this.readAnnotation(record, context);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
311
305
|
if (!DRAWN_ENTITIES.has(record.type)) {
|
|
312
306
|
this.skip(record.type);
|
|
313
307
|
return;
|
|
@@ -323,7 +317,7 @@ class DxfReading {
|
|
|
323
317
|
}
|
|
324
318
|
const own = this.ownSegmentsOf(record, context.depth > 0);
|
|
325
319
|
if (own.flaw !== undefined) {
|
|
326
|
-
this.
|
|
320
|
+
this.flaw(own.flaw);
|
|
327
321
|
}
|
|
328
322
|
if (own.skipped !== undefined) {
|
|
329
323
|
this.skip(own.skipped);
|
|
@@ -341,7 +335,7 @@ class DxfReading {
|
|
|
341
335
|
if (block === undefined || block.external) {
|
|
342
336
|
return { name, block, placement: undefined };
|
|
343
337
|
}
|
|
344
|
-
const placed = composeAxes(ocsAxesOf(
|
|
338
|
+
const placed = composeAxes(ocsAxesOf(recordNormalOf(record)), translation(recordPointOf(record, DXF_POINT_CODES)));
|
|
345
339
|
const turned = rotationAboutZ(radiansOf(numberOf(record, GROUP.rotation, 0)));
|
|
346
340
|
return {
|
|
347
341
|
name,
|
|
@@ -364,6 +358,9 @@ class DxfReading {
|
|
|
364
358
|
if (record.type === "INSERT") {
|
|
365
359
|
return this.capped(ENTITY_WORK + this.copiesWork(this.insertPlanOf(record, true), depth));
|
|
366
360
|
}
|
|
361
|
+
if (this.annotated && ANNOTATED_ENTITIES.has(record.type)) {
|
|
362
|
+
return ENTITY_WORK + this.ownAnnotationOf(record, true).work;
|
|
363
|
+
}
|
|
367
364
|
if (!DRAWN_ENTITIES.has(record.type)) {
|
|
368
365
|
return ENTITY_WORK;
|
|
369
366
|
}
|
|
@@ -438,119 +435,12 @@ class DxfReading {
|
|
|
438
435
|
}
|
|
439
436
|
}
|
|
440
437
|
ownSegmentsOf(record, keep) {
|
|
441
|
-
return this.remembered(this.ownSegments, record, keep, () =>
|
|
442
|
-
switch (record.type) {
|
|
443
|
-
case "LINE":
|
|
444
|
-
return drawn([{ kind: "line", start: pointOf(record, DXF_POINT_CODES), end: pointOf(record, DXF_OTHER_POINT_CODES) }]);
|
|
445
|
-
case "CIRCLE":
|
|
446
|
-
case "ARC":
|
|
447
|
-
return drawn([this.circleOf(record)]);
|
|
448
|
-
case "ELLIPSE":
|
|
449
|
-
return this.ellipseOf(record);
|
|
450
|
-
case "LWPOLYLINE":
|
|
451
|
-
return this.lightPolylineOf(record);
|
|
452
|
-
case "POLYLINE":
|
|
453
|
-
return this.heavyPolylineOf(record);
|
|
454
|
-
default:
|
|
455
|
-
return this.splineOf(record);
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
circleOf(record) {
|
|
460
|
-
const axes = ocsAxesOf(normalOf(record));
|
|
461
|
-
const radius = numberOf(record, GROUP.radius, 0);
|
|
462
|
-
const angleOf = (code) => radiansOf(angleWithinTurn(numberOf(record, code, 0), DEGREES_PER_TURN));
|
|
463
|
-
const start = record.type === "ARC" ? angleOf(GROUP.startAngle) : 0;
|
|
464
|
-
const end = record.type === "ARC" ? angleOf(GROUP.endAngle) : FULL_TURN;
|
|
465
|
-
const turn = angleWithinTurn(end - start, FULL_TURN);
|
|
466
|
-
return {
|
|
467
|
-
kind: "conic",
|
|
468
|
-
center: pointToWorld(axes, pointOf(record, DXF_POINT_CODES)),
|
|
469
|
-
xAxis: scale3(axes.x, radius),
|
|
470
|
-
yAxis: scale3(axes.y, radius),
|
|
471
|
-
start,
|
|
472
|
-
sweep: turn === 0 ? FULL_TURN : turn,
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
ellipseOf(record) {
|
|
476
|
-
const major = pointOf(record, DXF_OTHER_POINT_CODES);
|
|
477
|
-
const minor = unitOf(cross3(normalOf(record), major));
|
|
478
|
-
if (minor === undefined || length3(major) === 0) {
|
|
479
|
-
return flawOf("ELLIPSE", "its major axis has no length or runs along its extrusion");
|
|
480
|
-
}
|
|
481
|
-
const start = angleWithinTurn(numberOf(record, GROUP.startParameter, 0), FULL_TURN);
|
|
482
|
-
const end = numberOf(record, GROUP.endParameter, FULL_TURN);
|
|
483
|
-
const turn = angleWithinTurn(end - start, FULL_TURN);
|
|
484
|
-
return drawn([{ kind: "conic", center: pointOf(record, DXF_POINT_CODES), xAxis: major, yAxis: scale3(minor, length3(major) * numberOf(record, GROUP.ratio, 1)), start, sweep: turn === 0 ? FULL_TURN : turn }]);
|
|
485
|
-
}
|
|
486
|
-
lightPolylineOf(record) {
|
|
487
|
-
const axes = ocsAxesOf(normalOf(record));
|
|
488
|
-
const elevation = numberOf(record, GROUP.elevation, 0);
|
|
489
|
-
const points = [];
|
|
490
|
-
const bulges = [];
|
|
491
|
-
for (const group of record.groups) {
|
|
492
|
-
if (group.code === GROUP.x) {
|
|
493
|
-
points.push([numberIn(group), 0, elevation]);
|
|
494
|
-
bulges.push(0);
|
|
495
|
-
}
|
|
496
|
-
else if (group.code === GROUP.y && points.length > 0) {
|
|
497
|
-
points[points.length - 1][1] = numberIn(group);
|
|
498
|
-
}
|
|
499
|
-
else if (group.code === GROUP.bulge && bulges.length > 0) {
|
|
500
|
-
bulges[bulges.length - 1] = numberIn(group);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return this.polylineOf(record.type, points.map(point => pointToWorld(axes, point)), bulges, (numberOf(record, GROUP.flags, 0) & DXF_CLOSED_FLAG) !== 0, normalOf(record));
|
|
504
|
-
}
|
|
505
|
-
heavyPolylineOf(record) {
|
|
506
|
-
const flags = numberOf(record, GROUP.flags, 0);
|
|
507
|
-
if ((flags & (POLYFACE_FLAG | MESH_FLAG)) !== 0) {
|
|
508
|
-
return { segments: [], work: 0, flaw: undefined, skipped: "POLYLINE mesh" };
|
|
509
|
-
}
|
|
510
|
-
const vertices = record.vertices.filter(vertex => (numberOf(vertex, GROUP.flags, 0) & SPLINE_FRAME_VERTEX_FLAG) === 0);
|
|
511
|
-
const closed = (flags & DXF_CLOSED_FLAG) !== 0;
|
|
512
|
-
if ((flags & DXF_POLYLINE_3D_FLAG) !== 0) {
|
|
513
|
-
return this.polylineOf(record.type, vertices.map(vertex => pointOf(vertex, DXF_POINT_CODES)), vertices.map(() => 0), closed, [0, 0, 1]);
|
|
514
|
-
}
|
|
515
|
-
const axes = ocsAxesOf(normalOf(record));
|
|
516
|
-
const elevation = numberOf(record, GROUP.elevationZ, 0);
|
|
517
|
-
const points = vertices.map(vertex => pointToWorld(axes, [numberOf(vertex, GROUP.x, 0), numberOf(vertex, GROUP.y, 0), elevation]));
|
|
518
|
-
return this.polylineOf(record.type, points, vertices.map(vertex => numberOf(vertex, GROUP.bulge, 0)), closed, normalOf(record));
|
|
519
|
-
}
|
|
520
|
-
polylineOf(type, points, bulges, closed, normal) {
|
|
521
|
-
if (points.length < 2) {
|
|
522
|
-
return flawOf(type, "it has fewer than two points");
|
|
523
|
-
}
|
|
524
|
-
return drawn([{ kind: "polyline", points, bulges, closed, normal }]);
|
|
525
|
-
}
|
|
526
|
-
splineOf(record) {
|
|
527
|
-
const flags = numberOf(record, GROUP.flags, 0);
|
|
528
|
-
const degree = numberOf(record, GROUP.degree, DEFAULT_SPLINE_DEGREE);
|
|
529
|
-
if (degree > MAX_SPLINE_DEGREE) {
|
|
530
|
-
return flawOf("SPLINE", `its degree is above ${MAX_SPLINE_DEGREE}, the highest a kernel curve takes`);
|
|
531
|
-
}
|
|
532
|
-
const controls = pointsOf(record, GROUP.controlX);
|
|
533
|
-
const knots = numbersOf(record, GROUP.knot);
|
|
534
|
-
if (controls.length > degree && knots.length === controls.length + degree + 1 && degree >= 1 && Number.isInteger(degree)) {
|
|
535
|
-
const weights = numbersOf(record, GROUP.weight);
|
|
536
|
-
const rational = (flags & DXF_RATIONAL_FLAG) !== 0 && weights.length === controls.length && weights.every(weight => weight > 0);
|
|
537
|
-
return drawn([{ kind: "spline", curve: { degree, points: controls, weights: rational ? weights : controls.map(() => 1), knots } }]);
|
|
538
|
-
}
|
|
539
|
-
const fits = pointsOf(record, GROUP.fitX);
|
|
540
|
-
if (fits.length > MAX_FIT_POINTS) {
|
|
541
|
-
return flawOf("SPLINE", `it has more than ${MAX_FIT_POINTS} fit points, more than one spline is interpolated through`);
|
|
542
|
-
}
|
|
543
|
-
if (fits.length >= 2) {
|
|
544
|
-
const start = pointsOf(record, GROUP.startTangentX)[0];
|
|
545
|
-
const end = pointsOf(record, GROUP.endTangentX)[0];
|
|
546
|
-
return drawn([{ kind: "fit", points: fits, startTangent: start, endTangent: end, closed: (flags & (DXF_CLOSED_FLAG | PERIODIC_FLAG)) !== 0 }]);
|
|
547
|
-
}
|
|
548
|
-
return flawOf("SPLINE", "it holds neither control points with knots to match nor two fit points");
|
|
438
|
+
return this.remembered(this.ownSegments, record, keep, () => readSegmentsOf(record));
|
|
549
439
|
}
|
|
550
440
|
}
|
|
551
|
-
export const readDxfDrawing = (text, includeHidden) => {
|
|
441
|
+
export const readDxfDrawing = (text, includeHidden, annotated = false) => {
|
|
552
442
|
if (typeof includeHidden !== "boolean") {
|
|
553
443
|
throw new InputError(`\`includeHiddenLayers\` must be true or false, and is of type ${typeof includeHidden}.`, "includeHiddenLayers");
|
|
554
444
|
}
|
|
555
|
-
return new DxfReading(includeHidden, typeof text === "string" ? text.length : 0).read(text);
|
|
445
|
+
return new DxfReading(includeHidden, typeof text === "string" ? text.length : 0, annotated).read(text);
|
|
556
446
|
};
|
|
@@ -2,6 +2,8 @@ import type * as Inputs from "../../../../inputs";
|
|
|
2
2
|
import type { DrawingBounds } from "../drawing/drawing-types";
|
|
3
3
|
import type { DxfText } from "./dxf-text";
|
|
4
4
|
export type DxfVersion = "AC1009" | "AC1015";
|
|
5
|
+
export type DxfMeasurement = "imperial" | "metric";
|
|
6
|
+
export declare const dxfMeasurementOf: (unit: string | undefined) => DxfMeasurement;
|
|
5
7
|
export interface DxfLayerRow {
|
|
6
8
|
readonly name: string;
|
|
7
9
|
readonly color: string;
|