fix(dist): respect units settings in DIST measurement output

This commit is contained in:
Karim Jerbi committed 2026-09-22 11:42:56 +01:00
1 parent fcbab57627
commit 00e102607c
8 files changed
+172 -30

No files matched your search

+35
View File
@@ -2403,4 +2403,39 @@ mod find_replace_command_tests {
let _ = app.dispatch_inquiry(cmd, i);
}
}
#[test]
fn dist_command_respects_drawing_units_precision() {
let mut app = OpenCADStudio::new_for_test();
let i = app.active_tab;
// Simulate changing linear precision to 0 via UNITS dialog apply
app.drawing_units = Some(crate::ui::window::drawing_units::State {
linear_format: 2,
linear_precision: 0,
angular_format: 0,
angular_precision: 0,
clockwise: false,
base_angle: "0".into(),
insertion_units: 4,
});
let _ = app.update(Message::DrawingUnitsApply);
// Run DIST command
let _ = app.dispatch_inquiry("DIST", i);
assert!(app.tabs[i].active_cmd.is_some());
// First point
let _ = app.tabs[i].active_cmd.as_mut().unwrap().on_point(glam::DVec3::new(0.0, 0.0, 0.0));
// Second point
let res = app.tabs[i].active_cmd.as_mut().unwrap().on_point(glam::DVec3::new(10.0, 0.0, 0.0));
match res {
crate::command::CmdResult::Measurement(msg) => {
assert!(msg.contains("Distance = 10"), "Expected 'Distance = 10', got: {msg}");
assert!(msg.contains("Delta X = 10"), "Expected 'Delta X = 10', got: {msg}");
assert!(msg.contains("Delta Y = 0"), "Expected 'Delta Y = 0', got: {msg}");
assert!(msg.contains("Delta Z = 0"), "Expected 'Delta Z = 0', got: {msg}");
}
_ => panic!("Expected CmdResult::Measurement"),
}
}
}
+7
View File
@@ -2505,6 +2505,13 @@ impl OpenCADStudio {
if name == "PDMODE" || name == "PDSIZE" {
self.tabs[i].scene.invalidate_point_dependencies();
}
if matches!(name.as_str(), "LUNITS" | "LUPREC" | "AUNITS" | "AUPREC") {
crate::entities::common::set_unit_context(
crate::entities::common::UnitContext::from_header(
&self.tabs[i].scene.document.header,
),
);
}
// ORTHOMODE / OSMODE set the header directly; mirror them into
// the live Ortho / running OSNAP so the constraint + status
// bar follow and the save-time stamp doesn't revert them.