Nullptr safety for UI Conditions.

We don't really control when these are called, so best not to assume
we've finished initialization of the frame/screen/document/whatever.

Possible fix for KICAD-KY.
This commit is contained in:
Jeff Young 2023-06-12 12:38:50 +01:00
parent aa8a903940
commit b7f0aae006
8 changed files with 74 additions and 71 deletions

View File

@ -467,10 +467,10 @@ void EDA_BASE_FRAME::setupUIConditions()
{
// Setup the conditions to check a language menu item
auto isCurrentLang =
[] ( const SELECTION& aSel, int aLangIdentifier )
{
return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
};
[] ( const SELECTION& aSel, int aLangIdentifier )
{
return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
};
for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
{

View File

@ -489,10 +489,10 @@ void SCH_EDIT_FRAME::setupUIConditions()
};
auto searchPaneCond =
[this] ( const SELECTION& )
{
return m_auimgr.GetPane( SearchPaneName() ).IsShown();
};
[this] ( const SELECTION& )
{
return m_auimgr.GetPane( SearchPaneName() ).IsShown();
};
auto hierarchyNavigatorCond =
[ this ] ( const SELECTION& aSel )
@ -628,19 +628,22 @@ void SCH_EDIT_FRAME::setupUIConditions()
auto belowRootSheetCondition =
[this]( const SELECTION& aSel )
{
return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoUp();
SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
return navigateTool && navigateTool->CanGoUp();
};
auto navSchematicHasPreviousSheet =
[this]( const SELECTION& aSel )
{
return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoPrevious();
SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
return navigateTool && navigateTool->CanGoPrevious();
};
auto navSchematicHasNextSheet =
[this]( const SELECTION& aSel )
{
return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoNext();
SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
return navigateTool && navigateTool->CanGoNext();
};
mgr->SetConditions( EE_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );

View File

@ -389,8 +389,8 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
auto symbolModifiedCondition =
[this]( const SELECTION& sel )
{
return m_libMgr->IsSymbolModified( GetTargetLibId().GetLibItemName(),
GetTargetLibId().GetLibNickname() );
return m_libMgr && m_libMgr->IsSymbolModified( GetTargetLibId().GetLibItemName(),
GetTargetLibId().GetLibNickname() );
};
auto libSelectedCondition =
@ -446,7 +446,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
auto pinTypeCond =
[this]( const SELECTION& )
{
return GetRenderSettings()->m_ShowPinsElectricalType;
return GetRenderSettings() && GetRenderSettings()->m_ShowPinsElectricalType;
};
auto showCompTreeCond =

View File

@ -420,20 +420,19 @@ void SYMBOL_VIEWER_FRAME::setupUIConditions()
auto electricalTypesShownCondition =
[this]( const SELECTION& aSel )
{
return GetRenderSettings()->m_ShowPinsElectricalType;
return GetRenderSettings() && GetRenderSettings()->m_ShowPinsElectricalType;
};
auto pinNumbersShownCondition =
[this]( const SELECTION& )
{
return GetRenderSettings()->m_ShowPinNumbers;
return GetRenderSettings() && GetRenderSettings()->m_ShowPinNumbers;
};
auto demorganCond =
[this]( const SELECTION& )
{
LIB_SYMBOL* symbol = GetSelectedSymbol();
return symbol && symbol->HasConversion();
};
@ -453,7 +452,6 @@ void SYMBOL_VIEWER_FRAME::setupUIConditions()
[this]( const SELECTION& )
{
LIB_SYMBOL* symbol = GetSelectedSymbol();
return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
};

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 CERN (www.cern.ch)
* Copyright (C) 2004-2022 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2023 KiCad Developers, see change_log.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
@ -308,10 +308,10 @@ void KICAD_MANAGER_FRAME::setupUIConditions()
wxASSERT( manager );
auto activeProject =
[this] ( const SELECTION& )
{
return m_active_project;
};
[this] ( const SELECTION& )
{
return m_active_project;
};
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )

View File

@ -315,16 +315,16 @@ void PL_EDITOR_FRAME::setupUIConditions()
CHECK( SELECTION_CONDITIONS::ShowNever ) );
auto titleBlockNormalMode =
[] ( const SELECTION& )
{
return DS_DATA_MODEL::GetTheInstance().m_EditMode == false;
};
[] ( const SELECTION& )
{
return DS_DATA_MODEL::GetTheInstance().m_EditMode == false;
};
auto titleBlockEditMode =
[] ( const SELECTION& )
{
return DS_DATA_MODEL::GetTheInstance().m_EditMode == true;
};
[] ( const SELECTION& )
{
return DS_DATA_MODEL::GetTheInstance().m_EditMode == true;
};
mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );

View File

@ -1162,7 +1162,7 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
auto haveFootprintCond =
[this]( const SELECTION& )
{
return GetBoard()->GetFirstFootprint() != nullptr;
return GetBoard() && GetBoard()->GetFirstFootprint() != nullptr;
};
auto footprintTargettedCond =
@ -1221,7 +1221,7 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
auto boardFlippedCond =
[this]( const SELECTION& )
{
return GetCanvas()->GetView()->IsMirroredX();
return GetCanvas() && GetCanvas()->GetView()->IsMirroredX();
};
auto footprintTreeCond =
@ -1261,23 +1261,26 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::repairFootprint, ENABLE( haveFootprintCond ) );
mgr->SetConditions( PCB_ACTIONS::cleanupGraphics, ENABLE( haveFootprintCond ) );
auto isArcKeepCenterMode = [this]( const SELECTION& )
{
return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
};
auto isArcKeepCenterMode =
[this]( const SELECTION& )
{
return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
};
auto isArcKeepEndpointMode = [this]( const SELECTION& )
{
return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
};
auto isArcKeepEndpointMode =
[this]( const SELECTION& )
{
return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
};
mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepCenter, CHECK( isArcKeepCenterMode ) );
mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepEndpoint, CHECK( isArcKeepEndpointMode ) );
// Only enable a tool if the part is edtable
#define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, \
ACTION_CONDITIONS().Enable( haveFootprintCond ).Check( cond.CurrentTool( action ) ) )
#define CURRENT_EDIT_TOOL( action ) \
mgr->SetConditions( action, ACTION_CONDITIONS().Enable( haveFootprintCond ) \
.Check( cond.CurrentTool( action ) ) )
CURRENT_EDIT_TOOL( ACTIONS::deleteTool );
CURRENT_EDIT_TOOL( ACTIONS::measureTool );

View File

@ -724,7 +724,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
auto enableZoneControlCondition =
[this] ( const SELECTION& )
{
return GetBoard()->GetVisibleElements().Contains( LAYER_ZONES )
return GetBoard() && GetBoard()->GetVisibleElements().Contains( LAYER_ZONES )
&& GetDisplayOptions().m_ZoneOpacity > 0.0;
};
@ -752,16 +752,14 @@ void PCB_EDIT_FRAME::setupUIConditions()
auto enableBoardSetupCondition =
[this] ( const SELECTION& )
{
if( DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>() )
return !tool->IsDRCDialogShown();
return true;
DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
return !( tool && tool->IsDRCDialogShown() );
};
auto boardFlippedCond =
[this]( const SELECTION& )
{
return GetCanvas()->GetView()->IsMirroredX();
return GetCanvas() && GetCanvas()->GetView()->IsMirroredX();
};
auto layerManagerCond =
@ -771,16 +769,16 @@ void PCB_EDIT_FRAME::setupUIConditions()
};
auto propertiesCond =
[this] ( const SELECTION& )
{
return PropertiesShown();
};
[this] ( const SELECTION& )
{
return PropertiesShown();
};
auto searchPaneCond =
[this] ( const SELECTION& )
{
return m_auimgr.GetPane( SearchPaneName() ).IsShown();
};
[this] ( const SELECTION& )
{
return m_auimgr.GetPane( SearchPaneName() ).IsShown();
};
auto highContrastCond =
[this] ( const SELECTION& )
@ -811,7 +809,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
[this]( const SELECTION& )
{
BOARD_INSPECTION_TOOL* tool = m_toolManager->GetTool<BOARD_INSPECTION_TOOL>();
return tool->IsNetHighlightSet();
return tool && tool->IsNetHighlightSet();
};
mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( constrainedDrawingModeCond ) );
@ -826,16 +824,17 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::showProperties, CHECK( propertiesCond ) );
mgr->SetConditions( PCB_ACTIONS::showSearch, CHECK( searchPaneCond ) );
auto isArcKeepCenterMode = [this]( const SELECTION& )
{
return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
};
auto isArcKeepCenterMode =
[this]( const SELECTION& )
{
return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
};
auto isArcKeepEndpointMode = [this]( const SELECTION& )
{
return GetPcbNewSettings()->m_ArcEditMode
== ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
};
auto isArcKeepEndpointMode =
[this]( const SELECTION& )
{
return GetPcbNewSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
};
mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepCenter, CHECK( isArcKeepCenterMode ) );
mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepEndpoint, CHECK( isArcKeepEndpointMode ) );
@ -844,21 +843,21 @@ void PCB_EDIT_FRAME::setupUIConditions()
[this]( const SELECTION& )
{
ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
return tool->GetRouterMode() == PNS::RM_MarkObstacles;
return tool && tool->GetRouterMode() == PNS::RM_MarkObstacles;
};
auto isShoveMode =
[this]( const SELECTION& )
{
ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
return tool->GetRouterMode() == PNS::RM_Shove;
return tool && tool->GetRouterMode() == PNS::RM_Shove;
};
auto isWalkaroundMode =
[this]( const SELECTION& )
{
ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
return tool->GetRouterMode() == PNS::RM_Walkaround;
return tool && tool->GetRouterMode() == PNS::RM_Walkaround;
};
mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
@ -925,7 +924,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
[this] ( const SELECTION& )
{
DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
return !tool->IsDRCRunning();
return !( tool && tool->IsDRCRunning() );
};
#define CURRENT_EDIT_TOOL( action ) \