From e606587ff6a360f425753d9fca5d03b7995f0331 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 6 Jun 2019 12:45:28 +0100 Subject: [PATCH] Move remaining Symbol Tree ctx menu cmds to ACTIONS. Also moves the various Player instantiators down into COMMON_TOOLS for better sharing. --- common/tool/actions.cpp | 10 ++ common/tool/common_tools.cpp | 36 +++++ common/widgets/lib_tree.cpp | 1 + eeschema/eeschema_id.h | 1 - eeschema/libedit/lib_edit_frame.cpp | 1 - eeschema/menubar.cpp | 2 +- eeschema/sch_base_frame.cpp | 13 -- eeschema/sch_base_frame.h | 7 - eeschema/sch_edit_frame.cpp | 38 ------ eeschema/sch_edit_frame.h | 3 - eeschema/toolbars_sch_editor.cpp | 9 +- eeschema/tools/ee_actions.h | 1 - eeschema/tools/lib_control.cpp | 10 -- eeschema/tools/lib_control.h | 1 - eeschema/tools/sch_editor_control.cpp | 43 ++---- eeschema/tools/sch_editor_control.h | 2 - include/id.h | 2 - include/tool/actions.h | 2 + include/tool/common_tools.h | 2 + pcbnew/edit.cpp | 26 ---- pcbnew/footprint_edit_frame.cpp | 16 +-- pcbnew/footprint_edit_frame.h | 11 +- pcbnew/footprint_editor_utils.cpp | 74 ----------- pcbnew/footprint_libraries_utils.cpp | 9 +- pcbnew/footprint_tree_pane.cpp | 4 +- pcbnew/menubar_footprint_editor.cpp | 18 +-- pcbnew/pcb_edit_frame.cpp | 2 - pcbnew/pcbnew_id.h | 9 -- pcbnew/toolbars_footprint_editor.cpp | 35 +++-- pcbnew/toolbars_pcb_editor.cpp | 2 +- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/footprint_editor_tools.cpp | 169 +++++++++++++++++++++--- pcbnew/tools/footprint_editor_tools.h | 14 +- pcbnew/tools/pcb_actions.h | 8 ++ pcbnew/tools/pcbnew_control.cpp | 23 ---- pcbnew/tools/pcbnew_control.h | 1 - 36 files changed, 266 insertions(+), 341 deletions(-) diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index db0b4628b6..5fe3ea5dc4 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -363,11 +363,21 @@ TOOL_ACTION ACTIONS::showSymbolBrowser( "common.Control.showSymbolBrowser", _( "Symbol Library Browser" ), _( "Browse symbol libraries" ), library_browse_xpm ); +TOOL_ACTION ACTIONS::showSymbolEditor( "common.Control.showSymbolEditor", + AS_GLOBAL, 0, + _( "Symbol Editor" ), _( "Create, delete and edit symbols" ), + libedit_xpm ); + TOOL_ACTION ACTIONS::showFootprintBrowser( "common.Control.showFootprintBrowser", AS_GLOBAL, 0, _( "Footprint Library Browser" ), _( "Browse footprint libraries" ), modview_icon_xpm ); +TOOL_ACTION ACTIONS::showFootprintEditor( "common.Control.showFootprintEditor", + AS_GLOBAL, 0, + _( "Footprint Editor" ), _( "Create, delete and edit footprints" ), + module_editor_xpm ); + TOOL_ACTION ACTIONS::updatePcbFromSchematic( "common.Control.updatePcbFromSchematic", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_UPDATE_PCB_FROM_SCH ), _( "Update PCB from Schematic..." ), _( "Push changes from schematic to PCB" ), diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index 7af97d94e5..90599ce426 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -532,6 +532,38 @@ int COMMON_TOOLS::SwitchCanvas( const TOOL_EVENT& aEvent ) } +int COMMON_TOOLS::ShowPlayer( const TOOL_EVENT& aEvent ) +{ + FRAME_T playerType = FRAME_SCH_VIEWER; + + if( aEvent.IsAction( &ACTIONS::showSymbolBrowser ) ) + playerType = FRAME_SCH_VIEWER; + else if( aEvent.IsAction( &ACTIONS::showSymbolEditor ) ) + playerType = FRAME_SCH_LIB_EDITOR; + else if( aEvent.IsAction( &ACTIONS::showFootprintBrowser ) ) + playerType = FRAME_PCB_MODULE_VIEWER; + else if( aEvent.IsAction( &ACTIONS::showFootprintEditor ) ) + playerType = FRAME_PCB_MODULE_EDITOR; + else + wxFAIL_MSG( "ShowPlayer(): unexpected request" ); + + KIWAY_PLAYER* editor = m_frame->Kiway().Player( playerType, true ); + + // Needed on Windows, other platforms do not use it, but it creates no issue + if( editor->IsIconized() ) + editor->Iconize( false ); + + editor->Raise(); + + // Raising the window does not set the focus on Linux. This should work on + // any platform. + if( wxWindow::FindFocus() != editor ) + editor->SetFocus(); + + return 0; +} + + void COMMON_TOOLS::setTransitions() { // Cursor control @@ -585,6 +617,10 @@ void COMMON_TOOLS::setTransitions() Go( &COMMON_TOOLS::ShowLibraryTable, ACTIONS::showFootprintLibTable.MakeEvent() ); Go( &COMMON_TOOLS::SwitchCanvas, ACTIONS::acceleratedGraphics.MakeEvent() ); Go( &COMMON_TOOLS::SwitchCanvas, ACTIONS::standardGraphics.MakeEvent() ); + Go( &COMMON_TOOLS::ShowPlayer, ACTIONS::showSymbolBrowser.MakeEvent() ); + Go( &COMMON_TOOLS::ShowPlayer, ACTIONS::showSymbolEditor.MakeEvent() ); + Go( &COMMON_TOOLS::ShowPlayer, ACTIONS::showFootprintBrowser.MakeEvent() ); + Go( &COMMON_TOOLS::ShowPlayer, ACTIONS::showFootprintEditor.MakeEvent() ); } diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index 9ca0c0025e..a1a617521a 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -411,6 +411,7 @@ void LIB_TREE::onContextMenu( wxDataViewEvent& aEvent ) if( tool ) { tool->Activate(); + tool->GetManager()->VetoContextMenuMouseWarp(); tool->GetToolMenu().ShowContextMenu(); TOOL_EVENT evt( TC_MOUSE, TA_MOUSE_CLICK, BUT_RIGHT ); diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 3640ecea74..db1bdbc8c3 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -62,7 +62,6 @@ enum id_eeschema_frm ID_REMAP_SYMBOLS, /* Schematic editor horizontal toolbar IDs */ - ID_TO_LIBVIEW, ID_BACKANNO_ITEMS, /* Schematic editor vertical toolbar IDs */ diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 8039bb9f8b..eea0723c7b 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -83,7 +83,6 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_SIZE( LIB_EDIT_FRAME::OnSize ) // Main horizontal toolbar. - EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer ) EVT_TOOL( ID_LIBEDIT_SYNC_PIN_EDIT, LIB_EDIT_FRAME::OnSyncPinEditClick ) EVT_TOOL( ID_ADD_PART_TO_SCHEMATIC, LIB_EDIT_FRAME::OnAddPartToSchematic ) diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 1495bd27cc..ee61d08507 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -274,7 +274,7 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() toolsMenu->AddItem( EE_ACTIONS::showPcbNew, EE_CONDITIONS::ShowAlways ); toolsMenu->AddSeparator(); - toolsMenu->AddItem( EE_ACTIONS::showSymbolEditor, EE_CONDITIONS::ShowAlways ); + toolsMenu->AddItem( ACTIONS::showSymbolEditor, EE_CONDITIONS::ShowAlways ); toolsMenu->AddItem( ID_RESCUE_CACHED, _( "&Rescue Symbols..." ), _( "Find old symbols in project and rename/rescue them" ), rescue_xpm, EE_CONDITIONS::ShowAlways ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index e013d17893..36926b8bf8 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -104,19 +104,6 @@ SCH_BASE_FRAME::~SCH_BASE_FRAME() } -void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event ) -{ - LIB_VIEW_FRAME* viewlibFrame = (LIB_VIEW_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, true ); - - // On Windows, Raise() does not bring the window on screen, when iconized - if( viewlibFrame->IsIconized() ) - viewlibFrame->Iconize( false ); - - viewlibFrame->Show( true ); - viewlibFrame->Raise(); -} - - SCH_SCREEN* SCH_BASE_FRAME::GetScreen() const { return (SCH_SCREEN*) EDA_DRAW_FRAME::GetScreen(); diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index 8bf245ddfc..ee5292d37c 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -330,13 +330,6 @@ public: */ virtual void OnModify() {} - /** - * Open the library viewer only to browse library contents. - * If the viewed is already opened from this, raise the viewer - * If the viewed is already opened from another window, close it and reopen - */ - void OnOpenLibraryViewer( wxCommandEvent& event ); - protected: /** * Saves Symbol Library Tables to disk. diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 28f542e862..e14d082292 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -232,8 +232,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_RESCUE_CACHED, SCH_EDIT_FRAME::OnRescueProject ) EVT_MENU( ID_REMAP_SYMBOLS, SCH_EDIT_FRAME::OnRemapSymbols ) - EVT_TOOL( ID_RUN_PCB_MODULE_EDITOR, SCH_EDIT_FRAME::OnOpenFootprintEditor ) - EVT_TOOL( ID_GET_NETLIST, SCH_EDIT_FRAME::OnCreateNetlist ) EVT_TOOL( ID_BACKANNO_ITEMS, SCH_EDIT_FRAME::OnLoadCmpToFootprintLinkFile ) EVT_MENU( ID_GRID_SETTINGS, SCH_BASE_FRAME::OnGridSettings ) @@ -867,24 +865,6 @@ void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event ) } -void SCH_EDIT_FRAME::OnOpenFootprintEditor( wxCommandEvent& event ) -{ - wxFileName fn = Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); - - if( fn.IsOk() ) - { - KIWAY_PLAYER* fp_editor = Kiway().Player( FRAME_PCB_MODULE_EDITOR ); - - // On Windows, Raise() does not bring the window on screen, when iconized - if( fp_editor->IsIconized() ) - fp_editor->Iconize( false ); - - fp_editor->Show( true ); - fp_editor->Raise(); - } -} - - void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) { wxFileName fn = Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); @@ -915,24 +895,6 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) } -void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) -{ - LIB_EDIT_FRAME* libeditFrame = (LIB_EDIT_FRAME*) Kiway().Player( FRAME_SCH_LIB_EDITOR, false ); - - if( !libeditFrame ) - { - libeditFrame = (LIB_EDIT_FRAME*) Kiway().Player( FRAME_SCH_LIB_EDITOR, true ); - libeditFrame->Show( true ); - } - - // On Windows, Raise() does not bring the window on screen, when iconized - if( libeditFrame->IsIconized() ) - libeditFrame->Iconize( false ); - - libeditFrame->Raise(); -} - - void SCH_EDIT_FRAME::OnRescueProject( wxCommandEvent& event ) { SCH_SCREENS schematic; diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index f3c0a99c20..259bb7c844 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -621,8 +621,6 @@ public: bool OpenProjectFiles( const std::vector& aFileSet, int aCtl = 0 ) override; - void OnOpenLibraryEditor( wxCommandEvent& event ); - /** * Import a KiCad schematic into the current page. * @@ -749,7 +747,6 @@ public: void GetSchematicConnections( std::vector< wxPoint >& aConnections ); void OnOpenPcbnew( wxCommandEvent& event ); - void OnOpenFootprintEditor( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event ); void OnRescueProject( wxCommandEvent& event ); void OnRemapSymbols( wxCommandEvent& aEvent ); diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index 1291b4015f..d8e771bb2a 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -82,14 +82,9 @@ void SCH_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->Add( EE_ACTIONS::leaveSheet ); m_mainToolBar->AddSeparator(); - m_mainToolBar->Add( EE_ACTIONS::showSymbolEditor ); + m_mainToolBar->Add( ACTIONS::showSymbolEditor ); m_mainToolBar->Add( ACTIONS::showSymbolBrowser ); - - // modedit is with libedit in a "library section" because the user must have footprints before - // they can be assigned. - m_mainToolBar->AddTool( ID_RUN_PCB_MODULE_EDITOR, wxEmptyString, - KiScaledBitmap( module_editor_xpm, this ), - _( "Footprint Editor - Create/edit footprints" ) ); + m_mainToolBar->Add( ACTIONS::showFootprintEditor ); KiScaledSeparator( m_mainToolBar, this ); m_mainToolBar->Add( EE_ACTIONS::annotate ); diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index e4bd3d868e..5d0d46a56d 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -159,7 +159,6 @@ public: static TOOL_ACTION showBusManager; // Suite operations - static TOOL_ACTION showSymbolEditor; static TOOL_ACTION editWithLibEdit; static TOOL_ACTION showPcbNew; static TOOL_ACTION generateBOM; diff --git a/eeschema/tools/lib_control.cpp b/eeschema/tools/lib_control.cpp index ab4fc3880d..9165ef02e3 100644 --- a/eeschema/tools/lib_control.cpp +++ b/eeschema/tools/lib_control.cpp @@ -272,15 +272,6 @@ int LIB_CONTROL::OnDeMorgan( const TOOL_EVENT& aEvent ) } -int LIB_CONTROL::ShowLibraryBrowser( const TOOL_EVENT& aEvent ) -{ - wxCommandEvent dummy; - m_frame->OnOpenLibraryViewer( dummy ); - - return 0; -} - - int LIB_CONTROL::ShowComponentTree( const TOOL_EVENT& aEvent ) { if( m_frame->IsType( FRAME_SCH_LIB_EDITOR ) ) @@ -330,7 +321,6 @@ void LIB_CONTROL::setTransitions() Go( &LIB_CONTROL::OnDeMorgan, EE_ACTIONS::showDeMorganStandard.MakeEvent() ); Go( &LIB_CONTROL::OnDeMorgan, EE_ACTIONS::showDeMorganAlternate.MakeEvent() ); - Go( &LIB_CONTROL::ShowLibraryBrowser, ACTIONS::showSymbolBrowser.MakeEvent() ); Go( &LIB_CONTROL::ShowElectricalTypes, EE_ACTIONS::showElectricalTypes.MakeEvent() ); Go( &LIB_CONTROL::ShowComponentTree, EE_ACTIONS::showComponentTree.MakeEvent() ); } diff --git a/eeschema/tools/lib_control.h b/eeschema/tools/lib_control.h index 5b7f79c80f..63ec658d3c 100644 --- a/eeschema/tools/lib_control.h +++ b/eeschema/tools/lib_control.h @@ -60,7 +60,6 @@ public: int OnDeMorgan( const TOOL_EVENT& aEvent ); - int ShowLibraryBrowser( const TOOL_EVENT& aEvent ); int ShowElectricalTypes( const TOOL_EVENT& aEvent ); int ShowComponentTree( const TOOL_EVENT& aEvent ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 8f98f93858..3b91c01ad5 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -76,11 +76,6 @@ TOOL_ACTION EE_ACTIONS::highlightNetCursor( "eeschema.EditorControl.highlightNet _( "Highlight Nets" ), _( "Highlight wires and pins of a net" ), net_highlight_schematic_xpm, AF_ACTIVATE ); -TOOL_ACTION EE_ACTIONS::showSymbolEditor( "eeschema.EditorControl.showSymbolEditor", - AS_GLOBAL, 0, - _( "Show Symbol Editor" ), _( "Create, delete and edit symbols" ), - libedit_xpm ); - TOOL_ACTION EE_ACTIONS::editWithLibEdit( "eeschema.EditorControl.editWithSymbolEditor", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_EDIT_COMPONENT_WITH_LIBEDIT ), _( "Edit with Symbol Editor" ), _( "Open the symbol editor to edit the symbol" ), @@ -1048,41 +1043,21 @@ int SCH_EDITOR_CONTROL::EditWithLibEdit( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); - SCH_COMPONENT* comp = nullptr; + SCH_COMPONENT* sym = nullptr; + LIB_EDIT_FRAME* libEdit; if( selection.GetSize() >= 1 ) - comp = (SCH_COMPONENT*) selection.Front(); + sym = (SCH_COMPONENT*) selection.Front(); - if( !comp || comp->GetEditFlags() != 0 ) + if( !sym || sym->GetEditFlags() != 0 ) return 0; - wxCommandEvent dummy; - m_frame->OnOpenLibraryEditor( dummy ); + m_toolMgr->RunAction( ACTIONS::showSymbolEditor, true ); + libEdit = (LIB_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_LIB_EDITOR, false ); - auto libeditFrame = (LIB_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_LIB_EDITOR, false ); + if( libEdit ) + libEdit->LoadComponentAndSelectLib( sym->GetLibId(), sym->GetUnit(), sym->GetConvert() ); - if( libeditFrame ) - { - const LIB_ID& id = comp->GetLibId(); - libeditFrame->LoadComponentAndSelectLib( id, comp->GetUnit(), comp->GetConvert() ); - } - - return 0; -} - - -int SCH_EDITOR_CONTROL::ShowSymbolEditor( const TOOL_EVENT& aEvent ) -{ - wxCommandEvent dummy; - m_frame->OnOpenLibraryEditor( dummy ); - return 0; -} - - -int SCH_EDITOR_CONTROL::ShowLibraryBrowser( const TOOL_EVENT& aEvent ) -{ - wxCommandEvent dummy; - m_frame->OnOpenLibraryViewer( dummy ); return 0; } @@ -1249,8 +1224,6 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::EditWithLibEdit, EE_ACTIONS::editWithLibEdit.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::ShowSymbolEditor, EE_ACTIONS::showSymbolEditor.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::ShowLibraryBrowser, ACTIONS::showSymbolBrowser.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ShowCvpcb, EE_ACTIONS::assignFootprints.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Annotate, EE_ACTIONS::annotate.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::EditSymbolFields, EE_ACTIONS::editSymbolFields.MakeEvent() ); diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index c849793b68..dbd75aa7fd 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -102,8 +102,6 @@ public: int Paste( const TOOL_EVENT& aEvent ); int EditWithLibEdit( const TOOL_EVENT& aEvent ); - int ShowSymbolEditor( const TOOL_EVENT& aEvent ); - int ShowLibraryBrowser( const TOOL_EVENT& aEvent ); int ShowCvpcb( const TOOL_EVENT& aEvent ); int Annotate( const TOOL_EVENT& aEvent ); int EditSymbolFields( const TOOL_EVENT& aEvent ); diff --git a/include/id.h b/include/id.h index 86f77431ef..e8fa448f55 100644 --- a/include/id.h +++ b/include/id.h @@ -72,8 +72,6 @@ enum main_id { ID_RUN_PCB = wxID_HIGHEST, - ID_RUN_PCB_MODULE_EDITOR, - ID_RUN_LIBRARY, // pcbnew & eeschema each use this internally to load their respective lib editors ID_LOAD_PROJECT, ID_APPEND_PROJECT, diff --git a/include/tool/actions.h b/include/tool/actions.h index 4fd5945171..da0dfed50d 100644 --- a/include/tool/actions.h +++ b/include/tool/actions.h @@ -142,7 +142,9 @@ public: // Misc static TOOL_ACTION show3DViewer; static TOOL_ACTION showSymbolBrowser; + static TOOL_ACTION showSymbolEditor; static TOOL_ACTION showFootprintBrowser; + static TOOL_ACTION showFootprintEditor; static TOOL_ACTION updatePcbFromSchematic; static TOOL_ACTION configurePaths; static TOOL_ACTION showSymbolLibTable; diff --git a/include/tool/common_tools.h b/include/tool/common_tools.h index 073e5b1b50..4691669df6 100644 --- a/include/tool/common_tools.h +++ b/include/tool/common_tools.h @@ -82,6 +82,8 @@ public: int ConfigurePaths( const TOOL_EVENT& aEvent ); int ShowLibraryTable( const TOOL_EVENT& aEvent ); int SwitchCanvas( const TOOL_EVENT& aEvent ); + + int ShowPlayer( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. void setTransitions() override; diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 09ecdbfc06..5eb9e4dbfe 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -85,32 +85,6 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case 0: break; - case ID_OPEN_MODULE_EDITOR: - { - FOOTPRINT_EDIT_FRAME* editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, false ); - - if( !editor ) - { - editor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_PCB_MODULE_EDITOR, true ); - editor->Zoom_Automatique( false ); - } - else - { - // Needed on Windows, other platforms do not use it, - // but it creates no issue - if( editor->IsIconized() ) - editor->Iconize( false ); - - editor->Raise(); - - // Raising the window does not set the focus on Linux. This should work on - // any platform. - if( wxWindow::FindFocus() != editor ) - editor->SetFocus(); - } - } - break; - case ID_TOOLBARH_PCB_SELECT_LAYER: SetActiveLayer( ToLAYER_ID( m_SelLayerBox->GetLayerSelection() ) ); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index dbdb6b77d7..41ddeb7922 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -82,19 +82,10 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( ID_MODEDIT_SAVE_PNG, FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng ) - EVT_TOOL( ID_MODEDIT_CUT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_COPY_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_PASTE_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_IMPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_SHEET_SET, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_EDIT_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_CHECK, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::LoadModuleFromBoard ) EVT_TOOL( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_MODEDIT_SHOW_HIDE_SEARCH_TREE, FOOTPRINT_EDIT_FRAME::OnToggleSearchTree ) - // Preferences and option menus EVT_MENU( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, FOOTPRINT_EDIT_FRAME::ProcessPreferences ) EVT_MENU( wxID_PREFERENCES, FOOTPRINT_EDIT_FRAME::ProcessPreferences ) @@ -271,7 +262,7 @@ void FOOTPRINT_EDIT_FRAME::HardRedraw() } -void FOOTPRINT_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event ) +void FOOTPRINT_EDIT_FRAME::ToggleSearchTree() { auto& treePane = m_auimgr.GetPane( m_treePane ); treePane.Show( !IsSearchTreeShown() ); @@ -726,10 +717,9 @@ void FOOTPRINT_EDIT_FRAME::SyncLibraryTree( bool aProgress ) } -void FOOTPRINT_EDIT_FRAME::FocusOnLibrary( const wxString& aLibName ) +void FOOTPRINT_EDIT_FRAME::FocusOnLibID( const LIB_ID& aLibID ) { - LIB_ID libID( aLibName, wxEmptyString ); - m_treePane->GetLibTree()->SelectLibId( libID ); + m_treePane->GetLibTree()->SelectLibId( aLibID ); } diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 7422725ae6..e3d6d34945 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -42,7 +42,6 @@ class FOOTPRINT_EDIT_FRAME : public PCB_BASE_EDIT_FRAME FOOTPRINT_TREE_PANE* m_treePane; LIB_TREE_MODEL_ADAPTER::PTR m_adapter; - std::unique_ptr m_copiedModule; std::unique_ptr m_revertModule; wxString m_footprintNameWhenLoaded; @@ -128,11 +127,10 @@ public: // The Tool Framework initalization, for GAL mode void setupTools(); - void OnToggleSearchTree( wxCommandEvent& event ); - void OnSaveFootprintAsPng( wxCommandEvent& event ); bool IsSearchTreeShown(); + void ToggleSearchTree(); /** * Save a library to a new name and/or library type. @@ -174,6 +172,7 @@ public: bool SaveFootprint( MODULE* aModule ); bool SaveFootprintAs( MODULE* aModule ); bool SaveFootprintToBoard( bool aAddNew ); + bool SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName ); bool RevertFootprint(); /** @@ -339,7 +338,7 @@ public: * @param aProgress */ void SyncLibraryTree( bool aProgress ); - void FocusOnLibrary( const wxString& aLibName ); + void FocusOnLibID( const LIB_ID& aLibID ); void KiwayMailIn( KIWAY_EXPRESS& mail ) override; @@ -374,14 +373,10 @@ protected: void restoreLastFootprint(); void retainLastFootprint(); -private: - /** * Run the Footprint Properties dialog and handle changes made in it. */ void editFootprintProperties( MODULE* aFootprint ); - - bool saveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName ); }; #endif // FOOTPRINT_EDIT_FRAME_H diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index 63bdc510a0..f22bfba54f 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -317,84 +317,10 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) m_treePane->GetLibTree()->Refresh(); break; - case ID_MODEDIT_CUT_PART: - case ID_MODEDIT_COPY_PART: - if( GetTargetFPID().IsValid() ) - { - LIB_ID fpID = GetTargetFPID(); - - if( fpID == GetLoadedFPID() ) - m_copiedModule.reset( new MODULE( *GetBoard()->GetFirstModule() ) ); - else - m_copiedModule.reset( LoadFootprint( fpID ) ); - - if( id == ID_MODEDIT_CUT_PART ) - { - if( fpID == GetLoadedFPID() ) - Clear_Pcb( false ); - - DeleteModuleFromLibrary( fpID, false ); - } - - SyncLibraryTree( true ); - } - break; - - case ID_MODEDIT_PASTE_PART: - if( m_copiedModule && !GetTargetFPID().GetLibNickname().empty() ) - { - wxString newLib = GetTargetFPID().GetLibNickname(); - MODULE* newModule( m_copiedModule.get() ); - wxString newName = newModule->GetFPID().GetLibItemName(); - - while( Prj().PcbFootprintLibs()->FootprintExists( newLib, newName ) ) - newName += _( "_copy" ); - - newModule->SetFPID( LIB_ID( newLib, newName ) ); - saveFootprintInLibrary( newModule, newLib ); - - SyncLibraryTree( true ); - m_treePane->GetLibTree()->SelectLibId( newModule->GetFPID() ); - } - break; - case ID_ADD_FOOTPRINT_TO_BOARD: SaveFootprintToBoard( true ); break; - case ID_MODEDIT_IMPORT_PART: - if( ! Clear_Pcb( true ) ) - break; // this command is aborted - - SetCrossHairPosition( wxPoint( 0, 0 ) ); - Import_Module(); - - if( GetBoard()->GetFirstModule() ) - GetBoard()->GetFirstModule()->ClearFlags(); - - GetScreen()->SetModify(); - // Clear undo and redo lists because we don't have handling to in - // FP editor to undo across imports (the module _is_ the board with the stack) - // todo: Abstract undo/redo stack to a higher element or keep consistent board item in fpeditor - GetScreen()->ClearUndoRedoList(); - - Zoom_Automatique( false ); - GetGalCanvas()->Refresh(); - Update3DView( true ); - - break; - - case ID_MODEDIT_EXPORT_PART: - if( GetTargetFPID() == GetLoadedFPID() ) - Export_Module( GetBoard()->GetFirstModule() ); - else - Export_Module( LoadFootprint( GetTargetFPID() ) ); - break; - - case ID_MODEDIT_EDIT_MODULE: - LoadModuleFromLibrary( m_treePane->GetLibTree()->GetSelectedLibId() ); - break; - case ID_MODEDIT_CHECK: // Currently: not implemented break; diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 1c7458d1c7..f95cdfbfdc 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -572,8 +572,9 @@ bool PCB_BASE_EDIT_FRAME::AddLibrary( const wxString& aFilename ) if( editor ) { + LIB_ID libID( libName, wxEmptyString ); editor->SyncLibraryTree( true ); - editor->FocusOnLibrary( libName ); + editor->FocusOnLibID( libID ); } auto viewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_PCB_MODULE_VIEWER, false ); @@ -749,7 +750,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprint( MODULE* aModule ) DeleteModuleFromLibrary( oldFPID, false ); } - if( !saveFootprintInLibrary( aModule, libraryName ) ) + if( !SaveFootprintInLibrary( aModule, libraryName ) ) return false; if( nameChanged ) @@ -762,7 +763,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprint( MODULE* aModule ) } -bool FOOTPRINT_EDIT_FRAME::saveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName ) +bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName ) { try { @@ -978,7 +979,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintAs( MODULE* aModule ) return false; } - if( !saveFootprintInLibrary( aModule, libraryName ) ) + if( !SaveFootprintInLibrary( aModule, libraryName ) ) return false; // Once saved-as a board footprint is no longer a board footprint diff --git a/pcbnew/footprint_tree_pane.cpp b/pcbnew/footprint_tree_pane.cpp index 58fea2b464..a60c47736f 100644 --- a/pcbnew/footprint_tree_pane.cpp +++ b/pcbnew/footprint_tree_pane.cpp @@ -63,9 +63,7 @@ void FOOTPRINT_TREE_PANE::Regenerate() void FOOTPRINT_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent ) { - wxCommandEvent evt( wxEVT_COMMAND_TOOL_CLICKED, ID_MODEDIT_EDIT_MODULE ); - m_frame->Process_Special_Functions( evt ); - + m_frame->LoadModuleFromLibrary( GetLibTree()->GetSelectedLibId() ); // Make sure current-part highlighting doesn't get lost in seleciton highlighting m_tree->Unselect(); } diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index ac5bec6819..22029d6b4b 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -84,11 +84,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() submenuImport->SetTitle( _( "Import" ) ); submenuImport->SetIcon( import_xpm ); - submenuImport->Add( _( "&Footprint..." ), - _( "Import a footprint from file" ), - ID_MODEDIT_IMPORT_PART, import_module_xpm ); - - submenuImport->Add( _( "&Graphics..." ), + submenuImport->Add( PCB_ACTIONS::importFootprint ); + submenuImport->Add( _( "&Impot Graphics..." ), _( "Import 2D Drawing file to Footprint Editor on Drawings layer" ), ID_GEN_IMPORT_GRAPHICS_FILE, import_vector_xpm ); @@ -98,11 +95,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() submenuExport->SetTitle( _( "Export" ) ); submenuExport->SetIcon( export_xpm ); - submenuExport->AddItem( ID_MODEDIT_EXPORT_PART, _( "&Footprint..." ), - _( "Export current footprint to a file" ), - export_module_xpm, modifiedDocumentCondition ); - - submenuExport->AddItem( ID_MODEDIT_SAVE_PNG, _( "View as &PNG..." ), + submenuExport->AddItem( PCB_ACTIONS::exportFootprint, modifiedDocumentCondition ); + submenuExport->AddItem( ID_MODEDIT_SAVE_PNG, _( "Export View as &PNG..." ), _( "Create a PNG file from the current view" ), plot_xpm, SELECTION_CONDITIONS::ShowAlways ); @@ -224,9 +218,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() viewMenu->AddMenu( contrastModeSubMenu ); viewMenu->AddSeparator(); - viewMenu->AddCheckItem( ID_MODEDIT_SHOW_HIDE_SEARCH_TREE, - _( "&Search Tree" ), _( "Toggles the search tree visibility" ), - search_tree_xpm, searchTreeShownCondition ); + viewMenu->AddCheckItem( PCB_ACTIONS::toggleFootprintTree, searchTreeShownCondition ); viewMenu->Resolve(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 12ff473aa2..f73769130c 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -119,7 +119,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_TOOL( ID_MENU_READ_BOARD_BACKUP_FILE, PCB_EDIT_FRAME::Files_io ) EVT_TOOL( ID_MENU_RECOVER_BOARD_AUTOSAVE, PCB_EDIT_FRAME::Files_io ) - EVT_TOOL( ID_OPEN_MODULE_EDITOR, PCB_EDIT_FRAME::Process_Special_Functions ) // Menu Files: EVT_MENU( ID_MAIN_MENUBAR, PCB_EDIT_FRAME::Process_Special_Functions ) @@ -148,7 +147,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) EVT_MENU( ID_PCB_GEN_CMP_FILE, PCB_EDIT_FRAME::RecreateCmpFileFromBoard ) // Horizontal toolbar - EVT_TOOL( ID_RUN_LIBRARY, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_GEN_PLOT_SVG, PCB_EDIT_FRAME::ExportSVG ) EVT_TOOL( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, PCB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event ) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 7437cb6c3d..32eb084833 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -15,7 +15,6 @@ enum pcbnew_ids { ID_MAIN_MENUBAR = ID_END_LIST, ID_MICROWAVE_V_TOOLBAR, - ID_OPEN_MODULE_EDITOR, ID_SET_RELATIVE_OFFSET, ID_COPY_BOARD_AS, ID_IMPORT_NON_KICAD_BOARD, @@ -148,17 +147,9 @@ enum pcbnew_ids ID_MODEDIT_SAVE, ID_MODEDIT_SAVE_AS, ID_MODEDIT_SAVE_PNG, - ID_MODEDIT_COPY_PART, - ID_MODEDIT_CUT_PART, - ID_MODEDIT_PASTE_PART, ID_MODEDIT_NEW_MODULE, ID_MODEDIT_NEW_MODULE_FROM_WIZARD, - ID_MODEDIT_SHEET_SET, - ID_MODEDIT_EDIT_MODULE, ID_MODEDIT_LOAD_MODULE_FROM_BOARD, - ID_MODEDIT_IMPORT_PART, - ID_MODEDIT_EXPORT_PART, - ID_MODEDIT_SHOW_HIDE_SEARCH_TREE, ID_MODVIEW_LIB_LIST, ID_MODVIEW_FOOTPRINT_LIST, diff --git a/pcbnew/toolbars_footprint_editor.cpp b/pcbnew/toolbars_footprint_editor.cpp index 2094d606eb..0a5b38a696 100644 --- a/pcbnew/toolbars_footprint_editor.cpp +++ b/pcbnew/toolbars_footprint_editor.cpp @@ -154,21 +154,19 @@ void FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar() m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize, KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL ); - m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::imperialUnits, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::metricUnits, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::imperialUnits, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::metricUnits, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->AddSeparator(); - m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( PCB_ACTIONS::moduleEdgeOutlines, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::highContrastMode, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( PCB_ACTIONS::moduleEdgeOutlines, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::highContrastMode, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->AddSeparator(); - m_optionsToolBar->AddTool( ID_MODEDIT_SHOW_HIDE_SEARCH_TREE, wxEmptyString, - KiScaledBitmap( search_tree_xpm, this ), - _( "Toggles the search tree" ), wxITEM_CHECK ); + m_optionsToolBar->Add( PCB_ACTIONS::toggleFootprintTree, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->Realize(); } @@ -189,13 +187,14 @@ void FOOTPRINT_EDIT_FRAME::SyncMenusAndToolbars() m_mainToolBar->Toggle( PCB_ACTIONS::footprintProperties, GetBoard()->GetFirstModule() ); m_mainToolBar->Refresh(); - m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); - m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != INCHES ); - m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == INCHES ); - m_optionsToolBar->Toggle( ACTIONS::togglePolarCoords, GetShowPolarCoords() ); - m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts->m_DisplayPadFill ); - m_optionsToolBar->Toggle( PCB_ACTIONS::moduleEdgeOutlines, !opts->m_DisplayModEdgeFill ); - m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts->m_ContrastModeDisplay ); + m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); + m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != INCHES ); + m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == INCHES ); + m_optionsToolBar->Toggle( ACTIONS::togglePolarCoords, GetShowPolarCoords() ); + m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts->m_DisplayPadFill ); + m_optionsToolBar->Toggle( PCB_ACTIONS::moduleEdgeOutlines, !opts->m_DisplayModEdgeFill ); + m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts->m_ContrastModeDisplay ); + m_optionsToolBar->Toggle( PCB_ACTIONS::toggleFootprintTree, IsSearchTreeShown() ); m_optionsToolBar->Refresh(); m_drawToolBar->Toggle( ACTIONS::selectionTool, GetToolId() == ID_NO_TOOL_SELECTED ); diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index e43c5ffee7..2d0cf77a88 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -267,7 +267,7 @@ void PCB_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE ); KiScaledSeparator( m_mainToolBar, this ); - ADD_TOOL( ID_OPEN_MODULE_EDITOR, module_editor_xpm, _( "Open footprint editor" ) ); + m_mainToolBar->Add( ACTIONS::showFootprintEditor ); m_mainToolBar->Add( ACTIONS::showFootprintBrowser ); KiScaledSeparator( m_mainToolBar, this ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 34617c2ef2..a6ab2e581b 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2013-2017 CERN * @author Maciej Suminski * @author Tomasz Wlostowski - * Copyright (C) 2017 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index b0536a373c..af01bd6cea 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014-2019 CERN + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -47,14 +48,19 @@ #include #include #include - +#include #include - +#include #include using namespace std::placeholders; #include +TOOL_ACTION PCB_ACTIONS::toggleFootprintTree( "pcbnew.ModuleEditor.toggleFootprintTree", + AS_GLOBAL, 0, + _( "Show Footprint Tree" ), _( "Toggles the footprint tree visibility" ), + search_tree_xpm ); + TOOL_ACTION PCB_ACTIONS::newFootprint( "pcbnew.ModuleEditor.newFootprint", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_NEW ), _( "New Footprint..." ), _( "Create a new, empty footprint" ), @@ -75,17 +81,47 @@ TOOL_ACTION PCB_ACTIONS::saveToLibrary( "pcbnew.ModuleEditor.saveToLibrary", _( "Save to Library" ), _( "Save changes to library" ), save_xpm ); -// Module editor tools -TOOL_ACTION PCB_ACTIONS::footprintProperties( "pcbnew.ModuleEditor.footprintProperties", +TOOL_ACTION PCB_ACTIONS::editFootprint( "pcbnew.ModuleEditor.editFootprint", AS_GLOBAL, 0, - _( "Footprint Properties..." ), "", - module_options_xpm ); + _( "Edit Footprint" ), _( "Show selected footprint on editor canvas" ), + edit_xpm ); TOOL_ACTION PCB_ACTIONS::deleteFootprint( "pcbnew.ModuleEditor.deleteFootprint", AS_GLOBAL, 0, _( "Delete Footprint from Library" ), "", delete_xpm ); +TOOL_ACTION PCB_ACTIONS::cutFootprint( "pcbnew.ModuleEditor.cutFootprint", + AS_GLOBAL, 0, + _( "Cut Footprint" ), "", + cut_xpm ); + +TOOL_ACTION PCB_ACTIONS::copyFootprint( "pcbnew.ModuleEditor.copyFootprint", + AS_GLOBAL, 0, + _( "Copy Footprint" ), "", + copy_xpm ); + +TOOL_ACTION PCB_ACTIONS::pasteFootprint( "pcbnew.ModuleEditor.pasteFootprint", + AS_GLOBAL, 0, + _( "Paste Footprint" ), "", + paste_xpm ); + +TOOL_ACTION PCB_ACTIONS::importFootprint( "pcbnew.ModuleEditor.importFootprint", + AS_GLOBAL, 0, + _( "Import Footprint..." ), "", + import_module_xpm ); + +TOOL_ACTION PCB_ACTIONS::exportFootprint( "pcbnew.ModuleEditor.exportFootprint", + AS_GLOBAL, 0, + _( "Export Footprint..." ), "", + export_module_xpm ); + +// Module editor tools +TOOL_ACTION PCB_ACTIONS::footprintProperties( "pcbnew.ModuleEditor.footprintProperties", + AS_GLOBAL, 0, + _( "Footprint Properties..." ), "", + module_options_xpm ); + TOOL_ACTION PCB_ACTIONS::placePad( "pcbnew.ModuleEditor.placePad", AS_GLOBAL, 0, _( "Add Pad" ), _( "Add a pad" ), @@ -158,9 +194,7 @@ bool MODULE_EDITOR_TOOLS::Init() #ifdef KICAD_SCRIPTING ctxMenu.AddItem( PCB_ACTIONS::createFootprint, SELECTION_CONDITIONS::ShowAlways ); #endif - ctxMenu.AddItem( ID_MODEDIT_EDIT_MODULE, - _( "Edit Footprint" ), _( "Show selected footprint on editor canvas" ), - edit_xpm, fpSelectedCondition ); + ctxMenu.AddItem( PCB_ACTIONS::editFootprint, fpSelectedCondition ); ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways ); ctxMenu.AddItem( ACTIONS::save, fpSelectedCondition ); @@ -169,18 +203,13 @@ bool MODULE_EDITOR_TOOLS::Init() ctxMenu.AddItem( ACTIONS::revert, fpSelectedCondition ); ctxMenu.AddSeparator( SELECTION_CONDITIONS::ShowAlways ); - ctxMenu.AddItem( ID_MODEDIT_CUT_PART, _( "Cut Footprint" ), "", - cut_xpm, fpSelectedCondition ); - ctxMenu.AddItem( ID_MODEDIT_COPY_PART, _( "Copy Footprint" ), "", - copy_xpm, fpSelectedCondition ); - ctxMenu.AddItem( ID_MODEDIT_PASTE_PART, _( "Paste Footprint" ), "", - paste_xpm, SELECTION_CONDITIONS::ShowAlways ); + ctxMenu.AddItem( PCB_ACTIONS::cutFootprint, fpSelectedCondition ); + ctxMenu.AddItem( PCB_ACTIONS::copyFootprint, fpSelectedCondition ); + ctxMenu.AddItem( PCB_ACTIONS::pasteFootprint, SELECTION_CONDITIONS::ShowAlways ); ctxMenu.AddSeparator( fpSelectedCondition ); - ctxMenu.AddItem( ID_MODEDIT_IMPORT_PART, _( "Import Footprint..." ), "", - import_module_xpm, SELECTION_CONDITIONS::ShowAlways ); - ctxMenu.AddItem( ID_MODEDIT_EXPORT_PART, _( "Export Footprint..." ), "", - export_module_xpm, fpSelectedCondition ); + ctxMenu.AddItem( PCB_ACTIONS::importFootprint, SELECTION_CONDITIONS::ShowAlways ); + ctxMenu.AddItem( PCB_ACTIONS::exportFootprint, fpSelectedCondition ); return true; } @@ -225,7 +254,45 @@ int MODULE_EDITOR_TOOLS::Revert( const TOOL_EVENT& aEvent ) } -int MODULE_EDITOR_TOOLS::Delete( const TOOL_EVENT& aEvent ) +int MODULE_EDITOR_TOOLS::CutCopyFootprint( const TOOL_EVENT& aEvent ) +{ + LIB_ID fpID = m_frame->GetTreeFPID(); + + if( fpID == m_frame->GetLoadedFPID() ) + m_copiedModule.reset( new MODULE( *m_frame->GetBoard()->GetFirstModule() ) ); + else + m_copiedModule.reset( m_frame->LoadFootprint( fpID ) ); + + if( aEvent.IsAction( &PCB_ACTIONS::cutFootprint ) ) + DeleteFootprint(aEvent ); + + return 0; +} + + +int MODULE_EDITOR_TOOLS::PasteFootprint( const TOOL_EVENT& aEvent ) +{ + if( m_copiedModule && !m_frame->GetTreeFPID().GetLibNickname().empty() ) + { + wxString newLib = m_frame->GetTreeFPID().GetLibNickname(); + MODULE* newModule( m_copiedModule.get() ); + wxString newName = newModule->GetFPID().GetLibItemName(); + + while( m_frame->Prj().PcbFootprintLibs()->FootprintExists( newLib, newName ) ) + newName += _( "_copy" ); + + newModule->SetFPID( LIB_ID( newLib, newName ) ); + m_frame->SaveFootprintInLibrary( newModule, newLib ); + + m_frame->SyncLibraryTree( true ); + m_frame->FocusOnLibID( newModule->GetFPID() ); + } + + return 0; +} + + +int MODULE_EDITOR_TOOLS::DeleteFootprint( const TOOL_EVENT& aEvent ) { FOOTPRINT_EDIT_FRAME* frame = getEditFrame(); @@ -241,6 +308,57 @@ int MODULE_EDITOR_TOOLS::Delete( const TOOL_EVENT& aEvent ) } +int MODULE_EDITOR_TOOLS::ImportFootprint( const TOOL_EVENT& aEvent ) +{ + if( !m_frame->Clear_Pcb( true ) ) + return -1; // this command is aborted + + m_frame->SetCrossHairPosition( wxPoint( 0, 0 ) ); + m_frame->Import_Module(); + + if( m_frame->GetBoard()->GetFirstModule() ) + m_frame->GetBoard()->GetFirstModule()->ClearFlags(); + + // Clear undo and redo lists because we don't have handling to in + // FP editor to undo across imports (the module _is_ the board with the stack) + // todo: Abstract undo/redo stack to a higher element or keep consistent board item in fpeditor + frame()->GetScreen()->ClearUndoRedoList(); + + m_toolMgr->RunAction( ACTIONS::zoomFitScreen, true ); + m_frame->OnModify(); + return 0; +} + + +int MODULE_EDITOR_TOOLS::ExportFootprint( const TOOL_EVENT& aEvent ) +{ + LIB_ID fpID = m_frame->GetTreeFPID(); + MODULE* fp; + + if( fpID == m_frame->GetLoadedFPID() ) + fp = m_frame->GetBoard()->GetFirstModule(); + else + fp = m_frame->LoadFootprint( fpID ); + + m_frame->Export_Module( fp ); + return 0; +} + + +int MODULE_EDITOR_TOOLS::EditFootprint( const TOOL_EVENT& aEvent ) +{ + m_frame->LoadModuleFromLibrary( m_frame->GetTreeFPID() ); + return 0; +} + + +int MODULE_EDITOR_TOOLS::ToggleFootprintTree( const TOOL_EVENT& aEvent ) +{ + m_frame->ToggleSearchTree(); + return 0; +} + + int MODULE_EDITOR_TOOLS::Properties( const TOOL_EVENT& aEvent ) { MODULE* footprint = m_frame->GetBoard()->GetFirstModule(); @@ -711,8 +829,17 @@ void MODULE_EDITOR_TOOLS::setTransitions() Go( &MODULE_EDITOR_TOOLS::SaveAs, ACTIONS::saveAs.MakeEvent() ); Go( &MODULE_EDITOR_TOOLS::SaveAs, ACTIONS::saveCopyAs.MakeEvent() ); Go( &MODULE_EDITOR_TOOLS::Revert, ACTIONS::revert.MakeEvent() ); - Go( &MODULE_EDITOR_TOOLS::Delete, PCB_ACTIONS::deleteFootprint.MakeEvent() ); + Go( &MODULE_EDITOR_TOOLS::DeleteFootprint, PCB_ACTIONS::deleteFootprint.MakeEvent() ); + Go( &MODULE_EDITOR_TOOLS::EditFootprint, PCB_ACTIONS::editFootprint.MakeEvent() ); + Go( &MODULE_EDITOR_TOOLS::CutCopyFootprint, PCB_ACTIONS::cutFootprint.MakeEvent() ); + Go( &MODULE_EDITOR_TOOLS::CutCopyFootprint, PCB_ACTIONS::copyFootprint.MakeEvent() ); + Go( &MODULE_EDITOR_TOOLS::PasteFootprint, PCB_ACTIONS::pasteFootprint.MakeEvent() ); + + Go( &MODULE_EDITOR_TOOLS::ImportFootprint, PCB_ACTIONS::importFootprint.MakeEvent() ); + Go( &MODULE_EDITOR_TOOLS::ExportFootprint, PCB_ACTIONS::exportFootprint.MakeEvent() ); + + Go( &MODULE_EDITOR_TOOLS::ToggleFootprintTree, PCB_ACTIONS::toggleFootprintTree.MakeEvent() ); Go( &MODULE_EDITOR_TOOLS::Properties, PCB_ACTIONS::footprintProperties.MakeEvent() ); Go( &MODULE_EDITOR_TOOLS::DefaultPadProperties, PCB_ACTIONS::defaultPadProperties.MakeEvent() ); diff --git a/pcbnew/tools/footprint_editor_tools.h b/pcbnew/tools/footprint_editor_tools.h index 1837a75a26..22489aa273 100644 --- a/pcbnew/tools/footprint_editor_tools.h +++ b/pcbnew/tools/footprint_editor_tools.h @@ -54,8 +54,15 @@ public: int Save( const TOOL_EVENT& aEvent ); int SaveAs( const TOOL_EVENT& aEvent ); int Revert( const TOOL_EVENT& aEvent ); - int Delete( const TOOL_EVENT& aEvent ); + int EditFootprint( const TOOL_EVENT& aEvent ); + int CutCopyFootprint( const TOOL_EVENT& aEvent ); + int PasteFootprint( const TOOL_EVENT& aEvent ); + int DeleteFootprint( const TOOL_EVENT& aEvent ); + int ImportFootprint( const TOOL_EVENT& aEvent ); + int ExportFootprint( const TOOL_EVENT& aEvent ); + + int ToggleFootprintTree( const TOOL_EVENT& aEvent ); int Properties( const TOOL_EVENT& aEvent ); /** @@ -101,7 +108,10 @@ private: void setTransitions() override; private: - FOOTPRINT_EDIT_FRAME* m_frame; + FOOTPRINT_EDIT_FRAME* m_frame; + + // A private clipboard for cut/copy/past of an entire footprint + std::unique_ptr m_copiedModule; }; #endif diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 541e81f0e2..bb69b22b8c 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -287,6 +287,8 @@ public: // Module editor tools + static TOOL_ACTION toggleFootprintTree; + // We don't use ACTION::new here because we need to distinguish between New Library // and New Footprint. static TOOL_ACTION newFootprint; @@ -299,7 +301,13 @@ public: static TOOL_ACTION saveToBoard; static TOOL_ACTION saveToLibrary; + static TOOL_ACTION editFootprint; static TOOL_ACTION deleteFootprint; + static TOOL_ACTION cutFootprint; + static TOOL_ACTION copyFootprint; + static TOOL_ACTION pasteFootprint; + static TOOL_ACTION importFootprint; + static TOOL_ACTION exportFootprint; static TOOL_ACTION footprintProperties; static TOOL_ACTION defaultPadProperties; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index cb23786f51..558bf0caf2 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -1001,28 +1001,6 @@ int PCBNEW_CONTROL::Show3DViewer( const TOOL_EVENT& aEvent ) } -int PCBNEW_CONTROL::ShowFootprintBrowser( const TOOL_EVENT& aEvent ) -{ - auto* viewer = (FOOTPRINT_VIEWER_FRAME*) m_frame->Kiway().Player( FRAME_PCB_MODULE_VIEWER ); - - viewer->Show( true ); - - // On Windows, Raise() does not bring the window on screen, when iconized - if( viewer->IsIconized() ) - viewer->Iconize( false ); - - viewer->Raise(); - - // Raising the window does not set the focus on Linux. This should work on - // any platform. - if( wxWindow::FindFocus() != viewer ) - viewer->SetFocus(); - - return 0; - -} - - int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent ) { DisplayInfoMessage( m_frame, _( "Not available in OpenGL/Cairo canvases." ) ); @@ -1119,7 +1097,6 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::DeleteItemCursor, PCB_ACTIONS::deleteTool.MakeEvent() ); Go( &PCBNEW_CONTROL::ShowHelp, PCB_ACTIONS::showHelp.MakeEvent() ); Go( &PCBNEW_CONTROL::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() ); - Go( &PCBNEW_CONTROL::ShowFootprintBrowser, ACTIONS::showFootprintBrowser.MakeEvent() ); Go( &PCBNEW_CONTROL::ToBeDone, PCB_ACTIONS::toBeDone.MakeEvent() ); // Append control diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 826e231d81..a1b7c306f1 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -98,7 +98,6 @@ public: int AppendBoard( PLUGIN& pi, wxString& fileName ); int ShowHelp( const TOOL_EVENT& aEvent ); int Show3DViewer( const TOOL_EVENT& aEvent ); - int ShowFootprintBrowser( const TOOL_EVENT& aEvent ); int ToBeDone( const TOOL_EVENT& aEvent ); int UpdateMessagePanel( const TOOL_EVENT& aEvent );