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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_utils.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_router.h"
|
2022-10-26 22:24:05 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <geometry/shape_rect.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/box2.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2022-01-12 23:42:50 +00:00
|
|
|
bool VIA::PushoutForce( NODE* aNode, const ITEM* aOther, VECTOR2I& aForce )
|
|
|
|
{
|
|
|
|
int clearance = aNode->GetClearance( this, aOther );
|
2022-03-03 23:58:14 +00:00
|
|
|
VECTOR2I elementForces[4], force;
|
|
|
|
size_t nf = 0;
|
2022-01-12 23:42:50 +00:00
|
|
|
|
2022-03-03 23:58:14 +00:00
|
|
|
aOther->Shape()->Collide( Shape(), clearance, &elementForces[nf++] );
|
2022-01-12 23:42:50 +00:00
|
|
|
|
2022-03-03 23:58:14 +00:00
|
|
|
for( size_t i = 0; i < nf; i++ )
|
2022-01-12 23:42:50 +00:00
|
|
|
{
|
2022-03-03 23:58:14 +00:00
|
|
|
if( elementForces[i].SquaredEuclideanNorm() > force.SquaredEuclideanNorm() )
|
|
|
|
force = elementForces[i];
|
2022-01-12 23:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aForce = force;
|
|
|
|
|
|
|
|
return ( force != VECTOR2I( 0, 0 ) );
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool VIA::PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
|
2022-10-26 22:24:05 +00:00
|
|
|
int aCollisionMask, int aMaxIterations )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2022-10-26 22:24:05 +00:00
|
|
|
int iter = 0;
|
|
|
|
VIA mv( *this );
|
2022-01-12 23:42:50 +00:00
|
|
|
VECTOR2I totalForce;
|
|
|
|
|
2022-10-26 22:24:05 +00:00
|
|
|
auto dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
|
2022-11-18 14:08:16 +00:00
|
|
|
PNS_DBG( dbg, AddPoint, Pos(), YELLOW, 100000, wxString::Format( "via-force-init-pos, iter %d", aMaxIterations ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
while( iter < aMaxIterations )
|
|
|
|
{
|
2022-10-26 22:24:05 +00:00
|
|
|
NODE::OPT_OBSTACLE obs = aNode->CheckColliding( &mv, aCollisionMask );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !obs )
|
|
|
|
break;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:24:05 +00:00
|
|
|
VECTOR2I force;
|
2022-11-18 14:08:16 +00:00
|
|
|
bool collFound = mv.PushoutForce( aNode, obs->m_item, force );
|
2022-10-26 22:24:05 +00:00
|
|
|
|
|
|
|
if( !collFound )
|
2022-11-18 14:08:16 +00:00
|
|
|
{
|
|
|
|
if( obs )
|
|
|
|
{
|
|
|
|
// might happen (although rarely) that we see a collision, but the MTV
|
|
|
|
// is zero... Assume force propagation has failed in such case.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PNS_DBG( dbg, Message, wxString::Format( "no-coll %d", iter ) );
|
2022-10-26 22:24:05 +00:00
|
|
|
break;
|
2022-11-18 14:08:16 +00:00
|
|
|
}
|
2022-10-26 22:24:05 +00:00
|
|
|
|
|
|
|
const int threshold = Diameter() / 4; // another stupid heuristic.
|
|
|
|
const int forceMag = force.EuclideanNorm();
|
|
|
|
|
|
|
|
// We've been through a lot of iterations already and our pushout force is still too big?
|
|
|
|
// Perhaps the barycentric force goes in the wrong direction, let's try to move along
|
|
|
|
// the 'lead' vector instead (usually backwards to the cursor)
|
|
|
|
if( iter > aMaxIterations / 2 && forceMag > threshold )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-10-26 22:24:05 +00:00
|
|
|
VECTOR2I l = aDirection.Resize( threshold );
|
2013-09-26 21:53:54 +00:00
|
|
|
totalForce += l;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:24:05 +00:00
|
|
|
SHAPE_LINE_CHAIN ff;
|
|
|
|
ff.Append( mv.Pos() );
|
|
|
|
ff.Append( mv.Pos() + l );
|
2022-01-12 23:42:50 +00:00
|
|
|
|
2022-10-26 22:24:05 +00:00
|
|
|
mv.SetPos( mv.Pos() + l );
|
|
|
|
|
|
|
|
PNS_DBG( dbg, AddShape, &ff, YELLOW, 100000, "via-force-lead" );
|
|
|
|
}
|
|
|
|
else if( collFound ) // push along the minmum translation vector
|
2020-07-02 16:06:09 +00:00
|
|
|
{
|
2022-10-26 22:24:05 +00:00
|
|
|
// Limit the force magnitude to, say, 25% of the via diameter
|
|
|
|
// This adds a few iterations for large areas (e.g. keepouts)
|
|
|
|
// But makes the algorithm more predictable and less 'jumpy'
|
|
|
|
if( forceMag > threshold )
|
|
|
|
{
|
|
|
|
force.Resize( threshold );
|
|
|
|
}
|
|
|
|
|
2020-07-02 16:06:09 +00:00
|
|
|
totalForce += force;
|
2022-10-26 22:24:05 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN ff;
|
|
|
|
ff.Append( mv.Pos() );
|
|
|
|
ff.Append( mv.Pos() + force );
|
|
|
|
|
2020-07-02 16:06:09 +00:00
|
|
|
mv.SetPos( mv.Pos() + force );
|
2022-10-26 22:24:05 +00:00
|
|
|
|
|
|
|
PNS_DBG( dbg, AddShape, &ff, WHITE, 100000, "via-force-coll" );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
iter++;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( iter == aMaxIterations )
|
|
|
|
return false;
|
|
|
|
|
2022-10-26 22:24:05 +00:00
|
|
|
PNS_DBG( dbg, AddPoint, ( Pos() + totalForce ), WHITE, 1000000, "via-force-new" );
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
aForce = totalForce;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-08-16 19:36:58 +00:00
|
|
|
const SHAPE_LINE_CHAIN VIA::Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
int cl = ( aClearance + aWalkaroundThickness / 2 );
|
2020-08-16 19:36:58 +00:00
|
|
|
int width = m_diameter;
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( !ROUTER::GetInstance()->GetInterface()->IsFlashedOnLayer( this, aLayer ) )
|
2022-08-30 12:52:34 +00:00
|
|
|
width = m_hole->Radius() * 2;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-06-06 13:53:45 +00:00
|
|
|
// Chamfer = width * ( 1 - sqrt(2)/2 ) for equilateral octagon
|
|
|
|
return OctagonalHull( m_pos - VECTOR2I( width / 2, width / 2 ),
|
2022-09-11 21:17:45 +00:00
|
|
|
VECTOR2I( width, width ),
|
|
|
|
cl, ( 2 * cl + width ) * ( 1.0 - M_SQRT1_2 ) );
|
2022-06-07 23:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA* VIA::Clone() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA* v = new VIA();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
v->SetNet( Net() );
|
|
|
|
v->SetLayers( Layers() );
|
|
|
|
v->m_pos = m_pos;
|
|
|
|
v->m_diameter = m_diameter;
|
|
|
|
v->m_drill = m_drill;
|
|
|
|
v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
|
2022-08-30 12:52:34 +00:00
|
|
|
v->m_hole = m_hole->Clone();
|
2014-05-14 13:53:54 +00:00
|
|
|
v->m_rank = m_rank;
|
|
|
|
v->m_marker = m_marker;
|
2014-07-27 19:01:06 +00:00
|
|
|
v->m_viaType = m_viaType;
|
2019-07-24 15:19:03 +00:00
|
|
|
v->m_parent = m_parent;
|
2020-12-20 21:29:43 +00:00
|
|
|
v->m_isFree = m_isFree;
|
2021-06-03 20:30:00 +00:00
|
|
|
v->m_isVirtual = m_isVirtual;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
return v;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_BOX2I VIA::ChangedArea( const VIA* aOther ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if ( aOther->Pos() != Pos() )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
BOX2I tmp = Shape()->BBox();
|
2015-07-07 16:36:38 +00:00
|
|
|
tmp.Merge( aOther->Shape()->BBox() );
|
2015-02-18 00:29:54 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPT_BOX2I();
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2022-10-23 22:34:42 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
const VIA_HANDLE VIA::MakeHandle() const
|
|
|
|
{
|
|
|
|
VIA_HANDLE h;
|
|
|
|
h.pos = Pos();
|
|
|
|
h.layers = Layers();
|
|
|
|
h.net = Net();
|
|
|
|
h.valid = true;
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2022-10-23 22:34:42 +00:00
|
|
|
|
|
|
|
const std::string VIA::Format( ) const
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << ITEM::Format() << " drill " << m_drill << " ";
|
|
|
|
ss << m_shape.Format( false );
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|