From dca6c9d116a2254392b1f49f0c71f190f66201fe Mon Sep 17 00:00:00 2001 From: ramox81 <184937705+ramox81@users.noreply.github.com> Date: Fri, 16 Oct 2026 14:58:28 +0300 Subject: [PATCH] DGNIMPORT: cells inside shared cell definitions are part of the definition; empty cells stay out Co-Authored-By: Claude Opus 5.5 --- src/app/commands/dgn_import.rs | 10 +--------- src/modules/insert/dgn_import.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/commands/dgn_import.rs b/src/app/commands/dgn_import.rs index 4344e4d59..0fe00693b 100644 --- a/src/app/commands/dgn_import.rs +++ b/src/app/commands/dgn_import.rs @@ -715,15 +715,7 @@ fn place_converted( if scene.document.block_records.get(target).is_some() { continue; } - let entities: Vec = entities.into_iter().map(&fix).collect(); - if entities.is_empty() { - // A cell that draws nothing still names a block. - let mut record = codec::tables::block_record::BlockRecord::new(target); - record.handle = scene.document.allocate_handle(); - let _ = scene.document.block_records.add(record); - crate::io::xref::ensure_block_entities(&mut scene.document, target); - continue; - } + let entities = entities.into_iter().map(&fix).collect(); let _ = scene.define_block_from_owned_entities(entities, target, glam::DVec3::ZERO); } for entity in converted.entities { diff --git a/src/modules/insert/dgn_import.rs b/src/modules/insert/dgn_import.rs index 43a984a01..118ed7d8b 100644 --- a/src/modules/insert/dgn_import.rs +++ b/src/modules/insert/dgn_import.rs @@ -616,6 +616,9 @@ struct Converter<'a> { /// (cell, made inside a copy) → copy block name. copies: HashMap<(String, bool), String>, names: Vec, + /// Converting a shared cell definition: the cells inside it are not + /// blocks of their own, their objects are part of the definition. + in_definition: bool, } impl<'a> Converter<'a> { @@ -774,6 +777,9 @@ impl<'a> Converter<'a> { // A cell that is not shared becomes a block of its own ("the // cell's name, else AnonymousCell" and a number) placed at the // origin; its objects keep their layers. + DgnGeom::CellGroup { parts, .. } if self.in_definition => { + self.elements(parts, true, copy, depth + 1) + } DgnGeom::CellGroup { name, parts } => { let base = if name.is_empty() { "AnonymousCell" } else { name.as_str() }; let block = self.unique(&block_name(base)); @@ -864,6 +870,7 @@ pub fn convert(import: &DgnImport, sub_units: bool, explode_text_nodes: bool) -> .collect(), copies: HashMap::new(), names: cells.iter().map(|(name, _)| block_name(name)).collect(), + in_definition: false, }; if !import.v7 { for level in &import.level_order { @@ -877,13 +884,14 @@ pub fn convert(import: &DgnImport, sub_units: bool, explode_text_nodes: bool) -> c.layer(&element, false); } } + c.in_definition = true; for (name, elements) in &cells { let entities = c.elements(elements, true, CellCopy::default(), 0); - // Every named cell becomes a block, even one with nothing it draws. - if !name.is_empty() { + if !name.is_empty() && !entities.is_empty() { c.out.blocks.push((block_name(name), entities)); } } + c.in_definition = false; let entities = c.elements(&top, false, CellCopy::default(), 0); c.out.entities = entities; c.out