From 85805b95ba69dcd7b729c65ead0b65b4560cd810 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 19 Feb 2022 19:29:27 +0000 Subject: [PATCH] Cancel or commit pad edit mode when switching footprints. Fixes https://gitlab.com/kicad/code/kicad/issues/10209 --- pcbnew/footprint_libraries_utils.cpp | 12 ++++++++---- pcbnew/tools/pad_tool.cpp | 15 +++++++++++++-- pcbnew/tools/pad_tool.h | 2 ++ pcbnew/tools/pcb_grid_helper.cpp | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 3325b383da..f08023374f 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -48,6 +48,7 @@ #include #include #include "footprint_viewer_frame.h" +#include "tools/pad_tool.h" #include #include @@ -784,6 +785,11 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprint( FOOTPRINT* aFootprint ) if( !aFootprint ) // Happen if no footprint loaded return false; + PAD_TOOL* padTool = m_toolManager->GetTool(); + + if( padTool->InPadEditMode() ) + m_toolManager->RunAction( PCB_ACTIONS::recombinePad, true ); + wxString libraryName = aFootprint->GetFPID().GetLibNickname(); wxString footprintName = aFootprint->GetFPID().GetLibItemName(); bool nameChanged = m_footprintNameWhenLoaded != footprintName; @@ -879,7 +885,6 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) return false; } - TOOL_MANAGER* toolMgr = pcbframe->GetToolManager(); BOARD* mainpcb = pcbframe->GetBoard(); FOOTPRINT* sourceFootprint = nullptr; FOOTPRINT* editorFootprint = GetBoard()->GetFirstFootprint(); @@ -906,14 +911,13 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) return false; } - if( aAddNew && toolMgr->GetTool()->PlacingFootprint() ) + if( aAddNew && m_toolManager->GetTool()->PlacingFootprint() ) { DisplayError( this, _( "Previous footprint placement still in progress." ) ); return false; } m_toolManager->RunAction( PCB_ACTIONS::selectionClear, true ); - toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); BOARD_COMMIT commit( pcbframe ); // Create a copy for the board, first using Clone() to keep existing Uuids, and then either @@ -960,7 +964,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) commit.Push( wxT( "Insert footprint" ) ); pcbframe->Raise(); - toolMgr->RunAction( PCB_ACTIONS::placeFootprint, true, newFootprint ); + m_toolManager->RunAction( PCB_ACTIONS::placeFootprint, true, newFootprint ); } newFootprint->ClearFlags(); diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 184626ee15..b0f7439e47 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -59,6 +59,17 @@ void PAD_TOOL::Reset( RESET_REASON aReason ) if( aReason == MODEL_RELOAD ) m_lastPadNumber = wxT( "1" ); + if( m_editPad != niluuid ) + { + PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions(); + bool highContrast = ( opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ); + + if( m_wasHighContrast != highContrast ) + m_toolMgr->RunAction( ACTIONS::highContrastMode, true ); + + frame()->GetInfoBar()->Dismiss(); + } + m_editPad = niluuid; } @@ -576,7 +587,7 @@ int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent ) frame()->SetActiveLayer( layer ); if( !m_wasHighContrast ) - m_toolMgr->RunAction( ACTIONS::highContrastMode, false ); + m_toolMgr->RunAction( ACTIONS::highContrastMode, true ); if( PCB_ACTIONS::explodePad.GetHotKey() == PCB_ACTIONS::recombinePad.GetHotKey() ) { @@ -600,7 +611,7 @@ int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent ) bool highContrast = ( opts.m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ); if( m_wasHighContrast != highContrast ) - m_toolMgr->RunAction( ACTIONS::highContrastMode, false ); + m_toolMgr->RunAction( ACTIONS::highContrastMode, true ); infoBar->Dismiss(); } diff --git a/pcbnew/tools/pad_tool.h b/pcbnew/tools/pad_tool.h index dc4614d9e8..71a41a11be 100644 --- a/pcbnew/tools/pad_tool.h +++ b/pcbnew/tools/pad_tool.h @@ -59,6 +59,8 @@ public: */ int EditPad( const TOOL_EVENT& aEvent ); + bool InPadEditMode() { return m_editPad != niluuid; } + wxString GetLastPadNumber() const { return m_lastPadNumber; } void SetLastPadNumber( const wxString& aPadNumber ) { m_lastPadNumber = aPadNumber; } diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp index 113bac194c..90f29d663a 100644 --- a/pcbnew/tools/pcb_grid_helper.cpp +++ b/pcbnew/tools/pcb_grid_helper.cpp @@ -401,7 +401,7 @@ void PCB_GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos if( aFrom ) return; - const std::shared_ptr eshape = aPad->GetEffectiveShape( aPad->GetLayer() ); + const std::shared_ptr eshape = aPad->GetEffectiveShape(); // PTH reduced to only a hole do not return a valid pad shape list if( eshape->Type() != SH_COMPOUND )