diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 041da9602c..702be0b310 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -37,7 +37,7 @@ #include #include #include - +#include FOOTPRINT_INFO* FOOTPRINT_LIST::GetFootprintInfo( const wxString& aLibNickname, const wxString& aFootprintName ) @@ -123,9 +123,13 @@ static FOOTPRINT_LIST* get_instance_from_id( KIWAY& aKiway, int aId ) try { - KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB ); + ptr = Kiface().IfaceOrAddress( aId ); - ptr = kiface->IfaceOrAddress( aId ); + if( !ptr ) + { + KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB ); + ptr = kiface->IfaceOrAddress( aId ); + } return static_cast( ptr ); } diff --git a/common/project.cpp b/common/project.cpp index f3643a8dee..5989436381 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include diff --git a/cvpcb/cvpcb.cpp b/cvpcb/cvpcb.cpp index 00abbfc94f..840b583d8c 100644 --- a/cvpcb/cvpcb.cpp +++ b/cvpcb/cvpcb.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2007 Jean-Pierre Charras, jp..charras at wanadoo.fr * Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 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 @@ -23,12 +23,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file cvpcb.cpp - */ - #include #include +#include #include #include #include @@ -36,7 +33,7 @@ #include #include #include - +#include namespace CV { @@ -75,7 +72,23 @@ static struct IFACE : public KIFACE_I */ void* IfaceOrAddress( int aDataId ) override { - return NULL; + switch( aDataId ) + { + // Return a pointer to the global instance of the footprint list. + case KIFACE_FOOTPRINT_LIST: + return (void*) &GFootprintList; + + // 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; + } } } kiface( "cvpcb", KIWAY::FACE_CVPCB ); @@ -115,11 +128,19 @@ PGM_BASE* PgmOrNull() } +/// The global footprint library table. This is not dynamically allocated because +/// in a multiple project environment we must keep its address constant (since it is +/// the fallback table for multiple projects). +FP_LIB_TABLE GFootprintTable; + +/// The global footprint info table. This is performance-intensive to build so we +/// keep a hash-stamped global version. Any deviation from the request vs. stored +/// hash will result in it being rebuilt. +FOOTPRINT_LIST_IMPL GFootprintList; + + //!!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it. -FP_LIB_TABLE GFootprintTable; - - // A short lived implementation. cvpcb will get combine into pcbnew shortly, so // we skip setting KICAD6_FOOTPRINT_DIR here for now. User should set the environment // variable. @@ -150,24 +171,22 @@ bool IFACE::OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) if( !FP_LIB_TABLE::LoadGlobalTable( GFootprintTable ) ) { - DisplayInfoMessage( NULL, _( - "You have run CvPcb for the first time using the " - "new footprint library table method for finding " - "footprints.\nCvPcb has either copied the default " - "table or created an empty table in your home " - "folder.\nYou must first configure the library " - "table to include all footprint libraries not " - "included with KiCad.\nSee the \"Footprint Library " - "Table\" section of the CvPcb documentation for " - "more information." ) ); + DisplayInfoMessage( NULL, _( "You have run CvPcb for the first time using the " + "new footprint library table method for finding " + "footprints.\nCvPcb has either copied the default " + "table or created an empty table in your home " + "folder.\nYou must first configure the library " + "table to include all footprint libraries not " + "included with KiCad.\nSee the \"Footprint Library " + "Table\" section of the CvPcb documentation for " + "more information." ) ); } } catch( const IO_ERROR& ioe ) { - DisplayErrorMessage( - nullptr, - _( "An error occurred attempting to load the global footprint library table" ), - ioe.What() ); + DisplayErrorMessage( nullptr, _( "An error occurred attempting to load the global " + "footprint library table." ), + ioe.What() ); return false; } diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 346ee838ee..967ff8c9ea 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -57,15 +56,10 @@ #include #include + #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" ) -/// The global footprint info table. This is performance-intensive to build so we -/// keep a hash-stamped global version. Any deviation from the request vs. stored -/// hash will result in it being rebuilt. -FOOTPRINT_LIST_IMPL GFootprintList; - - 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 ) @@ -78,7 +72,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : m_skipComponentSelect = false; m_filteringOptions = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST; m_tcFilterString = NULL; - m_FootprintsList = &GFootprintList; + m_FootprintsList = FOOTPRINT_LIST::GetInstance( Kiway() ); m_initialized = false; m_aboutTitle = "CvPcb"; @@ -96,8 +90,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : ReCreateMenuBar(); ReCreateHToolbar(); - GFootprintList.ReadCacheFromFile( Prj().GetProjectPath() + "fp-info-cache" ); - // Create list of available footprints and symbols of the schematic BuildSymbolsListBox(); BuildFootprintsListBox(); @@ -777,7 +769,7 @@ void CVPCB_MAINFRAME::DisplayStatus() } // Extract the library information - FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() ); + FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs(); if( fptbl->HasLibrary( lib ) ) msg = wxString::Format( _( "Library location: %s" ), fptbl->GetFullURI( lib ) ); @@ -790,7 +782,7 @@ void CVPCB_MAINFRAME::DisplayStatus() bool CVPCB_MAINFRAME::LoadFootprintFiles() { - FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() ); + FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs(); // Check if there are footprint libraries in the footprint library table. if( !fptbl || !fptbl->GetLogicalLibs().size() ) @@ -949,7 +941,7 @@ void CVPCB_MAINFRAME::BuildLibrariesListBox() wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) ); } - FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() ); + FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); if( tbl ) { diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 222b96eb5a..a7765b9758 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -406,7 +406,7 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() ); wxString fpName = FROM_UTF8( fpid.GetLibItemName().c_str() ); - FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs( Kiway() ); + FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); wxASSERT( fpTable ); // See if the library requested is in the library table diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index bd1afcd01a..8de2efbecf 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -130,7 +130,7 @@ bool CVPCB_MAINFRAME::ReadNetListAndFpFiles( const std::string& aNetlist ) if( component->GetFPID().IsLegacy() ) { // get this first here, it's possibly obsoleted if we get it too soon. - FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() ); + FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); int guess = guessNickname( tbl, (LIB_ID*) &component->GetFPID() ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 57af982f21..d5991371c5 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -151,6 +151,10 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs() DisplayErrorMessage( nullptr, _( "Error loading project footprint libraries." ), ioe.What() ); } + catch( ... ) + { + DisplayErrorMessage( NULL, _( "Error loading project footprint library table." ) ); + } } return tbl;