From 75e91f4cfdaad1f4b03174f61b5a1e43656840b5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 1 May 2018 21:46:05 +0100 Subject: [PATCH] Make sure Cvpcb doesn't use its own FP_LIB_TABLE. It's just a vestige of when Cvpcb was a separate app. Fixes: lp:1768251 * https://bugs.launchpad.net/kicad/+bug/1768251 --- common/project.cpp | 4 ++-- cvpcb/cvpcb_mainframe.cpp | 16 ++++++++++++---- cvpcb/menubar.cpp | 8 ++++---- include/kiface_ids.h | 17 ++++++++++++----- pcbnew/pcbnew.cpp | 10 ++++++++-- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/common/project.cpp b/common/project.cpp index 052406f607..7243b18a8b 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -406,13 +406,13 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs( KIWAY& aKiway ) if( !tbl ) { - // Stack the project specific FP_LIB_TABLE overlay on top of the global table. + // Build a new project specific FP_LIB_TABLE with the global table as a fallback. // ~FP_LIB_TABLE() will not touch the fallback table, so multiple projects may // stack this way, all using the same global fallback table. KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB ); if( kiface ) - tbl = (FP_LIB_TABLE*) kiface->IfaceOrAddress( KIFACE_G_FOOTPRINT_TABLE ); + tbl = (FP_LIB_TABLE*) kiface->IfaceOrAddress( KIFACE_NEW_FOOTPRINT_TABLE ); wxASSERT( tbl ); SetElem( ELEM_FPTBL, tbl ); diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 677145b3eb..dc65c0a530 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,6 @@ #include #include - wxSize const FRAME_MIN_SIZE_DU( 350, 250 ); wxSize const FRAME_DEFAULT_SIZE_DU( 450, 300 ); @@ -438,8 +438,16 @@ bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector& aFileSet, i void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent ) { - bool tableChanged = false; - int r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs( Kiway() ) ); + FP_LIB_TABLE* globalTable; + bool tableChanged = false; + KIFACE* kiface = Kiway().KiFACE( KIWAY::FACE_PCB ); + + if( kiface ) + globalTable = (FP_LIB_TABLE*) kiface->IfaceOrAddress( KIFACE_GLOBAL_FOOTPRINT_TABLE ); + else + globalTable = &GFootprintTable; // Shouldn't happen now that Cvpcb is integrated + + int r = InvokePcbLibTableEditor( this, globalTable, Prj().PcbFootprintLibs( Kiway() ) ); if( r & 1 ) { @@ -447,7 +455,7 @@ void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent ) try { - GFootprintTable.Save( fileName ); + globalTable->Save( fileName ); tableChanged = true; } catch( const IO_ERROR& ioe ) diff --git a/cvpcb/menubar.cpp b/cvpcb/menubar.cpp index d378fb9713..817a0b3387 100644 --- a/cvpcb/menubar.cpp +++ b/cvpcb/menubar.cpp @@ -61,10 +61,6 @@ void CVPCB_MAINFRAME::ReCreateMenuBar() // Preferences Menu : wxMenu* preferencesMenu = new wxMenu; - AddMenuItem( preferencesMenu, ID_CVPCB_LIB_TABLE_EDIT, - _( "Manage Footprint &Libraries..." ), _( "Manage footprint libraries" ), - KiBitmap( library_table_xpm ) ); - // Path configuration edit dialog. AddMenuItem( preferencesMenu, ID_PREFERENCES_CONFIGURE_PATHS, @@ -72,6 +68,10 @@ void CVPCB_MAINFRAME::ReCreateMenuBar() _( "Edit path configuration environment variables" ), KiBitmap( editor_xpm ) ); + AddMenuItem( preferencesMenu, ID_CVPCB_LIB_TABLE_EDIT, + _( "Manage Footprint &Libraries..." ), _( "Manage footprint libraries" ), + KiBitmap( library_table_xpm ) ); + preferencesMenu->AppendSeparator(); AddMenuItem( preferencesMenu, ID_CVPCB_EQUFILES_LIST_EDIT, _( "Footprint &Association Files..." ), diff --git a/include/kiface_ids.h b/include/kiface_ids.h index bea9129439..61e9f16537 100644 --- a/include/kiface_ids.h +++ b/include/kiface_ids.h @@ -32,18 +32,25 @@ enum KIFACE_ADDR_ID : int INVALID, /** - * Return a new instance of FOOTPRINT_LIST from pcbnew. + * Return a pointer to the global instance of FOOTPRINT_LIST from pcbnew. * Type is FOOTPRINT_LIST* - * Caller takes ownership + * Caller does NOT own. */ - KIFACE_NEW_FOOTPRINT_LIST, + KIFACE_FOOTPRINT_LIST, /** - * Return a new FP_LIB_TABLE copying the global table. + * Return a new FP_LIB_TABLE with the global table installed as a fallback. * Type is FP_LIB_TABLE* * Caller takes ownership */ - KIFACE_G_FOOTPRINT_TABLE, ///< + KIFACE_NEW_FOOTPRINT_TABLE, + + /** + * Return the global FP_LIB_TABLE. + * Type is FP_LIB_TABLE* + * Caller does NOT own. + */ + KIFACE_GLOBAL_FOOTPRINT_TABLE }; #endif // KIFACE_IDS diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index b464f9f0b3..6129fc2a4c 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -159,12 +159,18 @@ static struct IFACE : public KIFACE_I { switch( aDataId ) { - case KIFACE_NEW_FOOTPRINT_LIST: + // Return a pointer to the global instance of the footprint list. + case KIFACE_FOOTPRINT_LIST: return (void*) &GFootprintList; - case KIFACE_G_FOOTPRINT_TABLE: + // Return a new FP_LIB_TABLE with the global table installed as a fallback. + case KIFACE_NEW_FOOTPRINT_TABLE: return (void*) new FP_LIB_TABLE( &GFootprintTable ); + // Return a pointer to the global instance of the global footprint table. + case KIFACE_GLOBAL_FOOTPRINT_TABLE: + return (void*) &GFootprintTable; + default: return nullptr; }