Annotation: annotate all sheet instances for new symbols

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/11841
This commit is contained in:
Mike Williams 2022-07-20 11:40:38 -04:00
parent bf550afa8c
commit d9449b9beb
1 changed files with 41 additions and 14 deletions

View File

@ -117,6 +117,19 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
REENTRANCY_GUARD guard( &m_inPlaceSymbol ); REENTRANCY_GUARD guard( &m_inPlaceSymbol );
// First we need to get all instances of this sheet so we can annotate
// whatever symbols we place on all copies
SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
SCH_SHEET_LIST newInstances =
hierarchy.FindAllSheetsForScreen( m_frame->GetCurrentSheet().LastScreen() );
newInstances.SortByPageNumbers();
// Get a list of all references in the schematic to avoid duplicates wherever
// they're placed
SCH_REFERENCE_LIST existingRefs;
hierarchy.GetSymbols( existingRefs );
existingRefs.SortByReferenceOnly();
if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) ) if( aEvent.IsAction( &EE_ACTIONS::placeSymbol ) )
{ {
historyList = &m_symbolHistoryList; historyList = &m_symbolHistoryList;
@ -171,22 +184,35 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
{ {
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig(); EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
// Then we need to annotate all instances by sheet
for( SCH_SHEET_PATH& instance : newInstances )
{
SCH_REFERENCE newReference( symbol, symbol->GetLibSymbolRef().get(), instance );
SCH_REFERENCE_LIST refs;
refs.AddItem( newReference );
if( symbol->GetLibSymbolRef()->IsPower() ) if( symbol->GetLibSymbolRef()->IsPower() )
{ {
NULL_REPORTER reporter; refs.ReannotateByOptions( UNSORTED, INCREMENTAL_BY_REF, 1, existingRefs,
m_frame->AnnotateSymbols( ANNOTATE_SELECTION, UNSORTED, INCREMENTAL_BY_REF, true, nullptr );
false, 1, false, false, reporter, true );
} }
else if( cfg->m_AnnotatePanel.automatic ) else if( cfg->m_AnnotatePanel.automatic )
{ {
NULL_REPORTER reporter; refs.ReannotateByOptions(
m_frame->AnnotateSymbols( ANNOTATE_SELECTION,
(ANNOTATE_ORDER_T) cfg->m_AnnotatePanel.sort_order, (ANNOTATE_ORDER_T) cfg->m_AnnotatePanel.sort_order,
(ANNOTATE_ALGO_T) cfg->m_AnnotatePanel.method, (ANNOTATE_ALGO_T) cfg->m_AnnotatePanel.method,
cfg->m_AnnotatePanel.recursive, m_frame->Schematic().Settings().m_AnnotateStartNum, existingRefs,
m_frame->Schematic().Settings().m_AnnotateStartNum, false, &hierarchy );
false, false, reporter, true );
refs.UpdateAnnotation();
// Update existing refs for next iteration
for( size_t i = 0; i < refs.GetCount(); i++ )
existingRefs.AddItem( refs[i] );
} }
}
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
}; };
Activate(); Activate();
@ -350,6 +376,7 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
nextSymbol->ClearAnnotation( nullptr, false ); nextSymbol->ClearAnnotation( nullptr, false );
addSymbol( nextSymbol ); addSymbol( nextSymbol );
symbol = nextSymbol; // annotate() looks at symbol, update it
annotate(); annotate();
} }
} }