From 4dda3a171564905df378e671794c5dbd58270da8 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 30 Sep 2020 19:04:31 -0400 Subject: [PATCH] Don't allow editing design rules without a project Also fix a crash initializing DRC engine on an empty board Fixes https://gitlab.com/kicad/code/kicad/-/issues/5835 --- pcbnew/dialogs/panel_setup_layers.cpp | 3 +++ pcbnew/dialogs/panel_setup_rules.cpp | 10 ++++++++++ pcbnew/pcb_base_edit_frame.cpp | 11 ++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pcbnew/dialogs/panel_setup_layers.cpp b/pcbnew/dialogs/panel_setup_layers.cpp index 61fc9819f6..c7f507a318 100644 --- a/pcbnew/dialogs/panel_setup_layers.cpp +++ b/pcbnew/dialogs/panel_setup_layers.cpp @@ -251,6 +251,9 @@ bool PANEL_SETUP_LAYERS::TransferDataToWindow() { m_enabledLayers = m_pcb->GetEnabledLayers(); + // Rescue may be enabled, but should not be shown in this dialog + m_enabledLayers.reset( Rescue ); + showCopperChoice( m_pcb->GetCopperLayerCount() ); setCopperLayerCheckBoxes( m_pcb->GetCopperLayerCount() ); diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index d630fd2274..22ba7247a5 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -349,6 +349,13 @@ bool PANEL_SETUP_RULES::TransferDataToWindow() m_originalText = m_textEditor->GetText(); + if( m_frame->Prj().IsNullProject() ) + { + m_textEditor->ClearAll(); + m_textEditor->AddText( _( "Design rules cannot be added without a project" ) ); + m_textEditor->Disable(); + } + return true; } @@ -358,6 +365,9 @@ bool PANEL_SETUP_RULES::TransferDataFromWindow() if( m_originalText == m_textEditor->GetText() ) return true; + if( m_frame->Prj().IsNullProject() ) + return true; + try { std::vector dummyRules; diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index fface7f089..5d92ad6cc7 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -143,6 +143,12 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard ) GetCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetDesignSettings().m_GridOrigin ) ); + if( new_board ) + { + BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); + bds.m_DRCEngine = std::make_shared( aBoard, &bds ); + } + // update the tool manager with the new board and its view. if( m_toolManager ) { @@ -153,12 +159,7 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard ) GetCanvas()->GetViewControls(), config(), this ); if( new_board ) - { - BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); - bds.m_DRCEngine = std::make_shared( aBoard, &bds ); - m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); - } } }