component.list: a compact form for large assemblies (#1305)
component.list {compact: true} gives counts of bodies, features, sketches and construction planes instead of their names, lists occurrences without identity transforms and children as occurrence ids; bodies: true keeps body names. The default form is unchanged.
This commit is contained in:
1 parent
9eddb1cbd3
commit
fd19efc6fc
2 files changed
+49
-6
No files matched your search
@@ -539,3 +539,28 @@ fn a_linked_design_brings_its_bodies_in_and_follows_edits_to_the_part_file() {
|
||||
near(&measured["total"]["center_of_mass"][0], 55.0);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// The compact list counts what a component holds and leaves out identity transforms; the full
|
||||
/// list stays as it was.
|
||||
#[test]
|
||||
fn compact_component_list_counts_and_skips_identity_transforms() {
|
||||
let mut s = Session::default();
|
||||
let (component, first) = created(&mut s, "Block");
|
||||
run(&mut s, "solid.box", json!({"length": 1, "width": 1, "height": 1, "body_name": "Cube"}));
|
||||
run(&mut s, "component.activate", json!({"component": "root"}));
|
||||
let second = run(&mut s, "occurrence.copy", json!({"component": component, "translate": [20, 0, 0]}))["occurrence"].as_u64().unwrap();
|
||||
let full = run(&mut s, "component.list", json!({}));
|
||||
let block = |l: &Value| l["components"].as_array().unwrap().iter().find(|c| c["id"] == component).unwrap().clone();
|
||||
assert_eq!(block(&full)["bodies"], json!(["Cube"]));
|
||||
assert!(block(&full)["occurrences"].as_array().unwrap().iter().all(|o| o["transform"].is_array()));
|
||||
let compact = run(&mut s, "component.list", json!({"compact": true}));
|
||||
let b = block(&compact);
|
||||
assert_eq!((&b["bodies"], &b["features"], &b["sketches"]), (&json!(1), &json!(1), &json!(0)), "{b}");
|
||||
let placed = |id: u64| b["occurrences"].as_array().unwrap().iter().find(|o| o["id"] == id).unwrap().clone();
|
||||
assert!(placed(first).get("transform").is_none(), "{b}");
|
||||
assert_eq!(placed(second)["transform"][3][0], 20.0, "{b}");
|
||||
let root = compact["components"].as_array().unwrap().iter().find(|c| c["id"] == 0).unwrap().clone();
|
||||
assert_eq!(root["children"], json!([first, second]), "{root}");
|
||||
// Body names on request.
|
||||
assert_eq!(block(&run(&mut s, "component.list", json!({"compact": true, "bodies": true})))["bodies"], json!(["Cube"]));
|
||||
}
|
||||
Reference in new issue
Block a user