7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 09:01:42 +00:00

Save schematic symbol field and unit by ordinal sheet instance.

Use the ordinal symbol reference and unit when saving schematics to
prevent file changes instead of the first instance.  The first instance
would change when sheets were moved and the hierarchy order changed.
The ordinal instance is defined as the first sheet instance when the
hierarchy sorted by page number.
This commit is contained in:
Wayne Stambaugh 2024-12-19 09:19:35 -05:00
parent d79b736e57
commit c4e2c0d3ec
4 changed files with 33 additions and 11 deletions

View File

@ -691,10 +691,30 @@ void SCH_IO_KICAD_SEXPR::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSche
mirrorY ? "y" : "" );
}
// The symbol unit is always set to the first instance regardless of the current sheet
// The symbol unit is always set to the ordianal instance regardless of the current sheet
// instance to prevent file churn.
int unit = ( aSymbol->GetInstances().size() == 0 ) ? aSymbol->GetUnit()
: aSymbol->GetInstances()[0].m_Unit;
SCH_SYMBOL_INSTANCE ordinalInstance;
ordinalInstance.m_Reference = aSymbol->GetPrefix();
const SCH_SCREEN* parentScreen = static_cast<const SCH_SCREEN*>( aSymbol->GetParent() );
wxASSERT( parentScreen );
if( parentScreen && m_schematic )
{
std::optional<SCH_SHEET_PATH> ordinalPath =
m_schematic->Hierarchy().GetOrdinalPath( parentScreen );
wxASSERT( ordinalPath );
if( ordinalPath )
aSymbol->GetInstance( ordinalInstance, ordinalPath->Path() );
else if( aSymbol->GetInstances().size() )
ordinalInstance = aSymbol->GetInstances()[0];
}
int unit = ordinalInstance.m_Unit;
if( aForClipboard && aRelativePath )
{
@ -732,7 +752,7 @@ void SCH_IO_KICAD_SEXPR::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSche
// sheet instance to prevent file churn.
if( id == REFERENCE_FIELD )
{
field.SetText( aSymbol->GetInstances()[0].m_Reference );
field.SetText( ordinalInstance.m_Reference );
}
else if( id == VALUE_FIELD )
{

View File

@ -221,9 +221,7 @@ SCH_SHEET_LIST SCHEMATIC::Hierarchy() const
void SCHEMATIC::RefreshHierarchy()
{
wxLogDebug( wxS( "Refreshing schematic heirarchy." ) );
m_hierarchy = SCH_SHEET_LIST( m_rootSheet );
m_hierarchy = BuildSheetListSortedByPageNumbers();
}

View File

@ -96,7 +96,11 @@ public:
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
{
return SCH_SHEET_LIST( m_rootSheet );
SCH_SHEET_LIST hierarchy( m_rootSheet );
hierarchy.SortByPageNumbers();
return hierarchy;
}
SCH_SHEET_LIST BuildUnorderedSheetList() const

View File

@ -417,11 +417,11 @@ void HIERARCHY_PANE::onRightClick( wxTreeItemId aItem )
if( dlg.ShowModal() == wxID_OK && dlg.GetValue() != itemData->m_SheetPath.GetPageNumber() )
{
SCH_COMMIT commit( m_frame );
SCH_SHEET_PATH parentPath = itemData->m_SheetPath;
parentPath.pop_back();
m_frame->SaveCopyInUndoList( parentPath.LastScreen(), itemData->m_SheetPath.Last(),
UNDO_REDO::CHANGED, false );
commit.Modify( itemData->m_SheetPath.Last(), parentPath.LastScreen() );
itemData->m_SheetPath.SetPageNumber( dlg.GetValue() );
@ -431,7 +431,7 @@ void HIERARCHY_PANE::onRightClick( wxTreeItemId aItem )
m_frame->OnPageSettingsChange();
}
m_frame->OnModify();
commit.Push( wxS( "Change sheet page number." ) );
UpdateLabelsHierarchyTree();
}