void FOOTPRINT_EDIT_FRAME::initLibraryTree() { FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 ); GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter ); progressReporter.Show( false ); if( GFootprintList.GetErrorCount() ) GFootprintList.DisplayErrors( this ); m_adapter = FP_TREE_SYNCHRONIZING_ADAPTER::Create( this, fpTable ); auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() ); adapter->AddLibraries(); }
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibTree( const SCHLIB_FILTER* aFilter, std::vector<COMPONENT_SELECTION>& aHistoryList, bool aAllowBrowser, int aUnit, int aConvert, bool aShowFootprints, const LIB_ID* aHighlight, bool aAllowFields ) { std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock ); wxString dialogTitle; SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable(); // One CHOOSE_COMPONENT dialog at a time. User probaby can't handle more anyway. if( !dialogLock.try_lock() ) return COMPONENT_SELECTION(); auto adapterPtr( SYMBOL_TREE_MODEL_ADAPTER::Create( libs ) ); auto adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( adapterPtr.get() ); bool loaded = false; if( aFilter ) { const wxArrayString& liblist = aFilter->GetAllowedLibList(); for( unsigned ii = 0; ii < liblist.GetCount(); ii++ ) { if( libs->HasLibrary( liblist[ii], true ) ) { loaded = true; adapter->AddLibrary( liblist[ii] ); } } adapter->AssignIntrinsicRanks(); if( aFilter->GetFilterPowerParts() ) adapter->SetFilter( SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER ); } std::vector< LIB_TREE_ITEM* > history_list; for( auto const& i : aHistoryList ) { LIB_ALIAS* alias = GetLibAlias( i.LibId ); if( alias ) history_list.push_back( alias ); } adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list, true ); if( !aHistoryList.empty() ) adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit ); const std::vector< wxString > libNicknames = libs->GetLogicalLibs(); if( !loaded ) adapter->AddLibraries( libNicknames, this ); if( aHighlight && aHighlight->IsValid() ) adapter->SetPreselectNode( *aHighlight, /* aUnit */ 0 ); if( adapter->GetFilter() == SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER ) dialogTitle.Printf( _( "Choose Power Symbol (%d items loaded)" ), adapter->GetItemCount() ); else dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, aConvert, aAllowFields, aShowFootprints, aAllowBrowser ); if( dlg.ShowQuasiModal() == wxID_CANCEL ) return COMPONENT_SELECTION(); COMPONENT_SELECTION sel; LIB_ID id = dlg.GetSelectedLibId( &sel.Unit ); if( dlg.IsExternalBrowserSelected() ) // User requested component browser. { sel = SelectComponentFromLibBrowser( this, aFilter, id, sel.Unit, sel.Convert ); id = sel.LibId; } if( !id.IsValid() ) // Dialog closed by OK button, // or the selection by lib browser was requested, // but no symbol selected return COMPONENT_SELECTION(); if( sel.Unit == 0 ) sel.Unit = 1; sel.Fields = dlg.GetFields(); sel.LibId = id; if( sel.LibId.IsValid() ) { aHistoryList.erase( std::remove_if( aHistoryList.begin(), aHistoryList.end(), [ &sel ]( COMPONENT_SELECTION const& i ){ return i.LibId == sel.LibId; } ), aHistoryList.end() ); aHistoryList.insert( aHistoryList.begin(), sel ); } return sel; }