Pcbnew: implement Find Next

Moves all of the find dialog control out of the selection tool similar
to the schematic editor. Dialog is also non-modal now to match the
schematic editor.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8966
This commit is contained in:
Mike Williams 2021-08-27 13:15:51 -04:00 committed by Seth Hillbrand
parent d18d993eac
commit 10247c268e
7 changed files with 75 additions and 21 deletions

View File

@ -63,6 +63,11 @@ public:
m_highlightCallback = aCallback;
}
/**
* Finds the next item
*/
void FindNext() { search( true ); }
protected:
void OnClose( wxCloseEvent& event ) override;
void OnCloseButtonClick( wxCommandEvent& aEvent ) override;

View File

@ -35,6 +35,7 @@
#include <pcb_layer_box_selector.h>
#include <footprint_edit_frame.h>
#include <dialog_plot.h>
#include <dialog_find.h>
#include <dialog_footprint_properties.h>
#include <dialogs/dialog_exchange_footprints.h>
#include <dialog_board_setup.h>
@ -173,7 +174,7 @@ END_EVENT_TABLE()
PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, wxT( "PCB Editor" ), wxDefaultPosition,
wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, PCB_EDIT_FRAME_NAME ),
m_exportNetlistAction( nullptr )
m_exportNetlistAction( nullptr ), m_findDialog( nullptr )
{
m_maximizeByDefault = true;
m_showBorderAndTitleBlock = true; // true to display sheet references
@ -1311,6 +1312,32 @@ void PCB_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
}
void PCB_EDIT_FRAME::ShowFindDialog()
{
if( !m_findDialog )
{
m_findDialog = new DIALOG_FIND( this );
m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
}
m_findDialog->Show( true );
}
void PCB_EDIT_FRAME::FindNext()
{
if( !m_findDialog )
{
m_findDialog = new DIALOG_FIND( this );
m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
}
m_findDialog->FindNext();
}
void PCB_EDIT_FRAME::ToPlotter( int aID )
{
PCB_PLOT_PARAMS plotSettings = GetPlotSettings();

View File

@ -40,6 +40,7 @@ class PCB_TARGET;
class PCB_GROUP;
class PCB_DIMENSION_BASE;
class DRC;
class DIALOG_FIND;
class DIALOG_PLOT;
class ZONE;
class GENERAL_COLLECTOR;
@ -120,6 +121,16 @@ public:
void KiwayMailIn( KIWAY_EXPRESS& aEvent ) override;
/**
* Show the Find dialog.
*/
void ShowFindDialog();
/**
* Find the next item using our existing search parameters.
*/
void FindNext();
/**
* Open a dialog frame to create plot and drill files relative to the current board.
*/
@ -767,6 +778,8 @@ private:
* option.
*/
TOOL_ACTION* m_exportNetlistAction;
DIALOG_FIND* m_findDialog;
};
#endif // __PCB_EDIT_FRAME_H__

View File

@ -351,6 +351,20 @@ int BOARD_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent )
}
int BOARD_EDITOR_CONTROL::Find( const TOOL_EVENT& aEvent )
{
m_frame->ShowFindDialog();
return 0;
}
int BOARD_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent )
{
m_frame->FindNext();
return 0;
}
int BOARD_EDITOR_CONTROL::BoardSetup( const TOOL_EVENT& aEvent )
{
getEditFrame<PCB_EDIT_FRAME>()->ShowBoardSetupDialog();
@ -1502,6 +1516,9 @@ void BOARD_EDITOR_CONTROL::setTransitions()
Go( &BOARD_EDITOR_CONTROL::PageSettings, ACTIONS::pageSettings.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::Find, ACTIONS::find.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::FindNext, ACTIONS::findNext.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::BoardSetup, PCB_ACTIONS::boardSetup.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::ImportNetlist, PCB_ACTIONS::importNetlist.MakeEvent() );
Go( &BOARD_EDITOR_CONTROL::ImportSpecctraSession,

View File

@ -59,6 +59,9 @@ public:
int PageSettings( const TOOL_EVENT& aEvent );
int Plot( const TOOL_EVENT& aEvent );
int Find( const TOOL_EVENT& aEvent );
int FindNext( const TOOL_EVENT& aEvent );
int BoardSetup( const TOOL_EVENT& aEvent );
int ImportNetlist( const TOOL_EVENT& aEvent );
int ImportSpecctraSession( const TOOL_EVENT& aEvent );

View File

@ -41,7 +41,6 @@ using namespace std::placeholders;
#include <pcb_marker.h>
#include <zone.h>
#include <collectors.h>
#include <dialog_find.h>
#include <dialog_filter_selection.h>
#include <dialogs/dialog_locked_items_query.h>
#include <class_draw_panel_gal.h>
@ -1466,7 +1465,7 @@ int PCB_SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent )
}
void PCB_SELECTION_TOOL::findCallback( BOARD_ITEM* aItem )
void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem )
{
bool cleared = false;
@ -1495,16 +1494,6 @@ void PCB_SELECTION_TOOL::findCallback( BOARD_ITEM* aItem )
}
int PCB_SELECTION_TOOL::find( const TOOL_EVENT& aEvent )
{
DIALOG_FIND dlg( m_frame );
dlg.SetCallback( std::bind( &PCB_SELECTION_TOOL::findCallback, this, _1 ) );
dlg.ShowModal();
return 0;
}
/**
* Determine if an item is included by the filter specified.
*
@ -2654,8 +2643,6 @@ void PCB_SELECTION_TOOL::setTransitions()
Go( &PCB_SELECTION_TOOL::UnselectItems, PCB_ACTIONS::unselectItems.MakeEvent() );
Go( &PCB_SELECTION_TOOL::SelectionMenu, PCB_ACTIONS::selectionMenu.MakeEvent() );
Go( &PCB_SELECTION_TOOL::find, ACTIONS::find.MakeEvent() );
Go( &PCB_SELECTION_TOOL::filterSelection, PCB_ACTIONS::filterSelection.MakeEvent() );
Go( &PCB_SELECTION_TOOL::expandConnection, PCB_ACTIONS::selectConnection.MakeEvent() );
Go( &PCB_SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() );

View File

@ -122,6 +122,14 @@ public:
void BrightenItem( BOARD_ITEM* aItem );
void UnbrightenItem( BOARD_ITEM* aItem );
/**
* Handle finding an item. Does not do the actual searching, is called
* by the find dialog.
*
* @param aItem Item that was found and needs to be handled.
*/
void FindItem( BOARD_ITEM* aItem );
/**
* Take necessary action mark an item as selected.
*
@ -305,12 +313,6 @@ private:
///< (same sheet path).
int selectSameSheet( const TOOL_EVENT& aEvent );
///< Find dialog callback.
void findCallback( BOARD_ITEM* aItem );
///< Find an item.
int find( const TOOL_EVENT& aEvent );
///< Invoke filter dialog and modify current selection
int filterSelection( const TOOL_EVENT& aEvent );