From 92edee5a08db57c923adf02032a629c0b270aac6 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 4 Sep 2022 18:22:02 +0200 Subject: [PATCH] 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 --- eeschema/connection_graph.cpp | 21 +++++++++++++++++-- eeschema/dialogs/dialog_symbol_properties.cpp | 6 ++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index df94495811..4ec87357f1 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -491,6 +491,9 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco for( const SCH_SHEET_PATH& sheet : aSheetList ) { std::vector items; + // Store current unit value, to regenerate it after calculations + // (useful in complex hierarchies) + std::vector> 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( 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 ) ) diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 03f29df6b6..9ae0a567b9 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -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; }