From fe1c2310e498655f504fba18f08af82f100604c4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 9 Apr 2019 16:58:23 +0100 Subject: [PATCH] Readjust Edit Symbol Properties when symbol references changes. The new reference may contain different numbers of units and/or different deMorgan conversion settings. Fixes: lp:1822316 * https://bugs.launchpad.net/kicad/+bug/1822316 --- .../dialog_edit_component_in_schematic.cpp | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 13e0f0e31e..bfd24fb281 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -235,11 +235,43 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnBrowseLibrary( wxCommandEvent& event m_libraryNameTextCtrl->SetValue( sel.LibId.Format() ); - // Update the value field for Power symbols LIB_PART* entry = GetParent()->GetLibPart( sel.LibId ); - if( entry && entry->IsPower() ) - m_grid->SetCellValue( VALUE, FDC_VALUE, sel.LibId.GetLibItemName() ); + if( entry ) + { + // Update the value field for Power symbols + if( entry->IsPower() ) + m_grid->SetCellValue( VALUE, FDC_VALUE, sel.LibId.GetLibItemName() ); + + // Update the units control + int unit = m_unitChoice->GetSelection(); + m_unitChoice->Clear(); + + if( entry->GetUnitCount() > 1 ) + { + for( int ii = 1; ii <= entry->GetUnitCount(); ii++ ) + m_unitChoice->Append( LIB_PART::SubReference( ii, false ) ); + + if( unit < 0 || unit >= m_unitChoice->GetCount() ) + unit = 0; + + m_unitChoice->SetSelection( unit ); + m_unitLabel->Enable( true ); + m_unitChoice->Enable( true ); + } + else + { + m_unitChoice->SetSelection( -1 ); + m_unitLabel->Enable( false ); + m_unitChoice->Enable( false ); + } + + // Update the deMorgan conversion controls + bool conversion = m_cbAlternateSymbol->GetValue(); + + m_cbAlternateSymbol->SetValue( conversion && entry->HasConversion() ); + m_cbAlternateSymbol->Enable( entry->HasConversion() ); + } } @@ -373,17 +405,17 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() m_cmp->SetLibId( id, Prj().SchSymbolLibTable(), Prj().SchLibs()->GetCacheLibrary() ); // For symbols with multiple shapes (De Morgan representation) Set the selected shape: - if( m_cbAlternateSymbol->IsEnabled() ) - m_cmp->SetConvert( m_cbAlternateSymbol->GetValue() ? 2 : 1 ); + int conversion = m_cbAlternateSymbol->IsEnabled() + ? m_cbAlternateSymbol->GetValue() + : 0; + m_cmp->SetConvert( conversion ); //Set the part selection in multiple part per package - if( m_cmp->GetUnitCount() > 1 ) - { - int unit_selection = m_unitChoice->GetCurrentSelection() + 1; - - m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection ); - m_cmp->SetUnit( unit_selection ); - } + int unit_selection = m_unitChoice->IsEnabled() + ? m_unitChoice->GetSelection() + 1 + : 0; + m_cmp->SetUnitSelection( &GetParent()->GetCurrentSheet(), unit_selection ); + m_cmp->SetUnit( unit_selection ); switch( m_rbOrientation->GetSelection() ) {