From 2ab9ceaf028c9d2f4e1cf01f116b15965dc91c1f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 23 Jun 2020 17:16:34 -0400 Subject: [PATCH] Pick up net for new zone from selection if no net is highlighted Fixes https://gitlab.com/kicad/code/kicad/-/issues/4706 --- pcbnew/tools/zone_create_helper.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp index fcf9cc02bb..24492f3c00 100644 --- a/pcbnew/tools/zone_create_helper.cpp +++ b/pcbnew/tools/zone_create_helper.cpp @@ -64,6 +64,18 @@ std::unique_ptr ZONE_CREATE_HELPER::createNewZone( bool aKeepout zoneInfo.SetIsKeepout( m_params.m_keepout ); zoneInfo.m_Zone_45_Only = ( m_params.m_leaderMode == POLYGON_GEOM_MANAGER::LEADER_MODE::DEG45 ); + // If we don't have a net from highlighing, maybe we can get one from the selection + SELECTION_TOOL* selectionTool = m_tool.GetManager()->GetTool(); + + if( selectionTool && !selectionTool->GetSelection().Empty() + && zoneInfo.m_NetcodeSelection == -1 ) + { + EDA_ITEM* item = *selectionTool->GetSelection().GetItems().begin(); + + if( BOARD_CONNECTED_ITEM* bci = dynamic_cast( item ) ) + zoneInfo.m_NetcodeSelection = bci->GetNetCode(); + } + if( m_params.m_mode != ZONE_MODE::GRAPHIC_POLYGON ) { // Get the current default settings for zones @@ -241,8 +253,6 @@ bool ZONE_CREATE_HELPER::OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr ) // the user's choice here can affect things like the colour of the preview if( !m_zone ) { - m_tool.GetManager()->RunAction( PCB_ACTIONS::selectionClear, true ); - if( m_params.m_sourceZone ) m_zone = createZoneFromExisting( *m_params.m_sourceZone ); else @@ -250,6 +260,8 @@ bool ZONE_CREATE_HELPER::OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr ) if( m_zone ) { + m_tool.GetManager()->RunAction( PCB_ACTIONS::selectionClear, true ); + // set up poperties from zone const auto& settings = *m_parentView.GetPainter()->GetSettings(); COLOR4D color = settings.GetColor( nullptr, m_zone->GetLayer() );