From 2fc96c1d110fbf6134b66df9adae8917a5d68fae Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 3 Feb 2024 17:42:41 +0000 Subject: [PATCH] Ensure stackup material returned is correct after list item deletion --- .../dialog_dielectric_list_manager.cpp | 24 +++++++++++++++++-- .../dielectric_material.h | 12 ++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pcbnew/board_stackup_manager/dialog_dielectric_list_manager.cpp b/pcbnew/board_stackup_manager/dialog_dielectric_list_manager.cpp index c1de2ee969..f31fe99c7d 100644 --- a/pcbnew/board_stackup_manager/dialog_dielectric_list_manager.cpp +++ b/pcbnew/board_stackup_manager/dialog_dielectric_list_manager.cpp @@ -134,6 +134,26 @@ void DIALOG_DIELECTRIC_MATERIAL::onListKeyDown( wxListEvent& event ) { int idx = event.GetIndex(); - if( ( idx > 0 ) && ( event.GetKeyCode() == WXK_DELETE ) ) - m_lcMaterials->DeleteItem( idx ); + switch( event.GetKeyCode() ) + { + case WXK_DELETE: + if( idx >= 0 ) + { + m_lcMaterials->DeleteItem( idx ); + m_materialList.DeleteSubstrate( idx ); + + // Get the new material information for the next item in the list + // (or last if the deleted item was the last item) + int next = ( idx < m_materialList.GetCount() ) ? idx : idx - 1; + + m_lcMaterials->SetItemState( next, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + m_lcMaterials->SetItemState( next, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED ); + m_lcMaterials->EnsureVisible( next ); + } + + break; + + default: + event.Skip(); + } } diff --git a/pcbnew/board_stackup_manager/dielectric_material.h b/pcbnew/board_stackup_manager/dielectric_material.h index f058c6351f..4b4723c259 100644 --- a/pcbnew/board_stackup_manager/dielectric_material.h +++ b/pcbnew/board_stackup_manager/dielectric_material.h @@ -115,6 +115,18 @@ public: m_substrateList.emplace_back( aItem ); return GetCount()-1; } + + /** + * Delete the specified item in the substrate list. + * + * @param aInd is the index in the substrate list to delete + */ + void DeleteSubstrate( int aIdx ) + { + wxCHECK( aIdx > 0 && aIdx < (int) m_substrateList.size(), /* void */ ); + + m_substrateList.erase( m_substrateList.begin() + aIdx ); + } }; #endif // #ifndef DIELECTRIC_MATERIAL_H