From a90e83a699fd1d4a31b617cf365d87c0acc220e2 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 19 Apr 2025 14:10:52 +0200 Subject: [PATCH] FOOTPRINT_WIZARD_FRAME: fix tools missing in toolbar (i.e. fix TODO items) These TODO were to convert missing tools to actions. Fixes https://gitlab.com/kicad/code/kicad/-/issues/20694 --- pcbnew/CMakeLists.txt | 1 + pcbnew/footprint_wizard_frame.cpp | 5 +- pcbnew/footprint_wizard_frame.h | 25 +++--- pcbnew/footprint_wizard_frame_functions.cpp | 67 +++++++--------- pcbnew/pcbnew_id.h | 3 - pcbnew/toolbars_footprint_wizard.cpp | 30 ++----- pcbnew/tools/footprint_wizard_tools.cpp | 86 +++++++++++++++++++++ pcbnew/tools/footprint_wizard_tools.h | 77 ++++++++++++++++++ pcbnew/tools/pcb_actions.cpp | 36 +++++++++ pcbnew/tools/pcb_actions.h | 7 ++ 10 files changed, 258 insertions(+), 79 deletions(-) create mode 100644 pcbnew/tools/footprint_wizard_tools.cpp create mode 100644 pcbnew/tools/footprint_wizard_tools.h diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 0e3fed083a..a1d67a5efb 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -395,6 +395,7 @@ set( PCBNEW_CLASS_SRCS tools/global_edit_tool.cpp tools/footprint_editor_control.cpp tools/footprint_chooser_selection_tool.cpp + tools/footprint_wizard_tools.cpp tools/item_modification_routine.cpp tools/pad_tool.cpp tools/pcb_control.cpp diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 0b12edf6e4..b0d91ab6de 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -53,6 +53,7 @@ #include "tools/pcb_selection_tool.h" #include "tools/pcb_control.h" #include "tools/pcb_actions.h" +#include "tools/footprint_wizard_tools.h" #include #include @@ -65,9 +66,6 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, PCB_BASE_EDIT_FRAME ) // Toolbar events EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard ) - EVT_TOOL( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, FOOTPRINT_WIZARD_FRAME::DefaultParameters ) - EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) - EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions ) EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE, FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint ) // listbox events @@ -146,6 +144,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid) m_toolManager->RegisterTool( new SCRIPTING_TOOL ); m_toolManager->RegisterTool( new COMMON_TOOLS ); + m_toolManager->RegisterTool( new FOOTPRINT_WIZARD_TOOLS ); m_toolManager->InitTools(); // Run the control tool, it is supposed to be always active diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 65c367430b..9244385437 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -69,6 +69,19 @@ public: COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override; + void SelectCurrentWizard( wxCommandEvent& aDummy ); // Open the wizard selector dialog + + void DefaultParameters(); // Reset the initial (default) values of the wizard prms + void SelectWizardPreviousPage(); // Select the previous parameter page for wizards having + // more than one parameter page + void SelectWizardNextPage(); // Select the next parameter page for wizards having + // more than one parameter page + + /** + * Will let the caller exit from the wait loop, and get the built footprint. + */ + void ExportSelectedFootprint( wxCommandEvent& aEvent ); + private: void OnSize( wxSizeEvent& event ) override; @@ -87,12 +100,6 @@ private: */ void updateView(); - /** - * Will let the caller exit from the wait loop, and get the built footprint. - * - */ - void ExportSelectedFootprint( wxCommandEvent& aEvent ); - /** * Resize the child windows when dragging a sash window border. */ @@ -140,8 +147,6 @@ private: */ FOOTPRINT_WIZARD* GetMyWizard(); - void Process_Special_Functions( wxCommandEvent& event ); - /** * Show all the details about the current wizard. */ @@ -161,10 +166,6 @@ private: */ void OnActivate( wxActivateEvent& event ); - void SelectCurrentWizard( wxCommandEvent& event ); - - void DefaultParameters( wxCommandEvent& event ); - /** * Update the footprint python parameters values from the values in grid. */ diff --git a/pcbnew/footprint_wizard_frame_functions.cpp b/pcbnew/footprint_wizard_frame_functions.cpp index 7dcafd61c9..1619e479f8 100644 --- a/pcbnew/footprint_wizard_frame_functions.cpp +++ b/pcbnew/footprint_wizard_frame_functions.cpp @@ -37,42 +37,6 @@ #include "footprint_wizard_frame.h" -void FOOTPRINT_WIZARD_FRAME::Process_Special_Functions( wxCommandEvent& event ) -{ - wxString msg; - int page; - - switch( event.GetId() ) - { - case ID_FOOTPRINT_WIZARD_NEXT: - page = m_pageList->GetSelection() + 1; - - if( (int)m_pageList->GetCount() <= page ) - page = m_pageList->GetCount() - 1; - - m_pageList->SetSelection( page, true ); - ClickOnPageList( event ); - break; - - case ID_FOOTPRINT_WIZARD_PREVIOUS: - page = m_pageList->GetSelection() - 1; - - if( page < 0 ) - page = 0; - - m_pageList->SetSelection( page, true ); - ClickOnPageList( event ); - break; - - default: - wxFAIL_MSG( wxString::Format( wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions " - "error: id = %d" ), - event.GetId() ) ); - break; - } -} - - /* Displays the name of the current opened library in the caption */ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos() { @@ -191,13 +155,13 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard() } -void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event ) +void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& aDummy ) { SelectFootprintWizard(); updateView(); } -void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event ) +void FOOTPRINT_WIZARD_FRAME::DefaultParameters() { FOOTPRINT_WIZARD* footprintWizard = GetMyWizard(); @@ -213,6 +177,33 @@ void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event ) } +void FOOTPRINT_WIZARD_FRAME::SelectWizardPreviousPage() +{ + int page = m_pageList->GetSelection() - 1; + + if( page < 0 ) + page = 0; + + m_pageList->SetSelection( page, true ); + + wxCommandEvent event; + ClickOnPageList( event ); +} + +void FOOTPRINT_WIZARD_FRAME::SelectWizardNextPage() +{ + int page = m_pageList->GetSelection() + 1; + + if( (int)m_pageList->GetCount() <= page ) + page = m_pageList->GetCount() - 1; + + m_pageList->SetSelection( page, true ); + + wxCommandEvent event; + ClickOnPageList( event ); +} + + // This is a flag to avoid reentering of ParametersUpdated // that can happen in some cases static bool lock_update_prms = false; diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 1b384a2569..8f036e83dc 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -101,13 +101,10 @@ enum pcbnew_ids ID_MODVIEW_PREVIOUS, ID_MODVIEW_NEXT, - ID_FOOTPRINT_WIZARD_NEXT, - ID_FOOTPRINT_WIZARD_PREVIOUS, ID_FOOTPRINT_WIZARD_DONE, ID_FOOTPRINT_WIZARD_PAGE_LIST, ID_FOOTPRINT_WIZARD_PARAMETER_LIST, ID_FOOTPRINT_WIZARD_SELECT_WIZARD, - ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, ID_PCBNEW_END_LIST }; diff --git a/pcbnew/toolbars_footprint_wizard.cpp b/pcbnew/toolbars_footprint_wizard.cpp index 7a88ec747e..cf6b21dae7 100644 --- a/pcbnew/toolbars_footprint_wizard.cpp +++ b/pcbnew/toolbars_footprint_wizard.cpp @@ -38,27 +38,14 @@ std::optional FOOTPRINT_WIZARD_TOOLBAR_SETTINGS::DefaultT return std::nullopt; case TOOLBAR_LOC::TOP_MAIN: - /* TODO (ISM): Convert to action - m_tbTopMain->AddTool( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, wxEmptyString, - KiBitmap( BITMAPS::module_wizard ), - _( "Select wizard script to run" ) ); - */ + config.AppendAction( PCB_ACTIONS::showWizards ); config.AppendSeparator(); - /* TODO (ISM): Convert to action - m_tbTopMain->AddTool( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, wxEmptyString, - KiBitmap( BITMAPS::reload ), - _( "Reset wizard parameters to default") ); - */ + config.AppendAction( PCB_ACTIONS::resetWizardPrms ); + config.AppendSeparator(); - /* TODO (ISM): Convert to action - m_tbTopMain->AddTool( ID_FOOTPRINT_WIZARD_PREVIOUS, wxEmptyString, - KiBitmap( BITMAPS::lib_previous ), - _( "Select previous parameters page" ) ); - m_tbTopMain->AddTool( ID_FOOTPRINT_WIZARD_NEXT, wxEmptyString, - KiBitmap( BITMAPS::lib_next ), - _( "Select next parameters page" ) ); - */ + config.AppendAction( PCB_ACTIONS::selectPreviousWizardPage ); + config.AppendAction( PCB_ACTIONS::selectNextWizardPage ); config.AppendSeparator() .AppendAction( ACTIONS::zoomRedraw ) @@ -68,11 +55,8 @@ std::optional FOOTPRINT_WIZARD_TOOLBAR_SETTINGS::DefaultT // The footprint wizard always can export the current footprint config.AppendSeparator(); - /* TODO (ISM): Convert to action - m_tbTopMain->AddTool( ID_FOOTPRINT_WIZARD_DONE, - wxEmptyString, KiBitmap( BITMAPS::export_footprint_names ), - _( "Export footprint to editor" ) ); - */ + config.AppendAction( PCB_ACTIONS::exportFpToEditor ); + break; } diff --git a/pcbnew/tools/footprint_wizard_tools.cpp b/pcbnew/tools/footprint_wizard_tools.cpp new file mode 100644 index 0000000000..961c984e51 --- /dev/null +++ b/pcbnew/tools/footprint_wizard_tools.cpp @@ -0,0 +1,86 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "tools/footprint_wizard_tools.h" + +#include + +#include + +bool FOOTPRINT_WIZARD_TOOLS::Init() +{ + return true; +} + + +void FOOTPRINT_WIZARD_TOOLS::Reset( RESET_REASON aReason ) +{ +} + + +int FOOTPRINT_WIZARD_TOOLS::ShowWizards( const TOOL_EVENT& aEvent ) +{ + wxCommandEvent dummy; + frame()->SelectCurrentWizard( dummy ); + return 0; +} + + +int FOOTPRINT_WIZARD_TOOLS::ResetWizardPrms( const TOOL_EVENT& aEvent ) +{ + frame()->DefaultParameters(); + return 0; +} + + +int FOOTPRINT_WIZARD_TOOLS::SelectPreviousWizardPage( const TOOL_EVENT& aEvent ) +{ + frame()->SelectWizardPreviousPage(); + return 0; +} + + +int FOOTPRINT_WIZARD_TOOLS::SelectNextWizardPage( const TOOL_EVENT& aEvent ) +{ + frame()->SelectWizardNextPage(); + return 0; +} + + +int FOOTPRINT_WIZARD_TOOLS::ExportFpToEditor( const TOOL_EVENT& aEvent ) +{ + wxPostEvent( frame(), wxCommandEvent( wxEVT_TOOL, ID_FOOTPRINT_WIZARD_DONE ) ); + return 0; +} + + +void FOOTPRINT_WIZARD_TOOLS::setTransitions() +{ + // clang-format off + Go( &FOOTPRINT_WIZARD_TOOLS::ShowWizards, PCB_ACTIONS::showWizards.MakeEvent() ); + Go( &FOOTPRINT_WIZARD_TOOLS::ResetWizardPrms, PCB_ACTIONS::resetWizardPrms.MakeEvent() ); + Go( &FOOTPRINT_WIZARD_TOOLS::SelectPreviousWizardPage, PCB_ACTIONS::selectPreviousWizardPage.MakeEvent() ); + Go( &FOOTPRINT_WIZARD_TOOLS::SelectNextWizardPage, PCB_ACTIONS::selectNextWizardPage.MakeEvent() ); + Go( &FOOTPRINT_WIZARD_TOOLS::ExportFpToEditor, PCB_ACTIONS::exportFpToEditor.MakeEvent() ); + // clang-format on +} diff --git a/pcbnew/tools/footprint_wizard_tools.h b/pcbnew/tools/footprint_wizard_tools.h new file mode 100644 index 0000000000..a3f28dd935 --- /dev/null +++ b/pcbnew/tools/footprint_wizard_tools.h @@ -0,0 +1,77 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright The 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef FOOTPRINT_WIZARD_TOOLS_H +#define FOOTPRINT_WIZARD_TOOLS_H + +#include +#include + +class FOOTPRINT_WIZARD_FRAME; + +/** + * Tool useful for viewing footprints. + * + * This tool is designed to be lighter-weight so that it doesn't bring in as many PcbNew + * dependencies (since it is used in cvpcb). + */ +class FOOTPRINT_WIZARD_TOOLS : public TOOL_INTERACTIVE +{ +public: + FOOTPRINT_WIZARD_TOOLS() : + TOOL_INTERACTIVE( "pcbnew.FpWizard" ), + m_wizardFrame( nullptr ) + {} + + ~FOOTPRINT_WIZARD_TOOLS() override {} + + bool Init() override; + + /// @copydoc TOOL_BASE::Reset() + void Reset( RESET_REASON aReason ) override; + + ///< Set up handlers for various events. + void setTransitions() override; + +protected: + int ShowWizards( const TOOL_EVENT& aEvent ); + int ResetWizardPrms( const TOOL_EVENT& aEvent ); + int SelectPreviousWizardPage( const TOOL_EVENT& aEvent ); + int SelectNextWizardPage( const TOOL_EVENT& aEvent ); + int ExportFpToEditor( const TOOL_EVENT& aEvent ); + + FOOTPRINT_WIZARD_FRAME* frame() const + { + return getEditFrame(); + } + + /*FOOTPRINT_WIZARD_FRAME* frame() const + { + return m_wizardFrame; + }*/ + +protected: + FOOTPRINT_WIZARD_FRAME* m_wizardFrame; ///< the associated footprint wizard frame +}; + +#endif diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index af2828ae03..23e2fe8488 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -2580,6 +2580,42 @@ TOOL_ACTION PCB_ACTIONS::ddImportFootprint( TOOL_ACTION_ARGS() .Name( "pcbnew.Control.ddImportFootprint" ) .Scope( AS_GLOBAL ) ); +// actions for footprint wizard frame +TOOL_ACTION PCB_ACTIONS::showWizards( TOOL_ACTION_ARGS() + .Name( "pcbnew.FpWizard.showWizards" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Show wizards selector" ) ) + .Tooltip( _( "Select wizard script to run" ) ) + .Icon( BITMAPS::module_wizard ) ); + +TOOL_ACTION PCB_ACTIONS::resetWizardPrms( TOOL_ACTION_ARGS() + .Name( "pcbnew.FpWizard.resetWizardPrms" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Reset wizard parameters" ) ) + .Tooltip( _( "Reset wizard parameters to default" ) ) + .Icon( BITMAPS::reload ) ); + +TOOL_ACTION PCB_ACTIONS::selectPreviousWizardPage( TOOL_ACTION_ARGS() + .Name( "pcbnew.FpWizard.selectPreviousWizardPage" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Select previous wizard page" ) ) + .Tooltip( _( "Select previous parameters page" ) ) + .Icon( BITMAPS::lib_previous ) ); + +TOOL_ACTION PCB_ACTIONS::selectNextWizardPage( TOOL_ACTION_ARGS() + .Name( "pcbnew.FpWizard.selectNextWizardPage" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Select next wizard page" ) ) + .Tooltip( _( "Select next parameters page" ) ) + .Icon( BITMAPS::lib_next ) ); + +TOOL_ACTION PCB_ACTIONS::exportFpToEditor( TOOL_ACTION_ARGS() + .Name( "pcbnew.FpWizard.exportFpToEditor" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Export footprint to editor" ) ) + .Tooltip( _( "Export footprint to editor" ) ) + .Icon( BITMAPS::export_footprint_names ) ); + const TOOL_EVENT& PCB_EVENTS::SnappingModeChangedByKeyEvent() { diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 842ab848cc..9eb8f7b375 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -582,6 +582,13 @@ public: static TOOL_ACTION repeatLayout; static TOOL_ACTION generatePlacementRuleAreas; + + /// Footprint wizard frame actions: + static TOOL_ACTION showWizards; + static TOOL_ACTION resetWizardPrms; + static TOOL_ACTION selectPreviousWizardPage; + static TOOL_ACTION selectNextWizardPage; + static TOOL_ACTION exportFpToEditor; }; class PCB_EVENTS