diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 8966ba5811..406b5bba8a 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -259,11 +259,12 @@ long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname ) } -void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname ) +void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname, + bool aBestEfforts ) { const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); wxASSERT( (PLUGIN*) row->plugin ); - row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), + row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts, row->GetProperties() ); } diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index 766f02a890..70d8bf326a 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -140,7 +140,7 @@ static int guessNickname( FP_LIB_TABLE* aTbl, LIB_ID* aFootprintId ) { wxArrayString fpnames; - aTbl->FootprintEnumerate( fpnames, nicks[libNdx] ); + aTbl->FootprintEnumerate( fpnames, nicks[libNdx], true ); for( unsigned nameNdx = 0; nameNdxfirst.c_str() ) ); + + if( !errorMsg.IsEmpty() && !aBestEfforts ) + THROW_IO_ERROR( errorMsg ); } diff --git a/pcbnew/eagle_plugin.h b/pcbnew/eagle_plugin.h index 01c01d37a3..fbe2901f85 100644 --- a/pcbnew/eagle_plugin.h +++ b/pcbnew/eagle_plugin.h @@ -127,7 +127,7 @@ public: const wxString GetFileExtension() const override; void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL) override; + bool aBestEfforts, const PROPERTIES* aProperties = NULL) override; MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ) override; diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp index 0efbe27034..6ec1cf4ed2 100644 --- a/pcbnew/footprint_info_impl.cpp +++ b/pcbnew/footprint_info_impl.cpp @@ -262,7 +262,7 @@ bool FOOTPRINT_LIST_IMPL::JoinWorkers() try { - m_lib_table->FootprintEnumerate( fpnames, nickname ); + m_lib_table->FootprintEnumerate( fpnames, nickname, false ); } catch( const IO_ERROR& ioe ) { diff --git a/pcbnew/github/github_plugin.cpp b/pcbnew/github/github_plugin.cpp index d450895b71..57593403b3 100644 --- a/pcbnew/github/github_plugin.cpp +++ b/pcbnew/github/github_plugin.cpp @@ -138,34 +138,38 @@ const wxString GITHUB_PLUGIN::GetFileExtension() const } -void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, - const wxString& aLibraryPath, const PROPERTIES* aProperties ) +void GITHUB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath, + bool aBestEfforts, const PROPERTIES* aProperties ) { - //D(printf("%s: this:%p aLibraryPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );) - cacheLib( aLibraryPath, aProperties ); - - typedef std::set MYSET; - - MYSET unique; - - if( m_pretty_dir.size() ) + try { - wxArrayString locals; + //D(printf("%s: this:%p aLibPath:\"%s\"\n", __func__, this, TO_UTF8(aLibraryPath) );) + cacheLib( aLibPath, aProperties ); - PCB_IO::FootprintEnumerate( locals, m_pretty_dir ); + typedef std::set MYSET; - for( unsigned i=0; ibegin(); it!=m_gh_cache->end(); ++it ) + unique.insert( it->first ); + + for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it ) + aFootprintNames.Add( *it ); } - - for( MODULE_ITER it = m_gh_cache->begin(); it!=m_gh_cache->end(); ++it ) + catch( const IO_ERROR& ioe ) { - unique.insert( it->first ); - } - - for( MYSET::const_iterator it = unique.begin(); it != unique.end(); ++it ) - { - aFootprintNames.Add( *it ); + if( !aBestEfforts ) + throw ioe; } } diff --git a/pcbnew/github/github_plugin.h b/pcbnew/github/github_plugin.h index ca633b1a1f..232babdfda 100644 --- a/pcbnew/github/github_plugin.h +++ b/pcbnew/github/github_plugin.h @@ -167,20 +167,20 @@ public: const wxString GetFileExtension() const override; - void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ) override; + void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath, + bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override; void PrefetchLib( const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ) override; + const PROPERTIES* aProperties = NULL ) override; - MODULE* FootprintLoad( const wxString& aLibraryPath, - const wxString& aFootprintName, const PROPERTIES* aProperties ) override; + MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, + const PROPERTIES* aProperties ) override; void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, - const PROPERTIES* aProperties = NULL ) override; + const PROPERTIES* aProperties = NULL ) override; void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, - const PROPERTIES* aProperties = NULL ) override; + const PROPERTIES* aProperties = NULL ) override; bool IsFootprintLibWritable( const wxString& aLibraryPath ) override; diff --git a/pcbnew/gpcb_plugin.cpp b/pcbnew/gpcb_plugin.cpp index 28a9378e79..c76cbdf8da 100644 --- a/pcbnew/gpcb_plugin.cpp +++ b/pcbnew/gpcb_plugin.cpp @@ -867,25 +867,26 @@ void GPCB_PLUGIN::validateCache( const wxString& aLibraryPath, bool checkModifie } -void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, - const wxString& aLibraryPath, - const PROPERTIES* aProperties ) +void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, + bool aBestEfforts, const PROPERTIES* aProperties ) { - LOCALE_IO toggle; // toggles on, then off, the C locale. - wxDir dir( aLibraryPath ); + LOCALE_IO toggle; // toggles on, then off, the C locale. + wxDir dir( aLibraryPath ); + wxString errorMsg; if( !dir.IsOpened() ) { - THROW_IO_ERROR( wxString::Format( _( "footprint library path \"%s\" does not exist" ), - GetChars( aLibraryPath ) ) ); + if( aBestEfforts ) + return; + else + { + THROW_IO_ERROR( wxString::Format( _( "footprint library path \"%s\" does not exist" ), + aLibraryPath ) ); + } } init( aProperties ); - wxString errorMsg; - - // Some of the files may have been parsed correctly so we want to add the valid files to - // the library. try { validateCache( aLibraryPath ); @@ -895,14 +896,13 @@ void GPCB_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, errorMsg = ioe.What(); } - const MODULE_MAP& mods = m_cache->GetModules(); + // Some of the files may have been parsed correctly so we want to add the valid files to + // the library. - for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) - { + for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it ) aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) ); - } - if( !errorMsg.IsEmpty() ) + if( !errorMsg.IsEmpty() && !aBestEfforts ) THROW_IO_ERROR( errorMsg ); } diff --git a/pcbnew/gpcb_plugin.h b/pcbnew/gpcb_plugin.h index 9d15ab51a6..35c3ea06db 100644 --- a/pcbnew/gpcb_plugin.h +++ b/pcbnew/gpcb_plugin.h @@ -63,7 +63,7 @@ public: } void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL) override; + bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override; const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath, const wxString& aFootprintName, diff --git a/pcbnew/io_mgr.h b/pcbnew/io_mgr.h index f8ae881467..d2362cc3d7 100644 --- a/pcbnew/io_mgr.h +++ b/pcbnew/io_mgr.h @@ -353,10 +353,12 @@ public: * * @param aFootprintNames is the array of available footprint names inside a library. * + * @param aBestEfforts if true, don't throw on errors, just return an empty list. + * * @throw IO_ERROR if the library cannot be found, or footprint cannot be loaded. */ virtual void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ); + bool aBestEfforts, const PROPERTIES* aProperties = NULL ); /** * Generate a timestamp representing all the files in the library (including the library diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index cf3155e776..70bb615ad5 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -1938,20 +1938,18 @@ void PCB_IO::validateCache( const wxString& aLibraryPath, bool checkModified ) } -void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, - const wxString& aLibraryPath, - const PROPERTIES* aProperties ) +void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath, + bool aBestEfforts, const PROPERTIES* aProperties ) { - LOCALE_IO toggle; // toggles on, then off, the C locale. - wxDir dir( aLibraryPath ); + LOCALE_IO toggle; // toggles on, then off, the C locale. + wxDir dir( aLibPath ); + wxString errorMsg; init( aProperties ); - wxString errorMsg; - try { - validateCache( aLibraryPath ); + validateCache( aLibPath ); } catch( const IO_ERROR& ioe ) { @@ -1961,14 +1959,10 @@ void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, // Some of the files may have been parsed correctly so we want to add the valid files to // the library. - const MODULE_MAP& mods = m_cache->GetModules(); - - for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) - { + for( MODULE_CITER it = m_cache->GetModules().begin(); it != m_cache->GetModules().end(); ++it ) aFootprintNames.Add( it->first ); - } - if( !errorMsg.IsEmpty() ) + if( !errorMsg.IsEmpty() && !aBestEfforts ) THROW_IO_ERROR( errorMsg ); } diff --git a/pcbnew/kicad_plugin.h b/pcbnew/kicad_plugin.h index 7b2e769f4d..343206ce90 100644 --- a/pcbnew/kicad_plugin.h +++ b/pcbnew/kicad_plugin.h @@ -119,7 +119,7 @@ public: const PROPERTIES* aProperties = NULL ) override; void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ) override; + bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override; const MODULE* GetEnumeratedFootprint( const wxString& aLibraryPath, const wxString& aFootprintName, diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 534caed702..679dda0d6e 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -3246,10 +3246,10 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader ) char* saveptr; if( !line ) - goto L_bad_library; + THROW_IO_ERROR( wxString::Format( _( "File '%s' is empty." ), m_lib_path ) ); if( !TESTLINE( "PCBNEW-LibModule-V1" ) ) - goto L_bad_library; + THROW_IO_ERROR( wxString::Format( _( "File '%s' is not a legacy library." ), m_lib_path ) ); while( ( line = aReader->ReadLine() ) != NULL ) { @@ -3258,18 +3258,12 @@ void LP_CACHE::ReadAndVerifyHeader( LINE_READER* aReader ) const char* units = strtok_r( line + SZ( "Units" ), delims, &saveptr ); if( !strcmp( units, "mm" ) ) - { m_owner->diskToBiu = IU_PER_MM; - } } else if( TESTLINE( "$INDEX" ) ) return; } - -L_bad_library: - THROW_IO_ERROR( wxString::Format( _( "File \"%s\" is empty or is not a legacy library" ), - m_lib_path.GetData() ) ); } @@ -3409,22 +3403,31 @@ void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath ) } -void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, - const wxString& aLibraryPath, - const PROPERTIES* aProperties ) +void LEGACY_PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath, + bool aBestEfforts, const PROPERTIES* aProperties ) { - LOCALE_IO toggle; // toggles on, then off, the C locale. + LOCALE_IO toggle; // toggles on, then off, the C locale. + wxString errorMsg; init( aProperties ); - cacheLib( aLibraryPath ); - - const MODULE_MAP& mods = m_cache->m_modules; - - for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it ) + try { - aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) ); + cacheLib( aLibPath ); } + catch( const IO_ERROR& ioe ) + { + errorMsg = ioe.What(); + } + + // Some of the files may have been parsed correctly so we want to add the valid files to + // the library. + + for( MODULE_CITER it = m_cache->m_modules.begin(); it != m_cache->m_modules.end(); ++it ) + aFootprintNames.Add( FROM_UTF8( it->first.c_str() ) ); + + if( !errorMsg.IsEmpty() && !aBestEfforts ) + THROW_IO_ERROR( errorMsg ); } diff --git a/pcbnew/legacy_plugin.h b/pcbnew/legacy_plugin.h index 297abfcb30..eaff07f9cb 100644 --- a/pcbnew/legacy_plugin.h +++ b/pcbnew/legacy_plugin.h @@ -85,7 +85,7 @@ public: const PROPERTIES* aProperties = NULL ) override; void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ) override; + bool aBestEfforts, const PROPERTIES* aProperties = NULL ) override; MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ) override; diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index 8a025c8312..614153e82a 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -411,7 +411,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveLibraryAs( const wxString& aLibraryPath ) wxArrayString footprints; - cur->FootprintEnumerate( footprints, curLibPath ); + cur->FootprintEnumerate( footprints, curLibPath, false ); for( unsigned i = 0; i < footprints.size(); ++i ) { diff --git a/pcbnew/plugin.cpp b/pcbnew/plugin.cpp index 14b6e14f13..6b85411c09 100644 --- a/pcbnew/plugin.cpp +++ b/pcbnew/plugin.cpp @@ -58,7 +58,7 @@ void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* a void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath, - const PROPERTIES* aProperties ) + bool aBestEfforts, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the PLUGIN interface. not_implemented( this, __FUNCTION__ ); diff --git a/pcbnew/swig/footprint.i b/pcbnew/swig/footprint.i index 5d13d8a223..c71ddede1e 100644 --- a/pcbnew/swig/footprint.i +++ b/pcbnew/swig/footprint.i @@ -77,18 +77,7 @@ { wxArrayString footprintNames; - if( aExitOnError ) - self->FootprintEnumerate( footprintNames, aLibraryPath ); - else - { - try - { - self->FootprintEnumerate( footprintNames, aLibraryPath ); - } - catch( const IO_ERROR& error ) - { - } - } + self->FootprintEnumerate( footprintNames, aLibraryPath, !aExitOnError ); return footprintNames; }