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 )
|
bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString tmp;
|
||||||
|
wxString errorMsg;
|
||||||
SCH_SCREENS screens;
|
SCH_SCREENS screens;
|
||||||
|
|
||||||
// Create a new empty library to archive components:
|
// 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 )
|
if( item->Type() != SCH_COMPONENT_T )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
LIB_PART* part = nullptr;
|
||||||
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
||||||
|
|
||||||
if( archLib->FindAlias( component->GetLibId().GetLibItemName() ) )
|
try
|
||||||
continue;
|
|
||||||
|
|
||||||
LIB_PART* part = GetLibPart( component->GetLibId() );
|
|
||||||
|
|
||||||
if( !part )
|
|
||||||
{
|
{
|
||||||
try
|
if( archLib->FindAlias( component->GetLibId().GetLibItemName() ) )
|
||||||
{
|
continue;
|
||||||
part = Prj().SchLibs()->GetCacheLibrary()->FindPart(
|
|
||||||
component->GetLibId().GetLibItemName() );
|
part = GetLibPart( component->GetLibId(), true );
|
||||||
}
|
}
|
||||||
catch( ... /* IO_ERROR ioe */ )
|
catch( const IO_ERROR& ioe )
|
||||||
{
|
{
|
||||||
msg.Printf( _( "Failed to add symbol %s to library file '%s'" ),
|
// Queue up error messages for later.
|
||||||
component->GetLibId().GetLibItemName().wx_str(), aFileName );
|
tmp.Printf( _( "Failed to add symbol %s to library file." ),
|
||||||
DisplayError( this, msg );
|
component->GetLibId().GetLibItemName().wx_str(), aFileName );
|
||||||
return false;
|
|
||||||
}
|
// 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 )
|
if( part )
|
||||||
|
@ -115,17 +117,38 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
||||||
// AddPart() does first clone the part before adding.
|
// AddPart() does first clone the part before adding.
|
||||||
archLib->AddPart( part );
|
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
|
try
|
||||||
{
|
{
|
||||||
archLib->Save( false );
|
archLib->Save( false );
|
||||||
}
|
}
|
||||||
catch( ... /* IO_ERROR ioe */ )
|
catch( ... /* IO_ERROR ioe */ )
|
||||||
{
|
{
|
||||||
msg.Printf( _( "Failed to save symbol library file '%s'" ), aFileName );
|
errorMsg.Printf( _( "Failed to save symbol library file '%s'" ), aFileName );
|
||||||
DisplayError( this, msg );
|
DisplayError( this, errorMsg );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -315,18 +315,25 @@ bool SCH_COMPONENT::Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib )
|
||||||
{
|
{
|
||||||
LIB_ALIAS* alias = nullptr;
|
LIB_ALIAS* alias = nullptr;
|
||||||
|
|
||||||
if( !m_lib_id.GetLibNickname().empty() && aLibTable.HasLibrary( m_lib_id.GetLibNickname() ) )
|
try
|
||||||
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();
|
if( m_lib_id.IsValid() )
|
||||||
return true;
|
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;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue