From 9fdadcbcf57454c607efdce58a827a01ba07888c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 1 Sep 2020 17:45:20 +0200 Subject: [PATCH] EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ): fix incorrect behavior. windowClosing() calls Destroy() when the wxCloseEvent has no veto. This is fine for usual EDA_BASE_FRAME frames, but not for frames shown in modal mode. In modal mode, windowClosing() should not call Destroy(), because the calling frame expects the instance not deleted after closing. (the caller has to call Destroy() only once the frame can be actually deleted) --- common/eda_base_frame.cpp | 7 +++- include/eda_base_frame.h | 8 ++++ include/kiway_player.h | 2 +- pcbnew/footprint_editor_utils.cpp | 68 +++++++++++++++---------------- pcbnew/footprint_wizard_frame.cpp | 5 +-- pcbnew/footprint_wizard_frame.h | 2 +- 6 files changed, 50 insertions(+), 42 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index fa510356bc..5f5d52cd5b 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -153,7 +153,7 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ) } - if( event.GetId() == wxEVT_QUERY_END_SESSION + if( event.GetId() == wxEVT_QUERY_END_SESSION || event.GetId() == wxEVT_END_SESSION ) { // End session means the OS is going to terminate us @@ -170,7 +170,10 @@ void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ) doCloseWindow(); - Destroy(); + // Destroy (safe delete frame) this frame only in non modal mode. + // In modal mode, the caller will call Destroy(). + if( !IsModal() ) + Destroy(); } else { diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 8d23b162b3..9b91a9f605 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -125,6 +125,14 @@ class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER wxWindow* findQuasiModalDialog(); + /** + * Return true if the frame is shown in our modal mode + * and false if the frame is shown as an usual frame + * In modal mode, the caller that created the frame is responsible to Destroy() + * this frame after closing + */ + virtual bool IsModal() const { return false; } + protected: FRAME_T m_Ident; // Id Type (pcb, schematic, library..) wxPoint m_FramePos; diff --git a/include/kiway_player.h b/include/kiway_player.h index 761f281156..2b2a68e3cf 100644 --- a/include/kiway_player.h +++ b/include/kiway_player.h @@ -173,7 +173,7 @@ public: */ bool Destroy() override; - bool IsModal() const { return m_modal; } + bool IsModal() const override { return m_modal; } void SetModal( bool aIsModal ) { m_modal = aIsModal; } /** diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index f47a2f645a..092550977c 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -190,48 +190,48 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) } } - auto wizard = (FOOTPRINT_WIZARD_FRAME*) Kiway().Player( FRAME_FOOTPRINT_WIZARD, true, - this ); + FOOTPRINT_WIZARD_FRAME* wizard = + (FOOTPRINT_WIZARD_FRAME*) Kiway().Player( FRAME_FOOTPRINT_WIZARD, true, this ); if( wizard->ShowModal( NULL, this ) ) { // Creates the new footprint from python script wizard MODULE* module = wizard->GetBuiltFootprint(); - if( module == NULL ) // i.e. if create module command aborted - break; - - Clear_Pcb( false ); - - GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); - // Add the new object to board - AddModuleToBoard( module ); - - // Initialize data relative to nets and netclasses (for a new - // module the defaults are used) - // This is mandatory to handle and draw pads - GetBoard()->BuildListOfNets(); - module->SetPosition( wxPoint( 0, 0 ) ); - module->ClearFlags(); - - Zoom_Automatique( false ); - GetScreen()->SetModify(); - - // If selected from the library tree then go ahead and save it there - if( !selected.GetLibNickname().empty() ) + if( module ) // i.e. if create module command is OK { - LIB_ID fpid = module->GetFPID(); - fpid.SetLibNickname( selected.GetLibNickname() ); - module->SetFPID( fpid ); - SaveFootprint( module ); - GetScreen()->ClrModify(); + Clear_Pcb( false ); + + GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); + // Add the new object to board + AddModuleToBoard( module ); + + // Initialize data relative to nets and netclasses (for a new + // module the defaults are used) + // This is mandatory to handle and draw pads + GetBoard()->BuildListOfNets(); + module->SetPosition( wxPoint( 0, 0 ) ); + module->ClearFlags(); + + Zoom_Automatique( false ); + GetScreen()->SetModify(); + + // If selected from the library tree then go ahead and save it there + if( !selected.GetLibNickname().empty() ) + { + LIB_ID fpid = module->GetFPID(); + fpid.SetLibNickname( selected.GetLibNickname() ); + module->SetFPID( fpid ); + SaveFootprint( module ); + GetScreen()->ClrModify(); + } + + updateView(); + GetCanvas()->Refresh(); + Update3DView( true ); + + SyncLibraryTree( false ); } - - updateView(); - GetCanvas()->Refresh(); - Update3DView( true ); - - SyncLibraryTree( false ); } wizard->Destroy(); diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index dd7369532f..8928a151fc 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -255,10 +255,7 @@ void FOOTPRINT_WIZARD_FRAME::doCloseWindow() if( !IsDismissed() ) DismissModal( false ); } - else - { - Destroy(); - } + // else do nothing } diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 7363327077..003b10e829 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -3,7 +3,7 @@ * * Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License