From 62fbaf5da455aff740a6f82e18569f21e5a6b454 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Wed, 22 Apr 2026 22:03:32 +0300 Subject: [PATCH] fix: hide block definition entities from viewport Block-definition geometry (entities stored inside named blocks) was leaking into the viewport when DXF files omit the owner-handle group code (330) on block-content entities. The fix tightens `belongs_to_visible_block`: when `owner_handle` is null, the current layout block-record's `entity_handles` list is used as the authoritative allow-list before falling back to the older "not-in-any-other-block" heuristic. This ensures block definitions are never rendered directly, only when referenced via an INSERT. Bumps version to 0.1.4. Co-Authored-By: Claude Sonnet 4.6 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/scene/mod.rs | 16 +++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 421e740c..cdfab1d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "H7CAD" -version = "0.1.3" +version = "0.1.4" dependencies = [ "acadrust", "bytemuck", diff --git a/Cargo.toml b/Cargo.toml index eeaaafc3..31433981 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "H7CAD" -version = "0.1.3" +version = "0.1.4" edition = "2021" build = "build.rs" diff --git a/src/scene/mod.rs b/src/scene/mod.rs index e512bff7..7024c072 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -429,11 +429,6 @@ impl Scene { } /// Decide whether an entity should be drawn as direct content of `block_handle`. - /// - /// Normal case: entity.owner_handle equals the active layout/model block. - /// Fallback: if owner is null, allow it only when the handle is not listed - /// under any other block record. This prevents block-definition geometry - /// from leaking into the viewport when malformed files omit owner handles. fn belongs_to_visible_block( &self, entity_handle: Handle, @@ -450,6 +445,17 @@ impl Scene { return false; } + // owner_handle is null (common in DXF files that omit group code 330). + // Use the current layout's entity_handles as the authoritative list when + // available — this prevents block-definition geometry from leaking into + // the viewport even when owner handles are missing. + if let Some(br) = self.document.block_records.iter().find(|br| br.handle == block_handle) { + if !br.entity_handles.is_empty() { + return br.entity_handles.contains(&entity_handle); + } + } + + // entity_handles not populated: fall back to "not listed in any other block". !self .document .block_records