feat(scale): drive scales from the drawing's scale list
Read the model-space annotation scale from the standard CANNOSCALE / CANNOSCALEVALUE header variables instead of a user-variable hack, and populate both the status-bar scale picker and the viewport Scale property purely from the drawing's ACAD_SCALELIST — no built-in fallback set. Xref-derived scales (`_XREF` suffix, `name|` prefix) are filtered out so only the host drawing's own scales appear. Bumps the patched acadrust to the commit that adds CANNOSCALE/ CANNOSCALEVALUE read/write. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
b5ce376d5c
commit
edc8cbc969
8 changed files with 128 additions and 30 deletions
|
|
@ -25,6 +25,20 @@ const STANDARD_SCALES: &[(&str, f64)] = &[
|
|||
("10:1", 10.0),
|
||||
];
|
||||
|
||||
/// Parse a scale ratio name to its paper/drawing factor: "1:50" -> 0.02,
|
||||
/// "2:1" -> 2.0. Also accepts a plain decimal ("0.02").
|
||||
fn parse_scale_ratio(label: &str) -> Option<f64> {
|
||||
if let Some((a, b)) = label.split_once(':') {
|
||||
let n: f64 = a.trim().parse().ok()?;
|
||||
let d: f64 = b.trim().parse().ok()?;
|
||||
if d.abs() > 1e-12 {
|
||||
return Some(n / d);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
label.trim().parse::<f64>().ok()
|
||||
}
|
||||
|
||||
fn scale_label(scale: f64) -> String {
|
||||
for (label, val) in STANDARD_SCALES {
|
||||
if (scale - val).abs() < val * 0.01 {
|
||||
|
|
@ -411,9 +425,11 @@ fn apply_geom_prop(vp: &mut Viewport, field: &str, value: &str) {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
// Standard scale picker.
|
||||
// Scale picker. The label is a ratio name from the drawing's scale list
|
||||
// ("1:50", "2:1"); parse it to the paper/drawing factor so any named
|
||||
// scale resolves, not just the built-in set.
|
||||
if field == "vscale_std" {
|
||||
if let Some(&(_, scale)) = STANDARD_SCALES.iter().find(|(label, _)| *label == value) {
|
||||
if let Some(scale) = parse_scale_ratio(value) {
|
||||
vp.custom_scale = scale;
|
||||
if scale > 1e-9 {
|
||||
vp.view_height = vp.height / scale;
|
||||
|
|
|
|||
Loading…
Reference in a new issue