@bitbybit-dev/base 1.6.1 → 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 +36 -7
- package/lib/api/inputs/base-inputs.js +10 -0
- package/lib/api/inputs/color-inputs.d.ts +54 -1
- package/lib/api/inputs/color-inputs.js +73 -1
- package/lib/api/inputs/frame-inputs.d.ts +2 -1
- package/lib/api/inputs/frame-inputs.js +2 -1
- 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/inputs/math-inputs.d.ts +62 -0
- package/lib/api/inputs/math-inputs.js +82 -0
- package/lib/api/inputs/mesh-inputs.d.ts +16 -0
- package/lib/api/inputs/mesh-inputs.js +14 -0
- package/lib/api/inputs/transforms-inputs.d.ts +76 -0
- package/lib/api/inputs/transforms-inputs.js +85 -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 +32 -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.d.ts +36 -2
- package/lib/api/services/color.js +60 -11
- package/lib/api/services/helpers/color/color-forms.constants.d.ts +10 -0
- package/lib/api/services/helpers/color/color-forms.constants.js +10 -0
- package/lib/api/services/helpers/color/color-forms.d.ts +3 -0
- package/lib/api/services/helpers/color/color-forms.js +27 -0
- 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/quaternions.constants.d.ts +3 -0
- package/lib/api/services/helpers/geometry/quaternions.constants.js +3 -0
- package/lib/api/services/helpers/geometry/quaternions.d.ts +14 -0
- package/lib/api/services/helpers/geometry/quaternions.js +71 -0
- package/lib/api/services/helpers/geometry/scalars.constants.d.ts +1 -0
- package/lib/api/services/helpers/geometry/scalars.constants.js +1 -0
- package/lib/api/services/helpers/geometry/scalars.d.ts +3 -0
- package/lib/api/services/helpers/geometry/scalars.js +29 -1
- 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/mesh/mesh-proximity.constants.d.ts +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +1 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.js +40 -40
- 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/math.d.ts +35 -0
- package/lib/api/services/math.js +56 -1
- package/lib/api/services/mesh.d.ts +17 -0
- package/lib/api/services/mesh.js +27 -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/lib/api/services/transforms.d.ts +119 -1
- package/lib/api/services/transforms.js +158 -30
- 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,247 @@
|
|
|
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_VIEW_ASPECT, DXF_VIEW_CENTER_CODES, DXF_VIEW_DIRECTION_CODES, DXF_VIEW_MARGIN, DXF_VIEW_TARGET_CODES, } from "./dxf.constants";
|
|
4
|
+
const ORIGIN = [0, 0, 0];
|
|
5
|
+
const isModern = (layout) => layout.version === "AC1015";
|
|
6
|
+
const variable = (text, name) => text.pair("9", name);
|
|
7
|
+
export const writeHeader = (text, layout) => {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
text.pair("0", "SECTION");
|
|
10
|
+
text.pair("2", "HEADER");
|
|
11
|
+
variable(text, "$ACADVER");
|
|
12
|
+
text.pair("1", layout.version);
|
|
13
|
+
if (isModern(layout)) {
|
|
14
|
+
variable(text, "$DWGCODEPAGE");
|
|
15
|
+
text.pair("3", "ANSI_1252");
|
|
16
|
+
}
|
|
17
|
+
variable(text, "$INSBASE");
|
|
18
|
+
text.point(DXF_POINT_CODES, ORIGIN);
|
|
19
|
+
variable(text, "$EXTMIN");
|
|
20
|
+
text.point(DXF_POINT_CODES, (_b = (_a = layout.bounds) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : ORIGIN);
|
|
21
|
+
variable(text, "$EXTMAX");
|
|
22
|
+
text.point(DXF_POINT_CODES, (_d = (_c = layout.bounds) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : ORIGIN);
|
|
23
|
+
let handseed;
|
|
24
|
+
if (isModern(layout)) {
|
|
25
|
+
if (layout.unit !== undefined) {
|
|
26
|
+
variable(text, "$INSUNITS");
|
|
27
|
+
text.pair("70", DXF_INSUNITS[layout.unit]);
|
|
28
|
+
variable(text, "$MEASUREMENT");
|
|
29
|
+
text.pair("70", layout.unit === "in" ? DXF_IMPERIAL_MEASUREMENT : DXF_METRIC_MEASUREMENT);
|
|
30
|
+
}
|
|
31
|
+
variable(text, "$HANDSEED");
|
|
32
|
+
handseed = text.reserve("5");
|
|
33
|
+
}
|
|
34
|
+
text.pair("0", "ENDSEC");
|
|
35
|
+
return handseed;
|
|
36
|
+
};
|
|
37
|
+
export const writeClasses = (text, layout) => {
|
|
38
|
+
if (isModern(layout)) {
|
|
39
|
+
text.pair("0", "SECTION");
|
|
40
|
+
text.pair("2", "CLASSES");
|
|
41
|
+
text.pair("0", "ENDSEC");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const openTable = (text, layout, name, count) => {
|
|
45
|
+
text.pair("0", "TABLE");
|
|
46
|
+
text.pair("2", name);
|
|
47
|
+
const handle = isModern(layout) ? text.nextHandle() : "";
|
|
48
|
+
if (isModern(layout)) {
|
|
49
|
+
text.pair("5", handle);
|
|
50
|
+
text.pair("330", "0");
|
|
51
|
+
text.pair("100", "AcDbSymbolTable");
|
|
52
|
+
}
|
|
53
|
+
text.pair("70", String(count));
|
|
54
|
+
return handle;
|
|
55
|
+
};
|
|
56
|
+
const openRecord = (text, layout, kind, table, subclass, handleCode = "5") => {
|
|
57
|
+
text.pair("0", kind);
|
|
58
|
+
const handle = isModern(layout) ? text.nextHandle() : "";
|
|
59
|
+
if (isModern(layout)) {
|
|
60
|
+
text.pair(handleCode, handle);
|
|
61
|
+
text.pair("330", table);
|
|
62
|
+
text.pair("100", "AcDbSymbolTableRecord");
|
|
63
|
+
text.pair("100", subclass);
|
|
64
|
+
}
|
|
65
|
+
return handle;
|
|
66
|
+
};
|
|
67
|
+
const closeTable = (text) => text.pair("0", "ENDTAB");
|
|
68
|
+
const writeViewports = (text, layout) => {
|
|
69
|
+
var _a, _b, _c, _d;
|
|
70
|
+
const table = openTable(text, layout, "VPORT", 1);
|
|
71
|
+
openRecord(text, layout, "VPORT", table, "AcDbViewportTableRecord");
|
|
72
|
+
const min = (_b = (_a = layout.bounds) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : ORIGIN;
|
|
73
|
+
const max = (_d = (_c = layout.bounds) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : ORIGIN;
|
|
74
|
+
const width = Math.max(max[0] - min[0], 1);
|
|
75
|
+
const height = Math.max(max[1] - min[1], width / DXF_VIEW_ASPECT);
|
|
76
|
+
text.pair("2", "*ACTIVE");
|
|
77
|
+
text.pair("70", "0");
|
|
78
|
+
text.point(DXF_POINT_CODES, ORIGIN);
|
|
79
|
+
text.point(DXF_OTHER_POINT_CODES, [1, 1, 0]);
|
|
80
|
+
text.point(DXF_VIEW_CENTER_CODES, [(min[0] + max[0]) / 2, (min[1] + max[1]) / 2, 0]);
|
|
81
|
+
text.point(DXF_SNAP_BASE_CODES, ORIGIN);
|
|
82
|
+
text.point(DXF_SNAP_SPACING_CODES, [1, 1, 0]);
|
|
83
|
+
text.point(DXF_GRID_SPACING_CODES, [1, 1, 0]);
|
|
84
|
+
text.point(DXF_VIEW_DIRECTION_CODES, [0, 0, 1]);
|
|
85
|
+
text.point(DXF_VIEW_TARGET_CODES, ORIGIN);
|
|
86
|
+
text.real("40", height * DXF_VIEW_MARGIN);
|
|
87
|
+
text.real("41", DXF_VIEW_ASPECT);
|
|
88
|
+
text.real("42", DXF_LENS_LENGTH);
|
|
89
|
+
text.real("43", 0);
|
|
90
|
+
text.real("44", 0);
|
|
91
|
+
text.real("50", 0);
|
|
92
|
+
text.real("51", 0);
|
|
93
|
+
for (const [code, value] of [["71", "0"], ["72", "100"], ["73", "1"], ["74", "3"], ["75", "0"], ["76", "0"], ["77", "0"], ["78", "0"]]) {
|
|
94
|
+
text.pair(code, value);
|
|
95
|
+
}
|
|
96
|
+
closeTable(text);
|
|
97
|
+
};
|
|
98
|
+
const writeLineTypeRecord = (text, layout, table, name, description, elements) => {
|
|
99
|
+
openRecord(text, layout, "LTYPE", table, "AcDbLinetypeTableRecord");
|
|
100
|
+
text.name("2", name);
|
|
101
|
+
text.pair("70", "0");
|
|
102
|
+
text.pair("3", description);
|
|
103
|
+
text.pair("72", "65");
|
|
104
|
+
text.pair("73", String(elements.length));
|
|
105
|
+
text.real("40", elements.reduce((total, element) => total + Math.abs(element), 0) * layout.patternUnit);
|
|
106
|
+
for (const element of elements) {
|
|
107
|
+
text.real("49", element * layout.patternUnit);
|
|
108
|
+
if (isModern(layout)) {
|
|
109
|
+
text.pair("74", "0");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const writeLineTypes = (text, layout) => {
|
|
114
|
+
const extra = isModern(layout) ? ["ByBlock", "ByLayer"] : [];
|
|
115
|
+
const table = openTable(text, layout, "LTYPE", extra.length + 1 + layout.lineTypes.length);
|
|
116
|
+
for (const name of extra) {
|
|
117
|
+
writeLineTypeRecord(text, layout, table, name, "", []);
|
|
118
|
+
}
|
|
119
|
+
writeLineTypeRecord(text, layout, table, LINE_TYPE_PATTERNS["continuous"].name, LINE_TYPE_PATTERNS["continuous"].description, []);
|
|
120
|
+
for (const lineType of layout.lineTypes) {
|
|
121
|
+
const pattern = LINE_TYPE_PATTERNS[lineType];
|
|
122
|
+
writeLineTypeRecord(text, layout, table, pattern.name, pattern.description, pattern.elements);
|
|
123
|
+
}
|
|
124
|
+
closeTable(text);
|
|
125
|
+
};
|
|
126
|
+
const writeLayers = (text, layout) => {
|
|
127
|
+
const table = openTable(text, layout, "LAYER", layout.layers.length);
|
|
128
|
+
for (const layer of layout.layers) {
|
|
129
|
+
openRecord(text, layout, "LAYER", table, "AcDbLayerTableRecord");
|
|
130
|
+
text.name("2", layer.name);
|
|
131
|
+
text.pair("70", "0");
|
|
132
|
+
text.pair("62", String(nearestAciIndex(layer.color)));
|
|
133
|
+
if (isModern(layout) && layout.colorFormat === "truecolor") {
|
|
134
|
+
text.pair("420", String(trueColorOf(layer.color)));
|
|
135
|
+
}
|
|
136
|
+
text.pair("6", LINE_TYPE_PATTERNS[layer.lineType].name);
|
|
137
|
+
if (isModern(layout)) {
|
|
138
|
+
text.pair("370", "-3");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
closeTable(text);
|
|
142
|
+
};
|
|
143
|
+
const writeStyles = (text, layout) => {
|
|
144
|
+
const table = openTable(text, layout, "STYLE", 1);
|
|
145
|
+
openRecord(text, layout, "STYLE", table, "AcDbTextStyleTableRecord");
|
|
146
|
+
for (const [code, value] of [["2", "Standard"], ["70", "0"], ["40", "0.0"], ["41", "1.0"], ["50", "0.0"], ["71", "0"], ["42", "2.5"], ["3", "txt"], ["4", ""]]) {
|
|
147
|
+
text.pair(code, value);
|
|
148
|
+
}
|
|
149
|
+
closeTable(text);
|
|
150
|
+
};
|
|
151
|
+
const writeEmptyTable = (text, layout, name) => {
|
|
152
|
+
openTable(text, layout, name, 0);
|
|
153
|
+
closeTable(text);
|
|
154
|
+
};
|
|
155
|
+
const writeApplications = (text, layout) => {
|
|
156
|
+
const table = openTable(text, layout, "APPID", 1);
|
|
157
|
+
openRecord(text, layout, "APPID", table, "AcDbRegAppTableRecord");
|
|
158
|
+
text.pair("2", "ACAD");
|
|
159
|
+
text.pair("70", "0");
|
|
160
|
+
closeTable(text);
|
|
161
|
+
};
|
|
162
|
+
const writeDimensionStyles = (text, layout) => {
|
|
163
|
+
const table = openTable(text, layout, "DIMSTYLE", 1);
|
|
164
|
+
if (isModern(layout)) {
|
|
165
|
+
text.pair("100", "AcDbDimStyleTable");
|
|
166
|
+
text.pair("71", "1");
|
|
167
|
+
text.pair("340", text.peekHandle());
|
|
168
|
+
}
|
|
169
|
+
openRecord(text, layout, "DIMSTYLE", table, "AcDbDimStyleTableRecord", "105");
|
|
170
|
+
text.pair("2", "Standard");
|
|
171
|
+
text.pair("70", "0");
|
|
172
|
+
closeTable(text);
|
|
173
|
+
};
|
|
174
|
+
const writeBlockRecords = (text, layout) => {
|
|
175
|
+
const table = openTable(text, layout, "BLOCK_RECORD", 2);
|
|
176
|
+
const modelSpace = openRecord(text, layout, "BLOCK_RECORD", table, "AcDbBlockTableRecord");
|
|
177
|
+
text.pair("2", "*Model_Space");
|
|
178
|
+
const paperSpace = openRecord(text, layout, "BLOCK_RECORD", table, "AcDbBlockTableRecord");
|
|
179
|
+
text.pair("2", "*Paper_Space");
|
|
180
|
+
closeTable(text);
|
|
181
|
+
return { modelSpace, paperSpace };
|
|
182
|
+
};
|
|
183
|
+
export const writeTables = (text, layout) => {
|
|
184
|
+
text.pair("0", "SECTION");
|
|
185
|
+
text.pair("2", "TABLES");
|
|
186
|
+
writeViewports(text, layout);
|
|
187
|
+
writeLineTypes(text, layout);
|
|
188
|
+
writeLayers(text, layout);
|
|
189
|
+
writeStyles(text, layout);
|
|
190
|
+
writeEmptyTable(text, layout, "VIEW");
|
|
191
|
+
writeEmptyTable(text, layout, "UCS");
|
|
192
|
+
writeApplications(text, layout);
|
|
193
|
+
writeDimensionStyles(text, layout);
|
|
194
|
+
const owners = isModern(layout) ? writeBlockRecords(text, layout) : { modelSpace: "", paperSpace: "" };
|
|
195
|
+
text.pair("0", "ENDSEC");
|
|
196
|
+
return owners;
|
|
197
|
+
};
|
|
198
|
+
const writeBlock = (text, owner, name, paper) => {
|
|
199
|
+
text.pair("0", "BLOCK");
|
|
200
|
+
text.pair("5", text.nextHandle());
|
|
201
|
+
text.pair("330", owner);
|
|
202
|
+
text.pair("100", "AcDbEntity");
|
|
203
|
+
if (paper) {
|
|
204
|
+
text.pair("67", "1");
|
|
205
|
+
}
|
|
206
|
+
text.pair("8", "0");
|
|
207
|
+
text.pair("100", "AcDbBlockBegin");
|
|
208
|
+
text.pair("2", name);
|
|
209
|
+
text.pair("70", "0");
|
|
210
|
+
text.point(DXF_POINT_CODES, ORIGIN);
|
|
211
|
+
text.pair("3", name);
|
|
212
|
+
text.pair("1", "");
|
|
213
|
+
text.pair("0", "ENDBLK");
|
|
214
|
+
text.pair("5", text.nextHandle());
|
|
215
|
+
text.pair("330", owner);
|
|
216
|
+
text.pair("100", "AcDbEntity");
|
|
217
|
+
if (paper) {
|
|
218
|
+
text.pair("67", "1");
|
|
219
|
+
}
|
|
220
|
+
text.pair("8", "0");
|
|
221
|
+
text.pair("100", "AcDbBlockEnd");
|
|
222
|
+
};
|
|
223
|
+
export const writeBlocks = (text, layout, owners) => {
|
|
224
|
+
text.pair("0", "SECTION");
|
|
225
|
+
text.pair("2", "BLOCKS");
|
|
226
|
+
if (isModern(layout)) {
|
|
227
|
+
writeBlock(text, owners.modelSpace, "*Model_Space", false);
|
|
228
|
+
writeBlock(text, owners.paperSpace, "*Paper_Space", true);
|
|
229
|
+
}
|
|
230
|
+
text.pair("0", "ENDSEC");
|
|
231
|
+
};
|
|
232
|
+
export const writeObjects = (text, layout) => {
|
|
233
|
+
if (!isModern(layout)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const root = text.nextHandle();
|
|
237
|
+
const groups = text.nextHandle();
|
|
238
|
+
text.pair("0", "SECTION");
|
|
239
|
+
text.pair("2", "OBJECTS");
|
|
240
|
+
for (const [code, value] of [["0", "DICTIONARY"], ["5", root], ["330", "0"], ["100", "AcDbDictionary"], ["281", "1"], ["3", "ACAD_GROUP"], ["350", groups]]) {
|
|
241
|
+
text.pair(code, value);
|
|
242
|
+
}
|
|
243
|
+
for (const [code, value] of [["0", "DICTIONARY"], ["5", groups], ["330", root], ["100", "AcDbDictionary"], ["281", "1"]]) {
|
|
244
|
+
text.pair(code, value);
|
|
245
|
+
}
|
|
246
|
+
text.pair("0", "ENDSEC");
|
|
247
|
+
};
|
|
@@ -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,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { InputError } from "../../../../kernel-calls";
|
|
2
|
+
import { BINARY_SENTINEL, 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)));
|
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const DXF_FIRST_HANDLE = 32;
|
|
2
2
|
export declare const DXF_INSUNITS: Readonly<Record<string, string>>;
|
|
3
3
|
export declare const DXF_IMPERIAL_MEASUREMENT = "0";
|
|
4
4
|
export declare const DXF_METRIC_MEASUREMENT = "1";
|
|
5
|
+
export declare const DXF_HIGHEST_ASCII = 126;
|
|
6
|
+
export declare const DXF_HEX_WIDTH = 4;
|
|
7
|
+
export declare const DXF_VIEW_MARGIN = 1.1;
|
|
8
|
+
export declare const DXF_VIEW_ASPECT = 1.5;
|
|
9
|
+
export declare const DXF_KNOT_TOLERANCE = "0.0000001";
|
|
10
|
+
export declare const DXF_FIXED_COLORS: readonly (readonly [number, number, number])[];
|
|
11
|
+
export declare const DXF_SHADES: number[];
|
|
12
|
+
export declare const DXF_GRAYS: number[];
|
|
13
|
+
export declare const DXF_HUE_STEP_DEGREES = 15;
|
|
14
|
+
export declare const DXF_PURE_HUE_LIGHTNESS = 0.5;
|
|
15
|
+
export declare const DXF_HUES = 24;
|
|
16
|
+
export declare const DXF_PASTEL_SHARE: number;
|
|
17
|
+
export declare const DXF_WHITE_OR_BLACK = 7;
|
|
18
|
+
export declare const DXF_TRUE_COLOR_RED = 65536;
|
|
19
|
+
export declare const DXF_TRUE_COLOR_GREEN = 256;
|
|
20
|
+
export declare const DXF_LENS_LENGTH = 50;
|
|
21
|
+
export declare const DXF_HEX_RADIX = 16;
|
|
22
|
+
export declare const DXF_TURN_SLACK = 1e-9;
|
|
23
|
+
export declare const DXF_POINT_CODES: readonly [10, 20, 30];
|
|
24
|
+
export declare const DXF_OTHER_POINT_CODES: readonly [11, 21, 31];
|
|
25
|
+
export declare const DXF_EXTRUSION_CODES: readonly [210, 220, 230];
|
|
26
|
+
export declare const DXF_VIEW_CENTER_CODES: readonly [12, 22, 32];
|
|
27
|
+
export declare const DXF_SNAP_BASE_CODES: readonly [13, 23, 33];
|
|
28
|
+
export declare const DXF_SNAP_SPACING_CODES: readonly [14, 24, 34];
|
|
29
|
+
export declare const DXF_GRID_SPACING_CODES: readonly [15, 25, 35];
|
|
30
|
+
export declare const DXF_VIEW_DIRECTION_CODES: readonly [16, 26, 36];
|
|
31
|
+
export declare const DXF_VIEW_TARGET_CODES: readonly [17, 27, 37];
|
|
32
|
+
export declare const DXF_CLOSED_FLAG = 1;
|
|
33
|
+
export declare const DXF_RATIONAL_FLAG = 4;
|
|
34
|
+
export declare const DXF_POLYLINE_3D_FLAG = 8;
|
|
35
|
+
export declare const DXF_MAX_NAME_LENGTH = 255;
|
|
@@ -1,4 +1,37 @@
|
|
|
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;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const BINARY_HEADER_BYTES = 80;
|
|
2
|
+
export declare const BINARY_COUNT_BYTES = 4;
|
|
3
|
+
export declare const BINARY_TRIANGLE_BYTES = 50;
|
|
4
|
+
export declare const BINARY_POINT_BYTES = 12;
|
|
5
|
+
export declare const BINARY_NUMBER_BYTES = 4;
|
|
6
|
+
export declare const COMPONENTS_OF_A_POINT = 3;
|
|
7
|
+
export declare const POINTS_OF_A_FACET = 4;
|
|
8
|
+
export declare const SECOND_VERTEX_SLOT = 2;
|
|
9
|
+
export declare const THIRD_VERTEX_SLOT = 3;
|
|
10
|
+
export declare const CORNERS_OF_A_TRIANGLE = 3;
|
|
11
|
+
export declare const NUMBERS_OF_A_TRIANGLE = 9;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const BINARY_HEADER_BYTES = 80;
|
|
2
|
+
export const BINARY_COUNT_BYTES = 4;
|
|
3
|
+
export const BINARY_TRIANGLE_BYTES = 50;
|
|
4
|
+
export const BINARY_POINT_BYTES = 12;
|
|
5
|
+
export const BINARY_NUMBER_BYTES = 4;
|
|
6
|
+
export const COMPONENTS_OF_A_POINT = 3;
|
|
7
|
+
export const POINTS_OF_A_FACET = 4;
|
|
8
|
+
export const SECOND_VERTEX_SLOT = 2;
|
|
9
|
+
export const THIRD_VERTEX_SLOT = 3;
|
|
10
|
+
export const CORNERS_OF_A_TRIANGLE = 3;
|
|
11
|
+
export const NUMBERS_OF_A_TRIANGLE = 9;
|