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,36 +79,31 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
continue;
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
LIB_PART* part = NULL;
// If not already saved in the new cache, add it.
if( !libCache->FindAlias( component->GetLibId().GetLibItemName() ) )
try
{
LIB_PART* part = NULL;
part = libs->FindLibPart( component->GetLibId() );
try
if( part )
{
part = libs->FindLibPart( component->GetLibId() );
if( part )
{
// AddPart() does first clone the part before adding.
libCache->AddPart( part );
}
}
catch( ... /* IO_ERROR ioe */ )
{
msg.Printf( _( "Failed to add symbol %s to library file '%s'" ),
wxString( component->GetLibId().GetLibItemName() ), aFileName );
DisplayError( this, msg );
return false;
// AddPart() does first clone the part before adding.
cacheLib->AddPart( part );
}
}
catch( ... /* IO_ERROR ioe */ )
{
msg.Printf( _( "Failed to add symbol %s to library file '%s'" ),
wxString( component->GetLibId().GetLibItemName() ), aFileName );
DisplayError( this, msg );
return false;
}
}
}
try
{
libCache->Save( false );
cacheLib->Save( false );
}
catch( ... /* IO_ERROR ioe */ )
{

View File

@ -3527,20 +3527,20 @@ 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 ) )
{
wxString oldFileName = m_cache->GetFileName();
if( !m_cache->IsFile( aLibraryPath ) )
{
m_cache->SetFileName( aLibraryPath );
}
// This is a forced save.
m_cache->SetModified();
m_cache->Save( writeDocFile( aProperties ) );
m_cache->SetFileName( oldFileName );
m_cache->SetFileName( aLibraryPath );
}
// This is a forced save.
m_cache->SetModified();
m_cache->Save( writeDocFile( aProperties ) );
m_cache->SetFileName( oldFileName );
}