From ac2eac8a408ae2cc1386656c989f963ca15bccf7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 00:09:11 +0000 Subject: [PATCH] =?UTF-8?q?[77]=20Zauberstab:=20Griffe=20an=20Lochpunkten,?= =?UTF-8?q?=20Aufl=C3=B6sen=20liefert=20Lochkanten,=20Versetzen/Bruch/Verb?= =?UTF-8?q?inden=20lassen=20L=C3=B6cher=20weg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.md | 7 +++-- src-tauri/core/src/cmd_edit.rs | 51 ++++++++++++++++++++++++++++++++-- src-tauri/core/src/grips.rs | 39 +++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 61d6c3a5..80426124 100644 --- a/TODO.md +++ b/TODO.md @@ -1773,9 +1773,10 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]). `kernel2d::region_with_islands`); nur äusserste Inseln (Insel im Loch einer Insel bleibt unberücksichtigt). Plan: Füllung/Schraffur als Ring mit Brücken (`merge_holes`, wie Decken) → SVG/PDF/DXF/Render sparen aus, Loch-Umrisse gezeichnet; Vorschau zeigt sie. Verschieben/Kopieren/Drehen/Spiegeln/Skalieren, Griff „ganz - verschieben", Geo-Verschiebung und Wand-Begrenzung nehmen `holes` mit. Offen: Fläche in der Objekt-Info (gibt - es für Polylinien nicht), Auflösen/Versetzen/Trennen/Booleans ignorieren `holes` (Loch geht verloren), Griffe an - Lochpunkten; nicht in der App geklickt. + verschieben", Geo-Verschiebung und Wand-Begrenzung nehmen `holes` mit. 4.11. Griffe: Loch-Ecken sind Eckgriffe (Index ab 2n, hinter den Bogen-Griffen; bestehende Indizes unverändert). + Auflösen liefert zusätzlich die Lochkanten als Linien. Verrunden/Fasen behalten die Löcher; Versetzen, Bruch, + Teilen, Trimmen/Verlängern und Verbinden bauen neue Ketten und lassen `holes` bewusst weg (Kopie ohne Löcher, kein + Panic). Offen: Fläche in der Objekt-Info (gibt es für Polylinien nicht); nicht in der App geklickt. - ✅ **[78] Autotext im Plankopf.** Titelblock löst Projekt/Blatt/Massstab/Datum auf; Plannummer laufend oder `Layout.planNumber` (27.10.). - ◐ **[79] Publikationssätze.** (30.10.) Modell (Rust, optional): `Project.publishSets` (`PublishSet`: Layouts in Reihenfolge, diff --git a/src-tauri/core/src/cmd_edit.rs b/src-tauri/core/src/cmd_edit.rs index 9b6e7868..e751e5e0 100644 --- a/src-tauri/core/src/cmd_edit.rs +++ b/src-tauri/core/src/cmd_edit.rs @@ -546,6 +546,16 @@ fn polyline_geom(pts: Vec, closed: Option, bulge: Option Value { + match field(src, "holes") { + Some(h) if truthy(Some(h)) => with(&g, "holes", h.clone()), + _ => g, + } +} + /// Verrunden der Ecke `index` von `id` mit Radius `r` (Bogen als bulge zwischen den Tangentenpunkten). pub fn fillet_ops(root: &Map, id: &str, index: f64, r: f64) -> Vec { let Some(h) = corner_of(root, id, index) else { return vec![] }; @@ -559,14 +569,14 @@ pub fn fillet_ops(root: &Map, id: &str, index: f64, r: f64) -> Ve if h.index < bulge.len() { bulge[h.index] = js_num(b); } - patch_geom(root, id, polyline_geom(pts, h.c.closed_raw.clone(), Some(bulge))) + patch_geom(root, id, keep_holes(find(root, id).map_or(&Value::Null, geom), polyline_geom(pts, h.c.closed_raw.clone(), Some(bulge)))) } /// Fasen der Ecke `index` von `id` um `d`. pub fn chamfer_ops(root: &Map, id: &str, index: f64, d: f64) -> Vec { let Some(h) = corner_of(root, id, index) else { return vec![] }; let Some(c) = chamfer_of(&h, d) else { return vec![] }; - patch_geom(root, id, polyline_geom(split_corner(&h, c.a, c.b), h.c.closed_raw.clone(), None)) + patch_geom(root, id, keep_holes(find(root, id).map_or(&Value::Null, geom), polyline_geom(split_corner(&h, c.a, c.b), h.c.closed_raw.clone(), None))) } /// Vorschau Verrunden/Fasen einer Ecke (`fillet`: Bogen, sonst die Fasung). @@ -830,6 +840,22 @@ fn explode_geom(g: &Value, root: &Map) -> Option> { } out.push(Value::Object(m)); } + // Löcher (nur geschlossen): ihre Kanten als Linien. + if segs == n { + for h in arr(field(g, "holes")) { + let ring = arr(Some(h)); + if ring.len() < 3 { + continue; + } + for i in 0..ring.len() { + let mut m = Map::new(); + m.insert("shape".into(), "line".into()); + m.insert("a".into(), ring[i].clone()); + m.insert("b".into(), ring[(i + 1) % ring.len()].clone()); + out.push(Value::Object(m)); + } + } + } Some(out) } "rect" => { @@ -1092,6 +1118,27 @@ mod tests { assert!(g["bulge"][1].as_f64().unwrap().abs() > 0.1); } + #[test] + fn aufloesen_polylinie_mit_loch_liefert_lochkanten() { + let pl = json!({"id": "p", "geom": {"shape": "polyline", "closed": true, "pts": [{"x": 0, "y": 0}, {"x": 4, "y": 0}, {"x": 4, "y": 4}, {"x": 0, "y": 4}], + "holes": [[{"x": 1, "y": 1}, {"x": 2, "y": 1}, {"x": 2, "y": 2}]]}}); + let r = root(json!({"drawings2d": [pl]})); + let ops = explode_ops(&r, &["p".into()], &mut IdGen::new("s")); + assert_eq!(ops.last().unwrap().to_json()["items"].as_array().unwrap().len(), 4 + 3); + } + + #[test] + fn offset_und_verbinden_mit_loch_ohne_panik_loecher_entfallen() { + let pl = json!({"id": "p", "geom": {"shape": "polyline", "closed": true, "pts": [{"x": 0, "y": 0}, {"x": 4, "y": 0}, {"x": 4, "y": 4}, {"x": 0, "y": 4}], + "holes": [[{"x": 1, "y": 1}, {"x": 2, "y": 1}, {"x": 2, "y": 2}]]}}); + let r = root(json!({"drawings2d": [pl, line("a", (0.0, 0.0), (1.0, 0.0))]})); + let ops = offset_ops(&r, "p", 0.5, &mut IdGen::new("s")); + assert_eq!(ops.len(), 1); + assert!(ops[0].to_json()["items"][0]["geom"].get("holes").is_none()); + let _ = join_ops(&r, &["p".into(), "a".into()], &mut IdGen::new("j")); + let _ = break_ops(&r, "p", P::new(0.0, 0.0), P::new(2.0, 0.0), &mut IdGen::new("b")); + } + #[test] fn aufloesen_rechteck_an_ort_und_stelle() { let rect = json!({"id": "r", "geom": {"shape": "rect", "min": {"x": 0, "y": 0}, "max": {"x": 1, "y": 1}}}); diff --git a/src-tauri/core/src/grips.rs b/src-tauri/core/src/grips.rs index c177f32b..4beda84a 100644 --- a/src-tauri/core/src/grips.rs +++ b/src-tauri/core/src/grips.rs @@ -456,6 +456,20 @@ fn drawing_grip(d: &Value, index: f64, x: f64, y: f64, scale: f64) -> Option 2 && index >= (2 * n) as f64 && field(g, "holes").is_some() { + let mut rest = index as usize - 2 * n; + let mut holes: Vec = arr(field(g, "holes")).to_vec(); + for h in holes.iter_mut() { + let ring = arr(Some(&*h)); + if rest < ring.len() { + *h = replace_at(ring, rest as f64, &p); + return set("holes", Value::Array(holes)); + } + rest -= ring.len(); + } + return None; + } // Bulge-Griff (Index ≥ n): Segment-Mitte senkrecht zur Sehne → Bogen dieses Segments. let seg = index - n as f64; let k = index_in(seg, n)?; @@ -1088,7 +1102,15 @@ pub fn drawing_vertices(g: &Value, scale: f64) -> Option> { "line" | "xline" | "ray" => vec![p("a"), p("b")], "polyline" => { let bulge = arr(field(g, "bulge")); - polyline_vertices(pts("pts"), truthy(field(g, "closed")), |i| num_or(bulge.get(i), 0.0)) + let closed = truthy(field(g, "closed")); + let mut out = polyline_vertices(pts("pts"), closed, |i| num_or(bulge.get(i), 0.0)); + // Loch-Ecken hinter den Bogen-Griffen (Index ≥ 2n); nur geschlossene Polylinien tragen Löcher. + if closed && out.len() >= 6 { + for h in arr(field(g, "holes")) { + out.extend(arr(Some(h)).iter().map(xy)); + } + } + out } "rect" | "image" => rect_corners(g).to_vec(), "circle" => { @@ -1328,6 +1350,21 @@ mod tests { assert_eq!(crate::ops::ops_to_json(&ops), r#"[{"kind":"add","collection":"ceilingTypes","items":[{"id":"ct-1","name":"Decke","layers":[{"componentId":"c","thickness":0.25}]}]},{"kind":"replace","collection":"ceilings","entity":{"id":"c1","wallTypeId":"wt","ceilingTypeId":"ct-1"}}]"#); } + #[test] + fn loch_ecken_haben_griffe() { + let pl = |o: bool| json!({"id": "d", "geom": {"shape": "polyline", "closed": o, "pts": [{"x": 0, "y": 0}, {"x": 4, "y": 0}, {"x": 4, "y": 4}, {"x": 0, "y": 4}], + "holes": [[{"x": 1, "y": 1}, {"x": 2, "y": 1}, {"x": 2, "y": 2}]]}}); + let v = drawing_vertices(&pl(true)["geom"], 100.0).unwrap(); + assert_eq!(v.len(), 4 + 4 + 3); + assert_eq!(v[9], (2.0, 1.0)); + let r = drawing_grip(&pl(true), 9.0, 3.0, 1.5, 100.0).unwrap(); + assert_eq!((r["geom"]["holes"][0][1]["x"].as_f64(), r["geom"]["holes"][0][1]["y"].as_f64()), (Some(3.0), Some(1.5))); + assert_eq!(r["geom"]["pts"].as_array().unwrap().len(), 4); + assert!(drawing_grip(&pl(true), 11.0, 0.0, 0.0, 100.0).is_none()); + // Bestehende Indizes bleiben: Bogen-Griff 4..8. + assert!(drawing_grip(&pl(true), 5.0, 2.0, -1.0, 100.0).unwrap()["geom"]["bulge"].is_array()); + } + #[test] fn griffe_und_kanten() { let g = json!({"shape": "polyline", "closed": true, "pts": [{"x": 0, "y": 0}, {"x": 2, "y": 0}, {"x": 2, "y": 2}], "bulge": [0, 0.5, 0]});