Fix library save bug in legacy schematic I/O plugin.

Add the ability to save empty symbol library file for caching and empty
schematic.

Remove check for existing symbol in cache populating routine.  Just perform
a complete rebuild of the cache library and overwrite the existing one.

Fixes lp:1663871

https://bugs.launchpad.net/kicad/+bug/1663871
This commit is contained in:
Wayne Stambaugh 2017-02-12 18:40:53 -05:00
parent 3f1bcf5be8
commit d5bf465dc6
2 changed files with 29 additions and 34 deletions

View File

@ -62,10 +62,10 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
SCH_SCREENS screens;
PART_LIBS* libs = Prj().SchLibs();
std::unique_ptr<PART_LIB> libCache( new PART_LIB( LIBRARY_TYPE_EESCHEMA, aFileName ) );
std::unique_ptr<PART_LIB> cacheLib( new PART_LIB( LIBRARY_TYPE_EESCHEMA, aFileName ) );
libCache->SetCache();
libCache->EnableBuffering();
cacheLib->SetCache();
cacheLib->EnableBuffering();
/* Examine all screens (not hierarchical sheets) used in the schematic and build a
* library of unique symbols found in all screens. Complex hierarchies are not a
@ -79,10 +79,6 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
continue;
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
// If not already saved in the new cache, add it.
if( !libCache->FindAlias( component->GetLibId().GetLibItemName() ) )
{
LIB_PART* part = NULL;
try
@ -92,7 +88,7 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
if( part )
{
// AddPart() does first clone the part before adding.
libCache->AddPart( part );
cacheLib->AddPart( part );
}
}
catch( ... /* IO_ERROR ioe */ )
@ -104,11 +100,10 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
}
}
}
}
try
{
libCache->Save( false );
cacheLib->Save( false );
}
catch( ... /* IO_ERROR ioe */ )
{

View File

@ -3527,8 +3527,9 @@ bool SCH_LEGACY_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath,
void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
if( m_cache )
{
if( !m_cache )
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
wxString oldFileName = m_cache->GetFileName();
if( !m_cache->IsFile( aLibraryPath ) )
@ -3541,7 +3542,6 @@ void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const PROPERT
m_cache->Save( writeDocFile( aProperties ) );
m_cache->SetFileName( oldFileName );
}
}
const char* SCH_LEGACY_PLUGIN::PropBuffering = "buffering";