forked from 1b-agent/opencadstudio-upstream
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:
1 parent
cfc7c06c6c
commit
523b85f42b
14 files changed
+937
-69
No files matched your search
+50
-13
@@ -11,8 +11,8 @@ pub struct UnitContext {
|
||||
pub lunits: i16,
|
||||
/// LUPREC — decimal places (linear)
|
||||
pub luprec: i16,
|
||||
/// AUNITS — 0=Decimal degrees, 1=DMS, 2=Grad, 3=Rad. Surfaced via
|
||||
/// `format_angle`, which is read on demand by code that already
|
||||
/// AUNITS — 0=Decimal degrees, 1=DMS, 2=Grad, 3=Rad, 4=Surveyor. Surfaced
|
||||
/// via `format_angle`, which is read on demand by code that already
|
||||
/// formats angular values via radians.
|
||||
#[allow(dead_code)]
|
||||
pub aunits: i16,
|
||||
@@ -98,26 +98,63 @@ pub fn format_angle(value_rad: f64) -> String {
|
||||
let ctx = unit_context();
|
||||
let prec = ctx.auprec.max(0) as usize;
|
||||
match ctx.aunits {
|
||||
1 => {
|
||||
// DMS — degrees / minutes / seconds.
|
||||
let deg = value_rad.to_degrees();
|
||||
let sign = if deg < 0.0 { "-" } else { "" };
|
||||
let a = deg.abs();
|
||||
let d = a.floor();
|
||||
let m_full = (a - d) * 60.0;
|
||||
let m = m_full.floor();
|
||||
let s = (m_full - m) * 60.0;
|
||||
format!("{}{:.0}°{:.0}'{:.*}\"", sign, d, m, prec, s)
|
||||
}
|
||||
1 => dms(value_rad.to_degrees(), prec),
|
||||
2 => {
|
||||
let g = value_rad.to_degrees() / 0.9;
|
||||
format!("{:.*}g", prec, g)
|
||||
}
|
||||
3 => format!("{:.*}r", prec, value_rad),
|
||||
4 => surveyor(value_rad, prec),
|
||||
_ => format!("{:.*}°", prec, value_rad.to_degrees()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Degrees / minutes / seconds. Each part carries its own mark — `d`, `'`, `"`
|
||||
/// — so the written angle says which convention it is in.
|
||||
fn dms(degrees: f64, prec: usize) -> String {
|
||||
let sign = if degrees < 0.0 { "-" } else { "" };
|
||||
let a = degrees.abs();
|
||||
let d = a.floor();
|
||||
let m_full = (a - d) * 60.0;
|
||||
let m = m_full.floor();
|
||||
let s = (m_full - m) * 60.0;
|
||||
format!("{}{:.0}d{:.0}'{:.*}\"", sign, d, m, prec, s)
|
||||
}
|
||||
|
||||
/// Surveyor's units: a bearing away from north or south, toward east or west,
|
||||
/// so the angle is never more than a quarter turn — `N 45d0'0" E`.
|
||||
///
|
||||
/// Due north, south, east and west have no bearing to quote and are written as
|
||||
/// the single letter, which is also what keeps a 90° angle from reading as the
|
||||
/// contradictory `N 90d0'0" E`.
|
||||
fn surveyor(value_rad: f64, prec: usize) -> String {
|
||||
let deg = value_rad.to_degrees().rem_euclid(360.0);
|
||||
let near = |target: f64| (deg - target).abs() < 1e-9;
|
||||
if near(0.0) {
|
||||
return "E".into();
|
||||
}
|
||||
if near(90.0) {
|
||||
return "N".into();
|
||||
}
|
||||
if near(180.0) {
|
||||
return "W".into();
|
||||
}
|
||||
if near(270.0) {
|
||||
return "S".into();
|
||||
}
|
||||
// Measured from the nearer pole, toward the side the angle falls on.
|
||||
let (pole, bearing, side) = if deg < 90.0 {
|
||||
("N", 90.0 - deg, "E")
|
||||
} else if deg < 180.0 {
|
||||
("N", deg - 90.0, "W")
|
||||
} else if deg < 270.0 {
|
||||
("S", 270.0 - deg, "W")
|
||||
} else {
|
||||
("S", deg - 270.0, "E")
|
||||
};
|
||||
format!("{pole} {} {side}", dms(bearing, prec))
|
||||
}
|
||||
|
||||
/// Two interior triangles covering a quad (flat list, 6 vertices) — the
|
||||
/// click-anywhere pick surface for frame-like entities (image, OLE frame,
|
||||
/// underlay, wipeout). Corners in ring order.
|
||||
|
||||
Reference in new issue
Block a user