diff --git a/TODO.md b/TODO.md index 89e490c6..ae6de899 100644 --- a/TODO.md +++ b/TODO.md @@ -105,7 +105,15 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `* reiner Wandauswahl. Neue umbelegbare Kürzel (Einstellungen): Cmd+D Duplizieren (Kopie 0.5 m versetzt, danach gewählt), Cmd+L Sperren/Entsperren, Cmd+Shift+H Ebenen der Auswahl ausblenden, Cmd+Shift+A alle Ebenen einblenden, Cmd+0 alles einpassen, Cmd+Shift+F auf Auswahl einpassen (ohne Plan: 3D-Kamera); alle im nativen Menü (`state/selectionActions.ts`). - Offen: Bogenwände werden nicht verbunden; T-Stoss nur bis zur Achse (nicht Fläche); „Auswahl ausblenden" im Grundriss + Nachtrag (13.11., Meldung Maintainer „Cmd+J geht bei Wänden nicht" in der Mac-App): T-Stoss endet jetzt an der dem Abzweig + zugewandten Fläche der Durchgangswand (Referenzlinie beachtet; `joins.rs` schneidet dort sauber, Test gegen `compute_joins`), + nicht mehr an der Achse. Hinweis ohne Wirkung nennt den Grund (`cmd.join.far` mit Abstand/Toleranz, `.met`, `.cross`, + `.parallel`, `.arc`, `.locked`, `.floors`, `.few`; Kern `join_hint`, Zahlen als `Schlüssel|arg|arg` im `notice`). Mac-Weg: + das native Menü (Accelerator CmdOrCtrl+J) fängt die Taste ab, das Fenster bekommt kein keydown; der Menü-Weg und das + Tastenkürzel laufen nun über `state/selectionJoin.ts` (Auswahl frisch aus dem Store, nicht aus der Render-Closure; auch der + Engine-Kontext liest sie frisch), e2e `wallJoinMenu190.spec.ts` löst `selectionAction("join")` wie der Menüpunkt aus. + Eine veraltete Closure war im Code nicht nachweisbar; die genaue Mac-Ursache ist ungeprüft (kein macOS hier). + Offen: Bogenwände werden nicht verbunden; „Auswahl ausblenden" im Grundriss schaltet Ebenen (persistent, undo-bar), nicht einzelne Elemente temporär; kein Cmd+E/F2 (keine Funktion dahinter); nicht in der Tauri-App geprüft. · S - ○ **[189]** Panels neu ordnen + Einstellungsdialog (12.11., Maintainer): Attribute-Panel unten links nur Gestaltung (Stift, Füllung, Linienstil, Schraffur); BIM-/Bauteil-Infos (Typ, Schichten, Masse, Kennwerte, IFC/Psets, Material …) in die Objekt-Info. Taste T bei Auswahl öffnet direkt den Einstellungsdialog des Objekts (wie Archicad Cmd+T), v. a. für Fenster/Türen, deren Einstellungen heute nur über das Attribute-Panel erreichbar sind. · M diff --git a/e2e/wallJoinMenu190.spec.ts b/e2e/wallJoinMenu190.spec.ts new file mode 100644 index 00000000..924d8014 --- /dev/null +++ b/e2e/wallJoinMenu190.spec.ts @@ -0,0 +1,86 @@ +// [190] Verbinden über den Menü-Weg: auf macOS fängt das native Menü „Bearbeiten > Verbinden" Cmd+J ab, das +// Fenster bekommt die Taste nie. Der Test löst deshalb dieselbe Aktion wie der Menüpunkt aus +// (`runSelectionAction("join")` über den Test-Haken `selectionAction`), ohne Tastendruck — die Auswahl wird +// vorher gesetzt, danach sofort verbunden (keine veraltete Render-Closure). Prüft auch den T-Stoss an der +// Fläche und den Hinweis mit Grund. +import { blurFocus, commandInput, expect, finishCommand, openTab, test, typeCommand } from "./app"; +import type { Page } from "@playwright/test"; + +type W = { id: string; start: { x: number; y: number }; end: { x: number; y: number } }; + +async function drawWalls(page: Page, walls: [string, string][]): Promise { + for (const [a, b] of walls) { + await page.getByRole("button", { name: "Wand", exact: true }).click(); + if (!(await page.locator(".cmdline-prompt").textContent())?.includes("Startpunkt")) { + await page.getByRole("button", { name: "Wand", exact: true }).click(); + } + await expect(page.locator(".cmdline-prompt")).toHaveText("Startpunkt der Wand:"); + await commandInput(page).focus(); + await typeCommand(page, a); + await typeCommand(page, b); + await finishCommand(page); + } +} + +const walls = (page: Page) => page.evaluate(() => window.__dossierTest!.walls()); +const menuJoin = async (page: Page) => { + const all = await walls(page); + await page.evaluate((ids) => { + window.__dossierTest!.select({ walls: ids }); + window.__dossierTest!.selectionAction("join"); + }, all.map((w) => w.id)); +}; + +async function start(page: Page): Promise { + await page.goto("/?dossierTest"); + await page.getByRole("button", { name: /Neues Projekt/ }).first().click(); + await expect(page.getByRole("group", { name: "Befehlszeile" })).toBeVisible(); + await openTab(page, "Elemente"); +} + +test("Menü Bearbeiten > Verbinden: Lücke an der Ecke schliessen, Auswahl wird aufgeräumt", async ({ page }) => { + await start(page); + await drawWalls(page, [ + ["0,0", "5.7,0"], + ["6,0.3", "6,4"], + ]); + await blurFocus(page); + await menuJoin(page); + await expect + .poll(async () => { + const ws = await walls(page); + return ws.some((w) => Math.abs(w.end.x - 6) < 1e-6 && Math.abs(w.end.y) < 1e-6) && ws.some((w) => Math.abs(w.start.x - 6) < 1e-6 && Math.abs(w.start.y) < 1e-6); + }) + .toBe(true); + await blurFocus(page); + await page.keyboard.press("ControlOrMeta+z"); + await expect.poll(async () => (await walls(page)).some((w) => Math.abs(w.end.x - 5.7) < 1e-6)).toBe(true); +}); + +test("Menü Verbinden: T-Stoss endet an der Fläche der Querwand", async ({ page }) => { + await start(page); + await drawWalls(page, [ + ["0,0", "5.7,0"], + ["6,-3", "6,3"], + ]); + await blurFocus(page); + await menuJoin(page); + // Der Abzweig endet an der zugewandten Fläche (Wandtyp-Dicke/2 vor der Achse x = 6), die Querwand bleibt. + await expect.poll(async () => (await walls(page)).find((w) => Math.abs(w.start.x) < 1e-6 && Math.abs(w.start.y) < 1e-6)!.end.x).toBeGreaterThan(5.7 + 1e-6); + const ws = await walls(page); + const branch = ws.find((w) => Math.abs(w.start.x) < 1e-6 && Math.abs(w.start.y) < 1e-6)!; + expect(branch.end.x).toBeLessThan(6 - 1e-6); + const through = ws.find((w) => Math.abs(w.start.x - 6) < 1e-6)!; + expect(through.end).toEqual({ x: 6, y: 3 }); +}); + +test("Menü Verbinden: Hinweis nennt den Grund (zu weit, parallel)", async ({ page }) => { + await start(page); + await drawWalls(page, [ + ["0,0", "4,0"], + ["6,0", "6,4"], + ]); + await blurFocus(page); + await menuJoin(page); + await expect.poll(() => page.evaluate(() => window.__dossierTest!.notices())).toContainEqual(expect.stringMatching(/Abstand zu gross \(2\.00 m, höchstens 0\.\d+ m\)/)); +}); diff --git a/src-tauri/core/src/cmd_transform.rs b/src-tauri/core/src/cmd_transform.rs index 10214f3a..b7e7bf55 100644 --- a/src-tauri/core/src/cmd_transform.rs +++ b/src-tauri/core/src/cmd_transform.rs @@ -979,7 +979,7 @@ pub fn transform_result(root: &Map, p: &Project, req: &TransformR ops.extend(add(key, items)); } ops.extend(add("openings", new_openings)); - crate::grips::GripResult { ops, notice: notice.get() } + crate::grips::GripResult { ops, notice: notice.get(), ..Default::default() } } // ── Ausrichten/Verteilen, Block definieren ─────────────────────────────────── diff --git a/src-tauri/core/src/cmd_wall_edit.rs b/src-tauri/core/src/cmd_wall_edit.rs index 2a20b422..240881c5 100644 --- a/src-tauri/core/src/cmd_wall_edit.rs +++ b/src-tauri/core/src/cmd_wall_edit.rs @@ -1038,10 +1038,20 @@ fn spot(ax: &Axis, x: P, tol: f64) -> Option { } } +/// T-Stoss ([190]): Punkt, an dem die Achse des Abzweigs (`ab`, Ende `at_end`) auf die dem Abzweig +/// zugewandte Fläche der Durchgangswand `wt` trifft. Dort endet der Abzweig; `joins.rs` +/// (`apply_mid_span_tee`) schneidet ihn an dieser Fläche, es bleibt kein Überstand im Durchgang. +fn tee_face_point(pr: &Project, ab: &Axis, at_end: bool, wt: &Wall, at: &Axis) -> Option

{ + let far = if at_end { ab.a } else { ab.b }; + let (lo, hi) = faces(pr, wt); + let face = if at.local(far).1 >= 0.0 { hi } else { lo }; + kernel2d::line_intersect(ab.a, ab.u, at.point(0.0, face), at.u).filter(|x| fin(*x)) +} + /// Verbinden von Ecken ([190], Archicad-Art): gewählte gerade Wände eines Geschosses, deren Achsen sich /// nicht sauber treffen, werden bis zum Achsschnittpunkt verlängert bzw. gekürzt. Zwei Enden nahe am /// Schnittpunkt ergeben eine L-Ecke (beide rücken), ein Ende nahe am Schnittpunkt, der im Innern der -/// anderen Wand liegt, einen T-Stoss (nur das Ende rückt). Toleranz je Paar: grösser von 0.5 m und der +/// anderen Wand liegt, einen T-Stoss (nur das Ende rückt, an die zugewandte Fläche der Durchgangswand). Toleranz je Paar: grösser von 0.5 m und der /// doppelten Wanddicke. Jedes Ende rückt höchstens einmal (nahe Paare zuerst). Die Gehrung bzw. der /// Anschluss folgt aus den Enden (`joins.rs`); Öffnungen und Bemassung führt [`commit`] nach (wie /// Trim/Extend — Öffnungen bleiben im Plan stehen). Wände in `skip` (schon kollinear verkettet) und @@ -1076,8 +1086,8 @@ pub fn connect_ops(root: &Map, pr: &Project, ids_sel: &[String], let tol = 0.5_f64.max(2.0 * thick(wi).max(thick(wj))); match (spot(ai, x, tol), spot(aj, x, tol)) { (Some(Spot::End(da, ea)), Some(Spot::End(db, eb))) => cands.push((da + db, vec![Move { i, at_end: ea, x }, Move { i: j, at_end: eb, x }])), - (Some(Spot::End(da, ea)), Some(Spot::Inner)) => cands.push((da, vec![Move { i, at_end: ea, x }])), - (Some(Spot::Inner), Some(Spot::End(db, eb))) => cands.push((db, vec![Move { i: j, at_end: eb, x }])), + (Some(Spot::End(da, ea)), Some(Spot::Inner)) => cands.push((da, vec![Move { i, at_end: ea, x: tee_face_point(pr, ai, ea, wj, aj).unwrap_or(x) }])), + (Some(Spot::Inner), Some(Spot::End(db, eb))) => cands.push((db, vec![Move { i: j, at_end: eb, x: tee_face_point(pr, aj, eb, wi, ai).unwrap_or(x) }])), _ => {} } } @@ -1117,6 +1127,83 @@ pub fn connect_ops(root: &Map, pr: &Project, ids_sel: &[String], commit(root, pr, &Edit { plans, extra: vec![] }, &mut IdGen::new("join")) } +/// Hinweis für die Hülle, wenn Verbinden ([190]) bei gewählten Wänden nichts bewirkt: i18n-Schlüssel, bei +/// Zahlen mit `|`-getrennten Werten dahinter (`cmd.join.far|0.73|0.50` = Abstand, Toleranz in Metern). +/// `None`, wenn kein Grund erkennbar ist (die Hülle zeigt dann den allgemeinen Hinweis). +pub fn join_hint(pr: &Project, ids_sel: &[String]) -> Option { + let sel: Vec<&Wall> = walls(pr).iter().filter(|w| ids_sel.contains(&w.id)).collect(); + if sel.len() < 2 { + return None; + } + let free: Vec<&Wall> = sel.iter().copied().filter(|w| editable(w)).collect(); + if free.len() < 2 { + return Some("cmd.join.locked".into()); + } + let straight: Vec<(&Wall, Axis)> = free.iter().filter_map(|w| Axis::of(w).filter(|a| a.arc.is_none()).map(|a| (*w, a))).collect(); + if straight.len() < 2 { + return Some("cmd.join.arc".into()); + } + let (mut same_floor, mut parallel, mut met, mut crossing) = (false, false, false, false); + let mut far: Option<(f64, f64)> = None; + for i in 0..straight.len() { + for j in i + 1..straight.len() { + let ((wi, ai), (wj, aj)) = (&straight[i], &straight[j]); + if wi.floor_id != wj.floor_id { + continue; + } + same_floor = true; + let den = cross(ai.u, aj.u); + if den.abs() < 0.02 { + parallel = true; + continue; + } + let t = cross(P::new(aj.a.x - ai.a.x, aj.a.y - ai.a.y), aj.u) / den; + let x = P::new(ai.a.x + ai.u.x * t, ai.a.y + ai.u.y * t); + if !fin(x) { + continue; + } + // Abstand des Schnittpunkts zur Wand: 0 im Innern, sonst zum nächsten Ende. + let gap = |a: &Axis| { + let s = a.local(x).0; + if s > 0.0 && s < a.len { + (0.0, true) + } else { + (s.abs().min((s - a.len).abs()), false) + } + }; + let ((gi, ini), (gj, inj)) = (gap(ai), gap(aj)); + let thick = |w: &Wall| { + let (lo, hi) = faces(pr, w); + (hi - lo).abs() + }; + let tol = 0.5_f64.max(2.0 * thick(wi).max(thick(wj))); + if ini && inj { + crossing = true; + } else if gi.max(gj) < 1e-6 { + met = true; + } else if gi.max(gj) > tol { + let g = gi.max(gj); + if far.map_or(true, |f| g < f.0) { + far = Some((g, tol)); + } + } + } + } + if !same_floor { + return Some("cmd.join.floors".into()); + } + if let Some((g, tol)) = far { + return Some(format!("cmd.join.far|{g:.2}|{tol:.2}")); + } + if met { + return Some("cmd.join.met".into()); + } + if crossing { + return Some("cmd.join.cross".into()); + } + parallel.then(|| "cmd.join.parallel".into()) +} + #[cfg(test)] mod tests { use super::*; @@ -1534,7 +1621,7 @@ mod tests { // a endet 0.3 vor der Querwand b (die weiter durchläuft): nur a rückt, b bleibt. let r = project(vec![wall("a", (0.0, 0.0), (5.7, 0.0), None), wall("b", (6.0, -3.0), (6.0, 3.0), None)], vec![opening("o", "a", 1.0, 1.0)], vec![]); let n = apply(&r, connect_ops(&r, &typed(&r), &["a".into(), "b".into()], &[])); - assert!(close(xy_of(&w_of(&n, "a")["end"]), (6.0, 0.0))); + assert!(close(xy_of(&w_of(&n, "a")["end"]), (5.9, 0.0))); assert!(close(xy_of(&w_of(&n, "b")["start"]), (6.0, -3.0))); assert!(close(xy_of(&w_of(&n, "b")["end"]), (6.0, 3.0))); assert_eq!(arr(n.get("openings")).len(), 1); @@ -1558,4 +1645,72 @@ mod tests { assert!(close(xy_of(&w_of(&n, "b")["end"]), (6.0, 4.0))); assert!(close(xy_of(&w_of(&n, "c")["start"]), (6.0, 4.0))); } + + #[test] + fn verbinden_t_stoss_endet_an_der_zugewandten_flaeche() { + // Wandtyp 0.2 m, Mitte: Fläche der Querwand b bei x = 5.9 bzw. 6.1. + let r = project(vec![wall("a", (0.0, 0.0), (5.7, 0.0), None), wall("b", (6.0, -3.0), (6.0, 3.0), None)], vec![], vec![]); + let n = apply(&r, connect_ops(&r, &typed(&r), &["a".into(), "b".into()], &[])); + assert!(close(xy_of(&w_of(&n, "a")["end"]), (5.9, 0.0))); + // Überstand durch die Querwand hindurch: gekürzt auf die Fläche. + let r = project(vec![wall("a", (0.0, 0.0), (6.4, 0.0), None), wall("b", (6.0, -3.0), (6.0, 3.0), None)], vec![], vec![]); + let n = apply(&r, connect_ops(&r, &typed(&r), &["a".into(), "b".into()], &[])); + assert!(close(xy_of(&w_of(&n, "a")["end"]), (5.9, 0.0))); + // Abzweig von der anderen Seite (Start am Durchgang): Fläche x = 6.1. + let r = project(vec![wall("a", (6.3, 0.0), (9.0, 0.0), None), wall("b", (6.0, -3.0), (6.0, 3.0), None)], vec![], vec![]); + let n = apply(&r, connect_ops(&r, &typed(&r), &["a".into(), "b".into()], &[])); + assert!(close(xy_of(&w_of(&n, "a")["start"]), (6.1, 0.0))); + // Referenzlinie links: Band x = 5.8 … 6.0. + let mut b = wall("b", (6.0, -3.0), (6.0, 3.0), None); + b["referenceLine"] = json!("left"); + let r = project(vec![wall("a", (0.0, 0.0), (5.5, 0.0), None), b], vec![], vec![]); + let n = apply(&r, connect_ops(&r, &typed(&r), &["a".into(), "b".into()], &[])); + assert!(close(xy_of(&w_of(&n, "a")["end"]), (5.8, 0.0))); + } + + #[test] + fn verbinden_t_stoss_passt_zu_den_wand_joins() { + use crate::joins::{compute_joins, JoinLayer, JoinWall, Reference}; + use kernel2d::Vec2; + let r = project(vec![wall("a", (0.0, 0.0), (5.7, 0.0), None), wall("b", (6.0, -3.0), (6.0, 3.0), None)], vec![], vec![]); + let n = apply(&r, connect_ops(&r, &typed(&r), &["a".into(), "b".into()], &[])); + let jw = |id: &str| { + let w = w_of(&n, id); + let (s, e) = (xy_of(&w["start"]), xy_of(&w["end"])); + JoinWall { + start: Vec2 { x: s.0, y: s.1 }, + end: Vec2 { x: e.0, y: e.1 }, + reference: Reference::Center, + layers: Some(vec![JoinLayer { thickness: 0.2, component: Some(0), priority: 1.0 }]), + bulge: None, + } + }; + let cuts = compute_joins(&[jw("a"), jw("b")]).unwrap(); + // a bekommt einen Schnitt an der Fläche x = 5.9 (senkrecht zu a), b bleibt durchgehend. + let cut = cuts[0].end_cut.expect("T-Anschluss: Schnitt am Ende von a"); + assert!((cut.point.x - 5.9).abs() < 1e-9 && cut.dir.x.abs() < 1e-9); + assert!(cuts[1].start_cut.is_none() && cuts[1].end_cut.is_none()); + } + + #[test] + fn verbinden_hinweis_nennt_den_grund() { + let ids = ["a".to_string(), "b".to_string()]; + let hint = |ws: Vec| { + let r = project(ws, vec![], vec![]); + join_hint(&typed(&r), &ids) + }; + // Zu weit auseinander: Abstand 1.7 m zur Ecke, Toleranz 0.5 m. + assert_eq!(hint(vec![wall("a", (0.0, 0.0), (4.3, 0.0), None), wall("b", (6.0, 0.0), (6.0, 4.0), None)]).as_deref(), Some("cmd.join.far|1.70|0.50")); + // Parallel (versetzt). + assert_eq!(hint(vec![wall("a", (0.0, 0.0), (4.0, 0.0), None), wall("b", (0.0, 1.0), (4.0, 1.0), None)]).as_deref(), Some("cmd.join.parallel")); + // Treffen sich schon. + assert_eq!(hint(vec![wall("a", (0.0, 0.0), (6.0, 0.0), None), wall("b", (6.0, 0.0), (6.0, 4.0), None)]).as_deref(), Some("cmd.join.met")); + // Kreuzung. + assert_eq!(hint(vec![wall("a", (0.0, 0.0), (6.0, 0.0), None), wall("b", (3.0, -2.0), (3.0, 2.0), None)]).as_deref(), Some("cmd.join.cross")); + // Bogenwand. + assert_eq!(hint(vec![wall("a", (0.0, 0.0), (6.0, 0.0), Some(0.5)), wall("b", (6.0, 0.0), (6.0, 4.0), None)]).as_deref(), Some("cmd.join.arc")); + // Eine Wand allein: kein besonderer Grund. + let r = project(vec![wall("a", (0.0, 0.0), (6.0, 0.0), None)], vec![], vec![]); + assert_eq!(join_hint(&typed(&r), &["a".to_string()]), None); + } } diff --git a/src-tauri/core/src/commands.rs b/src-tauri/core/src/commands.rs index ce781c47..9c6a6fce 100644 --- a/src-tauri/core/src/commands.rs +++ b/src-tauri/core/src/commands.rs @@ -58,9 +58,25 @@ pub fn result(root: &Map, p: &Project, text: &str) -> Result = v.get("ids").and_then(|x| serde_json::from_value(x.clone()).ok()).unwrap_or_default(); + let hint = crate::cmd_wall_edit::join_hint(p, &ids); + let mut parts = hint.as_deref().unwrap_or("cmd.join.nothing").split('|'); + notice = Some(match parts.next() { + Some("cmd.join.far") => "cmd.join.far", + Some("cmd.join.locked") => "cmd.join.locked", + Some("cmd.join.arc") => "cmd.join.arc", + Some("cmd.join.floors") => "cmd.join.floors", + Some("cmd.join.met") => "cmd.join.met", + Some("cmd.join.cross") => "cmd.join.cross", + Some("cmd.join.parallel") => "cmd.join.parallel", + _ => "cmd.join.nothing", + }); + notice_args = parts.map(str::to_owned).collect(); + } + Ok(GripResult { ops, notice, notice_args }) } /// Wie [`result`], als Antwort-JSON `{"ops": […], "notice": …}` (Zahlen mit Nicht-endlich-Marken). diff --git a/src-tauri/core/src/grips.rs b/src-tauri/core/src/grips.rs index 0361127d..d7c10d82 100644 --- a/src-tauri/core/src/grips.rs +++ b/src-tauri/core/src/grips.rs @@ -162,11 +162,13 @@ impl Request { pub struct GripResult { pub ops: Vec, pub notice: Option<&'static str>, + /// Zahlen/Texte für den Hinweis ([190]); die Antwort trägt sie als `Schlüssel|arg|arg` im Feld `notice`. + pub notice_args: Vec, } impl From> for GripResult { fn from(ops: Vec) -> Self { - GripResult { ops, notice: None } + GripResult { ops, notice: None, notice_args: vec![] } } } @@ -193,7 +195,7 @@ pub fn result_json(r: &GripResult) -> String { out.push(b']'); if let Some(n) = r.notice { out.extend_from_slice(b",\"notice\":"); - let _ = serde_json::to_writer(&mut out, n); + let _ = if r.notice_args.is_empty() { serde_json::to_writer(&mut out, n) } else { serde_json::to_writer(&mut out, &format!("{n}|{}", r.notice_args.join("|"))) }; } out.push(b'}'); String::from_utf8(out).unwrap_or_default() @@ -460,7 +462,7 @@ pub fn run(lk: &Lookup, req: &Request) -> Result { let pts = arr(field(g, "pts")); let min = if truthy(field(g, "closed")) { 4 } else { 3 }; if pts.len() < min { - return Ok(GripResult { ops: vec![], notice: Some("alert.polylineMinPoints") }); + return Ok(GripResult { ops: vec![], notice: Some("alert.polylineMinPoints"), ..Default::default() }); } let Some(k) = index_in(index, pts.len()) else { return Ok(GripResult::default()) }; // Zwei Segmente werden eins: der Bogen des entfernten Segments fällt weg, das verbleibende behält @@ -487,7 +489,7 @@ pub fn run(lk: &Lookup, req: &Request) -> Result { let Some(placed) = want.and_then(|w| crate::opening_slide::slide_to(root, o, w)) else { return Ok(GripResult::default()) }; let v = with(o, "position", js_num(placed.position)); let ops = if v == *o { vec![] } else { vec![replace("openings", v)] }; - GripResult { ops, notice: placed.clamped.then_some(crate::opening_slide::NOTICE_OVERLAP) } + GripResult { ops, notice: placed.clamped.then_some(crate::opening_slide::NOTICE_OVERLAP), ..Default::default() } } other => return Err(format!("Unbekannte Griff-Änderung: {other}")), }) diff --git a/src/i18n/de.ts b/src/i18n/de.ts index 328e8cbd..0b7f7078 100644 --- a/src/i18n/de.ts +++ b/src/i18n/de.ts @@ -2324,7 +2324,15 @@ export const de = { // Alt+Klick). Labels für Befehlsleiste/Menüs. "edit.split.label": "Teilen", "edit.join.label": "Verbinden", - "cmd.join.nothing": "Nichts zu verbinden: Wände treffen sich bereits oder liegen zu weit auseinander.", + "cmd.join.few": "Zum Verbinden mindestens zwei Elemente wählen.", + "cmd.join.nothing": "Nichts zu verbinden.", + "cmd.join.far": "Nichts zu verbinden: Abstand zu gross ({d} m, höchstens {max} m).", + "cmd.join.met": "Nichts zu verbinden: die Wände treffen sich bereits.", + "cmd.join.cross": "Nichts zu verbinden: die Wände kreuzen sich.", + "cmd.join.parallel": "Nichts zu verbinden: die Wände sind parallel.", + "cmd.join.arc": "Nichts zu verbinden: Bogenwände werden nicht an Ecken verbunden.", + "cmd.join.locked": "Nichts zu verbinden: die Wände sind gesperrt.", + "cmd.join.floors": "Nichts zu verbinden: die Wände liegen auf verschiedenen Geschossen.", "edit.cutSegment.label": "Segment löschen", // Tab-Feld-Zyklus (Präzisionseingabe): geordnete Zahlenfelder je Schritt. "cmd.field.length": "Länge", diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 7c7a4d41..d20f9cfe 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -2312,7 +2312,15 @@ export const en: Record = { // Alt+Click). Labels for the command line / menus. "edit.split.label": "Split", "edit.join.label": "Join", - "cmd.join.nothing": "Nothing to join: walls already meet or are too far apart.", + "cmd.join.few": "Select at least two elements to join.", + "cmd.join.nothing": "Nothing to join.", + "cmd.join.far": "Nothing to join: distance too large ({d} m, at most {max} m).", + "cmd.join.met": "Nothing to join: the walls already meet.", + "cmd.join.cross": "Nothing to join: the walls cross each other.", + "cmd.join.parallel": "Nothing to join: the walls are parallel.", + "cmd.join.arc": "Nothing to join: curved walls are not joined at corners.", + "cmd.join.locked": "Nothing to join: the walls are locked.", + "cmd.join.floors": "Nothing to join: the walls are on different floors.", "edit.cutSegment.label": "Delete segment", // Tab field cycle (precision input): ordered numeric fields per step. "cmd.field.length": "Length", diff --git a/src/state/projectSlice.ts b/src/state/projectSlice.ts index 0cbff1c1..10041114 100644 --- a/src/state/projectSlice.ts +++ b/src/state/projectSlice.ts @@ -596,7 +596,10 @@ export function createProjectSlice( const now = Date.now(); if (notice === lastNotice.key && now - lastNotice.at < 2000) return; lastNotice = { key: notice, at: now }; - get().notify(t(notice as Parameters[0]), "warning"); + // `Schlüssel|arg|arg` ([190]): Zahlen aus dem Kern, im Text als {d}, {max}. + const [key, ...args] = notice.split("|"); + const params = args.length ? { d: args[0], max: args[1] ?? "" } : undefined; + get().notify(t(key as Parameters[0], params), "warning"); }; // Griff-Änderung ([K4] S3): der Kern rechnet sie auf dem Dokument und wendet sie im selben Aufruf an diff --git a/src/state/selectionJoin.ts b/src/state/selectionJoin.ts new file mode 100644 index 00000000..7bd1f26b --- /dev/null +++ b/src/state/selectionJoin.ts @@ -0,0 +1,22 @@ +// [190] Verbinden der aktuellen Auswahl (Wände: Ecken/T-Stösse/kollinear; 2D-Elemente: Ketten). EIN Pfad für das +// Tastenkürzel im Fenster (`useSplitJoinShortcut`) und das native Menü „Bearbeiten > Verbinden" (`selectionActions`). +// Unter macOS fängt das Menü Cmd+J ab, das Fenster sieht die Taste dann nie — der Menü-Weg muss alles allein +// leisten. Darum liest dieser Pfad die Auswahl IMMER frisch aus dem Store und nicht aus einer Render-Closure. + +import { t } from "../i18n"; +import { getState } from "./appStore"; +import type { CommandEngine } from "../commands/engine"; + +/** Startet „join" auf der aktuellen Auswahl; false (mit Hinweis), wenn weniger als zwei Elemente gewählt sind. */ +export function joinCurrentSelection(engine: Pick): boolean { + const s = getState(); + const n = s.selection.drawings.length + s.selection.walls.length; + if (n < 2) { + s.notify(t("cmd.join.few"), "info"); + return false; + } + engine.start("join"); + // Die alte Auswahl zeigt nach dem Verbinden auf ersetzte ids → aufräumen. + s.setSelection({ drawings: [], walls: [] }); + return true; +} diff --git a/src/state/testHooks.ts b/src/state/testHooks.ts index b9542c34..dfa806fe 100644 --- a/src/state/testHooks.ts +++ b/src/state/testHooks.ts @@ -4,6 +4,7 @@ import { core, coreEpoch, coreReady } from "../engine/coreWasm"; import { getState } from "./appStore"; +import { runSelectionAction, type SelectionActionId } from "./selectionActions"; import { storeDocument } from "./historySlice"; import { ceilingThickness } from "../model/types"; import { computeSection, generatePlan, verticalExtents, generateSectionPlan, pickGeometry, projectToModel3d } from "../core"; @@ -60,6 +61,10 @@ declare global { layerView: () => { wallId: string; visible: string[]; prims: number; wallPrims: number }; /** [195] Strichstärke-Override der Wände (id → mm), nur gesetzte. */ wallWeights: () => Record; + /** [190] Auswahl-Aktion wie das native Menü (Bearbeiten > Verbinden usw.), ohne Tastendruck: `runSelectionAction`. */ + selectionAction: (id: SelectionActionId) => void; + /** [190] Wände (id, Start, Ende) des Projekts. */ + walls: () => { id: string; start: { x: number; y: number }; end: { x: number; y: number } }[]; /** [185] 3D-Element-Filter (Store) und die Wand-ids des 3D-Modells bzw. der Pick-Geometrie mit ihm. */ view3d: () => { only: string[] | null; hidden: string[]; walls: string[]; pickWalls: string[]; floors: string[]; pickOpenings: { id: string; host: string }[] }; }; @@ -98,6 +103,8 @@ export function installTestHooks(): void { }; }, wallWeights: () => Object.fromEntries(getState().project.walls.flatMap((w) => (w.strokeWeight === undefined ? [] : [[w.id, w.strokeWeight]]))), + selectionAction: (id) => runSelectionAction(id), + walls: () => getState().project.walls.map((w) => ({ id: w.id, start: { ...w.start }, end: { ...w.end } })), select: (patch) => getState().setSelection(patch), dimPts: (id) => { const g = getState().project.drawings2d.find((d) => d.id === id)?.geom; diff --git a/src/state/useCommandEngineHost.ts b/src/state/useCommandEngineHost.ts index 63383ca3..fd57ac7e 100644 --- a/src/state/useCommandEngineHost.ts +++ b/src/state/useCommandEngineHost.ts @@ -131,7 +131,8 @@ export function useCommandEngineHost(opts: { // Befehl). Move/Copy/Offset operieren darauf. // Im Schnitt/in der Ansicht nur die 2D-Elemente der Ebene: Bauteile // leben im Grundriss-Raum, ein Schnitt-Delta wäre dort falsch. - selection: sheetOnlySelection(c.activeLevel, toCommandSelection(c.selection)), + // Auswahl frisch aus dem Store ([190]): das native Menü ruft Befehle ausserhalb von React, die Render-Kopie kann dort veraltet sein. + selection: sheetOnlySelection(c.activeLevel, toCommandSelection(getState().selection)), }; }, snap: (raw, draftPoints, mods) => { diff --git a/src/state/useKeyboardShortcuts.ts b/src/state/useKeyboardShortcuts.ts index 85de0739..9cf9c876 100644 --- a/src/state/useKeyboardShortcuts.ts +++ b/src/state/useKeyboardShortcuts.ts @@ -34,6 +34,7 @@ import type { ElementClipboard, ElementSelectionIds, PastedIds } from "../editor import { parseClipboardText, serializeClipboardText } from "../editors/elementClipboardSerialize"; import { matchesShortcut, type ShortcutId, type ShortcutOverrides } from "./keyboardShortcuts"; import { isolateSelectionLayerCodes, showAllLayerCodes } from "./layerIsolate"; +import { joinCurrentSelection } from "./selectionJoin"; import { hideSelectionIn3d, showSelectionIn3d, stepActiveFloor } from "./tabNavigation"; const isEditableTarget = (e: KeyboardEvent): boolean => { @@ -332,7 +333,7 @@ export function useSplitJoinShortcut( selectedDrawingIds: string[], engine: CommandEngine, runSplit: (ids: string[]) => void, - setSelection: (patch: Partial) => void, + _setSelection: (patch: Partial) => void, overrides: ShortcutOverrides, selectedWallIds: string[] = [], ): void { @@ -351,10 +352,8 @@ export function useSplitJoinShortcut( runSplit(ids); return; } - // Join: exakt derselbe Befehl wie „join" tippen (Sofort-Befehl, autoRun). - // Nach dem Verbinden zeigt die alte Auswahl auf ersetzte IDs → aufräumen. - engine.start("join"); - setSelection({ drawings: [], walls: [] }); + // Join: derselbe Pfad wie das native Menü (Auswahl frisch aus dem Store, Hinweis bei < 2 Elementen). + joinCurrentSelection(engine); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); diff --git a/src/state/useSelectionCommands.ts b/src/state/useSelectionCommands.ts index 2803a767..c3b54a55 100644 --- a/src/state/useSelectionCommands.ts +++ b/src/state/useSelectionCommands.ts @@ -20,6 +20,7 @@ import type { BooleanResult } from "../editors/booleanOps"; import type { EngineView } from "../commands/engine"; import { clearKinds, fromIdLists, hasTransformable, isEmpty, toMembership, toTransformSelection } from "./selection"; import { registerSelectionActions } from "./selectionActions"; +import { joinCurrentSelection } from "./selectionJoin"; import { transformOps } from "../tools/transform"; import { addedIds, type PastedIds } from "../editors/elementClipboard"; import { containingGroupId, EMPTY_MEMBERSHIP } from "./groupActions"; @@ -327,11 +328,7 @@ export function useSelectionCommands(opts: { // [185] Cmd/Ctrl+3/4/5/6: Auswahl in 3D zeigen/ausblenden, Geschoss tiefer/höher. useViewNavigationShortcuts(shortcutOverrides); // [190] Verbinden (Cmd/Ctrl+J) auch aus dem nativen Menü: dieselbe Aktion wie das Tastenkürzel. - const joinSelection = () => { - if (selection.drawings.length + selection.walls.length === 0) return; - engine.start("join"); - setSelection({ drawings: [], walls: [] }); - }; + const joinSelection = () => void joinCurrentSelection(engine); registerSelectionActions({ duplicate: duplicateSelection, toggleLock: toggleSelectionLock,