diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index caf21c79be..8966ba5811 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -341,8 +341,11 @@ bool FP_LIB_TABLE::FootprintExists( const wxString& aNickname, const wxString& a { try { - std::unique_ptr m( FootprintLoad( aNickname, aFootprintName ) ); - return m.get() != nullptr; + const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); + wxASSERT( (PLUGIN*) row->plugin ); + + return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName, + row->GetProperties() ); } catch( ... ) { diff --git a/pcbnew/io_mgr.h b/pcbnew/io_mgr.h index d873633fa6..f8ae881467 100644 --- a/pcbnew/io_mgr.h +++ b/pcbnew/io_mgr.h @@ -420,6 +420,13 @@ public: const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ); + /** + * Function FootprintExists + * check for the existence of a footprint. + */ + virtual bool FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName, + const PROPERTIES* aProperties = NULL ); + /** * Function FootprintSave * will write @a aModule to an existing library located at @a aLibraryPath. diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index df0ec7a155..cf3155e776 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -2012,6 +2012,22 @@ const MODULE* PCB_IO::GetEnumeratedFootprint( const wxString& aLibraryPath, } +bool PCB_IO::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName, + const PROPERTIES* aProperties ) +{ + // Note: checking the cache sounds like a good idea, but won't catch files which differ + // only in case. + // + // Since this goes out to the native filesystem, we get platform differences (ie: MSW's + // case-insensitive filesystem) handled "for free". + + wxFileName footprintFile( aLibraryPath, aFootprintName ); + footprintFile.SetExt( KiCadFootprintFileExtension ); + + return footprintFile.Exists(); +} + + MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties ) { diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h index 2f408cc3bc..7b2e769f4d 100644 --- a/pcbnew/kicad_plugin.h +++ b/pcbnew/kicad_plugin.h @@ -125,6 +125,9 @@ public: const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ) override; + bool FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName, + const PROPERTIES* aProperties = NULL ) override; + MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ) override; diff --git a/pcbnew/plugin.cpp b/pcbnew/plugin.cpp index 5ca5a351dd..14b6e14f13 100644 --- a/pcbnew/plugin.cpp +++ b/pcbnew/plugin.cpp @@ -81,6 +81,14 @@ const MODULE* PLUGIN::GetEnumeratedFootprint( const wxString& aLibraryPath, } +bool PLUGIN::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName, + const PROPERTIES* aProperties ) +{ + // default implementation + return FootprintLoad( aLibraryPath, aFootprintName, aProperties ) != nullptr; +} + + MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties ) {