fix(units): make the units selector reach what it names

The status-bar units button wrote INSUNITS, which nothing on screen reads.
INSUNITS only tells the drawing how to scale content arriving from
elsewhere, so picking a unit relabelled the drawing and changed nothing
visible — the selector looked broken because the variable it moved was
invisible.

Point the button at LUNITS instead, the setting that decides how every
coordinate and distance is written, and give the three questions the word
"units" runs together a place each:

- The button offers the five length formats, each shown beside a sample of
  itself, so Engineering and Architectural are told apart by sight.
- UNITS / DDUNITS opens a real dialog: length and angle format and
  precision, the direction angle zero points, whether positive angles run
  clockwise, and the insertion unit. Its sample comes from the same
  formatters the drawing uses, so it cannot drift from the readout.
- DWGUNITS converts. Model geometry, viewport framing, the header's length
  defaults and each dimension style's scale all move together in one undo
  step; paper space is left alone, since the sheet is still the same sheet.
  Locked layers are converted too — a half-converted drawing would be at
  two scales at once.

The coordinate readout formatted at four decimal places whatever the
drawing asked for; it now goes through the same format_length the
properties panel uses. That made the angle formats reachable in turn, so
degrees-minutes-seconds now carries the d/'/" marks that say which
convention it is, and surveyor's units are written at all.

Typed input is still plain decimal: a length the readout writes as
5'-6 1/2" cannot yet be typed back. ANGBASE and ANGDIR are stored but not
yet applied to displayed directions.

Closes #668

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
Hakan SevenandClaude Opus 5 committed 2026-08-07 19:59:09 +03:00
1 parent cfc7c06c6c
commit 523b85f42b
14 files changed
+937 -69

No files matched your search

+96
View File
@@ -3534,11 +3534,107 @@ impl OpenCADStudio {
self.units_popup_open = false;
Task::none()
}
Message::OpenDrawingUnits => {
self.units_popup_open = false;
let header = &self.tabs[self.active_tab].scene.document.header;
self.drawing_units = Some(crate::ui::window::drawing_units::State {
linear_format: header.linear_unit_format,
linear_precision: header.linear_unit_precision,
angular_format: header.angular_unit_format,
angular_precision: header.angular_unit_precision,
clockwise: header.angle_direction != 0,
base_angle: format!("{:.6}", header.angle_base.to_degrees())
.trim_end_matches('0')
.trim_end_matches('.')
.to_string(),
insertion_units: header.insertion_units,
});
self.active_modal = Some(crate::app::ModalKind::DrawingUnits);
Task::none()
}
Message::DrawingUnitsField(field) => {
use crate::ui::window::drawing_units::Field;
let Some(state) = self.drawing_units.as_mut() else {
return Task::none();
};
match field {
Field::LinearFormat(v) => state.linear_format = v,
Field::LinearPrecision(v) => state.linear_precision = v,
Field::AngularFormat(v) => state.angular_format = v,
Field::AngularPrecision(v) => state.angular_precision = v,
Field::Clockwise(v) => state.clockwise = v,
// Kept as typed so a lone "-" or a trailing "." survives
// until the number it is becoming is finished.
Field::BaseAngle(v) => state.base_angle = v,
Field::InsertionUnits(v) => state.insertion_units = v,
}
Task::none()
}
Message::DrawingUnitsApply => {
let Some(state) = self.drawing_units.take() else {
self.active_modal = None;
return Task::none();
};
self.active_modal = None;
let i = self.active_tab;
self.push_undo_snapshot(i, "UNITS");
let header = &mut self.tabs[i].scene.document.header;
header.linear_unit_format = state.linear_format;
header.linear_unit_precision = state.linear_precision;
header.angular_unit_format = state.angular_format;
header.angular_unit_precision = state.angular_precision;
header.angle_direction = i16::from(state.clockwise);
// A base angle that will not parse is a half-finished edit, not
// an instruction to move zero — leave the drawing's own value.
if let Ok(degrees) = state.base_angle.trim().parse::<f64>() {
header.angle_base = degrees.to_radians();
}
header.insertion_units = state.insertion_units;
self.tabs[i].dirty = true;
self.tabs[i].scene.bump_geometry();
self.refresh_properties();
Task::none()
}
Message::SetLinearFormat(code) => {
self.units_popup_open = false;
let i = self.active_tab;
if self.tabs[i].scene.document.header.linear_unit_format == code {
return Task::none();
}
// Every displayed length is written through this, so the whole
// drawing re-reads at once — no geometry moves, only the way it
// is written down.
self.push_undo_snapshot(i, "LUNITS");
self.tabs[i].scene.document.header.linear_unit_format = code;
self.tabs[i].dirty = true;
self.tabs[i].scene.bump_geometry();
self.refresh_properties();
let label = crate::modules::draw::units::linear_format_label(code);
self.command_line
.push_output(crate::tf!("Length format is now {label}.").as_ref());
Task::none()
}
Message::SetDrawingUnits(code) => {
self.units_popup_open = false;
let i = self.active_tab;
let current = self.tabs[i].scene.document.header.insertion_units;
if current == code {
return Task::none();
}
// Relabelling only: the geometry keeps every number it had, and
// now says they count something else. Say so, because picking a
// unit and seeing the drawing sit still otherwise reads as the
// menu having done nothing. (#668)
self.push_undo_snapshot(i, "UNITS");
self.tabs[i].scene.document.header.insertion_units = code;
self.tabs[i].dirty = true;
let label = crate::modules::draw::units::label(code);
self.command_line.push_output(
crate::tf!(
"Drawing unit is now {label}. Geometry unchanged — use DWGUNITS to convert it."
)
.as_ref(),
);
Task::none()
}
Message::ToggleIsolatePopup => {