[213] Kameras in Verschieben/Kopieren/Drehen/Spiegeln, Mehrfachauswahl und Zwischenablage: Standpunkt und Ziel werden abgebildet, Kopien heissen „… Kopie“; Gruppen offen, IFC bewusst ohne Kameras

This commit is contained in:
Claude committed 2026-11-13 18:54:29 +00:00
1 parent 78e6ff0d82
commit 6cb4885ac2
10 files changed
+173 -18

No files matched your search

+35 -9
View File
@@ -20,7 +20,7 @@ use std::collections::HashMap;
/// Listen der Zwischenablage: (Schlüssel in `clip`, Projekt-Liste, id-Präfix, Geschoss-Feld).
/// Reihenfolge = Reihenfolge der ids und der Ops (Wände vor Öffnungen).
const LISTS: [(&str, &str, &str, &str); 10] = [
const LISTS: [(&str, &str, &str, &str); 11] = [
("walls", "walls", "W", "floorId"),
("drawings", "drawings2d", "dr2d", "levelId"),
("ceilings", "ceilings", "C", "floorId"),
@@ -31,15 +31,19 @@ const LISTS: [(&str, &str, &str, &str); 10] = [
("extrudedSolids", "extrudedSolids", "extrude", "levelId"),
("columns", "columns", "column", "floorId"),
("trees", "trees", "tree", "floorId"),
("cameras", "cameras", "camera", "floorId"),
];
/// 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> {
/// `root` = das Projekt-Dokument (nur für die Namen vorhandener Kameras, [213]).
pub fn paste_ops(root: &serde_json::Map<String, Value>, clip: &Value, level_id: &str, stamp: &str) -> Vec<Op> {
let mut ids = IdGen::new(stamp);
// 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();
// [213] Eingefügte Kameras heissen „… Kopie“ (nummeriert bei Kollision), damit Namen eindeutig bleiben.
let mut cam_names: std::collections::HashSet<String> = arr(root.get("cameras")).iter().filter_map(|c| field(c, "name").and_then(Value::as_str).map(String::from)).collect();
for (key, collection, prefix, level_field) in LISTS {
let mut items = Vec::new();
for e in arr(field(clip, key)) {
@@ -60,7 +64,12 @@ pub fn paste_ops(clip: &Value, level_id: &str, stamp: &str) -> Vec<Op> {
host_ids.insert(old.to_owned(), id.clone());
}
}
items.push(with_all(&as_copy(e), vec![("id", Value::String(id)), (level_field, level.clone())]));
let mut v = with_all(&as_copy(e), vec![("id", Value::String(id)), (level_field, level.clone())]);
if key == "cameras" {
let name = crate::cmd_transform::copy_name(field(e, "name").and_then(Value::as_str).unwrap_or(""), &mut cam_names);
v = with_all(&v, vec![("name", Value::String(name))]);
}
items.push(v);
}
if !items.is_empty() {
ops.push(Op::Add { collection: collection.into(), items, at: None });
@@ -82,7 +91,7 @@ mod tests {
"openings": [{"id": "o1", "hostWallId": "w1", "ifcGlobalId": "1AbcDEFghijKLMNOPQRSt2"}],
"columns": [{"id": "c1", "floorId": "eg", "ifcGlobalId": "2AbcDEFghijKLMNOPQRSt3"}]
});
for op in paste_ops(&clip, "og", "s") {
for op in paste_ops(&Default::default(), &clip, "og", "s") {
for item in op.to_json()["items"].as_array().unwrap() {
assert!(item.get("ifcGlobalId").is_none(), "{item}");
}
@@ -104,7 +113,7 @@ mod tests {
"columns": [{"id": "c1", "floorId": "eg"}],
"rooms": []
});
let ops: Vec<Value> = paste_ops(&clip, "og", "s").iter().map(Op::to_json).collect();
let ops: Vec<Value> = paste_ops(&Default::default(), &clip, "og", "s").iter().map(Op::to_json).collect();
assert_eq!(ops.len(), 4);
assert_eq!(ops[0]["collection"], "walls");
let walls = ops[0]["items"].as_array().unwrap();
@@ -134,7 +143,7 @@ mod tests {
{"id": "c", "hostWallId": "", "hostCeilingId": "c9"}
]
});
let ops: Vec<Value> = paste_ops(&clip, "eg", "s").iter().map(Op::to_json).collect();
let ops: Vec<Value> = paste_ops(&Default::default(), &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")));
@@ -142,10 +151,27 @@ mod tests {
assert_eq!((&os[2]["hostRoofId"], &os[2]["hostWallId"]), (&json!("RF-s-2"), &json!("")));
}
/// [213] Kameras: neue id, aktives Geschoss, Name „… Kopie“ (nummeriert bei Kollision).
#[test]
fn kameras_bekommen_kopie_namen() {
let clip = json!({"cameras": [
{"id": "k1", "type": "camera", "name": "Süd", "floorId": "eg", "position": {"x": 1, "y": 2}, "target": {"x": 5, "y": 2}, "fovDeg": 50},
{"id": "k2", "type": "camera", "name": "Süd", "floorId": "eg", "position": {"x": 1, "y": 2}, "target": {"x": 5, "y": 2}}
]});
let root = json!({"cameras": [{"id": "k1", "name": "Süd"}, {"id": "x", "name": "Süd Kopie"}]});
let ops: Vec<Value> = paste_ops(root.as_object().unwrap(), &clip, "og", "s").iter().map(Op::to_json).collect();
assert_eq!(ops.len(), 1);
assert_eq!(ops[0]["collection"], "cameras");
let c = ops[0]["items"].as_array().unwrap();
assert_eq!((c[0]["id"].as_str(), c[0]["name"].as_str(), c[0]["floorId"].as_str()), (Some("camera-s-1"), Some("Süd Kopie 2"), Some("og")));
assert_eq!(c[1]["name"], "Süd Kopie 3");
assert_eq!((c[0]["fovDeg"].clone(), c[0]["position"].clone()), (json!(50), json!({"x": 1, "y": 2})));
}
#[test]
fn leere_oder_kaputte_zwischenablage_ergibt_nichts() {
assert!(paste_ops(&json!({}), "og", "s").is_empty());
assert!(paste_ops(&json!(null), "og", "s").is_empty());
assert!(paste_ops(&json!({"walls": 3, "openings": [{"id": "o"}]}), "og", "s").is_empty());
assert!(paste_ops(&Default::default(), &json!({}), "og", "s").is_empty());
assert!(paste_ops(&Default::default(), &json!(null), "og", "s").is_empty());
assert!(paste_ops(&Default::default(), &json!({"walls": 3, "openings": [{"id": "o"}]}), "og", "s").is_empty());
}
}