Files
DOSSIER/src/state/siteSelection.test.ts
T
Claude cb9d8c3b0f [181] [152] Importe als eigenständige Elemente: Klasse Pflicht, Herkunft nur Auskunft, keine Import-Liste
Gelände, Höhenlinien, Netzkörper (Nachbargebäude, IFC/OBJ/STEP/DXF-Netze), Luftbilder und Baugruben
(`Project.context`) sind normale Elemente:
- Modell: `categoryCode` Pflicht (String) an allen fünf Arten; `layer` (Gruppierung) und `hidden`
  (Einzel-Ausblenden) entfallen; neu `source` (Herkunft, ohne Wirkung). `ContextObject::category_code()`.
- Kern: Plan, Schnitt, Ansicht, 3D, Pick fragen nur die Klasse ab (kein „ohne Kategorie immer sichtbar").
  IFC-Gelände (IfcSite bzw. Name Gelände/Terrain) wird beim Import ein Gelände-Element
  (`import_context::ifc_meshes`); `mesh_view::is_terrain` entfällt, geschlossene Gelände-Netze schneidet
  der Schnitt als Oberkante. Importe setzen `source` statt `layer` (IFC-Klasse, DXF-Layer, STEP-Datei).
- Objekt-Info: Klasse im Kopf änderbar und Farbe der Klasse auch für Gelände-/Umgebungs-Elemente,
  Herkunft als Auskunft; Einzel-Ausblenden-Schalter entfernt.
- Panel „Gelände": Import-Liste entfernt (nur Aktionen); Elemente-Panel mit Knoten „Gelände & Umgebung".
- swissBUILDINGS3D/OSM/swissALTI3D/SWISSIMAGE setzen Klasse und `source`; Dach-Trennung über den DXF-Layer
  beim Import.
- Musterhaus komplex nachgeführt (ohne `layer`); Doku: ARCHITEKTUR Abschnitt 8 (Entwurf), Glossar, READMEs.

Geprüft: cargo test im Kern (bis auf den Zeit-Wächter ansicht_gross_schnell unter Last), vitest (alle),
tsc, Plan-/CLI-Goldens unverändert, e2e siteSelect/excavation/terrainHide angepasst und grün.
Musterhaus komplex mit zwei Nachbarnetzen: Grundriss EG/UG 1:200, Schnitt A-A, Ansicht Süd per CLI
vor/nach byte-gleich (angesehen). Nicht in der Tauri-App/auf dem Mac geprüft.
2026-11-11 04:00:16 +00:00

111 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// [137] Alles Sichtbare anwählbar (Musterhaus komplex): Klick im Grundriss auf Baugrube, Gelände,
// Schatten und Baurechtslinien; Objekt-Info der Baugrube; Gelände neu glätten mit Undo.
import { beforeAll, describe, expect, it } from "vitest";
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
import { collectVisibleCodes } from "../model/layers";
import { generatePlan } from "../plan/generatePlan";
import { PlanPickIndex } from "../plan/planView/planPick";
import { planPrimAt } from "../plan/planLazy";
import { deriveSelection } from "./selectionInfo";
import { getState, setState } from "./appStore";
import type { Project, TerrainMesh } from "../model/types";
let p: Project;
let terrainId: string;
beforeAll(() => {
p = buildComplexSampleProject();
terrainId = p.context!.find((c) => c.type === "terrainMesh")!.id;
});
/** Pick-Ids (Feld `contextObjectId`) unter (x, y) im EG 1:500, oberste zuerst — wie `PlanView.contextIdsAt`. */
const idsAt = (proj: Project, pts: [number, number][]): string[][] => {
const plan = generatePlan(proj, "eg", collectVisibleCodes(proj.layers), undefined, "mittel", false, false, true, 500);
const ix = new PlanPickIndex(plan);
const out = pts.map(([x, y]) => ix.polygonsAt({ x, y }, "contextObjectId").map((i) => (planPrimAt(plan, i) as { contextObjectId?: string }).contextObjectId!));
ix.release();
return out;
};
/** Erstes Kontext-Objekt (ohne Lage-Darstellung `@…`). */
const contextAt = (proj: Project, x: number, y: number): string | null => idsAt(proj, [[x, y]])[0].find((id) => !id.startsWith("@")) ?? null;
describe("[137] Grundriss: Kontext anwählen", () => {
it("Baugrube (Sohle und Böschung) vor dem Gelände, daneben das Gelände", () => {
expect(contextAt(p, 8, -0.5)).toBe("baugrube");
// Südwest-Böschung: ausserhalb der Sohle (Arbeitsraum 0.8 m um −0.36), noch im Wirkbereich.
expect(contextAt(p, -1.6, 4)).toBe("baugrube");
expect(contextAt(p, 25, -10)).toBe(terrainId);
});
it("Objekt-Info der Baugrube: Kontext-Objekt der Art Baugrube", () => {
const sel = deriveSelection(p, { contextObjects: ["baugrube"] });
expect(sel?.kind).toBe("contextObject");
expect(sel?.contextObject?.objType).toBe("excavation");
});
});
describe("[137] Schatten und Baurecht anwählen", () => {
it("Parzellengrenze → Baurecht, Schattenfläche → Sonnenstand (Pick-Ids im Plan)", () => {
// Westgrenze der Parzelle von (−14, −12) nach (−15, 24): bei y = 6 liegt sie auf x = −14.5.
const grid: [number, number][] = [];
for (let y = 22; y >= -4; y -= 1) for (let x = -10; x <= 26; x += 1) grid.push([x, y]);
const [parcel, far, ...rest] = idsAt(p, [[-14.5, 6], [-40, -40], ...grid]);
expect(parcel).toContain("@siteRules");
expect(far).toEqual([]);
// Schatten (21. Juni, 10 Uhr): irgendwo neben dem Haus.
expect(rest.some((ids) => ids.includes("@sunStudy"))).toBe(true);
// Studie aus: keine Schatten-Ids mehr.
const off = idsAt({ ...p, sunStudy: { ...p.sunStudy!, show: false } }, grid);
expect(off.some((ids) => ids.includes("@sunStudy"))).toBe(false);
});
});
describe("[137] Gelände neu glätten", () => {
it("andere Stufe ersetzt das Netz (gleiche Id), Undo stellt es wieder her", () => {
const terrain = () => getState().project.context!.find((c) => c.id === terrainId) as TerrainMesh;
setState({ project: p, undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false });
getState().clearHistory();
const before = terrain();
expect(before.smooth).toBe(2);
expect(before.sourceId).toBe("hoehenlinien");
expect(getState().regenerateTerrain(terrainId, 0)).toBe(true);
const raw = terrain();
expect(raw.smooth).toBe(0);
expect(raw.indices.length).toBeLessThan(before.indices.length);
expect(raw.contourInterval).toBe(before.contourInterval);
getState().undo();
expect(terrain().indices.length).toBe(before.indices.length);
expect(terrain().smooth).toBe(2);
});
});
describe("[137] Raster-Gelände (swissALTI3D) nachglätten", () => {
it("additive Durchgänge, nur z ändert sich, Undo; TIN aus Höhenlinien wird abgelehnt", () => {
const positions: number[] = [];
for (let j = 0; j < 6; j++) for (let i = 0; i < 6; i++) positions.push(i * 2, j * 2, i === 3 && j === 3 ? 10 : 0);
const indices: number[] = [];
for (let j = 0; j < 5; j++)
for (let i = 0; i < 5; i++) {
const a = j * 6 + i;
indices.push(a, a + 1, a + 7, a, a + 7, a + 6);
}
const grid: TerrainMesh = { id: "alti", type: "terrainMesh", categoryCode: "02", name: "swissALTI3D", positions, indices, smooth: 1 };
setState({ project: { ...p, context: [grid] }, undoDepth: 0, redoDepth: 0, canUndo: false, canRedo: false });
getState().clearHistory();
const cur = () => getState().project.context!.find((c) => c.id === "alti") as TerrainMesh;
expect(getState().resmoothTerrain("alti", 2)).toBe(true);
expect(cur().smooth).toBe(3);
const peak = cur().positions[(3 * 6 + 3) * 3 + 2];
expect(peak).toBeLessThan(10);
expect(peak).toBeGreaterThan(0);
expect(cur().positions.filter((_, k) => k % 3 !== 2)).toEqual(positions.filter((_, k) => k % 3 !== 2));
expect(cur().indices).toEqual(indices);
getState().undo();
expect(cur().positions).toEqual(positions);
expect(cur().smooth).toBe(1);
// Musterhaus-Gelände (TIN aus Höhenlinien) ist kein Raster.
setState({ project: p });
expect(getState().resmoothTerrain(terrainId, 1)).toBe(false);
});
});