From 324f5e11270b3c719ca9c5b55b6581e9fba02495 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 4 May 2025 11:16:16 +0100 Subject: [PATCH] Timestamps for altium footprint libs. (cherry picked from commit afce3eb2d9092fd78a4c58d6247757ef0f99dff9) --- .../pcb_io/altium/pcb_io_altium_designer.cpp | 44 ++++++++----------- pcbnew/pcb_io/altium/pcb_io_altium_designer.h | 8 +++- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pcbnew/pcb_io/altium/pcb_io_altium_designer.cpp b/pcbnew/pcb_io/altium/pcb_io_altium_designer.cpp index a087642050..385c197fde 100644 --- a/pcbnew/pcb_io/altium/pcb_io_altium_designer.cpp +++ b/pcbnew/pcb_io/altium/pcb_io_altium_designer.cpp @@ -178,34 +178,33 @@ void PCB_IO_ALTIUM_DESIGNER::loadAltiumLibrary( const wxString& aLibraryPath ) { fontconfig::FONTCONFIG::SetReporter( nullptr ); + long long timestamp = GetLibraryTimestamp( aLibraryPath ); + + if( m_fplibFiles.contains( aLibraryPath ) && m_fplibFiles[aLibraryPath].m_Timestamp == timestamp ) + return; // Already loaded + try { - auto it = m_fplibFiles.find( aLibraryPath ); - - if( it != m_fplibFiles.end() ) - return; // Already loaded + ALTIUM_FILE_CACHE& libFiles = m_fplibFiles[aLibraryPath]; if( aLibraryPath.Lower().EndsWith( wxS( ".pcblib" ) ) ) { - m_fplibFiles[aLibraryPath].emplace_back( - std::make_unique( aLibraryPath ) ); + libFiles.m_Files.emplace_back( std::make_unique( aLibraryPath ) ); } else if( aLibraryPath.Lower().EndsWith( wxS( ".intlib" ) ) ) { - std::unique_ptr intCom = - std::make_unique( aLibraryPath ); - - std::map pcbLibFiles = - intCom->EnumDir( L"PCBLib" ); + std::unique_ptr lib = std::make_unique( aLibraryPath ); - for( const auto& [pcbLibName, pcbCfe] : pcbLibFiles ) + for( const auto& [pcbLibName, pcbCfe] : lib->EnumDir( L"PCBLib" ) ) { - auto decodedStream = std::make_unique(); + std::unique_ptr libFile = std::make_unique(); - if( intCom->DecodeIntLibStream( *pcbCfe, decodedStream.get() ) ) - m_fplibFiles[aLibraryPath].emplace_back( std::move( decodedStream ) ); + if( lib->DecodeIntLibStream( *pcbCfe, libFile.get() ) ) + libFiles.m_Files.emplace_back( std::move( libFile ) ); } } + + libFiles.m_Timestamp = timestamp; } catch( CFB::CFBException& exception ) { @@ -220,14 +219,12 @@ void PCB_IO_ALTIUM_DESIGNER::FootprintEnumerate( wxArrayString& aFootprintNames { loadAltiumLibrary( aLibraryPath ); - auto it = m_fplibFiles.find( aLibraryPath ); - - if( it == m_fplibFiles.end() ) + if( !m_fplibFiles.contains( aLibraryPath ) ) return; // No footprint libraries in file, ignore. try { - for( auto& altiumLibFile : it->second ) + for( std::unique_ptr& altiumLibFile : m_fplibFiles[aLibraryPath].m_Files ) { // Map code-page-dependent names to unicode names CASE_INSENSITIVE_MAP patternMap = altiumLibFile->ListLibFootprints(); @@ -279,8 +276,7 @@ void PCB_IO_ALTIUM_DESIGNER::FootprintEnumerate( wxArrayString& aFootprintNames } else { - THROW_IO_ERROR( - wxString::Format( "Component name not found: '%s'", fpPattern ) ); + THROW_IO_ERROR( wxString::Format( "Component name not found: '%s'", fpPattern ) ); } parser.SkipSubrecord(); @@ -312,14 +308,12 @@ FOOTPRINT* PCB_IO_ALTIUM_DESIGNER::FootprintLoad( const wxString& aLibraryPath, { loadAltiumLibrary( aLibraryPath ); - auto it = m_fplibFiles.find( aLibraryPath ); - - if( it == m_fplibFiles.end() ) + if( !m_fplibFiles.contains( aLibraryPath ) ) THROW_IO_ERROR( wxString::Format( _( "No footprints in library '%s'" ), aLibraryPath ) ); try { - for( std::unique_ptr& altiumLibFile : it->second ) + for( std::unique_ptr& altiumLibFile : m_fplibFiles[aLibraryPath].m_Files ) { altiumLibFile->CacheLibModels(); auto [dirName, fpCfe] = altiumLibFile->FindLibFootprintDirName( aFootprintName ); diff --git a/pcbnew/pcb_io/altium/pcb_io_altium_designer.h b/pcbnew/pcb_io/altium/pcb_io_altium_designer.h index fa218917ec..006176d90f 100644 --- a/pcbnew/pcb_io/altium/pcb_io_altium_designer.h +++ b/pcbnew/pcb_io/altium/pcb_io_altium_designer.h @@ -34,6 +34,7 @@ class ALTIUM_PCB_COMPOUND_FILE; + class PCB_IO_ALTIUM_DESIGNER : public PCB_IO, public LAYER_MAPPABLE_PLUGIN { public: @@ -87,8 +88,13 @@ public: const std::vector& aInputLayerDescriptionVector ); private: - std::map>> m_fplibFiles; + struct ALTIUM_FILE_CACHE + { + std::vector> m_Files; + long long m_Timestamp; + }; + std::map m_fplibFiles; void loadAltiumLibrary( const wxString& aLibraryPath ); };