forked from 1b-agent/opencadstudio-upstream
Fix: deduplicate layout tabs when opening DXF/DWG files
CadDocument::new() inserts default Layout1; DXF/DWG readers then add the file's own Layout1 on top, producing duplicate tabs with the same name but different handles. layout_names() now deduplicates by name, preferring the entry with a non-null block_record (the real layout from the file). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
a65a09c59e
commit
0b8f9bfa5b
1 file changed
+21
-8
+21
-8
@@ -231,14 +231,27 @@ impl Scene {
|
|||||||
/// Sorted list of layout names: "Model" first, then paper layouts by tab order.
|
/// Sorted list of layout names: "Model" first, then paper layouts by tab order.
|
||||||
pub fn layout_names(&self) -> Vec<String> {
|
pub fn layout_names(&self) -> Vec<String> {
|
||||||
let mut names = vec!["Model".to_string()];
|
let mut names = vec!["Model".to_string()];
|
||||||
let mut paper: Vec<(i16, String)> = self
|
// Deduplicate by name: prefer the entry with a non-null block_record (the
|
||||||
.document
|
// real layout from the file) over the default placeholder created by
|
||||||
.objects
|
// CadDocument::new().
|
||||||
.values()
|
let mut by_name: std::collections::HashMap<String, (i16, Handle)> =
|
||||||
.filter_map(|obj| match obj {
|
Default::default();
|
||||||
ObjectType::Layout(l) if l.name != "Model" => Some((l.tab_order, l.name.clone())),
|
for obj in self.document.objects.values() {
|
||||||
_ => None,
|
if let ObjectType::Layout(l) = obj {
|
||||||
})
|
if l.name == "Model" || l.name.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let entry = by_name
|
||||||
|
.entry(l.name.clone())
|
||||||
|
.or_insert((l.tab_order, l.block_record));
|
||||||
|
if entry.1.is_null() && !l.block_record.is_null() {
|
||||||
|
*entry = (l.tab_order, l.block_record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let mut paper: Vec<(i16, String)> = by_name
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, (order, _))| (order, name))
|
||||||
.collect();
|
.collect();
|
||||||
paper.sort_by_key(|(order, _)| *order);
|
paper.sort_by_key(|(order, _)| *order);
|
||||||
names.extend(paper.into_iter().map(|(_, n)| n));
|
names.extend(paper.into_iter().map(|(_, n)| n));
|
||||||
|
|||||||
Reference in new issue
Block a user