Document Settings: design units (document.units: mm, cm, m, in, ft; values keep their meaning) from the browser's Units row, display precision row; new designs take the preferred units; the Properties window shows lengths, areas and volumes in the design's units with the chosen precision

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
bherbruckandClaude Opus 5.5 committed 2026-10-08 12:09:31 +00:00
1 parent c99e7e41ec
commit 13070abc55
6 files changed
+127 -17

No files matched your search

+29
View File
@@ -24,6 +24,9 @@ pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("browser.rename_group", "Rename Group", rename_group).params("group: id, name"),
CommandSpec::new("browser.move", "Move Browser Items", move_items)
.params("folder, component?, items: [keys]; group?: id (into it; omit to take them out of groups); before?: key (position in the group)"),
CommandSpec::new("document.units", "Change Design Units", document_units)
.icon("settings")
.params("units: mm|cm|m|in|ft (display and unit-less parameters; values keep their meaning)"),
CommandSpec::new("view.save", "New Named View", view_save)
.icon("camera")
.params("name?; camera: {target: [x,y,z], yaw, pitch, distance, fov?} (replaces a view of the same name)"),
@@ -152,6 +155,18 @@ fn order(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({}))
}
fn document_units(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "document.units";
let u = str_(p, "units").ok_or_else(|| bad(cmd, "`units` is required"))?;
if !["mm", "cm", "m", "in", "ft"].contains(&u) {
return Err(bad(cmd, "`units` must be mm, cm, m, in or ft"));
}
if s.doc.units != u {
s.doc_mut().units = u.to_string();
}
Ok(json!({ "units": u }))
}
fn view_save(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "view.save";
let c = p.get("camera").ok_or_else(|| bad(cmd, "`camera` is required"))?;
@@ -365,6 +380,20 @@ mod tests {
assert!(s.execute("sketch.redefine", &json!({"sketch": 999, "plane": "XY"})).is_err());
}
#[test]
fn design_units_change_without_moving_geometry() {
let mut s = Session::default();
run(&mut s, "PrimitiveBox", json!({"length": 20, "width": 10, "height": 5}));
let vol = |s: &mut Session| run(s, "MeasureCommand", json!({}))["total"]["volume_mm3"].as_f64().unwrap();
let v0 = vol(&mut s);
run(&mut s, "document.units", json!({"units": "in"}));
assert_eq!(s.doc.units, "in");
assert!((vol(&mut s) - v0).abs() < 1e-6, "feature inputs keep their millimetres");
assert!(s.execute("document.units", &json!({"units": "furlong"})).is_err());
run(&mut s, "UndoCommand", json!({}));
assert_eq!(s.doc.units, "mm");
}
#[test]
fn named_views_are_saved_renamed_and_deleted() {
let mut s = Session::default();