[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
@@ -143,6 +143,20 @@ describe("dossier-cli", () => {
|
||||
expect(readFileSync(out, "utf8")).toContain("±0.00");
|
||||
}
|
||||
}, 60_000);
|
||||
it("[200] Schnitt und Ansicht als DXF/DWG (--format)", async () => {
|
||||
for (const kind of ["section", "elevation"] as const) {
|
||||
const lvl = sampleProject.drawingLevels.find((l) => l.kind === kind);
|
||||
if (!lvl) continue;
|
||||
const dxf = join(dir, `${kind}.dxf`);
|
||||
expect(await call(kind, lvl.name, "--format", "dxf", "--out", dxf)).toBe(0);
|
||||
const text = readFileSync(dxf, "utf8");
|
||||
expect(text).toContain("AC1032");
|
||||
expect(text).toContain("ENTITIES");
|
||||
const dwg = join(dir, `${kind}.dwg`);
|
||||
expect(await call(kind, lvl.name, "--format", "dwg", "--out", dwg)).toBe(0);
|
||||
expect(readFileSync(dwg).subarray(0, 6).toString("latin1")).toBe("AC1032");
|
||||
}
|
||||
}, 60_000);
|
||||
it("Schnitt und STEP über das WASM", async () => {
|
||||
const section = sampleProject.drawingLevels.find((l) => l.kind === "section");
|
||||
if (section) {
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
// json = render2d-Szene (planToRenderScene)
|
||||
// dossier-cli <projekt.obp> section <Name> [--sketch] [--hatch] [--color] [--out schnitt.svg] (--format json: render2d-Szene)
|
||||
// dossier-cli <projekt.obp> elevation <Name> [--sketch] [--hatch] [--color] [--out ansicht.svg] (--sketch: Skizzenstil [67])
|
||||
// section/elevation: --format dxf|dxfbin|dwg schreibt die Zeichnung als CAD-Datei [200]
|
||||
// (Modell-Space in Metern: x entlang der Schnitt-/Ansichtslinie, y = Höhe; --scale, --dim-unit cm, --layout wie bei dxf)
|
||||
// --color: Darstellung „Farbig" statt Tusche (Standard, [140])
|
||||
// plan/section/elevation: --template <Vorlage> wendet eine Ansichtsvorlage ganz an
|
||||
// (Ebenen-Felder wie verdeckte Kanten/Schnittflächen schraffiert/Schatten/Skizze,
|
||||
@@ -760,6 +762,16 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
out(args, JSON.stringify(planToRenderScene(plan, tv.scale)), `${lvl.name}.scene.json`);
|
||||
return 0;
|
||||
}
|
||||
// [200] `--format dxf|dxfbin|dwg`: Schnitt/Ansicht als Modell-Space-Zeichnung (Plan-Einheiten: Meter, y = Höhe).
|
||||
const cadFormat = args.flags.get("format");
|
||||
if (cadFormat === "dxf" || cadFormat === "dxfbin" || cadFormat === "dwg") {
|
||||
await loadFileio();
|
||||
const cad = { scaleDenominator: tv.scale, dimUnit: args.flags.get("dim-unit") === "cm" ? ("cm" as const) : ("m" as const), paperLayout: args.flags.has("layout"), levelId: lvl.id };
|
||||
if (cadFormat === "dxf") out(args, buildPlanDxf(plan, sp, cad), `${lvl.name}.dxf`);
|
||||
else if (cadFormat === "dxfbin") out(args, buildPlanDxfBinary(plan, sp, cad), `${lvl.name}.dxf`);
|
||||
else out(args, buildPlanDwg(plan, sp, cad), `${lvl.name}.dwg`);
|
||||
return 0;
|
||||
}
|
||||
out(args, planToSvgString(plan, { scaleDenominator: tv.scale, hatch: args.flags.has("hatch") && args.flags.get("hatch") !== "false" }), `${lvl.name}.svg`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -2633,6 +2633,9 @@ export const de = {
|
||||
"exportDxf.format.dxfbin": "DXF binär (AutoCAD 2018, kompakt)",
|
||||
"exportDxf.format.dwg": "DWG (AutoCAD 2018)",
|
||||
"exportDxf.failed": "Export fehlgeschlagen",
|
||||
"exportDxf.empty": "Die Ansicht enthält nichts zum Exportieren (Schnitt-/Ansichtslinie prüfen).",
|
||||
"export.section": "Schnitt",
|
||||
"export.elevation": "Ansicht",
|
||||
"exportDxf.unitsNote":
|
||||
"Modell-Space in Metern (1:1). Layer entsprechen den Ebenen des Projekts; beim Plot beliebig skalierbar.",
|
||||
"exportDxf.scale": "Massstab (Bemassung, Strichmuster, Beschriftung)",
|
||||
|
||||
@@ -2621,6 +2621,9 @@ export const en: Record<TranslationKey, string> = {
|
||||
"exportDxf.format.dxfbin": "DXF binary (AutoCAD 2018, compact)",
|
||||
"exportDxf.format.dwg": "DWG (AutoCAD 2018)",
|
||||
"exportDxf.failed": "Export failed",
|
||||
"exportDxf.empty": "The view has nothing to export (check the section/elevation line).",
|
||||
"export.section": "Section",
|
||||
"export.elevation": "Elevation",
|
||||
"exportDxf.unitsNote":
|
||||
"Model space in meters (1:1). Layers mirror the project's categories; scale freely on plot.",
|
||||
"exportDxf.scale": "Scale (dimensions, dash patterns, labels)",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// Extrahiert aus App.tsx. Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { generatePlan, withDocument } from "../core";
|
||||
import { generatePlan, viewportLevelPlan, withDocument } from "../core";
|
||||
import type { CategoryDisplayResolver } from "../core";
|
||||
import type { DetailLevel } from "../model/viewTypes";
|
||||
import type { DisplayResolver } from "../viewport/Viewport3D";
|
||||
@@ -155,18 +155,36 @@ export function useExportHandlers(opts: {
|
||||
const scoped = scopedProject(decision.selectionOnly);
|
||||
const exportProject = withDocument(scoped, () => projectToWorldCoords(scoped));
|
||||
await withDocument(exportProject, async () => {
|
||||
const plan = generatePlan(
|
||||
exportProject,
|
||||
activeLevelId,
|
||||
visibleCodes,
|
||||
categoryDisplay,
|
||||
detail,
|
||||
referenceLines,
|
||||
planColorMode === "mono",
|
||||
true, // includeGlobal (Default)
|
||||
decision.scaleDenominator, // Export-Massstab (wie PDF): Strichstärken, Bemassung
|
||||
true, // forPrint: `Drawing2D.noPrint`-Elemente ausschliessen
|
||||
);
|
||||
// [200] Schnitt und Ansicht: dieselbe Ableitung wie in der Schnitt-/Ansichts-Ansicht und im PDF-Blatt
|
||||
// (`viewportLevelPlan`: Projektion aus dem Kern, Koten, eigene 2D-Elemente), sonst der Grundriss.
|
||||
const levelKind = exportProject.drawingLevels.find((l) => l.id === activeLevelId)?.kind;
|
||||
const plan =
|
||||
levelKind === "section" || levelKind === "elevation"
|
||||
? await viewportLevelPlan(
|
||||
exportProject,
|
||||
activeLevelId,
|
||||
visibleCodes,
|
||||
detail,
|
||||
decision.scaleDenominator,
|
||||
true, // forPrint: `Drawing2D.noPrint`-Elemente ausschliessen
|
||||
planColorMode === "mono",
|
||||
)
|
||||
: generatePlan(
|
||||
exportProject,
|
||||
activeLevelId,
|
||||
visibleCodes,
|
||||
categoryDisplay,
|
||||
detail,
|
||||
referenceLines,
|
||||
planColorMode === "mono",
|
||||
true, // includeGlobal (Default)
|
||||
decision.scaleDenominator, // Export-Massstab (wie PDF): Strichstärken, Bemassung
|
||||
true, // forPrint: `Drawing2D.noPrint`-Elemente ausschliessen
|
||||
);
|
||||
if (plan.primitives.length === 0) {
|
||||
getState().notify(`${t("exportDxf.failed")}: ${t("exportDxf.empty")}`, "error");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await savePlanDxf(plan, exportProject, {
|
||||
title: activeLevelName,
|
||||
|
||||
@@ -201,6 +201,7 @@ export function AppDialogs(props: {
|
||||
{exportDxfOpen && (
|
||||
<ExportDxfDialog
|
||||
planTitle={activeLevel.name}
|
||||
levelKind={activeLevel.kind}
|
||||
initialScale={scaleDenominator}
|
||||
selectionCount={props.selectionCount}
|
||||
onExport={onExportDxf}
|
||||
|
||||
@@ -30,6 +30,8 @@ export interface ExportDxfDecision {
|
||||
export interface ExportDxfDialogProps {
|
||||
/** Titel/Geschossname (nur Anzeige im Dialogkopf). */
|
||||
planTitle: string;
|
||||
/** [200] Art der aktiven Ebene: Schnitt und Ansicht werden wie der Grundriss exportiert, nur anders beschriftet. */
|
||||
levelKind?: string;
|
||||
/** s. `ExportPdfDialogProps.selectionCount`. */
|
||||
selectionCount?: number;
|
||||
/** Massstab der aktiven Ansicht (Vorgabe, Default 1:100). */
|
||||
@@ -40,6 +42,7 @@ export interface ExportDxfDialogProps {
|
||||
|
||||
export function ExportDxfDialog({
|
||||
planTitle,
|
||||
levelKind,
|
||||
selectionCount = 0,
|
||||
initialScale = 100,
|
||||
onExport,
|
||||
@@ -93,7 +96,7 @@ export function ExportDxfDialog({
|
||||
|
||||
<div className="imp-body">
|
||||
<div className="imp-file">
|
||||
<span className="imp-file-label">{t("export.plan")}</span>
|
||||
<span className="imp-file-label">{levelKind === "section" ? t("export.section") : levelKind === "elevation" ? t("export.elevation") : t("export.plan")}</span>
|
||||
<span className="imp-file-name" title={planTitle}>
|
||||
{planTitle}
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user