forked from 1b-agent/opencadstudio-upstream
`viewport_content_wires` cloned model-space tessellations and overwrote `points` with paper-space projections (× scale) but left `pattern_length` and `pattern` at their model-coord values (pre-multiplied by PSLTSCALE's 1/vp_scale). The GPU then compared a paper-coord distance against a model-coord pattern, so dashed linetypes in viewport content collapsed to solid (a typical 9 mm paper line fell inside the first 180 mm dash). Multiply the projected wire's pattern by the same vp scale used for the points. Works for both PSLTSCALE on (paper-uniform dashes) and off (dashes shrink with viewport scale). Adds two diagnostic examples used to track this down: - inspect_lt: which layers/entities carry dashed linetypes - inspect_block: enumerate entities + linetypes inside a named block
117 lines
4.1 KiB
Rust
117 lines
4.1 KiB
Rust
// Summarise linetype usage in a DWG/DXF: which layers use which linetype,
|
|
// and which entities carry an explicit (non-bylayer) dashed linetype.
|
|
//
|
|
// cargo run --release --example inspect_lt -- <file>
|
|
|
|
use acadrust::entities::EntityType;
|
|
use acadrust::io::dwg::DwgReader;
|
|
use std::collections::BTreeMap;
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let path = std::env::args().nth(1).expect("usage: inspect_lt <file>");
|
|
let doc = DwgReader::from_file(&path)?.read()?;
|
|
|
|
println!("─── layers (linetype) ───────────────────");
|
|
let dashed_lts: std::collections::BTreeSet<String> = doc
|
|
.line_types
|
|
.iter()
|
|
.filter(|lt| !lt.elements.is_empty() && !lt.is_continuous())
|
|
.map(|lt| lt.name.clone())
|
|
.collect();
|
|
println!(" dashed linetypes in table: {:?}", dashed_lts);
|
|
println!();
|
|
|
|
let mut dashed_layers: BTreeMap<String, String> = BTreeMap::new();
|
|
for l in doc.layers.iter() {
|
|
if dashed_lts.contains(&l.line_type) {
|
|
dashed_layers.insert(l.name.clone(), l.line_type.clone());
|
|
}
|
|
}
|
|
println!(" layers using a dashed linetype:");
|
|
if dashed_layers.is_empty() {
|
|
println!(" (none)");
|
|
}
|
|
for (n, lt) in &dashed_layers {
|
|
println!(" \"{}\" → \"{}\"", n, lt);
|
|
}
|
|
println!();
|
|
|
|
// Per-entity explicit dashed override (lt field non-empty and non-byLayer/byBlock/Continuous).
|
|
let mut explicit_dashed: u32 = 0;
|
|
let mut by_layer_in_dashed_layer: u32 = 0;
|
|
let mut by_layer_in_continuous: u32 = 0;
|
|
let mut by_kind: BTreeMap<&'static str, u32> = BTreeMap::new();
|
|
let mut sample_explicit: Vec<String> = vec![];
|
|
let mut sample_layer_inh: Vec<String> = vec![];
|
|
|
|
for e in doc.entities() {
|
|
let c = e.common();
|
|
let kind: &'static str = match e {
|
|
EntityType::Line(_) => "Line",
|
|
EntityType::LwPolyline(_) => "LwPolyline",
|
|
EntityType::Polyline(_) => "Polyline",
|
|
EntityType::Polyline2D(_) => "Polyline2D",
|
|
EntityType::Arc(_) => "Arc",
|
|
EntityType::Circle(_) => "Circle",
|
|
EntityType::Spline(_) => "Spline",
|
|
EntityType::Ellipse(_) => "Ellipse",
|
|
EntityType::Insert(_) => "Insert",
|
|
_ => "Other",
|
|
};
|
|
let lt = c.linetype.trim();
|
|
let lt_norm = lt.to_ascii_lowercase();
|
|
let is_bylayer = lt.is_empty() || lt_norm == "bylayer";
|
|
let is_explicit_dashed = !is_bylayer
|
|
&& lt_norm != "byblock"
|
|
&& lt_norm != "continuous"
|
|
&& dashed_lts.iter().any(|d| d.eq_ignore_ascii_case(lt));
|
|
if is_explicit_dashed {
|
|
explicit_dashed += 1;
|
|
*by_kind.entry(kind).or_default() += 1;
|
|
if sample_explicit.len() < 6 {
|
|
sample_explicit.push(format!(
|
|
" [{:?}] {} layer=\"{}\" lt=\"{}\" lt_scale={:.4}",
|
|
c.handle, kind, c.layer, lt, c.linetype_scale
|
|
));
|
|
}
|
|
} else if is_bylayer && dashed_layers.contains_key(&c.layer) {
|
|
by_layer_in_dashed_layer += 1;
|
|
if sample_layer_inh.len() < 6 {
|
|
sample_layer_inh.push(format!(
|
|
" [{:?}] {} layer=\"{}\" (inherits \"{}\") lt_scale={:.4}",
|
|
c.handle,
|
|
kind,
|
|
c.layer,
|
|
dashed_layers.get(&c.layer).unwrap(),
|
|
c.linetype_scale
|
|
));
|
|
}
|
|
} else if is_bylayer {
|
|
by_layer_in_continuous += 1;
|
|
}
|
|
}
|
|
|
|
println!("─── entities w/ explicit dashed lt ──────");
|
|
println!(" total: {}", explicit_dashed);
|
|
for (k, v) in &by_kind {
|
|
println!(" {}: {}", k, v);
|
|
}
|
|
for s in &sample_explicit {
|
|
println!("{}", s);
|
|
}
|
|
println!();
|
|
|
|
println!("─── entities inheriting dashed via layer:");
|
|
println!(" total: {}", by_layer_in_dashed_layer);
|
|
for s in &sample_layer_inh {
|
|
println!("{}", s);
|
|
}
|
|
println!();
|
|
println!(
|
|
"─── entities bylayer/continuous: {}",
|
|
by_layer_in_continuous
|
|
);
|
|
|
|
Ok(())
|
|
}
|