From 0211d07060f8d84d5ca31a99e29946bcee05137e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 18 Apr 2022 10:32:36 +0200 Subject: [PATCH] Footprint viewers: fix regression: re-add automatic zoom option when loading a new footprint Fixes #11402 https://gitlab.com/kicad/code/kicad/issues/11402 --- cvpcb/cvpcb_id.h | 3 ++- cvpcb/cvpcb_settings.cpp | 5 ++++- cvpcb/cvpcb_settings.h | 3 ++- cvpcb/display_footprints_frame.cpp | 27 +++++++++++++++++++++++++-- pcbnew/footprint_viewer_frame.cpp | 16 ++++++++++++++-- pcbnew/pcbnew_id.h | 1 + pcbnew/pcbnew_settings.cpp | 6 +++++- pcbnew/pcbnew_settings.h | 3 ++- pcbnew/toolbars_footprint_viewer.cpp | 8 ++++++++ 9 files changed, 63 insertions(+), 9 deletions(-) diff --git a/cvpcb/cvpcb_id.h b/cvpcb/cvpcb_id.h index 7203766425..e2c34cb76a 100644 --- a/cvpcb/cvpcb_id.h +++ b/cvpcb/cvpcb_id.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2014 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2022 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 @@ -43,4 +43,5 @@ enum id_cvpcb_frm ID_CVPCB_FOOTPRINT_LIST, ID_CVPCB_LIBRARY_LIST, ID_CVPCB_FILTER_TEXT_EDIT, + ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL }; diff --git a/cvpcb/cvpcb_settings.cpp b/cvpcb/cvpcb_settings.cpp index b23e3d94fb..bd13f98ccb 100644 --- a/cvpcb/cvpcb_settings.cpp +++ b/cvpcb/cvpcb_settings.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * -* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. +* Copyright (C) 2022 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 @@ -32,6 +32,7 @@ const int cvpcbSchemaVersion = 0; CVPCB_SETTINGS::CVPCB_SETTINGS() : APP_SETTINGS_BASE( "cvpcb", cvpcbSchemaVersion ), m_FootprintViewerZoom( 1.0 ), + m_FootprintViewerAutoZoomOnSelect( true ), m_FilterFootprint( 0 ), m_LibrariesWidth( 0 ), m_FootprintsWidth( 0 ) @@ -50,6 +51,8 @@ CVPCB_SETTINGS::CVPCB_SETTINGS() : addParamsForWindow( &m_FootprintViewer, "footprint_viewer" ); m_params.emplace_back( new PARAM( "footprint_viewer.zoom", &m_FootprintViewerZoom, 1.0 ) ); + m_params.emplace_back( new PARAM( "footprint_viewer.autozoom", + &m_FootprintViewerAutoZoomOnSelect, true ) ); } diff --git a/cvpcb/cvpcb_settings.h b/cvpcb/cvpcb_settings.h index 6898f70f3e..a3914f3995 100644 --- a/cvpcb/cvpcb_settings.h +++ b/cvpcb/cvpcb_settings.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * -* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. +* Copyright (C) 2022 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 @@ -44,6 +44,7 @@ public: MAGNETIC_SETTINGS m_FootprintViewerMagneticSettings; double m_FootprintViewerZoom; + bool m_FootprintViewerAutoZoomOnSelect; int m_FilterFootprint; int m_LibrariesWidth; diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index b44ed12a4e..f7d141b22c 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 2007-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2007-2022 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 @@ -56,6 +56,7 @@ #include #include #include +#include BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME ) @@ -145,8 +146,17 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa CVPCB_SETTINGS* cfg = dynamic_cast( config() ); if( cfg ) + { GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom ); + wxAuiToolBarItem* toolOpt = m_mainToolBar->FindTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL ); + + if( cfg->m_FootprintViewerAutoZoomOnSelect ) + toolOpt->SetState( wxAUI_BUTTON_STATE_CHECKED ); + else + toolOpt->SetState( 0 ); + } + updateView(); Show( true ); @@ -306,6 +316,14 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar() UpdateZoomSelectBox(); m_mainToolBar->AddControl( m_zoomSelectBox ); + // Option to run Zoom automatique on footprint selection changge + m_mainToolBar->AddTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL, wxEmptyString, + KiScaledBitmap( BITMAPS::zoom_auto_fit_in_page, this ), + _( "Automatic Zoom on footprint change" ), + wxITEM_CHECK ); + + m_mainToolBar->AddScaledSeparator( this ); + m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT ); m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT ); @@ -349,6 +367,9 @@ void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) cfg->m_FootprintViewerDisplayOptions = GetDisplayOptions(); cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); + + wxAuiToolBarItem* toolOpt = m_mainToolBar->FindTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL ); + cfg->m_FootprintViewerAutoZoomOnSelect = ( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ); } @@ -495,7 +516,9 @@ void DISPLAY_FOOTPRINTS_FRAME::updateView() m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); - if( m_zoomSelectBox->GetSelection() == 0 ) + wxAuiToolBarItem* toolOpt = m_mainToolBar->FindTool( ID_CVPCB_FPVIEWER_AUTOZOOM_TOOL ); + + if( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ) m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); else m_toolManager->RunAction( ACTIONS::centerContents, true ); diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 2922978723..e74707918e 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -275,11 +275,18 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent GetCanvas()->GetGAL()->SetAxesEnabled( true ); ActivateGalCanvas(); - // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.) + // Restore last zoom and auto zoom option. (If auto-zooming we'll adjust when we load the footprint.) PCBNEW_SETTINGS* cfg = GetPcbNewSettings(); wxASSERT( cfg ); GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom ); + wxAuiToolBarItem* toolOpt = m_mainToolBar->FindTool( ID_FPVIEWER_AUTOZOOM_TOOL ); + + if( cfg->m_FootprintViewerAutoZoomOnSelect ) + toolOpt->SetState( wxAUI_BUTTON_STATE_CHECKED ); + else + toolOpt->SetState( 0 ); + updateView(); setupUnits( config() ); @@ -802,6 +809,9 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) if( GetCanvas() && GetCanvas()->GetView() ) cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); + + wxAuiToolBarItem* toolOpt = m_mainToolBar->FindTool( ID_FPVIEWER_AUTOZOOM_TOOL ); + cfg->m_FootprintViewerAutoZoomOnSelect = ( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ); } @@ -1060,7 +1070,9 @@ void FOOTPRINT_VIEWER_FRAME::updateView() m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); - if( m_zoomSelectBox->GetSelection() == 0 ) + wxAuiToolBarItem* toolOpt = m_mainToolBar->FindTool( ID_FPVIEWER_AUTOZOOM_TOOL ); + + if( toolOpt->GetState() & wxAUI_BUTTON_STATE_CHECKED ) m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); else m_toolManager->RunAction( ACTIONS::centerContents, true ); diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 9e92807a16..83d3d7d843 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -103,6 +103,7 @@ 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 4a23970595..30b08fbf1d 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -75,7 +75,8 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_AutoRefillZones( false ), m_AllowFreePads( false ), m_PnsSettings( nullptr ), - m_FootprintViewerZoom( 1.0 ) + m_FootprintViewerZoom( 1.0 ), + m_FootprintViewerAutoZoomOnSelect( true ) { m_MagneticItems.pads = MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL; m_MagneticItems.tracks = MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL; @@ -521,6 +522,9 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_params.emplace_back( new PARAM( "footprint_viewer.zoom", &m_FootprintViewerZoom, 1.0 ) ); + m_params.emplace_back( new PARAM( "footprint_viewer.autozoom", + &m_FootprintViewerAutoZoomOnSelect, true ) ); + addParamsForWindow( &m_FootprintWizard, "footprint_wizard" ); m_params.emplace_back( new PARAM( "system.last_footprint_lib_dir", diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index 2411c0deb5..e4575a7182 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -347,7 +347,8 @@ public: std::unique_ptr m_PnsSettings; - double m_FootprintViewerZoom; ///< The last zoom level used (0 for auto) + double m_FootprintViewerZoom; ///< The last zoom level used (0 for auto) + bool m_FootprintViewerAutoZoomOnSelect; ///< true to use automatic zoom on fp selection wxString m_lastFootprintLibDir; diff --git a/pcbnew/toolbars_footprint_viewer.cpp b/pcbnew/toolbars_footprint_viewer.cpp index e08d89ecd7..f0eb4adb9b 100644 --- a/pcbnew/toolbars_footprint_viewer.cpp +++ b/pcbnew/toolbars_footprint_viewer.cpp @@ -101,6 +101,14 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar() UpdateZoomSelectBox(); m_mainToolBar->AddControl( m_zoomSelectBox ); + // Option to run Zoom automatique on footprint selection changge + m_mainToolBar->AddTool( ID_FPVIEWER_AUTOZOOM_TOOL, wxEmptyString, + KiScaledBitmap( BITMAPS::zoom_auto_fit_in_page, this ), + _( "Automatic Zoom on footprint change" ), + wxITEM_CHECK ); + + m_mainToolBar->AddScaledSeparator( this ); + // after adding the buttons to the toolbar, must call Realize() to // reflect the changes m_mainToolBar->KiRealize();