Improve symbol library messages.

Includes both error messages and ERC messages.

Fixes https://gitlab.com/kicad/code/kicad/issues/6302
This commit is contained in:
Jeff Young 2020-12-18 12:47:10 +00:00
parent 01f6c90fac
commit 5d400a9e11
3 changed files with 65 additions and 42 deletions

View File

@ -57,9 +57,8 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, DisplayError( this, wxString::Format( _( "Error occurred writing empty symbol library "
wxString::Format( _( "Error occurred writing empty symbol library table " "table.\n\n%s" ),
"file.\n\n%s" ),
SYMBOL_LIB_TABLE::GetGlobalTableFileName(), SYMBOL_LIB_TABLE::GetGlobalTableFileName(),
ioe.What() ) ); ioe.What() ) );
return false; return false;
@ -81,8 +80,7 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
// Make sure the symbol library table to copy actually exists. // Make sure the symbol library table to copy actually exists.
if( !fn.FileExists() ) if( !fn.FileExists() )
{ {
DisplayError( this, DisplayError( this, wxString::Format( _( "File '%s' not found." ), fn.GetFullPath() ) );
wxString::Format( _( "File \"%s\" not found." ), fn.GetFullPath() ) );
return false; return false;
} }
@ -95,9 +93,9 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, DisplayError( this, wxString::Format( _( "'%s' is not a valid symbol library table.\n\n%s" ),
wxString::Format( _( "File \"%s\" is not a valid symbol library table " fn.GetFullPath(),
"file.\n\n%s" ), fn.GetFullPath(), ioe.What() ) ); ioe.What() ) );
return false; return false;
} }
@ -106,8 +104,7 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
if( !symTableFileName.DirExists() && !symTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) ) if( !symTableFileName.DirExists() && !symTableFileName.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
{ {
DisplayError( this, DisplayError( this, wxString::Format( _( "Cannot create global library table path '%s'." ),
wxString::Format( _( "Cannot create global library table path \"%s\"." ),
symTableFileName.GetPath() ) ); symTableFileName.GetPath() ) );
return false; return false;
} }
@ -115,10 +112,10 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
// Copy the global symbol library table file to the user config. // Copy the global symbol library table file to the user config.
if( !::wxCopyFile( fn.GetFullPath(), symTableFileName.GetFullPath() ) ) if( !::wxCopyFile( fn.GetFullPath(), symTableFileName.GetFullPath() ) )
{ {
DisplayError( this, DisplayError( this, wxString::Format( _( "Cannot copy global symbol library table file "
wxString::Format( _( "Cannot copy global symbol library table " "'%s' to '%s'." ),
"file:\n\n \"%s\"\n\n:to:\n\n\"%s\"." ), fn.GetFullPath(),
fn.GetFullPath(), symTableFileName.GetFullPath() ) ); symTableFileName.GetFullPath() ) );
return false; return false;
} }
@ -132,9 +129,9 @@ bool DIALOG_GLOBAL_SYM_LIB_TABLE_CONFIG::TransferDataFromWindow()
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, DisplayError( this, wxString::Format( _( "Error occurred loading global symbol library "
wxString::Format( _( "Error occurred loading global symbol library table:" "table.\n\n%s" ),
"\n\n%s" ), ioe.What() ) ); ioe.What() ) );
return false; return false;
} }

View File

@ -675,6 +675,7 @@ int ERC_TESTER::TestLibSymbolIssues()
{ {
wxCHECK( m_schematic, 0 ); wxCHECK( m_schematic, 0 );
SYMBOL_LIB_TABLE* libTable = m_schematic->Prj().SchSymbolLibTable();
wxString msg; wxString msg;
int err_count = 0; int err_count = 0;
@ -690,40 +691,67 @@ int ERC_TESTER::TestLibSymbolIssues()
wxCHECK2( symbol, continue ); wxCHECK2( symbol, continue );
LIB_PART* libSymbolInSchematic = screen->GetLibSymbols()[ wxString libIdStr = symbol->GetLibId().GetUniStringLibId();
symbol->GetLibId().GetUniStringLibId() ]; LIB_PART* libSymbolInSchematic = screen->GetLibSymbols()[ libIdStr ];
wxCHECK2( libSymbolInSchematic, continue ); wxCHECK2( libSymbolInSchematic, continue );
LIB_PART* libSymbol = SchGetLibPart( symbol->GetLibId(), wxString libName = symbol->GetLibId().GetLibNickname();
m_schematic->Prj().SchSymbolLibTable() ); LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName );
if( !libTableRow )
{
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol );
msg.Printf( _( "The current configuration does not include the library '%s'." ),
libName );
ercItem->SetErrorMessage( msg );
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
break;
}
else if( !libTable->HasLibrary( libName, true ) )
{
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol );
msg.Printf( _( "The library '%s' is not enabled in the current configuration." ),
libName );
ercItem->SetErrorMessage( msg );
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
break;
}
wxString symbolName = symbol->GetLibId().GetLibItemName();
LIB_PART* libSymbol = SchGetLibPart( symbol->GetLibId(), libTable );
if( libSymbol == nullptr ) if( libSymbol == nullptr )
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES ); std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol ); ercItem->SetItems( symbol );
msg.Printf( "Library symbol link \"%s\" cannot be found in symbol library table", msg.Printf( "Symbol '%s' not found in symbol library '%s'",
symbol->GetLibId().GetUniStringLibId() ); symbolName,
libName );
ercItem->SetErrorMessage( msg ); ercItem->SetErrorMessage( msg );
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) ); markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
break;
} }
else
{
std::unique_ptr<LIB_PART> flattenedSymbol = libSymbol->Flatten(); std::unique_ptr<LIB_PART> flattenedSymbol = libSymbol->Flatten();
if( *flattenedSymbol != *libSymbolInSchematic ) if( *flattenedSymbol != *libSymbolInSchematic )
{ {
std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES ); std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
ercItem->SetItems( symbol ); ercItem->SetItems( symbol );
msg.Printf( "Library symbol \"%s\" has been modified", msg.Printf( "Symbol '%s' has been modified in library '%s'.",
symbol->GetLibId().GetUniStringLibId() ); symbolName,
libName );
ercItem->SetErrorMessage( msg ); ercItem->SetErrorMessage( msg );
markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) ); markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
} }
} }
}
for( SCH_MARKER* marker : markers ) for( SCH_MARKER* marker : markers )
{ {

View File

@ -31,7 +31,6 @@
#include <sch_view.h> #include <sch_view.h>
#include <sch_painter.h> #include <sch_painter.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <gal/graphics_abstraction_layer.h>
#include <confirm.h> #include <confirm.h>
#include <preview_items/selection_area.h> #include <preview_items/selection_area.h>
#include <class_library.h> #include <class_library.h>
@ -42,7 +41,6 @@
#include <tool/tool_dispatcher.h> #include <tool/tool_dispatcher.h>
#include <tools/ee_actions.h> #include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h> #include <tools/ee_selection_tool.h>
#include <default_values.h> // For some default values
LIB_PART* SchGetLibPart( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable, PART_LIB* aCacheLib, LIB_PART* SchGetLibPart( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aLibTable, PART_LIB* aCacheLib,