diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index bbbc881767b..fe75d5dc259 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -130,6 +130,8 @@ set( PCBNEW_DIALOGS dialogs/dialog_SVG_print.cpp dialogs/dialog_SVG_print_base.cpp dialogs/dialog_select_pretty_lib.cpp + dialogs/dialog_select_net_from_list_base.cpp + dialogs/dialog_select_net_from_list.cpp dialogs/dialog_select_pretty_lib_base.cpp dialogs/dialog_set_grid.cpp dialogs/dialog_set_grid_base.cpp diff --git a/pcbnew/dialogs/dialog_select_net_from_list.cpp b/pcbnew/dialogs/dialog_select_net_from_list.cpp new file mode 100644 index 00000000000..9745cfd809d --- /dev/null +++ b/pcbnew/dialogs/dialog_select_net_from_list.cpp @@ -0,0 +1,206 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file dialog_select_net_from_list.cpp + * @brief methods to show available net names and select and highligth a net + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define COL_NETNAME 0 +#define COL_NETINFO 1 + +class DIALOG_SELECT_NET_FROM_LIST: public DIALOG_SELECT_NET_FROM_LIST_BASE +{ +private: + wxString m_selection; + bool m_wasSelected; + BOARD* m_brd; + +public: + DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME * aParent ); + ~DIALOG_SELECT_NET_FROM_LIST(); + + // returns true if a net was selected, and its name in aName + bool GetNetName( wxString& aName ); + +private: + void onCellClick( wxGridEvent& event ); + void onFilterChange( wxCommandEvent& event ); + + void buildNetsList(); +}; + + +void PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event ) +{ + DIALOG_SELECT_NET_FROM_LIST dlg( this ); + wxString netname; + + if( dlg.ShowModal() == wxID_CANCEL || !dlg.GetNetName( netname ) ) + return; + + // Search for the net selected. + NETINFO_ITEM* net = GetBoard()->FindNet( netname ); + + if( net == NULL ) // Should not occur. + return; + + if( IsGalCanvasActive() ) + { + KIGFX::RENDER_SETTINGS* render = GetGalCanvas()->GetView()->GetPainter()->GetSettings(); + render->SetHighlight( true, net->GetNet() ); + + GetGalCanvas()->GetView()->UpdateAllLayersColor(); + GetGalCanvas()->Refresh(); + } + else + { + INSTALL_UNBUFFERED_DC( dc, m_canvas ); + + if( GetBoard()->IsHighLightNetON() ) + HighLight( &dc ); + + GetBoard()->SetHighLightNet( net->GetNet() ); + HighLight( &dc ); + } +} + + +DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent ) + : DIALOG_SELECT_NET_FROM_LIST_BASE( aParent ) +{ + m_brd = aParent->GetBoard(); + m_wasSelected = false; + + // Choose selection mode + m_netsListGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); + + buildNetsList(); + + m_sdbSizerOK->SetDefault(); + GetSizer()->SetSizeHints( this ); + Center(); +} + +void DIALOG_SELECT_NET_FROM_LIST::buildNetsList() +{ + wxString netFilter = m_textCtrlFilter->GetValue(); + EDA_PATTERN_MATCH_WILDCARD filter; + filter.SetPattern( netFilter.MakeUpper() ); + wxString txt; + + int row_idx = 0; + + // Populate the nets list with nets names matching the filters: + // Note: the filtering is case insensitive. + for( unsigned netcode = 0; netcode < m_brd->GetNetCount(); netcode++ ) + { + NETINFO_ITEM* net = m_brd->GetNetInfo().GetNetItem( netcode ); + + if( !netFilter.IsEmpty() ) + { + wxString netname = net->GetNetname(); + if( filter.Find( netname.MakeUpper() ) == EDA_PATTERN_NOT_FOUND ) + continue; + } + + if( !m_cbShowZeroPad->IsChecked() && net->m_PadInNetList.size() == 0 ) + continue; + + if( m_netsListGrid->GetNumberRows() <= row_idx ) + m_netsListGrid->AppendRows( 1 ); + + txt.Printf( _( "net %.3d" ), net->GetNet() ); + m_netsListGrid->SetRowLabelValue( row_idx, txt ); + + m_netsListGrid->SetCellValue( row_idx, COL_NETNAME, net->GetNetname() ); + + if( netcode ) + { + txt.Printf( wxT( "%u" ), net->m_PadInNetList.size() ); + m_netsListGrid->SetCellValue( row_idx, COL_NETINFO, txt ); + } + else // For the net 0 (unconnected pads), the pad count is not known + m_netsListGrid->SetCellValue( row_idx, COL_NETINFO, "---" ); + + row_idx++; + } + + // Remove extra rows, if any: + int extra_row_idx = m_netsListGrid->GetNumberRows() - row_idx; + + if( extra_row_idx > 0 ) + m_netsListGrid->DeleteRows( row_idx, extra_row_idx ); + + m_netsListGrid->SetColLabelSize( wxGRID_AUTOSIZE ); + m_netsListGrid->SetRowLabelSize( wxGRID_AUTOSIZE ); + + m_netsListGrid->ClearSelection(); + m_wasSelected = false; +} + + +DIALOG_SELECT_NET_FROM_LIST::~DIALOG_SELECT_NET_FROM_LIST() +{ +} + +void DIALOG_SELECT_NET_FROM_LIST::onFilterChange( wxCommandEvent& event ) +{ + buildNetsList(); +} + + +void DIALOG_SELECT_NET_FROM_LIST::onCellClick( wxGridEvent& event ) +{ + int selected_row = event.GetRow(); + m_selection = m_netsListGrid->GetCellValue( selected_row, COL_NETNAME ); + m_wasSelected = true; + + // Select the full row when clicking on any cell off the row + m_netsListGrid->SelectRow( selected_row, false ); + m_netsListGrid->SetGridCursor(selected_row, COL_NETNAME ); +} + + +bool DIALOG_SELECT_NET_FROM_LIST::GetNetName( wxString& aName ) +{ + aName = m_selection; + return m_wasSelected; +} diff --git a/pcbnew/dialogs/dialog_select_net_from_list_base.cpp b/pcbnew/dialogs/dialog_select_net_from_list_base.cpp new file mode 100644 index 00000000000..4b200e75279 --- /dev/null +++ b/pcbnew/dialogs/dialog_select_net_from_list_base.cpp @@ -0,0 +1,103 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jan 1 2016) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_select_net_from_list_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_SELECT_NET_FROM_LIST_BASE::DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxSize( 400,200 ), wxDefaultSize ); + + wxBoxSizer* bSizerMain; + bSizerMain = new wxBoxSizer( wxVERTICAL ); + + wxFlexGridSizer* fgSizer1; + fgSizer1 = new wxFlexGridSizer( 0, 3, 0, 0 ); + fgSizer1->AddGrowableCol( 1 ); + fgSizer1->SetFlexibleDirection( wxBOTH ); + fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + m_staticTextFilter = new wxStaticText( this, wxID_ANY, _("Net name filter"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticTextFilter->Wrap( -1 ); + fgSizer1->Add( m_staticTextFilter, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + m_textCtrlFilter = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer1->Add( m_textCtrlFilter, 0, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); + + m_cbShowZeroPad = new wxCheckBox( this, wxID_ANY, _("Show zero pad nets"), wxDefaultPosition, wxDefaultSize, 0 ); + m_cbShowZeroPad->SetValue(true); + fgSizer1->Add( m_cbShowZeroPad, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); + + + bSizerMain->Add( fgSizer1, 0, wxEXPAND, 5 ); + + m_netsListGrid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + // Grid + m_netsListGrid->CreateGrid( 1, 2 ); + m_netsListGrid->EnableEditing( false ); + m_netsListGrid->EnableGridLines( true ); + m_netsListGrid->EnableDragGridSize( false ); + m_netsListGrid->SetMargins( 0, 0 ); + + // Columns + m_netsListGrid->SetColSize( 0, 325 ); + m_netsListGrid->SetColSize( 1, 100 ); + m_netsListGrid->EnableDragColMove( false ); + m_netsListGrid->EnableDragColSize( true ); + m_netsListGrid->SetColLabelSize( 20 ); + m_netsListGrid->SetColLabelValue( 0, _("Net name") ); + m_netsListGrid->SetColLabelValue( 1, _("Number of pads") ); + m_netsListGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE ); + + // Rows + m_netsListGrid->AutoSizeRows(); + m_netsListGrid->EnableDragRowSize( true ); + m_netsListGrid->SetRowLabelSize( 50 ); + m_netsListGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); + + // Label Appearance + + // Cell Defaults + m_netsListGrid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + m_netsListGrid->SetMinSize( wxSize( 485,300 ) ); + + bSizerMain->Add( m_netsListGrid, 1, wxALL|wxEXPAND, 5 ); + + m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + bSizerMain->Add( m_staticline, 0, wxEXPAND | wxALL, 5 ); + + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizer->Realize(); + + bSizerMain->Add( m_sdbSizer, 0, wxEXPAND|wxALL, 5 ); + + + this->SetSizer( bSizerMain ); + this->Layout(); + + this->Centre( wxBOTH ); + + // Connect Events + m_textCtrlFilter->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SELECT_NET_FROM_LIST_BASE::onFilterChange ), NULL, this ); + m_cbShowZeroPad->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SELECT_NET_FROM_LIST_BASE::onFilterChange ), NULL, this ); + m_netsListGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_SELECT_NET_FROM_LIST_BASE::onCellClick ), NULL, this ); +} + +DIALOG_SELECT_NET_FROM_LIST_BASE::~DIALOG_SELECT_NET_FROM_LIST_BASE() +{ + // Disconnect Events + m_textCtrlFilter->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SELECT_NET_FROM_LIST_BASE::onFilterChange ), NULL, this ); + m_cbShowZeroPad->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SELECT_NET_FROM_LIST_BASE::onFilterChange ), NULL, this ); + m_netsListGrid->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( DIALOG_SELECT_NET_FROM_LIST_BASE::onCellClick ), NULL, this ); + +} diff --git a/pcbnew/dialogs/dialog_select_net_from_list_base.fbp b/pcbnew/dialogs/dialog_select_net_from_list_base.fbp new file mode 100644 index 00000000000..d3784f85ca0 --- /dev/null +++ b/pcbnew/dialogs/dialog_select_net_from_list_base.fbp @@ -0,0 +1,629 @@ + + + + + + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_select_net_from_list_base + 1000 + none + 1 + dialog_select_net_from_list_base + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + 400,200 + DIALOG_SELECT_NET_FROM_LIST_BASE + + 477,278 + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER + DIALOG_SHIM; dialog_shim.h + Nets + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bSizerMain + wxVERTICAL + none + + 5 + wxEXPAND + 0 + + 3 + wxBOTH + 1 + + 0 + + fgSizer1 + wxFLEX_GROWMODE_SPECIFIED + none + 0 + 0 + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Net name filter + + 0 + + + 0 + + 1 + m_staticTextFilter + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + 0 + + 0 + + 1 + m_textCtrlFilter + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + onFilterChange + + + + + + + + 5 + wxALL|wxALIGN_CENTER_VERTICAL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Show zero pad nets + + 0 + + + 0 + + 1 + m_cbShowZeroPad + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + onFilterChange + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + 0 + 1 + + + + 1 + + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_LEFT + 20 + "Net name" "Number of pads" + wxALIGN_CENTRE + 2 + 325,100 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + 0 + 1 + 0 + 1 + + 1 + + + 1 + 0 + 0 + wxID_ANY + + + + 0 + 0 + + 0 + + + 0 + 485,300 + 1 + m_netsListGrid + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTRE + 50 + + wxALIGN_CENTRE + + 1 + 1 + + + 0 + + + + + + + + + onCellClick + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND | wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_staticline + 1 + + + protected + 1 + + Resizable + 1 + + wxLI_HORIZONTAL + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxALL + 0 + + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbSizer + protected + + + + + + + + + + + + + + diff --git a/pcbnew/dialogs/dialog_select_net_from_list_base.h b/pcbnew/dialogs/dialog_select_net_from_list_base.h new file mode 100644 index 00000000000..db3dc1838d4 --- /dev/null +++ b/pcbnew/dialogs/dialog_select_net_from_list_base.h @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jan 1 2016) +// http://www.wxformbuilder.org/ +// +// PLEASE DO "NOT" EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#ifndef __DIALOG_SELECT_NET_FROM_LIST_BASE_H__ +#define __DIALOG_SELECT_NET_FROM_LIST_BASE_H__ + +#include +#include +#include +class DIALOG_SHIM; + +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_SELECT_NET_FROM_LIST_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_SELECT_NET_FROM_LIST_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxStaticText* m_staticTextFilter; + wxTextCtrl* m_textCtrlFilter; + wxCheckBox* m_cbShowZeroPad; + wxGrid* m_netsListGrid; + wxStaticLine* m_staticline; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerCancel; + + // Virtual event handlers, overide them in your derived class + virtual void onFilterChange( wxCommandEvent& event ) { event.Skip(); } + virtual void onCellClick( wxGridEvent& event ) { event.Skip(); } + + + public: + + DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Nets"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 477,278 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_SELECT_NET_FROM_LIST_BASE(); + +}; + +#endif //__DIALOG_SELECT_NET_FROM_LIST_BASE_H__ diff --git a/pcbnew/highlight.cpp b/pcbnew/highlight.cpp index a7ae4e963ff..249a48b086b 100644 --- a/pcbnew/highlight.cpp +++ b/pcbnew/highlight.cpp @@ -30,10 +30,8 @@ #include #include -#include #include #include -#include #include #include @@ -43,73 +41,6 @@ #include -void PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event ) -{ - NETINFO_ITEM* net; - wxString netFilter; - wxArrayString list; - - netFilter = wxT( "*" ); - wxTextEntryDialog dlg( this, _( "Filter Net Names" ), _( "Net Filter" ), netFilter ); - - if( dlg.ShowModal() != wxID_OK ) - return; // cancelled by user - - netFilter = dlg.GetValue( ); - - if( netFilter.IsEmpty() ) - return; - - wxString Line; - for( unsigned ii = 0; ii < GetBoard()->GetNetCount(); ii++ ) - { - net = GetBoard()->m_NetInfo.GetNetItem( ii ); - - if( !WildCompareString( netFilter, net->GetNetname(), false ) ) - continue; - - Line.Printf( wxT( "net %3.3d: %s" ), net->GetNet(), - GetChars( net->GetNetname() ) ); - list.Add( Line ); - } - - wxSingleChoiceDialog choiceDlg( this, wxEmptyString, _( "Select Net" ), list ); - - if( (choiceDlg.ShowModal() == wxID_CANCEL) || (choiceDlg.GetSelection() == wxNOT_FOUND) ) - return; - - bool found = false; - unsigned netcode = (unsigned) choiceDlg.GetSelection(); - - // Search for the net selected. - for( unsigned ii = 0; ii < GetBoard()->GetNetCount(); ii++ ) - { - net = GetBoard()->FindNet( ii ); - - if( !WildCompareString( netFilter, net->GetNetname(), false ) ) - continue; - - if( ii == netcode ) - { - netcode = net->GetNet(); - found = true; - break; - } - } - - if( found ) - { - INSTALL_UNBUFFERED_DC( dc, m_canvas ); - - if( GetBoard()->IsHighLightNetON() ) - HighLight( &dc ); - - GetBoard()->SetHighLightNet( netcode ); - HighLight( &dc ); - } -} - - int PCB_EDIT_FRAME::SelectHighLight( wxDC* DC ) { int netcode = -1;