@bitbybit-dev/base 1.6.2 → 1.7.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/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +20 -7
- package/lib/api/inputs/base-inputs.js +10 -0
- package/lib/api/inputs/io-inputs.d.ts +527 -59
- package/lib/api/inputs/io-inputs.js +432 -40
- package/lib/api/inputs/line-inputs.d.ts +17 -0
- package/lib/api/inputs/line-inputs.js +15 -0
- package/lib/api/kernel-calls/index.d.ts +1 -0
- package/lib/api/kernel-calls/index.js +1 -0
- package/lib/api/kernel-calls/settings.d.ts +82 -0
- package/lib/api/kernel-calls/settings.js +123 -0
- package/lib/api/recipes/surface-mesh.d.ts +2 -1
- package/lib/api/recipes/surface-mesh.js +5 -3
- package/lib/api/resolved-inputs/index.d.ts +22 -2
- package/lib/api/services/base-bitbybit.d.ts +12 -0
- package/lib/api/services/base-bitbybit.js +19 -3
- package/lib/api/services/color.js +2 -3
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +3 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +1 -0
- package/lib/api/services/helpers/color/color-forms.js +4 -1
- package/lib/api/services/helpers/color/css-colors.constants.d.ts +9 -0
- package/lib/api/services/helpers/color/css-colors.constants.js +158 -0
- package/lib/api/services/helpers/color/css-colors.d.ts +1 -0
- package/lib/api/services/helpers/color/css-colors.js +61 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.constants.js +5 -0
- package/lib/api/services/helpers/curves/bezier-pieces.d.ts +24 -0
- package/lib/api/services/helpers/curves/bezier-pieces.js +149 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.d.ts +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.constants.js +5 -0
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +24 -0
- package/lib/api/services/helpers/curves/conic-arcs.js +85 -0
- package/lib/api/services/helpers/curves/nurbs-forms.d.ts +20 -0
- package/lib/api/services/helpers/curves/nurbs-forms.js +112 -0
- package/lib/api/services/helpers/curves/nurbs.d.ts +4 -0
- package/lib/api/services/helpers/curves/nurbs.js +10 -9
- package/lib/api/services/helpers/files/drawing/drawing-budget.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +24 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +18 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +84 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +5 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.js +252 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +60 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.js +1 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +28 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +29 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-colors.js +45 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +193 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.d.ts +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-file-text.js +50 -0
- package/lib/api/services/helpers/files/dxf/dxf-generator.d.ts +2 -36
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +81 -523
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.d.ts +6 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +81 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.d.ts +21 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-geometry.js +67 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +69 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.js +1 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +71 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +78 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +556 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +247 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.d.ts +26 -0
- package/lib/api/services/helpers/files/dxf/dxf-text.js +97 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +65 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +32 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +34 -1
- package/lib/api/services/helpers/files/file-bytes.d.ts +1 -0
- package/lib/api/services/helpers/files/file-bytes.js +15 -0
- package/lib/api/services/helpers/files/ground-axes.d.ts +2 -0
- package/lib/api/services/helpers/files/ground-axes.js +4 -0
- package/lib/api/services/helpers/files/mesh-file-axes.d.ts +7 -0
- package/lib/api/services/helpers/files/mesh-file-axes.js +17 -0
- package/lib/api/services/helpers/files/stl-axes.d.ts +4 -0
- package/lib/api/services/helpers/files/stl-axes.js +22 -0
- package/lib/api/services/helpers/files/stl-types.d.ts +7 -0
- package/lib/api/services/helpers/files/stl-types.js +1 -0
- package/lib/api/services/helpers/files/stl.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/stl.constants.js +11 -0
- package/lib/api/services/helpers/files/stl.d.ts +3 -0
- package/lib/api/services/helpers/files/stl.js +93 -0
- package/lib/api/services/helpers/files/svg/svg-css.d.ts +48 -0
- package/lib/api/services/helpers/files/svg/svg-css.js +444 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-dash-patterns.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-document.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-document.js +89 -0
- package/lib/api/services/helpers/files/svg/svg-memo.d.ts +1 -0
- package/lib/api/services/helpers/files/svg/svg-memo.js +8 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-normalizer.js +433 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.d.ts +15 -0
- package/lib/api/services/helpers/files/svg/svg-numbers.js +61 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.d.ts +8 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.constants.js +10 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-path-data.js +203 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.d.ts +33 -0
- package/lib/api/services/helpers/files/svg/svg-path-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.d.ts +35 -0
- package/lib/api/services/helpers/files/svg/svg-reader.constants.js +35 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.d.ts +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.constants.js +9 -0
- package/lib/api/services/helpers/files/svg/svg-reading.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-reading.js +233 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.d.ts +54 -0
- package/lib/api/services/helpers/files/svg/svg-scene-types.js +1 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.d.ts +6 -0
- package/lib/api/services/helpers/files/svg/svg-shapes.js +102 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +38 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.js +108 -0
- package/lib/api/services/helpers/files/svg/svg-style.d.ts +26 -0
- package/lib/api/services/helpers/files/svg/svg-style.js +211 -0
- package/lib/api/services/helpers/files/svg/svg-transform.d.ts +10 -0
- package/lib/api/services/helpers/files/svg/svg-transform.js +76 -0
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +16 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +153 -0
- package/lib/api/services/helpers/files/svg/svg-xml.d.ts +11 -0
- package/lib/api/services/helpers/files/svg/svg-xml.js +322 -0
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +13 -0
- package/lib/api/services/helpers/files/svg/svg.constants.js +13 -0
- package/lib/api/services/helpers/files/work-budget.d.ts +11 -0
- package/lib/api/services/helpers/files/work-budget.js +26 -0
- package/lib/api/services/helpers/geometry/affine2.d.ts +8 -0
- package/lib/api/services/helpers/geometry/affine2.js +18 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.d.ts +14 -0
- package/lib/api/services/helpers/geometry/ellipse-arcs.js +96 -0
- package/lib/api/services/helpers/geometry/frame-axes.d.ts +3 -1
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.d.ts +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.constants.js +6 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.d.ts +31 -0
- package/lib/api/services/helpers/geometry/polygon-nesting.js +251 -0
- package/lib/api/services/helpers/geometry/vectors.d.ts +1 -0
- package/lib/api/services/helpers/geometry/vectors.js +6 -0
- package/lib/api/services/io/drawing.d.ts +170 -0
- package/lib/api/services/io/drawing.js +212 -0
- package/lib/api/services/io/dxf.d.ts +134 -0
- package/lib/api/services/io/dxf.js +167 -0
- package/lib/api/services/io/index.d.ts +4 -0
- package/lib/api/services/io/index.js +4 -0
- package/lib/api/services/io/io.d.ts +14 -0
- package/lib/api/services/io/io.js +15 -0
- package/lib/api/services/io/svg.d.ts +64 -0
- package/lib/api/services/io/svg.js +102 -0
- package/lib/api/services/line.d.ts +17 -0
- package/lib/api/services/line.js +20 -1
- package/lib/api/services/point.d.ts +4 -1
- package/lib/api/services/point.js +9 -4
- package/lib/api/services/recipes.d.ts +3 -0
- package/lib/api/services/recipes.js +4 -1
- package/lib/api/services/text.d.ts +4 -1
- package/lib/api/services/text.js +8 -3
- package/package.json +1 -1
- package/lib/api/services/helpers/files/dxf/dxf.d.ts +0 -87
- package/lib/api/services/helpers/files/dxf/dxf.js +0 -111
- package/lib/api/services/io.d.ts +0 -9
- package/lib/api/services/io.js +0 -10
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import { InputError } from "../../../../kernel-calls";
|
|
3
|
+
import { hexOfChannels } from "../../color/color-forms";
|
|
4
|
+
import { angleWithinTurn } from "../../curves/conic-arcs";
|
|
5
|
+
import { composeAxes, pointToWorld, unitOf, WORLD_AXES } from "../../geometry/frame-axes";
|
|
6
|
+
import { radiansOf } from "../../geometry/scalars";
|
|
7
|
+
import { cross3, length3, scale3 } from "../../geometry/vectors";
|
|
8
|
+
import { ocsAxesOf } from "../drawing/drawing-geometry";
|
|
9
|
+
import { DEFAULT_SPLINE_DEGREE } from "../drawing/drawing.constants";
|
|
10
|
+
import { WorkBudget } from "../work-budget";
|
|
11
|
+
import { ACI_PALETTE } from "./dxf-colors";
|
|
12
|
+
import { mappedSegments, rotationAboutZ, scaling, translation } from "./dxf-reader-geometry";
|
|
13
|
+
import { BLACK, BY_BLOCK, BY_LAYER, BYTE, CONIC_WORK, COPY_WORK, DEGREES_PER_TURN, DRAWN_ENTITIES, ENTITY_WORK, FROZEN_FLAG, GREEN_SHIFT, GROUP, INSERT_WORK_CEILING, INSERT_WORK_FLOOR, INSERT_WORK_PER_CHARACTER, LINE_WORK, MAX_FIT_POINTS, MAX_INSERT_DEPTH, MAX_LISTED_NAMES, MAX_SPLINE_DEGREE, MESH_FLAG, PAPER_SPACE, PERIODIC_FLAG, POLYFACE_FLAG, RED_SHIFT, SPLINE_FRAME_VERTEX_FLAG, UNIT_CODES, UNIT_NAMES, XREF_FLAGS, Y_OFFSET, Z_OFFSET, } from "./dxf-reader.constants";
|
|
14
|
+
import { DXF_CLOSED_FLAG, DXF_EXTRUSION_CODES, DXF_MAX_NAME_LENGTH, DXF_OTHER_POINT_CODES, DXF_POINT_CODES, DXF_POLYLINE_3D_FLAG, DXF_RATIONAL_FLAG, DXF_WHITE_OR_BLACK, } from "./dxf.constants";
|
|
15
|
+
import { decodedText, dxfGroupsOf, numberIn, numberOf, numbersOf, recordsOf, textOf } from "./dxf-tokens";
|
|
16
|
+
const FULL_TURN = 2 * Math.PI;
|
|
17
|
+
const HIGH_SURROGATES = /[\uD800-\uDBFF]$/;
|
|
18
|
+
const DEEP_INSERTS_NOTE = `Block inserts nested deeper than ${MAX_INSERT_DEPTH} were left out.`;
|
|
19
|
+
const hexOfRgb = (rgb) => hexOfChannels([(rgb >> RED_SHIFT) & BYTE, (rgb >> GREEN_SHIFT) & BYTE, rgb & BYTE]);
|
|
20
|
+
const hexOfAci = (index) => {
|
|
21
|
+
if (index === DXF_WHITE_OR_BLACK) {
|
|
22
|
+
return BLACK;
|
|
23
|
+
}
|
|
24
|
+
const rgb = ACI_PALETTE[index - 1];
|
|
25
|
+
if (rgb === undefined) {
|
|
26
|
+
return BLACK;
|
|
27
|
+
}
|
|
28
|
+
const byteOf = (channel) => Math.min(BYTE, Math.round(channel));
|
|
29
|
+
return hexOfChannels([byteOf(rgb[0]), byteOf(rgb[1]), byteOf(rgb[2])]);
|
|
30
|
+
};
|
|
31
|
+
const segmentWork = (segment) => {
|
|
32
|
+
switch (segment.kind) {
|
|
33
|
+
case "line":
|
|
34
|
+
return LINE_WORK;
|
|
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;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
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
|
+
const lineTypeOf = (name) => {
|
|
48
|
+
const upper = name.toUpperCase();
|
|
49
|
+
if (upper.startsWith("HIDDEN")) {
|
|
50
|
+
return Inputs.IO.lineTypeEnum.hidden;
|
|
51
|
+
}
|
|
52
|
+
if (upper.startsWith("CENTER")) {
|
|
53
|
+
return Inputs.IO.lineTypeEnum.center;
|
|
54
|
+
}
|
|
55
|
+
if (upper.startsWith("DOT")) {
|
|
56
|
+
return Inputs.IO.lineTypeEnum.dotted;
|
|
57
|
+
}
|
|
58
|
+
if (upper.startsWith("DASH")) {
|
|
59
|
+
return Inputs.IO.lineTypeEnum.dashed;
|
|
60
|
+
}
|
|
61
|
+
return Inputs.IO.lineTypeEnum.continuous;
|
|
62
|
+
};
|
|
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
|
+
const shownName = (name) => name.slice(0, DXF_MAX_NAME_LENGTH);
|
|
105
|
+
const plural = (count, one, many) => (count === 1 ? one : many);
|
|
106
|
+
class DxfReading {
|
|
107
|
+
constructor(includeHidden, inputSize) {
|
|
108
|
+
this.includeHidden = includeHidden;
|
|
109
|
+
this.layers = new Map();
|
|
110
|
+
this.blocks = new Map();
|
|
111
|
+
this.entities = [];
|
|
112
|
+
this.skipped = new Map();
|
|
113
|
+
this.flawed = new Map();
|
|
114
|
+
this.notes = new Set();
|
|
115
|
+
this.missingBlocks = new Set();
|
|
116
|
+
this.externalBlocks = new Set();
|
|
117
|
+
this.ownStyles = new Map();
|
|
118
|
+
this.styles = new Map();
|
|
119
|
+
this.ownSegments = new Map();
|
|
120
|
+
this.inserts = new Map();
|
|
121
|
+
this.contentWork = new Map();
|
|
122
|
+
this.hiddenCount = 0;
|
|
123
|
+
this.leftOutInserts = 0;
|
|
124
|
+
this.cutNames = 0;
|
|
125
|
+
this.budget = WorkBudget.forInput(inputSize, INSERT_WORK_PER_CHARACTER, INSERT_WORK_FLOOR, INSERT_WORK_CEILING);
|
|
126
|
+
}
|
|
127
|
+
read(text) {
|
|
128
|
+
var _a, _b, _c, _d, _e;
|
|
129
|
+
const sections = sectionsOf(dxfGroupsOf(text));
|
|
130
|
+
const header = (_a = sections.get("HEADER")) !== null && _a !== void 0 ? _a : [];
|
|
131
|
+
this.readLayers((_b = sections.get("TABLES")) !== null && _b !== void 0 ? _b : []);
|
|
132
|
+
this.readBlocks((_c = sections.get("BLOCKS")) !== null && _c !== void 0 ? _c : []);
|
|
133
|
+
if (!sections.has("ENTITIES")) {
|
|
134
|
+
throw new InputError("`dxf` has no ENTITIES section, so it is not a DXF drawing.", "dxf");
|
|
135
|
+
}
|
|
136
|
+
const records = recordsOf(sections.get("ENTITIES"));
|
|
137
|
+
const modelSpace = records.filter(record => textOf(record, GROUP.space) !== PAPER_SPACE);
|
|
138
|
+
const paperSpace = records.length - modelSpace.length;
|
|
139
|
+
for (const record of modelSpace) {
|
|
140
|
+
this.readEntity(record, { map: WORLD_AXES, inherited: undefined, depth: 0 });
|
|
141
|
+
}
|
|
142
|
+
const unitGroup = headerGroupOf(header, "$INSUNITS");
|
|
143
|
+
const unitCode = unitGroup === undefined ? 0 : numberIn(unitGroup);
|
|
144
|
+
const unit = UNIT_CODES.get(unitCode);
|
|
145
|
+
const unitName = UNIT_NAMES.get(unitCode);
|
|
146
|
+
if (unit === undefined && unitName !== undefined) {
|
|
147
|
+
this.notes.add(`The file states its unit as ${unitName}, which is not one of mm, cm, m or in; it is read as drawn, with no unit.`);
|
|
148
|
+
}
|
|
149
|
+
const paperSpaceWarning = `${paperSpace} ${paperSpace === 1 ? "entity in paper space was" : "entities in paper space were"} left out: only model space is drawn.`;
|
|
150
|
+
const hiddenWarning = this.hiddenCount === 1
|
|
151
|
+
? "1 entity on a layer switched off or frozen was left out: set includeHiddenLayers to read it."
|
|
152
|
+
: `${this.hiddenCount} entities on layers switched off or frozen were left out: set includeHiddenLayers to read them.`;
|
|
153
|
+
return {
|
|
154
|
+
version: (_e = (_d = headerGroupOf(header, "$ACADVER")) === null || _d === void 0 ? void 0 : _d.value.trim()) !== null && _e !== void 0 ? _e : "",
|
|
155
|
+
unit,
|
|
156
|
+
layers: [...this.layers.values()],
|
|
157
|
+
entities: this.entities,
|
|
158
|
+
warnings: [
|
|
159
|
+
...this.skippedWarnings(),
|
|
160
|
+
...(paperSpace === 0 ? [] : [paperSpaceWarning]),
|
|
161
|
+
...(this.hiddenCount === 0 ? [] : [hiddenWarning]),
|
|
162
|
+
...[...this.flawed].map(([flaw, count]) => `${count} ${flaw.replace("\n", count === 1 ? " entity could not be drawn: " : " entities could not be drawn: ")}.`),
|
|
163
|
+
...this.notes,
|
|
164
|
+
...this.unlistedBlockWarnings(),
|
|
165
|
+
...(this.leftOutInserts === 0 ? [] : [this.leftOutInsertsWarning(text.length)]),
|
|
166
|
+
...(this.cutNames === 0 ? [] : [this.cutNamesWarning()]),
|
|
167
|
+
],
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
skippedWarnings() {
|
|
171
|
+
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.`);
|
|
173
|
+
const rest = kinds.slice(MAX_LISTED_NAMES);
|
|
174
|
+
if (rest.length === 0) {
|
|
175
|
+
return listed;
|
|
176
|
+
}
|
|
177
|
+
const count = rest.reduce((total, [, each]) => total + each, 0);
|
|
178
|
+
return [...listed, `${count} more ${plural(count, "entity", "entities")} of ${rest.length} other ${plural(rest.length, "kind was", "kinds were")} left out as well.`];
|
|
179
|
+
}
|
|
180
|
+
unlistedBlockWarnings() {
|
|
181
|
+
const missing = this.missingBlocks.size - MAX_LISTED_NAMES;
|
|
182
|
+
const external = this.externalBlocks.size - MAX_LISTED_NAMES;
|
|
183
|
+
return [
|
|
184
|
+
...(missing > 0 ? [`Block inserts name ${missing} more ${plural(missing, "block", "blocks")} the file does not define; ${plural(missing, "it was", "they were")} left out.`] : []),
|
|
185
|
+
...(external > 0 ? [`${external} more ${plural(external, "block is an external reference", "blocks are external references")} to another file; ${plural(external, "it was", "they were")} left out.`] : []),
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
leftOutInsertsWarning(size) {
|
|
189
|
+
const count = this.leftOutInserts;
|
|
190
|
+
return `${count} block ${plural(count, "insert was", "inserts were")} left out: with the inserts read before ${plural(count, "it", "them")}, `
|
|
191
|
+
+ `${plural(count, "it places", "they place")} more entities, points and copies than the ${this.budget.capacity} a file of ${size} characters may expand to.`;
|
|
192
|
+
}
|
|
193
|
+
cutNamesWarning() {
|
|
194
|
+
const count = this.cutNames;
|
|
195
|
+
return `${count} layer, block or line type ${plural(count, "name was", "names were")} longer than ${DXF_MAX_NAME_LENGTH} characters, the most AutoCAD allows, and ${plural(count, "was", "were")} cut to ${plural(count, "its", "their")} first ${DXF_MAX_NAME_LENGTH}.`;
|
|
196
|
+
}
|
|
197
|
+
nameOf(value) {
|
|
198
|
+
if (value.length <= DXF_MAX_NAME_LENGTH) {
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
this.cutNames++;
|
|
202
|
+
const cut = value.slice(0, DXF_MAX_NAME_LENGTH);
|
|
203
|
+
return HIGH_SURROGATES.test(cut) ? cut.slice(0, -1) : cut;
|
|
204
|
+
}
|
|
205
|
+
readLayers(tables) {
|
|
206
|
+
for (const record of recordsOf(tables).filter(candidate => candidate.type === "LAYER")) {
|
|
207
|
+
const name = this.nameOf(decodedText(textOf(record, GROUP.name, "0")));
|
|
208
|
+
const aci = numberOf(record, GROUP.color, DXF_WHITE_OR_BLACK);
|
|
209
|
+
const trueColor = textOf(record, GROUP.trueColor);
|
|
210
|
+
this.layers.set(name.toUpperCase(), {
|
|
211
|
+
name,
|
|
212
|
+
color: trueColor === "" ? hexOfAci(Math.abs(aci)) : hexOfRgb(Number(trueColor)),
|
|
213
|
+
lineType: lineTypeOf(this.nameOf(textOf(record, GROUP.lineType, "CONTINUOUS"))),
|
|
214
|
+
hidden: aci < 0 || (numberOf(record, GROUP.flags, 0) & FROZEN_FLAG) !== 0,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
readBlocks(blocks) {
|
|
219
|
+
let open;
|
|
220
|
+
for (const record of recordsOf(blocks)) {
|
|
221
|
+
if (record.type === "BLOCK") {
|
|
222
|
+
open = { name: this.nameOf(decodedText(textOf(record, GROUP.name))), base: pointOf(record, DXF_POINT_CODES), entities: [], external: (numberOf(record, GROUP.flags, 0) & XREF_FLAGS) !== 0 };
|
|
223
|
+
}
|
|
224
|
+
else if (record.type === "ENDBLK") {
|
|
225
|
+
if (open !== undefined) {
|
|
226
|
+
this.blocks.set(open.name.toUpperCase(), { base: open.base, entities: open.entities, external: open.external });
|
|
227
|
+
}
|
|
228
|
+
open = undefined;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
open === null || open === void 0 ? void 0 : open.entities.push(record);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
remembered(memo, record, keep, make) {
|
|
236
|
+
const known = memo.get(record);
|
|
237
|
+
if (known !== undefined) {
|
|
238
|
+
return known;
|
|
239
|
+
}
|
|
240
|
+
const made = make();
|
|
241
|
+
if (keep) {
|
|
242
|
+
memo.set(record, made);
|
|
243
|
+
}
|
|
244
|
+
return made;
|
|
245
|
+
}
|
|
246
|
+
ownStyleOf(record, keep) {
|
|
247
|
+
return this.remembered(this.ownStyles, record, keep, () => {
|
|
248
|
+
const trueColor = textOf(record, GROUP.trueColor);
|
|
249
|
+
const lineTypeName = this.nameOf(textOf(record, GROUP.lineType, "BYLAYER")).toUpperCase();
|
|
250
|
+
return {
|
|
251
|
+
layer: this.nameOf(decodedText(textOf(record, GROUP.layer, "0"))),
|
|
252
|
+
trueColor: trueColor === "" ? undefined : hexOfRgb(Number(trueColor)),
|
|
253
|
+
aci: numberOf(record, GROUP.color, BY_LAYER),
|
|
254
|
+
lineTypeName,
|
|
255
|
+
lineType: lineTypeOf(lineTypeName),
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
styleOf(record, context) {
|
|
260
|
+
var _a;
|
|
261
|
+
if (context.depth === 0) {
|
|
262
|
+
return this.styleFrom(this.ownStyleOf(record, false), context.inherited);
|
|
263
|
+
}
|
|
264
|
+
const known = (_a = this.styles.get(record)) !== null && _a !== void 0 ? _a : new Map();
|
|
265
|
+
this.styles.set(record, known);
|
|
266
|
+
if (known.has(context.inherited)) {
|
|
267
|
+
return known.get(context.inherited);
|
|
268
|
+
}
|
|
269
|
+
const style = this.styleFrom(this.ownStyleOf(record, true), context.inherited);
|
|
270
|
+
known.set(context.inherited, style);
|
|
271
|
+
return style;
|
|
272
|
+
}
|
|
273
|
+
styleFrom(own, inherited) {
|
|
274
|
+
var _a, _b, _c, _d, _e;
|
|
275
|
+
const layerName = own.layer === "0" && inherited !== undefined ? inherited.layer : own.layer;
|
|
276
|
+
const layer = this.layers.get(layerName.toUpperCase());
|
|
277
|
+
if ((layer === null || layer === void 0 ? void 0 : layer.hidden) === true && !this.includeHidden) {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
let color;
|
|
281
|
+
if (own.trueColor !== undefined) {
|
|
282
|
+
color = own.trueColor;
|
|
283
|
+
}
|
|
284
|
+
else if (own.aci === BY_BLOCK) {
|
|
285
|
+
color = (_a = inherited === null || inherited === void 0 ? void 0 : inherited.color) !== null && _a !== void 0 ? _a : BLACK;
|
|
286
|
+
}
|
|
287
|
+
else if (own.aci === BY_LAYER) {
|
|
288
|
+
color = (_b = layer === null || layer === void 0 ? void 0 : layer.color) !== null && _b !== void 0 ? _b : BLACK;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
color = hexOfAci(Math.abs(own.aci));
|
|
292
|
+
}
|
|
293
|
+
let lineType;
|
|
294
|
+
if (own.lineTypeName === "BYLAYER") {
|
|
295
|
+
lineType = (_c = layer === null || layer === void 0 ? void 0 : layer.lineType) !== null && _c !== void 0 ? _c : Inputs.IO.lineTypeEnum.continuous;
|
|
296
|
+
}
|
|
297
|
+
else if (own.lineTypeName === "BYBLOCK") {
|
|
298
|
+
lineType = (_d = inherited === null || inherited === void 0 ? void 0 : inherited.lineType) !== null && _d !== void 0 ? _d : Inputs.IO.lineTypeEnum.continuous;
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
lineType = own.lineType;
|
|
302
|
+
}
|
|
303
|
+
return { layer: (_e = layer === null || layer === void 0 ? void 0 : layer.name) !== null && _e !== void 0 ? _e : layerName, color, lineType };
|
|
304
|
+
}
|
|
305
|
+
skip(type) {
|
|
306
|
+
var _a;
|
|
307
|
+
this.skipped.set(type, ((_a = this.skipped.get(type)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
308
|
+
}
|
|
309
|
+
readEntity(record, context) {
|
|
310
|
+
var _a;
|
|
311
|
+
if (!DRAWN_ENTITIES.has(record.type)) {
|
|
312
|
+
this.skip(record.type);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const style = this.styleOf(record, context);
|
|
316
|
+
if (style === undefined) {
|
|
317
|
+
this.hiddenCount++;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (record.type === "INSERT") {
|
|
321
|
+
this.readInsert(record, style, context);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const own = this.ownSegmentsOf(record, context.depth > 0);
|
|
325
|
+
if (own.flaw !== undefined) {
|
|
326
|
+
this.flawed.set(own.flaw, ((_a = this.flawed.get(own.flaw)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
327
|
+
}
|
|
328
|
+
if (own.skipped !== undefined) {
|
|
329
|
+
this.skip(own.skipped);
|
|
330
|
+
}
|
|
331
|
+
if (own.segments.length === 0) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const segments = context.map === WORLD_AXES ? own.segments : own.segments.flatMap(segment => mappedSegments(context.map, segment));
|
|
335
|
+
this.entities.push({ style, segments });
|
|
336
|
+
}
|
|
337
|
+
insertPlanOf(record, keep) {
|
|
338
|
+
return this.remembered(this.inserts, record, keep, () => {
|
|
339
|
+
const name = this.nameOf(decodedText(textOf(record, GROUP.name)));
|
|
340
|
+
const block = this.blocks.get(name.toUpperCase());
|
|
341
|
+
if (block === undefined || block.external) {
|
|
342
|
+
return { name, block, placement: undefined };
|
|
343
|
+
}
|
|
344
|
+
const placed = composeAxes(ocsAxesOf(normalOf(record)), translation(pointOf(record, DXF_POINT_CODES)));
|
|
345
|
+
const turned = rotationAboutZ(radiansOf(numberOf(record, GROUP.rotation, 0)));
|
|
346
|
+
return {
|
|
347
|
+
name,
|
|
348
|
+
block,
|
|
349
|
+
placement: {
|
|
350
|
+
oriented: composeAxes(placed, turned),
|
|
351
|
+
scaled: composeAxes(scaling(numberOf(record, GROUP.scaleX, 1), numberOf(record, GROUP.scaleY, 1), numberOf(record, GROUP.scaleZ, 1)), translation(scale3(block.base, -1))),
|
|
352
|
+
rows: Math.max(1, Math.floor(numberOf(record, GROUP.rows, 1))),
|
|
353
|
+
columns: Math.max(1, Math.floor(numberOf(record, GROUP.columns, 1))),
|
|
354
|
+
columnStep: numberOf(record, GROUP.columnStep, 0),
|
|
355
|
+
rowStep: numberOf(record, GROUP.rowStep, 0),
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
capped(work) {
|
|
361
|
+
return Math.min(work, this.budget.capacity + 1);
|
|
362
|
+
}
|
|
363
|
+
entityWork(record, depth) {
|
|
364
|
+
if (record.type === "INSERT") {
|
|
365
|
+
return this.capped(ENTITY_WORK + this.copiesWork(this.insertPlanOf(record, true), depth));
|
|
366
|
+
}
|
|
367
|
+
if (!DRAWN_ENTITIES.has(record.type)) {
|
|
368
|
+
return ENTITY_WORK;
|
|
369
|
+
}
|
|
370
|
+
return ENTITY_WORK + this.ownSegmentsOf(record, true).work;
|
|
371
|
+
}
|
|
372
|
+
copiesWork(plan, depth) {
|
|
373
|
+
if (plan.block === undefined || plan.placement === undefined || depth >= MAX_INSERT_DEPTH || plan.block.entities.length === 0) {
|
|
374
|
+
return 0;
|
|
375
|
+
}
|
|
376
|
+
return this.capped(plan.placement.rows * plan.placement.columns * (COPY_WORK + this.contentsWork(plan.block, depth + 1)));
|
|
377
|
+
}
|
|
378
|
+
contentsWork(block, depth) {
|
|
379
|
+
var _a;
|
|
380
|
+
const known = (_a = this.contentWork.get(block)) !== null && _a !== void 0 ? _a : [];
|
|
381
|
+
this.contentWork.set(block, known);
|
|
382
|
+
const remembered = known[depth];
|
|
383
|
+
if (remembered !== undefined) {
|
|
384
|
+
return remembered;
|
|
385
|
+
}
|
|
386
|
+
let total = 0;
|
|
387
|
+
for (const entity of block.entities) {
|
|
388
|
+
total = this.capped(total + this.entityWork(entity, depth));
|
|
389
|
+
if (total > this.budget.capacity) {
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
known[depth] = total;
|
|
394
|
+
return total;
|
|
395
|
+
}
|
|
396
|
+
leaveOutBlock(names, name, note) {
|
|
397
|
+
if (!names.has(name)) {
|
|
398
|
+
names.add(name);
|
|
399
|
+
if (names.size <= MAX_LISTED_NAMES) {
|
|
400
|
+
this.notes.add(note());
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
readInsert(record, style, context) {
|
|
405
|
+
const plan = this.insertPlanOf(record, context.depth > 0);
|
|
406
|
+
const { name, block, placement } = plan;
|
|
407
|
+
if (block === undefined) {
|
|
408
|
+
this.leaveOutBlock(this.missingBlocks, name, () => `A block insert names the block "${name}", which the file does not define; it was left out.`);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (placement === undefined) {
|
|
412
|
+
this.leaveOutBlock(this.externalBlocks, name, () => `The block "${name}" is an external reference to another file; it was left out.`);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (context.depth >= MAX_INSERT_DEPTH) {
|
|
416
|
+
this.notes.add(DEEP_INSERTS_NOTE);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (block.entities.length === 0) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (context.depth === 0) {
|
|
423
|
+
const work = this.copiesWork(plan, 0);
|
|
424
|
+
if (!this.budget.affords(work)) {
|
|
425
|
+
this.leftOutInserts++;
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
this.budget.spend(work);
|
|
429
|
+
}
|
|
430
|
+
const { oriented, scaled, rows, columns, columnStep, rowStep } = placement;
|
|
431
|
+
for (let row = 0; row < rows; row++) {
|
|
432
|
+
for (let column = 0; column < columns; column++) {
|
|
433
|
+
const map = composeAxes(context.map, composeAxes(oriented, composeAxes(translation([column * columnStep, row * rowStep, 0]), scaled)));
|
|
434
|
+
for (const entity of block.entities) {
|
|
435
|
+
this.readEntity(entity, { map, inherited: style, depth: context.depth + 1 });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
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");
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
export const readDxfDrawing = (text, includeHidden) => {
|
|
552
|
+
if (typeof includeHidden !== "boolean") {
|
|
553
|
+
throw new InputError(`\`includeHiddenLayers\` must be true or false, and is of type ${typeof includeHidden}.`, "includeHiddenLayers");
|
|
554
|
+
}
|
|
555
|
+
return new DxfReading(includeHidden, typeof text === "string" ? text.length : 0).read(text);
|
|
556
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as Inputs from "../../../../inputs";
|
|
2
|
+
import type { DrawingBounds } from "../drawing/drawing-types";
|
|
3
|
+
import type { DxfText } from "./dxf-text";
|
|
4
|
+
export type DxfVersion = "AC1009" | "AC1015";
|
|
5
|
+
export interface DxfLayerRow {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly color: string;
|
|
8
|
+
readonly lineType: Inputs.IO.lineTypeEnum;
|
|
9
|
+
}
|
|
10
|
+
export interface DxfLayout {
|
|
11
|
+
readonly version: DxfVersion;
|
|
12
|
+
readonly colorFormat: "aci" | "truecolor";
|
|
13
|
+
readonly unit: string | undefined;
|
|
14
|
+
readonly bounds: DrawingBounds | undefined;
|
|
15
|
+
readonly layers: readonly DxfLayerRow[];
|
|
16
|
+
readonly lineTypes: readonly Inputs.IO.lineTypeEnum[];
|
|
17
|
+
readonly patternUnit: number;
|
|
18
|
+
}
|
|
19
|
+
export interface DxfOwners {
|
|
20
|
+
readonly modelSpace: string;
|
|
21
|
+
readonly paperSpace: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const writeHeader: (text: DxfText, layout: DxfLayout) => number | undefined;
|
|
24
|
+
export declare const writeClasses: (text: DxfText, layout: DxfLayout) => void;
|
|
25
|
+
export declare const writeTables: (text: DxfText, layout: DxfLayout) => DxfOwners;
|
|
26
|
+
export declare const writeBlocks: (text: DxfText, layout: DxfLayout, owners: DxfOwners) => void;
|
|
27
|
+
export declare const writeObjects: (text: DxfText, layout: DxfLayout) => void;
|