// Schnellexport-Dialog (modal) für die Direkt-Formate CSV/IFC/OBJ/STL aus dem // Topbar-Export-Menü: Format wählen + Dateiname festlegen, dann speichern. // (PDF/DXF haben eigene Options-Dialoge.) Später bekommen „Ausschnitte" einen // vordefinierten Namen + Speicherort; dies ist der interaktive Schnellweg. // // Muster wie ExportDxfDialog: abgedunkeltes Overlay, Klick auf Hintergrund + Esc // schliessen. Rein gesteuert — meldet Format + Dateiname über `onSave` nach oben // (App führt Erzeugung + Download aus). Bezeichner englisch, UI deutsch (t()). import { useEffect, useState } from "react"; import { t } from "../i18n"; import { Dropdown } from "./Dropdown"; import type { IfcExportOptions, IfcSchema } from "../export/exportIfc"; /** Direkt-herunterladbare Exportformate (mit Datei-Endung). */ export type ExportSaveFormat = "csv" | "ifc" | "obj" | "stl" | "glb" | "step"; /** Datei-Endung je Format. */ export const EXPORT_FORMAT_EXT: Record = { csv: "csv", ifc: "ifc", obj: "obj", stl: "stl", glb: "glb", step: "stp", }; export interface ExportSaveDialogProps { /** Vorausgewähltes Format (aus dem angeklickten Menüeintrag). */ initialFormat: ExportSaveFormat; /** Basis-Dateiname OHNE Endung (i. d. R. Projektname). */ baseName: string; /** `ifc`: Klassifikations-Optionen (nur bei Format IFC gesetzt). */ onSave: (format: ExportSaveFormat, filename: string, ifc?: IfcExportOptions) => void; onClose: () => void; } /** Endung sicher an den Basisnamen hängen (doppelte Endung vermeiden). */ function withExt(base: string, ext: string): string { const trimmed = base.trim() || "modell"; const lower = trimmed.toLowerCase(); return lower.endsWith(`.${ext}`) ? trimmed : `${trimmed}.${ext}`; } export function ExportSaveDialog({ initialFormat, baseName, onSave, onClose, }: ExportSaveDialogProps) { useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); const [format, setFormat] = useState(initialFormat); // Der Dateiname wird OHNE Endung editiert; die Endung folgt aus dem Format. const [name, setName] = useState(baseName); const filename = withExt(name, EXPORT_FORMAT_EXT[format]); // IFC-Klassifikation (Schweizer Praxis): beides aus, bis die Nutzerin es wählt. const [ebkph, setEbkph] = useState(false); const [layerCodes, setLayerCodes] = useState(false); // IFC-Schema: IFC4 (Standard) oder IFC2x3 für ältere Fachplaner-Programme. const [schema, setSchema] = useState("IFC4"); const onConfirm = () => onSave(format, filename, format === "ifc" ? { schema, ebkph, layerCodes } : undefined); return (
e.stopPropagation()} >
{t("exportSave.title")}
{t("exportSave.format")}
setFormat(v as ExportSaveFormat)} title={t("exportSave.format")} options={[ { value: "csv", label: t("exportSave.fmt.csv") }, { value: "ifc", label: t("exportSave.fmt.ifc") }, { value: "obj", label: t("exportSave.fmt.obj") }, { value: "stl", label: t("exportSave.fmt.stl") }, { value: "glb", label: t("exportSave.fmt.glb") }, { value: "step", label: t("exportSave.fmt.step") }, ]} />
{format === "ifc" && (
{t("exportSave.ifc.schema")}
setSchema(v as IfcSchema)} title={t("exportSave.ifc.schema")} options={[ { value: "IFC4", label: t("exportSave.ifc.schema4") }, { value: "IFC2X3", label: t("exportSave.ifc.schema2x3") }, ]} />
{t("exportSave.ifc.schemaHint")}
{t("exportSave.ifc.ebkphHint")}
{t("exportSave.ifc.layersHint")}
{t("exportSave.ifc.zonesNote")}
)}
{t("exportSave.filename")}
setName(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") onConfirm(); }} placeholder="modell" />
{filename} · {t("exportSave.locationNote")}
); }