Symbol library archive bug fixes.
Move FindAlias() inside a try/catch block as is can throw an exception. Don't abort adding symbols to library when a symbol cannot be found in the symbol library table or the cache library. Instead, queue up error messages and display them after attempting to add all of the symbols. Always save the library file even if some of the symbols could not be archived. Catch IO_ERRORs in SCH_COMPONENT resolve to prevent unhandled exceptions further up the stack.
This commit is contained in:
parent
56d73f837d
commit
168bf5e4b0
|
@ -66,7 +66,8 @@ bool SCH_EDIT_FRAME::CreateArchiveLibraryCacheFile( bool aUseCurrentSheetFilenam
|
|||
|
||||
bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
||||
{
|
||||
wxString msg;
|
||||
wxString tmp;
|
||||
wxString errorMsg;
|
||||
SCH_SCREENS screens;
|
||||
|
||||
// Create a new empty library to archive components:
|
||||
|
@ -87,27 +88,28 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
|||
if( item->Type() != SCH_COMPONENT_T )
|
||||
continue;
|
||||
|
||||
LIB_PART* part = nullptr;
|
||||
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
||||
|
||||
if( archLib->FindAlias( component->GetLibId().GetLibItemName() ) )
|
||||
continue;
|
||||
|
||||
LIB_PART* part = GetLibPart( component->GetLibId() );
|
||||
|
||||
if( !part )
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
part = Prj().SchLibs()->GetCacheLibrary()->FindPart(
|
||||
component->GetLibId().GetLibItemName() );
|
||||
}
|
||||
catch( ... /* IO_ERROR ioe */ )
|
||||
{
|
||||
msg.Printf( _( "Failed to add symbol %s to library file '%s'" ),
|
||||
component->GetLibId().GetLibItemName().wx_str(), aFileName );
|
||||
DisplayError( this, msg );
|
||||
return false;
|
||||
}
|
||||
if( archLib->FindAlias( component->GetLibId().GetLibItemName() ) )
|
||||
continue;
|
||||
|
||||
part = GetLibPart( component->GetLibId(), true );
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
// Queue up error messages for later.
|
||||
tmp.Printf( _( "Failed to add symbol %s to library file." ),
|
||||
component->GetLibId().GetLibItemName().wx_str(), aFileName );
|
||||
|
||||
// Don't bail out here. Attempt to add as many of the symbols to the library
|
||||
// as possible.
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
tmp = _( "Unexpected exception occurred." );
|
||||
}
|
||||
|
||||
if( part )
|
||||
|
@ -115,17 +117,38 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
|||
// AddPart() does first clone the part before adding.
|
||||
archLib->AddPart( part );
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp.Printf( _( "Symbol %s not found in any library or cache." ),
|
||||
component->GetLibId().Format().wx_str() );
|
||||
}
|
||||
|
||||
if( !tmp.empty() )
|
||||
{
|
||||
if( errorMsg.empty() )
|
||||
errorMsg += tmp;
|
||||
else
|
||||
errorMsg += "\n" + tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !errorMsg.empty() )
|
||||
{
|
||||
tmp.Printf( _( "Errors occurred creating symbol library %s." ), aFileName );
|
||||
DisplayErrorMessage( this, tmp, errorMsg );
|
||||
}
|
||||
|
||||
archLib->EnableBuffering( false );
|
||||
|
||||
try
|
||||
{
|
||||
archLib->Save( false );
|
||||
}
|
||||
catch( ... /* IO_ERROR ioe */ )
|
||||
{
|
||||
msg.Printf( _( "Failed to save symbol library file '%s'" ), aFileName );
|
||||
DisplayError( this, msg );
|
||||
errorMsg.Printf( _( "Failed to save symbol library file '%s'" ), aFileName );
|
||||
DisplayError( this, errorMsg );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -315,18 +315,25 @@ bool SCH_COMPONENT::Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib )
|
|||
{
|
||||
LIB_ALIAS* alias = nullptr;
|
||||
|
||||
if( !m_lib_id.GetLibNickname().empty() && aLibTable.HasLibrary( m_lib_id.GetLibNickname() ) )
|
||||
alias = aLibTable.LoadSymbol( m_lib_id );
|
||||
|
||||
// Fall back to cache library. This is temporary until the new schematic file
|
||||
// format is implemented.
|
||||
if( !alias && aCacheLib )
|
||||
alias = aCacheLib->FindAlias( m_lib_id.GetLibItemName() );
|
||||
|
||||
if( alias && alias->GetPart() )
|
||||
try
|
||||
{
|
||||
m_part = alias->GetPart()->SharedPtr();
|
||||
return true;
|
||||
if( m_lib_id.IsValid() )
|
||||
alias = aLibTable.LoadSymbol( m_lib_id );
|
||||
|
||||
// Fall back to cache library. This is temporary until the new schematic file
|
||||
// format is implemented.
|
||||
if( !alias && aCacheLib )
|
||||
alias = aCacheLib->FindAlias( m_lib_id.GetLibItemName() );
|
||||
|
||||
if( alias && alias->GetPart() )
|
||||
{
|
||||
m_part = alias->GetPart()->SharedPtr();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
wxLogDebug( "Cannot resolve library symbol %s", m_lib_id.Format().wx_str() );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue