2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-18 00:29:54 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pns_walkaround.h"
|
|
|
|
#include "pns_shove.h"
|
|
|
|
#include "pns_router.h"
|
|
|
|
#include "pns_diff_pair_placer.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_topology.h"
|
2016-08-15 15:16:48 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR_PLACER::DIFF_PAIR_PLACER( ROUTER* aRouter ) :
|
|
|
|
PLACEMENT_ALGO( aRouter )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-03-10 14:38:27 +00:00
|
|
|
m_state = RT_START;
|
|
|
|
m_chainedPlacement = false;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_initialDiagonal = false;
|
|
|
|
m_startDiagonal = false;
|
2015-03-10 14:38:27 +00:00
|
|
|
m_fitOk = false;
|
|
|
|
m_netP = 0;
|
|
|
|
m_netN = 0;
|
|
|
|
m_iteration = 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_world = NULL;
|
|
|
|
m_shove = NULL;
|
|
|
|
m_currentNode = NULL;
|
2015-03-10 14:38:27 +00:00
|
|
|
m_lastNode = NULL;
|
|
|
|
m_placingVia = false;
|
|
|
|
m_viaDiameter = 0;
|
|
|
|
m_viaDrill = 0;
|
|
|
|
m_currentWidth = 0;
|
|
|
|
m_currentNet = 0;
|
|
|
|
m_currentLayer = 0;
|
|
|
|
m_startsOnVia = false;
|
|
|
|
m_orthoMode = false;
|
|
|
|
m_snapOnTarget = false;
|
|
|
|
m_currentEndItem = NULL;
|
|
|
|
m_currentMode = RM_MarkObstacles;
|
2021-04-15 02:43:54 +00:00
|
|
|
m_currentTraceOk = false;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_idle = true;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR_PLACER::~DIFF_PAIR_PLACER()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_shove )
|
|
|
|
delete m_shove;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::setWorld( NODE* aWorld )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_world = aWorld;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const VIA DIFF_PAIR_PLACER::makeVia( const VECTOR2I& aP, int aNet )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const LAYER_RANGE layers( m_sizes.GetLayerTop(), m_sizes.GetLayerBottom() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA v( aP, layers, m_sizes.ViaDiameter(), m_sizes.ViaDrill(), -1, m_sizes.ViaType() );
|
2015-02-18 16:53:46 +00:00
|
|
|
v.SetNet( aNet );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::SetOrthoMode ( bool aOrthoMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_orthoMode = aOrthoMode;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( !m_idle )
|
|
|
|
Move( m_currentEnd, NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::ToggleVia( bool aEnabled )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_placingVia = aEnabled;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( !m_idle )
|
|
|
|
Move( m_currentEnd, NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::rhMarkObstacles( const VECTOR2I& aP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !routeHead( aP ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-07-22 08:46:45 +00:00
|
|
|
bool collP = static_cast<bool>( m_currentNode->CheckColliding( &m_currentTrace.PLine() ) );
|
|
|
|
bool collN = static_cast<bool>( m_currentNode->CheckColliding( &m_currentTrace.NLine() ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
m_fitOk = !( collP || collN ) ;
|
2015-09-30 09:18:19 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return m_fitOk;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::propagateDpHeadForces ( const VECTOR2I& aP, VECTOR2I& aNewP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA virtHead = makeVia( aP, -1 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_placingVia )
|
|
|
|
virtHead.SetDiameter( viaGap() + 2 * virtHead.Diameter() );
|
|
|
|
else
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
virtHead.SetLayer( m_currentLayer );
|
2019-02-04 02:46:52 +00:00
|
|
|
virtHead.SetDiameter( m_sizes.DiffPairGap() + 2 * m_sizes.DiffPairWidth() );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool solidsOnly = true;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_currentMode == RM_MarkObstacles )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aNewP = aP;
|
2015-02-18 16:53:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( m_currentMode == RM_Walkaround )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
solidsOnly = false;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
// fixme: I'm too lazy to do it well. Circular approximaton will do for the moment.
|
2021-04-18 02:37:30 +00:00
|
|
|
|
|
|
|
// Note: this code is lifted from VIA::PushoutForce and then optimized for this use case and to
|
|
|
|
// check proper clearances to the diff pair line. It can be removed if some specialized
|
|
|
|
// pushout for traces / diff pairs is implemented. Just calling VIA::PushoutForce does not work
|
|
|
|
// as the via may have different resolved clearance to items than the diff pair should.
|
|
|
|
int maxIter = 40;
|
|
|
|
int iter = 0;
|
|
|
|
bool collided = false;
|
|
|
|
VECTOR2I force, totalForce;
|
|
|
|
std::set<ITEM*> handled;
|
|
|
|
|
|
|
|
while( iter < maxIter )
|
|
|
|
{
|
|
|
|
NODE::OPT_OBSTACLE obs = m_currentNode->CheckColliding( &virtHead, solidsOnly ?
|
|
|
|
ITEM::SOLID_T :
|
|
|
|
ITEM::ANY_T );
|
|
|
|
if( !obs || handled.count( obs->m_item ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
int clearance = m_currentNode->GetClearance( obs->m_item, &m_currentTrace.PLine() );
|
|
|
|
|
|
|
|
if( obs->m_item->Shape()->Collide( virtHead.Shape(), clearance, &force ) )
|
|
|
|
{
|
|
|
|
collided = true;
|
|
|
|
totalForce += force;
|
|
|
|
virtHead.SetPos( virtHead.Pos() + force );
|
|
|
|
}
|
|
|
|
|
|
|
|
handled.insert( obs->m_item );
|
|
|
|
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool succeeded = ( !collided || iter != maxIter );
|
|
|
|
|
|
|
|
if( succeeded )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aNewP = aP + force;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent,
|
|
|
|
DIFF_PAIR& aWalk, bool aPFirst, bool aWindCw, bool aSolidsOnly )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND walkaround( aNode, Router() );
|
|
|
|
WALKAROUND::WALKAROUND_STATUS wf1;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
walkaround.SetSolidsOnly( aSolidsOnly );
|
|
|
|
walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE shove( aNode, Router() );
|
|
|
|
LINE walkP, walkN;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
aWalk = *aCurrent;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int iter = 0;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR cur( *aCurrent );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
bool currentIsP = aPFirst;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int mask = aSolidsOnly ? ITEM::SOLID_T : ITEM::ANY_T;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE preWalk = ( currentIsP ? cur.PLine() : cur.NLine() );
|
|
|
|
LINE preShove = ( currentIsP ? cur.NLine() : cur.PLine() );
|
|
|
|
LINE postWalk;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !aNode->CheckColliding ( &preWalk, mask ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
currentIsP = !currentIsP;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( !aNode->CheckColliding( &preShove, mask ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
break;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
wf1 = walkaround.Route( preWalk, postWalk, false );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( wf1 != WALKAROUND::DONE )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE postShove( preShove );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-03-02 16:21:04 +00:00
|
|
|
shove.ForceClearance( true, cur.Gap() - 2 * PNS_HULL_MARGIN );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS sh1;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
sh1 = shove.ShoveObstacleLine( postWalk, preShove, postShove );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( sh1 != SHOVE::SH_OK )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
postWalk.Line().Simplify();
|
|
|
|
postShove.Line().Simplify();
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
cur.SetShape( postWalk.CLine(), postShove.CLine(), !currentIsP );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
currentIsP = !currentIsP;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !aNode->CheckColliding( &postShove, mask ) )
|
|
|
|
break;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
iter++;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
while( iter < 3 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( iter == 3 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aWalk.SetShape( cur.CP(), cur.CN() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::tryWalkDp( NODE* aNode, DIFF_PAIR &aPair, bool aSolidsOnly )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR best;
|
2015-02-18 00:29:54 +00:00
|
|
|
double bestScore = 100000000000000.0;
|
|
|
|
|
2016-05-11 09:18:27 +00:00
|
|
|
for( int attempt = 0; attempt <= 3; attempt++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
DIFF_PAIR p;
|
|
|
|
NODE *tmp = m_currentNode->Branch();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-05-11 09:18:27 +00:00
|
|
|
bool pfirst = ( attempt & 1 ) ? true : false;
|
|
|
|
bool wind_cw = ( attempt & 2 ) ? true : false;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-05-11 09:18:27 +00:00
|
|
|
if( attemptWalk( tmp, &aPair, p, pfirst, wind_cw, aSolidsOnly ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
// double len = p.TotalLength();
|
|
|
|
double cl = p.CoupledLength();
|
|
|
|
double skew = p.Skew();
|
|
|
|
|
2016-05-11 09:18:27 +00:00
|
|
|
double score = cl + fabs( skew ) * 3.0;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( score < bestScore )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
bestScore = score;
|
|
|
|
best = p;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
delete tmp;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( bestScore > 0.0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
OPTIMIZER optimizer( m_currentNode );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aPair.SetShape( best );
|
|
|
|
optimizer.Optimize( &aPair );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::rhWalkOnly( const VECTOR2I& aP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !routeHead ( aP ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_fitOk = tryWalkDp( m_currentNode, m_currentTrace, false );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return m_fitOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::route( const VECTOR2I& aP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
switch( m_currentMode )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_MarkObstacles:
|
|
|
|
return rhMarkObstacles( aP );
|
|
|
|
case RM_Walkaround:
|
|
|
|
return rhWalkOnly( aP );
|
|
|
|
case RM_Shove:
|
|
|
|
return rhShoveOnly( aP );
|
|
|
|
default:
|
|
|
|
break;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::rhShoveOnly( const VECTOR2I& aP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
|
2015-09-30 09:18:19 +00:00
|
|
|
bool ok = routeHead( aP );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_fitOk = false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !ok )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !tryWalkDp( m_currentNode, m_currentTrace, true ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE pLine( m_currentTrace.PLine() );
|
|
|
|
LINE nLine( m_currentTrace.NLine() );
|
|
|
|
ITEM_SET head;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
head.Add( &pLine );
|
|
|
|
head.Add( &nLine );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS status = m_shove->ShoveMultiLines( head );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( status == SHOVE::SH_OK )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_currentNode = m_shove->CurrentNode();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( !m_currentNode->CheckColliding( &m_currentTrace.PLine() ) &&
|
|
|
|
!m_currentNode->CheckColliding( &m_currentTrace.NLine() ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_fitOk = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_fitOk;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET DIFF_PAIR_PLACER::Traces()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET t;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2020-12-20 18:59:07 +00:00
|
|
|
t.Add( &m_currentTrace.PLine() );
|
|
|
|
t.Add( &m_currentTrace.NLine() );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::FlipPosture()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_startDiagonal = !m_startDiagonal;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_idle )
|
|
|
|
Move( m_currentEnd, NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* DIFF_PAIR_PLACER::CurrentNode( bool aLoopsRemoved ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_lastNode )
|
|
|
|
return m_lastNode;
|
|
|
|
|
|
|
|
return m_currentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::SetLayer( int aLayer )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_idle )
|
|
|
|
{
|
|
|
|
m_currentLayer = aLayer;
|
|
|
|
return true;
|
2018-07-03 15:19:35 +00:00
|
|
|
}
|
|
|
|
else if( m_chainedPlacement || !m_prevPair )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2018-07-03 15:19:35 +00:00
|
|
|
}
|
|
|
|
else if( !m_prevPair->PrimP() || ( m_prevPair->PrimP()->OfKind( ITEM::VIA_T ) &&
|
2015-02-18 16:53:46 +00:00
|
|
|
m_prevPair->PrimP()->Layers().Overlaps( aLayer ) ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_currentLayer = aLayer;
|
|
|
|
m_start = *m_prevPair;
|
2016-08-15 15:16:51 +00:00
|
|
|
initPlacement();
|
2015-02-18 16:53:46 +00:00
|
|
|
Move( m_currentEnd, NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
OPT_VECTOR2I getDanglingAnchor( NODE* aNode, ITEM* aItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( aItem->Kind() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
|
|
|
case ITEM::SOLID_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
return aItem->Anchor( 0 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
case ITEM::ARC_T:
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
SEGMENT* s = static_cast<SEGMENT*>( aItem );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
JOINT* jA = aNode->FindJoint( aItem->Anchor( 0 ), aItem );
|
|
|
|
JOINT* jB = aNode->FindJoint( aItem->Anchor( 1 ), aItem );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
if( jA && jA->LinkCount() == 1 )
|
2015-10-05 16:28:41 +00:00
|
|
|
return s->Seg().A;
|
2019-05-17 00:13:21 +00:00
|
|
|
else if( jB && jB->LinkCount() == 1 )
|
2015-10-05 16:28:41 +00:00
|
|
|
return s->Seg().B;
|
|
|
|
else
|
2015-02-18 00:29:54 +00:00
|
|
|
return OPT_VECTOR2I();
|
2015-10-05 16:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return OPT_VECTOR2I();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
bool DIFF_PAIR_PLACER::FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, ITEM* aItem,
|
2018-05-19 00:50:52 +00:00
|
|
|
DP_PRIMITIVE_PAIR& aPair, wxString* aErrorMsg )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
int netP, netN;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
wxLogTrace( "PNS", "world %p", aWorld );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
bool result = aWorld->GetRuleResolver()->DpNetPair( aItem, netP, netN );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( !result )
|
2018-05-19 00:50:52 +00:00
|
|
|
{
|
|
|
|
if( aErrorMsg )
|
|
|
|
{
|
|
|
|
*aErrorMsg = _( "Unable to find complementary differential pair "
|
|
|
|
"nets. Make sure the names of the nets belonging "
|
2021-04-21 01:08:34 +00:00
|
|
|
"to a differential pair end with either N/P or +/-." );
|
2018-05-19 00:50:52 +00:00
|
|
|
}
|
2015-03-05 09:01:54 +00:00
|
|
|
return false;
|
2018-05-19 00:50:52 +00:00
|
|
|
}
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
int refNet = aItem->Net();
|
2016-08-15 15:16:53 +00:00
|
|
|
int coupledNet = ( refNet == netP ) ? netN : netP;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "result %d", !!result );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
OPT_VECTOR2I refAnchor = getDanglingAnchor( aWorld, aItem );
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* primRef = aItem;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "refAnchor %p", aItem );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !refAnchor )
|
2018-05-19 00:50:52 +00:00
|
|
|
{
|
|
|
|
if( aErrorMsg )
|
|
|
|
{
|
|
|
|
*aErrorMsg = _( "Can't find a suitable starting point. If starting "
|
|
|
|
"from an existing differential pair make sure you are "
|
2018-12-20 16:10:05 +00:00
|
|
|
"at the end." );
|
2018-05-19 00:50:52 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2018-05-19 00:50:52 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
std::set<ITEM*> coupledItems;
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
aWorld->AllItemsInNet( coupledNet, coupledItems );
|
2015-02-18 00:29:54 +00:00
|
|
|
double bestDist = std::numeric_limits<double>::max();
|
|
|
|
bool found = false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : coupledItems )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( item->Kind() == aItem->Kind() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-01-05 18:45:32 +00:00
|
|
|
OPT_VECTOR2I anchor = getDanglingAnchor( aWorld, item );
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !anchor )
|
2015-02-18 00:29:54 +00:00
|
|
|
continue;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
double dist = ( *anchor - *refAnchor ).EuclideanNorm();
|
|
|
|
|
2015-10-07 17:26:33 +00:00
|
|
|
bool shapeMatches = true;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( item->OfKind( ITEM::SOLID_T ) && item->Layers() != aItem->Layers() )
|
2015-10-07 17:26:33 +00:00
|
|
|
{
|
|
|
|
shapeMatches = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( dist < bestDist && shapeMatches )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
bestDist = dist;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2018-10-18 11:48:19 +00:00
|
|
|
if( refNet != netP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
aPair = DP_PRIMITIVE_PAIR ( item, primRef );
|
2015-02-18 16:53:46 +00:00
|
|
|
aPair.SetAnchors( *anchor, *refAnchor );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
aPair = DP_PRIMITIVE_PAIR( primRef, item );
|
2015-02-18 16:53:46 +00:00
|
|
|
aPair.SetAnchors( *refAnchor, *anchor );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-19 00:50:52 +00:00
|
|
|
if( !found )
|
|
|
|
{
|
|
|
|
if( aErrorMsg )
|
|
|
|
{
|
|
|
|
*aErrorMsg = wxString::Format( _( "Can't find a suitable starting point "
|
|
|
|
"for coupled net \"%s\"." ),
|
2021-01-05 18:45:32 +00:00
|
|
|
aWorld->GetRuleResolver()->NetName( coupledNet ) );
|
2018-05-19 00:50:52 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int DIFF_PAIR_PLACER::viaGap() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-02-24 17:33:05 +00:00
|
|
|
return std::max( m_sizes.DiffPairViaGap(),
|
2021-02-25 14:21:50 +00:00
|
|
|
m_sizes.GetHoleToHole() + m_sizes.ViaDrill() - m_sizes.ViaDiameter() );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int DIFF_PAIR_PLACER::gap() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_sizes.DiffPairGap() + m_sizes.DiffPairWidth();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I p( aP );
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
setWorld( Router()->GetWorld() );
|
|
|
|
m_currentNode = m_world;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
if( !FindDpPrimitivePair( m_currentNode, aP, aStartItem, m_start ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
m_netP = m_start.PrimP()->Net();
|
|
|
|
m_netN = m_start.PrimN()->Net();
|
|
|
|
|
|
|
|
m_currentStart = p;
|
|
|
|
m_currentEnd = p;
|
|
|
|
m_placingVia = false;
|
|
|
|
m_chainedPlacement = false;
|
2021-04-15 02:43:54 +00:00
|
|
|
m_currentTraceOk = false;
|
|
|
|
m_currentTrace = DIFF_PAIR();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-15 15:16:51 +00:00
|
|
|
initPlacement();
|
2015-09-30 11:37:19 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::initPlacement()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_idle = false;
|
|
|
|
m_orthoMode = false;
|
|
|
|
m_currentEndItem = NULL;
|
|
|
|
m_startDiagonal = m_initialDiagonal;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* world = Router()->GetWorld();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
world->KillChildren();
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* rootNode = world->Branch();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
setWorld( rootNode );
|
|
|
|
|
|
|
|
m_lastNode = NULL;
|
|
|
|
m_currentNode = rootNode;
|
|
|
|
m_currentMode = Settings().Mode();
|
|
|
|
|
|
|
|
if( m_shove )
|
|
|
|
delete m_shove;
|
|
|
|
|
|
|
|
m_shove = NULL;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( m_currentMode == RM_Shove || m_currentMode == RM_Smart )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
m_shove = new SHOVE( m_currentNode, Router() );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::routeHead( const VECTOR2I& aP )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_fitOk = false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_GATEWAYS gwsEntry( gap() );
|
|
|
|
DP_GATEWAYS gwsTarget( gap() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_prevPair )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_prevPair = m_start;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
gwsEntry.BuildFromPrimitivePair( *m_prevPair, m_startDiagonal );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DP_PRIMITIVE_PAIR target;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
if( FindDpPrimitivePair( m_currentNode, aP, m_currentEndItem, target ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
gwsTarget.BuildFromPrimitivePair( target, m_startDiagonal );
|
|
|
|
m_snapOnTarget = true;
|
2016-08-15 15:16:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I fp;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !propagateDpHeadForces( aP, fp ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
VECTOR2I midp, dirV;
|
2016-08-15 15:16:53 +00:00
|
|
|
m_prevPair->CursorOrientation( fp, midp, dirV );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
VECTOR2I fpProj = SEG( midp, midp + dirV ).LineProject( fp );
|
2018-10-18 12:29:06 +00:00
|
|
|
|
|
|
|
// compute 'leader point' distance from the cursor (project cursor position
|
|
|
|
// on the extension of the starting segment pair of the DP)
|
2016-08-15 15:16:53 +00:00
|
|
|
int lead_dist = ( fpProj - fp ).EuclideanNorm();
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
gwsTarget.SetFitVias( m_placingVia, m_sizes.ViaDiameter(), viaGap() );
|
2016-08-15 15:16:49 +00:00
|
|
|
|
2018-10-18 12:29:06 +00:00
|
|
|
// far from the initial segment extension line -> allow a 45-degree obtuse turn
|
2021-04-15 02:42:33 +00:00
|
|
|
if( lead_dist > ( m_sizes.DiffPairGap() + m_sizes.DiffPairWidth() ) / 2 )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
|
|
|
gwsTarget.BuildForCursor( fp );
|
2016-08-15 15:16:53 +00:00
|
|
|
}
|
2018-10-18 12:29:06 +00:00
|
|
|
// close to the initial segment extension line -> keep straight part only, project as close
|
|
|
|
// as possible to the cursor
|
2016-08-15 15:16:53 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
gwsTarget.BuildForCursor( fpProj );
|
2021-04-15 02:42:33 +00:00
|
|
|
gwsTarget.FilterByOrientation( DIRECTION_45::ANG_STRAIGHT | DIRECTION_45::ANG_HALF_FULL,
|
|
|
|
DIRECTION_45( dirV ) );
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_snapOnTarget = false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_currentTrace.SetGap( gap() );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_currentTrace.SetLayer( m_currentLayer );
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
bool result = gwsEntry.FitGateways( gwsEntry, gwsTarget, m_startDiagonal, m_currentTrace );
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( result )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-04-15 02:43:54 +00:00
|
|
|
m_currentTraceOk = true;
|
2015-02-18 16:53:46 +00:00
|
|
|
m_currentTrace.SetNets( m_netP, m_netN );
|
|
|
|
m_currentTrace.SetWidth( m_sizes.DiffPairWidth() );
|
|
|
|
m_currentTrace.SetGap( m_sizes.DiffPairGap() );
|
|
|
|
|
|
|
|
if( m_placingVia )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
m_currentTrace.AppendVias ( makeVia( m_currentTrace.CP().CPoint( -1 ), m_netP ),
|
|
|
|
makeVia( m_currentTrace.CN().CPoint( -1 ), m_netN ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-15 02:43:54 +00:00
|
|
|
return m_currentTraceOk;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DIFF_PAIR_PLACER::Move( const VECTOR2I& aP , ITEM* aEndItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_currentEndItem = aEndItem;
|
|
|
|
m_fitOk = false;
|
|
|
|
|
|
|
|
delete m_lastNode;
|
|
|
|
m_lastNode = NULL;
|
|
|
|
|
2018-10-02 21:38:02 +00:00
|
|
|
bool retval = route( aP );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* latestNode = m_currentNode;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_lastNode = latestNode->Branch();
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
assert( m_lastNode != NULL );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_currentEnd = aP;
|
|
|
|
|
|
|
|
updateLeadingRatLine();
|
|
|
|
|
2018-10-02 21:38:02 +00:00
|
|
|
return retval;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::UpdateSizes( const SIZES_SETTINGS& aSizes )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_sizes = aSizes;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( !m_idle )
|
|
|
|
{
|
2020-12-12 02:52:33 +00:00
|
|
|
m_currentTrace.SetWidth( m_sizes.DiffPairWidth() );
|
|
|
|
m_currentTrace.SetGap( m_sizes.DiffPairGap() );
|
|
|
|
|
|
|
|
if( m_currentTrace.EndsWithVias() )
|
|
|
|
{
|
|
|
|
m_currentTrace.SetViaDiameter( m_sizes.ViaDiameter() );
|
|
|
|
m_currentTrace.SetViaDrill( m_sizes.ViaDrill() );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
bool DIFF_PAIR_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-04-10 09:31:42 +00:00
|
|
|
if( !m_fitOk && !Settings().AllowDRCViolations() )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2021-04-10 09:31:42 +00:00
|
|
|
if( m_currentTrace.CP().SegmentCount() < 1 || m_currentTrace.CN().SegmentCount() < 1 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_currentTrace.CP().SegmentCount() > 1 )
|
|
|
|
m_initialDiagonal = !DIRECTION_45( m_currentTrace.CP().CSegment( -2 ) ).IsDiagonal();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
TOPOLOGY topo( m_lastNode );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-04-15 02:41:24 +00:00
|
|
|
if( !m_snapOnTarget && !m_currentTrace.EndsWithVias() && !aForceFinish &&
|
|
|
|
!Settings().GetFixAllSegments() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-09-30 09:18:19 +00:00
|
|
|
SHAPE_LINE_CHAIN newP( m_currentTrace.CP() );
|
|
|
|
SHAPE_LINE_CHAIN newN( m_currentTrace.CN() );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( newP.SegmentCount() > 1 && newN.SegmentCount() > 1 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
newP.Remove( -1, -1 );
|
|
|
|
newN.Remove( -1, -1 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_currentTrace.SetShape( newP, newN );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_currentTrace.EndsWithVias() )
|
|
|
|
{
|
2016-08-30 15:28:35 +00:00
|
|
|
m_lastNode->Add( Clone( m_currentTrace.PLine().Via() ) );
|
|
|
|
m_lastNode->Add( Clone( m_currentTrace.NLine().Via() ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_chainedPlacement = false;
|
2015-09-30 09:18:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-19 17:29:36 +00:00
|
|
|
m_chainedPlacement = !m_snapOnTarget && !aForceFinish;
|
2015-09-30 09:18:19 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE lineP( m_currentTrace.PLine() );
|
|
|
|
LINE lineN( m_currentTrace.NLine() );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
m_lastNode->Add( lineP );
|
|
|
|
m_lastNode->Add( lineN );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
topo.SimplifyLine( &lineP );
|
|
|
|
topo.SimplifyLine( &lineN );
|
|
|
|
|
|
|
|
m_prevPair = m_currentTrace.EndingPrimitives();
|
|
|
|
|
2020-03-04 23:21:50 +00:00
|
|
|
CommitPlacement();
|
2015-02-18 00:29:54 +00:00
|
|
|
m_placingVia = false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
if( m_snapOnTarget || aForceFinish )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_idle = true;
|
2015-02-18 16:53:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
initPlacement();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-04 23:21:50 +00:00
|
|
|
bool DIFF_PAIR_PLACER::AbortPlacement()
|
|
|
|
{
|
|
|
|
m_world->KillChildren();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIFF_PAIR_PLACER::HasPlacedAnything() const
|
|
|
|
{
|
|
|
|
return m_currentTrace.CP().SegmentCount() > 0 ||
|
|
|
|
m_currentTrace.CN().SegmentCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIFF_PAIR_PLACER::CommitPlacement()
|
|
|
|
{
|
|
|
|
if( m_lastNode )
|
|
|
|
Router()->CommitRouting( m_lastNode );
|
|
|
|
|
|
|
|
m_lastNode = NULL;
|
|
|
|
m_currentNode = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::GetModifiedNets( std::vector<int> &aNets ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aNets.push_back( m_netP );
|
|
|
|
aNets.push_back( m_netN );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void DIFF_PAIR_PLACER::updateLeadingRatLine()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN ratLineN, ratLineP;
|
2016-08-29 17:31:13 +00:00
|
|
|
TOPOLOGY topo( m_lastNode );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( topo.LeadingRatLine( &m_currentTrace.PLine(), ratLineP ) )
|
2020-10-14 00:04:47 +00:00
|
|
|
m_router->GetInterface()->DisplayRatline( ratLineP, 1 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( topo.LeadingRatLine ( &m_currentTrace.NLine(), ratLineN ) )
|
2020-10-14 00:04:47 +00:00
|
|
|
m_router->GetInterface()->DisplayRatline( ratLineN, 3 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-08-21 14:35:34 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const std::vector<int> DIFF_PAIR_PLACER::CurrentNets() const
|
2015-08-21 14:35:34 +00:00
|
|
|
{
|
|
|
|
std::vector<int> rv;
|
|
|
|
rv.push_back( m_netP );
|
|
|
|
rv.push_back( m_netN );
|
|
|
|
return rv;
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|