@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,96 @@
|
|
|
1
|
+
import * as Inputs from "../../../../inputs";
|
|
2
|
+
import { InputError } from "../../../../kernel-calls";
|
|
3
|
+
import { angleWithinTurn } from "../../curves/conic-arcs";
|
|
4
|
+
import { scale2 } from "../../geometry/vectors";
|
|
5
|
+
import { hatchFamiliesOf } from "../drawing/drawing-hatch";
|
|
6
|
+
import { drawingLoopsOf } from "../drawing/drawing-loops";
|
|
7
|
+
import { textEndOf, textInked, textStartOf } from "../drawing/drawing-text";
|
|
8
|
+
import { FULL_TURN_DEGREES } from "../drawing/drawing.constants";
|
|
9
|
+
import { isModern, openEntity } from "./dxf-entities";
|
|
10
|
+
import { encodedText } from "./dxf-text";
|
|
11
|
+
import { DXF_CHARACTER_CODE_START, DXF_CODED_BACKSLASH, DXF_EXTRUSION_CODES, DXF_FIT_JUSTIFICATION, DXF_HATCH_NAMES, DXF_HATCH_NATIVE_ANGLE, DXF_HATCH_NATIVE_SPACING, DXF_OTHER_POINT_CODES, DXF_POINT_CODES, DXF_POLYLINE_BOUNDARY, DXF_TEXT_STYLE, } from "./dxf.constants";
|
|
12
|
+
export const dxfTextValue = (value) => encodedText(value.replace(DXF_CHARACTER_CODE_START, DXF_CODED_BACKSLASH).replace(/\^/g, "^ ").replace(/%%/g, "%%%%%%"));
|
|
13
|
+
export const writeText = (context, text, style) => {
|
|
14
|
+
if (!textInked(text)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
openEntity(context, "TEXT", Object.assign(Object.assign({}, style), { lineType: undefined }));
|
|
18
|
+
const out = context.text;
|
|
19
|
+
if (isModern(context)) {
|
|
20
|
+
out.pair("100", "AcDbText");
|
|
21
|
+
}
|
|
22
|
+
out.point(DXF_POINT_CODES, textStartOf(text));
|
|
23
|
+
out.real("40", text.height);
|
|
24
|
+
out.pair("1", dxfTextValue(text.value));
|
|
25
|
+
if (text.rotationDegrees !== 0) {
|
|
26
|
+
out.real("50", angleWithinTurn(text.rotationDegrees, FULL_TURN_DEGREES));
|
|
27
|
+
}
|
|
28
|
+
if (text.widthFactor !== 1) {
|
|
29
|
+
out.real("41", text.widthFactor);
|
|
30
|
+
}
|
|
31
|
+
out.pair("7", DXF_TEXT_STYLE);
|
|
32
|
+
out.pair("72", DXF_FIT_JUSTIFICATION);
|
|
33
|
+
out.point(DXF_OTHER_POINT_CODES, textEndOf(text));
|
|
34
|
+
if (isModern(context)) {
|
|
35
|
+
out.pair("100", "AcDbText");
|
|
36
|
+
out.pair("73", "0");
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const writeHatch = (context, hatch, style, property) => {
|
|
40
|
+
if (!isModern(context)) {
|
|
41
|
+
throw new InputError(`\`${property}\` holds a hatch, which an AC1009 (R12) file has no entity for: write AC1015.`, property);
|
|
42
|
+
}
|
|
43
|
+
const out = context.text;
|
|
44
|
+
const loops = drawingLoopsOf(hatch.boundaries, context.curveTolerance, out.budget);
|
|
45
|
+
out.refuseWhenSpent();
|
|
46
|
+
if (loops.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const solid = hatch.pattern === Inputs.IO.hatchPatternEnum.solid;
|
|
50
|
+
openEntity(context, "HATCH", Object.assign(Object.assign({}, style), { lineType: undefined }));
|
|
51
|
+
out.pair("100", "AcDbHatch");
|
|
52
|
+
out.point(DXF_POINT_CODES, [0, 0, 0]);
|
|
53
|
+
out.point(DXF_EXTRUSION_CODES, [0, 0, 1]);
|
|
54
|
+
out.pair("2", DXF_HATCH_NAMES[hatch.pattern]);
|
|
55
|
+
out.pair("70", solid ? "1" : "0");
|
|
56
|
+
out.pair("71", "0");
|
|
57
|
+
out.pair("91", String(loops.length));
|
|
58
|
+
for (const loop of loops) {
|
|
59
|
+
const bulged = loop.bulges.some(bulge => bulge !== 0);
|
|
60
|
+
out.pair("92", DXF_POLYLINE_BOUNDARY);
|
|
61
|
+
out.pair("72", bulged ? "1" : "0");
|
|
62
|
+
out.pair("73", "1");
|
|
63
|
+
out.pair("93", String(loop.points.length));
|
|
64
|
+
loop.points.forEach((point, at) => {
|
|
65
|
+
var _a;
|
|
66
|
+
out.real("10", point[0]);
|
|
67
|
+
out.real("20", point[1]);
|
|
68
|
+
if (bulged) {
|
|
69
|
+
out.real("42", (_a = loop.bulges[at]) !== null && _a !== void 0 ? _a : 0);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
out.pair("97", "0");
|
|
73
|
+
}
|
|
74
|
+
out.pair("75", "0");
|
|
75
|
+
out.pair("76", "1");
|
|
76
|
+
if (!solid) {
|
|
77
|
+
const families = hatchFamiliesOf(hatch);
|
|
78
|
+
out.real("52", angleWithinTurn(hatch.angle - DXF_HATCH_NATIVE_ANGLE, FULL_TURN_DEGREES));
|
|
79
|
+
out.real("41", hatch.spacing / DXF_HATCH_NATIVE_SPACING[context.measurement][hatch.pattern]);
|
|
80
|
+
out.pair("77", "0");
|
|
81
|
+
out.pair("78", String(families.length));
|
|
82
|
+
for (const family of families) {
|
|
83
|
+
const base = scale2(family.across, family.phase);
|
|
84
|
+
const offset = scale2(family.across, hatch.spacing);
|
|
85
|
+
out.real("53", angleWithinTurn(family.angle, FULL_TURN_DEGREES));
|
|
86
|
+
out.real("43", base[0]);
|
|
87
|
+
out.real("44", base[1]);
|
|
88
|
+
out.real("45", offset[0]);
|
|
89
|
+
out.real("46", offset[1]);
|
|
90
|
+
out.pair("79", "0");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
out.pair("98", "1");
|
|
94
|
+
out.real("10", loops[0].points[0][0]);
|
|
95
|
+
out.real("20", loops[0].points[0][1]);
|
|
96
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { hexChannels, hslChannels } from "../../color/color-forms";
|
|
2
|
+
import { DXF_FIXED_COLORS, DXF_GRAYS, DXF_HUE_STEP_DEGREES, DXF_HUES, DXF_PASTEL_SHARE, DXF_PURE_HUE_LIGHTNESS, DXF_SHADES, DXF_TRUE_COLOR_GREEN, DXF_TRUE_COLOR_RED, DXF_WHITE_OR_BLACK, } from "./dxf.constants";
|
|
3
|
+
const hueRgb = (hue, level) => {
|
|
4
|
+
const [red, green, blue] = hslChannels(hue, 1, DXF_PURE_HUE_LIGHTNESS);
|
|
5
|
+
return [red * level, green * level, blue * level];
|
|
6
|
+
};
|
|
7
|
+
const pastel = (rgb, level) => [
|
|
8
|
+
rgb[0] + (level - rgb[0]) * DXF_PASTEL_SHARE,
|
|
9
|
+
rgb[1] + (level - rgb[1]) * DXF_PASTEL_SHARE,
|
|
10
|
+
rgb[2] + (level - rgb[2]) * DXF_PASTEL_SHARE,
|
|
11
|
+
];
|
|
12
|
+
const huePalette = () => {
|
|
13
|
+
const palette = [];
|
|
14
|
+
for (let hue = 0; hue < DXF_HUES; hue++) {
|
|
15
|
+
for (const level of DXF_SHADES) {
|
|
16
|
+
const full = hueRgb(hue * DXF_HUE_STEP_DEGREES, level);
|
|
17
|
+
palette.push(full, pastel(full, level));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return palette;
|
|
21
|
+
};
|
|
22
|
+
export const ACI_PALETTE = [
|
|
23
|
+
...DXF_FIXED_COLORS,
|
|
24
|
+
...huePalette(),
|
|
25
|
+
...DXF_GRAYS.map((gray) => [gray, gray, gray]),
|
|
26
|
+
];
|
|
27
|
+
const BLACK = [0, 0, 0];
|
|
28
|
+
const INDEXED_COLORS = [[DXF_WHITE_OR_BLACK, BLACK], ...ACI_PALETTE.map((rgb, at) => [at + 1, rgb])];
|
|
29
|
+
export const nearestAciIndex = (hex) => {
|
|
30
|
+
const [red, green, blue] = hexChannels(hex);
|
|
31
|
+
let nearest = DXF_WHITE_OR_BLACK;
|
|
32
|
+
let nearestDistance = Infinity;
|
|
33
|
+
for (const [index, rgb] of INDEXED_COLORS) {
|
|
34
|
+
const distance = Math.pow((rgb[0] - red), 2) + Math.pow((rgb[1] - green), 2) + Math.pow((rgb[2] - blue), 2);
|
|
35
|
+
if (distance < nearestDistance) {
|
|
36
|
+
nearestDistance = distance;
|
|
37
|
+
nearest = index;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return nearest;
|
|
41
|
+
};
|
|
42
|
+
export const trueColorOf = (hex) => {
|
|
43
|
+
const [red, green, blue] = hexChannels(hex);
|
|
44
|
+
return red * DXF_TRUE_COLOR_RED + green * DXF_TRUE_COLOR_GREEN + blue;
|
|
45
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as Inputs from "../../../../inputs";
|
|
2
|
+
import type { DrawingSegment } from "../drawing/drawing-types";
|
|
3
|
+
import type { DxfText } from "./dxf-text";
|
|
4
|
+
import type { DxfMeasurement, DxfVersion } from "./dxf-tables";
|
|
5
|
+
export interface DxfEntityStyle {
|
|
6
|
+
readonly layer: string;
|
|
7
|
+
readonly color: string;
|
|
8
|
+
readonly lineType: Inputs.IO.lineTypeEnum | undefined;
|
|
9
|
+
readonly lineWeight: number | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface DxfEntityContext {
|
|
12
|
+
readonly text: DxfText;
|
|
13
|
+
readonly version: DxfVersion;
|
|
14
|
+
readonly owner: string;
|
|
15
|
+
readonly colorFormat: "aci" | "truecolor";
|
|
16
|
+
readonly curveTolerance: number;
|
|
17
|
+
readonly measurement: DxfMeasurement;
|
|
18
|
+
}
|
|
19
|
+
export declare const isModern: (context: DxfEntityContext) => boolean;
|
|
20
|
+
export declare const openEntity: (context: DxfEntityContext, kind: string, style: DxfEntityStyle, owner?: string) => string;
|
|
21
|
+
export declare const writeSegment: (context: DxfEntityContext, segment: DrawingSegment, style: DxfEntityStyle) => void;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { angleWithinTurn } from "../../curves/conic-arcs";
|
|
2
|
+
import { isRationalPiece } from "../../curves/nurbs-forms";
|
|
3
|
+
import { vectorToLocal } from "../../geometry/frame-axes";
|
|
4
|
+
import { distance3 } from "../../geometry/vectors";
|
|
5
|
+
import { ocsAxesOf, segmentSamples } from "../drawing/drawing-geometry";
|
|
6
|
+
import { LINE_TYPE_PATTERNS, SAME_POINT } from "../drawing/drawing.constants";
|
|
7
|
+
import { nearestAciIndex, trueColorOf } from "./dxf-colors";
|
|
8
|
+
import { DXF_CLOSED_FLAG, DXF_EXTRUSION_CODES, DXF_KNOT_TOLERANCE, DXF_OTHER_POINT_CODES, DXF_POINT_CODES, DXF_POLYLINE_3D_FLAG, DXF_RATIONAL_FLAG, DXF_TURN_SLACK } from "./dxf.constants";
|
|
9
|
+
const PLANAR_FLAG = 8;
|
|
10
|
+
const VERTEX_3D_FLAG = "32";
|
|
11
|
+
const PLUS_Z = [0, 0, 1];
|
|
12
|
+
export const isModern = (context) => context.version === "AC1015";
|
|
13
|
+
const isPlusZ = (normal) => normal[0] === 0 && normal[1] === 0 && normal[2] > 0;
|
|
14
|
+
export const openEntity = (context, kind, style, owner = context.owner) => {
|
|
15
|
+
const text = context.text;
|
|
16
|
+
text.pair("0", kind);
|
|
17
|
+
let handle = "";
|
|
18
|
+
if (isModern(context)) {
|
|
19
|
+
handle = text.nextHandle();
|
|
20
|
+
text.pair("5", handle);
|
|
21
|
+
text.pair("330", owner);
|
|
22
|
+
text.pair("100", "AcDbEntity");
|
|
23
|
+
}
|
|
24
|
+
text.name("8", style.layer);
|
|
25
|
+
if (style.lineType !== undefined) {
|
|
26
|
+
text.pair("6", LINE_TYPE_PATTERNS[style.lineType].name);
|
|
27
|
+
}
|
|
28
|
+
text.pair("62", String(nearestAciIndex(style.color)));
|
|
29
|
+
if (isModern(context) && context.colorFormat === "truecolor") {
|
|
30
|
+
text.pair("420", String(trueColorOf(style.color)));
|
|
31
|
+
}
|
|
32
|
+
if (isModern(context) && style.lineWeight !== undefined) {
|
|
33
|
+
text.pair("370", String(style.lineWeight));
|
|
34
|
+
}
|
|
35
|
+
return handle;
|
|
36
|
+
};
|
|
37
|
+
const writeLine = (context, line, style) => {
|
|
38
|
+
openEntity(context, "LINE", style);
|
|
39
|
+
if (isModern(context)) {
|
|
40
|
+
context.text.pair("100", "AcDbLine");
|
|
41
|
+
}
|
|
42
|
+
context.text.point(DXF_POINT_CODES, line.start);
|
|
43
|
+
context.text.point(DXF_OTHER_POINT_CODES, line.end);
|
|
44
|
+
};
|
|
45
|
+
const writeCircleOrArc = (context, segment, style) => {
|
|
46
|
+
const axes = ocsAxesOf(segment.normal);
|
|
47
|
+
const isWhole = segment.kind === "circle" || segment.endAngle - segment.startAngle >= 2 * Math.PI - DXF_TURN_SLACK;
|
|
48
|
+
openEntity(context, isWhole ? "CIRCLE" : "ARC", style);
|
|
49
|
+
const text = context.text;
|
|
50
|
+
if (isModern(context)) {
|
|
51
|
+
text.pair("100", "AcDbCircle");
|
|
52
|
+
}
|
|
53
|
+
text.point(DXF_POINT_CODES, vectorToLocal(axes, segment.center));
|
|
54
|
+
text.real("40", segment.radius);
|
|
55
|
+
if (!isPlusZ(segment.normal)) {
|
|
56
|
+
text.point(DXF_EXTRUSION_CODES, segment.normal);
|
|
57
|
+
}
|
|
58
|
+
if (!isWhole && segment.kind === "arc") {
|
|
59
|
+
if (isModern(context)) {
|
|
60
|
+
text.pair("100", "AcDbArc");
|
|
61
|
+
}
|
|
62
|
+
text.real("50", segment.startDegrees);
|
|
63
|
+
text.real("51", segment.endDegrees);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const writeLightPolyline = (context, points, bulges, closed, style) => {
|
|
67
|
+
openEntity(context, "LWPOLYLINE", style);
|
|
68
|
+
const text = context.text;
|
|
69
|
+
text.pair("100", "AcDbPolyline");
|
|
70
|
+
text.pair("90", String(points.length));
|
|
71
|
+
text.pair("70", closed ? "1" : "0");
|
|
72
|
+
if (points[0][2] !== 0) {
|
|
73
|
+
text.real("38", points[0][2]);
|
|
74
|
+
}
|
|
75
|
+
points.forEach((point, at) => {
|
|
76
|
+
var _a;
|
|
77
|
+
text.real("10", point[0]);
|
|
78
|
+
text.real("20", point[1]);
|
|
79
|
+
const bulge = (_a = bulges[at]) !== null && _a !== void 0 ? _a : 0;
|
|
80
|
+
if (bulge !== 0) {
|
|
81
|
+
text.real("42", bulge);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const writeHeavyPolyline = (context, points, bulges, closed, planar, style) => {
|
|
86
|
+
const owner = openEntity(context, "POLYLINE", style);
|
|
87
|
+
const text = context.text;
|
|
88
|
+
const vertexStyle = Object.assign(Object.assign({}, style), { lineType: undefined });
|
|
89
|
+
if (isModern(context)) {
|
|
90
|
+
text.pair("100", "AcDb3dPolyline");
|
|
91
|
+
}
|
|
92
|
+
text.pair("66", "1");
|
|
93
|
+
text.point(DXF_POINT_CODES, [0, 0, planar ? points[0][2] : 0]);
|
|
94
|
+
text.pair("70", String((closed ? DXF_CLOSED_FLAG : 0) + (planar ? 0 : DXF_POLYLINE_3D_FLAG)));
|
|
95
|
+
points.forEach((point, at) => {
|
|
96
|
+
var _a;
|
|
97
|
+
openEntity(context, "VERTEX", vertexStyle, owner);
|
|
98
|
+
if (isModern(context)) {
|
|
99
|
+
text.pair("100", "AcDbVertex");
|
|
100
|
+
text.pair("100", "AcDb3dPolylineVertex");
|
|
101
|
+
}
|
|
102
|
+
text.point(DXF_POINT_CODES, point);
|
|
103
|
+
const bulge = (_a = bulges[at]) !== null && _a !== void 0 ? _a : 0;
|
|
104
|
+
if (planar && bulge !== 0) {
|
|
105
|
+
text.real("42", bulge);
|
|
106
|
+
}
|
|
107
|
+
text.pair("70", planar ? "0" : VERTEX_3D_FLAG);
|
|
108
|
+
});
|
|
109
|
+
openEntity(context, "SEQEND", vertexStyle, owner);
|
|
110
|
+
};
|
|
111
|
+
const writePoints = (context, points, bulges, closed, style) => {
|
|
112
|
+
const planar = points.every(point => point[2] === points[0][2]);
|
|
113
|
+
if (planar && isModern(context)) {
|
|
114
|
+
writeLightPolyline(context, points, bulges, closed, style);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
writeHeavyPolyline(context, points, bulges, closed, planar, style);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const writePolyline = (context, polyline, style) => writePoints(context, polyline.points, polyline.bulges, polyline.closed, style);
|
|
121
|
+
const writeSamples = (context, segment, style) => {
|
|
122
|
+
const samples = segmentSamples(segment, context.curveTolerance, context.text.budget);
|
|
123
|
+
context.text.refuseWhenSpent();
|
|
124
|
+
const closed = samples.length > 2 && distance3(samples[0], samples[samples.length - 1]) <= SAME_POINT;
|
|
125
|
+
const points = closed ? samples.slice(0, -1) : samples;
|
|
126
|
+
writePoints(context, points, [], closed, style);
|
|
127
|
+
};
|
|
128
|
+
const writeSpline = (context, spline, style) => {
|
|
129
|
+
const curve = spline.curve;
|
|
130
|
+
const planar = curve.points.every(point => point[2] === curve.points[0][2]);
|
|
131
|
+
const rational = isRationalPiece(curve);
|
|
132
|
+
openEntity(context, "SPLINE", style);
|
|
133
|
+
const text = context.text;
|
|
134
|
+
text.pair("100", "AcDbSpline");
|
|
135
|
+
if (planar) {
|
|
136
|
+
text.point(DXF_EXTRUSION_CODES, PLUS_Z);
|
|
137
|
+
}
|
|
138
|
+
text.pair("70", String((planar ? PLANAR_FLAG : 0) + (rational ? DXF_RATIONAL_FLAG : 0)));
|
|
139
|
+
text.pair("71", String(curve.degree));
|
|
140
|
+
text.pair("72", String(curve.knots.length));
|
|
141
|
+
text.pair("73", String(curve.points.length));
|
|
142
|
+
text.pair("74", "0");
|
|
143
|
+
text.pair("42", DXF_KNOT_TOLERANCE);
|
|
144
|
+
text.pair("43", DXF_KNOT_TOLERANCE);
|
|
145
|
+
for (const knot of curve.knots) {
|
|
146
|
+
text.real("40", knot);
|
|
147
|
+
}
|
|
148
|
+
curve.points.forEach((point, at) => {
|
|
149
|
+
text.point(DXF_POINT_CODES, point);
|
|
150
|
+
if (rational) {
|
|
151
|
+
text.real("41", curve.weights[at]);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const writeEllipse = (context, ellipse, style) => {
|
|
156
|
+
openEntity(context, "ELLIPSE", style);
|
|
157
|
+
const text = context.text;
|
|
158
|
+
const isWhole = ellipse.end - ellipse.start >= 2 * Math.PI - DXF_TURN_SLACK;
|
|
159
|
+
text.pair("100", "AcDbEllipse");
|
|
160
|
+
text.point(DXF_POINT_CODES, ellipse.center);
|
|
161
|
+
text.point(DXF_OTHER_POINT_CODES, ellipse.majorAxis);
|
|
162
|
+
text.point(DXF_EXTRUSION_CODES, ellipse.normal);
|
|
163
|
+
text.real("40", ellipse.ratio);
|
|
164
|
+
text.real("41", isWhole ? 0 : angleWithinTurn(ellipse.start, 2 * Math.PI));
|
|
165
|
+
text.real("42", isWhole ? 2 * Math.PI : angleWithinTurn(ellipse.end, 2 * Math.PI));
|
|
166
|
+
};
|
|
167
|
+
export const writeSegment = (context, segment, style) => {
|
|
168
|
+
switch (segment.kind) {
|
|
169
|
+
case "line":
|
|
170
|
+
writeLine(context, segment, style);
|
|
171
|
+
break;
|
|
172
|
+
case "circle":
|
|
173
|
+
case "arc":
|
|
174
|
+
writeCircleOrArc(context, segment, style);
|
|
175
|
+
break;
|
|
176
|
+
case "polyline":
|
|
177
|
+
writePolyline(context, segment, style);
|
|
178
|
+
break;
|
|
179
|
+
case "spline":
|
|
180
|
+
if (isModern(context)) {
|
|
181
|
+
writeSpline(context, segment, style);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
writeSamples(context, segment, style);
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
case "ellipse":
|
|
188
|
+
if (isModern(context)) {
|
|
189
|
+
writeEllipse(context, segment, style);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
writeSamples(context, segment, style);
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dxfTextOf: (data: unknown, property: string) => string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { InputError } from "../../../../kernel-calls";
|
|
2
|
+
import { bytesOfData } from "../file-bytes";
|
|
3
|
+
const FIRST_UTF8_VERSION = 1021;
|
|
4
|
+
const UNNAMED_CODE_PAGE = "windows-1252";
|
|
5
|
+
const CODE_PAGE_ENCODINGS = new Map([
|
|
6
|
+
["ANSI_874", "windows-874"],
|
|
7
|
+
["ANSI_932", "shift_jis"],
|
|
8
|
+
["ANSI_936", "gbk"],
|
|
9
|
+
["ANSI_949", "euc-kr"],
|
|
10
|
+
["ANSI_950", "big5"],
|
|
11
|
+
["ANSI_1250", "windows-1250"],
|
|
12
|
+
["ANSI_1251", "windows-1251"],
|
|
13
|
+
["ANSI_1252", "windows-1252"],
|
|
14
|
+
["ANSI_1253", "windows-1253"],
|
|
15
|
+
["ANSI_1254", "windows-1254"],
|
|
16
|
+
["ANSI_1255", "windows-1255"],
|
|
17
|
+
["ANSI_1256", "windows-1256"],
|
|
18
|
+
["ANSI_1257", "windows-1257"],
|
|
19
|
+
["ANSI_1258", "windows-1258"],
|
|
20
|
+
]);
|
|
21
|
+
const VERSION_IN_HEADER = /(?:^|[\r\n])[ \t]*9[ \t]*(?:\r\n|\r|\n)[ \t]*\$ACADVER[ \t]*(?:\r\n|\r|\n)[ \t]*1[ \t]*(?:\r\n|\r|\n)[ \t]*AC(\d+)/;
|
|
22
|
+
const CODE_PAGE_IN_HEADER = /(?:^|[\r\n])[ \t]*9[ \t]*(?:\r\n|\r|\n)[ \t]*\$DWGCODEPAGE[ \t]*(?:\r\n|\r|\n)[ \t]*3[ \t]*(?:\r\n|\r|\n)[ \t]*(\S+)/;
|
|
23
|
+
const strictUtf8 = (bytes) => {
|
|
24
|
+
try {
|
|
25
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const dxfTextOf = (data, property) => {
|
|
32
|
+
var _a, _b, _c, _d, _e;
|
|
33
|
+
if (typeof data === "string") {
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
const bytes = bytesOfData(data);
|
|
37
|
+
if (bytes === undefined) {
|
|
38
|
+
throw new InputError(`\`${property}\` must be the text of a DXF file or its bytes; it is ${data === null ? "null" : typeof data}.`, property);
|
|
39
|
+
}
|
|
40
|
+
const utf8 = strictUtf8(bytes);
|
|
41
|
+
if (utf8 !== undefined) {
|
|
42
|
+
return utf8;
|
|
43
|
+
}
|
|
44
|
+
const unnamed = new TextDecoder(UNNAMED_CODE_PAGE).decode(bytes);
|
|
45
|
+
if (Number((_b = (_a = VERSION_IN_HEADER.exec(unnamed)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : 0) >= FIRST_UTF8_VERSION) {
|
|
46
|
+
return new TextDecoder().decode(bytes);
|
|
47
|
+
}
|
|
48
|
+
const encoding = CODE_PAGE_ENCODINGS.get((_e = (_d = (_c = CODE_PAGE_IN_HEADER.exec(unnamed)) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.toUpperCase()) !== null && _e !== void 0 ? _e : "");
|
|
49
|
+
return encoding === undefined ? unnamed : new TextDecoder(encoding).decode(bytes);
|
|
50
|
+
};
|
|
@@ -1,38 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import type * as Resolved from "../../../../resolved-inputs";
|
|
2
2
|
export declare class DxfGenerator {
|
|
3
|
-
|
|
4
|
-
private colorFormat;
|
|
5
|
-
private acadVersion;
|
|
6
|
-
/**
|
|
7
|
-
* Generate a complete DXF file content from path-based entities
|
|
8
|
-
*/
|
|
9
|
-
generateDxf(dxfInputs: Inputs.IO.DxfModelDto): string;
|
|
10
|
-
private generateHeader;
|
|
11
|
-
private unitHeader;
|
|
12
|
-
private generateTables;
|
|
13
|
-
private generateLineTypeTable;
|
|
14
|
-
private generateStyleTable;
|
|
15
|
-
private generateVportTable;
|
|
16
|
-
private generateViewTable;
|
|
17
|
-
private generateUcsTable;
|
|
18
|
-
private generateAppidTable;
|
|
19
|
-
private generateDimstyleTable;
|
|
20
|
-
private generateBlocks;
|
|
21
|
-
private generateLayerTable;
|
|
22
|
-
private generateEntities;
|
|
23
|
-
private generateSegmentEntity;
|
|
24
|
-
private isLineSegment;
|
|
25
|
-
private isArcSegment;
|
|
26
|
-
private isCircleSegment;
|
|
27
|
-
private isPolylineSegment;
|
|
28
|
-
private isSplineSegment;
|
|
29
|
-
private generateLineEntity;
|
|
30
|
-
private generateCircleEntity;
|
|
31
|
-
private generateArcEntity;
|
|
32
|
-
private generatePolylineEntity;
|
|
33
|
-
private generateSplineEntity;
|
|
34
|
-
private isClosedPolyline;
|
|
35
|
-
private getNextHandle;
|
|
36
|
-
private convertColorToDxf;
|
|
37
|
-
private rgbToAciColorIndex;
|
|
3
|
+
generateDxf(model: Resolved.IO.DxfModelDto): string;
|
|
38
4
|
}
|