Allow hiding symbol library tables from symbol chooser

Hidden but loaded libraries are useful when using database libraries
This commit is contained in:
Jon Evans 2022-08-26 20:18:16 -04:00
parent 161775fdbc
commit 300d92438c
10 changed files with 47 additions and 4 deletions

View File

@ -6,4 +6,5 @@ type
uri uri
options options
descr descr
disabled disabled
hidden

View File

@ -89,6 +89,9 @@ void LIB_TABLE_ROW::Format( OUTPUTFORMATTER* out, int nestLevel ) const
if( !GetIsEnabled() ) if( !GetIsEnabled() )
extraOptions += "(disabled)"; extraOptions += "(disabled)";
if( !GetIsVisible() )
extraOptions += "(hidden)";
out->Print( nestLevel, "(lib (name %s)(type %s)(uri %s)(options %s)(descr %s)%s)\n", out->Print( nestLevel, "(lib (name %s)(type %s)(uri %s)(options %s)(descr %s)%s)\n",
out->Quotew( GetNickName() ).c_str(), out->Quotew( GetNickName() ).c_str(),
out->Quotew( GetType() ).c_str(), out->Quotew( GetType() ).c_str(),
@ -105,7 +108,8 @@ bool LIB_TABLE_ROW::operator==( const LIB_TABLE_ROW& r ) const
&& uri_user == r.uri_user && uri_user == r.uri_user
&& options == r.options && options == r.options
&& description == r.description && description == r.description
&& enabled == r.enabled; && enabled == r.enabled
&& visible == r.visible;
} }

View File

@ -1,6 +1,6 @@
/* /*
* 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.
* *lib_tree_model
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com> * Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org> * Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
* Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.

View File

@ -257,6 +257,11 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_ENABLED, attr ); aGrid->SetColAttr( COL_ENABLED, attr );
attr = new wxGridCellAttr;
attr->SetRenderer( new wxGridCellBoolRenderer() );
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_VISIBLE, attr );
// all but COL_OPTIONS, which is edited with Option Editor anyways. // all but COL_OPTIONS, which is edited with Option Editor anyways.
aGrid->AutoSizeColumn( COL_NICKNAME, false ); aGrid->AutoSizeColumn( COL_NICKNAME, false );
aGrid->AutoSizeColumn( COL_TYPE, false ); aGrid->AutoSizeColumn( COL_TYPE, false );

View File

@ -129,7 +129,8 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SYMBOL_LIBRARY_FILTER
bool pinned = alg::contains( cfg->m_Session.pinned_symbol_libs, nickname ) bool pinned = alg::contains( cfg->m_Session.pinned_symbol_libs, nickname )
|| alg::contains( project.m_PinnedSymbolLibs, nickname ); || alg::contains( project.m_PinnedSymbolLibs, nickname );
modelAdapter->AddLibrary( nickname, pinned ); if( libs->FindRow( nickname )->GetIsVisible() )
modelAdapter->AddLibrary( nickname, pinned );
} }
} }

View File

@ -150,6 +150,7 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
bool sawDesc = false; bool sawDesc = false;
bool sawUri = false; bool sawUri = false;
bool sawDisabled = false; bool sawDisabled = false;
bool sawHidden = false;
while( ( tok = in->NextTok() ) != T_RIGHT ) while( ( tok = in->NextTok() ) != T_RIGHT )
{ {
@ -202,6 +203,13 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in )
row->SetEnabled( false ); row->SetEnabled( false );
break; break;
case T_hidden:
if( sawHidden )
in->Duplicate( tok );
sawHidden = true;
row->SetVisible( false );
break;
default: default:
in->Unexpected( tok ); in->Unexpected( tok );
} }

View File

@ -120,6 +120,9 @@ bool SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNick
for( const std::pair<const wxString, std::vector<LIB_SYMBOL*>>& pair : loadedSymbols ) for( const std::pair<const wxString, std::vector<LIB_SYMBOL*>>& pair : loadedSymbols )
{ {
if( !m_libs->FindRow( pair.first )->GetIsVisible() )
continue;
std::vector<LIB_TREE_ITEM*> treeItems( pair.second.begin(), pair.second.end() ); std::vector<LIB_TREE_ITEM*> treeItems( pair.second.begin(), pair.second.end() );
bool pinned = alg::contains( cfg->m_Session.pinned_symbol_libs, pair.first ) bool pinned = alg::contains( cfg->m_Session.pinned_symbol_libs, pair.first )
|| alg::contains( project.m_PinnedSymbolLibs, pair.first ); || alg::contains( project.m_PinnedSymbolLibs, pair.first );

View File

@ -69,6 +69,7 @@ class LIB_TABLE_ROW : boost::noncopyable
public: public:
LIB_TABLE_ROW() : LIB_TABLE_ROW() :
enabled( true ), enabled( true ),
visible( true ),
m_loaded( false ), m_loaded( false ),
m_parent( nullptr ) m_parent( nullptr )
{ {
@ -83,6 +84,7 @@ public:
nickName( aNick ), nickName( aNick ),
description( aDescr ), description( aDescr ),
enabled( true ), enabled( true ),
visible( true ),
m_loaded( false ), m_loaded( false ),
m_parent( aParent ) m_parent( aParent )
{ {
@ -125,6 +127,10 @@ public:
*/ */
void SetEnabled( bool aEnabled = true ) { enabled = aEnabled; } void SetEnabled( bool aEnabled = true ) { enabled = aEnabled; }
bool GetIsVisible() const { return visible; }
void SetVisible( bool aVisible = true ) { visible = aVisible; }
/** /**
* Return the type of library represented by this row. * Return the type of library represented by this row.
*/ */
@ -205,6 +211,7 @@ protected:
options( aRow.options ), options( aRow.options ),
description( aRow.description ), description( aRow.description ),
enabled( aRow.enabled ), enabled( aRow.enabled ),
visible( aRow.visible ),
m_loaded( aRow.m_loaded ), m_loaded( aRow.m_loaded ),
m_parent( aRow.m_parent ) m_parent( aRow.m_parent )
{ {
@ -232,6 +239,7 @@ private:
wxString description; wxString description;
bool enabled = true; ///< Whether the LIB_TABLE_ROW is enabled bool enabled = true; ///< Whether the LIB_TABLE_ROW is enabled
bool visible = true; ///< Whether the LIB_TABLE_ROW is visible in choosers
bool m_loaded = false; ///< Whether the LIB_TABLE_ROW is loaded bool m_loaded = false; ///< Whether the LIB_TABLE_ROW is loaded
LIB_TABLE* m_parent; ///< Pointer to the table this row lives in (maybe null) LIB_TABLE* m_parent; ///< Pointer to the table this row lives in (maybe null)

View File

@ -31,6 +31,7 @@ const wxColour COLOUR_ROW_DISABLED( 100, 100, 100 );
enum COL_ORDER enum COL_ORDER
{ {
COL_ENABLED, COL_ENABLED,
COL_VISIBLE,
COL_NICKNAME, COL_NICKNAME,
COL_URI, COL_URI,
COL_TYPE, COL_TYPE,
@ -68,6 +69,7 @@ public:
case COL_OPTIONS: return r->GetOptions(); case COL_OPTIONS: return r->GetOptions();
case COL_DESCR: return r->GetDescr(); case COL_DESCR: return r->GetDescr();
case COL_ENABLED: return r->GetIsEnabled() ? wxT( "1" ) : wxT( "0" ); case COL_ENABLED: return r->GetIsEnabled() ? wxT( "1" ) : wxT( "0" );
case COL_VISIBLE: return r->GetIsVisible() ? wxT( "1" ) : wxT( "0" );
default: return wxEmptyString; default: return wxEmptyString;
} }
} }
@ -79,6 +81,8 @@ public:
{ {
if( aRow < (int) size() && aCol == COL_ENABLED ) if( aRow < (int) size() && aCol == COL_ENABLED )
return at( (size_t) aRow )->GetIsEnabled(); return at( (size_t) aRow )->GetIsEnabled();
else if( aRow < (int) size() && aCol == COL_VISIBLE )
return at( (size_t) aRow )->GetIsVisible();
else else
return false; return false;
} }
@ -97,6 +101,7 @@ public:
case COL_OPTIONS: r->SetOptions( aValue ); break; case COL_OPTIONS: r->SetOptions( aValue ); break;
case COL_DESCR: r->SetDescr( aValue ); break; case COL_DESCR: r->SetDescr( aValue ); break;
case COL_ENABLED: r->SetEnabled( aValue == wxT( "1" ) ); break; case COL_ENABLED: r->SetEnabled( aValue == wxT( "1" ) ); break;
case COL_VISIBLE: r->SetVisible( aValue == wxT( "1" ) ); break;
} }
} }
} }
@ -105,6 +110,8 @@ public:
{ {
if( aRow < (int) size() && aCol == COL_ENABLED ) if( aRow < (int) size() && aCol == COL_ENABLED )
at( (size_t) aRow )->SetEnabled( aValue ); at( (size_t) aRow )->SetEnabled( aValue );
else if( aRow < (int) size() && aCol == COL_VISIBLE )
at( (size_t) aRow )->SetVisible( aValue );
} }
bool IsEmptyCell( int aRow, int aCol ) override bool IsEmptyCell( int aRow, int aCol ) override
@ -184,6 +191,7 @@ public:
case COL_OPTIONS: return _( "Options" ); case COL_OPTIONS: return _( "Options" );
case COL_DESCR: return _( "Description" ); case COL_DESCR: return _( "Description" );
case COL_ENABLED: return _( "Active" ); case COL_ENABLED: return _( "Active" );
case COL_VISIBLE: return _( "Visible" );
default: return wxEmptyString; default: return wxEmptyString;
} }

View File

@ -419,6 +419,11 @@ PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent,
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
aGrid->SetColAttr( COL_ENABLED, attr ); aGrid->SetColAttr( COL_ENABLED, attr );
// No visibility control for footprint libraries yet; this feature is primarily
// useful for database libraries and it's only implemented for schematic symbols
// at the moment.
aGrid->HideCol( COL_VISIBLE );
// all but COL_OPTIONS, which is edited with Option Editor anyways. // all but COL_OPTIONS, which is edited with Option Editor anyways.
aGrid->AutoSizeColumn( COL_NICKNAME, false ); aGrid->AutoSizeColumn( COL_NICKNAME, false );
aGrid->AutoSizeColumn( COL_TYPE, false ); aGrid->AutoSizeColumn( COL_TYPE, false );