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