From 9a1eeab53d38111f5f67390e1847d7a197836d43 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Thu, 2 Apr 2026 23:48:17 +0300 Subject: [PATCH] =?UTF-8?q?Feat:=20Phase=206.4=20=E2=80=94=20Draw=20order?= =?UTF-8?q?=20render=20pipeline=20via=20SortEntitiesTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wires_for_block() now looks up the SortEntitiesTable for the current block. When found, wires are sorted by sort_handle.value() so DRAWORDER F/B results are immediately visible in the viewport (not just written to DXF). Entities not in the sort table default to u64::MAX/2 (middle of draw order). Co-Authored-By: Claude Sonnet 4.6 --- src/scene/mod.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/scene/mod.rs b/src/scene/mod.rs index da1faaef4..9a40c5354 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -319,7 +319,18 @@ impl Scene { /// Tessellate all non-invisible entities owned by `block_handle`. fn wires_for_block(&self, block_handle: Handle) -> Vec { - self.document + use acadrust::objects::ObjectType; + + // Find the SortEntitiesTable for this block (if any). + let sort_table = self.document.objects.values().find_map(|obj| { + if let ObjectType::SortEntitiesTable(t) = obj { + if t.block_owner_handle == block_handle { Some(t) } else { None } + } else { + None + } + }); + + let mut wires: Vec = self.document .entities() .filter(|e| { let c = e.common(); @@ -338,7 +349,21 @@ impl Scene { self.belongs_to_visible_block(e.common().handle, c.owner_handle, block_handle) }) .flat_map(|e| self.tessellate_one(e)) - .collect() + .collect(); + + // Apply draw order if a SortEntitiesTable exists and has entries. + if let Some(table) = sort_table { + if !table.is_empty() { + wires.sort_by_key(|w| { + let handle = Self::handle_from_wire_name(&w.name) + .unwrap_or(Handle::NULL); + table.get_sort_handle(handle) + .map(|sh| sh.value()) + .unwrap_or(u64::MAX / 2) // unsorted entities draw in the middle + }); + } + } + wires } /// Decide whether an entity should be drawn as direct content of `block_handle`.