[K4] S4 Import: Aufrufer auf den Kern umgestellt, TS-Umwandlung gelöscht

DXF/DWG/PDF (Import-Dialog, CLI), IFC (Meshes/Bauteile) und Meshes laufen über ProjectDocument.importDrawing/
importIfc/importMesh (Store commitImport, ein Undo-Schritt). Dialoge halten nur Puffer + Zusammenfassung
(io/importSource.ts). Gelöscht: dxfToDrawings, pdfLineStyles, ifcElements, decodeImport/decodeIfc/decodeMesh,
ifcToImportedMeshes, meshObjectsToImportedMeshes, pdfPageToImport, buildDrawings, planImportLayers, Store
addDrawingLevel/importDrawings, Paritätstests. ensureContextCategories als Fassade über den Kern; CLI-PDF bekommt
wie die App Linienstile für Strichmuster. Tests über importView.testutil (Leseansicht des Kerns).
This commit is contained in:
Claude committed 2026-10-29 14:52:21 +00:00
1 parent 65e7f3a2ea
commit a5c3ea55f2
52 files changed
+880 -3010

No files matched your search

+8
View File
@@ -16,6 +16,7 @@ import {
TERRAIN_CATEGORY,
IMPORTED_ROOF_CATEGORY,
CONTEXT_PARENT_CATEGORY,
GENERIC_IMPORT_CATEGORY,
} from "./contextCategories";
import type { LayerCategory } from "./types";
@@ -107,4 +108,11 @@ describe("ensureContextCategories", () => {
const out = ensureContextCategories([], ["zz-unknown"]);
expect(out).toEqual([]);
});
it("Tabelle im Kern = Definitionen hier (alle Codes)", () => {
const nested = [TERRAIN_CATEGORY, IMAGE_CATEGORY, GENERIC_IMPORT_CATEGORY, ...Object.values(GEO_CATEGORY_DEFS)];
const cat = (c: { code: string; name: string; color: string; lw: number }) => ({ code: c.code, name: c.name, color: c.color, lw: c.lw, visible: true, locked: false });
const out = ensureContextCategories([], [...nested.map((c) => c.code), IMPORTED_ROOF_CATEGORY.code]);
expect(out).toEqual([{ ...cat(CONTEXT_PARENT_CATEGORY), children: nested.map(cat) }, cat(IMPORTED_ROOF_CATEGORY)]);
});
});
+12 -49
View File
@@ -23,6 +23,7 @@
import type { GeoCategory } from "../io/geoContext";
import { flattenCategories } from "./layers";
import { core } from "../engine/coreWasm";
import type { LayerCategory } from "./types";
/** Eine Kategorie-Definition (Code + Default-Name/Farbe/Strichstärke). */
@@ -102,65 +103,27 @@ export const GEO_CATEGORY_DEFS: Record<GeoCategory, ContextCategoryDef> = {
green: { code: "18", name: "Grünflächen", color: "#70b070", lw: 0.13 },
};
/** Kategorien, die als KINDER von {@link CONTEXT_PARENT_CATEGORY} gruppiert
* werden (alles ausser der Top-Level-Ausnahme „31 Dächer"). */
const NESTED_CONTEXT_CATEGORIES: ContextCategoryDef[] = [
TERRAIN_CATEGORY,
IMAGE_CATEGORY,
GENERIC_IMPORT_CATEGORY,
...Object.values(GEO_CATEGORY_DEFS),
];
const toLayerCategory = (c: ContextCategoryDef): LayerCategory => ({
code: c.code,
name: c.name,
color: c.color,
lw: c.lw,
visible: true,
locked: false,
});
/**
* Ergänzt `layers` um jede fehlende Kontext-Kategorie aus `codes` — bereits
* vorhandene Codes (auch vom Nutzer umbenannte, egal auf welcher Baumtiefe)
* bleiben unverändert, nur wirklich fehlende werden mit ihrem Default-Namen/
* -Farbe ergänzt. Fehlende {@link NESTED_CONTEXT_CATEGORIES} landen als
* KINDER von {@link CONTEXT_PARENT_CATEGORY} (legt „05 Kontext" bei Bedarf
* selbst an); die Top-Level-Ausnahme „31 Dächer" bleibt Top-Level (s.
* -Farbe ergänzt. Fehlende Kinder (alles ausser „31 Dächer") landen unter
* {@link CONTEXT_PARENT_CATEGORY} (legt „05 Kontext" bei Bedarf selbst an);
* die Top-Level-Ausnahme „31 Dächer" bleibt Top-Level (s.
* {@link IMPORTED_ROOF_CATEGORY}-Moduldoc). Reiner No-op, wenn nichts fehlt
* (liefert dieselbe Referenz zurück, spart eine unnötige `project`-Neuanlage).
* Rechnung im Kern (`core/src/import_context.rs`, auch für Importe; Tabelle der
* Kategorien dort, Gleichheit mit den Definitionen hier prüft `contextCategories.test.ts`).
*/
export function ensureContextCategories(
layers: LayerCategory[],
codes: Iterable<string>,
): LayerCategory[] {
const existing = new Set(flattenCategories(layers).map((c) => c.code));
const missing = new Set<string>();
for (const code of codes) {
if (!existing.has(code)) missing.add(code);
}
if (missing.size === 0) return layers;
const missingNested = NESTED_CONTEXT_CATEGORIES.filter((c) => missing.has(c.code)).map(
toLayerCategory,
);
const missingTopLevel = missing.has(IMPORTED_ROOF_CATEGORY.code)
? [toLayerCategory(IMPORTED_ROOF_CATEGORY)]
: [];
let out = layers;
if (missingNested.length > 0) {
const parentIdx = out.findIndex((l) => l.code === CONTEXT_PARENT_CATEGORY.code);
if (parentIdx >= 0) {
out = out.map((l, i) =>
i === parentIdx ? { ...l, children: [...(l.children ?? []), ...missingNested] } : l,
);
} else {
out = [...out, { ...toLayerCategory(CONTEXT_PARENT_CATEGORY), children: missingNested }];
}
}
if (missingTopLevel.length > 0) {
out = [...out, ...missingTopLevel];
}
return out;
const missing = [...codes].filter((c) => !existing.has(c));
if (missing.length === 0) return layers;
const out = core().layers_call("ensureContext", JSON.stringify(layers), JSON.stringify(missing), Date.now());
if (out === "") throw new Error("Kern: Kontext-Kategorien fehlgeschlagen");
const next = JSON.parse(out) as LayerCategory[] | null;
return next ?? layers;
}
-9
View File
@@ -11,7 +11,6 @@ import {
insertAfterCode,
nextFreeCode,
patchCategoryByCode,
planImportLayers,
recomputeFloorElevations,
removeCategoryByCode,
toggleCategoryByCode,
@@ -53,14 +52,6 @@ describe("Kategorie-Baum (Kern)", () => {
expect(nextFreeCode([])).toBe("01");
expect(nextFreeCode(tree())).toBe("102");
});
it("Import-Layer: bestehende Namen (case-insensitiv) behalten ihren Code", () => {
const r = planImportLayers(["wände", "Neu", "NEU"], tree(), { Neu: "#123" }, {});
expect(r.children).toHaveLength(1);
expect(r.children[0]).toMatchObject({ code: "102", name: "Neu", color: "#123", lw: 0.18 });
expect(r.parentCode).toBe("103");
expect([...r.codeByLayer]).toEqual([["wände", "20"], ["Neu", "102"], ["NEU", "102"]]);
});
});
describe("Geschoss-Stapelung (Kern)", () => {
-15
View File
@@ -100,21 +100,6 @@ export const insertAfterCode = (cats: LayerCategory[], code: string, clone: Laye
/** Entfernt die Kategorie mit `code` (samt Kindern) aus dem Baum. */
export const removeCategoryByCode = (cats: LayerCategory[], code: string): LayerCategory[] => call("remove", cats, code);
/** Neue Kategorien für Import-Layer ohne gleichnamige Kategorie (s. `planImportCategories`, `io/dxfToDrawings.ts`). */
export function planImportLayers(
layerNames: readonly string[],
existing: readonly LayerCategory[],
colors: Readonly<Record<string, string>>,
weights: Readonly<Record<string, number>>,
): { children: LayerCategory[]; parentCode: string; codeByLayer: Map<string, string> } {
const r = call<{ children: LayerCategory[]; parentCode: string; codeByLayer: [string, string][] }>("planImport", existing as LayerCategory[], {
names: layerNames,
colors,
weights,
});
return { children: r.children, parentCode: r.parentCode, codeByLayer: new Map(r.codeByLayer) };
}
/** Auswahl nach Elementart (ids je Art, wie `selectionLockMembers` in App.tsx). */
export interface SelectionMembers {
wallIds?: readonly string[];