From a9e18c68a7b125f31302a67fe730ce182fc2b075 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 9 Jul 2022 18:15:36 -0600 Subject: [PATCH] Add pinned library support to CvPCB. --- cvpcb/cvpcb_mainframe.cpp | 37 ++++++++++++++++++++++++++----------- cvpcb/library_listbox.cpp | 30 +++++++++++++----------------- cvpcb/listboxes.h | 2 +- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index c90bd99ad5..f25d8ba746 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -30,8 +30,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -93,7 +95,9 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : // Create list of available footprints and symbols of the schematic BuildSymbolsListBox(); BuildFootprintsListBox(); - BuildLibrariesListBox(); + + m_librariesListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST ); + m_librariesListBox->SetFont( KIUI::GetMonospacedUIFont() ); m_auimgr.SetManagedWindow( this ); @@ -957,15 +961,20 @@ void CVPCB_MAINFRAME::BuildSymbolsListBox() void CVPCB_MAINFRAME::BuildLibrariesListBox() { - wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); + PROJECT_FILE& project = Kiway().Prj().GetProjectFile(); + FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); + std::set pinnedMatches; + std::set otherMatches; - if( m_librariesListBox == nullptr ) - { - m_librariesListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST ); - m_librariesListBox->SetFont( KIUI::GetMonospacedUIFont() ); - } + auto process = + [&]( const wxString& aNickname ) + { + if( alg::contains( project.m_PinnedFootprintLibs, aNickname ) ) + pinnedMatches.insert( aNickname ); + else + otherMatches.insert( aNickname ); + }; - FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); if( tbl ) { @@ -974,10 +983,16 @@ void CVPCB_MAINFRAME::BuildLibrariesListBox() std::vector< wxString > libNickNames = tbl->GetLogicalLibs(); for( const wxString& libNickName : libNickNames ) - libNames.Add( libNickName ); - - m_librariesListBox->SetLibraryList( libNames ); + process( libNickName ); } + + for( const wxString& nickname : pinnedMatches ) + m_librariesListBox->AppendLine( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname ); + + for( const wxString& nickname : otherMatches ) + m_librariesListBox->AppendLine( nickname ); + + m_librariesListBox->Finish(); } diff --git a/cvpcb/library_listbox.cpp b/cvpcb/library_listbox.cpp index bae26a0281..db54089d30 100644 --- a/cvpcb/library_listbox.cpp +++ b/cvpcb/library_listbox.cpp @@ -32,6 +32,7 @@ #include #include #include +#include "lib_tree_model_adapter.h" /***************************************/ @@ -62,6 +63,7 @@ void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text ) { if( linecount >= count ) linecount = count - 1; + m_libraryList[linecount] = text; UpdateWidth( linecount ); } @@ -70,24 +72,27 @@ void LIBRARY_LISTBOX::SetString( unsigned linecount, const wxString& text ) wxString LIBRARY_LISTBOX::GetSelectedLibrary() { - wxString libraryName; + wxString libName; int ii = GetFirstSelected(); if( ii >= 0 ) { - libraryName = m_libraryList[ii]; + libName = m_libraryList[ii]; + libName.Trim( false ); + + if( libName.StartsWith( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() ) ) + libName = libName.substr( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol().length() ); } - return libraryName; + return libName; } void LIBRARY_LISTBOX::AppendLine( const wxString& text ) { - m_libraryList.Add( text ); + m_libraryList.Add( wxT( " " ) + text ); int lines = m_libraryList.Count(); SetItemCount( lines ); - UpdateWidth( lines - 1 ); } @@ -115,17 +120,8 @@ void LIBRARY_LISTBOX::SetSelection( int index, bool State ) } -void LIBRARY_LISTBOX::SetLibraryList( const wxArrayString& aList ) +void LIBRARY_LISTBOX::Finish() { - int oldSelection = GetSelection(); - - m_libraryList = aList; - - SetItemCount( m_libraryList.GetCount() ); - - if( GetCount() == 0 || oldSelection < 0 || oldSelection >= GetCount() ) - SetSelection( 0, true ); - if( m_libraryList.Count() ) { RefreshItems( 0L, m_libraryList.Count()-1 ); @@ -201,8 +197,8 @@ void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event ) void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event ) { // Apply the filter - GetParent()->SetFootprintFilter( - FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY, CVPCB_MAINFRAME::FILTER_ENABLE ); + GetParent()->SetFootprintFilter( FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY, + CVPCB_MAINFRAME::FILTER_ENABLE ); SetFocus(); GetParent()->OnSelectComponent( event ); diff --git a/cvpcb/listboxes.h b/cvpcb/listboxes.h index f5679f4984..ca2f13dae7 100644 --- a/cvpcb/listboxes.h +++ b/cvpcb/listboxes.h @@ -149,7 +149,7 @@ public: void SetSelection( int index, bool State = true ); void SetString( unsigned linecount, const wxString& text ); void AppendLine( const wxString& text ); - void SetLibraryList( const wxArrayString& aList ); + void Finish(); wxString GetSelectedLibrary(); wxString OnGetItemText( long item, long column ) const override;