More safety (and better impl) for not sharing FP table/info stuff.

Fixes https://gitlab.com/kicad/code/kicad/issues/8657
This commit is contained in:
Jeff Young 2021-06-29 12:45:02 +01:00
parent 6c67dfa032
commit 1db33c7b3a
7 changed files with 61 additions and 43 deletions

View File

@ -37,7 +37,7 @@
#include <lib_id.h>
#include <thread>
#include <utility>
#include <kiface_i.h>
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<FOOTPRINT_LIST*>( ptr );
}

View File

@ -24,7 +24,6 @@
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <config_params.h>
#include <confirm.h>
#include <core/arraydim.h>
#include <fp_lib_table.h>

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2007 Jean-Pierre Charras, jp..charras at wanadoo.fr
* Copyright (C) 2014 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* 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 <confirm.h>
#include <fp_lib_table.h>
#include <footprint_info_impl.h>
#include <kiface_i.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
@ -36,7 +33,7 @@
#include <cvpcb_mainframe.h>
#include <cvpcb_settings.h>
#include <display_footprints_frame.h>
#include <kiface_ids.h>
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;
}

View File

@ -32,7 +32,6 @@
#include <kiway_express.h>
#include <macros.h>
#include <netlist_reader/netlist_reader.h>
#include <footprint_info_impl.h>
#include <numeric>
#include <tool/action_manager.h>
#include <tool/action_toolbar.h>
@ -57,15 +56,10 @@
#include <wx/button.h>
#include <wx/settings.h>
#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 )
{

View File

@ -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

View File

@ -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() );

View File

@ -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;