diff --git a/common/widgets/net_selector.cpp b/common/widgets/net_selector.cpp index acf2ec8580..2e54c70adf 100644 --- a/common/widgets/net_selector.cpp +++ b/common/widgets/net_selector.cpp @@ -46,6 +46,7 @@ wxDEFINE_EVENT( NET_SELECTED, wxCommandEvent ); #endif #define NO_NET _( "" ) +#define CREATE_NET _( "" ) class NET_SELECTOR_COMBOPOPUP : public wxPanel, public wxComboPopup @@ -58,6 +59,7 @@ public: m_minPopupWidth( -1 ), m_maxPopupHeight( 1000 ), m_netinfoList( nullptr ), + m_board( nullptr ), m_selectedNetcode( 0 ), m_focusHandler( nullptr ) { } @@ -122,6 +124,11 @@ public: rebuildList(); } + void SetBoard( BOARD* aBoard ) + { + m_board = aBoard; + } + void SetIndeterminate() { m_selectedNetcode = -1; } bool IsIndeterminate() { return m_selectedNetcode == -1; } @@ -171,8 +178,10 @@ public: void Accept() { - wxString selectedNetName; - int selection = m_listBox->GetSelection(); + wxString selectedNetName; + wxString remainingName; + int selection = m_listBox->GetSelection(); + wxString prefix = CREATE_NET; if( selection >= 0 ) selectedNetName = m_listBox->GetString( (unsigned) selection ); @@ -187,6 +196,28 @@ public: m_selectedNetcode = 0; GetComboCtrl()->SetValue( NO_NET ); } + else if( selectedNetName.StartsWith( CREATE_NET, &remainingName ) && + !remainingName.IsEmpty() ) + { + // Remove the first character ':' and all whitespace + remainingName = remainingName.Mid( 1 ).Trim().Trim( false ); + NETINFO_ITEM *newnet = new NETINFO_ITEM( m_board, remainingName, 0 ); + + m_netinfoList->AppendNet( newnet ); + rebuildList(); + + if( newnet->GetNet() > 0 ) + { + m_selectedNetcode = newnet->GetNet(); + GetComboCtrl()->SetValue( remainingName ); + } + else + { + // This indicates that the NETINFO_ITEM was not successfully appended + // to the list for unknown reasons + delete newnet; + } + } else { NETINFO_ITEM* netInfo = m_netinfoList->GetNetItem( selectedNetName ); @@ -242,7 +273,8 @@ protected: void rebuildList() { wxArrayString netNames; - wxString filter = m_filterCtrl->GetValue().MakeLower(); + wxString netstring = m_filterCtrl->GetValue().MakeLower(); + wxString filter = netstring; if( !filter.IsEmpty() ) filter = wxT( "*" ) + filter + wxT( "*" ); @@ -263,6 +295,12 @@ protected: if( filter.IsEmpty() || wxString( NO_NET ).MakeLower().Matches( filter ) ) netNames.insert( netNames.begin(), NO_NET ); + if( !filter.IsEmpty() && netNames.IsEmpty() ) + { + wxString newnet = wxString::Format( "%s: %s", CREATE_NET, netstring ); + netNames.insert( netNames.begin(), newnet ); + } + m_listBox->Set( netNames ); } @@ -453,6 +491,7 @@ protected: int m_maxPopupHeight; NETINFO_LIST* m_netinfoList; + BOARD* m_board; int m_selectedNetcode; @@ -522,6 +561,12 @@ void NET_SELECTOR::SetNetInfo( NETINFO_LIST* aNetInfoList ) } +void NET_SELECTOR::SetBoard( BOARD* aBoard ) +{ + m_netSelectorPopup->SetBoard( aBoard ); +} + + void NET_SELECTOR::SetSelectedNetcode( int aNetcode ) { m_netSelectorPopup->SetSelectedNetcode( aNetcode ); diff --git a/include/widgets/net_selector.h b/include/widgets/net_selector.h index f3d3463f84..a17d0503c6 100644 --- a/include/widgets/net_selector.h +++ b/include/widgets/net_selector.h @@ -49,6 +49,8 @@ public: void SetNetInfo( NETINFO_LIST* aNetInfoList ); + void SetBoard( BOARD* aBoard ); + void SetSelectedNetcode( int aNetcode ); void SetSelectedNet( const wxString& aNetname ); void SetIndeterminate(); diff --git a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp index 20b4116864..39a31e5281 100644 --- a/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp +++ b/pcbnew/dialogs/dialog_global_edit_tracks_and_vias.cpp @@ -159,6 +159,7 @@ DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::~DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS() void DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists() { // Populate the net filter list with net names + m_netFilter->SetBoard( m_brd ); m_netFilter->SetNetInfo( &m_brd->GetNetInfo() ); m_netFilter->SetSelectedNetcode( m_brd->GetHighLightNetCode() ); diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 9174116668..912f94913b 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -134,6 +134,7 @@ DIALOG_PAD_PROPERTIES::DIALOG_PAD_PROPERTIES( PCB_BASE_FRAME* aParent, D_PAD* aP m_choiceFabProperty->Show( false ); } + m_PadNetSelector->SetBoard( m_board ); m_PadNetSelector->SetNetInfo( &m_board->GetNetInfo() ); m_OrientValidator.SetRange( -360.0, 360.0 ); diff --git a/pcbnew/dialogs/dialog_track_via_properties.cpp b/pcbnew/dialogs/dialog_track_via_properties.cpp index 99686b9da4..80a7503489 100644 --- a/pcbnew/dialogs/dialog_track_via_properties.cpp +++ b/pcbnew/dialogs/dialog_track_via_properties.cpp @@ -55,6 +55,7 @@ DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES( PCB_BASE_FRAME* aParen VIATYPE viaType = VIATYPE::NOT_DEFINED; + m_netSelector->SetBoard( aParent->GetBoard() ); m_netSelector->SetNetInfo( &aParent->GetBoard()->GetNetInfo() ); m_TrackLayerCtrl->SetLayersHotkeys( false );