Fix library tree behavior when duplicate project table entry is disabled.

Fixes https://gitlab.com/kicad/code/kicad/issues/5438
This commit is contained in:
Wayne Stambaugh 2021-01-10 17:55:30 -05:00
parent 6c648df4c6
commit 1eee72ec65
12 changed files with 99 additions and 71 deletions

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2012-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -244,19 +244,26 @@ void FP_LIB_TABLE::Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const
long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname ) long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname )
{ {
long long hash = 0;
if( aNickname ) if( aNickname )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( *aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( *aNickname, true );
wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) + wxHashTable::MakeKey( *aNickname ); wxCHECK( row && row->plugin, hash );
return row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) +
wxHashTable::MakeKey( *aNickname );
} }
long long hash = 0; for( const wxString& nickname : GetLogicalLibs() )
for( wxString const& nickname : GetLogicalLibs() )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( nickname ); const FP_LIB_TABLE_ROW* row = FindRow( nickname, true );
wxASSERT( (PLUGIN*) row->plugin );
hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) + wxHashTable::MakeKey( nickname ); wxCHECK2( row && row->plugin, continue );
hash += row->plugin->GetLibraryTimestamp( row->GetFullURI( true ) ) +
wxHashTable::MakeKey( nickname );
} }
return hash; return hash;
@ -266,7 +273,7 @@ long long FP_LIB_TABLE::GenerateTimestamp( const wxString* aNickname )
void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname, void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname,
bool aBestEfforts ) bool aBestEfforts )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts, row->plugin->FootprintEnumerate( aFootprintNames, row->GetFullURI( true ), aBestEfforts,
row->GetProperties() ); row->GetProperties() );
@ -275,17 +282,17 @@ void FP_LIB_TABLE::FootprintEnumerate( wxArrayString& aFootprintNames, const wxS
void FP_LIB_TABLE::PrefetchLib( const wxString& aNickname ) void FP_LIB_TABLE::PrefetchLib( const wxString& aNickname )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() ); row->plugin->PrefetchLib( row->GetFullURI( true ), row->GetProperties() );
} }
const FP_LIB_TABLE_ROW* FP_LIB_TABLE::FindRow( const wxString& aNickname ) const FP_LIB_TABLE_ROW* FP_LIB_TABLE::FindRow( const wxString& aNickname, bool aCheckIfEnabled )
{ {
// Do not optimize this code. Is done this way specifically to fix a runtime // Do not optimize this code. Is done this way specifically to fix a runtime
// error with clang 4.0.1. // error with clang 4.0.1.
LIB_TABLE_ROW* ltrow = findRow( aNickname ); LIB_TABLE_ROW* ltrow = findRow( aNickname, aCheckIfEnabled );
FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( ltrow ); FP_LIB_TABLE_ROW* row = dynamic_cast< FP_LIB_TABLE_ROW* >( ltrow );
if( !row ) if( !row )
@ -333,7 +340,7 @@ static void setLibNickname( FOOTPRINT* aModule, const wxString& aNickname,
const FOOTPRINT* FP_LIB_TABLE::GetEnumeratedFootprint( const wxString& aNickname, const FOOTPRINT* FP_LIB_TABLE::GetEnumeratedFootprint( const wxString& aNickname,
const wxString& aFootprintName ) const wxString& aFootprintName )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName, return row->plugin->GetEnumeratedFootprint( row->GetFullURI( true ), aFootprintName,
@ -345,7 +352,7 @@ bool FP_LIB_TABLE::FootprintExists( const wxString& aNickname, const wxString& a
{ {
try try
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName, return row->plugin->FootprintExists( row->GetFullURI( true ), aFootprintName,
@ -360,7 +367,7 @@ bool FP_LIB_TABLE::FootprintExists( const wxString& aNickname, const wxString& a
FOOTPRINT* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxString& aFootprintName ) FOOTPRINT* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxString& aFootprintName )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
FOOTPRINT* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName, FOOTPRINT* ret = row->plugin->FootprintLoad( row->GetFullURI( true ), aFootprintName,
@ -375,7 +382,7 @@ FOOTPRINT* FP_LIB_TABLE::FootprintLoad( const wxString& aNickname, const wxStrin
FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave( const wxString& aNickname, FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave( const wxString& aNickname,
const FOOTPRINT* aFootprint, bool aOverwrite ) const FOOTPRINT* aFootprint, bool aOverwrite )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
if( !aOverwrite ) if( !aOverwrite )
@ -401,7 +408,7 @@ FP_LIB_TABLE::SAVE_T FP_LIB_TABLE::FootprintSave( const wxString& aNickname,
void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& aFootprintName ) void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& aFootprintName )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName, return row->plugin->FootprintDelete( row->GetFullURI( true ), aFootprintName,
row->GetProperties() ); row->GetProperties() );
@ -410,7 +417,7 @@ void FP_LIB_TABLE::FootprintDelete( const wxString& aNickname, const wxString& a
bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname ) bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) ); return row->plugin->IsFootprintLibWritable( row->GetFullURI( true ) );
} }
@ -418,7 +425,7 @@ bool FP_LIB_TABLE::IsFootprintLibWritable( const wxString& aNickname )
void FP_LIB_TABLE::FootprintLibDelete( const wxString& aNickname ) void FP_LIB_TABLE::FootprintLibDelete( const wxString& aNickname )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() ); row->plugin->FootprintLibDelete( row->GetFullURI( true ), row->GetProperties() );
} }
@ -426,7 +433,7 @@ void FP_LIB_TABLE::FootprintLibDelete( const wxString& aNickname )
void FP_LIB_TABLE::FootprintLibCreate( const wxString& aNickname ) void FP_LIB_TABLE::FootprintLibCreate( const wxString& aNickname )
{ {
const FP_LIB_TABLE_ROW* row = FindRow( aNickname ); const FP_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxASSERT( (PLUGIN*) row->plugin ); wxASSERT( (PLUGIN*) row->plugin );
row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() ); row->plugin->FootprintLibCreate( row->GetFullURI( true ), row->GetProperties() );
} }

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012-2017 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -146,7 +146,7 @@ bool LIB_TABLE::IsEmpty( bool aIncludeFallback )
const wxString LIB_TABLE::GetDescription( const wxString& aNickname ) const wxString LIB_TABLE::GetDescription( const wxString& aNickname )
{ {
// use "no exception" form of find row: // Use "no exception" form of find row and ignore disabled flag.
const LIB_TABLE_ROW* row = findRow( aNickname ); const LIB_TABLE_ROW* row = findRow( aNickname );
if( row ) if( row )
@ -158,21 +158,18 @@ const wxString LIB_TABLE::GetDescription( const wxString& aNickname )
bool LIB_TABLE::HasLibrary( const wxString& aNickname, bool aCheckEnabled ) const bool LIB_TABLE::HasLibrary( const wxString& aNickname, bool aCheckEnabled ) const
{ {
const LIB_TABLE_ROW* row = findRow( aNickname ); const LIB_TABLE_ROW* row = findRow( aNickname, aCheckEnabled );
if( row == nullptr ) if( row == nullptr )
return false; return false;
if( aCheckEnabled && !row->GetIsEnabled() )
return false;
return true; return true;
} }
wxString LIB_TABLE::GetFullURI( const wxString& aNickname, bool aExpandEnvVars ) const wxString LIB_TABLE::GetFullURI( const wxString& aNickname, bool aExpandEnvVars ) const
{ {
const LIB_TABLE_ROW* row = findRow( aNickname ); const LIB_TABLE_ROW* row = findRow( aNickname, true );
wxString retv; wxString retv;
@ -183,8 +180,9 @@ wxString LIB_TABLE::GetFullURI( const wxString& aNickname, bool aExpandEnvVars )
} }
LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName ) const LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName, bool aCheckIfEnabled ) const
{ {
LIB_TABLE_ROW* row = nullptr;
LIB_TABLE* cur = (LIB_TABLE*) this; LIB_TABLE* cur = (LIB_TABLE*) this;
do do
@ -194,7 +192,12 @@ LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName ) const
for( const std::pair<const wxString, int>& entry : cur->nickIndex ) for( const std::pair<const wxString, int>& entry : cur->nickIndex )
{ {
if( entry.first == aNickName ) if( entry.first == aNickName )
return &cur->rows[entry.second ]; {
row = &cur->rows[entry.second];
if( !aCheckIfEnabled || ( aCheckIfEnabled && row->GetIsEnabled() ) )
return row;
}
} }
// Repeat, this time looking for names that were "fixed" by legacy versions because // Repeat, this time looking for names that were "fixed" by legacy versions because
@ -205,7 +208,12 @@ LIB_TABLE_ROW* LIB_TABLE::findRow( const wxString& aNickName ) const
legacyLibName.Replace( " ", "_" ); legacyLibName.Replace( " ", "_" );
if( legacyLibName == aNickName ) if( legacyLibName == aNickName )
return &cur->rows[entry.second ]; {
row = &cur->rows[entry.second];
if( !aCheckIfEnabled || ( aCheckIfEnabled && row->GetIsEnabled() ) )
return row;
}
} }
// not found, search fall back table(s), if any // not found, search fall back table(s), if any

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -697,7 +697,7 @@ int ERC_TESTER::TestLibSymbolIssues()
wxCHECK2( libSymbolInSchematic, continue ); wxCHECK2( libSymbolInSchematic, continue );
wxString libName = symbol->GetLibId().GetLibNickname(); wxString libName = symbol->GetLibId().GetLibNickname();
LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName ); LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
if( !libTableRow ) if( !libTableRow )
{ {

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 CERN * Copyright (C) 2017 CERN
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -118,7 +118,7 @@ SYMBOL_LIB_TABLE_ROW* SYMBOL_LIBRARY_MANAGER::GetLibrary( const wxString& aLibra
try try
{ {
row = symTable()->FindRow( aLibrary ); row = symTable()->FindRow( aLibrary, true );
} }
catch( const IO_ERROR& e ) catch( const IO_ERROR& e )
{ {

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016-2019 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2016 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -262,7 +262,7 @@ int SYMBOL_LIB_TABLE::GetModifyHash()
for( const auto& libName : libNames ) for( const auto& libName : libNames )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( libName, true );
if( !row || !row->plugin ) if( !row || !row->plugin )
{ {
@ -282,7 +282,7 @@ int SYMBOL_LIB_TABLE::GetModifyHash()
void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames, void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
bool aPowerSymbolsOnly ) bool aPowerSymbolsOnly )
{ {
SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, /* void */ ); wxCHECK( row && row->plugin, /* void */ );
wxString options = row->GetOptions(); wxString options = row->GetOptions();
@ -299,10 +299,10 @@ void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayStr
} }
SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname ) SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname, bool aCheckIfEnabled )
{ {
SYMBOL_LIB_TABLE_ROW* row = dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname ) ); SYMBOL_LIB_TABLE_ROW* row =
dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname, aCheckIfEnabled ) );
if( !row ) if( !row )
return nullptr; return nullptr;
@ -320,7 +320,7 @@ SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname )
void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_PART*>& aSymbolList, void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_PART*>& aSymbolList,
const wxString& aNickname, bool aPowerSymbolsOnly ) const wxString& aNickname, bool aPowerSymbolsOnly )
{ {
SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, /* void */ ); wxCHECK( row && row->plugin, /* void */ );
wxString options = row->GetOptions(); wxString options = row->GetOptions();
@ -351,7 +351,7 @@ void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_PART*>& aSymbolList,
LIB_PART* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aSymbolName ) LIB_PART* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aSymbolName )
{ {
SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
if( !row || !row->plugin ) if( !row || !row->plugin )
return nullptr; return nullptr;
@ -381,7 +381,7 @@ LIB_PART* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxStrin
SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol( const wxString& aNickname, SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol( const wxString& aNickname,
const LIB_PART* aSymbol, bool aOverwrite ) const LIB_PART* aSymbol, bool aOverwrite )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, SAVE_SKIPPED ); wxCHECK( row && row->plugin, SAVE_SKIPPED );
if( !aOverwrite ) if( !aOverwrite )
@ -407,7 +407,7 @@ SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol( const wxString& aNickname
void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName ) void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, /* void */ ); wxCHECK( row && row->plugin, /* void */ );
return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName, return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName,
row->GetProperties() ); row->GetProperties() );
@ -416,14 +416,14 @@ void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString&
bool SYMBOL_LIB_TABLE::IsSymbolLibWritable( const wxString& aNickname ) bool SYMBOL_LIB_TABLE::IsSymbolLibWritable( const wxString& aNickname )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, false ); wxCHECK( row && row->plugin, false );
return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) ); return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
} }
bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded( const wxString& aNickname ) bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded( const wxString& aNickname )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row, false ); wxCHECK( row, false );
return row->GetIsLoaded(); return row->GetIsLoaded();
} }
@ -431,7 +431,7 @@ bool SYMBOL_LIB_TABLE::IsSymbolLibLoaded( const wxString& aNickname )
void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname ) void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, /* void */ ); wxCHECK( row && row->plugin, /* void */ );
row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() ); row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
} }
@ -439,7 +439,7 @@ void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname )
void SYMBOL_LIB_TABLE::CreateSymbolLib( const wxString& aNickname ) void SYMBOL_LIB_TABLE::CreateSymbolLib( const wxString& aNickname )
{ {
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname ); const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, /* void */ ); wxCHECK( row && row->plugin, /* void */ );
row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() ); row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2016 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2016-2020 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2016-2021 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -142,12 +142,10 @@ public:
* not already loaded. * not already loaded.
* *
* @param aNickName is the name of the row to find. * @param aNickName is the name of the row to find.
* * @param aCheckIfEnabled is a flag to verify if the table entry is enabled or disabled.
* @return the row found or NULL if \a aNickName was not found. * @return the row found or NULL if \a aNickName was not found.
*
* @throw IO_ERROR if \a aNickName cannot be found.
*/ */
SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName ); SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName, bool aCheckIfEnabled = false );
int GetModifyHash(); int GetModifyHash();

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 CERN * Copyright (C) 2017 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -92,7 +92,9 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( bool aForce,
// libraries before the symbol library table which prevents the library from being // libraries before the symbol library table which prevents the library from being
// removed from the tree control. // removed from the tree control.
if( !m_libMgr->LibraryExists( name, true ) if( !m_libMgr->LibraryExists( name, true )
|| !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true ) ) || !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true )
|| ( m_frame->Prj().SchSymbolLibTable()->FindRow( name, true ) !=
m_frame->Prj().SchSymbolLibTable()->FindRow( name, false ) ) )
{ {
it = deleteLibrary( it ); it = deleteLibrary( it );
continue; continue;

View File

@ -891,7 +891,7 @@ void SYMBOL_VIEWER_FRAME::DisplayLibInfos()
{ {
if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() ) if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
{ {
const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName ); const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName, true );
wxString title = wxString::Format( wxT( "%s \u2014 " ) + _( "Symbol Library Browser" ), wxString title = wxString::Format( wxT( "%s \u2014 " ) + _( "Symbol Library Browser" ),
row ? row->GetFullURI() : _( "no library selected" ) ); row ? row->GetFullURI() : _( "no library selected" ) );

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012-2020 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2012-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -118,14 +118,20 @@ public:
/** /**
* Return an #FP_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained * Return an #FP_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained
* fallBack table fragment. * fall back table fragment.
*
* If \a aCheckIfEnabled is true, the library will be ignored even if it is disabled.
* Otherwise, the row found will be returned even if entry is disabled.
* *
* The #PLUGIN is loaded and attached to the "plugin" field of the #FP_LIB_TABLE_ROW if * The #PLUGIN is loaded and attached to the "plugin" field of the #FP_LIB_TABLE_ROW if
* not already loaded. * not already loaded.
* *
* @param aNickName is the name of library nickname to find.
* @param aCheckIfEnabled is the flag to check if the library found is enabled.
* @return the library \a NickName if found.
* @throw IO_ERROR if \a aNickName cannot be found. * @throw IO_ERROR if \a aNickName cannot be found.
*/ */
const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName ); const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName, bool aCheckIfEnabled = false );
/** /**
* Return a list of footprint names contained within the library given by @a aNickname. * Return a list of footprint names contained within the library given by @a aNickname.

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2012-2017 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2012-2021 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -492,8 +492,12 @@ protected:
/** /**
* Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained * Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained
* fallBack table fragment, else NULL. * fallBack table fragment, else NULL.
*
* @param aNickname is the name of the library table entry to find.
* @param aCheckIfEnabled is a flag to check if the library table entry is enabled.
* @return a pointer to the #LIB_TABLE_ROW found.
*/ */
LIB_TABLE_ROW* findRow( const wxString& aNickname ) const; LIB_TABLE_ROW* findRow( const wxString& aNickname, bool aCheckIfEnabled = false ) const;
void reindex() void reindex()
{ {

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -45,7 +45,7 @@ void FP_TREE_MODEL_ADAPTER::AddLibraries()
{ {
for( const wxString& libName : m_libs->GetLogicalLibs() ) for( const wxString& libName : m_libs->GetLogicalLibs() )
{ {
const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName ); const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true ); DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 CERN * Copyright (C) 2017 CERN
* Copyright (C)-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -68,11 +68,14 @@ bool FP_TREE_SYNCHRONIZING_ADAPTER::IsContainer( const wxDataViewItem& aItem ) c
void FP_TREE_SYNCHRONIZING_ADAPTER::Sync() void FP_TREE_SYNCHRONIZING_ADAPTER::Sync()
{ {
// Process already stored libraries // Process already stored libraries
for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); ) for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); )
{ {
const wxString& name = it->get()->m_Name; const wxString& name = it->get()->m_Name;
if( !m_libs->HasLibrary( name, true ) ) // Remove the library if it no longer exists or it exists in both the global and the
// project library but the project library entry is disabled.
if( !m_libs->HasLibrary( name, true )
|| ( m_libs->FindRow( name, true ) != m_libs->FindRow( name, false ) ) )
{ {
it = deleteLibrary( it ); it = deleteLibrary( it );
continue; continue;
@ -89,7 +92,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::Sync()
{ {
if( m_libMap.count( libName ) == 0 ) if( m_libMap.count( libName ) == 0 )
{ {
const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName ); const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true ); DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
m_libMap.insert( libName ); m_libMap.insert( libName );