diff --git a/src/App.tsx b/src/App.tsx index 9a58c0e8..1187c0b7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -51,6 +51,7 @@ import { LockConflictDialog } from "./ui/LockConflictDialog"; import { UnsavedChangesDialog } from "./ui/UnsavedChangesDialog"; import { Toast } from "./ui/Toast"; import { isTauriRuntime, PROJECT_TEMPLATE_EXT } from "./io/projectFile"; +import { stepTextToImportedMeshes } from "./io/stepImport"; import { checkForUpdate } from "./update/checkForUpdate"; import type { PlanViewHandle } from "./plan/PlanView"; import type { DisplayResolver } from "./viewport/Viewport3D"; @@ -539,6 +540,8 @@ export default function App() { // Der Klick auf „DXF importieren" triggert .click() dieses Inputs; onChange // liest die Datei als Text und reicht sie durch parseDxf → addContextObjects. const dxfInputRef = useRef(null); + // Verstecktes Datei-Input für den STEP-Import (Menü Datei, STEP importieren). + const stepInputRef = useRef(null); // Verstecktes Datei-Input für „Bild einfügen" (Werkzeug „image", s. tools.ts- // Kommentar) — akzeptiert auch PDF (jede Seite wird gerastert, s. pdfImport.ts); @@ -1824,6 +1827,7 @@ export default function App() { onExportIfc, onExportObj, onExportStl, + onExportStep, onOpenProject, openProjectAtPath, onProjectFileChosen, @@ -2377,6 +2381,8 @@ export default function App() { onExportIfc, onExportObj, onExportStl, + onExportStep, + onImportStep: () => stepInputRef.current?.click(), onUndo: undo, onRedo: redo, onDeleteSelection: deleteSelection, @@ -3209,6 +3215,25 @@ export default function App() { e.target.value = ""; }} /> + {/* Verstecktes STEP-Datei-Input (Menü Datei, STEP importieren). */} + { + const f = e.target.files?.[0]; + e.target.value = ""; + if (!f) return; + void f + .text() + .then((text) => stepTextToImportedMeshes(text, f.name)) + .then((objs) => addContextObjectsAndFit(objs)) + .catch((err) => + window.alert(`${t("step.import.failed")}: ${err instanceof Error ? err.message : String(err)}`), + ); + }} + /> {/* Verstecktes Bild/PDF-Datei-Input (Werkzeug „image"). */} = { "file.exportIfc": "Export IFC", "file.exportObj": "Export OBJ (3D mesh)", "file.exportStl": "Export STL (3D mesh)", + "exportSave.fmt.step": "STEP (B-rep, truck)", + "step.export.failed": "STEP export failed", + "step.export.skipped": "{n} solids could not be exported", + "step.import.failed": "STEP import failed", + "step.import.done": "STEP imported: {n} solids", + "menu.native.importStep": "Import STEP …", "file.export": "Export", "file.openFailed": "Could not read the project file.", diff --git a/src/io/stepImport.ts b/src/io/stepImport.ts new file mode 100644 index 00000000..aff3f8df --- /dev/null +++ b/src/io/stepImport.ts @@ -0,0 +1,24 @@ +// STEP-Import (ISO 10303-42 B-Rep) über truck-stepio: jede Shell der Datei wird zu einem +// tessellierten `ImportedMesh` des Kontexts (Kategorie „Import"), anwählbar wie jeder +// andere importierte Körper. Koordinaten bleiben unverändert (Meter, Z = Höhe). + +import { importStepMeshes } from "../engine/truckSolid"; +import { GENERIC_IMPORT_CATEGORY } from "../model/contextCategories"; +import type { ImportedMesh } from "../model/types"; + +let counter = 0; + +/** Liest STEP-Text → ein `ImportedMesh` je Körper. Wirft bei unlesbarer Datei. */ +export async function stepTextToImportedMeshes(text: string, fileName: string): Promise { + const base = fileName.replace(/\.[^.]+$/, "") || "STEP"; + const meshes = await importStepMeshes(text); + const stamp = Date.now().toString(36); + return meshes.map((m, i) => ({ + id: `imported-step-${stamp}-${counter++}`, + type: "importedMesh" as const, + name: meshes.length > 1 ? `${base} (${i + 1}/${meshes.length})` : base, + categoryCode: GENERIC_IMPORT_CATEGORY.code, + positions: m.positions, + indices: m.indices, + })); +} diff --git a/src/native/appMenu.ts b/src/native/appMenu.ts index 3a191d6d..e938bd32 100644 --- a/src/native/appMenu.ts +++ b/src/native/appMenu.ts @@ -32,6 +32,8 @@ export interface NativeAppMenuHandlers { onExportIfc: () => void; onExportObj: () => void; onExportStl: () => void; + onExportStep: () => void; + onImportStep: () => void; onUndo: () => void; onRedo: () => void; @@ -166,6 +168,10 @@ export function useNativeAppMenu( text: t("menu.native.import"), action: () => handlersRef.current.onImport(), }), + await MenuItem.new({ + text: t("menu.native.importStep"), + action: () => handlersRef.current.onImportStep(), + }), await Submenu.new({ text: t("menu.native.export"), items: [ @@ -193,6 +199,10 @@ export function useNativeAppMenu( text: "STL", action: () => handlersRef.current.onExportStl(), }), + await MenuItem.new({ + text: "STEP", + action: () => handlersRef.current.onExportStep(), + }), ], }), ], diff --git a/src/state/useProjectFileActions.ts b/src/state/useProjectFileActions.ts index f1e28272..f6848aae 100644 --- a/src/state/useProjectFileActions.ts +++ b/src/state/useProjectFileActions.ts @@ -17,6 +17,7 @@ import { distinctImportLayers, planImportCategories } from "../io/dxfToDrawings" import type { ImportDecision } from "../ui/ImportDialog"; import { exportScheduleCsv } from "../export/exportSchedule"; import { exportIfcSpf } from "../export/exportIfc"; +import { exportProjectStep } from "../export/exportStep"; import { exportObj, exportStl } from "../export/exportMesh"; import type { ExportSaveFormat } from "../ui/ExportSaveDialog"; import { saveTextFile } from "../io/saveFile"; @@ -442,6 +443,18 @@ export function useProjectFileActions( case "stl": downloadTextFile(exportStl(project), filename); break; + case "step": + // B-Rep via truck-WASM (asynchron): Körper, die truck nicht bauen kann, werden + // übersprungen — der Export bleibt trotzdem erhalten, Hinweis per Meldung. + void exportProjectStep(project, filename.replace(/\.[^.]+$/, "")) + .then((r) => { + downloadTextFile(r.text, filename); + if (r.skipped.length > 0) { + window.alert(t("step.export.skipped", { n: r.skipped.length })); + } + }) + .catch((e) => window.alert(`${t("step.export.failed")}: ${e instanceof Error ? e.message : String(e)}`)); + break; } }; // Schnellexport aus dem Topbar-Menü öffnet den Format-/Dateiname-Dialog @@ -450,6 +463,7 @@ export function useProjectFileActions( const onExportIfc = () => setExportSaveFormat("ifc"); const onExportObj = () => setExportSaveFormat("obj"); const onExportStl = () => setExportSaveFormat("stl"); + const onExportStep = () => setExportSaveFormat("step"); // Unter Tauri: nativer Öffnen-Dialog (echter Pfad → Lock möglich). Im // Browser: verstecktes wie bisher (kein echter Pfad, also // ohne Lock — File-API im Browser liefert keinen Dateisystempfad). @@ -570,6 +584,7 @@ export function useProjectFileActions( onExportIfc, onExportObj, onExportStl, + onExportStep, onOpenProject, onProjectFileChosen, runImport, diff --git a/src/ui/ExportSaveDialog.tsx b/src/ui/ExportSaveDialog.tsx index 33570d4e..dcfb9126 100644 --- a/src/ui/ExportSaveDialog.tsx +++ b/src/ui/ExportSaveDialog.tsx @@ -12,7 +12,7 @@ import { t } from "../i18n"; import { Dropdown } from "./Dropdown"; /** Direkt-herunterladbare Exportformate (mit Datei-Endung). */ -export type ExportSaveFormat = "csv" | "ifc" | "obj" | "stl"; +export type ExportSaveFormat = "csv" | "ifc" | "obj" | "stl" | "step"; /** Datei-Endung je Format. */ export const EXPORT_FORMAT_EXT: Record = { @@ -20,6 +20,7 @@ export const EXPORT_FORMAT_EXT: Record = { ifc: "ifc", obj: "obj", stl: "stl", + step: "stp", }; export interface ExportSaveDialogProps { @@ -87,6 +88,7 @@ export function ExportSaveDialog({ { value: "ifc", label: t("exportSave.fmt.ifc") }, { value: "obj", label: t("exportSave.fmt.obj") }, { value: "stl", label: t("exportSave.fmt.stl") }, + { value: "step", label: t("exportSave.fmt.step") }, ]} /> diff --git a/src/ui/TopBar.tsx b/src/ui/TopBar.tsx index fbf2ef89..1c95aca0 100644 --- a/src/ui/TopBar.tsx +++ b/src/ui/TopBar.tsx @@ -122,6 +122,7 @@ export interface TopBarProps { onExportIfc: () => void; onExportObj: () => void; onExportStl: () => void; + onExportStep?: () => void; // Kamera-Settings (FOV), ZUSÄTZLICH zur bestehenden im „Ansichten"-Ribbon- // Tab (ViewRibbonTab) und im 3D-Ribbon-Tab (Ribbon3dTab) — hier direkt neben