Small improvements to lifecycle safety.

Fixes https://gitlab.com/kicad/code/kicad/issues/14521

Fixes https://gitlab.com/kicad/code/kicad/issues/14315
This commit is contained in:
Jeff Young 2023-04-16 18:45:17 +01:00
parent 6fb8916798
commit cc4a8dcc89
1 changed files with 16 additions and 29 deletions

View File

@ -27,6 +27,7 @@
#include <bitmaps.h> #include <bitmaps.h>
#include <confirm.h> #include <confirm.h>
#include <core/arraydim.h> #include <core/arraydim.h>
#include <core/kicad_algo.h>
#include <dialog_shim.h> #include <dialog_shim.h>
#include <eda_draw_frame.h> #include <eda_draw_frame.h>
#include <file_history.h> #include <file_history.h>
@ -733,21 +734,21 @@ void EDA_DRAW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
int aPadding ) int aPadding )
{ {
if( m_messagePanel ) if( m_messagePanel && !m_isClosing )
m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding ); m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
} }
void EDA_DRAW_FRAME::ClearMsgPanel() void EDA_DRAW_FRAME::ClearMsgPanel()
{ {
if( m_messagePanel ) if( m_messagePanel && !m_isClosing )
m_messagePanel->EraseMsgBox(); m_messagePanel->EraseMsgBox();
} }
void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList ) void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
{ {
if( m_messagePanel ) if( m_messagePanel && !m_isClosing )
{ {
m_messagePanel->EraseMsgBox(); m_messagePanel->EraseMsgBox();
@ -760,10 +761,9 @@ void EDA_DRAW_FRAME::SetMsgPanel( const std::vector<MSG_PANEL_ITEM>& aList )
void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, void EDA_DRAW_FRAME::SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower,
int aPadding ) int aPadding )
{ {
if( m_messagePanel ) if( m_messagePanel && !m_isClosing )
{ {
m_messagePanel->EraseMsgBox(); m_messagePanel->EraseMsgBox();
m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding ); m_messagePanel->AppendMessage( aTextUpper, aTextLower, aPadding );
} }
} }
@ -834,26 +834,15 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas
// Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some // Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
// have a fixed type, or do not have a option to set the canvas type (they inherit from // have a fixed type, or do not have a option to set the canvas type (they inherit from
// a parent frame) // a parent frame)
FRAME_T allowed_frames[] = static std::vector<FRAME_T> s_allowedFrames =
{ {
FRAME_SCH, FRAME_SCH_SYMBOL_EDITOR, FRAME_SCH, FRAME_SCH_SYMBOL_EDITOR,
FRAME_PCB_EDITOR, FRAME_FOOTPRINT_EDITOR, FRAME_PCB_EDITOR, FRAME_FOOTPRINT_EDITOR,
FRAME_GERBER, FRAME_GERBER,
FRAME_PL_EDITOR FRAME_PL_EDITOR
}; };
bool allow_save = false; if( !alg::contains( s_allowedFrames, m_ident ) )
for( unsigned ii = 0; ii < arrayDim( allowed_frames ); ii++ )
{
if( m_ident == allowed_frames[ii] )
{
allow_save = true;
break;
}
}
if( !allow_save )
return false; return false;
if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
@ -863,9 +852,7 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas
return false; return false;
} }
APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings(); if( APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings() )
if( cfg )
cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType ); cfg->m_Graphics.canvas_type = static_cast<int>( aCanvasType );
return false; return false;
@ -875,7 +862,7 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas
VECTOR2I EDA_DRAW_FRAME::GetNearestGridPosition( const VECTOR2I& aPosition ) const VECTOR2I EDA_DRAW_FRAME::GetNearestGridPosition( const VECTOR2I& aPosition ) const
{ {
const VECTOR2I& gridOrigin = GetGridOrigin(); const VECTOR2I& gridOrigin = GetGridOrigin();
VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize(); VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
double xOffset = fmod( gridOrigin.x, gridSize.x ); double xOffset = fmod( gridOrigin.x, gridSize.x );
int x = KiROUND( (aPosition.x - xOffset) / gridSize.x ); int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );
@ -889,7 +876,7 @@ VECTOR2I EDA_DRAW_FRAME::GetNearestGridPosition( const VECTOR2I& aPosition ) con
VECTOR2I EDA_DRAW_FRAME::GetNearestHalfGridPosition( const VECTOR2I& aPosition ) const VECTOR2I EDA_DRAW_FRAME::GetNearestHalfGridPosition( const VECTOR2I& aPosition ) const
{ {
const VECTOR2I& gridOrigin = GetGridOrigin(); const VECTOR2I& gridOrigin = GetGridOrigin();
VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0; VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize() / 2.0;
double xOffset = fmod( gridOrigin.x, gridSize.x ); double xOffset = fmod( gridOrigin.x, gridSize.x );
int x = KiROUND( (aPosition.x - xOffset) / gridSize.x ); int x = KiROUND( (aPosition.x - xOffset) / gridSize.x );