From 194ee9ef258e85195b200273112599cbc26fa65e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 16 Apr 2025 18:09:25 +0100 Subject: [PATCH] Move Use45Limit processing to VIEWER_TOOLS. (We need it for the ruler in footprint preview widgets.) Fixes https://gitlab.com/kicad/code/kicad/-/issues/20668 --- common/settings/cvpcb_settings.cpp | 3 +++ pcbnew/footprint_chooser_frame.cpp | 2 ++ pcbnew/pcbnew_settings.h | 1 + pcbnew/tools/drawing_tool.cpp | 21 --------------------- pcbnew/tools/pcb_editor_conditions.cpp | 4 +++- pcbnew/tools/pcb_viewer_tools.cpp | 23 ++++++++++++++++++++++- pcbnew/tools/pcb_viewer_tools.h | 1 + 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/common/settings/cvpcb_settings.cpp b/common/settings/cvpcb_settings.cpp index 15b51b5402..9c29520efc 100644 --- a/common/settings/cvpcb_settings.cpp +++ b/common/settings/cvpcb_settings.cpp @@ -54,6 +54,9 @@ CVPCB_SETTINGS::CVPCB_SETTINGS() : m_params.emplace_back( new PARAM( "footprint_viewer.autozoom", &m_FootprintViewerAutoZoomOnSelect, true ) ); + m_params.emplace_back( new PARAM( "footprint_viewer.use_45_limit", + &m_ViewersDisplay.m_Use45Limit, true ) ); + m_params.emplace_back( new PARAM( "footprint_viewer.show_pad_fill", &m_ViewersDisplay.m_DisplayPadFill, true ) ); diff --git a/pcbnew/footprint_chooser_frame.cpp b/pcbnew/footprint_chooser_frame.cpp index 6277863cfc..14f1c5665d 100644 --- a/pcbnew/footprint_chooser_frame.cpp +++ b/pcbnew/footprint_chooser_frame.cpp @@ -777,6 +777,8 @@ void FOOTPRINT_CHOOSER_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCH ) ) ); mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) ); + mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( cond.Get45degMode() ) ); + mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) ); mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) ); diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index 29d4325f89..3d1b1a6bee 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -110,6 +110,7 @@ class PCB_VIEWERS_SETTINGS_BASE : public APP_SETTINGS_BASE public: struct VIEWERS_DISPLAY_OPTIONS { + bool m_Use45Limit; bool m_DisplayGraphicsFill; bool m_DisplayTextFill; bool m_DisplayPadNumbers; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index aaea45953f..c4c9c1bb03 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -2113,25 +2113,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) } -int DRAWING_TOOL::ToggleHV45Mode( const TOOL_EVENT& toolEvent ) -{ -#define TOGGLE( a ) a = !a - - SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - - if( frame()->IsType( FRAME_PCB_EDITOR ) ) - TOGGLE( mgr.GetAppSettings( "pcbnew" )->m_Use45DegreeLimit ); - else - TOGGLE( mgr.GetAppSettings( "fpedit" )->m_Use45Limit ); - - UpdateStatusBar(); - - return 0; - -#undef TOGGLE -} - - /** * Update a #PCB_SHAPE from the current state of a #TWO_POINT_GEOMETRY_MANAGER. */ @@ -4169,8 +4150,6 @@ void DRAWING_TOOL::setTransitions() Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() ); Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() ); - Go( &DRAWING_TOOL::ToggleHV45Mode, PCB_ACTIONS::toggleHV45Mode.MakeEvent() ); - Go( &DRAWING_TOOL::PlaceTuningPattern, PCB_ACTIONS::tuneSingleTrack.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTuningPattern, PCB_ACTIONS::tuneDiffPair.MakeEvent() ); Go( &DRAWING_TOOL::PlaceTuningPattern, PCB_ACTIONS::tuneSkew.MakeEvent() ); diff --git a/pcbnew/tools/pcb_editor_conditions.cpp b/pcbnew/tools/pcb_editor_conditions.cpp index 9306d29c21..53f2d22aef 100644 --- a/pcbnew/tools/pcb_editor_conditions.cpp +++ b/pcbnew/tools/pcb_editor_conditions.cpp @@ -203,8 +203,10 @@ bool PCB_EDITOR_CONDITIONS::get45degModeFunc( const SELECTION& aSelection, PCB_B if( aFrame->IsType( FRAME_PCB_EDITOR ) ) return mgr.GetAppSettings( "pcbnew" )->m_Use45DegreeLimit; - else + else if( aFrame->IsType( FRAME_FOOTPRINT_EDITOR ) ) return mgr.GetAppSettings( "fpedit" )->m_Use45Limit; + else + return aFrame->GetViewerSettingsBase()->m_ViewersDisplay.m_Use45Limit; } diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index db66601f53..842ff1daa2 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -105,6 +105,23 @@ template void Flip( T& aValue ) } +int PCB_VIEWER_TOOLS::ToggleHV45Mode( const TOOL_EVENT& toolEvent ) +{ + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + + if( frame()->IsType( FRAME_PCB_EDITOR ) ) + Flip( mgr.GetAppSettings( "pcbnew" )->m_Use45DegreeLimit ); + else if( frame()->IsType( FRAME_FOOTPRINT_EDITOR ) ) + Flip( mgr.GetAppSettings( "fpedit" )->m_Use45Limit ); + else + Flip( frame()->GetViewerSettingsBase()->m_ViewersDisplay.m_Use45Limit ); + + frame()->UpdateStatusBar(); + + return 0; +} + + int PCB_VIEWER_TOOLS::ShowPadNumbers( const TOOL_EVENT& aEvent ) { PCB_VIEWERS_SETTINGS_BASE* cfg = frame()->GetViewerSettingsBase(); @@ -331,8 +348,10 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) if( frame()->IsType( FRAME_PCB_EDITOR ) ) force45Deg = mgr.GetAppSettings( "pcbnew" )->m_Use45DegreeLimit; - else + else if( frame()->IsType( FRAME_FOOTPRINT_EDITOR ) ) force45Deg = mgr.GetAppSettings( "fpedit" )->m_Use45Limit; + else + force45Deg = frame()->GetViewerSettingsBase()->m_ViewersDisplay.m_Use45Limit; twoPtMgr.SetAngleSnap( force45Deg ); twoPtMgr.SetEnd( cursorPos ); @@ -421,6 +440,8 @@ void PCB_VIEWER_TOOLS::setTransitions() // clang-format off Go( &PCB_VIEWER_TOOLS::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() ); + Go( &PCB_VIEWER_TOOLS::ToggleHV45Mode, PCB_ACTIONS::toggleHV45Mode.MakeEvent() ); + // Display modes Go( &PCB_VIEWER_TOOLS::ShowPadNumbers, PCB_ACTIONS::showPadNumbers.MakeEvent() ); Go( &PCB_VIEWER_TOOLS::PadDisplayMode, PCB_ACTIONS::padDisplayMode.MakeEvent() ); diff --git a/pcbnew/tools/pcb_viewer_tools.h b/pcbnew/tools/pcb_viewer_tools.h index 37659497f3..7f189d3820 100644 --- a/pcbnew/tools/pcb_viewer_tools.h +++ b/pcbnew/tools/pcb_viewer_tools.h @@ -54,6 +54,7 @@ public: ///< Launch a tool to measure between points. int MeasureTool( const TOOL_EVENT& aEvent ); + int ToggleHV45Mode( const TOOL_EVENT& aEvent ); // Display modes int ShowPadNumbers( const TOOL_EVENT& aEvent );