Add pinned library support to CvPCB.
This commit is contained in:
parent
190fb23e88
commit
a9e18c68a7
|
@ -30,8 +30,10 @@
|
|||
#include <kiface_base.h>
|
||||
#include <kiplatform/app.h>
|
||||
#include <kiway_express.h>
|
||||
#include <project/project_file.h>
|
||||
#include <macros.h>
|
||||
#include <netlist_reader/netlist_reader.h>
|
||||
#include <lib_tree_model_adapter.h>
|
||||
#include <numeric>
|
||||
#include <tool/action_manager.h>
|
||||
#include <tool/action_toolbar.h>
|
||||
|
@ -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<wxString> pinnedMatches;
|
||||
std::set<wxString> 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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <listboxes.h>
|
||||
#include <cvpcb_id.h>
|
||||
#include <wx/log.h>
|
||||
#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 );
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue