From 784246575b101c9dbbfb151662786a0484f71bf7 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 20 Feb 2025 15:00:50 +0000 Subject: [PATCH] Move footprint viewer/cvpcb actions to tool framework --- common/settings/cvpcb_settings.cpp | 2 -- cvpcb/cvpcb_id.h | 1 - cvpcb/display_footprints_frame.cpp | 37 +++++--------------------- include/settings/cvpcb_settings.h | 3 --- pcbnew/footprint_viewer_frame.cpp | 18 +++++-------- pcbnew/pcbnew_id.h | 1 - pcbnew/pcbnew_settings.cpp | 2 -- pcbnew/pcbnew_settings.h | 9 ++++--- pcbnew/toolbars_footprint_viewer.cpp | 11 ++------ pcbnew/tools/pcb_actions.cpp | 8 ++++++ pcbnew/tools/pcb_actions.h | 1 + pcbnew/tools/pcb_editor_conditions.cpp | 17 ++++++++++++ pcbnew/tools/pcb_editor_conditions.h | 10 +++++++ pcbnew/tools/pcb_viewer_tools.cpp | 14 ++++++++++ pcbnew/tools/pcb_viewer_tools.h | 3 +++ 15 files changed, 75 insertions(+), 62 deletions(-) diff --git a/common/settings/cvpcb_settings.cpp b/common/settings/cvpcb_settings.cpp index 018e8c03b7..15b51b5402 100644 --- a/common/settings/cvpcb_settings.cpp +++ b/common/settings/cvpcb_settings.cpp @@ -31,8 +31,6 @@ const int cvpcbSchemaVersion = 0; CVPCB_SETTINGS::CVPCB_SETTINGS() : PCB_VIEWERS_SETTINGS_BASE( "cvpcb", cvpcbSchemaVersion ), - m_FootprintViewerZoom( 1.0 ), - m_FootprintViewerAutoZoomOnSelect( true ), m_FilterFlags( 0 ), m_LibrariesWidth( 0 ), m_FootprintsWidth( 0 ) diff --git a/cvpcb/cvpcb_id.h b/cvpcb/cvpcb_id.h index f8a2ccbda2..6fe6709434 100644 --- a/cvpcb/cvpcb_id.h +++ b/cvpcb/cvpcb_id.h @@ -31,5 +31,4 @@ enum id_cvpcb_frm ID_CVPCB_COMPONENT_LIST = ID_END_LIST, ID_CVPCB_FOOTPRINT_LIST, ID_CVPCB_LIBRARY_LIST, - ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL }; diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 792ebb856e..0481da5ad2 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -144,20 +144,9 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.) CVPCB_SETTINGS* cfg = dynamic_cast( config() ); - /* TODO (ISM): Re-enable this once this is turned into an action if( cfg ) - { GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom ); - wxAuiToolBarItem* toolOpt = m_tbTopMain->FindTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL ); - - if( cfg->m_FootprintViewerAutoZoomOnSelect ) - toolOpt->SetState( wxAUI_BUTTON_STATE_CHECKED ); - else - toolOpt->SetState( 0 ); - } - */ - updateView(); Show( true ); @@ -219,7 +208,7 @@ void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) ); - + mgr->SetConditions( PCB_ACTIONS::fpAutoZoom, CHECK( cond.FootprintViewerAutoZoom() ) ); #undef CHECK } @@ -271,15 +260,9 @@ std::optional DISPLAY_FOOTPRINTS_FRAME::DefaultTopMainToo config.AppendSeparator() .AppendControl( m_tbZoomSelectName ); - config.AppendSeparator(); + config.AppendSeparator() + .AppendAction( PCB_ACTIONS::fpAutoZoom ); -/* TODO (ISM): Turn this into an action - // Option to run Zoom automatique on footprint selection change - m_tbTopMain->AddTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL, wxEmptyString, - KiScaledBitmap( BITMAPS::zoom_auto_fit_in_page, this ), - _( "Automatic Zoom on footprint change" ), - wxITEM_CHECK ); -*/ // clang-format on return config; } @@ -307,13 +290,7 @@ void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) PCB_BASE_FRAME::SaveSettings( cfg ); cfg->m_FootprintViewerDisplayOptions = GetDisplayOptions(); - cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); - - /* TODO (ISM): Move to action framework - wxAuiToolBarItem* toolOpt = m_tbTopMain->FindTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL ); - cfg->m_FootprintViewerAutoZoomOnSelect = ( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ); - */ } @@ -504,14 +481,14 @@ void DISPLAY_FOOTPRINTS_FRAME::updateView() m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); - /* TODO (ISM): Move to action framework - wxAuiToolBarItem* toolOpt = m_tbTopMain->FindTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL ); + CVPCB_SETTINGS* cfg = dynamic_cast( config() ); + wxCHECK( cfg, /* void */ ); - if( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ) + if( cfg->m_FootprintViewerAutoZoomOnSelect ) m_toolManager->RunAction( ACTIONS::zoomFitScreen ); else m_toolManager->RunAction( ACTIONS::centerContents ); -*/ + UpdateMsgPanel(); } diff --git a/include/settings/cvpcb_settings.h b/include/settings/cvpcb_settings.h index a23b1e6526..ad233c12bb 100644 --- a/include/settings/cvpcb_settings.h +++ b/include/settings/cvpcb_settings.h @@ -43,9 +43,6 @@ public: MAGNETIC_SETTINGS m_FootprintViewerMagneticSettings; - double m_FootprintViewerZoom; - bool m_FootprintViewerAutoZoomOnSelect; - int m_FilterFlags; wxString m_FilterString; int m_LibrariesWidth; diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 4a6320776f..d287110e7c 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -292,13 +293,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent wxASSERT( cfg ); GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom ); - wxAuiToolBarItem* toolOpt = m_tbTopMain->FindTool( ID_FPVIEWER_AUTOZOOM_TOOL ); - - if( cfg->m_FootprintViewerAutoZoomOnSelect ) - toolOpt->SetState( wxAUI_BUTTON_STATE_CHECKED ); - else - toolOpt->SetState( 0 ); - updateView(); setupUnits( config() ); @@ -376,6 +370,8 @@ void FOOTPRINT_VIEWER_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) ); mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) ); + mgr->SetConditions( PCB_ACTIONS::fpAutoZoom, CHECK( cond.FootprintViewerAutoZoom() ) ); + #undef ENABLE #undef CHECK } @@ -843,8 +839,6 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) if( GetCanvas() && GetCanvas()->GetView() ) cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); - wxAuiToolBarItem* toolOpt = m_tbTopMain->FindTool( ID_FPVIEWER_AUTOZOOM_TOOL ); - cfg->m_FootprintViewerAutoZoomOnSelect = ( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ); cfg->m_FootprintViewerLibListWidth = m_libList->GetSize().x; cfg->m_FootprintViewerFPListWidth = m_fpList->GetSize().x; @@ -1095,13 +1089,15 @@ void FOOTPRINT_VIEWER_FRAME::updateView() m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); - wxAuiToolBarItem* toolOpt = m_tbTopMain->FindTool( ID_FPVIEWER_AUTOZOOM_TOOL ); + PCBNEW_SETTINGS* cfg = dynamic_cast( config() ); + wxCHECK( cfg, /* void */ ); - if( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ) + if( cfg->m_FootprintViewerAutoZoomOnSelect ) m_toolManager->RunAction( ACTIONS::zoomFitScreen ); else m_toolManager->RunAction( ACTIONS::centerContents ); + UpdateMsgPanel(); } diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index e458b0cd2b..5e740239c5 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -100,7 +100,6 @@ enum pcbnew_ids ID_MODVIEW_FOOTPRINT_LIST, ID_MODVIEW_PREVIOUS, ID_MODVIEW_NEXT, - ID_FPVIEWER_AUTOZOOM_TOOL, ID_FOOTPRINT_WIZARD_NEXT, ID_FOOTPRINT_WIZARD_PREVIOUS, diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index 1ddf0e695a..ec00193c86 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -81,8 +81,6 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_AutoRefillZones( false ), m_AllowFreePads( false ), m_PnsSettings( nullptr ), - m_FootprintViewerZoom( 1.0 ), - m_FootprintViewerAutoZoomOnSelect( true ), m_FootprintViewerLibListWidth( 200 ), m_FootprintViewerFPListWidth( 300 ) { diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index 2d714e8a00..3c89b90c2f 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -116,10 +116,15 @@ public: bool m_DisplayPadFill; }; + double m_FootprintViewerZoom; ///< The last zoom level used (0 for auto) + bool m_FootprintViewerAutoZoomOnSelect; ///< true to use automatic zoom on fp selection + VIEWERS_DISPLAY_OPTIONS m_ViewersDisplay; PCB_VIEWERS_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ): - APP_SETTINGS_BASE( aFilename, aSchemaVersion ) + APP_SETTINGS_BASE( aFilename, aSchemaVersion ), + m_FootprintViewerZoom( 1.0 ), + m_FootprintViewerAutoZoomOnSelect( true ) { m_ViewersDisplay.m_DisplayGraphicsFill = true; m_ViewersDisplay.m_DisplayTextFill = true; @@ -457,8 +462,6 @@ public: std::unique_ptr m_PnsSettings; - double m_FootprintViewerZoom; ///< The last zoom level used (0 for auto) - bool m_FootprintViewerAutoZoomOnSelect; ///< true to use automatic zoom on fp selection int m_FootprintViewerLibListWidth; int m_FootprintViewerFPListWidth; diff --git a/pcbnew/toolbars_footprint_viewer.cpp b/pcbnew/toolbars_footprint_viewer.cpp index 84e768a7c1..980c4f8160 100644 --- a/pcbnew/toolbars_footprint_viewer.cpp +++ b/pcbnew/toolbars_footprint_viewer.cpp @@ -69,15 +69,8 @@ std::optional FOOTPRINT_VIEWER_FRAME::DefaultTopMainToolb .AppendControl( m_tbGridSelectName ); config.AppendSeparator() - .AppendControl( m_tbZoomSelectName ); - - // Option to run Zoom automatique on footprint selection change - /* TODO (ISM): Convert to action - m_tbTopMain->AddTool( ID_FPVIEWER_AUTOZOOM_TOOL, wxEmptyString, - KiScaledBitmap( BITMAPS::zoom_auto_fit_in_page, this ), - _( "Automatic Zoom on footprint change" ), - wxITEM_CHECK ); -*/ + .AppendControl( m_tbZoomSelectName ) + .AppendAction( PCB_ACTIONS::fpAutoZoom); // clang-format on return config; diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 3abed6c451..9c95ab6ae0 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -1508,6 +1508,14 @@ TOOL_ACTION PCB_ACTIONS::zoneDisplayToggle( TOOL_ACTION_ARGS() .Icon( BITMAPS::show_zone ) ); +TOOL_ACTION PCB_ACTIONS::fpAutoZoom( TOOL_ACTION_ARGS() + .Name( "pcbnew.Control.fpAutoZoom" ) + .Scope( AS_GLOBAL ) + .FriendlyName( _( "Automatic zoom" ) ) + .Tooltip( _( "Automatic Zoom on footprint change" ) ) + .Icon( BITMAPS::zoom_auto_fit_in_page ) + .ToolbarState( TOOLBAR_STATE::TOGGLE ) ); + // Layer control // Translate aLayer to the action that switches to it diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 6766130364..c177edaa51 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -345,6 +345,7 @@ public: static TOOL_ACTION zoneDisplayTriangulated; static TOOL_ACTION zoneDisplayToggle; static TOOL_ACTION showPadNumbers; + static TOOL_ACTION fpAutoZoom; // Layer control static TOOL_ACTION layerTop; diff --git a/pcbnew/tools/pcb_editor_conditions.cpp b/pcbnew/tools/pcb_editor_conditions.cpp index a59c81e288..9306d29c21 100644 --- a/pcbnew/tools/pcb_editor_conditions.cpp +++ b/pcbnew/tools/pcb_editor_conditions.cpp @@ -136,6 +136,16 @@ SELECTION_CONDITION PCB_EDITOR_CONDITIONS::Get45degMode() } +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::FootprintViewerAutoZoom() +{ + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::footprintViewerAutoZoom, _1, drwFrame ); +} + + bool PCB_EDITOR_CONDITIONS::hasItemsFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { BOARD* board = aFrame->GetBoard(); @@ -186,6 +196,7 @@ bool PCB_EDITOR_CONDITIONS::zoneDisplayModeFunc( const SELECTION& aSelection, PC return aFrame->GetDisplayOptions().m_ZoneDisplayMode == aMode; } + bool PCB_EDITOR_CONDITIONS::get45degModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); @@ -195,3 +206,9 @@ bool PCB_EDITOR_CONDITIONS::get45degModeFunc( const SELECTION& aSelection, PCB_B else return mgr.GetAppSettings( "fpedit" )->m_Use45Limit; } + + +bool PCB_EDITOR_CONDITIONS::footprintViewerAutoZoom( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return static_cast( aFrame->config() )->m_FootprintViewerAutoZoomOnSelect; +} diff --git a/pcbnew/tools/pcb_editor_conditions.h b/pcbnew/tools/pcb_editor_conditions.h index cc63d17215..6649dee3ef 100644 --- a/pcbnew/tools/pcb_editor_conditions.h +++ b/pcbnew/tools/pcb_editor_conditions.h @@ -109,6 +109,13 @@ public: */ SELECTION_CONDITION Get45degMode(); + /** + * Create a functor that tests if the footprint viewer should auto zoom on new footprints. + * + * @return Functor returning true if auto zoom is enabled. + */ + SELECTION_CONDITION FootprintViewerAutoZoom(); + protected: ///< Helper function used by HasItems() static bool hasItemsFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); @@ -137,6 +144,9 @@ protected: ///< Helper function used by Line45degMode() static bool get45degModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); + + /// Helper function used by FootprintViewerAutoZoom() + static bool footprintViewerAutoZoom( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); }; #endif /* PCB_EDITOR_CONDITIONS_H_ */ diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index c52cc859f9..db66601f53 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -404,6 +404,18 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) } +int PCB_VIEWER_TOOLS::FootprintAutoZoom( const TOOL_EVENT& aEvent ) +{ + PCB_VIEWERS_SETTINGS_BASE* cfg = dynamic_cast( frame()->config() ); + + // Toggle the setting + if( cfg ) + cfg->m_FootprintViewerAutoZoomOnSelect = !cfg->m_FootprintViewerAutoZoomOnSelect; + + return 0; +} + + void PCB_VIEWER_TOOLS::setTransitions() { // clang-format off @@ -415,6 +427,8 @@ void PCB_VIEWER_TOOLS::setTransitions() Go( &PCB_VIEWER_TOOLS::GraphicOutlines, PCB_ACTIONS::graphicsOutlines.MakeEvent() ); Go( &PCB_VIEWER_TOOLS::TextOutlines, PCB_ACTIONS::textOutlines.MakeEvent() ); + Go( &PCB_VIEWER_TOOLS::FootprintAutoZoom, PCB_ACTIONS::fpAutoZoom.MakeEvent() ); + Go( &PCB_VIEWER_TOOLS::MeasureTool, ACTIONS::measureTool.MakeEvent() ); // clang-format on } diff --git a/pcbnew/tools/pcb_viewer_tools.h b/pcbnew/tools/pcb_viewer_tools.h index 8529134a03..37659497f3 100644 --- a/pcbnew/tools/pcb_viewer_tools.h +++ b/pcbnew/tools/pcb_viewer_tools.h @@ -61,6 +61,9 @@ public: int GraphicOutlines( const TOOL_EVENT& aEvent ); int TextOutlines( const TOOL_EVENT& aEvent ); + /// Automatically zoom to fit on footprints + int FootprintAutoZoom( const TOOL_EVENT& aEvent ); + /// Show the 3D viewer int Show3DViewer( const TOOL_EVENT& aEvent );