From 2116e272b5fee6683b00d0a9b687125e602ad812 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 26 Sep 2025 10:57:42 -0700 Subject: [PATCH] Maintain units even when opening standalone The unit data is maintained in the instances so we need a temporary instance setting if we do not have the parent sheet Fixes https://gitlab.com/kicad/code/kicad/-/issues/19361 (cherry picked from commit 39ed3c538f9f0316d6fab7ef8cc05441c8334bf7) --- eeschema/sch_reference_list.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/eeschema/sch_reference_list.cpp b/eeschema/sch_reference_list.cpp index 4b2d6eda4f..eba4f13f42 100644 --- a/eeschema/sch_reference_list.cpp +++ b/eeschema/sch_reference_list.cpp @@ -803,6 +803,24 @@ SCH_REFERENCE::SCH_REFERENCE( SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSheetP wxASSERT( aSymbol != nullptr ); m_rootSymbol = aSymbol; + + // Ensure the symbol has instance data for the current sheet path so that the unit selection + // remains consistent even when loading a sheet without symbol instance records (for example + // when editing a subsheet directly). + SCH_SYMBOL_INSTANCE instance; + + if( !aSymbol->GetInstance( instance, aSheetPath.Path(), false ) ) + { + instance.m_Path = aSheetPath.Path(); + instance.m_Reference = aSymbol->GetRef( &aSheetPath, false ); + + if( instance.m_Reference.IsEmpty() ) + instance.m_Reference = aSymbol->GetField( FIELD_T::REFERENCE )->GetText(); + + instance.m_Unit = aSymbol->GetUnit(); + aSymbol->AddHierarchicalReference( instance ); + } + m_unit = aSymbol->GetUnitSelection( &aSheetPath ); m_footprint = aSymbol->GetFootprintFieldText( true, &aSheetPath, false ); m_sheetPath = aSheetPath;