Fix net name to net code map to handle sorting and filtering.

Fixes https://gitlab.com/kicad/code/kicad/issues/8714
This commit is contained in:
Jeff Young 2021-07-03 20:12:30 +01:00
parent ddc20dadc0
commit 4b07a55ef8
1 changed files with 20 additions and 16 deletions

View File

@ -51,7 +51,7 @@ private:
ZONE_SETTINGS m_settings; ZONE_SETTINGS m_settings;
ZONE_SETTINGS* m_ptr; ZONE_SETTINGS* m_ptr;
std::vector<int> m_listIndexToNetCodeMap; std::map<wxString, int> m_displayNameToNetCodeMap;
bool m_netSortingByPadCount; bool m_netSortingByPadCount;
long m_netFiltering; long m_netFiltering;
@ -426,7 +426,7 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
int netcode = 0; int netcode = 0;
if( m_ListNetNameSelection->GetSelection() > 0 ) if( m_ListNetNameSelection->GetSelection() > 0 )
netcode = m_listIndexToNetCodeMap[ m_ListNetNameSelection->GetSelection() ]; netcode = m_displayNameToNetCodeMap[ m_ListNetNameSelection->GetStringSelection() ];
m_settings.m_NetcodeSelection = netcode; m_settings.m_NetcodeSelection = netcode;
@ -543,8 +543,10 @@ static bool sortNetsByNames( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
void DIALOG_COPPER_ZONE::buildAvailableListOfNets() void DIALOG_COPPER_ZONE::buildAvailableListOfNets()
{ {
NETINFO_LIST& netInfo = m_Parent->GetBoard()->GetNetInfo(); NETINFO_LIST& netInfo = m_Parent->GetBoard()->GetNetInfo();
wxArrayString listNetName; wxString displayNetName;
m_listIndexToNetCodeMap.clear(); wxArrayString displayNetNameList;
m_displayNameToNetCodeMap.clear();
if( netInfo.GetNetCount() > 0 ) if( netInfo.GetNetCount() > 0 )
{ {
@ -591,8 +593,9 @@ void DIALOG_COPPER_ZONE::buildAvailableListOfNets()
for( NETINFO_ITEM* net : netBuffer ) for( NETINFO_ITEM* net : netBuffer )
{ {
listNetName.Add( UnescapeString( net->GetNetname() ) ); displayNetName = UnescapeString( net->GetNetname() );
m_listIndexToNetCodeMap.push_back( net->GetNetCode() ); displayNetNameList.Add( displayNetName );
m_displayNameToNetCodeMap[ displayNetName ] = net->GetNetCode();
} }
} }
@ -601,23 +604,24 @@ void DIALOG_COPPER_ZONE::buildAvailableListOfNets()
wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue().Lower(); wxString doNotShowFilter = m_DoNotShowNetNameFilter->GetValue().Lower();
wxString ShowFilter = m_ShowNetNameFilter->GetValue().Lower(); wxString ShowFilter = m_ShowNetNameFilter->GetValue().Lower();
for( unsigned ii = 0; ii < listNetName.GetCount(); ii++ ) for( unsigned ii = 0; ii < displayNetNameList.GetCount(); ii++ )
{ {
if( listNetName[ii].Lower().Matches( doNotShowFilter ) ) if( displayNetNameList[ii].Lower().Matches( doNotShowFilter ) )
{ {
listNetName.RemoveAt( ii ); displayNetNameList.RemoveAt( ii );
ii--; ii--;
} }
else if( !listNetName[ii].Lower().Matches( ShowFilter ) ) else if( !displayNetNameList[ii].Lower().Matches( ShowFilter ) )
{ {
listNetName.RemoveAt( ii ); displayNetNameList.RemoveAt( ii );
ii--; ii--;
} }
} }
} }
listNetName.Insert( wxT( "<no net>" ), 0 ); displayNetName = _( "<no net>" );
m_listIndexToNetCodeMap.insert( m_listIndexToNetCodeMap.begin(), 0 ); displayNetNameList.Insert( displayNetName, 0 );
m_displayNameToNetCodeMap[ displayNetName ] = 0;
// Ensure currently selected net for the zone is visible, regardless of filters // Ensure currently selected net for the zone is visible, regardless of filters
int selectedNetListNdx = 0; int selectedNetListNdx = 0;
@ -629,20 +633,20 @@ void DIALOG_COPPER_ZONE::buildAvailableListOfNets()
if( selectedNet ) if( selectedNet )
{ {
selectedNetListNdx = listNetName.Index( selectedNet->GetNetname() ); selectedNetListNdx = displayNetNameList.Index( selectedNet->GetNetname() );
if( wxNOT_FOUND == selectedNetListNdx ) if( wxNOT_FOUND == selectedNetListNdx )
{ {
// the currently selected net must *always* be visible. // the currently selected net must *always* be visible.
// <no net> is the zero'th index, so pick next lowest // <no net> is the zero'th index, so pick next lowest
listNetName.Insert( selectedNet->GetNetname(), 1 ); displayNetNameList.Insert( selectedNet->GetNetname(), 1 );
selectedNetListNdx = 1; selectedNetListNdx = 1;
} }
} }
} }
m_ListNetNameSelection->Clear(); m_ListNetNameSelection->Clear();
m_ListNetNameSelection->InsertItems( listNetName, 0 ); m_ListNetNameSelection->InsertItems( displayNetNameList, 0 );
m_ListNetNameSelection->SetSelection( selectedNetListNdx ); m_ListNetNameSelection->SetSelection( selectedNetListNdx );
m_ListNetNameSelection->EnsureVisible( selectedNetListNdx ); m_ListNetNameSelection->EnsureVisible( selectedNetListNdx );
} }