Select first unassigned symbol when running CvPCB.

Also cleans up some dead code, and makes more use of sharing.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9938
This commit is contained in:
Jeff Young 2023-06-17 12:44:36 +01:00
parent 940f92a44f
commit cf4f0723f8
6 changed files with 71 additions and 225 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 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
@ -33,7 +33,6 @@
#include <kiway_express.h>
#include <string_utils.h>
#include <project/project_file.h>
#include <macros.h>
#include <netlist_reader/netlist_reader.h>
#include <lib_tree_model_adapter.h>
#include <numeric>
@ -44,8 +43,6 @@
#include <tool/tool_dispatcher.h>
#include <tool/tool_manager.h>
#include <widgets/wx_progress_reporters.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <cvpcb_association.h>
#include <cvpcb_id.h>
@ -57,30 +54,30 @@
#include <tools/cvpcb_actions.h>
#include <tools/cvpcb_association_tool.h>
#include <tools/cvpcb_control.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <wx/button.h>
#include <wx/settings.h>
#define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition,
wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, CVPCB_MAINFRAME_NAME,
wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, wxT( "CvpcbFrame" ),
unityScale ),
m_mainToolBar( nullptr ),
m_footprintListBox( nullptr ),
m_librariesListBox( nullptr ),
m_symbolsListBox( nullptr ),
m_tcFilterString( nullptr ),
m_viewerPendingUpdate( false )
{
m_symbolsListBox = nullptr;
m_footprintListBox = nullptr;
m_librariesListBox = nullptr;
m_mainToolBar = nullptr;
m_modified = false;
m_cannotClose = false;
m_skipComponentSelect = false;
m_filteringOptions = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST;
m_tcFilterString = nullptr;
m_FootprintsList = FOOTPRINT_LIST::GetInstance( Kiway() );
m_initialized = false;
m_aboutTitle = wxS( "CvPcb" );
m_aboutTitle = _( "Assign Footprints" );
// Give an icon
wxIcon icon;
@ -96,13 +93,17 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
ReCreateMenuBar();
ReCreateHToolbar();
// Create list of available footprints and symbols of the schematic
BuildSymbolsListBox();
BuildFootprintsListBox();
m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST );
m_footprintListBox->SetFont( KIUI::GetMonospacedUIFont() );
m_symbolsListBox = new SYMBOLS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST );
m_symbolsListBox->SetFont( KIUI::GetMonospacedUIFont() );
m_librariesListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST );
m_librariesListBox->SetFont( KIUI::GetMonospacedUIFont() );
BuildFootprintsList();
m_auimgr.SetManagedWindow( this );
m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
@ -169,45 +170,32 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
m_auimgr.Update();
m_initialized = true;
auto setPaneWidth =
[this]( wxAuiPaneInfo& pane, int width )
{
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
pane.MinSize( width, -1 );
pane.BestSize( width, -1 );
pane.MaxSize( width, -1 );
pane.Fixed();
m_auimgr.Update();
// now make it resizable again
pane.MinSize( 20, -1 );
pane.Resizable();
m_auimgr.Update();
};
if( CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() ) )
{
m_tcFilterString->ChangeValue( cfg->m_FilterString );
if( cfg->m_LibrariesWidth > 0 )
{
wxAuiPaneInfo& librariesPane = m_auimgr.GetPane( "Libraries" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
librariesPane.MinSize( cfg->m_LibrariesWidth, -1 );
librariesPane.BestSize( cfg->m_LibrariesWidth, -1 );
librariesPane.MaxSize( cfg->m_LibrariesWidth, -1 );
librariesPane.Fixed();
m_auimgr.Update();
// now make it resizable again
librariesPane.MinSize( 20, -1 );
librariesPane.Resizable();
m_auimgr.Update();
}
setPaneWidth( m_auimgr.GetPane( "Libraries" ), cfg->m_LibrariesWidth );
if( cfg->m_FootprintsWidth > 0 )
{
wxAuiPaneInfo& footprintsPane = m_auimgr.GetPane( "Footprints" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
footprintsPane.MinSize( cfg->m_FootprintsWidth, -1 );
footprintsPane.BestSize( cfg->m_FootprintsWidth, -1 );
footprintsPane.MaxSize( cfg->m_FootprintsWidth, -1 );
footprintsPane.Fixed();
m_auimgr.Update();
// now make it resizable again
footprintsPane.MinSize( 20, -1 );
footprintsPane.Resizable();
m_auimgr.Update();
}
setPaneWidth( m_auimgr.GetPane( "Footprints" ), cfg->m_FootprintsWidth );
}
// Connect Events
@ -653,17 +641,10 @@ void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
candidate->GetFPID().Format().wx_str() );
m_symbolsListBox->SetString( idx, description );
FOOTPRINT_INFO* fp =
m_FootprintsList->GetFootprintInfo( symbol->GetFPID().Format().wx_str() );
if( !fp )
{
if( !m_FootprintsList->GetFootprintInfo( symbol->GetFPID().Format().wx_str() ) )
m_symbolsListBox->AppendWarning( idx );
}
else
{
m_symbolsListBox->RemoveWarning( idx );
}
}
}
@ -840,7 +821,7 @@ void CVPCB_MAINFRAME::DisplayStatus()
else
msg.Printf( _( "Filtered by %s" ), filters );
msg << wxT( ": " ) << m_footprintListBox->GetCount();
msg += wxString::Format( _( ": %i matching footprints" ), m_footprintListBox->GetCount() );
SetStatusText( msg );
@ -909,9 +890,7 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles()
m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
if( m_FootprintsList->GetErrorCount() )
{
m_FootprintsList->DisplayErrors( this );
}
return true;
}
@ -991,66 +970,15 @@ int CVPCB_MAINFRAME::readSchematicNetlist( const std::string& aNetlist )
}
void CVPCB_MAINFRAME::BuildFootprintsListBox()
void CVPCB_MAINFRAME::BuildFootprintsList()
{
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_footprintListBox == nullptr )
{
m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST );
m_footprintListBox->SetFont( KIUI::GetMonospacedUIFont() );
}
m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, nullptr, wxEmptyString,
FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST );
DisplayStatus();
}
void CVPCB_MAINFRAME::BuildSymbolsListBox()
{
wxString msg;
COMPONENT* symbol;
wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
if( m_symbolsListBox == nullptr )
{
m_symbolsListBox = new SYMBOLS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST );
m_symbolsListBox->SetFont( KIUI::GetMonospacedUIFont() );
}
m_symbolsListBox->m_SymbolList.Clear();
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
symbol = m_netlist.GetComponent( i );
msg = formatSymbolDesc( m_symbolsListBox->GetCount() + 1,
symbol->GetReference(),
symbol->GetValue(),
symbol->GetFPID().Format().wx_str() );
m_symbolsListBox->m_SymbolList.Add( msg );
FOOTPRINT_INFO* fp =
m_FootprintsList->GetFootprintInfo( symbol->GetFPID().Format().wx_str() );
if( !fp )
{
m_symbolsListBox->AppendWarning( i );
}
}
if( m_symbolsListBox->m_SymbolList.Count() )
{
m_symbolsListBox->SetItemCount( m_symbolsListBox->m_SymbolList.Count() );
m_symbolsListBox->SetSelection( 0, true );
m_symbolsListBox->RefreshItems( 0L, m_symbolsListBox->m_SymbolList.Count() - 1 );
m_symbolsListBox->UpdateWidth();
}
}
void CVPCB_MAINFRAME::BuildLibrariesListBox()
void CVPCB_MAINFRAME::BuildLibrariesList()
{
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
@ -1124,8 +1052,8 @@ void CVPCB_MAINFRAME::SetSelectedComponent( int aIndex, bool aSkipUpdate )
}
std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
CVPCB_MAINFRAME::CRITERIA aCriteria )
std::vector<unsigned int>
CVPCB_MAINFRAME::GetComponentIndices( CVPCB_MAINFRAME::CRITERIA aCriteria )
{
std::vector<unsigned int> idx;
int lastIdx;
@ -1198,14 +1126,10 @@ wxWindow* CVPCB_MAINFRAME::GetToolCanvas() const
CVPCB_MAINFRAME::CONTROL_TYPE CVPCB_MAINFRAME::GetFocusedControl() const
{
if( m_librariesListBox->HasFocus() )
return CVPCB_MAINFRAME::CONTROL_LIBRARY;
else if( m_symbolsListBox->HasFocus() )
return CVPCB_MAINFRAME::CONTROL_COMPONENT;
else if( m_footprintListBox->HasFocus() )
return CVPCB_MAINFRAME::CONTROL_FOOTPRINT;
return CVPCB_MAINFRAME::CONTROL_NONE;
if( m_librariesListBox->HasFocus() ) return CVPCB_MAINFRAME::CONTROL_LIBRARY;
else if( m_symbolsListBox->HasFocus() ) return CVPCB_MAINFRAME::CONTROL_COMPONENT;
else if( m_footprintListBox->HasFocus() ) return CVPCB_MAINFRAME::CONTROL_FOOTPRINT;
else return CVPCB_MAINFRAME::CONTROL_NONE;
}
@ -1268,8 +1192,8 @@ void CVPCB_MAINFRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
case MAIL_RELOAD_LIB:
m_cannotClose = true;
LoadFootprintFiles();
BuildFootprintsListBox();
BuildLibrariesListBox();
BuildFootprintsList();
BuildLibrariesList();
m_cannotClose = false;
break;
default:

View File

@ -213,11 +213,10 @@ public:
bool aAddUndoItem = true );
/*
* Functions to build the listboxes and their contents
* Functions to build the listbox contents
*/
void BuildSymbolsListBox();
void BuildFootprintsListBox();
void BuildLibrariesListBox();
void BuildFootprintsList();
void BuildLibrariesList();
/**
* Save the edits that the user has done by sending them back to Eeschema via the kiway.

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2018 Jean-Pierre Charras, jean-pierre.charras
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2023 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
@ -94,8 +94,8 @@ bool CVPCB_MAINFRAME::readNetListAndFpFiles( const std::string& aNetlist )
LoadFootprintFiles();
BuildFootprintsListBox();
BuildLibrariesListBox();
BuildFootprintsList();
BuildLibrariesList();
m_symbolsListBox->Clear();
@ -258,6 +258,8 @@ bool CVPCB_MAINFRAME::readNetListAndFpFiles( const std::string& aNetlist )
}
}
int firstUnassigned = wxNOT_FOUND;
// Populates the component list box:
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
@ -270,17 +272,15 @@ bool CVPCB_MAINFRAME::readNetListAndFpFiles( const std::string& aNetlist )
m_symbolsListBox->AppendLine( msg );
FOOTPRINT_INFO* fp =
m_FootprintsList->GetFootprintInfo( component->GetFPID().Format().wx_str() );
if( firstUnassigned == wxNOT_FOUND && component->GetFPID().empty() )
firstUnassigned = i;
if( !fp )
{
if( !m_FootprintsList->GetFootprintInfo( component->GetFPID().Format().wx_str() ) )
m_symbolsListBox->AppendWarning( i );
}
}
if( !m_netlist.IsEmpty() )
m_symbolsListBox->SetSelection( 0, true );
if( firstUnassigned >= 0 )
m_symbolsListBox->SetSelection( firstUnassigned, true );
DisplayStatus();

View File

@ -69,6 +69,7 @@
#include <widgets/lib_tree.h>
#include <widgets/wx_progress_reporters.h>
#include <widgets/symbol_tree_pane.h>
#include <widgets/wx_aui_utils.h>
#include <wildcards_and_files_ext.h>
#include <panel_sym_lib_table.h>
#include <string_utils.h>
@ -202,23 +203,7 @@ SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
FinishAUIInitialization();
if( m_settings->m_LibWidth > 0 )
{
wxAuiPaneInfo& treePane = m_auimgr.GetPane( "SymbolTree" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
treePane.MinSize( m_settings->m_LibWidth, -1 );
treePane.Fixed();
m_auimgr.Update();
// now make it resizable again
treePane.Resizable();
m_auimgr.Update();
// Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
// back to minimum.
treePane.MinSize( 250, -1 );
}
SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "SymbolTree" ), m_settings->m_LibWidth, -1 );
Raise();
Show( true );

View File

@ -37,6 +37,8 @@
#include <symbol_viewer_frame.h>
#include <widgets/msgpanel.h>
#include <widgets/wx_listbox.h>
#include <widgets/wx_aui_utils.h>
#include <widgets/wx_progress_reporters.h>
#include <sch_view.h>
#include <sch_painter.h>
#include <symbol_lib_table.h>
@ -57,7 +59,6 @@
#include <tools/symbol_editor_control.h>
#include <tools/ee_inspection_tool.h>
#include <view/view_controls.h>
#include <widgets/wx_progress_reporters.h>
#include <wx/srchctrl.h>
#include <default_values.h>
@ -239,42 +240,10 @@ SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAM
m_auimgr.Update();
if( m_libListWidth > 0 )
{
wxAuiPaneInfo& treePane = m_auimgr.GetPane( "Libraries" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
treePane.MinSize( m_libListWidth, -1 );
treePane.Fixed();
m_auimgr.Update();
// now make it resizable again
treePane.Resizable();
m_auimgr.Update();
// Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
// back to minimum.
treePane.MinSize( 100, -1 );
}
SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Libraries" ), m_libListWidth, -1 );
if( m_symbolListWidth > 0 )
{
wxAuiPaneInfo& treePane = m_auimgr.GetPane( "Symbols" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
treePane.MinSize( m_symbolListWidth, -1 );
treePane.Fixed();
m_auimgr.Update();
// now make it resizable again
treePane.Resizable();
m_auimgr.Update();
// Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
// back to minimum.
treePane.MinSize( 100, -1 );
}
SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Symbols" ), m_symbolListWidth, -1 );
FinishAUIInitialization();

View File

@ -38,6 +38,7 @@
#include <netlist_reader/pcb_netlist.h>
#include <widgets/msgpanel.h>
#include <widgets/wx_listbox.h>
#include <widgets/wx_aui_utils.h>
#include <pcb_draw_panel_gal.h>
#include <pcb_painter.h>
#include <pcbnew_id.h>
@ -288,42 +289,10 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
m_auimgr.Update();
if( m_libListWidth > 0 )
{
wxAuiPaneInfo& treePane = m_auimgr.GetPane( "Libraries" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
treePane.MinSize( m_libListWidth, -1 );
treePane.Fixed();
m_auimgr.Update();
// now make it resizable again
treePane.Resizable();
m_auimgr.Update();
// Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
// back to minimum.
treePane.MinSize( 100, -1 );
}
SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Libraries" ), m_libListWidth, -1 );
if( m_fpListWidth > 0 )
{
wxAuiPaneInfo& treePane = m_auimgr.GetPane( "Footprints" );
// wxAUI hack: force width by setting MinSize() and then Fixed()
// thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
treePane.MinSize( m_fpListWidth, -1 );
treePane.Fixed();
m_auimgr.Update();
// now make it resizable again
treePane.Resizable();
m_auimgr.Update();
// Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
// back to minimum.
treePane.MinSize( 100, -1 );
}
SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Footprints" ), m_fpListWidth, -1 );
// The canvas should not steal the focus from the list boxes
GetCanvas()->SetCanFocus( false );