pcbnew: search for nets

Fixes https://gitlab.com/kicad/code/kicad/-/issues/10601
This commit is contained in:
Fabien Corona 2022-03-10 23:12:30 +00:00 committed by Seth Hillbrand
parent 455e330f3b
commit d452f79860
7 changed files with 122 additions and 26 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2012 Marco Mattila <marcom99@gmail.com>
* Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
* Copyright (C) 1992-2021 Kicad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2022 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
@ -49,6 +49,7 @@ bool FindIncludeTexts = true;
bool FindIncludeValues = true;
bool FindIncludeReferences = true;
bool FindIncludeMarkers = true;
bool FindIncludeNets = true;
DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME *aFrame ) :
@ -80,6 +81,7 @@ DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME *aFrame ) :
m_includeValues->SetValue( FindIncludeValues );
m_includeReferences->SetValue( FindIncludeReferences );
m_includeMarkers->SetValue( FindIncludeMarkers );
m_includeNets->SetValue( FindIncludeNets );
m_status->SetLabel( wxEmptyString);
m_upToDate = false;
@ -213,6 +215,12 @@ void DIALOG_FIND::search( bool aDirection )
m_upToDate = false;
}
if( FindIncludeNets != m_includeNets->GetValue() )
{
FindIncludeNets = m_includeNets->GetValue();
m_upToDate = false;
}
if( FindOptionCase )
flags |= wxFR_MATCHCASE;
@ -229,6 +237,8 @@ void DIALOG_FIND::search( bool aDirection )
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
m_frame->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
BOARD* board = m_frame->GetBoard();
// Refresh the list of results
if( !m_upToDate )
{
@ -237,7 +247,7 @@ void DIALOG_FIND::search( bool aDirection )
if( FindIncludeTexts || FindIncludeValues || FindIncludeReferences )
{
for( FOOTPRINT* fp : m_frame->GetBoard()->Footprints() )
for( FOOTPRINT* fp : board->Footprints() )
{
if( ( fp->Reference().Matches( m_frame->GetFindReplaceData(), nullptr )
&& FindIncludeReferences )
@ -264,7 +274,7 @@ void DIALOG_FIND::search( bool aDirection )
if( FindIncludeTexts )
{
for( BOARD_ITEM* item : m_frame->GetBoard()->Drawings() )
for( BOARD_ITEM* item : board->Drawings() )
{
PCB_TEXT* textItem = dynamic_cast<PCB_TEXT*>( item );
@ -274,7 +284,7 @@ void DIALOG_FIND::search( bool aDirection )
}
}
for( BOARD_ITEM* item : m_frame->GetBoard()->Zones() )
for( BOARD_ITEM* item : board->Zones() )
{
ZONE* zoneItem = dynamic_cast<ZONE*>( item );
@ -288,13 +298,24 @@ void DIALOG_FIND::search( bool aDirection )
if( FindIncludeMarkers )
{
for( PCB_MARKER* marker : m_frame->GetBoard()->Markers() )
for( PCB_MARKER* marker : board->Markers() )
{
if( marker->Matches( m_frame->GetFindReplaceData(), nullptr ) )
m_hitList.push_back( marker );
}
}
if( FindIncludeNets )
{
for( NETINFO_ITEM* net : board->GetNetInfo() )
{
if( net && net->Matches( m_frame->GetFindReplaceData(), nullptr ) )
{
m_hitList.push_back( net );
}
}
}
m_upToDate = true;
isFirstSearch = true;
@ -365,7 +386,6 @@ void DIALOG_FIND::search( bool aDirection )
else
{
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, *m_it );
m_frame->FocusOnLocation( ( *m_it )->GetPosition() );
msg.Printf( _( "'%s' found" ), searchString );
m_frame->SetStatusText( msg );
@ -412,6 +432,7 @@ void DIALOG_FIND::OnClose( wxCloseEvent& aEvent )
FindIncludeValues = m_includeValues->GetValue();
FindIncludeMarkers = m_includeMarkers->GetValue();
FindIncludeReferences = m_includeReferences->GetValue();
FindIncludeNets = m_includeNets->GetValue();
aEvent.Skip();
}

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.9.0 Jun 18 2020)
// C++ code generated with wxFormBuilder (version May 14 2021)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -75,11 +75,9 @@ DIALOG_FIND_BASE::DIALOG_FIND_BASE( wxWindow* parent, wxWindowID id, const wxStr
m_includeMarkers->SetValue(true);
sizerInclude->Add( m_includeMarkers, 0, wxALL, 5 );
m_includeVias = new wxCheckBox( this, wxID_ANY, _("Vias"), wxDefaultPosition, wxDefaultSize, 0 );
m_includeVias->SetValue(true);
m_includeVias->Hide();
sizerInclude->Add( m_includeVias, 0, wxALL, 5 );
m_includeNets = new wxCheckBox( this, wxID_ANY, _("Search net names"), wxDefaultPosition, wxDefaultSize, 0 );
m_includeNets->SetValue(true);
sizerInclude->Add( m_includeNets, 0, wxALL, 5 );
leftSizer->Add( sizerInclude, 0, wxEXPAND, 5 );

View File

@ -14,7 +14,6 @@
<property name="file">dialog_find_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">dialog_pcbnew_find</property>
@ -26,7 +25,6 @@
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
@ -780,9 +778,9 @@
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">1</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Vias</property>
<property name="label">Search net names</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -790,7 +788,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_includeVias</property>
<property name="name">m_includeNets</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -839,7 +837,6 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
@ -913,7 +910,6 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
@ -987,7 +983,6 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
@ -1061,7 +1056,6 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.9.0 Jun 18 2020)
// C++ code generated with wxFormBuilder (version May 14 2021)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -20,10 +20,10 @@
#include <wx/combobox.h>
#include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/button.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/statline.h>
#include <wx/dialog.h>
@ -48,7 +48,7 @@ class DIALOG_FIND_BASE : public DIALOG_SHIM
wxCheckBox* m_includeValues;
wxCheckBox* m_includeTexts;
wxCheckBox* m_includeMarkers;
wxCheckBox* m_includeVias;
wxCheckBox* m_includeNets;
wxButton* m_findNext;
wxButton* m_findPrevious;
wxButton* m_searchAgain;

View File

@ -85,6 +85,8 @@ public:
}
#endif
const EDA_RECT GetBoundingBox() const override;
VECTOR2I GetPosition() const override
{
static VECTOR2I dummy( 0, 0 );
@ -167,6 +169,8 @@ public:
return m_parent;
}
bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
private:
friend class NETINFO_LIST;

View File

@ -33,6 +33,7 @@
#include <base_units.h>
#include <board.h>
#include <board_design_settings.h>
#include <connectivity/connectivity_data.h>
#include <footprint.h>
#include <pcb_track.h>
#include <pad.h>
@ -130,3 +131,30 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
}
}
}
bool NETINFO_ITEM::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
{
return BOARD_ITEM::Matches( GetNetname(), aSearchData );
}
const EDA_RECT NETINFO_ITEM::GetBoundingBox() const
{
constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_ZONE_T, PCB_PAD_T, EOT };
auto connectivity = GetBoard()->GetConnectivity();
std::vector<BOARD_CONNECTED_ITEM*> items = connectivity->GetNetItems( m_netCode, types );
EDA_RECT bbox = EDA_RECT( wxPoint( 0, 0 ), wxPoint( 0, 0 ) );
if( items.size() >= 1 )
{
bbox = items.at( 0 )->GetBoundingBox();
for( BOARD_CONNECTED_ITEM* item : items )
{
bbox.Merge( item->GetBoundingBox() );
}
}
return bbox;
}

View File

@ -1823,9 +1823,60 @@ void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem )
if( aItem )
{
select( aItem );
m_frame->FocusOnLocation( aItem->GetPosition() );
switch( aItem->Type() )
{
case PCB_NETINFO_T:
{
int netCode = static_cast<NETINFO_ITEM*>( aItem )->GetNetCode();
if( netCode > 0 )
{
selectAllItemsOnNet( netCode, true );
m_frame->FocusOnLocation( aItem->GetCenter() );
}
break;
}
default:
select( aItem );
m_frame->FocusOnLocation( aItem->GetPosition() );
}
// If the item has a bouding box, then zoom out if needed
if( aItem->GetBoundingBox().GetHeight() > 0 && aItem->GetBoundingBox().GetWidth() > 0 )
{
// This adds some margin
double marginFactor = 2;
KIGFX::PCB_VIEW* pcbView = canvas()->GetView();
BOX2D screenBox = pcbView->GetViewport();
wxSize screenSize = wxSize( screenBox.GetWidth(), screenBox.GetHeight() );
screenSize /= marginFactor;
wxPoint screenPos = wxPoint( screenBox.GetOrigin() );
EDA_RECT* screenRect = new EDA_RECT( screenPos, screenSize );
if( !screenRect->Contains( aItem->GetBoundingBox() ) )
{
double scaleX = screenSize.GetWidth()
/ static_cast<double>( aItem->GetBoundingBox().GetWidth() );
double scaleY = screenSize.GetHeight()
/ static_cast<double>( aItem->GetBoundingBox().GetHeight() );
scaleX /= marginFactor;
scaleY /= marginFactor;
double scale = scaleX > scaleY ? scaleY : scaleX;
if( scale < 1 ) // Don't zoom in, only zoom out
{
pcbView->SetScale( pcbView->GetScale() * ( scale ) );
//Let's refocus because there is an algortihm to avoid dialogs in there.
m_frame->FocusOnLocation( aItem->GetCenter() );
}
}
}
// Inform other potentially interested tools
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
}