diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index ac46252bdb..b8e94ba5a7 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -444,13 +444,12 @@ public: FP_LIB_TABLE* aTable ); /** - * Function LoadModuleFromLibrary + * Function SelectFootprintFromLibTree * opens a dialog to select a footprint. * - * @param aLibrary = the library name to use, or empty string to search all libraries * @param aUseFootprintViewer = true to allow selection by the footprint viewer */ - MODULE* SelectFootprintFromLibTree( const wxString& aLibrary, bool aUseFootprintViewer = true ); + MODULE* SelectFootprintFromLibTree( bool aUseFootprintViewer = true ); /** * Adds the given module to the board. diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index bf44250ab0..826b773651 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -87,16 +87,10 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME ) EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout ) // Toolbar events - EVT_TOOL( ID_MODVIEW_SELECT_LIB, - FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary ) - EVT_TOOL( ID_MODVIEW_SELECT_PART, - FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint ) - EVT_TOOL( ID_MODVIEW_NEXT, - FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList ) - EVT_TOOL( ID_MODVIEW_PREVIOUS, - FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList ) - EVT_TOOL( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, - FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint ) + EVT_TOOL( ID_MODVIEW_SELECT_PART, FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint ) + EVT_TOOL( ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList ) + EVT_TOOL( ID_MODVIEW_PREVIOUS, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList ) + EVT_TOOL( ID_MODVIEW_EXPORT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint ) EVT_TOOL( ID_MODVIEW_SHOW_3D_VIEW, FOOTPRINT_VIEWER_FRAME::Show3D_Frame ) // listbox events @@ -762,65 +756,29 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle() } -void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event ) -{ - wxString selection = SelectLibrary( getCurNickname() ); - - if( !!selection && selection != getCurNickname() ) - { - setCurNickname( selection ); - - UpdateTitle(); - ReCreateFootprintList(); - - int id = m_libList->FindString( getCurNickname() ); - - if( id >= 0 ) - m_libList->SetSelection( id ); - } -} - - void FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint( wxCommandEvent& event ) { - wxString curr_nickname = getCurNickname(); - MODULE* oldmodule = GetBoard()->m_Modules; - MODULE* module = SelectFootprintFromLibTree( curr_nickname, false ); + MODULE* module = SelectFootprintFromLibTree( false ); if( module ) { - // Only one footprint allowed: remove the previous footprint (if exists) - if( oldmodule ) + const LIB_ID& fpid = module->GetFPID(); + + setCurNickname( fpid.GetLibNickname() ); + setCurFootprintName( fpid.GetLibItemName() ); + + int index = m_libList->FindString( fpid.GetLibNickname() ); + + if( index != wxNOT_FOUND ) { - GetBoard()->Remove( oldmodule ); - delete oldmodule; + m_libList->SetSelection( index, true ); + m_libList->EnsureVisible( index ); } - SetCrossHairPosition( wxPoint( 0, 0 ) ); - AddModuleToBoard( module ); + ReCreateFootprintList(); - setCurFootprintName( module->GetFPID().GetLibItemName() ); - - wxString nickname = module->GetFPID().GetLibNickname(); - - if( !getCurNickname() && nickname.size() ) - { - // Set the listbox - int index = m_libList->FindString( nickname ); - if( index != wxNOT_FOUND ) - m_libList->SetSelection( index, true ); - - setCurNickname( nickname ); - } - - module->ClearFlags(); - SetCurItem( NULL ); - - Zoom_Automatique( false ); - m_canvas->Refresh(); - Update3D_Frame(); - m_footprintList->SetStringSelection( getCurFootprintName() ); - } + SelectAndViewFootprint( NEW_PART ); + } } @@ -846,14 +804,16 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) if( selection != wxNOT_FOUND ) { m_footprintList->SetSelection( selection ); - setCurFootprintName( m_footprintList->GetString( selection ) ); + m_footprintList->EnsureVisible( selection ); + + setCurFootprintName( m_footprintList->GetString( (unsigned) selection ) ); SetCurItem( NULL ); // Delete the current footprint GetBoard()->m_Modules.DeleteAll(); - MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( - getCurNickname(), getCurFootprintName() ); + MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( getCurNickname(), + getCurFootprintName() ); if( footprint ) GetBoard()->Add( footprint, ADD_APPEND ); diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index 1480be2d93..20cdda12fa 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -147,8 +147,6 @@ private: */ virtual void OnActivate( wxActivateEvent& event ) override; - void SelectCurrentLibrary( wxCommandEvent& event ); - /** * Function SelectCurrentFootprint * Selects the current footprint name and display it diff --git a/pcbnew/generate_footprint_info.cpp b/pcbnew/generate_footprint_info.cpp index fe6038b90c..90a4e1b582 100644 --- a/pcbnew/generate_footprint_info.cpp +++ b/pcbnew/generate_footprint_info.cpp @@ -100,7 +100,7 @@ public: desc = desc.substr( 0, (unsigned) idx ); desc = desc.Trim( true ); - if( desc.Last() == ',' ) + if( !desc.IsEmpty() && desc.Last() == ',' ) desc.RemoveLast( 1 ); } diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index d7f27b2afc..6d2ce0485e 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -183,7 +183,7 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser() } -MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( const wxString& aLibrary, bool aAllowBrowser ) +MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( bool aAllowBrowser ) { FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs(); wxString moduleName; @@ -193,7 +193,7 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( const wxString& aLibrary, bo static wxString lastComponentName; WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 ); - GFootprintList.ReadFootprintFiles( fpTable, aLibrary.length() ? &aLibrary : NULL, &progressReporter ); + GFootprintList.ReadFootprintFiles( fpTable, nullptr, &progressReporter ); progressReporter.Show( false ); if( GFootprintList.GetErrorCount() ) @@ -202,16 +202,15 @@ MODULE* PCB_BASE_FRAME::SelectFootprintFromLibTree( const wxString& aLibrary, bo auto adapterPtr( FP_TREE_MODEL_ADAPTER::Create( fpTable ) ); auto adapter = static_cast( adapterPtr.get() ); - if( !s_ModuleHistoryList.empty() ) - { - std::vector history_list; + std::vector historyInfos; - for( auto const& item : s_ModuleHistoryList ) - history_list.push_back( GFootprintList.GetModuleInfo( item ) ); + for( auto const& item : s_ModuleHistoryList ) + historyInfos.push_back( GFootprintList.GetModuleInfo( item ) ); - adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, history_list ); - adapter->SetPreselectNode( history_list[0]->GetLibId(), 0 ); - } + adapter->DoAddLibrary( "-- " + _( "Recently Used" ) + " --", wxEmptyString, historyInfos ); + + if( !historyInfos.empty() ) + adapter->SetPreselectNode( historyInfos[0]->GetLibId(), 0 ); adapter->AddLibraries(); diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index f5178e84eb..6f5da5db53 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -368,7 +368,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) ) { m_canvas->MoveCursorToCrossHair(); - MODULE* module = SelectFootprintFromLibTree( wxEmptyString, Prj().PcbFootprintLibs()); + MODULE* module = SelectFootprintFromLibTree(); SetCurItem( (BOARD_ITEM*) module ); diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index d13558dfba..b07638337a 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -384,16 +384,14 @@ enum pcbnew_ids ID_MODEDIT_EXPORT_PART, ID_POPUP_MODEDIT_EDIT_BODY_ITEM, - ID_MODVIEW_LIBWINDOW, - ID_MODVIEW_FOOTPRINT_WINDOW, ID_MODVIEW_LIB_LIST, ID_MODVIEW_FOOTPRINT_LIST, - ID_MODVIEW_SELECT_LIB, ID_MODVIEW_SELECT_PART, ID_MODVIEW_PREVIOUS, ID_MODVIEW_NEXT, ID_MODVIEW_SHOW_3D_VIEW, - ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, + ID_MODVIEW_EXPORT_TO_BOARD, + ID_FOOTPRINT_WIZARD_WINDOW, ID_FOOTPRINT_WIZARD_PAGES, ID_FOOTPRINT_WIZARD_PARAMETERS, diff --git a/pcbnew/tool_footprint_viewer.cpp b/pcbnew/tool_footprint_viewer.cpp index 7832c7c60f..d7caa96196 100644 --- a/pcbnew/tool_footprint_viewer.cpp +++ b/pcbnew/tool_footprint_viewer.cpp @@ -45,14 +45,9 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar() m_mainToolBar->Clear(); else m_mainToolBar = new wxAuiToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, - KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT - | wxAUI_TB_OVERFLOW ); + KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT ); // Set up toolbar - m_mainToolBar->AddTool( ID_MODVIEW_SELECT_LIB, wxEmptyString, - KiScaledBitmap( open_library_xpm, this ), - _( "Select library to browse" ) ); - m_mainToolBar->AddTool( ID_MODVIEW_SELECT_PART, wxEmptyString, KiScaledBitmap( load_module_lib_xpm, this ), _( "Select footprint to browse" ) ); @@ -75,30 +70,26 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar() KiScaledSeparator( m_mainToolBar, this ); - msg = AddHotkeyName( _( "Zoom in" ), g_Module_Viewer_Hotkeys_Descr, - HK_ZOOM_IN, IS_COMMENT ); + msg = AddHotkeyName( _( "Zoom in" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_IN, IS_COMMENT ); m_mainToolBar->AddTool( ID_VIEWER_ZOOM_IN, wxEmptyString, KiScaledBitmap( zoom_in_xpm, this ), msg ); - msg = AddHotkeyName( _( "Zoom out" ), g_Module_Viewer_Hotkeys_Descr, - HK_ZOOM_OUT, IS_COMMENT ); + msg = AddHotkeyName( _( "Zoom out" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_OUT, IS_COMMENT ); m_mainToolBar->AddTool( ID_VIEWER_ZOOM_OUT, wxEmptyString, KiScaledBitmap( zoom_out_xpm, this ), msg ); - msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, - HK_ZOOM_REDRAW ); + msg = AddHotkeyName( _( "Redraw view" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_REDRAW ); m_mainToolBar->AddTool( ID_VIEWER_ZOOM_REDRAW, wxEmptyString, KiScaledBitmap( zoom_redraw_xpm, this ), msg ); - msg = AddHotkeyName( _( "Zoom to fit footprint" ), g_Module_Viewer_Hotkeys_Descr, - HK_ZOOM_AUTO ); + msg = AddHotkeyName( _( "Zoom to fit" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO ); m_mainToolBar->AddTool( ID_VIEWER_ZOOM_PAGE, wxEmptyString, KiScaledBitmap( zoom_fit_in_page_xpm, this ), msg ); if( IsModal() ) { KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->AddTool( ID_MODVIEW_FOOTPRINT_EXPORT_TO_BOARD, wxEmptyString, + m_mainToolBar->AddTool( ID_MODVIEW_EXPORT_TO_BOARD, wxEmptyString, KiScaledBitmap( export_footprint_names_xpm, this ), _( "Insert footprint in board" ) ); } @@ -116,7 +107,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateVToolbar() // Virtual function -void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar( void ) +void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar() { // wxWidgets handles the Mac Application menu behind the scenes, but that means // we always have to start from scratch with a new wxMenuBar. @@ -129,11 +120,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar( void ) // Menu File: wxMenu* fileMenu = new wxMenu; - // Active library selection - AddMenuItem( fileMenu, ID_MODVIEW_SELECT_LIB, _("Set Active Library..."), - _( "Select library to be displayed" ), KiBitmap( open_library_xpm ) ); - fileMenu->AppendSeparator(); - // Close viewer AddMenuItem( fileMenu, wxID_EXIT, _( "Cl&ose" ), @@ -151,8 +137,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar( void ) HK_ZOOM_OUT, IS_ACCELERATOR ); AddMenuItem( viewMenu, ID_VIEWER_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) ); - text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, - HK_ZOOM_AUTO ); + text = AddHotkeyName( _( "&Fit on Screen" ), g_Module_Viewer_Hotkeys_Descr, HK_ZOOM_AUTO ); AddMenuItem( viewMenu, ID_VIEWER_ZOOM_PAGE, text, _( "Zoom to fit footprint" ), KiBitmap( zoom_fit_in_page_xpm ) ); diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index be2a875533..e3485629d0 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -467,7 +467,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) if( !module ) { // Pick the module to be placed - module = m_frame->SelectFootprintFromLibTree( wxEmptyString ); + module = m_frame->SelectFootprintFromLibTree(); if( module == NULL ) continue;