From 4c0fd6e791a99f4ea5153e28da0192b9d78fa9b3 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 5 May 2024 07:41:32 -0700 Subject: [PATCH] Re-initialize conversion settings on failure When the conversion fails, it may be the result of the settings values, so reset them to their original values afterward Fixes https://gitlab.com/kicad/code/kicad/-/issues/17886 --- pcbnew/tools/convert_tool.cpp | 18 ++++++++++++++---- pcbnew/tools/convert_tool.h | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pcbnew/tools/convert_tool.cpp b/pcbnew/tools/convert_tool.cpp index cea9e81684..693968965a 100644 --- a/pcbnew/tools/convert_tool.cpp +++ b/pcbnew/tools/convert_tool.cpp @@ -235,10 +235,7 @@ CONVERT_TOOL::CONVERT_TOOL() : m_menu( nullptr ), m_frame( nullptr ) { - m_userSettings.m_Strategy = CENTERLINE; - m_userSettings.m_Gap = 0; - m_userSettings.m_LineWidth = 0; - m_userSettings.m_DeleteOriginals = true; + initUserSettings(); } @@ -319,6 +316,15 @@ bool CONVERT_TOOL::Init() } +void CONVERT_TOOL::initUserSettings() +{ + m_userSettings.m_Strategy = CENTERLINE; + m_userSettings.m_Gap = 0; + m_userSettings.m_LineWidth = 0; + m_userSettings.m_DeleteOriginals = true; +} + + int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) { BOARD_DESIGN_SETTINGS& bds = m_frame->GetBoard()->GetDesignSettings(); @@ -400,6 +406,8 @@ int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) showCopyLineWidth = false; } + CONVERT_SETTINGS previousSettings = m_userSettings; + CONVERT_SETTINGS_DIALOG dlg( m_frame, &m_userSettings, showCopyLineWidth, true, true ); if( dlg.ShowModal() != wxID_OK ) @@ -429,6 +437,8 @@ int CONVERT_TOOL::CreatePolys( const TOOL_EVENT& aEvent ) msg = _( "Objects must form a closed shape" ); DisplayErrorMessage( m_frame, _( "Could not convert selection" ), msg ); + + m_userSettings = previousSettings; return 0; } diff --git a/pcbnew/tools/convert_tool.h b/pcbnew/tools/convert_tool.h index 1de29290c9..fd881e040e 100644 --- a/pcbnew/tools/convert_tool.h +++ b/pcbnew/tools/convert_tool.h @@ -96,6 +96,11 @@ private: SHAPE_POLY_SET makePolysFromClosedGraphics( const std::deque& aItems, CONVERT_STRATEGY aStrategy ); + /** + * Initialize the user settings for the tool. + */ + void initUserSettings(); + private: PCB_SELECTION_TOOL* m_selectionTool; CONDITIONAL_MENU* m_menu;