Netlist dialog: highlight nets on selection

This commit is contained in:
Maciej Suminski 2018-02-15 15:35:29 +01:00
parent d08f19a0a2
commit 4a8a168079
1 changed files with 50 additions and 32 deletions

View File

@ -50,22 +50,30 @@
class DIALOG_SELECT_NET_FROM_LIST: public DIALOG_SELECT_NET_FROM_LIST_BASE class DIALOG_SELECT_NET_FROM_LIST: public DIALOG_SELECT_NET_FROM_LIST_BASE
{ {
private: private:
wxString m_selection;
bool m_wasSelected;
BOARD* m_brd;
public: public:
DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME * aParent ); DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent );
~DIALOG_SELECT_NET_FROM_LIST(); ~DIALOG_SELECT_NET_FROM_LIST();
// returns true if a net was selected, and its name in aName // returns true if a net was selected, and its name in aName
bool GetNetName( wxString& aName ); bool GetNetName( wxString& aName );
/**
* Visually highlights a net.
* @param aEnabled true to enable highlight mode, false to disable.
* @param aNetName is the name of net to be highlighted.
*/
void HighlightNet( bool aEnabled, const wxString& aNetName );
private: private:
void onCellClick( wxGridEvent& event ) override; void onCellClick( wxGridEvent& event ) override;
void onFilterChange( wxCommandEvent& event ) override; void onFilterChange( wxCommandEvent& event ) override;
void buildNetsList(); void buildNetsList();
wxString m_selection;
bool m_wasSelected;
BOARD* m_brd;
PCB_EDIT_FRAME* m_frame;
}; };
@ -74,38 +82,16 @@ void PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event )
DIALOG_SELECT_NET_FROM_LIST dlg( this ); DIALOG_SELECT_NET_FROM_LIST dlg( this );
wxString netname; wxString netname;
if( dlg.ShowModal() == wxID_CANCEL || !dlg.GetNetName( netname ) ) if( dlg.ShowModal() == wxID_CANCEL )
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(); // Clear highlight
render->SetHighlight( true, net->GetNet() ); dlg.HighlightNet( false, "" );
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::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent )
: DIALOG_SELECT_NET_FROM_LIST_BASE( aParent ) : DIALOG_SELECT_NET_FROM_LIST_BASE( aParent ), m_frame( aParent )
{ {
m_brd = aParent->GetBoard(); m_brd = aParent->GetBoard();
m_wasSelected = false; m_wasSelected = false;
@ -120,6 +106,7 @@ DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParen
Center(); Center();
} }
void DIALOG_SELECT_NET_FROM_LIST::buildNetsList() void DIALOG_SELECT_NET_FROM_LIST::buildNetsList()
{ {
wxString netFilter = m_textCtrlFilter->GetValue(); wxString netFilter = m_textCtrlFilter->GetValue();
@ -180,10 +167,39 @@ void DIALOG_SELECT_NET_FROM_LIST::buildNetsList()
} }
void DIALOG_SELECT_NET_FROM_LIST::HighlightNet( bool aEnabled, const wxString& aNetName )
{
// Search for the net selected.
NETINFO_ITEM* net = aEnabled ? m_brd->FindNet( aNetName ) : nullptr;
int netCode = net ? net->GetNet() : -1;
if( m_frame->IsGalCanvasActive() )
{
auto galCanvas = m_frame->GetGalCanvas();
KIGFX::RENDER_SETTINGS* render = galCanvas->GetView()->GetPainter()->GetSettings();
render->SetHighlight( aEnabled, netCode );
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 );
}
}
DIALOG_SELECT_NET_FROM_LIST::~DIALOG_SELECT_NET_FROM_LIST() DIALOG_SELECT_NET_FROM_LIST::~DIALOG_SELECT_NET_FROM_LIST()
{ {
} }
void DIALOG_SELECT_NET_FROM_LIST::onFilterChange( wxCommandEvent& event ) void DIALOG_SELECT_NET_FROM_LIST::onFilterChange( wxCommandEvent& event )
{ {
buildNetsList(); buildNetsList();
@ -199,6 +215,8 @@ void DIALOG_SELECT_NET_FROM_LIST::onCellClick( wxGridEvent& event )
// Select the full row when clicking on any cell off the row // Select the full row when clicking on any cell off the row
m_netsListGrid->SelectRow( selected_row, false ); m_netsListGrid->SelectRow( selected_row, false );
m_netsListGrid->SetGridCursor(selected_row, COL_NETNAME ); m_netsListGrid->SetGridCursor(selected_row, COL_NETNAME );
HighlightNet( true, m_selection );
} }