[C2] Import-Dialog: Fehlermeldung, "teilweise gelesen", Papierbereich-Layouts wählbar
Rust-Fehlermeldungen erscheinen im Dialog statt "keine Geometrie gefunden"; Layouts mit Inhalt werden aufgelistet und lassen sich statt des Modellraums laden (Datei bleibt im Speicher, kein erneutes Wählen). Texte de + en. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
6 files changed
+86
-2
No files matched your search
@@ -1847,6 +1847,7 @@ export default function App() {
|
||||
pendingDiscard,
|
||||
setPendingDiscard,
|
||||
openImportForFile,
|
||||
loadImportLayout,
|
||||
onSaveProject,
|
||||
onNewProject,
|
||||
onNewProjectFromSample,
|
||||
@@ -3904,6 +3905,8 @@ export default function App() {
|
||||
isDwg={importState.isDwg}
|
||||
loading={importState.loading ?? false}
|
||||
progress={importState.progress}
|
||||
error={importState.error}
|
||||
onSelectLayout={loadImportLayout}
|
||||
parsed={importState.parsed}
|
||||
project={project}
|
||||
activeCategoryCode={activeCategoryCode}
|
||||
|
||||
@@ -1622,6 +1622,11 @@ export const de = {
|
||||
"import.summary.layers": "Layer: {layers}",
|
||||
"import.summary.noLayers": "keine Layer-Namen",
|
||||
"import.summary.empty": "Keine importierbare 2D-Geometrie gefunden.",
|
||||
"import.summary.recovered": "Die Datei ist beschädigt oder abgeschnitten und wurde nur teilweise gelesen.",
|
||||
"import.layouts.heading": "Papierbereich (Layouts)",
|
||||
"import.layouts.model": "Modellraum (Zeichnung)",
|
||||
"import.layouts.entities": "{n} Objekte",
|
||||
"import.layouts.note": "Ein Layout bringt Plankopf, Linien und Texte des Papierbereichs; die Modellansichten (Ansichtsfenster) fehlen.",
|
||||
"import.target.heading": "Ziel-Zeichnungsebene",
|
||||
"import.target.existing": "In bestehende Zeichnungsebene importieren",
|
||||
"import.target.new": "Neue Zeichnung anlegen",
|
||||
|
||||
@@ -1609,6 +1609,11 @@ export const en: Record<TranslationKey, string> = {
|
||||
"import.summary.meshes": "{n} meshes",
|
||||
"import.summary.layers": "Layers: {layers}",
|
||||
"import.summary.noLayers": "no layer names",
|
||||
"import.summary.recovered": "The file is damaged or truncated and was only partly read.",
|
||||
"import.layouts.heading": "Paper space (layouts)",
|
||||
"import.layouts.model": "Model space (drawing)",
|
||||
"import.layouts.entities": "{n} objects",
|
||||
"import.layouts.note": "A layout brings the title block, lines and texts of the paper space; the model views (viewports) are missing.",
|
||||
"import.summary.empty": "No importable 2D geometry found.",
|
||||
"import.target.heading": "Target drawing level",
|
||||
"import.target.existing": "Import into existing drawing level",
|
||||
|
||||
@@ -42,6 +42,8 @@ export function useDialogState() {
|
||||
loading?: boolean;
|
||||
// Grober Phasenname während `loading` (nur DXF), s. ImportDialog.tsx.
|
||||
progress?: string;
|
||||
// Fehlermeldung des Format-Moduls (Datei leer/beschädigt/kein DXF).
|
||||
error?: string;
|
||||
} | null>(null);
|
||||
// Modaler PDF-Export-Dialog (Grundriss → Vektor-PDF). true = offen.
|
||||
const [exportOpen, setExportOpen] = useState(false);
|
||||
|
||||
@@ -126,8 +126,13 @@ export type ImportDialogState = {
|
||||
/** Grober Phasenname während `loading` (DXF via `parseDxfAsync`'s
|
||||
* `onProgress`) — rein informativ, s. `ImportDialog.tsx`. */
|
||||
progress?: string;
|
||||
/** Fehlermeldung des Format-Moduls (Datei leer, beschädigt, kein DXF/DWG …); `null`/fehlend = kein Fehler. */
|
||||
error?: string;
|
||||
} | null;
|
||||
|
||||
/** Meldung eines abgefangenen Fehlers (Rust-Fehler kommen als String, Worker-Fehler als Error). */
|
||||
const errorText = (err: unknown): string => (err instanceof Error ? err.message : String(err));
|
||||
|
||||
|
||||
/**
|
||||
* Liest Projekt-Text über den gemeinsamen Format-Parser (Version, Migration, Toleranz) und
|
||||
@@ -249,8 +254,32 @@ export function useProjectFileActions(
|
||||
// und DWG werden als Bytes im Web-Worker über das Rust-Format-Modul gelesen (lazy,
|
||||
// asynchron); beide münden in dasselbe {meshes, contours}-Format und denselben Dialog.
|
||||
// Parse-Fehler werden ruhig abgefangen: DWG fällt auf den ODA-Hinweis zurück.
|
||||
// Rohdaten der zuletzt geöffneten Import-Datei: der Dialog kann damit ein Papierbereich-Layout
|
||||
// statt des Modellraums nachladen (`loadImportLayout`), ohne die Datei erneut zu wählen.
|
||||
const importSourceRef = useRef<{ fileName: string; buf: ArrayBuffer } | null>(null);
|
||||
|
||||
/** Liest `layout` (Papierbereich) oder, bei `null`, den Modellraum der geöffneten Import-Datei neu. */
|
||||
const loadImportLayout = (layout: string | null) => {
|
||||
const src = importSourceRef.current;
|
||||
if (!src) return;
|
||||
setImportState({ fileName: src.fileName, isDwg: false, parsed: null, loading: true });
|
||||
parseDxfAsync(src.buf, undefined, layout ?? undefined)
|
||||
.then((parsed) => setImportState({ fileName: src.fileName, isDwg: false, parsed, loading: false }))
|
||||
.catch((err) => {
|
||||
console.error("Layout-Import fehlgeschlagen:", err);
|
||||
setImportState({
|
||||
fileName: src.fileName,
|
||||
isDwg: false,
|
||||
parsed: { meshes: [], contours: [] },
|
||||
loading: false,
|
||||
error: errorText(err),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const openImportForFile = (file: File) => {
|
||||
const isDwg = /\.dwg$/i.test(file.name);
|
||||
importSourceRef.current = null;
|
||||
if (isDwg) {
|
||||
// Async-Zustand: Dialog öffnet sofort und zeigt „DWG wird gelesen …",
|
||||
// während WASM lädt/parst. Danach echte Zusammenfassung ODER ODA-Hinweis.
|
||||
@@ -272,6 +301,7 @@ export function useProjectFileActions(
|
||||
});
|
||||
return;
|
||||
}
|
||||
importSourceRef.current = { fileName: file.name, buf };
|
||||
// Dynamisch importieren (das Format-Modul wird ohnehin erst im Worker geladen).
|
||||
import("../io/dwgParser")
|
||||
.then(({ parseDwg }) => parseDwg(buf))
|
||||
@@ -291,6 +321,7 @@ export function useProjectFileActions(
|
||||
isDwg: true,
|
||||
parsed: null,
|
||||
loading: false,
|
||||
error: errorText(err),
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -307,6 +338,7 @@ export function useProjectFileActions(
|
||||
r.onload = () => {
|
||||
// Bytes statt Text: Binär-DXF und Code-Seiten (vor R2007) liest erst Rust richtig.
|
||||
const buf = r.result instanceof ArrayBuffer ? r.result : new ArrayBuffer(0);
|
||||
importSourceRef.current = { fileName: file.name, buf };
|
||||
parseDxfAsync(buf, (progress) => {
|
||||
setImportState({ fileName: file.name, isDwg: false, parsed: null, loading: true, progress });
|
||||
})
|
||||
@@ -316,7 +348,7 @@ export function useProjectFileActions(
|
||||
.catch((err) => {
|
||||
console.error("DXF-Import fehlgeschlagen:", err);
|
||||
const parsed: DxfImportResult = { meshes: [], contours: [] };
|
||||
setImportState({ fileName: file.name, isDwg: false, parsed, loading: false });
|
||||
setImportState({ fileName: file.name, isDwg: false, parsed, loading: false, error: errorText(err) });
|
||||
});
|
||||
};
|
||||
r.readAsArrayBuffer(file);
|
||||
@@ -641,6 +673,7 @@ export function useProjectFileActions(
|
||||
pendingDiscard,
|
||||
setPendingDiscard,
|
||||
openImportForFile,
|
||||
loadImportLayout,
|
||||
onSaveProject,
|
||||
onNewProject,
|
||||
onNewProjectFromSample,
|
||||
|
||||
+37
-1
@@ -106,6 +106,10 @@ export interface ImportDialogProps {
|
||||
* `onProgress`) — `"structure"`, `"parse-single"` oder
|
||||
* `"parse-parallel:<N>"`; `undefined` = noch keine Phase bekannt/DWG. */
|
||||
progress?: string;
|
||||
/** Meldung des Format-Moduls, wenn die Datei nicht gelesen werden konnte (leer, beschädigt …). */
|
||||
error?: string;
|
||||
/** Wählt ein Papierbereich-Layout (Name) oder den Modellraum (`null`) zum Import; liest neu. */
|
||||
onSelectLayout?: (layout: string | null) => void;
|
||||
/** Geparstes Ergebnis (null während Laden / bei DWG-Parse-Fehler). */
|
||||
parsed: DxfImportResult | null;
|
||||
project: Project;
|
||||
@@ -119,6 +123,8 @@ export function ImportDialog({
|
||||
isDwg,
|
||||
loading = false,
|
||||
progress,
|
||||
error,
|
||||
onSelectLayout,
|
||||
parsed,
|
||||
project,
|
||||
activeCategoryCode,
|
||||
@@ -245,6 +251,7 @@ export function ImportDialog({
|
||||
// DWG konnte nicht gelesen werden → ODA-Fallback-Hinweis.
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("import.dwg.heading")}</div>
|
||||
{error && <div className="imp-warn">{error}</div>}
|
||||
<div className="imp-dwg-hint">{t("import.dwg.hint")}</div>
|
||||
</section>
|
||||
) : (
|
||||
@@ -266,9 +273,10 @@ export function ImportDialog({
|
||||
: t("import.summary.noLayers")}
|
||||
</li>
|
||||
</ul>
|
||||
{parsed?.recovered && <div className="imp-warn">{t("import.summary.recovered")}</div>}
|
||||
{!hasDrawings && !hasMeshes && (
|
||||
<div className="imp-warn">
|
||||
{t("import.summary.empty")}
|
||||
{error ?? t("import.summary.empty")}
|
||||
{/* Diagnose-Histogramm (vom DWG-Parser): macht sichtbar,
|
||||
WORAN es liegt — 0 Entities (Encoding/Version) vs.
|
||||
Abdeckungslücke (z. B. „500 ARC, 200 INSERT"). Entity-Typ-
|
||||
@@ -283,6 +291,34 @@ export function ImportDialog({
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Papierbereich: Layouts der Datei (Bericht) und, wenn möglich, eines statt des Modellraums lesen. */}
|
||||
{parsed?.layouts && parsed.layouts.length > 0 && (
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("import.layouts.heading")}</div>
|
||||
{onSelectLayout ? (
|
||||
<Dropdown
|
||||
value={parsed.layout ?? ""}
|
||||
onChange={(v) => onSelectLayout(v === "" ? null : v)}
|
||||
title={t("import.layouts.heading")}
|
||||
options={[
|
||||
{ value: "", label: t("import.layouts.model") },
|
||||
...parsed.layouts.map((l) => ({
|
||||
value: l.name,
|
||||
label: `${l.name} · ${t("import.layouts.entities", { n: l.entities })}`,
|
||||
})),
|
||||
]}
|
||||
/>
|
||||
) : (
|
||||
<ul className="imp-summary">
|
||||
{parsed.layouts.map((l) => (
|
||||
<li key={l.name}>{`${l.name} · ${t("import.layouts.entities", { n: l.entities })}`}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<div className="imp-dwg-hint">{t("import.layouts.note")}</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Ziel-Zeichnungsebene. */}
|
||||
{hasDrawings && (
|
||||
<section className="imp-section">
|
||||
|
||||
Reference in new issue
Block a user