[C2] DXF-Export: Verlauf als Gradient-HATCH, Binär-DXF als Format

Verlauf-Schraffuren (linear/radial) gehen als echte Gradient-HATCH (neuer
Datensatz REC_GRADIENT) statt nur als Umriss. Neues Ausgabeformat "DXF binär"
(acadrust new_binary) im Dialog und als CLI-Option `dxf --binary`.
Rundreise acadrust (DXF, binär, DWG) und ezdxf (Auditor, Name, Winkel, Farben).

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-28 12:38:08 +00:00
1 parent 5ef3d07efa
commit d909acc875
11 files changed
+324 -30

No files matched your search

+4 -2
View File
@@ -8,7 +8,7 @@
// dossier-cli <projekt.obp> plan [--level EG] [--scale 100] [--out eg.svg]
// dossier-cli <projekt.obp> section <Name> [--out schnitt.svg] (braucht render3d-WASM)
// dossier-cli <projekt.obp> elevation <Name> [--out ansicht.svg]
// dossier-cli <projekt.obp> dxf|dwg|ifc|step|obj|stl|schedule|kennzahlen|sun [--level EG] [--out datei]
// dossier-cli <projekt.obp> dxf [--binary]|dwg|ifc|step|obj|stl|schedule|kennzahlen|sun [--level EG] [--out datei]
// dossier-cli <projekt.obp> import-ifc <datei.ifc> [--out neu.obp] [--group product|class]
// IFC als Kontext-Meshes ([B3]); Bericht als JSON auf stdout
// dossier-cli <projekt.obp> model3d [--out modell.json] 3D-Modell fürs Headless-Rendern (render_png)
@@ -23,6 +23,7 @@ import { fileURLToPath } from "node:url";
import {
buildPlanDxf,
buildPlanDwg,
buildPlanDxfBinary,
loadFileio,
readIfc,
ifcToImportedMeshes,
@@ -221,7 +222,8 @@ export async function run(argv: string[]): Promise<number> {
const world = projectToWorldCoords(project);
const plan = generatePlan(world, lvl.id, allCodes);
await loadFileio();
if (command === "dxf") out(args, buildPlanDxf(plan, world), `${lvl.name}.dxf`);
if (command === "dxf" && args.flags.has("binary")) out(args, buildPlanDxfBinary(plan, world), `${lvl.name}.dxf`);
else if (command === "dxf") out(args, buildPlanDxf(plan, world), `${lvl.name}.dxf`);
else out(args, buildPlanDwg(plan, world), `${lvl.name}.dwg`);
return 0;
}
+1
View File
@@ -5,6 +5,7 @@ export { parseProjectFile, serializeProject, PROJECT_FORMAT_VERSION } from "../i
export { exportIfcSpf } from "../export/exportIfc";
export { buildPlanDxf } from "../export/exportDxf";
export { buildPlanDwg } from "../export/exportDxf";
export { buildPlanDxfBinary } from "../export/exportDxf";
export { loadFileio } from "../engine/fileioWasm";
export { readIfc, ifcToImportedMeshes } from "../io/ifcImport";
export { projectGeoOrigin } from "../model/geoRebase";
+49 -2
View File
@@ -9,7 +9,7 @@ import { spawnSync } from "node:child_process";
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { buildPlanDxf } from "./exportDxf";
import { buildPlanDxf, buildPlanDxfBinary } from "./exportDxf";
import { sampleProject } from "../model/sampleProject";
import { generatePlan } from "../plan/generatePlan";
import type { Plan } from "../plan/generatePlan";
@@ -29,6 +29,7 @@ interface EzEntity {
paths?: number;
pattern_lines?: number;
rgb?: number[] | null;
gradient?: { name: string; rotation: number; color1: number[]; color2: number[] } | null;
}
interface EzResult {
version: string;
@@ -38,7 +39,7 @@ interface EzResult {
entities: EzEntity[];
}
function ezdxfRead(name: string, dxf: string): { status: number | null; result: EzResult | null; err: string } {
function ezdxfRead(name: string, dxf: string | Uint8Array): { status: number | null; result: EzResult | null; err: string } {
const dir = mkdtempSync(join(tmpdir(), "dossier-dxf-"));
const file = join(dir, `${name}.dxf`);
writeFileSync(file, dxf);
@@ -122,4 +123,50 @@ describe.skipIf(!hasEzdxf)("DXF-Export gegen ezdxf", { timeout: 60_000 }, () =>
expect(h.pts).toEqual(sq.map((p) => [p.x, p.y]));
}
});
const gradPlan = (): Plan => {
const sq = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 3 }, { x: 0, y: 3 }];
const poly = (gradient: object) => ({
kind: "polygon", pts: sq, fill: "#eee", stroke: "#111", strokeWidthMm: 0.25,
hatch: { pattern: "crosshatch", scale: 1, angle: 0, color: "#336699", lineWeight: 0.13, dash: null, kind: "gradient", gradient },
});
return {
primitives: [
poly({ color1: "#ffffff", color2: "#003399", angle: 90, type: "linear" }),
poly({ color1: "#f00", color2: "#00f", angle: 0, type: "radial" }),
],
bounds: { minX: 0, minY: 0, maxX: 4, maxY: 3 },
} as unknown as Plan;
};
it("Verlauf: ezdxf liest echte Gradient-HATCHs (linear, radial) ohne Auditor-Fehler", () => {
const r = ezdxfRead("gradient", buildPlanDxf(gradPlan(), sampleProject));
expect(r.result, r.err).not.toBeNull();
expect(r.result!.errors).toEqual([]);
expect(r.status).toBe(0);
const hs = r.result!.entities.filter((e) => e.type === "HATCH");
expect(hs.length).toBe(2);
expect(hs[0].gradient).toMatchObject({ name: "LINEAR", color1: [255, 255, 255], color2: [0, 0x33, 0x99] });
expect(hs[0].gradient!.rotation).toBeCloseTo(90, 6);
expect(hs[1].gradient).toMatchObject({ name: "SPHERICAL", color1: [255, 0, 0], color2: [0, 0, 255] });
});
it("Binär-DXF: ezdxf liest dieselbe Zeichnung wie die ASCII-Fassung ohne Auditor-Fehler", () => {
const plan = generatePlan(sampleProject, "eg", new Set(flattenCategories(sampleProject.layers).map((l) => l.code)));
const asc = ezdxfRead("bin-asc", buildPlanDxf(plan, sampleProject));
const bin = ezdxfRead("bin-bin", buildPlanDxfBinary(plan, sampleProject));
expect(bin.result, bin.err).not.toBeNull();
expect(bin.result!.errors).toEqual([]);
expect(bin.status).toBe(0);
expect(bin.result!.entities).toEqual(asc.result!.entities);
expect(Object.keys(bin.result!.layers)).toEqual(Object.keys(asc.result!.layers));
// und kleiner als der Text
expect(buildPlanDxfBinary(plan, sampleProject).length).toBeLessThan(buildPlanDxf(plan, sampleProject).length);
});
it("Binär-DXF mit Verlauf: Gradient bleibt erhalten", () => {
const r = ezdxfRead("bin-grad", buildPlanDxfBinary(gradPlan(), sampleProject));
expect(r.result!.errors).toEqual([]);
expect(r.result!.entities.filter((e) => e.type === "HATCH").map((h) => h.gradient?.name)).toEqual(["LINEAR", "SPHERICAL"]);
});
});
+41 -7
View File
@@ -1,15 +1,14 @@
/**
* DXF-Export von Verlauf-Schraffuren (`HatchStyle.kind === "gradient"`).
* DXF trägt keine echten Farbverläufe (wie bereits bei Bild-Schraffuren
* akzeptiert) — der Export muss auf die reine Umriss-Polylinie zurückfallen
* und darf KEINE (aus dem stehengebliebenen `pattern`-Feld abgeleiteten)
* Musterlinien mehr ausgeben.
* Verläufe gehen als echte Gradient-HATCH ins DXF ([C2], 28.10.: Gruppencodes 450–470);
* es dürfen KEINE (aus dem stehengebliebenen `pattern`-Feld abgeleiteten) Musterlinien
* mehr ausgegeben werden. Ohne lesbare Farben bleibt es beim Umriss.
*/
import { describe, expect, it } from "vitest";
import "../engine/fileioWasm.setup";
import { buildPlanDxf } from "./exportDxf";
import { nums, readDxf } from "./cadReadBack.testutil";
import { num, nums, readDxf, str } from "./cadReadBack.testutil";
import { sampleProject } from "../model/sampleProject";
import type { Plan } from "../plan/generatePlan";
import type { HatchRender } from "../plan/generatePlan/shared";
@@ -58,7 +57,7 @@ describe("buildPlanDxf — Verlauf-Schraffur", () => {
expect(nums(h, 53).map((a) => Math.round(a))).toEqual([0, 90]);
});
it("gradient: KEINE Musterlinien, nur die Umriss-Polylinie", () => {
it("gradient: eine Gradient-HATCH (LINEAR, zwei Farben, Winkel) plus Umriss, keine Musterlinien", () => {
const dxf = buildPlanDxf(
planWith([
polyWith({
@@ -69,7 +68,42 @@ describe("buildPlanDxf — Verlauf-Schraffur", () => {
sampleProject,
);
expect(countEntities(dxf, "LINE")).toBe(0);
expect(countEntities(dxf, "HATCH")).toBe(0);
expect(countEntities(dxf, "HATCH")).toBe(1);
expect(countEntities(dxf, "LWPOLYLINE")).toBe(1); // Umriss bleibt erhalten
const h = readDxf(dxf).entities.find((e) => e.type === "HATCH")!;
expect(str(h, 470)).toBe("LINEAR");
expect(num(h, 460)).toBeCloseTo(Math.PI / 4, 9);
expect(nums(h, 463)).toEqual([0, 1]);
expect(nums(h, 421)).toEqual([0xffffff, 0x000000]);
});
it("gradient radial: SPHERICAL; 3-stellige Farben werden erweitert", () => {
const dxf = buildPlanDxf(
planWith([polyWith({ kind: "gradient", gradient: { color1: "#f00", color2: "#00f", angle: 0, type: "radial" } })]),
sampleProject,
);
const h = readDxf(dxf).entities.find((e) => e.type === "HATCH")!;
expect(str(h, 470)).toBe("SPHERICAL");
expect(nums(h, 421)).toEqual([0xff0000, 0x0000ff]);
});
it("gradient ohne lesbare Farbe oder ohne Parameter: nur der Umriss", () => {
for (const hatch of [
polyWith({ kind: "gradient", gradient: { color1: "none", color2: "#000000", angle: 0, type: "linear" } }),
polyWith({ kind: "gradient" }),
]) {
const dxf = buildPlanDxf(planWith([hatch]), sampleProject);
expect(countEntities(dxf, "HATCH")).toBe(0);
expect(countEntities(dxf, "LWPOLYLINE")).toBe(1);
}
});
it("gradient ohne Schraffuren-Option: nur der Umriss", () => {
const dxf = buildPlanDxf(
planWith([polyWith({ kind: "gradient", gradient: { color1: "#fff", color2: "#000", angle: 0, type: "linear" } })]),
sampleProject,
{ includeHatches: false },
);
expect(countEntities(dxf, "HATCH")).toBe(0);
});
});
+53 -10
View File
@@ -32,7 +32,12 @@ export interface ExportDxfOptions {
}
/** Ausgabeformat des Modell-Space-Exports. */
export type CadExportFormat = "dxf" | "dwg";
export type CadExportFormat = "dxf" | "dxfbin" | "dwg";
/** Dateiendung zum Ausgabeformat (Binär-DXF trägt ebenfalls `.dxf`). */
export function cadExtension(format: CadExportFormat): "dxf" | "dwg" {
return format === "dwg" ? "dwg" : "dxf";
}
/** Sammel-Layer-Namen für Primitive ohne eigene Kategorie. */
const LAYER_HATCH = "HATCH";
@@ -54,6 +59,7 @@ const REC_ARC = 4;
const REC_CIRCLE = 5;
const REC_TEXT = 6;
const REC_HATCH = 7;
const REC_GRADIENT = 8;
/**
* Sammelt Ebenen und Entitäten als flachen Zahlenpuffer + Zeichenkettenliste. Ebenen sind
@@ -128,6 +134,17 @@ export class FlatDrawing {
for (const p of pts) this.nums.push(p.x, p.y);
}
/**
* Zweifarben-Verlauf als echte Gradient-HATCH-Entität (Rand `pts`, geschlossen). `rgb1`/`rgb2` =
* 0xRRGGBB; `angle` (Radiant) = Richtung von `rgb1` nach `rgb2` (nur linear); `radial`: `rgb1` in der
* Mitte, `rgb2` am Rand.
*/
addGradient(layer: string, pts: Vec2[], g: { rgb1: number; rgb2: number; angle: number; radial: boolean }): void {
if (pts.length < 3) return;
this.nums.push(REC_GRADIENT, this.layer(layer), g.rgb1, g.rgb2, g.angle, g.radial ? 1 : 0, pts.length);
for (const p of pts) this.nums.push(p.x, p.y);
}
/** Argumente für die Rust-Bindungen. */
args(): [Float64Array, string] {
return [Float64Array.from(this.nums), this.strings.join("\0")];
@@ -213,6 +230,15 @@ export function buildPlanDxf(
return new TextDecoder().decode(writeCad("dxf", collectPlanDrawing(plan, project, opts)));
}
/** Wie {@link buildPlanDxf}, aber als Binär-DXF (R2018, Bytes; deutlich kleiner und schneller zu lesen). */
export function buildPlanDxfBinary(
plan: Plan,
project: Project,
opts: ExportDxfOptions = {},
): Uint8Array {
return writeCad("dxfbin", collectPlanDrawing(plan, project, opts));
}
/** Wie {@link buildPlanDxf}, aber als DWG (R2018, Bytes). */
export function buildPlanDwg(
plan: Plan,
@@ -226,10 +252,15 @@ export function buildPlanDwg(
function writeCad(format: CadExportFormat, drawing: FlatDrawing): Uint8Array {
const m = fileio();
const [flat, strings] = drawing.args();
const bytes = format === "dxf" ? m.export_dxf_flat(flat, strings) : m.export_dwg_flat(flat, strings);
const bytes =
format === "dxf"
? m.export_dxf_flat(flat, strings)
: format === "dxfbin"
? m.export_dxf_binary_flat(flat, strings)
: m.export_dwg_flat(flat, strings);
if (bytes.length === 0) {
const why = m.export_check_flat(flat, strings);
throw new Error(`${format.toUpperCase()}-Export fehlgeschlagen${why ? `: ${why}` : ""}`);
throw new Error(`${cadExtension(format).toUpperCase()}-Export fehlgeschlagen${why ? `: ${why}` : ""}`);
}
return bytes;
}
@@ -289,11 +320,20 @@ function emitPrimitive(
if (pts.length < 2) break;
// Schraffur ([C2], 28.10.) als echte HATCH-Entität UNTER dem Umriss (Zeichenreihenfolge der
// Datei): Vollfüllung bzw. Linienmuster (diagonal/Kreuz/Dämmung/frei, auch gestrichelt) mit dem
// Polygon als Rand und der aufgelösten Vordergrundfarbe. Bild-/Verlauf-Schraffur (kind==="image"/
// "gradient") trägt DXF nicht → FALLBACK ohne Muster (nur der Umriss). Random-Vektor
// Polygon als Rand und der aufgelösten Vordergrundfarbe. Verlauf-Schraffur (kind==="gradient")
// als echte Gradient-HATCH (zwei Farben, linear/radial); ohne lesbare Farben oder Bild-
// Schraffur (kind==="image") trägt DXF das nicht → FALLBACK ohne Muster (nur der Umriss). Random-Vektor
// (deterministische Streu-Striche, Modell-Meter, identischer Seed wie Bildschirm/PDF) hat kein
// Musteräquivalent → bleibt als einzelne Linien auf dem HATCH-Layer.
if (includeHatches && p.hatch.kind !== "image" && p.hatch.kind !== "gradient" && pts.length >= 3) {
if (includeHatches && p.hatch.kind === "gradient" && pts.length >= 3) {
const g = p.hatch.gradient;
const rgb1 = g ? rgbOrNull(g.color1) : null;
const rgb2 = g ? rgbOrNull(g.color2) : null;
if (g && rgb1 !== null && rgb2 !== null && Number.isFinite(g.angle)) {
// Richtung wie der SVG-Verlauf der Ansicht: Vektor (cos, sin) in Plan-Koordinaten = DXF-Winkel.
dxf.addGradient(LAYER_HATCH, pts, { rgb1, rgb2, angle: (g.angle * Math.PI) / 180, radial: g.type === "radial" });
}
} else if (includeHatches && p.hatch.kind !== "image" && pts.length >= 3) {
const h = p.hatch;
if (h.pattern === "solid") {
dxf.addHatch(LAYER_HATCH, pts, { solid: true, rgb: rgbOrNull(h.color) });
@@ -430,8 +470,10 @@ export function rgbFromHex(hex: string): number {
/** "#rrggbb" → 0xRRGGBB, bei unlesbarer Farbe (z. B. "none") null = Farbe der Ebene. */
function rgbOrNull(hex: string): number | null {
const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
return m ? parseInt(m[1], 16) : null;
const m = /^#?([0-9a-f]{6}|[0-9a-f]{3})$/i.exec(hex.trim());
if (!m) return null;
const h = m[1].length === 3 ? m[1].replace(/./g, (c) => c + c) : m[1];
return parseInt(h, 16);
}
/** Millimeter → DXF-LWEIGHT (1/100 mm), gerundet auf gültige Stufen ≥ 0. */
@@ -448,12 +490,13 @@ export async function savePlanDxf(
await loadFileio();
const format = opts.format ?? "dxf";
const data = writeCad(format, collectPlanDrawing(plan, project, opts));
const ext = cadExtension(format);
const name = (opts.fileName ?? "grundriss").replace(/\.(dxf|dwg)$/i, "");
const blob = new Blob([data as BlobPart], { type: format === "dxf" ? "application/dxf" : "image/vnd.dwg" });
const blob = new Blob([data as BlobPart], { type: ext === "dxf" ? "application/dxf" : "image/vnd.dwg" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${name}.${format}`;
a.download = `${name}.${ext}`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
+1
View File
@@ -1703,6 +1703,7 @@ export const de = {
"exportDxf.hatches.no": "Nur Umrisse",
"exportDxf.format": "Format",
"exportDxf.format.dxf": "DXF (AutoCAD 2018, Text)",
"exportDxf.format.dxfbin": "DXF binär (AutoCAD 2018, kompakt)",
"exportDxf.format.dwg": "DWG (AutoCAD 2018)",
"exportDxf.failed": "Export fehlgeschlagen",
"exportDxf.unitsNote":
+1
View File
@@ -1691,6 +1691,7 @@ export const en: Record<TranslationKey, string> = {
"exportDxf.hatches.no": "Outlines only",
"exportDxf.format": "Format",
"exportDxf.format.dxf": "DXF (AutoCAD 2018, text)",
"exportDxf.format.dxfbin": "DXF binary (AutoCAD 2018, compact)",
"exportDxf.format.dwg": "DWG (AutoCAD 2018)",
"exportDxf.failed": "Export failed",
"exportDxf.unitsNote":
+3 -2
View File
@@ -13,7 +13,7 @@ import type { CadExportFormat } from "../export/exportDxf";
/** Entscheidung, die der Dialog beim Bestätigen liefert. */
export interface ExportDxfDecision {
/** Dateiformat: DXF (R2018 ASCII) oder DWG (R2018). */
/** Dateiformat: DXF (R2018 ASCII), Binär-DXF (R2018) oder DWG (R2018). */
format: CadExportFormat;
includeHatches: boolean;
/** „nur Auswahl" statt des ganzen Plans (nur relevant, wenn `selectionCount > 0`). */
@@ -78,10 +78,11 @@ export function ExportDxfDialog({
<div className="imp-section-title">{t("exportDxf.format")}</div>
<Dropdown
value={format}
onChange={(v) => setFormat(v === "dwg" ? "dwg" : "dxf")}
onChange={(v) => setFormat(v === "dwg" ? "dwg" : v === "dxfbin" ? "dxfbin" : "dxf")}
title={t("exportDxf.format")}
options={[
{ value: "dxf", label: t("exportDxf.format.dxf") },
{ value: "dxfbin", label: t("exportDxf.format.dxfbin") },
{ value: "dwg", label: t("exportDxf.format.dwg") },
]}
/>