2016-03-16 14:14:00 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2017-03-13 20:45:41 +00:00
|
|
|
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-03-16 14:14:00 +00:00
|
|
|
*
|
|
|
|
* 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 <fctsys.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <kicad_device_context.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <pcbnew.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2016-03-16 14:14:00 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <dialog_select_net_from_list_base.h>
|
|
|
|
#include <eda_pattern_match.h>
|
|
|
|
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <pcb_painter.h>
|
2017-11-15 17:33:06 +00:00
|
|
|
#include <connectivity_data.h>
|
2016-03-16 14:14:00 +00:00
|
|
|
|
|
|
|
class DIALOG_SELECT_NET_FROM_LIST: public DIALOG_SELECT_NET_FROM_LIST_BASE
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
public:
|
2018-02-15 14:35:29 +00:00
|
|
|
DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent );
|
2016-03-16 14:14:00 +00:00
|
|
|
~DIALOG_SELECT_NET_FROM_LIST();
|
|
|
|
|
|
|
|
// returns true if a net was selected, and its name in aName
|
|
|
|
bool GetNetName( wxString& aName );
|
|
|
|
|
2018-02-15 14:35:29 +00:00
|
|
|
/**
|
|
|
|
* Visually highlights a net.
|
2018-02-28 09:44:22 +00:00
|
|
|
* @param aNetName is the name of net to be highlighted. An empty string will unhighlight
|
|
|
|
* any currently highlighted net.
|
2018-02-15 14:35:29 +00:00
|
|
|
*/
|
2018-02-28 09:44:22 +00:00
|
|
|
void HighlightNet( const wxString& aNetName );
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
private:
|
2018-02-28 09:44:22 +00:00
|
|
|
void onSelChanged( wxDataViewEvent& event ) override;
|
2018-02-15 14:35:29 +00:00
|
|
|
void onFilterChange( wxCommandEvent& event ) override;
|
2018-02-28 09:44:22 +00:00
|
|
|
void onListSize( wxSizeEvent& event ) override;
|
2016-03-16 14:14:00 +00:00
|
|
|
|
|
|
|
void buildNetsList();
|
2018-02-28 09:44:22 +00:00
|
|
|
void adjustListColumns( int aWidth );
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
wxString m_selection;
|
|
|
|
bool m_wasSelected;
|
|
|
|
BOARD* m_brd;
|
2018-02-15 14:35:29 +00:00
|
|
|
PCB_EDIT_FRAME* m_frame;
|
2016-03-16 14:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
DIALOG_SELECT_NET_FROM_LIST dlg( this );
|
|
|
|
wxString netname;
|
|
|
|
|
2018-02-15 14:35:29 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
2018-02-15 14:35:29 +00:00
|
|
|
// Clear highlight
|
2018-02-28 09:44:22 +00:00
|
|
|
dlg.HighlightNet( "" );
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent )
|
2018-02-15 14:35:29 +00:00
|
|
|
: DIALOG_SELECT_NET_FROM_LIST_BASE( aParent ), m_frame( aParent )
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
|
|
|
m_brd = aParent->GetBoard();
|
|
|
|
m_wasSelected = false;
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_netsList->AppendTextColumn( _( "Net" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
|
|
|
|
m_netsList->AppendTextColumn( _( "Name" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
|
|
|
|
m_netsList->AppendTextColumn( _( "Pad Count" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_CENTER, 0 );
|
|
|
|
|
|
|
|
// The fact that we're a list should keep the control from reserving space for the
|
|
|
|
// expander buttons... but it doesn't. Fix by forcing the indent to 0.
|
|
|
|
m_netsList->SetIndent( 0 );
|
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
buildNetsList();
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
adjustListColumns( wxCOL_WIDTH_AUTOSIZE );
|
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
FinishDialogSettings();
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
void DIALOG_SELECT_NET_FROM_LIST::buildNetsList()
|
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
wxString netFilter = m_textCtrlFilter->GetValue();
|
2016-03-16 14:14:00 +00:00
|
|
|
EDA_PATTERN_MATCH_WILDCARD filter;
|
2018-02-28 09:44:22 +00:00
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
filter.SetPattern( netFilter.MakeUpper() );
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_netsList->DeleteAllItems();
|
2016-03-16 14:14:00 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2018-06-04 05:55:03 +00:00
|
|
|
unsigned nodes = m_brd->GetNodesCount( netcode );
|
2017-03-22 13:51:07 +00:00
|
|
|
|
2018-06-04 05:55:03 +00:00
|
|
|
if( !m_cbShowZeroPad->IsChecked() && nodes == 0 )
|
2016-03-16 14:14:00 +00:00
|
|
|
continue;
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
wxVector<wxVariant> dataLine;
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
dataLine.push_back( wxVariant( wxString::Format( _( "%.3d" ), netcode ) ) );
|
|
|
|
dataLine.push_back( wxVariant( net->GetNetname() ) );
|
2016-03-16 14:14:00 +00:00
|
|
|
|
|
|
|
if( netcode )
|
2018-02-28 09:44:22 +00:00
|
|
|
dataLine.push_back( wxVariant( wxString::Format( _( "%u" ), nodes ) ) );
|
2016-03-16 14:14:00 +00:00
|
|
|
else // For the net 0 (unconnected pads), the pad count is not known
|
2018-02-28 09:44:22 +00:00
|
|
|
dataLine.push_back( wxVariant( wxT( "---" ) ) );
|
2016-03-16 14:14:00 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_netsList->AppendItem( dataLine );
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_wasSelected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
void DIALOG_SELECT_NET_FROM_LIST::HighlightNet( const wxString& aNetName )
|
2018-02-15 14:35:29 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
NETINFO_ITEM* net = nullptr;
|
|
|
|
int netCode = -1;
|
|
|
|
|
|
|
|
if( !aNetName.IsEmpty() )
|
|
|
|
{
|
|
|
|
net = m_brd->FindNet( aNetName );
|
|
|
|
netCode = net->GetNet();
|
|
|
|
}
|
2018-02-15 14:35:29 +00:00
|
|
|
|
|
|
|
if( m_frame->IsGalCanvasActive() )
|
|
|
|
{
|
|
|
|
auto galCanvas = m_frame->GetGalCanvas();
|
|
|
|
KIGFX::RENDER_SETTINGS* render = galCanvas->GetView()->GetPainter()->GetSettings();
|
2018-02-28 09:44:22 +00:00
|
|
|
render->SetHighlight( netCode >= 0, netCode );
|
2018-02-15 14:35:29 +00:00
|
|
|
|
|
|
|
galCanvas->GetView()->UpdateAllLayersColor();
|
|
|
|
galCanvas->Refresh();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_frame->GetCanvas() );
|
|
|
|
|
|
|
|
if( m_brd->IsHighLightNetON() )
|
|
|
|
m_frame->HighLight( &dc );
|
|
|
|
|
|
|
|
m_brd->SetHighLightNet( netCode );
|
|
|
|
m_frame->HighLight( &dc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
DIALOG_SELECT_NET_FROM_LIST::~DIALOG_SELECT_NET_FROM_LIST()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:35:29 +00:00
|
|
|
|
2016-03-16 14:14:00 +00:00
|
|
|
void DIALOG_SELECT_NET_FROM_LIST::onFilterChange( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
buildNetsList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
void DIALOG_SELECT_NET_FROM_LIST::onSelChanged( wxDataViewEvent& )
|
2018-05-17 23:42:27 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
int selected_row = m_netsList->GetSelectedRow();
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
if( selected_row >= 0 )
|
|
|
|
{
|
|
|
|
m_selection = m_netsList->GetTextValue( selected_row, 1 );
|
|
|
|
m_wasSelected = true;
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
HighlightNet( m_selection );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HighlightNet( "" );
|
|
|
|
m_wasSelected = false;
|
|
|
|
}
|
2018-05-17 23:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
void DIALOG_SELECT_NET_FROM_LIST::adjustListColumns( int aWidth )
|
2018-05-17 23:42:27 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
if( aWidth == wxCOL_WIDTH_AUTOSIZE )
|
|
|
|
{
|
|
|
|
m_netsList->GetColumn( 0 )->SetWidth( wxCOL_WIDTH_AUTOSIZE );
|
|
|
|
m_netsList->GetColumn( 0 )->SetWidth( m_netsList->GetColumn( 0 )->GetWidth() + 12 );
|
|
|
|
m_netsList->GetColumn( 2 )->SetWidth( wxCOL_WIDTH_AUTOSIZE );
|
|
|
|
m_netsList->GetColumn( 2 )->SetWidth( m_netsList->GetColumn( 2 )->GetWidth() + 12 );
|
|
|
|
aWidth = m_netsList->GetRect().GetWidth();
|
|
|
|
}
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
aWidth -= m_netsList->GetColumn( 0 )->GetWidth();
|
|
|
|
aWidth -= m_netsList->GetColumn( 2 )->GetWidth();
|
2018-05-17 23:42:27 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_netsList->GetColumn( 1 )->SetWidth( aWidth - 8 );
|
2018-05-17 23:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
void DIALOG_SELECT_NET_FROM_LIST::onListSize( wxSizeEvent& aEvent )
|
2016-03-16 14:14:00 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
adjustListColumns( aEvent.GetSize().GetX() );
|
2016-03-16 14:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SELECT_NET_FROM_LIST::GetNetName( wxString& aName )
|
|
|
|
{
|
|
|
|
aName = m_selection;
|
|
|
|
return m_wasSelected;
|
|
|
|
}
|