Prevent PCB Editor from opening multiple board_setup

ShowBoardSetup can be called multiple times from multiple locations,
resulting in duplicate board setup dialog boxes.  This is confusing and
should be prevented.  We use the established patter from the symbol
picker to ensure that only one copy of the dialog is ever opened at a
time

(cherry picked from commit 7695d510d6)
This commit is contained in:
Seth Hillbrand 2023-03-30 15:32:24 -07:00
parent 1e8055f504
commit 85038c2b46
3 changed files with 12 additions and 0 deletions

View File

@ -45,6 +45,8 @@
#include <wx/treebook.h>
std::mutex DIALOG_BOARD_SETUP::g_Mutex;
DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) :
PAGED_DIALOG( aFrame, _( "Board Setup" ), false,

View File

@ -21,6 +21,7 @@
#ifndef KICAD_DIALOG_BOARD_SETUP_H
#define KICAD_DIALOG_BOARD_SETUP_H
#include <mutex>
#include <widgets/paged_dialog.h>
#include "panel_setup_formatting.h"
@ -64,6 +65,9 @@ protected:
PANEL_SETUP_SEVERITIES* m_severities;
PANEL_TEXT_VARIABLES* m_textVars;
public:
static std::mutex g_Mutex; // Mutex to prevent multiple windows opening
private:
int m_currentPage; // the current page index
int m_physicalStackupPage; // the page index of the PANEL_SETUP_BOARD_STACKUP page

View File

@ -1138,6 +1138,12 @@ void PCB_EDIT_FRAME::ActivateGalCanvas()
void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
{
std::unique_lock<std::mutex> dialogLock( DIALOG_BOARD_SETUP::g_Mutex, std::try_to_lock );
// One DIALOG_BOARD_SETUP dialog at a time.
if( !dialogLock.owns_lock() )
return;
// Make sure everything's up-to-date
GetBoard()->BuildListOfNets();