2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2022-09-11 21:17:45 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
#include "pns_node.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_line.h"
|
2020-08-16 19:36:58 +00:00
|
|
|
#include "pns_router.h"
|
2022-08-30 12:52:34 +00:00
|
|
|
|
|
|
|
#include <geometry/shape_compound.h>
|
|
|
|
#include <geometry/shape_poly_set.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-07-21 22:35:41 +00:00
|
|
|
typedef VECTOR2I::extended_type ecoord;
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
static void dumpObstacles( const PNS::NODE::OBSTACLES &obstacles )
|
|
|
|
{
|
2023-05-20 12:00:00 +00:00
|
|
|
printf( "&&&& %zu obstacles: \n", obstacles.size() );
|
2022-08-30 12:52:34 +00:00
|
|
|
|
|
|
|
for( const auto& obs : obstacles )
|
|
|
|
{
|
2022-09-11 21:17:45 +00:00
|
|
|
printf( "%p [%s] - %p [%s], clearance %d\n",
|
|
|
|
obs.m_head, obs.m_head->KindStr().c_str(),
|
|
|
|
obs.m_item, obs.m_item->KindStr().c_str(),
|
|
|
|
obs.m_clearance );
|
2022-08-30 12:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-17 12:07:15 +00:00
|
|
|
|
2023-05-24 23:18:53 +00:00
|
|
|
// prune self-collisions, i.e. a via/pad annular ring with its own hole
|
2023-06-21 22:33:10 +00:00
|
|
|
static bool shouldWeConsiderHoleCollisions( const ITEM* aItem, const ITEM* aHead )
|
2023-05-24 23:18:53 +00:00
|
|
|
{
|
2023-06-21 22:33:10 +00:00
|
|
|
const HOLE* holeI = aItem->OfKind( ITEM::HOLE_T ) ? static_cast<const HOLE*>( aItem ) : nullptr;
|
|
|
|
const HOLE* holeH = aHead->OfKind( ITEM::HOLE_T ) ? static_cast<const HOLE*>( aHead ) : nullptr;
|
2023-05-24 23:18:53 +00:00
|
|
|
|
2023-06-21 22:33:10 +00:00
|
|
|
if( holeI && holeH ) // hole-to-hole case
|
2023-05-24 23:18:53 +00:00
|
|
|
{
|
2023-06-21 22:33:10 +00:00
|
|
|
const ITEM* parentI = holeI->ParentPadVia();
|
|
|
|
const ITEM* parentH = holeH->ParentPadVia();
|
|
|
|
if( !parentH || !parentI )
|
2023-05-24 23:18:53 +00:00
|
|
|
return true;
|
|
|
|
|
2023-06-21 22:33:10 +00:00
|
|
|
const VIA* parentViaI = dyn_cast<const VIA*>( parentI );
|
|
|
|
const VIA* parentViaH = dyn_cast<const VIA*>( parentH );
|
|
|
|
|
2023-10-17 12:07:15 +00:00
|
|
|
// Note to self: the if() below is an ugly heuristic to determine if we aren't trying
|
|
|
|
// to check for collisions of the hole of the via with another (although identical)
|
|
|
|
// copy of it. Such case occurs when checking a LINE against a NODE where this LINE
|
|
|
|
// has been already added. LINE has no notion of ownership of it's via (it's just a
|
|
|
|
// copy) and before hole-to-hole clearance support has been introduced it didn't matter
|
|
|
|
// becasue we didn't consider collisions of the objects belonging to the same net anyway
|
|
|
|
// Now that hole clearance check doesn't care about the nets assigned to the parent
|
|
|
|
// vias/solids, I'll probably have to refactor the LINE class to manage ownership of
|
|
|
|
// its (optional) VIA. For the moment, we just treat via holes that are geometrically
|
|
|
|
// identical and belonging to the same net as non-colliding.
|
2023-06-21 22:33:10 +00:00
|
|
|
|
|
|
|
if( parentViaI && parentViaH && parentViaI->Pos() == parentViaH->Pos()
|
|
|
|
&& parentViaI->Diameter() == parentViaH->Diameter()
|
|
|
|
&& parentViaI->Net() == parentViaH->Net()
|
|
|
|
&& parentViaI->Drill() == parentViaH->Drill() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return parentI != parentH;
|
2023-05-24 23:18:53 +00:00
|
|
|
}
|
|
|
|
|
2023-06-21 22:33:10 +00:00
|
|
|
if( holeI )
|
|
|
|
return holeI->ParentPadVia() != aHead;
|
|
|
|
else if( holeH )
|
|
|
|
return holeH->ParentPadVia() != aItem;
|
2023-05-24 23:18:53 +00:00
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
2022-08-30 12:52:34 +00:00
|
|
|
|
2023-06-21 22:33:10 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
bool ITEM::collideSimple( const ITEM* aHead, const NODE* aNode,
|
|
|
|
COLLISION_SEARCH_CONTEXT* aCtx ) const
|
2019-07-21 22:35:41 +00:00
|
|
|
{
|
2023-04-07 12:40:52 +00:00
|
|
|
// Note: if 'this' is a pad or a via then its hole is a separate PNS::ITEM in the node's
|
|
|
|
// index and we don't need to deal with holeI here. The same is *not* true of the routing
|
|
|
|
// "head", so we do need to handle holeH.
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
const SHAPE* shapeI = Shape();
|
|
|
|
int lineWidthI = 0;
|
|
|
|
|
|
|
|
const SHAPE* shapeH = aHead->Shape();
|
|
|
|
const HOLE* holeH = aHead->Hole();
|
|
|
|
int lineWidthH = 0;
|
|
|
|
int clearanceEpsilon = aNode->GetRuleResolver()->ClearanceEpsilon();
|
|
|
|
bool collisionsFound = false;
|
|
|
|
|
2023-05-23 13:08:53 +00:00
|
|
|
if( this == aHead ) // we cannot be self-colliding
|
2022-09-14 21:02:30 +00:00
|
|
|
return false;
|
|
|
|
|
2023-05-24 23:18:53 +00:00
|
|
|
if ( !shouldWeConsiderHoleCollisions( this, aHead ) )
|
|
|
|
return false;
|
|
|
|
|
2022-09-14 21:02:30 +00:00
|
|
|
// Special cases for "head" lines with vias attached at the end. Note that this does not
|
|
|
|
// support head-line-via to head-line-via collisions, but you can't route two independent
|
|
|
|
// tracks at once so it shouldn't come up.
|
|
|
|
|
|
|
|
if( const auto line = dyn_cast<const LINE*>( this ) )
|
|
|
|
{
|
|
|
|
if( line->EndsWithVia() )
|
|
|
|
collisionsFound |= line->Via().collideSimple( aHead, aNode, aCtx );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( const auto line = dyn_cast<const LINE*>( aHead ) )
|
|
|
|
{
|
|
|
|
if( line->EndsWithVia() )
|
|
|
|
collisionsFound |= line->Via().collideSimple( this, aNode, aCtx );
|
|
|
|
}
|
|
|
|
|
2023-04-07 12:40:52 +00:00
|
|
|
// And a special case for the "head" via's hole.
|
2023-05-24 23:18:53 +00:00
|
|
|
if( holeH && shouldWeConsiderHoleCollisions( this, holeH ) )
|
|
|
|
{
|
2023-07-01 12:00:19 +00:00
|
|
|
if( collideSimple( holeH, aNode, aCtx ) )
|
2023-05-24 23:18:53 +00:00
|
|
|
collisionsFound = true;
|
|
|
|
}
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
// Sadly collision routines ignore SHAPE_POLY_LINE widths so we have to pass them in as part
|
|
|
|
// of the clearance value.
|
|
|
|
if( m_kind == LINE_T )
|
2022-08-30 12:52:34 +00:00
|
|
|
lineWidthI = static_cast<const LINE*>( this )->Width() / 2;
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( aHead->m_kind == LINE_T )
|
|
|
|
lineWidthH = static_cast<const LINE*>( aHead )->Width() / 2;
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
// check if we are not on completely different layers first
|
2022-08-30 12:52:34 +00:00
|
|
|
if( !m_layers.Overlaps( aHead->m_layers ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2023-04-06 14:33:49 +00:00
|
|
|
// fixme: this f***ing singleton must go...
|
|
|
|
ROUTER* router = ROUTER::GetInstance();
|
|
|
|
ROUTER_IFACE* iface = router ? router->GetInterface() : nullptr;
|
2023-06-22 21:52:11 +00:00
|
|
|
bool differentNetsOnly = true;
|
2023-04-06 14:33:49 +00:00
|
|
|
int clearance;
|
2022-08-30 12:52:34 +00:00
|
|
|
|
2023-06-22 21:52:11 +00:00
|
|
|
if( aCtx )
|
|
|
|
differentNetsOnly = aCtx->options.m_differentNetsOnly;
|
|
|
|
|
2023-04-07 12:40:52 +00:00
|
|
|
// Hole-to-hole collisions don't have anything to do with nets
|
|
|
|
if( Kind() == HOLE_T && aHead->Kind() == HOLE_T )
|
|
|
|
differentNetsOnly = false;
|
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
if( differentNetsOnly && Net() == aHead->Net() && aHead->Net() )
|
2022-08-30 12:52:34 +00:00
|
|
|
{
|
2023-04-06 14:33:49 +00:00
|
|
|
// same nets? no clearance!
|
|
|
|
clearance = -1;
|
|
|
|
}
|
|
|
|
else if( differentNetsOnly && ( IsFreePad() || aHead->IsFreePad() ) )
|
|
|
|
{
|
|
|
|
// a pad associated with a "free" pin (NIC) doesn't have a net until it has been used
|
|
|
|
clearance = -1;
|
2022-08-30 12:52:34 +00:00
|
|
|
}
|
2022-09-14 21:02:30 +00:00
|
|
|
else if( aNode->GetRuleResolver()->IsKeepout( this, aHead ) )
|
|
|
|
{
|
|
|
|
clearance = 0; // keepouts are exact boundary; no clearance
|
|
|
|
}
|
2023-04-09 19:25:22 +00:00
|
|
|
else if( iface && !iface->IsFlashedOnLayer( this, aHead->Layers() ) )
|
2022-08-30 12:52:34 +00:00
|
|
|
{
|
2023-04-06 14:33:49 +00:00
|
|
|
clearance = -1;
|
2022-08-30 12:52:34 +00:00
|
|
|
}
|
2023-04-09 19:25:22 +00:00
|
|
|
else if( iface && !iface->IsFlashedOnLayer( aHead, Layers() ) )
|
2022-09-14 21:02:30 +00:00
|
|
|
{
|
2023-04-06 14:33:49 +00:00
|
|
|
clearance = -1;
|
|
|
|
}
|
|
|
|
else if( aCtx && aCtx->options.m_overrideClearance >= 0 )
|
|
|
|
{
|
|
|
|
clearance = aCtx->options.m_overrideClearance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-12 10:27:32 +00:00
|
|
|
clearance = aNode->GetClearance( this, aHead, aCtx ? aCtx->options.m_useClearanceEpsilon
|
|
|
|
: false );
|
2022-09-14 21:02:30 +00:00
|
|
|
}
|
2022-06-27 21:07:25 +00:00
|
|
|
|
2022-07-09 17:24:19 +00:00
|
|
|
if( clearance >= 0 )
|
2022-06-27 21:07:25 +00:00
|
|
|
{
|
2022-09-14 21:02:30 +00:00
|
|
|
// Note: we can't do castellation or net-tie processing in GetClearance() because they
|
|
|
|
// depend on *where* the collision is.
|
|
|
|
|
2022-08-19 17:34:53 +00:00
|
|
|
bool checkCastellation = ( m_parent && m_parent->GetLayer() == Edge_Cuts );
|
2022-09-14 21:02:30 +00:00
|
|
|
bool checkNetTie = ( m_parent && aNode->GetRuleResolver()->IsInNetTie( this ) );
|
2022-08-19 17:34:53 +00:00
|
|
|
|
|
|
|
if( checkCastellation || checkNetTie )
|
2022-07-09 17:24:19 +00:00
|
|
|
{
|
2022-08-19 17:34:53 +00:00
|
|
|
// Slow method
|
2022-07-09 17:24:19 +00:00
|
|
|
int actual;
|
|
|
|
VECTOR2I pos;
|
2022-06-27 21:07:25 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( shapeH->Collide( shapeI, clearance + lineWidthH + lineWidthI - clearanceEpsilon,
|
|
|
|
&actual, &pos ) )
|
2022-07-09 17:24:19 +00:00
|
|
|
{
|
2022-08-19 17:34:53 +00:00
|
|
|
if( checkCastellation && aNode->QueryEdgeExclusions( pos ) )
|
|
|
|
return false;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( checkNetTie && aNode->GetRuleResolver()->IsNetTieExclusion( aHead, pos, this ) )
|
2022-08-19 17:34:53 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( aCtx )
|
|
|
|
{
|
|
|
|
collisionsFound = true;
|
|
|
|
OBSTACLE obs;
|
|
|
|
obs.m_head = const_cast<ITEM*>( aHead );
|
|
|
|
obs.m_item = const_cast<ITEM*>( this );
|
|
|
|
obs.m_clearance = clearance;
|
2023-10-27 20:48:03 +00:00
|
|
|
obs.m_distFirst = 0;
|
|
|
|
obs.m_maxFanoutWidth = 0;
|
2022-08-30 12:52:34 +00:00
|
|
|
aCtx->obstacles.insert( obs );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2022-07-09 17:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-19 17:34:53 +00:00
|
|
|
// Fast method
|
2022-08-30 12:52:34 +00:00
|
|
|
if( shapeH->Collide( shapeI, clearance + lineWidthH + lineWidthI - clearanceEpsilon ) )
|
2022-08-15 13:31:43 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
if( aCtx )
|
|
|
|
{
|
|
|
|
collisionsFound = true;
|
|
|
|
OBSTACLE obs;
|
|
|
|
obs.m_head = const_cast<ITEM*>( aHead );
|
|
|
|
obs.m_item = const_cast<ITEM*>( this );
|
|
|
|
obs.m_clearance = clearance;
|
2023-08-27 19:16:29 +00:00
|
|
|
obs.m_distFirst = 0;
|
2023-10-16 21:04:01 +00:00
|
|
|
obs.m_maxFanoutWidth = 0;
|
2023-10-30 13:16:24 +00:00
|
|
|
obs.m_violatingConstraint = CONSTRAINT_TYPE::CT_CLEARANCE;
|
2022-08-30 12:52:34 +00:00
|
|
|
aCtx->obstacles.insert( obs );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2022-08-15 13:31:43 +00:00
|
|
|
}
|
2022-07-09 17:24:19 +00:00
|
|
|
}
|
2022-06-27 21:07:25 +00:00
|
|
|
}
|
2022-07-09 17:24:19 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
return collisionsFound;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
bool ITEM::Collide( const ITEM* aOther, const NODE* aNode, COLLISION_SEARCH_CONTEXT *aCtx ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
if( collideSimple( aOther, aNode, aCtx ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-07-21 22:35:41 +00:00
|
|
|
std::string ITEM::KindStr() const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
switch( m_kind )
|
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
case ARC_T: return "arc";
|
|
|
|
case LINE_T: return "line";
|
|
|
|
case SEGMENT_T: return "segment";
|
|
|
|
case VIA_T: return "via";
|
|
|
|
case JOINT_T: return "joint";
|
|
|
|
case SOLID_T: return "solid";
|
|
|
|
case DIFF_PAIR_T: return "diff-pair";
|
2022-08-30 12:52:34 +00:00
|
|
|
case HOLE_T: return "hole";
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
default: return "unknown";
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM::~ITEM()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
|
2022-10-23 22:34:42 +00:00
|
|
|
const std::string ITEM::Format() const
|
|
|
|
{
|
2023-08-29 16:28:37 +00:00
|
|
|
ROUTER* router = ROUTER::GetInstance();
|
|
|
|
ROUTER_IFACE* iface = router ? router->GetInterface() : nullptr;
|
|
|
|
|
2022-10-23 22:34:42 +00:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << KindStr() << " ";
|
2023-08-29 16:28:37 +00:00
|
|
|
|
|
|
|
if( iface )
|
|
|
|
ss << "net " << iface->GetNetCode( Net() ) << " ";
|
|
|
|
|
2022-10-23 22:34:42 +00:00
|
|
|
ss << "layers " << m_layers.Start() << " " << m_layers.End();
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2023-06-21 22:33:10 +00:00
|
|
|
|
|
|
|
const NODE* ITEM::OwningNode() const
|
|
|
|
{
|
|
|
|
if( ParentPadVia() )
|
|
|
|
return static_cast<const NODE*>( ParentPadVia()->Owner() );
|
|
|
|
else
|
|
|
|
return static_cast<const NODE*>( Owner() );
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
2023-06-21 22:33:10 +00:00
|
|
|
|
|
|
|
} // namespace PNS
|