From 45b4e4d080be70fdb0e0185b1002f8cd23a73dc5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 23:22:23 +0000 Subject: [PATCH] =?UTF-8?q?[143]=20Baugrube:=20Sohle=20aus=20drawingLevels?= =?UTF-8?q?=20(las=20nicht=20vorhandene=20floors,=20immer=20=E2=88=920.30)?= =?UTF-8?q?,=20Hinweise=20statt=20stillem=20Scheitern=20(ohne=20Gel=C3=A4n?= =?UTF-8?q?de,=20ausserhalb,=20nur=20Aufsch=C3=BCttung,=20kein=20Geschoss)?= =?UTF-8?q?,=20Gel=C3=A4nde-Befehl=20sofort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/core/src/cmd_solid.rs | 38 ++++++++++++++++------------ src/commands/cmds/excavation.ts | 41 +++++++++++++++++++++++++++++-- src/commands/cmds/terrain.ts | 10 ++++++++ src/commands/engine.ts | 14 +++++++++-- src/commands/types.ts | 17 +++++++++++++ src/i18n/de.ts | 8 ++++++ src/i18n/en.ts | 8 ++++++ src/state/useCommandEngineHost.ts | 2 +- 8 files changed, 117 insertions(+), 21 deletions(-) diff --git a/src-tauri/core/src/cmd_solid.rs b/src-tauri/core/src/cmd_solid.rs index c8fad215..56f6705c 100644 --- a/src-tauri/core/src/cmd_solid.rs +++ b/src-tauri/core/src/cmd_solid.rs @@ -521,13 +521,19 @@ pub struct ExCheck { pub datum: Option, } -fn excavation_check(root: &Map, p: &Project, pts: &[V], level: &str) -> ExCheck { +fn excavation_check(p: &Project, pts: &[V], level: &str) -> ExCheck { use crate::terrain::{datum, Tin, TinIndex}; // Sohle unter dem TIEFSTEN Geschoss: im EG gezeichnet lag sie sonst auf −0.30 m, am Hang über dem - // Gelände → nur Aufschüttung statt Grube. - let floors = arr(root.get("floors")); - let active = floors.iter().find(|f| field(f, "id").and_then(Value::as_str) == Some(level)).map_or(0.0, |f| num_or(field(f, "baseElevation"), 0.0)); - let base = floors.iter().map(|f| num_or(field(f, "baseElevation"), 0.0)).filter(|z| z.is_finite()).fold(active, f64::min); + // Gelände → nur Aufschüttung statt Grube. (Vorher las der Befehl eine Liste `floors`, die es im + // Projekt nicht gibt — Geschosse sind `drawingLevels` —, die Sohle lag darum IMMER auf −0.30 m.) + use crate::model::DrawingLevelKind; + let base = p + .drawing_levels + .iter() + .filter(|l| l.kind == DrawingLevelKind::Floor || l.id == level) + .filter_map(|l| l.base_elevation.filter(|z| z.is_finite())) + .fold(f64::INFINITY, f64::min); + let base = if base.is_finite() { base } else { 0.0 }; let bottom = base - 0.3; let terrains = crate::excavation::terrains(p); let mut out = ExCheck { bottom, terrain: !terrains.is_empty(), over: false, cut: false, datum: None }; @@ -588,7 +594,7 @@ fn excavation_ops(root: &Map, p: &Project, v: &Value, ctx: &Ctx, if pts.is_empty() { return Vec::new(); } - let check = excavation_check(root, p, &pts, ctx.level); + let check = excavation_check(p, &pts, ctx.level); let n = arr(root.get("context")).iter().filter(|o| field(o, "type").and_then(Value::as_str) == Some("excavation")).count(); let mut out = Vec::new(); if let Some(d) = check.datum { @@ -923,7 +929,7 @@ pub fn query(root: &Map, p: &Project, v: &Value) -> Option // [143] Baugrube vor dem Anlegen prüfen (Meldungen im Befehl). "excavationCheck" => { let pts = excavation_outline(v); - let c = excavation_check(root, p, &pts, s_of(v, "level")); + let c = excavation_check(p, &pts, s_of(v, "level")); json!({ "valid": !pts.is_empty(), "bottom": js_num(c.bottom), "terrain": c.terrain, "over": c.over, "cut": c.cut, "datum": c.datum.map(js_num) }) } _ => return None, @@ -1008,7 +1014,7 @@ mod tests { /// [68] Baugrube: Umriss (2 Punkte = Rechteck), Sohle = Geschoss − 0.30, als Kontext-Objekt. #[test] fn baugrube_befehl() { - let root = json!({"floors": [{"id": "ug", "baseElevation": -3.0}]}); + let root = json!({"drawingLevels": [{"id": "ug", "name": "UG", "kind": "floor", "visible": true, "locked": false, "baseElevation": -3.0}]}); let root = root.as_object().unwrap(); let run = |pts: Value| { let mut ids = IdGen::new("s"); @@ -1026,7 +1032,7 @@ mod tests { /// [143] Im EG gezeichnet: Sohle unter dem tiefsten Geschoss (UG), nicht −0.30 unter dem EG. #[test] fn baugrube_sohle_unter_tiefstem_geschoss() { - let root = json!({"floors": [{"id": "eg", "baseElevation": 0.0}, {"id": "ug", "baseElevation": -2.7}, {"id": "og", "baseElevation": 2.9}]}); + let root = json!({"drawingLevels": json!([{"id": "eg", "name": "EG", "kind": "floor", "visible": true, "locked": false, "baseElevation": 0.0}, {"id": "ug", "name": "UG", "kind": "floor", "visible": true, "locked": false, "baseElevation": -2.7}, {"id": "og", "name": "OG", "kind": "floor", "visible": true, "locked": false, "baseElevation": 2.9}])}); let root = root.as_object().unwrap(); let run = |level: &str| { let mut ids = IdGen::new("s"); @@ -1057,21 +1063,21 @@ mod tests { let r = root.as_object().unwrap(); query(r, &crate::model::lenient::typed_for_test(r), &json!({"q": "excavationCheck", "pts": pts, "level": "eg"})).unwrap() }; - let floors = json!([{"id": "eg", "baseElevation": 0.0}, {"id": "ug", "baseElevation": -2.7}]); + let floors = json!([{"id": "eg", "name": "EG", "kind": "floor", "visible": true, "locked": false, "baseElevation": 0.0}, {"id": "ug", "name": "UG", "kind": "floor", "visible": true, "locked": false, "baseElevation": -2.7}, {"id": "og", "name": "OG", "kind": "floor", "visible": true, "locked": false, "baseElevation": 2.9}]); // Kein Gelände. - let c = check(&json!({"floors": floors}), &rect); + let c = check(&json!({"drawingLevels": floors}), &rect); assert_eq!((c["valid"].as_bool(), c["terrain"].as_bool(), c["over"].as_bool(), c["bottom"].as_f64()), (Some(true), Some(false), Some(false), Some(-3.0))); // Gelände um ±0.00: Grube, kein neuer Bezug. - let c = check(&json!({"floors": floors, "context": [tri(0.0)]}), &rect); + let c = check(&json!({"drawingLevels": floors, "context": [tri(0.0)]}), &rect); assert_eq!((c["over"].as_bool(), c["cut"].as_bool(), c["datum"].is_null()), (Some(true), Some(true), true)); // Ausserhalb des Geländes. - let c = check(&json!({"floors": floors, "context": [tri(0.0)]}), &json!([{"x": 100, "y": 100}, {"x": 110, "y": 108}])); + let c = check(&json!({"drawingLevels": floors, "context": [tri(0.0)]}), &json!([{"x": 100, "y": 100}, {"x": 110, "y": 108}])); assert_eq!((c["terrain"].as_bool(), c["over"].as_bool()), (Some(true), Some(false))); // Gelände tief unter der Sohle: nur Aufschüttung. - let c = check(&json!({"floors": floors, "context": [tri(-10.0)]}), &rect); + let c = check(&json!({"drawingLevels": floors, "context": [tri(-10.0)]}), &rect); assert_eq!((c["over"].as_bool(), c["cut"].as_bool()), (Some(true), Some(false))); // Gelände in m ü. M., kein Bezug: ±0.00 = Höhe im Schwerpunkt (512 + 4·14/40 = 513.40). - let root = json!({"floors": floors, "context": [tri(512.0)]}); + let root = json!({"drawingLevels": floors, "context": [tri(512.0)]}); let c = check(&root, &rect); assert_eq!((c["cut"].as_bool(), c["datum"].as_f64()), (Some(true), Some(513.4))); let r = root.as_object().unwrap(); @@ -1087,7 +1093,7 @@ mod tests { let o2 = ops(r2, &crate::model::lenient::typed_for_test(r2), &json!({"cmd": "excavation", "pts": rect}), &ctx, &mut ids).unwrap(); assert_eq!(o2.len(), 1); // Mit gesetztem Bezug: kein neuer. - let c = check(&json!({"floors": floors, "referenceElevationMasl": 512.5, "context": [tri(512.0)]}), &rect); + let c = check(&json!({"drawingLevels": floors, "referenceElevationMasl": 512.5, "context": [tri(512.0)]}), &rect); assert!(c["datum"].is_null()); assert_eq!(c["cut"].as_bool(), Some(true)); } diff --git a/src/commands/cmds/excavation.ts b/src/commands/cmds/excavation.ts index 9460fbc1..13ddb017 100644 --- a/src/commands/cmds/excavation.ts +++ b/src/commands/cmds/excavation.ts @@ -7,8 +7,12 @@ // 2) „Nächster Punkt …" → Punkt … Schliessen per Klick auf den Startpunkt, Option „Schliessen" oder // Enter (≥ 3 Punkte; bei genau 2 Punkten: Rechteck aus den Ecken). +// +// [143] Meldungen statt stillem Scheitern: ohne Gelände startet der Befehl nicht; ausserhalb des Geländes +// oder entartet entsteht nichts (Hinweis); sonst Hinweis mit Sohle (und neuem Höhenbezug ±0.00, s. Kern). + import type { Command, CommandContext, CommandResult, CommandState, CmdOption, DraftShape, ToolDraft, Vec2 } from "../types"; -import { createMutation } from "../createCore"; +import { createMutation, createQuery } from "../createCore"; const EPS = 1e-6; const CLOSE_HIT = 0.08; // Modell-Meter: Klick nahe Startpunkt schliesst die Kontur @@ -46,9 +50,40 @@ const excavationOps = (points: Vec2[], ctx: CommandContext) => createMutation(ct const idle = (): [CommandState, CommandResult] => [{ phase: "start", lastPoint: null } as HoleIdle, { draft: null, done: true }]; +/** Prüfung des Kerns vor dem Anlegen (`cmd_solid.rs`, `excavationCheck`). */ +interface ExcavationCheck { + valid: boolean; + bottom: number; + terrain: boolean; + over: boolean; + cut: boolean; + datum: number | null; +} + +const hasTerrain = (ctx: CommandContext): boolean => (ctx.project.context ?? []).some((o) => o.type === "terrainMesh"); + +/** Sohle als Kote (−3.00). */ +const kote = (z: number): string => (z > 0 ? "+" : z < 0 ? "−" : "±") + Math.abs(z).toFixed(2); + +/** Baugrube anlegen oder sagen, warum nicht. */ +function finishResult(points: Vec2[], ctx: CommandContext): CommandResult { + const c = createQuery(ctx.project, { q: "excavationCheck", pts: points, level: ctx.level.id }); + if (!c.valid) return { draft: null, done: true, notice: { key: "cmd.excavation.degenerate", kind: "warning" } }; + if (!c.terrain) return { draft: null, done: true, notice: { key: "cmd.excavation.noTerrain", kind: "warning" } }; + if (!c.over) return { draft: null, done: true, notice: { key: "cmd.excavation.outside", kind: "warning" } }; + const bottom = kote(c.bottom); + const notice: CommandResult["notice"] = + c.datum != null + ? { key: "cmd.excavation.createdDatum", params: { bottom, datum: c.datum.toFixed(2) }, kind: "info" } + : c.cut + ? { key: "cmd.excavation.created", params: { bottom }, kind: "info" } + : { key: "cmd.excavation.fillOnly", params: { bottom }, kind: "warning" }; + return { draft: null, done: true, commit: excavationOps(points, ctx), notice }; +} + const finish = (points: Vec2[], ctx: CommandContext): [CommandState, CommandResult] => [ { phase: "start", lastPoint: null } as HoleIdle, - { draft: null, done: true, commit: excavationOps(points, ctx) }, + finishResult(points, ctx), ]; export const excavationCommand: Command = { @@ -62,6 +97,8 @@ export const excavationCommand: Command = { if (ps.phase !== "next") return []; return ps.points.length >= 3 ? [CLOSE, UNDO] : [UNDO]; }, + // [143] Ohne Gelände gibt es nichts auszuheben (das Panel zeigt den Knopf erst mit Gelände). + precondition: (ctx) => (hasTerrain(ctx) ? null : "cmd.excavation.noTerrain"), init: (): HoleIdle => ({ phase: "start", lastPoint: null }), onInput: (state, input, ctx): [CommandState, CommandResult] => { diff --git a/src/commands/cmds/terrain.ts b/src/commands/cmds/terrain.ts index d6deac39..44a62076 100644 --- a/src/commands/cmds/terrain.ts +++ b/src/commands/cmds/terrain.ts @@ -22,6 +22,15 @@ const commitDone = (ctx: CommandContext): CommandResult => ({ draft: null, done: const IDLE: CommandState = { phase: "idle", lastPoint: null }; +/** + * [143] Sofort ausführen (vorher wartete der Befehl auf eine Eingabe und schluckte die nächsten getippten + * Befehle); ohne Höhenlinien ein Hinweis statt stillem Nichts. + */ +const run = (ctx: CommandContext): CommandResult => + (ctx.project.context ?? []).some((o) => o.type === "contourSet") + ? commitDone(ctx) + : { draft: null, done: true, notice: { key: "cmd.terrain.noContours", kind: "warning" } }; + export const terrainCommand: Command = { name: "terrain", labelKey: "cmd.terrain.label", @@ -30,6 +39,7 @@ export const terrainCommand: Command = { accepts: () => [], options: () => [], init: () => ({ ...IDLE }), + autoRun: run, // Jeglicher Input beendet den Befehl mit dem Commit (es gibt keine Schritte). onInput: (_s, _i, ctx): [CommandState, CommandResult] => [{ ...IDLE }, commitDone(ctx)], diff --git a/src/commands/engine.ts b/src/commands/engine.ts index 22202d22..3d978c7c 100644 --- a/src/commands/engine.ts +++ b/src/commands/engine.ts @@ -67,7 +67,7 @@ export interface EngineHost { */ inputUnits?(): DisplayUnits; /** Optional: Hinweis zeigen (i18n-Key), z. B. „erst Objekte wählen" (`Command.needsSelection`). */ - notify?(key: string): void; + notify?(key: string, params?: Record, kind?: "info" | "warning" | "error"): void; } /** Öffentlicher Schnappschuss für die Command-Line-UI (rein lesend). */ @@ -323,7 +323,16 @@ export class CommandEngine { /** Startet einen konkreten Befehl (z. B. zur Wiederholung). */ startCommand(cmd: Command): boolean { - if (cmd.floorOnly && !this.host.isFloor()) return false; + if (cmd.floorOnly && !this.host.isFloor()) { + // [143] Nicht still scheitern (Schnitt/Ansicht/Blatt aktiv). + this.host.notify?.("cmd.needsFloor", undefined, "info"); + return false; + } + const blocked = cmd.precondition?.(this.host.context(null)); + if (blocked) { + this.host.notify?.(blocked, undefined, "warning"); + return false; + } if (cmd.needsSelection && !hasTransformSelection(this.host.context(null).selection)) { this.host.notify?.(cmd.needsSelection); return false; @@ -624,6 +633,7 @@ export class CommandEngine { private applyResult(res: CommandResult): void { if (res.commit) this.host.commit(res.commit); if (res.focusDrawingId) this.host.focusDrawing?.(res.focusDrawingId, res.focusMinHeightM); + if (res.notice) this.host.notify?.(res.notice.key, res.notice.params, res.notice.kind ?? "info"); if (res.draft) this.host.setDraft(res.draft); else this.host.setDraft(null); if (res.done) { diff --git a/src/commands/types.ts b/src/commands/types.ts index 979c5fb9..b3c0c360 100644 --- a/src/commands/types.ts +++ b/src/commands/types.ts @@ -137,6 +137,18 @@ export interface CommandResult { * sie, bestimmt allein der Inhalt die Höhe (Text-Werkzeug ohne Rahmen). */ focusMinHeightM?: number; + /** + * [143] Hinweis an den Nutzer (Toast über `EngineHost.notify`), z. B. warum nichts entstand oder was + * angenommen wurde. Ohne ihn scheitern Befehle still. + */ + notice?: CommandNotice; +} + +/** [143] Hinweis eines Befehls: i18n-Key, Platzhalter, Art. */ +export interface CommandNotice { + key: TranslationKey; + params?: Record; + kind?: "info" | "warning" | "error"; } // ── Befehls-Zustand ────────────────────────────────────────────────────────── @@ -193,6 +205,11 @@ export interface Command { * Befehl nicht, die Engine meldet diesen Hinweis über `EngineHost.notify`. */ needsSelection?: TranslationKey; + /** + * [143] Voraussetzung (optional): liefert einen Hinweis-Key, wenn der Befehl jetzt nicht sinnvoll ist + * (z. B. Baugrube ohne Gelände); die Engine startet ihn dann nicht und meldet den Hinweis. + */ + precondition?(ctx: CommandContext): TranslationKey | null; /** Initialer Schritt-Zustand. */ init(): CommandState; /** Eine Eingabe (Punkt/Zahl/Option/Auswahl) verarbeiten. */ diff --git a/src/i18n/de.ts b/src/i18n/de.ts index f44ad867..519996b6 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -1682,6 +1682,14 @@ export const de = { "cmd.ceilingOpening.start": "Erste Ecke der Aussparung (in einer Decke):", "cmd.ceilingOpening.corner": "Gegenecke:", "cmd.roofHole.label": "Dachhof", + "cmd.needsFloor": "Dieser Befehl zeichnet im Grundriss: zuerst ein Geschoss wählen", + "cmd.excavation.noTerrain": "Baugrube braucht ein Gelände: zuerst Höhenlinien importieren und „Gelände erzeugen“ (Panel Gelände) oder den Standort importieren", + "cmd.excavation.outside": "Keine Baugrube: der Umriss liegt ausserhalb des Geländes", + "cmd.excavation.degenerate": "Keine Baugrube: der Umriss hat keine Fläche", + "cmd.excavation.created": "Baugrube angelegt: Sohle {bottom} m (tiefstes Geschoss − 0.30), Böschung 45° — anpassen in der Objekt-Info", + "cmd.excavation.createdDatum": "Baugrube angelegt: Sohle {bottom} m; das Gelände liegt in m ü. M., ±0.00 = {datum} m ü. M. angenommen (Einstellungen)", + "cmd.excavation.fillOnly": "Baugrube angelegt, aber die Sohle {bottom} m liegt über dem Gelände: nur Aufschüttung — Sohle in der Objekt-Info tiefer setzen", + "cmd.terrain.noContours": "Kein Gelände erzeugt: es gibt keine Höhenlinien (DXF importieren oder Standort importieren)", "cmd.excavation.label": "Baugrube", "cmd.excavation.start": "Erster Punkt der Baugrubensohle:", "cmd.excavation.next": "Nächster Punkt (Enter bei 2 Punkten = Rechteck, ab 3 Punkten Polygon):", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 536b9f4a..c9cd4b2f 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -1671,6 +1671,14 @@ export const en: Record = { "cmd.ceilingOpening.start": "First corner of the opening (inside a slab):", "cmd.ceilingOpening.corner": "Opposite corner:", "cmd.roofHole.label": "Roof court", + "cmd.needsFloor": "This command draws in plan view: select a storey first", + "cmd.excavation.noTerrain": "An excavation needs terrain: import contour lines and “Generate terrain” (Terrain panel) or import the site first", + "cmd.excavation.outside": "No excavation: the outline lies outside the terrain", + "cmd.excavation.degenerate": "No excavation: the outline has no area", + "cmd.excavation.created": "Excavation created: bottom {bottom} m (lowest storey − 0.30), slope 45° — adjust in Object Info", + "cmd.excavation.createdDatum": "Excavation created: bottom {bottom} m; the terrain is in m a.s.l., ±0.00 = {datum} m a.s.l. assumed (Settings)", + "cmd.excavation.fillOnly": "Excavation created, but its bottom {bottom} m lies above the terrain: fill only — lower the bottom in Object Info", + "cmd.terrain.noContours": "No terrain generated: there are no contour lines (import a DXF or the site)", "cmd.excavation.label": "Excavation", "cmd.excavation.start": "First point of the excavation bottom:", "cmd.excavation.next": "Next point (Enter with 2 points = rectangle, 3 or more = polygon):", diff --git a/src/state/useCommandEngineHost.ts b/src/state/useCommandEngineHost.ts index 2f967d7b..f1558e3b 100644 --- a/src/state/useCommandEngineHost.ts +++ b/src/state/useCommandEngineHost.ts @@ -169,7 +169,7 @@ export function useCommandEngineHost(opts: { }, isFloor: () => cmdLatest.current.activeLevel.kind === "floor", // Befehl braucht eine Auswahl (Bewegen/Drehen/Spiegeln), es ist keine da. - notify: (key) => notify(t(key as Parameters[0]), "info"), + notify: (key, params, kind) => notify(t(key as Parameters[0], params), kind ?? "info"), // Getippte Werte auf einem Layout-Blatt in Papier-mm, y nach unten ([93]). inputUnits: () => unitsForLevel(cmdLatest.current.activeLevel), // Frisch über `text`/`textbox` erzeugtes Element sofort inline editieren