7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 14:50:11 +00:00

Pcbnew: get footprint by name doesn't have to be a member on PCB_BASE_FRAME

This function doesn't access anything private to PCB_BASE_FRAME. So
split it into a static and slim the PCB_BASE_FRAME API just a
smidgen.
This commit is contained in:
John Beard 2024-11-01 20:18:59 +08:00
parent fdd4994bbb
commit c39573ace3
4 changed files with 42 additions and 50 deletions

View File

@ -243,13 +243,6 @@ public:
*/
wxString SelectLibrary( const wxString& aNicknameExisting );
/**
* @return a reference to the footprint found by its reference on the current board. The
* reference is entered by the user from a dialog (by awxTextCtlr, or a list of
* available references)
*/
FOOTPRINT* GetFootprintFromBoardByReference();
/**
* Must be called after a change in order to set the "modify" flag and update other data
* structures and GUI elements.

View File

@ -31,7 +31,6 @@ using namespace std::placeholders;
#include <confirm.h>
#include <connectivity/connectivity_data.h>
#include <dialog_footprint_chooser.h>
#include <dialog_get_footprint_by_name.h>
#include <eda_list_dialog.h>
#include <footprint_edit_frame.h>
#include <footprint_tree_pane.h>
@ -392,40 +391,6 @@ static FOOTPRINT* s_FootprintInitialCopy = nullptr; // Copy of footprint for
static PICKED_ITEMS_LIST s_PickedList; // A pick-list to save initial footprint
// and dragged tracks
FOOTPRINT* PCB_BASE_FRAME::GetFootprintFromBoardByReference()
{
wxString footprintName;
wxArrayString fplist;
// Build list of available fp references, to display them in dialog
for( FOOTPRINT* fp : GetBoard()->Footprints() )
fplist.Add( fp->GetReference() + wxT( " ( " ) + fp->GetValue() + wxT( " )" ) );
fplist.Sort();
DIALOG_GET_FOOTPRINT_BY_NAME dlg( this, fplist );
if( dlg.ShowModal() != wxID_OK ) //Aborted by user
return nullptr;
footprintName = dlg.GetValue();
footprintName.Trim( true );
footprintName.Trim( false );
if( !footprintName.IsEmpty() )
{
for( FOOTPRINT* fp : GetBoard()->Footprints() )
{
if( fp->GetReference().CmpNoCase( footprintName ) == 0 )
return fp;
}
}
return nullptr;
}
void PCB_BASE_FRAME::PlaceFootprint( FOOTPRINT* aFootprint, bool aRecreateRatsnest )
{
if( aFootprint == nullptr )

View File

@ -65,6 +65,7 @@ using namespace std::placeholders;
#include "kicad_clipboard.h"
#include <wx/hyperlink.h>
#include <router/router_tool.h>
#include <dialog_get_footprint_by_name.h>
#include <dialogs/dialog_move_exact.h>
#include <dialogs/dialog_track_via_properties.h>
#include <dialogs/dialog_tablecell_properties.h>
@ -412,15 +413,54 @@ bool EDIT_TOOL::Init()
}
/**
* @return a reference to the footprint found by its reference on the current board. The
* reference is entered by the user from a dialog (by awxTextCtlr, or a list of
* available references)
*/
static FOOTPRINT* GetFootprintFromBoardByReference( PCB_BASE_FRAME& aFrame )
{
wxString footprintName;
wxArrayString fplist;
const FOOTPRINTS& footprints = aFrame.GetBoard()->Footprints();
// Build list of available fp references, to display them in dialog
for( FOOTPRINT* fp : footprints )
fplist.Add( fp->GetReference() + wxT( " ( " ) + fp->GetValue() + wxT( " )" ) );
fplist.Sort();
DIALOG_GET_FOOTPRINT_BY_NAME dlg( &aFrame, fplist );
if( dlg.ShowModal() != wxID_OK ) //Aborted by user
return nullptr;
footprintName = dlg.GetValue();
footprintName.Trim( true );
footprintName.Trim( false );
if( !footprintName.IsEmpty() )
{
for( FOOTPRINT* fp : footprints )
{
if( fp->GetReference().CmpNoCase( footprintName ) == 0 )
return fp;
}
}
return nullptr;
}
int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
{
// GetAndPlace makes sense only in board editor, although it is also called
// in fpeditor, that shares the same EDIT_TOOL list
if( !getEditFrame<PCB_BASE_FRAME>()->IsType( FRAME_PCB_EDITOR ) )
if( IsFootprintEditor() )
return 0;
PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
FOOTPRINT* fp = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
FOOTPRINT* fp = GetFootprintFromBoardByReference( *frame() );
if( fp )
{

View File

@ -111,12 +111,6 @@ DIALOG_FIND_BASE::~DIALOG_FIND_BASE()
}
FOOTPRINT* PCB_BASE_FRAME::GetFootprintFromBoardByReference()
{
return nullptr;
}
DIALOG_FILTER_SELECTION_BASE::DIALOG_FILTER_SELECTION_BASE( wxWindow* parent, wxWindowID id,
const wxString& title,
const wxPoint& pos, const wxSize& size,