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;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if( archLib->FindAlias( component->GetLibId().GetLibItemName() ) )
|
if( archLib->FindAlias( component->GetLibId().GetLibItemName() ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LIB_PART* part = GetLibPart( component->GetLibId() );
|
part = GetLibPart( component->GetLibId(), true );
|
||||||
|
|
||||||
if( !part )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
part = Prj().SchLibs()->GetCacheLibrary()->FindPart(
|
|
||||||
component->GetLibId().GetLibItemName() );
|
|
||||||
}
|
}
|
||||||
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.
|
||||||
|
tmp.Printf( _( "Failed to add symbol %s to library file." ),
|
||||||
component->GetLibId().GetLibItemName().wx_str(), aFileName );
|
component->GetLibId().GetLibItemName().wx_str(), aFileName );
|
||||||
DisplayError( this, msg );
|
|
||||||
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,8 +117,29 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -124,8 +147,8 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
||||||
}
|
}
|
||||||
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,7 +315,9 @@ 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
|
||||||
|
{
|
||||||
|
if( m_lib_id.IsValid() )
|
||||||
alias = aLibTable.LoadSymbol( m_lib_id );
|
alias = aLibTable.LoadSymbol( m_lib_id );
|
||||||
|
|
||||||
// Fall back to cache library. This is temporary until the new schematic file
|
// Fall back to cache library. This is temporary until the new schematic file
|
||||||
|
@ -328,6 +330,11 @@ bool SCH_COMPONENT::Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib )
|
||||||
m_part = alias->GetPart()->SharedPtr();
|
m_part = alias->GetPart()->SharedPtr();
|
||||||
return true;
|
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