diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 664d344a0f..533a992a4f 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -90,15 +90,6 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( ID_FPEDIT_SAVE_PNG, FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng ) - EVT_TOOL( ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnLoadFootprintFromBoard ) - EVT_TOOL( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_EDIT_FRAME::OnSaveFootprintToBoard ) - - // UI update events. - EVT_UPDATE_UI( ID_LOAD_FOOTPRINT_FROM_BOARD, - FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard ) - EVT_UPDATE_UI( ID_ADD_FOOTPRINT_TO_BOARD, - FOOTPRINT_EDIT_FRAME::OnUpdateSaveFootprintToBoard ) - // Drop files event EVT_DROP_FILES( FOOTPRINT_EDIT_FRAME::OnDropFiles ) @@ -918,42 +909,6 @@ void FOOTPRINT_EDIT_FRAME::CloseFootprintEditor( wxCommandEvent& Event ) } -void FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard( wxUpdateUIEvent& aEvent ) -{ - PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false ); - - aEvent.Enable( frame != nullptr ); -} - - -void FOOTPRINT_EDIT_FRAME::OnUpdateSaveFootprintToBoard( wxUpdateUIEvent& aEvent ) -{ - PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false ); - - FOOTPRINT* editorFootprint = GetBoard()->GetFirstFootprint(); - bool canInsert = frame && editorFootprint && editorFootprint->GetLink() == niluuid; - - // If the source was deleted, the footprint can inserted but not updated in the board. - if( frame && editorFootprint && editorFootprint->GetLink() != niluuid ) - { - BOARD* mainpcb = frame->GetBoard(); - canInsert = true; - - // search if the source footprint was not deleted: - for( FOOTPRINT* candidate : mainpcb->Footprints() ) - { - if( editorFootprint->GetLink() == candidate->m_Uuid ) - { - canInsert = false; - break; - } - } - } - - aEvent.Enable( canInsert ); -} - - void FOOTPRINT_EDIT_FRAME::ShowChangedLanguage() { // call my base class @@ -1244,12 +1199,51 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions() return IsCurrentFPFromBoard(); }; + auto pcbFrameExistsCond = + [this]( const SELECTION& ) + { + PCB_EDIT_FRAME* frame = dynamic_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB_EDITOR, false ) ); + + return ( frame != nullptr ); + }; + + auto boardFootprintExistsCond = + [this]( const SELECTION& ) + { + PCB_EDIT_FRAME* frame = dynamic_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB_EDITOR, false ) ); + + FOOTPRINT* editorFootprint = GetBoard()->GetFirstFootprint(); + bool canInsert = frame && editorFootprint && editorFootprint->GetLink() == niluuid; + + // If the source was deleted, the footprint can inserted but not updated in the board. + if( frame && editorFootprint && editorFootprint->GetLink() != niluuid ) + { + BOARD* mainpcb = frame->GetBoard(); + canInsert = true; + + // search if the source footprint was not deleted: + for( FOOTPRINT* candidate : mainpcb->Footprints() ) + { + if( editorFootprint->GetLink() == candidate->m_Uuid ) + { + canInsert = false; + break; + } + } + } + + return canInsert; + }; + // clang-format off mgr->SetConditions( ACTIONS::saveAs, ENABLE( footprintTargettedCond ) ); mgr->SetConditions( ACTIONS::revert, ENABLE( cond.ContentModified() ) ); mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) ); mgr->SetConditions( PCB_ACTIONS::editLibFpInFpEditor,ENABLE( footprintFromBoardCond ) ); + mgr->SetConditions( PCB_ACTIONS::saveFpToBoard, ENABLE( boardFootprintExistsCond ) ); + mgr->SetConditions( PCB_ACTIONS::loadFpFromBoard, ENABLE( pcbFrameExistsCond ) ); + mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) ); mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) ); diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 4f704e6c34..042eeea614 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -149,19 +149,9 @@ public: */ bool SaveLibraryAs( const wxString& aLibraryPath ); - void OnUpdateLoadFootprintFromBoard( wxUpdateUIEvent& aEvent ); - void OnUpdateSaveFootprintToBoard( wxUpdateUIEvent& aEvent ); - ///< @copydoc PCB_BASE_EDIT_FRAME::OnEditItemRequest() void OnEditItemRequest( BOARD_ITEM* aItem ) override; - /** - * Called from the main toolbar to load a footprint from board mainly to edit it. - */ - void OnLoadFootprintFromBoard( wxCommandEvent& event ); - - void OnSaveFootprintToBoard( wxCommandEvent& event ); - void LoadFootprintFromLibrary( LIB_ID aFPID ); /** diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 2e490a38d1..aa025bf016 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -52,12 +52,6 @@ using namespace std::placeholders; -void FOOTPRINT_EDIT_FRAME::OnLoadFootprintFromBoard( wxCommandEvent& event ) -{ - LoadFootprintFromBoard( nullptr ); -} - - void FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary( LIB_ID aFPID ) { bool is_last_fp_from_brd = IsCurrentFPFromBoard(); @@ -115,12 +109,6 @@ void FOOTPRINT_EDIT_FRAME::centerItemIdleHandler( wxIdleEvent& aEvent ) } -void FOOTPRINT_EDIT_FRAME::OnSaveFootprintToBoard( wxCommandEvent& event ) -{ - SaveFootprintToBoard( true ); -} - - class BASIC_FOOTPRINT_INFO : public FOOTPRINT_INFO { public: diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index d287110e7c..02da9d1ff2 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -74,13 +74,6 @@ using namespace std::placeholders; - -#define NEW_PART 0 -#define NEXT_PART 1 -#define PREVIOUS_PART 2 -#define RELOAD_PART 3 - - BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, PCB_BASE_FRAME ) // Window events EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize ) @@ -90,14 +83,9 @@ BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, PCB_BASE_FRAME ) EVT_MENU( wxID_CLOSE, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer ) // Toolbar events - EVT_TOOL( ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList ) - EVT_TOOL( ID_MODVIEW_PREVIOUS, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList ) - EVT_TOOL( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB ) EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectZoom ) EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectGrid ) - EVT_UPDATE_UI( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton ) - EVT_TEXT( ID_MODVIEW_LIB_FILTER, FOOTPRINT_VIEWER_FRAME::OnLibFilter ) EVT_TEXT( ID_MODVIEW_FOOTPRINT_FILTER, FOOTPRINT_VIEWER_FRAME::OnFPFilter ) @@ -347,6 +335,12 @@ void FOOTPRINT_VIEWER_FRAME::setupUIConditions() wxASSERT( mgr ); + auto addToBoardCond = + [this]( const SELECTION& ) + { + return ( GetBoard()->GetFirstFootprint() != nullptr ); + }; + #define ENABLE( x ) ACTION_CONDITIONS().Enable( x ) #define CHECK( x ) ACTION_CONDITIONS().Check( x ) @@ -356,6 +350,7 @@ void FOOTPRINT_VIEWER_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) ); mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) ); + mgr->SetConditions( PCB_ACTIONS::saveFpToBoard, ENABLE( addToBoardCond ) ); mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); @@ -611,8 +606,7 @@ void FOOTPRINT_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent ) else if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER ) && m_fpList->GetSelection() >= 0 ) { - wxCommandEvent dummy; - AddFootprintToPCB( dummy ); + AddFootprintToPCB(); } else { @@ -696,7 +690,7 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent ) if( getCurFootprintName().CmpNoCase( name ) != 0 ) { setCurFootprintName( name ); - SelectAndViewFootprint( NEW_PART ); + SelectAndViewFootprint( FPVIEWER_CONSTANTS::NEW_PART ); } } @@ -722,12 +716,11 @@ void FOOTPRINT_VIEWER_FRAME::displayFootprint( FOOTPRINT* aFootprint ) void FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList( wxMouseEvent& aEvent ) { - wxCommandEvent evt; - AddFootprintToPCB( evt ); + AddFootprintToPCB(); } -void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent ) +void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB() { if( GetBoard()->GetFirstFootprint() ) { @@ -934,17 +927,11 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) } -void FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton( wxUpdateUIEvent& aEvent ) -{ - aEvent.Enable( GetBoard()->GetFirstFootprint() != nullptr ); -} - - void FOOTPRINT_VIEWER_FRAME::ReloadFootprint( FOOTPRINT* aFootprint ) { setCurNickname( aFootprint->GetFPID().GetLibNickname() ); setCurFootprintName( aFootprint->GetFPID().GetLibItemName() ); - SelectAndViewFootprint( RELOAD_PART ); + SelectAndViewFootprint( FPVIEWER_CONSTANTS::RELOAD_PART ); } @@ -982,25 +969,6 @@ COLOR4D FOOTPRINT_VIEWER_FRAME::GetGridColor() } -void FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList( wxCommandEvent& event ) -{ - switch( event.GetId() ) - { - case ID_MODVIEW_NEXT: - SelectAndViewFootprint( NEXT_PART ); - break; - - case ID_MODVIEW_PREVIOUS: - SelectAndViewFootprint( PREVIOUS_PART ); - break; - - default: - wxString id = wxString::Format( wxT( "%i" ), event.GetId() ); - wxFAIL_MSG( wxT( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " ) + id ); - } -} - - void FOOTPRINT_VIEWER_FRAME::UpdateTitle() { wxString title; @@ -1030,20 +998,20 @@ void FOOTPRINT_VIEWER_FRAME::UpdateTitle() } -void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) +void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( FPVIEWER_CONSTANTS aMode ) { if( !getCurNickname() ) return; int selection = m_fpList->FindString( getCurFootprintName(), true ); - if( aMode == NEXT_PART ) + if( aMode == FPVIEWER_CONSTANTS::NEXT_PART ) { if( selection != wxNOT_FOUND && selection < (int)m_fpList->GetCount() - 1 ) selection++; } - if( aMode == PREVIOUS_PART ) + if( aMode == FPVIEWER_CONSTANTS::PREVIOUS_PART ) { if( selection != wxNOT_FOUND && selection > 0 ) selection--; @@ -1069,7 +1037,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) if( footprint ) displayFootprint( footprint ); - if( aMode != RELOAD_PART ) + if( aMode != FPVIEWER_CONSTANTS::RELOAD_PART ) setFPWatcher( footprint ); Update3DView( true, true ); diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index ed50dc4ab4..05a8d5caf2 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -40,6 +40,14 @@ class SELECTION; namespace PCB { struct IFACE; } +enum class FPVIEWER_CONSTANTS +{ + NEW_PART = 0, + NEXT_PART = 1, + PREVIOUS_PART = 2, + RELOAD_PART = 3 +}; + /** * Component library viewer main window. */ @@ -67,17 +75,27 @@ public: */ void ReCreateLibraryList(); - /** - * Update the ID_ADD_FOOTPRINT_TO_BOARD tool state in main toolbar. - */ - void OnUpdateFootprintButton( wxUpdateUIEvent& aEvent ); - /** * Override from PCB_BASE_FRAME which reloads the footprint from the library without * setting the footprint watcher */ void ReloadFootprint( FOOTPRINT* aFootprint ) override; + /** + * Export the current footprint name and close the library browser. + */ + void AddFootprintToPCB(); + + /** + * Select and load the next or the previous footprint. + * + * If no current footprint, rebuild the list of footprints available in a given footprint + * library. + * + * @param aMode #NEXT_PART or #PREVIOUS_PART. + */ + void SelectAndViewFootprint( FPVIEWER_CONSTANTS aMode ); + ///< @copydoc EDADRAW_FRAME::UpdateMsgPanel void UpdateMsgPanel() override; @@ -110,7 +128,6 @@ private: void OnSize( wxSizeEvent& event ) override; void ReCreateFootprintList(); - void OnIterateFootprintList( wxCommandEvent& event ); /** * Update the window title with current library information. @@ -146,21 +163,6 @@ private: */ void OnActivate( wxActivateEvent& event ); - /** - * Export the current footprint name and close the library browser. - */ - void AddFootprintToPCB( wxCommandEvent& aEvent ); - - /** - * Select and load the next or the previous footprint. - * - * If no current footprint, rebuild the list of footprints available in a given footprint - * library. - * - * @param aMode #NEXT_PART or #PREVIOUS_PART. - */ - void SelectAndViewFootprint( int aMode ); - /// @copydoc PCB_BASE_FRAME::Update3DView void Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle = nullptr ) override; diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index 48b8522a31..75cb7b1699 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -212,15 +212,8 @@ void FOOTPRINT_EDIT_FRAME::doReCreateMenuBar() // ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool ); - toolsMenu->Add( _( "&Load Footprint from PCB..." ), - _( "Load a footprint from the current board into the editor" ), - ID_LOAD_FOOTPRINT_FROM_BOARD, - BITMAPS::load_module_board ); - - toolsMenu->Add( _( "&Insert Footprint on PCB" ), - _( "Insert footprint onto current board" ), - ID_ADD_FOOTPRINT_TO_BOARD, - BITMAPS::insert_module_board ); + toolsMenu->Add( PCB_ACTIONS::loadFpFromBoard ); + toolsMenu->Add( PCB_ACTIONS::saveFpToBoard ); toolsMenu->AppendSeparator(); toolsMenu->Add( PCB_ACTIONS::cleanupGraphics ); diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 5e740239c5..1b384a2569 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -109,9 +109,6 @@ enum pcbnew_ids ID_FOOTPRINT_WIZARD_SELECT_WIZARD, ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, - ID_ADD_FOOTPRINT_TO_BOARD, - ID_LOAD_FOOTPRINT_FROM_BOARD, - ID_PCBNEW_END_LIST }; diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 34734a3b7d..9bc25d32c8 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -170,17 +170,9 @@ std::optional<TOOLBAR_CONFIGURATION> FOOTPRINT_EDIT_FRAME::DefaultTopMainToolbar .AppendAction( ACTIONS::showDatasheet ) .AppendAction( PCB_ACTIONS::checkFootprint ); - config.AppendSeparator(); - - /* TODO (ISM): Implement these as actions - m_tbTopMain->AddTool( ID_LOAD_FOOTPRINT_FROM_BOARD, wxEmptyString, - KiScaledBitmap( BITMAPS::import_brd_file, this ), - _( "Load footprint from current board" ) ); - - m_tbTopMain->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString, - KiScaledBitmap( BITMAPS::insert_module_board, this ), - _( "Insert footprint into current board" ) ); -*/ + config.AppendSeparator() + .AppendAction( PCB_ACTIONS::loadFpFromBoard ) + .AppendAction( PCB_ACTIONS::saveFpToBoard ); config.AppendSeparator() .AppendControl( m_tbGridSelectName ); diff --git a/pcbnew/toolbars_footprint_viewer.cpp b/pcbnew/toolbars_footprint_viewer.cpp index 980c4f8160..bd6802a688 100644 --- a/pcbnew/toolbars_footprint_viewer.cpp +++ b/pcbnew/toolbars_footprint_viewer.cpp @@ -40,14 +40,8 @@ std::optional<TOOLBAR_CONFIGURATION> FOOTPRINT_VIEWER_FRAME::DefaultTopMainToolb TOOLBAR_CONFIGURATION config; // clang-format off - /* TODO (ISM): Convert to actions - m_tbTopMain->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString, - KiScaledBitmap( BITMAPS::lib_previous, this ), - _( "Display previous footprint" ) ); - m_tbTopMain->AddTool( ID_MODVIEW_NEXT, wxEmptyString, - KiScaledBitmap( BITMAPS::lib_next, this ), - _( "Display next footprint" ) ); -*/ + config.AppendAction( PCB_ACTIONS::previousFootprint ) + .AppendAction( PCB_ACTIONS::nextFootprint ); config.AppendSeparator() .AppendAction( ACTIONS::zoomRedraw ) @@ -57,13 +51,8 @@ std::optional<TOOLBAR_CONFIGURATION> FOOTPRINT_VIEWER_FRAME::DefaultTopMainToolb .AppendAction( ACTIONS::zoomTool ); config.AppendSeparator() - .AppendAction( ACTIONS::show3DViewer ); - - /* TODO (ISM): Convert to action - m_tbTopMain->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString, - KiScaledBitmap( BITMAPS::insert_module_board, this ), - _( "Insert footprint in board" ) ); -*/ + .AppendAction( ACTIONS::show3DViewer ) + .AppendAction( PCB_ACTIONS::saveFpToBoard ); config.AppendSeparator() .AppendControl( m_tbGridSelectName ); diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 9c95ab6ae0..e5e4cc052e 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -29,6 +29,7 @@ #include <pcbnew_id.h> #include <bitmaps.h> #include <layer_ids.h> +#include <footprint_viewer_frame.h> #include <microwave/microwave_tool.h> #include <pcb_reference_image.h> #include <tool/tool_manager.h> @@ -798,6 +799,34 @@ TOOL_ACTION PCB_ACTIONS::checkFootprint( TOOL_ACTION_ARGS() .Tooltip( _( "Show the footprint checker window" ) ) .Icon( BITMAPS::erc ) ); +TOOL_ACTION PCB_ACTIONS::loadFpFromBoard( TOOL_ACTION_ARGS() + .Name( "pcbnew.ModuleEditor.loadFootprintFromBoard" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Load footprint from current PCB" ) ) + .Tooltip( _( "Load footprint from current board" ) ) + .Icon( BITMAPS::load_module_board ) ); + +TOOL_ACTION PCB_ACTIONS::saveFpToBoard( TOOL_ACTION_ARGS() + .Name( "pcbnew.ModuleEditor.saveFootprintToBoard" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Insert footprint into PCB" ) ) + .Tooltip( _( "Insert footprint into current board" ) ) + .Icon( BITMAPS::insert_module_board) ); + +TOOL_ACTION PCB_ACTIONS::previousFootprint( TOOL_ACTION_ARGS() + .Name( "pcbnew.Control.previousFootprint" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Display previous footprint" ) ) + .Icon( BITMAPS::lib_previous ) + .Parameter<FPVIEWER_CONSTANTS>( FPVIEWER_CONSTANTS::PREVIOUS_PART ) ); + +TOOL_ACTION PCB_ACTIONS::nextFootprint( TOOL_ACTION_ARGS() + .Name( "pcbnew.Control.nextFootprint" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Display next footprint" ) ) + .Icon( BITMAPS::lib_next ) + .Parameter<FPVIEWER_CONSTANTS>( FPVIEWER_CONSTANTS::NEXT_PART ) ); + // GLOBAL_EDIT_TOOL // TOOL_ACTION PCB_ACTIONS::updateFootprint( TOOL_ACTION_ARGS() diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index c177edaa51..356c732108 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -483,6 +483,12 @@ public: static TOOL_ACTION checkFootprint; + static TOOL_ACTION loadFpFromBoard; + static TOOL_ACTION saveFpToBoard; + + static TOOL_ACTION previousFootprint; + static TOOL_ACTION nextFootprint; + /// Activation of the drawing tool (placing a PAD) static TOOL_ACTION placePad; diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index de650ccc86..822848dc95 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -67,6 +67,7 @@ #include <tool/tool_manager.h> #include <footprint_edit_frame.h> #include <footprint_editor_settings.h> +#include <footprint_viewer_frame.h> #include <widgets/appearance_controls.h> #include <widgets/wx_progress_reporters.h> #include <widgets/wx_infobar.h> @@ -122,6 +123,26 @@ int PCB_CONTROL::AddLibrary( const TOOL_EVENT& aEvent ) } +int PCB_CONTROL::LoadFpFromBoard( const TOOL_EVENT& aEvent ) +{ + if( m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) ) + static_cast<FOOTPRINT_EDIT_FRAME*>( m_frame )->LoadFootprintFromBoard( nullptr ); + + return 0; +} + + +int PCB_CONTROL::SaveFpToBoard( const TOOL_EVENT& aEvent ) +{ + if( m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) ) + static_cast<FOOTPRINT_EDIT_FRAME*>( m_frame )->SaveFootprintToBoard( true ); + else if( m_frame->IsType( FRAME_FOOTPRINT_VIEWER ) ) + static_cast<FOOTPRINT_VIEWER_FRAME*>( m_frame )->AddFootprintToPCB(); + + return 0; +} + + int PCB_CONTROL::DdAddLibrary( const TOOL_EVENT& aEvent ) { const wxString fn = *aEvent.Parameter<wxString*>(); @@ -139,6 +160,15 @@ int PCB_CONTROL::DdImportFootprint( const TOOL_EVENT& aEvent ) } +int PCB_CONTROL::IterateFootprint( const TOOL_EVENT& aEvent ) +{ + if( m_frame->IsType( FRAME_FOOTPRINT_VIEWER ) ) + static_cast<FOOTPRINT_VIEWER_FRAME*>( m_frame )->SelectAndViewFootprint( aEvent.Parameter<FPVIEWER_CONSTANTS>() ); + + return 0; +} + + int PCB_CONTROL::Quit( const TOOL_EVENT& aEvent ) { m_frame->Close( false ); @@ -1981,6 +2011,12 @@ void PCB_CONTROL::setTransitions() Go( &PCB_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &PCB_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); + // Footprint library actions + Go( &PCB_CONTROL::SaveFpToBoard, PCB_ACTIONS::saveFpToBoard.MakeEvent() ); + Go( &PCB_CONTROL::LoadFpFromBoard, PCB_ACTIONS::loadFpFromBoard.MakeEvent() ); + Go( &PCB_CONTROL::IterateFootprint, PCB_ACTIONS::nextFootprint.MakeEvent() ); + Go( &PCB_CONTROL::IterateFootprint, PCB_ACTIONS::previousFootprint.MakeEvent() ); + // Display modes Go( &PCB_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() ); Go( &PCB_CONTROL::ToggleRatsnest, PCB_ACTIONS::showRatsnest.MakeEvent() ); diff --git a/pcbnew/tools/pcb_control.h b/pcbnew/tools/pcb_control.h index bc4163a63d..300a48533a 100644 --- a/pcbnew/tools/pcb_control.h +++ b/pcbnew/tools/pcb_control.h @@ -56,6 +56,11 @@ public: int Print( const TOOL_EVENT& aEvent ); int Quit( const TOOL_EVENT& aEvent ); + // Footprint library control actions + int LoadFpFromBoard( const TOOL_EVENT& aEvent ); + int SaveFpToBoard( const TOOL_EVENT& aEvent ); + int IterateFootprint( const TOOL_EVENT& aEvent ); + // Display modes int ToggleRatsnest( const TOOL_EVENT& aEvent ); int ZoneDisplayMode( const TOOL_EVENT& aEvent );