[134] Wandöffnungen beim Kopieren/Reihe/Spiegeln mitkopieren, Türaufschlag beim Spiegeln kehren, Dach-/Deckenöffnungen beim Einfügen
This commit is contained in:
5 files changed
+154
-12
No files matched your search
@@ -2446,6 +2446,15 @@ Reihenfolge = Abhängigkeiten. Neue Geometrie entsteht in Rust ([K]).
|
||||
(`floor_finish_pattern`, [100]), kein Dach — richtig so (Boden des DG). (3) Aussenbemassung: Teilstrecken unter
|
||||
1,5 mm Papier (Bogenfacetten am Erkerscheitel, Mauerversprünge) werden zusammengefasst (`auto_dimensions::thin`); Test
|
||||
`keine_kleinmasse`. · S
|
||||
- ✅ **[134] Wandöffnungen beim Kopieren mitnehmen.** (5.11.) Kopie/Reihe/Verteilen/gespiegelte Kopie (Bewegen,
|
||||
Drehen, Spiegeln, Skalieren) kopieren die Türen/Fenster der kopierten Wände mit (neue ids, `hostWallId` = Wandkopie,
|
||||
`position` unverändert, da die Wand starr mitgeht); mitmarkierte Öffnungen entstehen nur einmal (Öffnungen sind keine
|
||||
eigenen Transformations-Elemente). Spiegeln kehrt den Türaufschlag (`swing` links ↔ rechts, Scharnier bleibt) — jetzt
|
||||
auch beim Verschieben-Spiegeln (vorher blieb die Tür ungespiegelt). Assoziative Bemassung, mit der Wand kopiert:
|
||||
Bezüge auf deren Öffnungen zeigen auf die kopierten Öffnungen (bei starrer Kopie). Einfügen (`cmd_paste`) hängt nun
|
||||
auch Dach-/Deckenöffnungen an Dach-/Deckenkopie (Zwischenablage sammelt sie mit). Tests: `wandoeffnungen_werden_mitkopiert`,
|
||||
`oeffnungen_folgen_kopiertem_wirt`, vitest `elementClipboard`. Offen: Skalieren-Kopie lässt `position`/Breite
|
||||
unverändert (wie Skalieren-Verschieben); nicht in der Tauri-App geprüft. · S
|
||||
|
||||
## Priorität 4 — später
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
//!
|
||||
//! Einfügen = Klone mit neuen ids (`prefix-stamp-k`, [`IdGen`]) auf dem aktiven Geschoss, an
|
||||
//! denselben Modell-Koordinaten (kein Versatz, wie das bisherige Verhalten). Verweise: eine Öffnung
|
||||
//! hängt an ihrer Wirtswand (`hostWallId`) und wird auf die neue Wand umgehängt; ohne mitkopierte
|
||||
//! Wirtswand fällt sie weg (keine Öffnung ohne Wirt). Gruppen-Mitgliedschaften werden nicht
|
||||
//! hängt an ihrer Wirtswand (`hostWallId`) bzw. ihrem Dach/ihrer Decke (`hostRoofId`/`hostCeilingId`,
|
||||
//! [134]) und wird auf die Kopie des Wirts umgehängt; ohne mitkopierten Wirt fällt sie weg (keine
|
||||
//! Öffnung ohne Wirt). Gruppen-Mitgliedschaften werden nicht
|
||||
//! mitkopiert (die Klone sind neue, ungruppierte Elemente).
|
||||
//!
|
||||
//! Rechnung auf rohem JSON (`{...e, id, floorId}`: vorhandene Schlüssel behalten ihre Stelle,
|
||||
@@ -34,24 +35,28 @@ const LISTS: [(&str, &str, &str, &str); 9] = [
|
||||
/// Ops des Einfügens: je Liste ein `add` (leere Listen ohne Op).
|
||||
pub fn paste_ops(clip: &Value, level_id: &str, stamp: &str) -> Vec<Op> {
|
||||
let mut ids = IdGen::new(stamp);
|
||||
let mut wall_ids: HashMap<String, String> = HashMap::new();
|
||||
// Alte → neue ids der Wirte (Wände, Decken, Dächer; ids sind projektweit eindeutig).
|
||||
let mut host_ids: HashMap<String, String> = HashMap::new();
|
||||
let level = Value::String(level_id.to_owned());
|
||||
let mut ops = Vec::new();
|
||||
for (key, collection, prefix, level_field) in LISTS {
|
||||
let mut items = Vec::new();
|
||||
for e in arr(field(clip, key)) {
|
||||
if level_field.is_empty() {
|
||||
// Öffnung: nur mit mitkopierter Wirtswand, umgehängt.
|
||||
let host = field(e, "hostWallId").and_then(Value::as_str).and_then(|h| wall_ids.get(h));
|
||||
let Some(host) = host else { continue };
|
||||
// Öffnung: nur mit mitkopiertem Wirt (Wand, Dach oder Decke), umgehängt.
|
||||
let host = ["hostWallId", "hostRoofId", "hostCeilingId"].into_iter().find_map(|k| {
|
||||
let h = field(e, k).and_then(Value::as_str).filter(|h| !h.is_empty())?;
|
||||
Some((k, host_ids.get(h)?))
|
||||
});
|
||||
let Some((key, host)) = host else { continue };
|
||||
let host = Value::String(host.clone());
|
||||
items.push(with_all(e, vec![("id", Value::String(ids.next(prefix))), ("hostWallId", host)]));
|
||||
items.push(with_all(e, vec![("id", Value::String(ids.next(prefix))), (key, host)]));
|
||||
continue;
|
||||
}
|
||||
let id = ids.next(prefix);
|
||||
if key == "walls" {
|
||||
if matches!(key, "walls" | "ceilings" | "roofs") {
|
||||
if let Some(old) = id_of(e) {
|
||||
wall_ids.insert(old.to_owned(), id.clone());
|
||||
host_ids.insert(old.to_owned(), id.clone());
|
||||
}
|
||||
}
|
||||
items.push(with_all(e, vec![("id", Value::String(id)), (level_field, level.clone())]));
|
||||
@@ -100,6 +105,27 @@ mod tests {
|
||||
assert_eq!(ops[3]["items"][0], json!({"id": "column-s-5", "floorId": "og"}));
|
||||
}
|
||||
|
||||
/// [134] Wand mit Tür und Fenster, Dach mit Dachfenster: alle Öffnungen an den neuen Wirten.
|
||||
#[test]
|
||||
fn oeffnungen_folgen_kopiertem_wirt() {
|
||||
let clip = json!({
|
||||
"walls": [{"id": "w", "start": {"x": 0, "y": 0}, "end": {"x": 5, "y": 0}}],
|
||||
"roofs": [{"id": "r", "outline": []}],
|
||||
"openings": [
|
||||
{"id": "d", "hostWallId": "w", "kind": "door", "position": 1},
|
||||
{"id": "f", "hostWallId": "w", "kind": "window", "position": 3},
|
||||
{"id": "o", "hostWallId": "", "hostRoofId": "r", "hostPoint": {"x": 1, "y": 1}},
|
||||
{"id": "c", "hostWallId": "", "hostCeilingId": "c9"}
|
||||
]
|
||||
});
|
||||
let ops: Vec<Value> = paste_ops(&clip, "eg", "s").iter().map(Op::to_json).collect();
|
||||
let os = ops.iter().find(|o| o["collection"] == "openings").unwrap()["items"].as_array().unwrap().clone();
|
||||
assert_eq!(os.len(), 3, "Deckenöffnung ohne kopierte Decke fällt weg");
|
||||
assert_eq!((&os[0]["hostWallId"], &os[1]["hostWallId"]), (&json!("W-s-1"), &json!("W-s-1")));
|
||||
assert_eq!((&os[0]["position"], &os[1]["position"]), (&json!(1), &json!(3)));
|
||||
assert_eq!((&os[2]["hostRoofId"], &os[2]["hostWallId"]), (&json!("RF-s-2"), &json!("")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leere_oder_kaputte_zwischenablage_ergibt_nichts() {
|
||||
assert!(paste_ops(&json!({}), "og", "s").is_empty());
|
||||
|
||||
@@ -303,6 +303,23 @@ fn surface_host(o: &Value) -> Option<(&'static str, &str)> {
|
||||
s("hostRoofId").map(|id| ("hostRoofId", id)).or_else(|| s("hostCeilingId").map(|id| ("hostCeilingId", id)))
|
||||
}
|
||||
|
||||
/// Wandöffnung ([134]): `position` (ab Wand-Start) bleibt gültig, weil die Wand starr mitgeht; eine
|
||||
/// Spiegelung kehrt den Aufschlag einer Tür (`swing` links ↔ rechts der Wandachse), damit die Tür
|
||||
/// gespiegelt aufschlägt (Händigkeit wechselt). Das Scharnier bleibt am selben Pfosten (Start ↦ Start).
|
||||
fn mv_wall_opening(o: &Value, xf: &Xf) -> Value {
|
||||
let door = field(o, "kind").and_then(Value::as_str) == Some("door") || field(o, "swing").is_some();
|
||||
if !(door && xf.reverses()) {
|
||||
return o.clone();
|
||||
}
|
||||
let right = field(o, "swing").and_then(Value::as_str) == Some("right");
|
||||
with(o, "swing", Value::String(if right { "left" } else { "right" }.into()))
|
||||
}
|
||||
|
||||
/// Wirtswand einer Wandöffnung (leer bei Dach-/Deckenöffnungen).
|
||||
fn wall_host(o: &Value) -> Option<&str> {
|
||||
field(o, "hostWallId").and_then(Value::as_str).filter(|v| !v.is_empty())
|
||||
}
|
||||
|
||||
fn mv_room(r: &Value, xf: &Xf) -> Value {
|
||||
let mut f = vec![("boundary", xf.pts(field(r, "boundary")))];
|
||||
if truthy(field(r, "stampAnchor")) {
|
||||
@@ -594,6 +611,14 @@ pub fn transform_ops(root: &Map<String, Value>, p: &Project, req: &TransformReq)
|
||||
};
|
||||
let walls = Ids::of(sel.wall_ids.iter().map(String::as_str));
|
||||
patch("walls", &|w| walls.has(w) && !locked(w), &|w| mv_wall(w, &xf));
|
||||
// Gespiegelte Wände ([134]): Türen ihrer Öffnungen schlagen gespiegelt auf.
|
||||
if xf.reverses() {
|
||||
let mirrored: std::collections::HashSet<&str> =
|
||||
list(root, "walls").iter().filter(|w| walls.has(w) && !locked(w)).filter_map(|w| id_of(w)).collect();
|
||||
if !mirrored.is_empty() {
|
||||
patch("openings", &|o| wall_host(o).is_some_and(|h| mirrored.contains(h)) && mv_wall_opening(o, &xf) != *o, &|o| mv_wall_opening(o, &xf));
|
||||
}
|
||||
}
|
||||
let draw = Ids::of(sel.drawings());
|
||||
if !draw.is_empty() {
|
||||
let same = |id: &str| (moved.contains(id) || moved_openings.contains(id)).then(|| id.to_owned());
|
||||
@@ -646,8 +671,17 @@ pub fn transform_ops(root: &Map<String, Value>, p: &Project, req: &TransformReq)
|
||||
})
|
||||
.collect();
|
||||
let new_ids: Vec<String> = prefixes.iter().map(|p| ids.next(p)).collect();
|
||||
let copied: std::collections::HashMap<&str, &str> = items.iter().zip(&new_ids).filter_map(|((_, e), n)| Some((id_of(e)?, n.as_str()))).collect();
|
||||
let to_copy = |id: &str| copied.get(id).map(|n| (*n).to_owned());
|
||||
let mut copied: std::collections::HashMap<&str, String> = items.iter().zip(&new_ids).filter_map(|((_, e), n)| Some((id_of(e)?, n.clone()))).collect();
|
||||
// Öffnungen kopierter Wände ([134]) mit neuer id an der neuen Wand — vor den Zeichnungen, damit
|
||||
// Bemassungs-Bezüge auf diese Öffnungen auf die Kopie umgeschrieben werden. Öffnungen sind keine
|
||||
// eigenen Transformations-Elemente; mitmarkierte entstehen so nur einmal.
|
||||
for o in list(root, "openings") {
|
||||
let (Some(oid), Some(nh)) = (id_of(o), wall_host(o).and_then(|h| copied.get(h)).cloned()) else { continue };
|
||||
let nid = ids.next("O");
|
||||
new_openings.push(with_all(&mv_wall_opening(o, &xf), vec![("id", Value::String(nid.clone())), ("hostWallId", Value::String(nh))]));
|
||||
copied.insert(oid, nid);
|
||||
}
|
||||
let to_copy = |id: &str| copied.get(id).cloned();
|
||||
for ((kind, e), new_id) in items.iter().zip(&new_ids) {
|
||||
let (slot, v) = match kind {
|
||||
Kind::Wall => (0, mv_wall(e, &xf)),
|
||||
@@ -1147,6 +1181,66 @@ mod tests {
|
||||
assert_eq!(items[0]["hostPoint"], json!({"x":11,"y":2}));
|
||||
}
|
||||
|
||||
/// [134] Wandöffnungen werden mit ihrer Wand kopiert (Kopie, Reihe, gespiegelte Kopie): neue ids,
|
||||
/// neue Wirtswand, gleiche Lage entlang der Wand; Spiegeln kehrt den Türaufschlag wie beim
|
||||
/// Verschieben-Spiegeln; mitmarkierte Öffnungen entstehen nur einmal; Bemassungs-Bezüge folgen.
|
||||
#[test]
|
||||
fn wandoeffnungen_werden_mitkopiert() {
|
||||
let r = root(json!({
|
||||
"walls":[{"id":"w","start":{"x":0,"y":0},"end":{"x":5,"y":0}},{"id":"w2","start":{"x":0,"y":3},"end":{"x":5,"y":3}}],
|
||||
"openings":[
|
||||
{"id":"d","hostWallId":"w","kind":"door","position":1,"width":0.9,"swing":"left","hinge":"start"},
|
||||
{"id":"f","hostWallId":"w","kind":"window","position":3,"width":1.2},
|
||||
{"id":"x","hostWallId":"w2","kind":"door","position":1,"width":0.9},
|
||||
{"id":"r","hostWallId":"","hostRoofId":"rf","hostPoint":{"x":1,"y":1}}
|
||||
],
|
||||
"drawings2d":[{"id":"m","geom":{"shape":"dimension","pts":[{"x":1,"y":0},{"x":1.9,"y":0}],"refs":[{"id":"d","feature":"opening","index":0},{"id":"d","feature":"opening","index":1}]}}]}));
|
||||
let run = |op: &str, pts: Value, mode: &str, sel: Value, count: f64| {
|
||||
let req: TransformReq = serde_json::from_value(json!({"sel":sel,"op":op,"pts":pts,"mode":mode,"count":count,"stamp":"s"})).unwrap();
|
||||
transform_ops(&r, &Project::default(), &req).iter().map(|o| o.to_json()).collect::<Vec<_>>()
|
||||
};
|
||||
let added = |ops: &[Value], c: &str| ops.iter().find(|o| o["kind"] == "add" && o["collection"] == c).map(|o| o["items"].as_array().unwrap().clone()).unwrap_or_default();
|
||||
// Kopie (Tür + Fenster mitmarkiert): 2 neue Öffnungen an der neuen Wand, nicht doppelt.
|
||||
let ops = run("move", json!([[0, 0], [0, 10]]), "copy", json!({"wallIds":["w"],"openingIds":["d","f"]}), 1.0);
|
||||
let nw = added(&ops, "walls")[0]["id"].as_str().unwrap().to_owned();
|
||||
let os = added(&ops, "openings");
|
||||
assert_eq!(os.len(), 2);
|
||||
for (o, (old, pos)) in os.iter().zip([("d", 1), ("f", 3)]) {
|
||||
assert_eq!(o["hostWallId"], json!(nw));
|
||||
assert_ne!(o["id"], json!(old));
|
||||
assert_eq!(o["position"], json!(pos));
|
||||
}
|
||||
assert_eq!(os[0]["swing"], "left", "Verschieben-Kopie behält den Aufschlag");
|
||||
// Reihe ×3: je Wand Tür + Fenster.
|
||||
let ops = run("move", json!([[0, 0], [0, 10]]), "array", json!({"wallIds":["w"]}), 3.0);
|
||||
let (ws, os) = (added(&ops, "walls"), added(&ops, "openings"));
|
||||
assert_eq!((ws.len(), os.len()), (3, 6));
|
||||
for w in &ws {
|
||||
assert_eq!(os.iter().filter(|o| o["hostWallId"] == w["id"]).count(), 2);
|
||||
}
|
||||
let mut ids: Vec<&str> = os.iter().map(|o| o["id"].as_str().unwrap()).collect();
|
||||
ids.dedup();
|
||||
assert_eq!(ids.len(), 6, "eindeutige ids");
|
||||
// Gespiegelte Kopie: Tür schlägt gespiegelt auf (links → rechts), Scharnier/Lage bleiben.
|
||||
let ops = run("mirror", json!([[0, 1], [5, 1]]), "copy", json!({"wallIds":["w","w2"]}), 1.0);
|
||||
let os = added(&ops, "openings");
|
||||
assert_eq!(os.len(), 3);
|
||||
assert_eq!((&os[0]["swing"], &os[0]["hinge"], &os[0]["position"]), (&json!("right"), &json!("start"), &json!(1)));
|
||||
assert!(os[1].get("swing").is_none(), "Fenster ohne Aufschlag");
|
||||
assert_eq!(os[2]["swing"], "right", "fehlender Aufschlag gilt als links");
|
||||
// Verschieben-Spiegeln kehrt denselben Aufschlag (gleiches Ergebnis wie die gespiegelte Kopie).
|
||||
let ops = run("mirror", json!([[0, 1], [5, 1]]), "move", json!({"wallIds":["w"]}), 1.0);
|
||||
let rep: Vec<&Value> = ops.iter().filter(|o| o["kind"] == "replace" && o["collection"] == "openings").collect();
|
||||
assert_eq!(rep.len(), 1, "nur die Tür ändert sich");
|
||||
assert_eq!((&rep[0]["entity"]["id"], &rep[0]["entity"]["swing"]), (&json!("d"), &json!("right")));
|
||||
// Bemassung auf die Tür, mit der Wand kopiert: Bezug zeigt auf die kopierte Tür.
|
||||
let ops = run("move", json!([[0, 0], [0, 10]]), "copy", json!({"wallIds":["w"],"drawingIds":["m"]}), 1.0);
|
||||
let nd = added(&ops, "openings")[0]["id"].clone();
|
||||
let dim = &added(&ops, "drawings2d")[0];
|
||||
assert_eq!(dim["geom"]["refs"][0]["id"], nd);
|
||||
assert_eq!(dim["geom"]["refs"][1]["id"], nd);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verschieben_und_kopieren() {
|
||||
let r = root(json!({"walls":[{"id":"a","start":{"x":0,"y":0},"end":{"x":1,"y":0},"locked":false},{"id":"b","start":{"x":0,"y":0},"end":{"x":1,"y":0},"locked":true}]}));
|
||||
|
||||
@@ -116,6 +116,13 @@ describe("collectElementClipboard", () => {
|
||||
expect(clip.ceilings.length).toBe(1);
|
||||
expect(isClipboardEmpty(clip)).toBe(false);
|
||||
});
|
||||
|
||||
it("[134] kopiert Deckenöffnungen mit ihrer Decke, nicht ohne sie", () => {
|
||||
const p = project();
|
||||
p.openings!.push({ ...opening("oc", ""), hostCeilingId: "c1", hostPoint: { x: 1, y: 1 } });
|
||||
expect(collectElementClipboard(p, { ...emptySel(), ceilingIds: ["c1"] })!.openings.map((o) => o.id)).toEqual(["oc"]);
|
||||
expect(collectElementClipboard(p, { ...emptySel(), wallIds: ["w1"] })!.openings.map((o) => o.id)).toEqual(["o1"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("pasteElementClipboard", () => {
|
||||
|
||||
@@ -107,7 +107,13 @@ export function collectElementClipboard(
|
||||
// Öffnungen: automatisch mitkopiert, wenn ihre Wirtswand mitkopiert wird
|
||||
// (kaskadiert wie beim Löschen einer Wand/Ebene, unabhängig davon, ob die
|
||||
// Öffnung selbst zusätzlich explizit markiert war, s. Kopfkommentar).
|
||||
const openings = (project.openings ?? []).filter((o) => wallIds.has(o.hostWallId));
|
||||
// Dach-/Deckenöffnungen ([134]) ebenso mit ihrem Dach/ihrer Decke.
|
||||
const openings = (project.openings ?? []).filter(
|
||||
(o) =>
|
||||
wallIds.has(o.hostWallId) ||
|
||||
(o.hostRoofId != null && roofIds.has(o.hostRoofId)) ||
|
||||
(o.hostCeilingId != null && ceilingIds.has(o.hostCeilingId)),
|
||||
);
|
||||
const stairIds = new Set(sel.stairIds);
|
||||
const stairs = (project.stairs ?? []).filter((s) => stairIds.has(s.id));
|
||||
const roomIds = new Set(sel.roomIds);
|
||||
|
||||
Reference in new issue
Block a user