Files
cadcraft/crates/engine/tests/purge_arrow_blocks.rs
T
47e978b58e DXF/DWG: keep a file's own arrowhead blocks with standard names (_Dot, _DotSmall) (#1694)
* DXF/DWG: keep a file's own arrowhead blocks with standard names

Reading dropped every block with a standard arrowhead name (`_Dot`,
`_DotSmall`, ...) that no INSERT used, since CADCraft regenerates its own on
save. A block only a dimension style names (DIMBLK) was dropped too, so
AutoCAD's `_Dot` (a polyline with width) or a user's redefinition came back
as CADCraft's disc of 24 SOLIDs. Now only blocks whose content is exactly what
CADCraft writes are dropped; any other content is kept and saved as it was,
through DXF and DWG. PURGE keeps arrowhead blocks that dimension styles or
dimension overrides name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Arrowheads: compare all properties, trim names in PURGE, test every standard arrow

is_generated_arrow now requires the whole Common to match, so only blocks
exactly as CADCraft writes them are regenerated. PURGE trims arrowhead names
from dimension styles and overrides. A new test writes every standard
arrowhead to DXF and DWG and checks none reads back as a user block. Review
of #1694.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: ffishman <20211677+ffishman@users.noreply.github.com>
2026-10-24 01:48:46 -04:00

26 lines
1.2 KiB
Rust

//! PURGE keeps arrowhead blocks a dimension style or a dimension's overrides name (a file's own
//! `_Dot`, a user's arrow), and still removes blocks nothing references.
use std::sync::Arc;
use cadcraft_engine::Session;
use cadcraft_engine::doc::{Block, Circle, DimStyle, Entity, EntityKind, Handle};
use cadcraft_engine::geom::Vec3;
use serde_json::json;
#[test]
fn purge_keeps_arrowhead_blocks_dimension_styles_name() {
let mut s = Session::new();
let d = s.doc_mut().unwrap();
for (i, name) in ["_Dot", "MyArrow", "Unused"].into_iter().enumerate() {
let mut b = Block::new(name);
b.entities.push(Entity::new(Handle(0x9000 + i as u64), EntityKind::Circle(Circle { center: Vec3::ZERO, radius: 0.5 })));
d.blocks.insert(name.into(), Arc::new(b));
}
d.dim_styles.push(DimStyle { name: "Dots".into(), arrow_block1: " _DOT ".into(), leader_arrow_block: "MyArrow".into(), ..DimStyle::default() });
let r = s.execute("purge", &json!({ "type": "blocks" })).unwrap();
assert_eq!(r["purged"]["blocks"], json!(["Unused"]), "{r}");
let d = s.doc().unwrap();
assert!(d.block("_Dot").is_some() && d.block("MyArrow").is_some());
}