From cd5b4ec8f221ca4b02a998fbded560baf1c84494 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 27 Jun 2022 22:07:25 +0100 Subject: [PATCH] Add edge-exclusions to router (for castellated pads). Fixes https://gitlab.com/kicad/code/kicad/issues/1790 (cherry picked from commit 833dc70bff6627767db4c6a136913411cf67c732) --- eeschema/dialogs/dialog_erc.cpp | 2 +- pcbnew/router/pns_item.cpp | 16 ++++++++++++++-- pcbnew/router/pns_kicad_iface.cpp | 7 +++++++ pcbnew/router/pns_node.cpp | 20 +++++++++++++++++++- pcbnew/router/pns_node.h | 8 +++++++- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 177023d179..09fdfc2b68 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -223,7 +223,7 @@ void DIALOG_ERC::updateDisplayedCounts() msg.Replace( wxT( "(%s)" ), wxEmptyString ); } - m_notebook->SetPageText( 0, msg ); + m_notebook->SetPageText( 1, msg ); if( !m_ercRun && numErrors == 0 ) numErrors = -1; diff --git a/pcbnew/router/pns_item.cpp b/pcbnew/router/pns_item.cpp index 8de76802d5..fe0edd9e93 100644 --- a/pcbnew/router/pns_item.cpp +++ b/pcbnew/router/pns_item.cpp @@ -2,7 +2,7 @@ * KiRouter - a push-and-(sometimes-)shove PCB router * * Copyright (C) 2013-2014 CERN - * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. * Author: Tomasz Wlostowski * * This program is free software: you can redistribute it and/or modify it @@ -124,7 +124,19 @@ bool ITEM::collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferent return false; int clearance = aNode->GetClearance( this, aOther ); - return shapeA->Collide( shapeB, clearance + lineWidthA + lineWidthB ); + + if( m_parent && m_parent->GetLayer() == Edge_Cuts ) + { + int actual; + VECTOR2I pos; + + return( shapeA->Collide( shapeB, clearance + lineWidthA, &actual, &pos ) + && !aNode->QueryEdgeExclusions( pos ) ); + } + else + { + return shapeA->Collide( shapeB, clearance + lineWidthA + lineWidthB ); + } } diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 6b396ce1f3..a646140d9f 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -1343,6 +1343,13 @@ void PNS_KICAD_IFACE_BASE::SyncWorld( PNS::NODE *aWorld ) aWorld->Add( std::move( solid ) ); worstClearance = std::max( worstClearance, pad->GetLocalClearance() ); + + if( pad->GetProperty() == PAD_PROP::CASTELLATED ) + { + std::unique_ptr hole; + hole.reset( new SHAPE_SEGMENT( *pad->GetEffectiveHoleShape() ) ); + aWorld->AddEdgeExclusion( std::move( hole ) ); + } } syncTextItem( aWorld, &footprint->Reference(), footprint->Reference().GetLayer() ); diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 8ea571cc8d..691a3d4d90 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -2,7 +2,7 @@ * KiRouter - a push-and-(sometimes-)shove PCB router * * Copyright (C) 2013-2019 CERN - * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @@ -712,6 +712,24 @@ void NODE::Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant ) } +void NODE::AddEdgeExclusion( std::unique_ptr aShape ) +{ + m_edgeExclusions.push_back( std::move( aShape ) ); +} + + +bool NODE::QueryEdgeExclusions( const VECTOR2I& aPos ) const +{ + for( const std::unique_ptr& edgeExclusion : m_edgeExclusions ) + { + if( edgeExclusion->Collide( aPos ) ) + return true; + } + + return false; +} + + void NODE::doRemove( ITEM* aItem ) { // case 1: removing an item that is stored in the root node from any branch: diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h index 816e5834a2..f6a05bfefe 100644 --- a/pcbnew/router/pns_node.h +++ b/pcbnew/router/pns_node.h @@ -2,7 +2,7 @@ * KiRouter - a push-and-(sometimes-)shove PCB router * * Copyright (C) 2013-2014 CERN - * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors. * * @author Tomasz Wlostowski * @@ -269,6 +269,10 @@ public: void Add( LINE& aLine, bool aAllowRedundant = false ); + void AddEdgeExclusion( std::unique_ptr aShape ); + + bool QueryEdgeExclusions( const VECTOR2I& aPos ) const; + /** * Remove an item from this branch. */ @@ -465,6 +469,8 @@ private: int m_depth; ///< depth of the node (number of parent nodes in the ///< inheritance chain) + std::vector< std::unique_ptr > m_edgeExclusions; + std::unordered_set m_garbageItems; };