STEP export: an inserted assembly's nested parts are placed once (#1895)

Thanks @NOWN-DEV.
This commit is contained in:
NOWN-DEV authored and GitHub committed 2026-10-17 04:08:26 -04:00
1 parent 2831426c51
commit 713111d9df
2 files changed
+52 -4

No files matched your search

@@ -322,3 +322,41 @@ fn a_design_with_a_loose_import_rebuilds_unchanged() {
assert_eq!(shown_boxes(&s), file_boxes(&path));
let _ = std::fs::remove_dir_all(&dir);
}
/// A design whose `Outer` component holds a plate and an `Inner` component placed twice (the
/// first placement turned and moved), with `Outer` itself turned about X and lifted.
fn nested_file(dir: &std::path::Path) -> String {
let mut s = Session::default();
let outer = run(&mut s, "component.create", json!({"name": "Outer"}))["occurrence"].clone();
run(&mut s, "solid.box", json!({"length": 30, "width": 30, "height": 5, "body_name": "Plate"}));
let inner = run(&mut s, "component.create", json!({"name": "Inner"}))["occurrence"].clone();
run(&mut s, "solid.box", json!({"length": 40, "width": 20, "height": 10, "body_name": "Block"}));
run(&mut s, "component.activate", json!({"component": "Outer"}));
run(&mut s, "occurrence.move", json!({"occurrence": inner, "axis": [0, 0, 1], "angle": "90 deg", "translate": [100, 0, 0]}));
run(&mut s, "occurrence.copy", json!({"component": "Inner", "translate": [0, 0, 30]}));
run(&mut s, "component.activate", json!({"component": "root"}));
run(&mut s, "occurrence.move", json!({"occurrence": outer, "space": "world", "axis": [1, 0, 0], "angle": "90 deg", "translate": [0, 0, 50]}));
let path = dir.join("nested.step").to_string_lossy().to_string();
run(&mut s, "file.export", json!({"path": path}));
path
}
#[test]
fn an_inserted_assembly_exports_its_nested_parts_where_they_are() {
let dir = temp_dir("reexport");
let path = nested_file(&dir);
let placed = file_boxes(&path);
assert_eq!(placed.len(), 3, "a plate and two blocks: {placed:?}");
let mut s = Session::default();
run(&mut s, "file.insert_step", json!({"path": path}));
assert_eq!(shown_boxes(&s), placed);
// The whole design as an assembly: every part is placed once, by its occurrences.
let again = dir.join("again.step").to_string_lossy().to_string();
run(&mut s, "file.export", json!({"path": again}));
assert_eq!(file_boxes(&again), placed);
// And inserted again, it shows as the first file did.
let mut back = Session::default();
run(&mut back, "file.insert_step", json!({"path": again}));
assert_eq!(shown_boxes(&back), placed);
let _ = std::fs::remove_dir_all(&dir);
}