Fix issues related to m_unit SYMBOL member:

- ensure it is updated in DIALOG_SYMBOL_PROPERTIES
- ensure it is restored after changes in CONNECTION_GRAPH::Recalculate
This commit is contained in:
jean-pierre charras 2022-09-04 18:22:02 +02:00
parent 26ba8e1938
commit 92edee5a08
2 changed files with 25 additions and 2 deletions

View File

@ -491,6 +491,9 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
for( const SCH_SHEET_PATH& sheet : aSheetList )
{
std::vector<SCH_ITEM*> items;
// Store current unit value, to regenerate it after calculations
// (useful in complex hierarchies)
std::vector<std::pair<SCH_SYMBOL*, int>> symbolsChanged;
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
{
@ -498,11 +501,18 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
items.push_back( item );
// Ensure the hierarchy info stored in SCREENS is built and up to date
// (multi-unit symbols and pin mapping)
// (multi-unit symbols)
if( item->Type() == SCH_SYMBOL_T )
{
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
symbol->UpdateUnit( symbol->GetUnitSelection( &sheet ) );
int new_unit = symbol->GetUnitSelection( &sheet );
// Store the initial unit value, to regenerate it after calculations,
// if modified
if( symbol->GetUnit() != new_unit )
symbolsChanged.push_back( { symbol, symbol->GetUnit() } );
symbol->UpdateUnit( new_unit );
}
}
@ -512,6 +522,13 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
// UpdateDanglingState() also adds connected items for SCH_TEXT
sheet.LastScreen()->TestDanglingEnds( &sheet, aChangedItemHandler );
// Restore the m_unit member, to avoid changes in current active sheet path
// after calculations
for( auto& item : symbolsChanged )
{
item.first->UpdateUnit( item.second );
}
}
if( wxLog::IsAllowedTraceMask( ConnProfileMask ) )

View File

@ -476,6 +476,10 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataToWindow()
// If a multi-unit symbol, set up the unit selector and interchangeable checkbox.
if( m_symbol->GetUnitCount() > 1 )
{
// Ensure symbol unit is the currently selected unit (mandatory in complex hierarchies)
// from the current sheet path, because it can be modified by previous calculations
m_symbol->UpdateUnit( m_symbol->GetUnitSelection( &GetParent()->GetCurrentSheet() ) );
for( int ii = 1; ii <= m_symbol->GetUnitCount(); ii++ )
m_unitChoice->Append( LIB_SYMBOL::SubReference( ii, false ) );
@ -799,6 +803,8 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow()
// This must go after OnModify() so that the connectivity graph will have been updated.
GetParent()->GetToolManager()->PostEvent( EVENTS::SelectedItemsModified );
m_symbol->SetUnit( unit_selection );
return true;
}