Skip to content

Commit

Permalink
Pcbnew: Dialog list and select net: better dialog and make net select…
Browse files Browse the repository at this point in the history
…ion to highlight a net working on GAL.
  • Loading branch information
jp-charras committed Mar 16, 2016
1 parent b116318 commit 5de8545
Show file tree
Hide file tree
Showing 6 changed files with 1,003 additions and 69 deletions.
2 changes: 2 additions & 0 deletions pcbnew/CMakeLists.txt
Expand Up @@ -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
Expand Down
206 changes: 206 additions & 0 deletions 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 <wx/grid.h>

#include <fctsys.h>
#include <kicad_string.h>
#include <kicad_device_context.h>
#include <class_drawpanel.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#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>

#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;
}
103 changes: 103 additions & 0 deletions 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 );

}

0 comments on commit 5de8545

Please sign in to comment.