From 6fd79929be7e874a542e9921a2f13badc044a94e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 10 Mar 2023 10:46:55 +0100 Subject: [PATCH] DIALOG_BOARD_REANNOTATE: fix some issues, and protect against bad settings. Fixes #14234 https://gitlab.com/kicad/code/kicad/issues/14234 --- pcbnew/dialogs/dialog_board_reannotate.cpp | 38 ++++++++----- .../dialogs/dialog_board_reannotate_base.cpp | 10 ++-- .../dialogs/dialog_board_reannotate_base.fbp | 54 +++++++++++++++++-- pcbnew/dialogs/dialog_board_reannotate_base.h | 2 +- 4 files changed, 81 insertions(+), 23 deletions(-) diff --git a/pcbnew/dialogs/dialog_board_reannotate.cpp b/pcbnew/dialogs/dialog_board_reannotate.cpp index 5d94e3e807..9cc6949a79 100644 --- a/pcbnew/dialogs/dialog_board_reannotate.cpp +++ b/pcbnew/dialogs/dialog_board_reannotate.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Brian Piccioni brian@documenteddesigns.com - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * @author Brian Piccioni * * This program is free software; you can redistribute it and/or @@ -105,6 +105,16 @@ DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE( PCB_EDIT_FRAME* aParentFrame ) m_Config = Kiface().KifaceSettings(); InitValues(); + // Init bitmaps associated to some wxRadioButton + reannotate_down_right_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_right_down ) ); + reannotate_right_down_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_left_down ) ); + reannotate_down_left_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_right_up ) ); + reannotate_left_down_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_left_up ) ); + reannotate_up_right_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_down_left ) ); + reannotate_right_up_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_up_left ) ); + reannotate_up_left_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_down_right ) ); + reannotate_left_up_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_up_right ) ); + m_FrontRefDesStart->SetValidator( wxTextValidator( wxFILTER_DIGITS ) ); m_BackRefDesStart->SetValidator( wxTextValidator( wxFILTER_DIGITS ) ); @@ -125,29 +135,27 @@ DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE( PCB_EDIT_FRAME* aParentFrame ) m_GridChoice->Set( gridslist ); m_GridChoice->SetSelection( m_gridIndex ); + // Ensure m_sortCode is a valid value (0 .. m_sortButtons.size()-1) + m_sortCode = std::max( 0, m_sortCode ); + m_sortCode = std::min( m_sortCode, (int)m_sortButtons.size()-1 ); + for( wxRadioButton* button : m_sortButtons ) button->SetValue( false ); - m_sortButtons[m_sortCode]->SetValue( true ); - m_selection = m_frame->GetToolManager()->GetTool()->GetSelection(); if( !m_selection.Empty() ) m_annotationScope = AnnotateSelected; + // Ensure m_annotationScope is a valid value (0 .. m_scopeRadioButtons.size()-1) + m_annotationScope = std::max( 0, m_annotationScope ); + m_annotationScope = std::min( m_annotationScope, (int)m_scopeRadioButtons.size()-1 ); + for( wxRadioButton* button : m_scopeRadioButtons ) button->SetValue( false ); - m_scopeRadioButtons[m_annotationScope]->SetValue( true ); - - reannotate_down_right_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_right_down ) ); - reannotate_right_down_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_left_down ) ); - reannotate_down_left_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_right_up ) ); - reannotate_left_down_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_left_up ) ); - reannotate_up_right_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_down_left ) ); - reannotate_right_up_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_up_left ) ); - reannotate_up_left_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_down_right ) ); - reannotate_left_up_bitmap->SetBitmap( KiBitmap( BITMAPS::reannotate_up_right ) ); + m_scopeRadioButtons.at( m_annotationScope )->SetValue( true ); + m_sortButtons.at( m_sortCode )->SetValue( true ); m_ExcludeList->SetToolTip( m_ExcludeListText->GetToolTipText() ); m_GridChoice->SetToolTip( m_SortGridText->GetToolTipText() ); @@ -419,6 +427,10 @@ void DIALOG_BOARD_REANNOTATE::GetParameters() m_annotationScope++; } + // Ensure m_annotationScope value is valid + if( m_annotationScope >= (int)m_scopeRadioButtons.size() ) + m_annotationScope = AnnotateAll; + m_MessageWindow->SetLazyUpdate( true ); } diff --git a/pcbnew/dialogs/dialog_board_reannotate_base.cpp b/pcbnew/dialogs/dialog_board_reannotate_base.cpp index 91cb682080..c5e94eafc8 100644 --- a/pcbnew/dialogs/dialog_board_reannotate_base.cpp +++ b/pcbnew/dialogs/dialog_board_reannotate_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) +// C++ code generated with wxFormBuilder (version 3.10.1-282-g1fa54006) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -42,7 +42,7 @@ DIALOG_BOARD_REANNOTATE_BASE::DIALOG_BOARD_REANNOTATE_BASE( wxWindow* parent, wx fgSizerButtons->SetFlexibleDirection( wxBOTH ); fgSizerButtons->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - m_Down_Right = new wxRadioButton( m_StandardOptions, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_Down_Right = new wxRadioButton( m_StandardOptions, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); m_Down_Right->SetValue( true ); fgSizerButtons->Add( m_Down_Right, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); @@ -99,7 +99,7 @@ DIALOG_BOARD_REANNOTATE_BASE::DIALOG_BOARD_REANNOTATE_BASE( wxWindow* parent, wx fgSizerButtons->Add( m_Right_Up, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); reannotate_right_up_bitmap = new wxStaticBitmap( m_StandardOptions, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 48,48 ), 0 ); - reannotate_right_up_bitmap->SetToolTip( _("Vertically: top right to bottom left") ); + reannotate_right_up_bitmap->SetToolTip( _("Vertically: bottom left to top right") ); fgSizerButtons->Add( reannotate_right_up_bitmap, 0, wxALL, 5 ); @@ -110,7 +110,7 @@ DIALOG_BOARD_REANNOTATE_BASE::DIALOG_BOARD_REANNOTATE_BASE( wxWindow* parent, wx fgSizerButtons->Add( m_Up_Left, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); reannotate_up_left_bitmap = new wxStaticBitmap( m_StandardOptions, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 48,48 ), 0 ); - reannotate_up_left_bitmap->SetToolTip( _("Vertically: bottom left to top right") ); + reannotate_up_left_bitmap->SetToolTip( _("Vertically: top right to bottom left") ); fgSizerButtons->Add( reannotate_up_left_bitmap, 0, wxALL, 5 ); @@ -177,7 +177,7 @@ DIALOG_BOARD_REANNOTATE_BASE::DIALOG_BOARD_REANNOTATE_BASE( wxWindow* parent, wx fgSizer6111->SetFlexibleDirection( wxVERTICAL ); fgSizer6111->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); - m_AnnotateAll = new wxRadioButton( m_StandardOptions, wxID_ANY, _("All"), wxDefaultPosition, wxDefaultSize, 0 ); + m_AnnotateAll = new wxRadioButton( m_StandardOptions, wxID_ANY, _("All"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); m_AnnotateAll->SetValue( true ); fgSizer6111->Add( m_AnnotateAll, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 ); diff --git a/pcbnew/dialogs/dialog_board_reannotate_base.fbp b/pcbnew/dialogs/dialog_board_reannotate_base.fbp index d61881ddc3..687d1386a6 100644 --- a/pcbnew/dialogs/dialog_board_reannotate_base.fbp +++ b/pcbnew/dialogs/dialog_board_reannotate_base.fbp @@ -36,6 +36,7 @@ 1 + 0 1 impl_virtual @@ -97,6 +98,7 @@ Dock 0 Left + 0 1 1 @@ -153,6 +155,7 @@ Dock 0 Left + 0 1 1 @@ -213,6 +216,7 @@ Dock 0 Left + 0 1 1 @@ -274,6 +278,7 @@ Dock 0 Left + 0 1 1 @@ -348,6 +353,7 @@ Dock 0 Left + 0 1 1 @@ -373,7 +379,7 @@ Resizable 1 - + wxRB_GROUP ; ; forward_declare 0 @@ -413,6 +419,7 @@ Dock 0 Left + 0 1 1 @@ -480,6 +487,7 @@ Dock 0 Left + 0 1 1 @@ -545,6 +553,7 @@ Dock 0 Left + 0 1 1 @@ -612,6 +621,7 @@ Dock 0 Left + 0 1 1 @@ -677,6 +687,7 @@ Dock 0 Left + 0 1 1 @@ -744,6 +755,7 @@ Dock 0 Left + 0 1 1 @@ -809,6 +821,7 @@ Dock 0 Left + 0 1 1 @@ -866,6 +879,7 @@ Dock 0 Left + 0 1 1 @@ -931,6 +945,7 @@ Dock 0 Left + 0 1 1 @@ -998,6 +1013,7 @@ Dock 0 Left + 0 1 1 @@ -1063,6 +1079,7 @@ Dock 0 Left + 0 1 1 @@ -1089,7 +1106,7 @@ 48,48 ; ; forward_declare 0 - Vertically: top right to bottom left + Vertically: bottom left to top right @@ -1130,6 +1147,7 @@ Dock 0 Left + 0 1 1 @@ -1195,6 +1213,7 @@ Dock 0 Left + 0 1 1 @@ -1221,7 +1240,7 @@ 48,48 ; ; forward_declare 0 - Vertically: bottom left to top right + Vertically: top right to bottom left @@ -1262,6 +1281,7 @@ Dock 0 Left + 0 1 1 @@ -1327,6 +1347,7 @@ Dock 0 Left + 0 1 1 @@ -1402,6 +1423,7 @@ Dock 0 Left + 0 1 1 @@ -1464,6 +1486,7 @@ Dock 0 Left + 0 1 1 @@ -1527,6 +1550,7 @@ Dock 0 Left + 0 1 1 @@ -1589,6 +1613,7 @@ Dock 0 Left + 0 1 1 @@ -1664,6 +1689,7 @@ Dock 0 Left + 0 1 1 @@ -1725,6 +1751,7 @@ Dock 0 Left + 0 1 1 @@ -1799,6 +1826,7 @@ Dock 0 Left + 0 1 1 @@ -1824,7 +1852,7 @@ Resizable 1 - + wxRB_GROUP ; ; forward_declare 0 @@ -1863,6 +1891,7 @@ Dock 0 Left + 0 1 1 @@ -1927,6 +1956,7 @@ Dock 0 Left + 0 1 1 @@ -1991,6 +2021,7 @@ Dock 0 Left + 0 1 1 @@ -2060,6 +2091,7 @@ Dock 0 Left + 0 1 1 @@ -2138,6 +2170,7 @@ Dock 0 Left + 0 1 1 @@ -2202,6 +2235,7 @@ Dock 0 Left + 0 1 1 @@ -2269,6 +2303,7 @@ Dock 0 Left + 0 1 1 @@ -2333,6 +2368,7 @@ Dock 0 Left + 0 1 1 @@ -2401,6 +2437,7 @@ Dock 0 Left + 0 1 1 @@ -2468,6 +2505,7 @@ Dock 0 Left + 0 1 1 @@ -2534,6 +2572,7 @@ Dock 0 Left + 0 1 1 @@ -2598,6 +2637,7 @@ Dock 0 Left + 0 1 1 @@ -2666,6 +2706,7 @@ Dock 0 Left + 0 1 1 @@ -2730,6 +2771,7 @@ Dock 0 Left + 0 1 1 @@ -2799,6 +2841,7 @@ Dock 0 Left + 0 1 1 @@ -2865,6 +2908,7 @@ Dock 0 Left + 0 1 1 @@ -2929,6 +2973,7 @@ Dock 0 Left + 0 1 1 @@ -3009,6 +3054,7 @@ Dock 0 Left + 0 1 1 diff --git a/pcbnew/dialogs/dialog_board_reannotate_base.h b/pcbnew/dialogs/dialog_board_reannotate_base.h index feaa48c361..1da20f25fd 100644 --- a/pcbnew/dialogs/dialog_board_reannotate_base.h +++ b/pcbnew/dialogs/dialog_board_reannotate_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) +// C++ code generated with wxFormBuilder (version 3.10.1-282-g1fa54006) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE!