From 8f8fa402798154bae2cbaa3a796b454cb8d11e4f Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 25 Jun 2026 18:44:02 +0300 Subject: [PATCH] fix(scale): restore default scale list when drawing has none (#154) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Driving the annotation / viewport scale picker purely from the drawing's ACAD_SCALELIST regressed every drawing that carries no Scale objects (most fresh drawings and minimal DXF/DWG exports): scale_list() returned empty, so the status-bar scale popup opened with nothing to pick and the button looked dead. Fall back to the standard ratio set (1:500 … 1:1 … 10:1) when the drawing defines no scales of its own; file-defined scales still take precedence whenever present. Also re-enables the viewport-scale picker in the properties panel for those drawings. Co-Authored-By: Claude Opus 4.8 --- src/scene/mod.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 29a8c5139..6673e0f26 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -1685,8 +1685,8 @@ impl Scene { /// viewport_factor)`. The annotation multiplier sizes model-space /// text/dims (50.0 for "1:50"); the viewport factor is the paper/drawing /// ratio (0.02 for "1:50"). Sorted smallest ratio first (1:100 … 1:1 … - /// 10:1). Empty when the drawing carries no scale list — the caller - /// substitutes its built-in defaults. + /// 10:1). Falls back to a standard ratio set when the drawing carries no + /// scale list of its own, so the scale picker is always usable. (#154) pub fn scale_list(&self) -> Vec<(String, f32, f64)> { let mut list: Vec<(String, f32, f64)> = self .document @@ -1708,6 +1708,31 @@ impl Scene { }) .collect(); list.sort_by(|a, b| a.2.partial_cmp(&b.2).unwrap_or(std::cmp::Ordering::Equal)); + if list.is_empty() { + // Many drawings (and minimal DXF/DWG exports) carry no + // ACAD_SCALELIST Scale objects at all. Without a fallback the + // annotation / viewport scale picker would be empty and so appear + // broken. Substitute the standard ratio set — file scales still + // win whenever the drawing actually defines any. (#154) + const DEFAULT_SCALES: &[(&str, f64)] = &[ + ("1:500", 0.002), + ("1:200", 0.005), + ("1:100", 0.01), + ("1:50", 0.02), + ("1:20", 0.05), + ("1:10", 0.1), + ("1:5", 0.2), + ("1:2", 0.5), + ("1:1", 1.0), + ("2:1", 2.0), + ("5:1", 5.0), + ("10:1", 10.0), + ]; + list = DEFAULT_SCALES + .iter() + .map(|&(label, vp)| (label.to_string(), (1.0 / vp) as f32, vp)) + .collect(); + } list }