33#include <wx/display.h>
34#include <wx/valtext.h>
35#include <wx/listbox.h>
36#include <wx/stattext.h>
38#include <wx/textctrl.h>
44#if defined( __WXOSX_MAC__ )
45 #define POPUP_PADDING 2
46 #define LIST_ITEM_PADDING 5
47 #define LIST_PADDING 5
48#elif defined( __WXMSW__ )
49 #define POPUP_PADDING 0
50 #define LIST_ITEM_PADDING 2
51 #define LIST_PADDING 5
53 #define POPUP_PADDING 0
54 #define LIST_ITEM_PADDING 6
55 #define LIST_PADDING 5
58#define NO_NET _( "<no net>" )
59#define CREATE_NET _( "<create net>" )
77 bool Create(wxWindow* aParent)
override
79 wxPanel::Create( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER );
81 wxBoxSizer* mainSizer;
82 mainSizer =
new wxBoxSizer( wxVERTICAL );
84 wxStaticText* filterLabel =
new wxStaticText(
this, wxID_ANY,
_(
"Filter:" ) );
85 mainSizer->Add( filterLabel, 0, wxEXPAND, 0 );
87 m_filterCtrl =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
88 wxDefaultSize, wxTE_PROCESS_ENTER );
94 m_listBox =
new wxListBox(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0,
nullptr,
95 wxLB_SINGLE|wxLB_NEEDED_SB );
96 mainSizer->Add(
m_listBox, 0, wxEXPAND|wxTOP, 2 );
98 SetSizer( mainSizer );
168 return wxEmptyString;
200 wxString selectedNetName;
201 wxString escapedNetName;
202 wxString remainingName;
203 int selection =
m_listBox->GetSelection();
206 selectedNetName =
m_listBox->GetString( (
unsigned) selection );
211 escapedNetName = it->second;
213 escapedNetName = selectedNetName;
222 else if( escapedNetName ==
NO_NET )
225 GetComboCtrl()->SetValue(
NO_NET );
227 else if( escapedNetName.StartsWith(
CREATE_NET, &remainingName ) &&
228 !remainingName.IsEmpty() )
231 remainingName = remainingName.Mid( 1 ).Trim().Trim(
false );
238 if( board !=
nullptr )
239 board->
Add( newnet );
254 if( board !=
nullptr )
266 if( netInfo ==
nullptr || netInfo->
GetNetCode() == 0 )
269 GetComboCtrl()->SetValue(
NO_NET );
278 wxCommandEvent changeEvent( NET_SELECTED );
279 wxPostEvent( GetComboCtrl(), changeEvent );
294 for(
size_t i = 0; i <
m_listBox->GetCount(); ++i )
297 listWidth = std::max( listWidth, itemWidth +
LIST_PADDING * 3 );
300 wxSize listSize( listWidth, listHeight );
301 wxSize popupSize( listWidth, listTop + listHeight );
303 SetSize( popupSize );
304 GetParent()->SetSize( popupSize );
314 wxArrayString netNames;
315 wxString netstring =
m_filterCtrl->GetValue().Trim().Trim(
false );
316 wxString
filter = netstring.Lower();
325 if( netinfo->GetNetCode() > 0 && netinfo->IsCurrent() )
329 if(
filter.IsEmpty() || wxString( netname ).MakeLower().Matches(
filter ) )
331 netNames.push_back( netname );
337 std::sort( netNames.begin(), netNames.end(),
338 [](
const wxString& lhs,
const wxString& rhs )
340 return StrNumCmp( lhs, rhs, true ) < 0;
346 netNames.insert( netNames.begin(),
NO_NET );
351 netNames.insert( netNames.end(), newnet );
363 static wxPoint lastPos;
364 wxPoint screenPos = wxGetMousePosition();
366 if( screenPos != lastPos )
382 if(
m_listBox->GetScreenRect().Contains( aScreenPos ) )
386 wxPoint relativePos =
m_listBox->ScreenToClient( aScreenPos );
387 int item =
m_listBox->HitTest( relativePos );
392 else if(
m_filterCtrl->GetScreenRect().Contains( aScreenPos ) )
403 if( aEvent.GetEventObject() ==
m_listBox )
410 wxWindow* window =
dynamic_cast<wxWindow*
>( aEvent.GetEventObject() );
414 wxPoint screenPos = window->ClientToScreen( aEvent.GetPosition() );
416 if(
m_listBox->GetScreenRect().Contains( screenPos ) )
418 wxPoint localPos =
m_listBox->ScreenToClient( screenPos );
428 switch( aEvent.GetKeyCode() )
434 m_parent->NavigateIn( ( aEvent.ShiftDown() ? 0 : wxNavigationKeyEvent::IsForward ) |
435 ( aEvent.ControlDown() ? wxNavigationKeyEvent::WinChange : 0 ) );
448 case WXK_NUMPAD_DOWN:
499 if( aEvent.GetKeyCode() == WXK_BACK )
507 int ch = aEvent.GetUnicodeKey();
513 ch = aEvent.GetKeyCode();
514 isPrintable = ch > WXK_SPACE && ch < WXK_START;
519 wxString
text(
static_cast<wxChar
>( ch ) );
522 if( !aEvent.ShiftDown() )
555 const wxSize &size,
long style ) :
556 wxComboCtrl( parent, id, wxEmptyString, pos, size, style|wxCB_READONLY|wxTE_PROCESS_ENTER )
575 int key = aEvt.GetKeyCode();
585 else if( key == WXK_RETURN && aEvt.ShiftDown() )
587 wxPostEvent( m_parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
591 else if( key == WXK_RETURN || key == WXK_DOWN || key == WXK_NUMPAD_DOWN || key == WXK_SPACE )
597 else if( key > WXK_SPACE && key < WXK_START )
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Handle the data for a net.
const wxString & GetNetname() const
Container for NETINFO_ITEM elements, which are the nets.
BOARD * GetParent() const
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
NETINFO_ITEM * GetNetItem(int aNetCode) const
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
wxString m_indeterminateString
NET_SELECTOR_COMBOPOPUP * m_netSelectorPopup
NET_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0)
void SetBoard(BOARD *aBoard)
void SetIndeterminateString(const wxString &aString)
void SetSelectedNetcode(int aNetcode)
void onKeyDown(wxKeyEvent &aEvt)
void SetNetInfo(NETINFO_LIST *aNetInfoList)
void SetSelectedNet(const wxString &aNetname)
wxString GetSelectedNetname()
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
wxDEFINE_EVENT(NET_SELECTED, wxCommandEvent)
#define LIST_ITEM_PADDING
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
wxString UnescapeString(const wxString &aSource)
Functions to provide common constants and other functions to assist in making a consistent UI.