[200] DXF-Export: Stifte je Element (Farbe 420/62, Strichstärke 370) und Schnitt/Ansicht als DXF/DWG (App-Dialog, CLI --format)
This commit is contained in:
15 files changed
+396
-33
No files matched your search
@@ -29,6 +29,10 @@ interface EzEntity {
|
||||
paths?: number;
|
||||
pattern_lines?: number;
|
||||
rgb?: number[] | null;
|
||||
/** [200] Eigene Farbe (True-Color 420 / ACI 62) und Strichstärke (370); `null` = nach Ebene. */
|
||||
trueColor?: number[] | null;
|
||||
aci?: number | null;
|
||||
lineweight?: number | null;
|
||||
gradient?: { name: string; rotation: number; color1: number[]; color2: number[] } | null;
|
||||
}
|
||||
interface EzResult {
|
||||
@@ -173,4 +177,41 @@ describe.skipIf(!hasEzdxf)("DXF-Export gegen ezdxf", { timeout: 60_000 }, () =>
|
||||
expect(r.result!.errors).toEqual([]);
|
||||
expect(r.result!.entities.filter((e) => e.type === "HATCH").map((h) => h.gradient?.name)).toEqual(["LINEAR", "SPHERICAL"]);
|
||||
});
|
||||
|
||||
// [200] Stifte je Element: Entitäten tragen eigene Farbe (420 + nächste ACI 62) und Strichstärke (370), wenn sie vom
|
||||
// Ebenen-Standard abweichen; Standardwerte bleiben ByLayer.
|
||||
it("[200] Stift je Element: abweichende Farbe/Strichstärke je Entität, sonst nach Ebene", () => {
|
||||
const cat = sampleProject.layers[0];
|
||||
const project: Project = {
|
||||
...sampleProject,
|
||||
drawings2d: [{ ...(sampleProject.drawings2d[0] ?? {}), id: "d1", categoryCode: cat.code } as Project["drawings2d"][number]],
|
||||
};
|
||||
const line = (y: number, color: string, weightMm: number) => ({ kind: "line", a: { x: 0, y }, b: { x: 1, y }, cls: "x", color, weightMm, opacity: 1, drawingId: "d1" });
|
||||
const plan = {
|
||||
primitives: [
|
||||
line(0, cat.color, cat.lw), // Standard der Ebene
|
||||
line(1, "#c03020", 0.35), // abweichend
|
||||
line(2, cat.color, 0.7), // nur die Stärke weicht ab
|
||||
{ kind: "polygon", pts: [{ x: 0, y: 5 }, { x: 2, y: 5 }, { x: 2, y: 7 }], fill: "none", stroke: "#336699", strokeWidthMm: 0.5, hatch: { pattern: "none", scale: 1, angle: 0, color: "#000", lineWeight: 0.1, dash: null }, drawingId: "d1" },
|
||||
],
|
||||
bounds: { minX: 0, minY: 0, maxX: 2, maxY: 7 },
|
||||
} as unknown as Plan;
|
||||
for (const bytes of [buildPlanDxf(plan, project), buildPlanDxfBinary(plan, project)]) {
|
||||
const r = ezdxfRead("stift", bytes);
|
||||
expect(r.result, r.err).not.toBeNull();
|
||||
expect(r.result!.errors).toEqual([]);
|
||||
expect(r.status).toBe(0);
|
||||
const e = r.result!.entities;
|
||||
expect(e.map((x) => x.type)).toEqual(["LINE", "LINE", "LINE", "LWPOLYLINE"]);
|
||||
expect(e[0].trueColor ?? null).toBeNull();
|
||||
expect(e[0].lineweight ?? null).toBeNull();
|
||||
expect(e[1].trueColor).toEqual([0xc0, 0x30, 0x20]);
|
||||
expect(e[1].aci).toBeGreaterThan(0);
|
||||
expect(e[1].lineweight).toBe(35);
|
||||
expect(e[2].trueColor ?? null).toBeNull();
|
||||
expect(e[2].lineweight).toBe(70);
|
||||
expect(e[3].trueColor).toEqual([0x33, 0x66, 0x99]);
|
||||
expect(e[3].lineweight).toBe(50);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
// [200] Schnitt und Ansicht als DXF/DWG: dieselbe Ableitung wie in der App und im PDF-Blatt
|
||||
// (`viewportLevelPlan`) geht durch den Plan-Sammler des Kerns. Gegengelesen mit dem eigenen Import und
|
||||
// (falls installiert) ezdxf; Stifte je Element wie im Grundriss.
|
||||
|
||||
import "../engine/fileioWasm.setup";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { buildPlanDwg, buildPlanDxf } from "./exportDxf";
|
||||
import { countByType, readDxf } from "./cadReadBack.testutil";
|
||||
import { parseDxf } from "../io/dxfParser";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { collectVisibleCodes } from "../model/types";
|
||||
import { viewportLevelPlan } from "../plan/viewportPlan";
|
||||
|
||||
const hasEzdxf = spawnSync("python3", ["-c", "import ezdxf"]).status === 0;
|
||||
const p = buildComplexSampleProject();
|
||||
const codes = collectVisibleCodes(p.layers);
|
||||
|
||||
describe.each([
|
||||
["schnitt-a", "Schnitt"],
|
||||
["ansicht-sued", "Ansicht"],
|
||||
])("[200] %s als DXF/DWG", (levelId, label) => {
|
||||
it(`${label}: Entitäten, eigene Stifte, Rückimport`, async () => {
|
||||
const plan = await viewportLevelPlan(p, levelId, codes, "mittel", 100, true, false);
|
||||
expect(plan.primitives.length).toBeGreaterThan(100);
|
||||
const text = buildPlanDxf(plan, p, { scaleDenominator: 100, levelId });
|
||||
const dxf = readDxf(text);
|
||||
const n = countByType(dxf.entities);
|
||||
expect((n.LINE ?? 0) + (n.LWPOLYLINE ?? 0)).toBeGreaterThan(100);
|
||||
// Farbig (mono: false): Elemente mit eigener Farbe tragen True-Color (420), abweichende Stärken 370.
|
||||
expect(dxf.entities.filter((e) => e.codes.some(([c]) => c === 420)).length).toBeGreaterThan(0);
|
||||
expect(dxf.entities.filter((e) => e.codes.some(([c]) => c === 370)).length).toBeGreaterThan(0);
|
||||
// Der eigene Import liest die Zeichnung zurück.
|
||||
const parsed = parseDxf(text);
|
||||
expect(parsed.summary.contours).toBeGreaterThan(50);
|
||||
// DWG derselben Zeichnung.
|
||||
expect(Buffer.from(buildPlanDwg(plan, p, { scaleDenominator: 100, levelId }).subarray(0, 6)).toString()).toBe("AC1032");
|
||||
}, 60_000);
|
||||
|
||||
it.skipIf(!hasEzdxf)(`${label}: ezdxf liest ohne Auditor-Fehler`, async () => {
|
||||
const plan = await viewportLevelPlan(p, levelId, codes, "mittel", 100, true, false);
|
||||
const dir = mkdtempSync(join(tmpdir(), "dossier-dxf-"));
|
||||
const file = join(dir, `${levelId}.dxf`);
|
||||
writeFileSync(file, buildPlanDxf(plan, p, { scaleDenominator: 100, levelId }));
|
||||
const r = spawnSync("python3", ["scripts/validate-dxf.py", file], { encoding: "utf8", timeout: 60_000, maxBuffer: 256 * 1024 * 1024 });
|
||||
const res = JSON.parse(r.stdout) as { errors: string[]; entities: unknown[] };
|
||||
expect(res.errors).toEqual([]);
|
||||
expect(r.status).toBe(0);
|
||||
expect(res.entities.length).toBeGreaterThan(100);
|
||||
}, 60_000);
|
||||
});
|
||||
Reference in new issue
Block a user