// DXF-/DWG-Export-Dialog (modal). Fragt Format (DXF/DWG) und „Schraffuren mitexportieren?" ab und weist auf // die Meter-Einheit hin (DXF ist Modell-Space in echten Metern, 1:1). Muster wie // ExportPdfDialog: abgedunkeltes Overlay, Klick auf den Hintergrund + Esc schliessen. // // Rein gesteuert: hält nur Formular-Zustand und meldet die Entscheidung über // `onExport` nach oben (App führt den Export aus, da es den Plan erzeugt). // Bezeichner englisch, UI-Text/Kommentare deutsch (CONVENTIONS.md). import { useEffect, useState } from "react"; import { t } from "../i18n"; import { useModalFocus } from "./modalFocus"; import { Dropdown } from "./Dropdown"; import type { CadExportFormat } from "../export/exportDxf"; import { SCALE_PRESETS } from "./TopBar"; /** Entscheidung, die der Dialog beim Bestätigen liefert. */ export interface ExportDxfDecision { /** 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`). */ selectionOnly: boolean; /** Massstabsnenner für Bemassungsstil, Strichmuster, Raumstempel und Ansichtsfenster. */ scaleDenominator: number; /** Einheit der Masszahlen. */ dimUnit: "m" | "cm"; /** Zusätzlich ein Layout (Papierbereich) mit Ansichtsfenster anlegen. */ paperLayout: boolean; } 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). */ initialScale?: number; onExport: (decision: ExportDxfDecision) => void; onClose: () => void; } export function ExportDxfDialog({ planTitle, levelKind, selectionCount = 0, initialScale = 100, onExport, onClose, }: ExportDxfDialogProps) { const dialogRef = useModalFocus({}); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); const [format, setFormat] = useState("dxf"); const [includeHatches, setIncludeHatches] = useState(true); const [selectionOnly, setSelectionOnly] = useState(false); const [scale, setScale] = useState(initialScale); const [dimUnit, setDimUnit] = useState<"m" | "cm">("m"); const [paperLayout, setPaperLayout] = useState(false); const scaleOptions = [ ...(SCALE_PRESETS.includes(scale) ? [] : [{ value: String(scale), label: `1:${scale}` }]), ...SCALE_PRESETS.filter((n) => n > 1).map((n) => ({ value: String(n), label: `1:${n}` })), ]; const onConfirm = () => onExport({ format, includeHatches, selectionOnly: selectionCount > 0 && selectionOnly, scaleDenominator: scale, dimUnit, paperLayout, }); return (
e.stopPropagation()} >
{t("exportDxf.title")}
{levelKind === "section" ? t("export.section") : levelKind === "elevation" ? t("export.elevation") : t("export.plan")} {planTitle}
{t("exportDxf.format")}
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") }, ]} />
{t("exportDxf.hatches")}
setIncludeHatches(v === "yes")} title={t("exportDxf.hatches")} options={[ { value: "yes", label: t("exportDxf.hatches.yes") }, { value: "no", label: t("exportDxf.hatches.no") }, ]} />
{t("exportDxf.scale")}
setScale(Number(v))} title={t("exportDxf.scale")} options={scaleOptions} />
{t("exportDxf.dimUnit")}
setDimUnit(v === "cm" ? "cm" : "m")} title={t("exportDxf.dimUnit")} options={[ { value: "m", label: t("exportDxf.dimUnit.m") }, { value: "cm", label: t("exportDxf.dimUnit.cm") }, ]} />
{t("exportDxf.layout")}
setPaperLayout(v === "yes")} title={t("exportDxf.layout")} options={[ { value: "no", label: t("exportDxf.layout.no") }, { value: "yes", label: t("exportDxf.layout.yes") }, ]} />
{t("exportDxf.unitsNote")}
{t("exportDxf.objectsNote")}
{selectionCount > 0 && (
)}
); }