From 076c2c762a40af011f6a05fb0076fc49bb0a2ef2 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sun, 22 Sep 2013 13:20:46 -0400 Subject: [PATCH] Pcbnew footprint library table fixes. * Make footprint editor work properly with library table. * Fix bug in Eagle plugin when comparing file timestamps. * Fix bug in footprint viewer when error occur loading footprints from the selected library. * Fix error message display by in footprint viewer on library load error. --- pcbnew/eagle_plugin.cpp | 17 +++++++++++------ pcbnew/librairi.cpp | 16 +++------------- pcbnew/loadcmp.cpp | 16 +++++++++++++++- pcbnew/modview_frame.cpp | 19 ++++++++++++++----- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index f660ee28ab..842c94aed8 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -93,6 +93,9 @@ typedef boost::optional opt_double; typedef boost::optional opt_bool; +const wxChar* traceEaglePlugin = wxT( "KicadEaglePlugin" ); + + /// segment (element) of our XPATH into the Eagle XML document tree in PTREE form. struct TRIPLET { @@ -2731,15 +2734,17 @@ void EAGLE_PLUGIN::cacheLib( const wxString& aLibPath ) { try { - wxDateTime modtime; + wxDateTime modtime = getModificationTime( aLibPath ); - if( !m_mod_time.IsValid() ) - m_mod_time.Now(); + // Fixes assertions in wxWidgets debug builds for the wxDateTime object. Refresh the + // cache if either of the wxDateTime objects are invalid or the last file modification + // time differs from the current file modification time. + bool load = !m_mod_time.IsValid() || !modtime.IsValid() || + m_mod_time != modtime; - if( aLibPath != m_lib_path || - m_mod_time != ( modtime = getModificationTime( aLibPath ) ) ) + if( aLibPath != m_lib_path || load ) { - //D(printf("Loading '%s'\n", TO_UTF8( aLibPath ) );) + wxLogTrace( traceEaglePlugin, wxT( "Loading '%s'" ), TO_UTF8( aLibPath ) ); PTREE doc; LOCALE_IO toggle; // toggles on, then off, the C locale. diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index d7b5889e5a..708fca9e1e 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -825,20 +825,10 @@ void FOOTPRINT_EDIT_FRAME::Select_Active_Library() wxString uri = m_footprintLibTable->FindRow( dlg.GetTextSelection() )->GetFullURI(); wxFileName fileName = FP_LIB_TABLE::ExpandSubstitutions( uri ); - if( fileName.IsOk() && fileName.FileExists() ) - { - setLibPath( fileName.GetFullPath() ); - } - else - { - wxString msg = wxString::Format( FMT_BAD_PATHS, GetChars( dlg.GetTextSelection() ) ); - - DisplayError( this, msg ); - - setLibNickName( wxEmptyString ); - setLibPath( wxEmptyString ); - } + wxLogDebug( wxT( "Loading footprint library <%s> from <%s>." ), + GetChars( dlg.GetTextSelection() ), GetChars( fileName.GetFullPath() ) ); + setLibPath( fileName.GetFullPath() ); updateTitle(); } diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index d4a6134d7c..53dde24230 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -511,7 +511,21 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow, return wxEmptyString; } - MList.ReadFootprintFiles( libTable ); + if( !MList.ReadFootprintFiles( libTable ) ) + { + msg.Format( _( "Error occurred attempting to load footprint library <%s>:\n\n" ), + GetChars( aLibraryFullFilename ) ); + + if( !MList.m_filesNotFound.IsEmpty() ) + msg += _( "Files not found:\n\n" ) + MList.m_filesNotFound; + + if( !MList.m_filesInvalid.IsEmpty() ) + msg += _("\n\nFile load errors:\n\n" ) + MList.m_filesInvalid; + + DisplayError( this, msg ); + return wxEmptyString; + } + #endif if( MList.GetCount() == 0 ) diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 69bdee754f..24e21aae95 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -429,7 +429,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList() bool libLoaded = false; FOOTPRINT_LIST fp_info_list; wxArrayString libsList; - wxBusyCursor busyCursor; #if !defined( USE_FP_LIB_TABLE ) libsList.Add( m_libraryName ); @@ -453,11 +452,18 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList() if( !libLoaded ) { + m_libraryName = wxEmptyString; + wxString msg; - msg.Format( _( "Error occurred attempting to load footprint library <%s>:\n\n" - "Files not found:\n\n%s\n\nFile load errors:\n\n%s" ), - GetChars( m_libraryName ), GetChars( fp_info_list.m_filesNotFound ), - GetChars( fp_info_list.m_filesInvalid ) ); + msg.Format( _( "Error occurred attempting to load footprint library <%s>:\n\n" ), + GetChars( m_libraryName ) ); + + if( !fp_info_list.m_filesNotFound.IsEmpty() ) + msg += _( "Files not found:\n\n" ) + fp_info_list.m_filesNotFound; + + if( !fp_info_list.m_filesInvalid.IsEmpty() ) + msg += _("\n\nFile load errors:\n\n" ) + fp_info_list.m_filesInvalid; + DisplayError( this, msg ); return; } @@ -502,6 +508,9 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event ) void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) { + if( m_FootprintList->GetCount() == 0 ) + return; + int ii = m_FootprintList->GetSelection(); if( ii < 0 )