@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,248 @@
|
|
|
1
|
+
import { LINE_TYPE_PATTERNS } from "../drawing/drawing.constants";
|
|
2
|
+
import { nearestAciIndex, trueColorOf } from "./dxf-colors";
|
|
3
|
+
import { DXF_GRID_SPACING_CODES, DXF_IMPERIAL_MEASUREMENT, DXF_INSUNITS, DXF_LENS_LENGTH, DXF_METRIC_MEASUREMENT, DXF_OTHER_POINT_CODES, DXF_POINT_CODES, DXF_SNAP_BASE_CODES, DXF_SNAP_SPACING_CODES, DXF_TEXT_STYLE, DXF_VIEW_ASPECT, DXF_VIEW_CENTER_CODES, DXF_VIEW_DIRECTION_CODES, DXF_VIEW_MARGIN, DXF_VIEW_TARGET_CODES, } from "./dxf.constants";
|
|
4
|
+
export const dxfMeasurementOf = (unit) => unit === "in" ? "imperial" : "metric";
|
|
5
|
+
const ORIGIN = [0, 0, 0];
|
|
6
|
+
const isModern = (layout) => layout.version === "AC1015";
|
|
7
|
+
const variable = (text, name) => text.pair("9", name);
|
|
8
|
+
export const writeHeader = (text, layout) => {
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
text.pair("0", "SECTION");
|
|
11
|
+
text.pair("2", "HEADER");
|
|
12
|
+
variable(text, "$ACADVER");
|
|
13
|
+
text.pair("1", layout.version);
|
|
14
|
+
if (isModern(layout)) {
|
|
15
|
+
variable(text, "$DWGCODEPAGE");
|
|
16
|
+
text.pair("3", "ANSI_1252");
|
|
17
|
+
}
|
|
18
|
+
variable(text, "$INSBASE");
|
|
19
|
+
text.point(DXF_POINT_CODES, ORIGIN);
|
|
20
|
+
variable(text, "$EXTMIN");
|
|
21
|
+
text.point(DXF_POINT_CODES, (_b = (_a = layout.bounds) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : ORIGIN);
|
|
22
|
+
variable(text, "$EXTMAX");
|
|
23
|
+
text.point(DXF_POINT_CODES, (_d = (_c = layout.bounds) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : ORIGIN);
|
|
24
|
+
let handseed;
|
|
25
|
+
if (isModern(layout)) {
|
|
26
|
+
if (layout.unit !== undefined) {
|
|
27
|
+
variable(text, "$INSUNITS");
|
|
28
|
+
text.pair("70", DXF_INSUNITS[layout.unit]);
|
|
29
|
+
variable(text, "$MEASUREMENT");
|
|
30
|
+
text.pair("70", dxfMeasurementOf(layout.unit) === "imperial" ? DXF_IMPERIAL_MEASUREMENT : DXF_METRIC_MEASUREMENT);
|
|
31
|
+
}
|
|
32
|
+
variable(text, "$HANDSEED");
|
|
33
|
+
handseed = text.reserve("5");
|
|
34
|
+
}
|
|
35
|
+
text.pair("0", "ENDSEC");
|
|
36
|
+
return handseed;
|
|
37
|
+
};
|
|
38
|
+
export const writeClasses = (text, layout) => {
|
|
39
|
+
if (isModern(layout)) {
|
|
40
|
+
text.pair("0", "SECTION");
|
|
41
|
+
text.pair("2", "CLASSES");
|
|
42
|
+
text.pair("0", "ENDSEC");
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const openTable = (text, layout, name, count) => {
|
|
46
|
+
text.pair("0", "TABLE");
|
|
47
|
+
text.pair("2", name);
|
|
48
|
+
const handle = isModern(layout) ? text.nextHandle() : "";
|
|
49
|
+
if (isModern(layout)) {
|
|
50
|
+
text.pair("5", handle);
|
|
51
|
+
text.pair("330", "0");
|
|
52
|
+
text.pair("100", "AcDbSymbolTable");
|
|
53
|
+
}
|
|
54
|
+
text.pair("70", String(count));
|
|
55
|
+
return handle;
|
|
56
|
+
};
|
|
57
|
+
const openRecord = (text, layout, kind, table, subclass, handleCode = "5") => {
|
|
58
|
+
text.pair("0", kind);
|
|
59
|
+
const handle = isModern(layout) ? text.nextHandle() : "";
|
|
60
|
+
if (isModern(layout)) {
|
|
61
|
+
text.pair(handleCode, handle);
|
|
62
|
+
text.pair("330", table);
|
|
63
|
+
text.pair("100", "AcDbSymbolTableRecord");
|
|
64
|
+
text.pair("100", subclass);
|
|
65
|
+
}
|
|
66
|
+
return handle;
|
|
67
|
+
};
|
|
68
|
+
const closeTable = (text) => text.pair("0", "ENDTAB");
|
|
69
|
+
const writeViewports = (text, layout) => {
|
|
70
|
+
var _a, _b, _c, _d;
|
|
71
|
+
const table = openTable(text, layout, "VPORT", 1);
|
|
72
|
+
openRecord(text, layout, "VPORT", table, "AcDbViewportTableRecord");
|
|
73
|
+
const min = (_b = (_a = layout.bounds) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : ORIGIN;
|
|
74
|
+
const max = (_d = (_c = layout.bounds) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : ORIGIN;
|
|
75
|
+
const width = Math.max(max[0] - min[0], 1);
|
|
76
|
+
const height = Math.max(max[1] - min[1], width / DXF_VIEW_ASPECT);
|
|
77
|
+
text.pair("2", "*ACTIVE");
|
|
78
|
+
text.pair("70", "0");
|
|
79
|
+
text.point(DXF_POINT_CODES, ORIGIN);
|
|
80
|
+
text.point(DXF_OTHER_POINT_CODES, [1, 1, 0]);
|
|
81
|
+
text.point(DXF_VIEW_CENTER_CODES, [(min[0] + max[0]) / 2, (min[1] + max[1]) / 2, 0]);
|
|
82
|
+
text.point(DXF_SNAP_BASE_CODES, ORIGIN);
|
|
83
|
+
text.point(DXF_SNAP_SPACING_CODES, [1, 1, 0]);
|
|
84
|
+
text.point(DXF_GRID_SPACING_CODES, [1, 1, 0]);
|
|
85
|
+
text.point(DXF_VIEW_DIRECTION_CODES, [0, 0, 1]);
|
|
86
|
+
text.point(DXF_VIEW_TARGET_CODES, ORIGIN);
|
|
87
|
+
text.real("40", height * DXF_VIEW_MARGIN);
|
|
88
|
+
text.real("41", DXF_VIEW_ASPECT);
|
|
89
|
+
text.real("42", DXF_LENS_LENGTH);
|
|
90
|
+
text.real("43", 0);
|
|
91
|
+
text.real("44", 0);
|
|
92
|
+
text.real("50", 0);
|
|
93
|
+
text.real("51", 0);
|
|
94
|
+
for (const [code, value] of [["71", "0"], ["72", "100"], ["73", "1"], ["74", "3"], ["75", "0"], ["76", "0"], ["77", "0"], ["78", "0"]]) {
|
|
95
|
+
text.pair(code, value);
|
|
96
|
+
}
|
|
97
|
+
closeTable(text);
|
|
98
|
+
};
|
|
99
|
+
const writeLineTypeRecord = (text, layout, table, name, description, elements) => {
|
|
100
|
+
openRecord(text, layout, "LTYPE", table, "AcDbLinetypeTableRecord");
|
|
101
|
+
text.name("2", name);
|
|
102
|
+
text.pair("70", "0");
|
|
103
|
+
text.pair("3", description);
|
|
104
|
+
text.pair("72", "65");
|
|
105
|
+
text.pair("73", String(elements.length));
|
|
106
|
+
text.real("40", elements.reduce((total, element) => total + Math.abs(element), 0) * layout.patternUnit);
|
|
107
|
+
for (const element of elements) {
|
|
108
|
+
text.real("49", element * layout.patternUnit);
|
|
109
|
+
if (isModern(layout)) {
|
|
110
|
+
text.pair("74", "0");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const writeLineTypes = (text, layout) => {
|
|
115
|
+
const extra = isModern(layout) ? ["ByBlock", "ByLayer"] : [];
|
|
116
|
+
const table = openTable(text, layout, "LTYPE", extra.length + 1 + layout.lineTypes.length);
|
|
117
|
+
for (const name of extra) {
|
|
118
|
+
writeLineTypeRecord(text, layout, table, name, "", []);
|
|
119
|
+
}
|
|
120
|
+
writeLineTypeRecord(text, layout, table, LINE_TYPE_PATTERNS["continuous"].name, LINE_TYPE_PATTERNS["continuous"].description, []);
|
|
121
|
+
for (const lineType of layout.lineTypes) {
|
|
122
|
+
const pattern = LINE_TYPE_PATTERNS[lineType];
|
|
123
|
+
writeLineTypeRecord(text, layout, table, pattern.name, pattern.description, pattern.elements);
|
|
124
|
+
}
|
|
125
|
+
closeTable(text);
|
|
126
|
+
};
|
|
127
|
+
const writeLayers = (text, layout) => {
|
|
128
|
+
const table = openTable(text, layout, "LAYER", layout.layers.length);
|
|
129
|
+
for (const layer of layout.layers) {
|
|
130
|
+
openRecord(text, layout, "LAYER", table, "AcDbLayerTableRecord");
|
|
131
|
+
text.name("2", layer.name);
|
|
132
|
+
text.pair("70", "0");
|
|
133
|
+
text.pair("62", String(nearestAciIndex(layer.color)));
|
|
134
|
+
if (isModern(layout) && layout.colorFormat === "truecolor") {
|
|
135
|
+
text.pair("420", String(trueColorOf(layer.color)));
|
|
136
|
+
}
|
|
137
|
+
text.pair("6", LINE_TYPE_PATTERNS[layer.lineType].name);
|
|
138
|
+
if (isModern(layout)) {
|
|
139
|
+
text.pair("370", "-3");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
closeTable(text);
|
|
143
|
+
};
|
|
144
|
+
const writeStyles = (text, layout) => {
|
|
145
|
+
const table = openTable(text, layout, "STYLE", 1);
|
|
146
|
+
openRecord(text, layout, "STYLE", table, "AcDbTextStyleTableRecord");
|
|
147
|
+
for (const [code, value] of [["2", DXF_TEXT_STYLE], ["70", "0"], ["40", "0.0"], ["41", "1.0"], ["50", "0.0"], ["71", "0"], ["42", "2.5"], ["3", "txt"], ["4", ""]]) {
|
|
148
|
+
text.pair(code, value);
|
|
149
|
+
}
|
|
150
|
+
closeTable(text);
|
|
151
|
+
};
|
|
152
|
+
const writeEmptyTable = (text, layout, name) => {
|
|
153
|
+
openTable(text, layout, name, 0);
|
|
154
|
+
closeTable(text);
|
|
155
|
+
};
|
|
156
|
+
const writeApplications = (text, layout) => {
|
|
157
|
+
const table = openTable(text, layout, "APPID", 1);
|
|
158
|
+
openRecord(text, layout, "APPID", table, "AcDbRegAppTableRecord");
|
|
159
|
+
text.pair("2", "ACAD");
|
|
160
|
+
text.pair("70", "0");
|
|
161
|
+
closeTable(text);
|
|
162
|
+
};
|
|
163
|
+
const writeDimensionStyles = (text, layout) => {
|
|
164
|
+
const table = openTable(text, layout, "DIMSTYLE", 1);
|
|
165
|
+
if (isModern(layout)) {
|
|
166
|
+
text.pair("100", "AcDbDimStyleTable");
|
|
167
|
+
text.pair("71", "1");
|
|
168
|
+
text.pair("340", text.peekHandle());
|
|
169
|
+
}
|
|
170
|
+
openRecord(text, layout, "DIMSTYLE", table, "AcDbDimStyleTableRecord", "105");
|
|
171
|
+
text.pair("2", DXF_TEXT_STYLE);
|
|
172
|
+
text.pair("70", "0");
|
|
173
|
+
closeTable(text);
|
|
174
|
+
};
|
|
175
|
+
const writeBlockRecords = (text, layout) => {
|
|
176
|
+
const table = openTable(text, layout, "BLOCK_RECORD", 2);
|
|
177
|
+
const modelSpace = openRecord(text, layout, "BLOCK_RECORD", table, "AcDbBlockTableRecord");
|
|
178
|
+
text.pair("2", "*Model_Space");
|
|
179
|
+
const paperSpace = openRecord(text, layout, "BLOCK_RECORD", table, "AcDbBlockTableRecord");
|
|
180
|
+
text.pair("2", "*Paper_Space");
|
|
181
|
+
closeTable(text);
|
|
182
|
+
return { modelSpace, paperSpace };
|
|
183
|
+
};
|
|
184
|
+
export const writeTables = (text, layout) => {
|
|
185
|
+
text.pair("0", "SECTION");
|
|
186
|
+
text.pair("2", "TABLES");
|
|
187
|
+
writeViewports(text, layout);
|
|
188
|
+
writeLineTypes(text, layout);
|
|
189
|
+
writeLayers(text, layout);
|
|
190
|
+
writeStyles(text, layout);
|
|
191
|
+
writeEmptyTable(text, layout, "VIEW");
|
|
192
|
+
writeEmptyTable(text, layout, "UCS");
|
|
193
|
+
writeApplications(text, layout);
|
|
194
|
+
writeDimensionStyles(text, layout);
|
|
195
|
+
const owners = isModern(layout) ? writeBlockRecords(text, layout) : { modelSpace: "", paperSpace: "" };
|
|
196
|
+
text.pair("0", "ENDSEC");
|
|
197
|
+
return owners;
|
|
198
|
+
};
|
|
199
|
+
const writeBlock = (text, owner, name, paper) => {
|
|
200
|
+
text.pair("0", "BLOCK");
|
|
201
|
+
text.pair("5", text.nextHandle());
|
|
202
|
+
text.pair("330", owner);
|
|
203
|
+
text.pair("100", "AcDbEntity");
|
|
204
|
+
if (paper) {
|
|
205
|
+
text.pair("67", "1");
|
|
206
|
+
}
|
|
207
|
+
text.pair("8", "0");
|
|
208
|
+
text.pair("100", "AcDbBlockBegin");
|
|
209
|
+
text.pair("2", name);
|
|
210
|
+
text.pair("70", "0");
|
|
211
|
+
text.point(DXF_POINT_CODES, ORIGIN);
|
|
212
|
+
text.pair("3", name);
|
|
213
|
+
text.pair("1", "");
|
|
214
|
+
text.pair("0", "ENDBLK");
|
|
215
|
+
text.pair("5", text.nextHandle());
|
|
216
|
+
text.pair("330", owner);
|
|
217
|
+
text.pair("100", "AcDbEntity");
|
|
218
|
+
if (paper) {
|
|
219
|
+
text.pair("67", "1");
|
|
220
|
+
}
|
|
221
|
+
text.pair("8", "0");
|
|
222
|
+
text.pair("100", "AcDbBlockEnd");
|
|
223
|
+
};
|
|
224
|
+
export const writeBlocks = (text, layout, owners) => {
|
|
225
|
+
text.pair("0", "SECTION");
|
|
226
|
+
text.pair("2", "BLOCKS");
|
|
227
|
+
if (isModern(layout)) {
|
|
228
|
+
writeBlock(text, owners.modelSpace, "*Model_Space", false);
|
|
229
|
+
writeBlock(text, owners.paperSpace, "*Paper_Space", true);
|
|
230
|
+
}
|
|
231
|
+
text.pair("0", "ENDSEC");
|
|
232
|
+
};
|
|
233
|
+
export const writeObjects = (text, layout) => {
|
|
234
|
+
if (!isModern(layout)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const root = text.nextHandle();
|
|
238
|
+
const groups = text.nextHandle();
|
|
239
|
+
text.pair("0", "SECTION");
|
|
240
|
+
text.pair("2", "OBJECTS");
|
|
241
|
+
for (const [code, value] of [["0", "DICTIONARY"], ["5", root], ["330", "0"], ["100", "AcDbDictionary"], ["281", "1"], ["3", "ACAD_GROUP"], ["350", groups]]) {
|
|
242
|
+
text.pair(code, value);
|
|
243
|
+
}
|
|
244
|
+
for (const [code, value] of [["0", "DICTIONARY"], ["5", groups], ["330", root], ["100", "AcDbDictionary"], ["281", "1"]]) {
|
|
245
|
+
text.pair(code, value);
|
|
246
|
+
}
|
|
247
|
+
text.pair("0", "ENDSEC");
|
|
248
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WorkBudget } from "../work-budget";
|
|
2
|
+
export interface DxfTextLimit {
|
|
3
|
+
readonly budget: WorkBudget;
|
|
4
|
+
readonly property: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const realText: (value: number) => string;
|
|
7
|
+
export declare const encodedText: (value: string) => string;
|
|
8
|
+
export declare class DxfText {
|
|
9
|
+
private readonly limit;
|
|
10
|
+
private readonly pieces;
|
|
11
|
+
private readonly encodedNames;
|
|
12
|
+
private handle;
|
|
13
|
+
constructor(firstHandle: number, limit?: DxfTextLimit);
|
|
14
|
+
get budget(): WorkBudget;
|
|
15
|
+
refuseWhenSpent(): void;
|
|
16
|
+
pair(code: string, value: string): void;
|
|
17
|
+
real(code: string, value: number): void;
|
|
18
|
+
point(codes: readonly [number, number, number], point: readonly [number, number, number]): void;
|
|
19
|
+
name(code: string, value: string): void;
|
|
20
|
+
nextHandle(): string;
|
|
21
|
+
peekHandle(): string;
|
|
22
|
+
reserve(code: string): number;
|
|
23
|
+
fill(slot: number, value: string): void;
|
|
24
|
+
joined(): string;
|
|
25
|
+
private tooLarge;
|
|
26
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { InputError } from "../../../../kernel-calls";
|
|
2
|
+
import { WorkBudget } from "../work-budget";
|
|
3
|
+
import { DXF_HEX_RADIX, DXF_HEX_WIDTH, DXF_HIGHEST_ASCII } from "./dxf.constants";
|
|
4
|
+
const plainDecimalOf = (exponential) => {
|
|
5
|
+
const [mantissa, exponentText] = exponential.split("e");
|
|
6
|
+
const negative = mantissa.startsWith("-");
|
|
7
|
+
const digits = (negative ? mantissa.slice(1) : mantissa).replace(".", "");
|
|
8
|
+
const exponent = Number(exponentText);
|
|
9
|
+
const plain = exponent < 0
|
|
10
|
+
? `0.${"0".repeat(-exponent - 1)}${digits}`
|
|
11
|
+
: `${digits}${"0".repeat(exponent + 1 - digits.length)}`;
|
|
12
|
+
return negative ? `-${plain}` : plain;
|
|
13
|
+
};
|
|
14
|
+
export const realText = (value) => {
|
|
15
|
+
if (value === 0) {
|
|
16
|
+
return "0.0";
|
|
17
|
+
}
|
|
18
|
+
const shortest = String(value);
|
|
19
|
+
const text = shortest.includes("e") ? plainDecimalOf(shortest) : shortest;
|
|
20
|
+
return text.includes(".") ? text : `${text}.0`;
|
|
21
|
+
};
|
|
22
|
+
export const encodedText = (value) => {
|
|
23
|
+
let encoded = "";
|
|
24
|
+
for (let at = 0; at < value.length; at++) {
|
|
25
|
+
const code = value.charCodeAt(at);
|
|
26
|
+
encoded += code > DXF_HIGHEST_ASCII ? `\\U+${code.toString(DXF_HEX_RADIX).toUpperCase().padStart(DXF_HEX_WIDTH, "0")}` : value[at];
|
|
27
|
+
}
|
|
28
|
+
return encoded;
|
|
29
|
+
};
|
|
30
|
+
export class DxfText {
|
|
31
|
+
constructor(firstHandle, limit = { budget: new WorkBudget(Number.POSITIVE_INFINITY), property: "dxf" }) {
|
|
32
|
+
this.limit = limit;
|
|
33
|
+
this.pieces = [];
|
|
34
|
+
this.encodedNames = new Map();
|
|
35
|
+
this.handle = firstHandle;
|
|
36
|
+
}
|
|
37
|
+
get budget() {
|
|
38
|
+
return this.limit.budget;
|
|
39
|
+
}
|
|
40
|
+
refuseWhenSpent() {
|
|
41
|
+
if (this.limit.budget.exhausted) {
|
|
42
|
+
throw this.tooLarge();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
pair(code, value) {
|
|
46
|
+
if (!this.limit.budget.spend(code.length + value.length + 2)) {
|
|
47
|
+
throw this.tooLarge();
|
|
48
|
+
}
|
|
49
|
+
this.pieces.push(code, value);
|
|
50
|
+
}
|
|
51
|
+
real(code, value) {
|
|
52
|
+
this.pair(code, realText(value));
|
|
53
|
+
}
|
|
54
|
+
point(codes, point) {
|
|
55
|
+
this.real(String(codes[0]), point[0]);
|
|
56
|
+
this.real(String(codes[1]), point[1]);
|
|
57
|
+
this.real(String(codes[2]), point[2]);
|
|
58
|
+
}
|
|
59
|
+
name(code, value) {
|
|
60
|
+
let encoded = this.encodedNames.get(value);
|
|
61
|
+
if (encoded === undefined) {
|
|
62
|
+
encoded = encodedText(value);
|
|
63
|
+
this.encodedNames.set(value, encoded);
|
|
64
|
+
}
|
|
65
|
+
this.pair(code, encoded);
|
|
66
|
+
}
|
|
67
|
+
nextHandle() {
|
|
68
|
+
const handle = this.handle.toString(DXF_HEX_RADIX).toUpperCase();
|
|
69
|
+
this.handle++;
|
|
70
|
+
return handle;
|
|
71
|
+
}
|
|
72
|
+
peekHandle() {
|
|
73
|
+
return this.handle.toString(DXF_HEX_RADIX).toUpperCase();
|
|
74
|
+
}
|
|
75
|
+
reserve(code) {
|
|
76
|
+
this.pair(code, "");
|
|
77
|
+
return this.pieces.length - 1;
|
|
78
|
+
}
|
|
79
|
+
fill(slot, value) {
|
|
80
|
+
if (!this.limit.budget.spend(value.length)) {
|
|
81
|
+
throw this.tooLarge();
|
|
82
|
+
}
|
|
83
|
+
this.pieces[slot] = value;
|
|
84
|
+
}
|
|
85
|
+
joined() {
|
|
86
|
+
try {
|
|
87
|
+
return `${this.pieces.join("\n")}\n`;
|
|
88
|
+
}
|
|
89
|
+
catch (_a) {
|
|
90
|
+
throw this.tooLarge();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
tooLarge() {
|
|
94
|
+
const { budget, property } = this.limit;
|
|
95
|
+
return new InputError(`\`${property}\` is too large to write as DXF: it takes more than ${budget.capacity} steps, each character written and each control point blended counted, the most a drawing of its size may take.`, property);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DxfEntityRecord, DxfGroup } from "./dxf-reader-types";
|
|
2
|
+
export declare const dxfGroupsOf: (text: string) => DxfGroup[];
|
|
3
|
+
export declare const recordsOf: (groups: readonly DxfGroup[]) => DxfEntityRecord[];
|
|
4
|
+
export declare const numberIn: (group: DxfGroup) => number;
|
|
5
|
+
export declare const valueOf: (record: DxfEntityRecord, code: number) => string | undefined;
|
|
6
|
+
export declare const textOf: (record: DxfEntityRecord, code: number, fallback?: string) => string;
|
|
7
|
+
export declare const numberOf: (record: DxfEntityRecord, code: number, fallback: number) => number;
|
|
8
|
+
export declare const numbersOf: (record: DxfEntityRecord, code: number) => number[];
|
|
9
|
+
export declare const decodedText: (value: string) => string;
|
|
10
|
+
export declare const sectionsOf: (groups: readonly DxfGroup[]) => Map<string, DxfGroup[]>;
|
|
11
|
+
export declare const headerGroupOf: (header: readonly DxfGroup[], name: string) => DxfGroup | undefined;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { InputError } from "../../../../kernel-calls";
|
|
2
|
+
import { BINARY_SENTINEL, GROUP, QUOTED_LENGTH } from "./dxf-reader.constants";
|
|
3
|
+
import { DXF_HEX_RADIX } from "./dxf.constants";
|
|
4
|
+
export const dxfGroupsOf = (text) => {
|
|
5
|
+
if (text.startsWith(BINARY_SENTINEL)) {
|
|
6
|
+
throw new InputError("`dxf` is a binary DXF file; save it as ASCII DXF, which every CAD program can write.", "dxf");
|
|
7
|
+
}
|
|
8
|
+
const lines = text.split(/\r\n|\r|\n/);
|
|
9
|
+
const groups = [];
|
|
10
|
+
for (let at = 0; at + 1 < lines.length; at += 2) {
|
|
11
|
+
const codeText = lines[at].trim();
|
|
12
|
+
if (codeText === "" && at + 2 >= lines.length) {
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
const code = Number(codeText);
|
|
16
|
+
if (codeText === "" || !Number.isInteger(code)) {
|
|
17
|
+
throw new InputError(`\`dxf\` is damaged: line ${at + 1} should hold a group code, a whole number, and holds "${codeText.slice(0, QUOTED_LENGTH)}".`, "dxf");
|
|
18
|
+
}
|
|
19
|
+
groups.push({ code, value: lines[at + 1], line: at + 1 });
|
|
20
|
+
}
|
|
21
|
+
return groups;
|
|
22
|
+
};
|
|
23
|
+
export const recordsOf = (groups) => {
|
|
24
|
+
const records = [];
|
|
25
|
+
let current;
|
|
26
|
+
let polyline;
|
|
27
|
+
for (const group of groups) {
|
|
28
|
+
if (group.code !== 0) {
|
|
29
|
+
current === null || current === void 0 ? void 0 : current.groups.push(group);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const type = group.value.trim();
|
|
33
|
+
current = { type, groups: [], vertices: [] };
|
|
34
|
+
if (type === "VERTEX") {
|
|
35
|
+
polyline === null || polyline === void 0 ? void 0 : polyline.vertices.push(current);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (type === "SEQEND") {
|
|
39
|
+
polyline = undefined;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
polyline = type === "POLYLINE" ? current : undefined;
|
|
43
|
+
records.push(current);
|
|
44
|
+
}
|
|
45
|
+
return records;
|
|
46
|
+
};
|
|
47
|
+
export const numberIn = (group) => {
|
|
48
|
+
const text = group.value.trim();
|
|
49
|
+
const value = Number(text);
|
|
50
|
+
if (text === "" || !Number.isFinite(value)) {
|
|
51
|
+
throw new InputError(`\`dxf\` is damaged: line ${group.line + 1} should hold a number for group code ${group.code} and holds "${text.slice(0, QUOTED_LENGTH)}".`, "dxf");
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
};
|
|
55
|
+
export const valueOf = (record, code) => { var _a; return (_a = record.groups.find(group => group.code === code)) === null || _a === void 0 ? void 0 : _a.value; };
|
|
56
|
+
export const textOf = (record, code, fallback = "") => { var _a, _b; return (_b = (_a = valueOf(record, code)) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : fallback; };
|
|
57
|
+
export const numberOf = (record, code, fallback) => {
|
|
58
|
+
const group = record.groups.find(candidate => candidate.code === code);
|
|
59
|
+
if (group === undefined) {
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
return numberIn(group);
|
|
63
|
+
};
|
|
64
|
+
export const numbersOf = (record, code) => record.groups.filter(group => group.code === code).map(numberIn);
|
|
65
|
+
export const decodedText = (value) => value.replace(/\\U\+([0-9A-Fa-f]{4})/g, (_match, hex) => String.fromCharCode(parseInt(hex, DXF_HEX_RADIX)));
|
|
66
|
+
export const sectionsOf = (groups) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const sections = new Map();
|
|
69
|
+
let current;
|
|
70
|
+
for (let at = 0; at < groups.length; at++) {
|
|
71
|
+
const group = groups[at];
|
|
72
|
+
if (group.code === 0 && group.value.trim() === "SECTION") {
|
|
73
|
+
current = [];
|
|
74
|
+
sections.set((_b = (_a = groups[at + 1]) === null || _a === void 0 ? void 0 : _a.value.trim()) !== null && _b !== void 0 ? _b : "", current);
|
|
75
|
+
at++;
|
|
76
|
+
}
|
|
77
|
+
else if (group.code === 0 && group.value.trim() === "ENDSEC") {
|
|
78
|
+
current = undefined;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
current === null || current === void 0 ? void 0 : current.push(group);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return sections;
|
|
85
|
+
};
|
|
86
|
+
export const headerGroupOf = (header, name) => {
|
|
87
|
+
const at = header.findIndex(group => group.code === GROUP.variable && group.value.trim() === name);
|
|
88
|
+
return at < 0 ? undefined : header[at + 1];
|
|
89
|
+
};
|
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import type { DxfMeasurement } from "./dxf-tables";
|
|
2
|
+
export declare const DXF_FIRST_HANDLE = 32;
|
|
2
3
|
export declare const DXF_INSUNITS: Readonly<Record<string, string>>;
|
|
3
4
|
export declare const DXF_IMPERIAL_MEASUREMENT = "0";
|
|
4
5
|
export declare const DXF_METRIC_MEASUREMENT = "1";
|
|
6
|
+
export declare const DXF_HIGHEST_ASCII = 126;
|
|
7
|
+
export declare const DXF_HEX_WIDTH = 4;
|
|
8
|
+
export declare const DXF_VIEW_MARGIN = 1.1;
|
|
9
|
+
export declare const DXF_VIEW_ASPECT = 1.5;
|
|
10
|
+
export declare const DXF_KNOT_TOLERANCE = "0.0000001";
|
|
11
|
+
export declare const DXF_FIXED_COLORS: readonly (readonly [number, number, number])[];
|
|
12
|
+
export declare const DXF_SHADES: number[];
|
|
13
|
+
export declare const DXF_GRAYS: number[];
|
|
14
|
+
export declare const DXF_HUE_STEP_DEGREES = 15;
|
|
15
|
+
export declare const DXF_PURE_HUE_LIGHTNESS = 0.5;
|
|
16
|
+
export declare const DXF_HUES = 24;
|
|
17
|
+
export declare const DXF_PASTEL_SHARE: number;
|
|
18
|
+
export declare const DXF_WHITE_OR_BLACK = 7;
|
|
19
|
+
export declare const DXF_TRUE_COLOR_RED = 65536;
|
|
20
|
+
export declare const DXF_TRUE_COLOR_GREEN = 256;
|
|
21
|
+
export declare const DXF_LENS_LENGTH = 50;
|
|
22
|
+
export declare const DXF_HEX_RADIX = 16;
|
|
23
|
+
export declare const DXF_TURN_SLACK = 1e-9;
|
|
24
|
+
export declare const DXF_POINT_CODES: readonly [10, 20, 30];
|
|
25
|
+
export declare const DXF_OTHER_POINT_CODES: readonly [11, 21, 31];
|
|
26
|
+
export declare const DXF_EXTRUSION_CODES: readonly [210, 220, 230];
|
|
27
|
+
export declare const DXF_VIEW_CENTER_CODES: readonly [12, 22, 32];
|
|
28
|
+
export declare const DXF_SNAP_BASE_CODES: readonly [13, 23, 33];
|
|
29
|
+
export declare const DXF_SNAP_SPACING_CODES: readonly [14, 24, 34];
|
|
30
|
+
export declare const DXF_GRID_SPACING_CODES: readonly [15, 25, 35];
|
|
31
|
+
export declare const DXF_VIEW_DIRECTION_CODES: readonly [16, 26, 36];
|
|
32
|
+
export declare const DXF_VIEW_TARGET_CODES: readonly [17, 27, 37];
|
|
33
|
+
export declare const DXF_CLOSED_FLAG = 1;
|
|
34
|
+
export declare const DXF_RATIONAL_FLAG = 4;
|
|
35
|
+
export declare const DXF_POLYLINE_3D_FLAG = 8;
|
|
36
|
+
export declare const DXF_MAX_NAME_LENGTH = 255;
|
|
37
|
+
export declare const DXF_LINE_WEIGHTS: number[];
|
|
38
|
+
export declare const DXF_LINE_WEIGHTS_PER_MILLIMETRE = 100;
|
|
39
|
+
export declare const DXF_TEXT_STYLE = "Standard";
|
|
40
|
+
export declare const DXF_CODED_BACKSLASH = "\\U+005C";
|
|
41
|
+
export declare const DXF_CHARACTER_CODE_START: RegExp;
|
|
42
|
+
export declare const DXF_FIT_JUSTIFICATION = "5";
|
|
43
|
+
export declare const DXF_POLYLINE_BOUNDARY = "3";
|
|
44
|
+
export declare const DXF_HATCH_NAMES: Readonly<Record<string, string>>;
|
|
45
|
+
export declare const DXF_HATCH_NATIVE_ANGLE = 45;
|
|
46
|
+
export declare const DXF_HATCH_NATIVE_SPACING: Readonly<Record<DxfMeasurement, Readonly<Record<string, number>>>>;
|
|
@@ -1,4 +1,50 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const DXF_FIRST_HANDLE = 0x20;
|
|
2
2
|
export const DXF_INSUNITS = { in: "1", mm: "4", cm: "5", m: "6" };
|
|
3
3
|
export const DXF_IMPERIAL_MEASUREMENT = "0";
|
|
4
4
|
export const DXF_METRIC_MEASUREMENT = "1";
|
|
5
|
+
export const DXF_HIGHEST_ASCII = 126;
|
|
6
|
+
export const DXF_HEX_WIDTH = 4;
|
|
7
|
+
export const DXF_VIEW_MARGIN = 1.1;
|
|
8
|
+
export const DXF_VIEW_ASPECT = 1.5;
|
|
9
|
+
export const DXF_KNOT_TOLERANCE = "0.0000001";
|
|
10
|
+
export const DXF_FIXED_COLORS = [
|
|
11
|
+
[255, 0, 0], [255, 255, 0], [0, 255, 0], [0, 255, 255], [0, 0, 255], [255, 0, 255], [255, 255, 255], [65, 65, 65], [128, 128, 128],
|
|
12
|
+
];
|
|
13
|
+
export const DXF_SHADES = [255, 189, 129, 104, 79];
|
|
14
|
+
export const DXF_GRAYS = [51, 80, 105, 130, 190, 255];
|
|
15
|
+
export const DXF_HUE_STEP_DEGREES = 15;
|
|
16
|
+
export const DXF_PURE_HUE_LIGHTNESS = 0.5;
|
|
17
|
+
export const DXF_HUES = 24;
|
|
18
|
+
export const DXF_PASTEL_SHARE = 2 / 3;
|
|
19
|
+
export const DXF_WHITE_OR_BLACK = 7;
|
|
20
|
+
export const DXF_TRUE_COLOR_RED = 65536;
|
|
21
|
+
export const DXF_TRUE_COLOR_GREEN = 256;
|
|
22
|
+
export const DXF_LENS_LENGTH = 50;
|
|
23
|
+
export const DXF_HEX_RADIX = 16;
|
|
24
|
+
export const DXF_TURN_SLACK = 1e-9;
|
|
25
|
+
export const DXF_POINT_CODES = [10, 20, 30];
|
|
26
|
+
export const DXF_OTHER_POINT_CODES = [11, 21, 31];
|
|
27
|
+
export const DXF_EXTRUSION_CODES = [210, 220, 230];
|
|
28
|
+
export const DXF_VIEW_CENTER_CODES = [12, 22, 32];
|
|
29
|
+
export const DXF_SNAP_BASE_CODES = [13, 23, 33];
|
|
30
|
+
export const DXF_SNAP_SPACING_CODES = [14, 24, 34];
|
|
31
|
+
export const DXF_GRID_SPACING_CODES = [15, 25, 35];
|
|
32
|
+
export const DXF_VIEW_DIRECTION_CODES = [16, 26, 36];
|
|
33
|
+
export const DXF_VIEW_TARGET_CODES = [17, 27, 37];
|
|
34
|
+
export const DXF_CLOSED_FLAG = 1;
|
|
35
|
+
export const DXF_RATIONAL_FLAG = 4;
|
|
36
|
+
export const DXF_POLYLINE_3D_FLAG = 8;
|
|
37
|
+
export const DXF_MAX_NAME_LENGTH = 255;
|
|
38
|
+
export const DXF_LINE_WEIGHTS = [0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60, 70, 80, 90, 100, 106, 120, 140, 158, 200, 211];
|
|
39
|
+
export const DXF_LINE_WEIGHTS_PER_MILLIMETRE = 100;
|
|
40
|
+
export const DXF_TEXT_STYLE = "Standard";
|
|
41
|
+
export const DXF_CODED_BACKSLASH = "\\U+005C";
|
|
42
|
+
export const DXF_CHARACTER_CODE_START = /\\(?=[UM]\+)/g;
|
|
43
|
+
export const DXF_FIT_JUSTIFICATION = "5";
|
|
44
|
+
export const DXF_POLYLINE_BOUNDARY = "3";
|
|
45
|
+
export const DXF_HATCH_NAMES = { solid: "SOLID", ansi31: "ANSI31", ansi32: "ANSI32", ansi37: "ANSI37" };
|
|
46
|
+
export const DXF_HATCH_NATIVE_ANGLE = 45;
|
|
47
|
+
export const DXF_HATCH_NATIVE_SPACING = {
|
|
48
|
+
imperial: { solid: 1, ansi31: 0.125, ansi32: 0.375, ansi37: 0.125 },
|
|
49
|
+
metric: { solid: 1, ansi31: 3.175, ansi32: 9.525, ansi37: 3.175 },
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const bytesOfData: (data: unknown) => Uint8Array | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const bytesOfData = (data) => {
|
|
2
|
+
if (typeof data === "string") {
|
|
3
|
+
return new TextEncoder().encode(data);
|
|
4
|
+
}
|
|
5
|
+
if (data instanceof Uint8Array) {
|
|
6
|
+
return data;
|
|
7
|
+
}
|
|
8
|
+
if (data instanceof ArrayBuffer) {
|
|
9
|
+
return new Uint8Array(data);
|
|
10
|
+
}
|
|
11
|
+
if (ArrayBuffer.isView(data)) {
|
|
12
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Base } from "../../../inputs/base-inputs";
|
|
2
|
+
export declare function meshMatrixInFile(coordinateSystem: Base.coordinateSystemEnum.leftHanded, zUp: boolean): Base.TransformMatrix;
|
|
3
|
+
export declare function meshMatrixInFile(coordinateSystem: Base.coordinateSystemEnum, zUp: true): Base.TransformMatrix;
|
|
4
|
+
export declare function meshMatrixInFile(coordinateSystem: Base.coordinateSystemEnum, zUp: boolean): Base.TransformMatrix | undefined;
|
|
5
|
+
export declare function meshMatrixInModel(coordinateSystem: Base.coordinateSystemEnum.leftHanded, zUp: boolean): Base.TransformMatrix;
|
|
6
|
+
export declare function meshMatrixInModel(coordinateSystem: Base.coordinateSystemEnum, zUp: true): Base.TransformMatrix;
|
|
7
|
+
export declare function meshMatrixInModel(coordinateSystem: Base.coordinateSystemEnum, zUp: boolean): Base.TransformMatrix | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Base } from "../../../inputs/base-inputs";
|
|
2
|
+
const Y_AND_Z_SWAPPED = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1];
|
|
3
|
+
const X_MIRRORED = [-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
4
|
+
const TURNED_TO_Z_UP = [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1];
|
|
5
|
+
const TURNED_TO_Y_UP = [1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1];
|
|
6
|
+
export function meshMatrixInFile(coordinateSystem, zUp) {
|
|
7
|
+
if (coordinateSystem === Base.coordinateSystemEnum.rightHanded) {
|
|
8
|
+
return zUp ? TURNED_TO_Z_UP : undefined;
|
|
9
|
+
}
|
|
10
|
+
return zUp ? Y_AND_Z_SWAPPED : X_MIRRORED;
|
|
11
|
+
}
|
|
12
|
+
export function meshMatrixInModel(coordinateSystem, zUp) {
|
|
13
|
+
if (coordinateSystem === Base.coordinateSystemEnum.rightHanded) {
|
|
14
|
+
return zUp ? TURNED_TO_Y_UP : undefined;
|
|
15
|
+
}
|
|
16
|
+
return zUp ? Y_AND_Z_SWAPPED : X_MIRRORED;
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Base } from "../../../inputs/base-inputs";
|
|
2
|
+
import type { StlAxes } from "./stl-types";
|
|
3
|
+
export declare function stlAxesInFile(coordinateSystem: Base.coordinateSystemEnum, zUp: boolean): StlAxes;
|
|
4
|
+
export declare function stlAxesInModel(coordinateSystem: Base.coordinateSystemEnum, zUp: boolean): StlAxes;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { linearDeterminant } from "../geometry/matrices";
|
|
2
|
+
import { MATRIX_COLUMN } from "../geometry/matrices.constants";
|
|
3
|
+
import { meshMatrixInFile, meshMatrixInModel } from "./mesh-file-axes";
|
|
4
|
+
const COMPONENTS = [0, 1, 2];
|
|
5
|
+
const AS_IT_IS = { x: [0, false], y: [1, false], z: [2, false], mirrors: false };
|
|
6
|
+
function stlAxesOf(matrix) {
|
|
7
|
+
if (matrix === undefined) {
|
|
8
|
+
return AS_IT_IS;
|
|
9
|
+
}
|
|
10
|
+
const axisOf = (row) => {
|
|
11
|
+
var _a;
|
|
12
|
+
const source = (_a = COMPONENTS.find(column => matrix[column * MATRIX_COLUMN + row] !== 0)) !== null && _a !== void 0 ? _a : row;
|
|
13
|
+
return [source, matrix[source * MATRIX_COLUMN + row] < 0];
|
|
14
|
+
};
|
|
15
|
+
return { x: axisOf(0), y: axisOf(1), z: axisOf(2), mirrors: linearDeterminant(matrix) < 0 };
|
|
16
|
+
}
|
|
17
|
+
export function stlAxesInFile(coordinateSystem, zUp) {
|
|
18
|
+
return stlAxesOf(meshMatrixInFile(coordinateSystem, zUp));
|
|
19
|
+
}
|
|
20
|
+
export function stlAxesInModel(coordinateSystem, zUp) {
|
|
21
|
+
return stlAxesOf(meshMatrixInModel(coordinateSystem, zUp));
|
|
22
|
+
}
|