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
|
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
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_item.h>
|
|
|
|
#include <view/view_group.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
#include <geometry/shape_circle.h>
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
#include <tools/grid_helper.h>
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "trace.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_line_placer.h"
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_utils.h"
|
|
|
|
#include "pns_router.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_shove.h"
|
|
|
|
#include "pns_dragger.h"
|
2015-02-26 15:34:10 +00:00
|
|
|
#include "pns_topology.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_diff_pair_placer.h"
|
|
|
|
#include "pns_meander_placer.h"
|
|
|
|
#include "pns_meander_skew_placer.h"
|
|
|
|
#include "pns_dp_meander_placer.h"
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <router/router_preview_item.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <class_board_connected_item.h>
|
2014-01-07 13:23:46 +00:00
|
|
|
#include <class_module.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <class_track.h>
|
2013-12-20 14:18:41 +00:00
|
|
|
#include <ratsnest_data.h>
|
2013-09-26 21:53:54 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// an ugly singleton for drawing debug items within the router context.
|
2013-09-26 21:53:54 +00:00
|
|
|
// To be fixed sometime in the future.
|
|
|
|
static PNS_ROUTER* theRouter;
|
|
|
|
|
|
|
|
|
2015-06-15 15:54:58 +00:00
|
|
|
PNS_PCBNEW_CLEARANCE_FUNC::PNS_PCBNEW_CLEARANCE_FUNC( PNS_ROUTER* aRouter ) :
|
2015-02-26 15:34:10 +00:00
|
|
|
m_router( aRouter )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-06-15 15:54:58 +00:00
|
|
|
BOARD* brd = m_router->GetBoard();
|
|
|
|
PNS_NODE* world = m_router->GetWorld();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-26 15:34:10 +00:00
|
|
|
PNS_TOPOLOGY topo( world );
|
|
|
|
m_clearanceCache.resize( brd->GetNetCount() );
|
2015-08-21 14:37:44 +00:00
|
|
|
m_useDpGap = false;
|
2015-03-09 10:06:54 +00:00
|
|
|
|
2015-02-26 15:34:10 +00:00
|
|
|
for( unsigned int i = 0; i < brd->GetNetCount(); i++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-26 15:34:10 +00:00
|
|
|
NETINFO_ITEM* ni = brd->FindNet( i );
|
2015-02-18 00:29:54 +00:00
|
|
|
if( ni == NULL )
|
|
|
|
continue;
|
|
|
|
|
2015-02-26 15:34:10 +00:00
|
|
|
CLEARANCE_ENT ent;
|
|
|
|
ent.coupledNet = topo.DpCoupledNet( i );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
wxString netClassName = ni->GetClassName();
|
2015-02-26 15:34:10 +00:00
|
|
|
NETCLASSPTR nc = brd->GetDesignSettings().m_NetClasses.Find( netClassName );
|
2015-03-09 10:06:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int clearance = nc->GetClearance();
|
2015-02-26 15:34:10 +00:00
|
|
|
ent.clearance = clearance;
|
|
|
|
m_clearanceCache[i] = ent;
|
2015-03-09 10:06:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
TRACE( 1, "Add net %d netclass %s clearance %d", i % netClassName.mb_str() %
|
|
|
|
clearance );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_overrideEnabled = false;
|
2015-06-15 14:01:43 +00:00
|
|
|
m_defaultClearance = Millimeter2iu( 0.254 ); // aBoard->m_NetClasses.Find ("Default clearance")->GetClearance();
|
|
|
|
m_overrideNetA = 0;
|
|
|
|
m_overrideNetB = 0;
|
|
|
|
m_overrideClearance = 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_PCBNEW_CLEARANCE_FUNC::~PNS_PCBNEW_CLEARANCE_FUNC()
|
|
|
|
{
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int PNS_PCBNEW_CLEARANCE_FUNC::localPadClearance( const PNS_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
|
|
|
|
return 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
|
|
|
|
return pad->GetLocalClearance();
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int PNS_PCBNEW_CLEARANCE_FUNC::operator()( const PNS_ITEM* aA, const PNS_ITEM* aB )
|
|
|
|
{
|
|
|
|
int net_a = aA->Net();
|
2015-02-26 15:34:10 +00:00
|
|
|
int cl_a = ( net_a >= 0 ? m_clearanceCache[net_a].clearance : m_defaultClearance );
|
2015-02-18 00:29:54 +00:00
|
|
|
int net_b = aB->Net();
|
2015-02-26 15:34:10 +00:00
|
|
|
int cl_b = ( net_b >= 0 ? m_clearanceCache[net_b].clearance : m_defaultClearance );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-03-02 16:21:04 +00:00
|
|
|
bool linesOnly = aA->OfKind( PNS_ITEM::SEGMENT | PNS_ITEM::LINE ) && aB->OfKind( PNS_ITEM::SEGMENT | PNS_ITEM::LINE );
|
2015-02-26 15:34:10 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( net_a == net_b )
|
|
|
|
return 0;
|
|
|
|
|
2015-08-21 14:37:44 +00:00
|
|
|
if( m_useDpGap && linesOnly && net_a >= 0 && net_b >= 0 && m_clearanceCache[net_a].coupledNet == net_b )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-03-02 16:21:04 +00:00
|
|
|
cl_a = cl_b = m_router->Sizes().DiffPairGap() - 2 * PNS_HULL_MARGIN;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int pad_a = localPadClearance( aA );
|
|
|
|
int pad_b = localPadClearance( aB );
|
|
|
|
|
|
|
|
cl_a = std::max( cl_a, pad_a );
|
|
|
|
cl_b = std::max( cl_b, pad_b );
|
|
|
|
|
|
|
|
return std::max( cl_a, cl_b );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
// fixme: ugly hack to make the optimizer respect gap width for currently routed differential pair.
|
2015-02-18 16:53:46 +00:00
|
|
|
void PNS_PCBNEW_CLEARANCE_FUNC::OverrideClearance( bool aEnable, int aNetA, int aNetB , int aClearance )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_overrideEnabled = aEnable;
|
|
|
|
m_overrideNetA = aNetA;
|
|
|
|
m_overrideNetB = aNetB;
|
|
|
|
m_overrideClearance = aClearance;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_ITEM* PNS_ROUTER::syncPad( D_PAD* aPad )
|
|
|
|
{
|
2014-07-07 08:48:47 +00:00
|
|
|
PNS_LAYERSET layers( 0, MAX_CU_LAYERS - 1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
// ignore non-copper pads
|
|
|
|
if ( (aPad->GetLayerSet() & LSET::AllCuMask()).none() )
|
|
|
|
return NULL;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
switch( aPad->GetAttribute() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_ATTRIB_STANDARD:
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_ATTRIB_SMD:
|
|
|
|
case PAD_ATTRIB_HOLE_NOT_PLATED:
|
|
|
|
case PAD_ATTRIB_CONN:
|
2014-05-29 11:48:14 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
LSET lmsk = aPad->GetLayerSet();
|
2014-11-26 14:46:47 +00:00
|
|
|
bool is_copper = false;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < MAX_CU_LAYERS; i++ )
|
2013-10-14 14:13:35 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( lmsk[i] )
|
|
|
|
{
|
2014-11-26 14:46:47 +00:00
|
|
|
is_copper = true;
|
2015-08-23 19:40:33 +00:00
|
|
|
if( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED )
|
2015-07-22 11:49:53 +00:00
|
|
|
layers = PNS_LAYERSET( i );
|
2014-06-24 16:17:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-10-14 14:13:35 +00:00
|
|
|
}
|
2014-11-26 14:46:47 +00:00
|
|
|
|
|
|
|
if( !is_copper )
|
|
|
|
return NULL;
|
2014-05-29 11:48:14 +00:00
|
|
|
}
|
2013-10-14 14:13:35 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
TRACE( 0, "unsupported pad type 0x%x", aPad->GetAttribute() );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PNS_SOLID* solid = new PNS_SOLID;
|
|
|
|
|
|
|
|
solid->SetLayers( layers );
|
2014-02-25 10:47:27 +00:00
|
|
|
solid->SetNet( aPad->GetNetCode() );
|
2014-05-14 13:53:54 +00:00
|
|
|
solid->SetParent( aPad );
|
|
|
|
|
2015-06-23 09:41:53 +00:00
|
|
|
wxPoint wx_c = aPad->ShapePos();
|
2013-09-26 21:53:54 +00:00
|
|
|
wxSize wx_sz = aPad->GetSize();
|
2015-08-04 10:15:47 +00:00
|
|
|
wxPoint offset = aPad->GetOffset();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
VECTOR2I c( wx_c.x, wx_c.y );
|
|
|
|
VECTOR2I sz( wx_sz.x, wx_sz.y );
|
|
|
|
|
2015-08-04 10:15:47 +00:00
|
|
|
RotatePoint( &offset, aPad->GetOrientation() );
|
|
|
|
|
|
|
|
solid->SetPos( VECTOR2I( c.x - offset.x, c.y - offset.y ) );
|
|
|
|
solid->SetOffset ( VECTOR2I ( offset.x, offset.y ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
double orient = aPad->GetOrientation() / 10.0;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-07-02 14:09:43 +00:00
|
|
|
solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
|
2015-07-02 14:11:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-02 14:09:43 +00:00
|
|
|
if( orient == 0.0 || orient == 90.0 || orient == 180.0 || orient == 270.0 )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-07-02 14:09:43 +00:00
|
|
|
if( orient == 90.0 || orient == 270.0 )
|
|
|
|
sz = VECTOR2I( sz.y, sz.x );
|
|
|
|
|
|
|
|
switch( aPad->GetShape() )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
2015-07-02 14:09:43 +00:00
|
|
|
if( sz.x == sz.y )
|
|
|
|
solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
|
2014-05-29 11:48:14 +00:00
|
|
|
else
|
2015-07-02 14:09:43 +00:00
|
|
|
{
|
|
|
|
VECTOR2I delta;
|
|
|
|
|
|
|
|
if( sz.x > sz.y )
|
|
|
|
delta = VECTOR2I( ( sz.x - sz.y ) / 2, 0 );
|
|
|
|
else
|
|
|
|
delta = VECTOR2I( 0, ( sz.y - sz.x ) / 2 );
|
|
|
|
|
|
|
|
SHAPE_SEGMENT* shape = new SHAPE_SEGMENT( c - delta, c + delta,
|
|
|
|
std::min( sz.x, sz.y ) );
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_RECT:
|
2015-07-02 14:09:43 +00:00
|
|
|
solid->SetShape( new SHAPE_RECT( c - sz / 2, sz.x, sz.y ) );
|
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2015-07-02 14:09:43 +00:00
|
|
|
{
|
|
|
|
wxPoint coords[4];
|
|
|
|
aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
|
|
|
|
SHAPE_CONVEX* shape = new SHAPE_CONVEX();
|
2015-08-10 15:50:10 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
|
|
|
shape->Append( wx_c + coords[ii] );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
solid->SetShape( shape );
|
2015-07-02 14:09:43 +00:00
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
default:
|
|
|
|
TRACEn( 0, "unsupported pad shape" );
|
|
|
|
delete solid;
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-07-02 14:11:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-02 14:09:43 +00:00
|
|
|
switch( aPad->GetShape() )
|
|
|
|
{
|
2015-08-23 19:40:33 +00:00
|
|
|
// PAD_SHAPE_CIRCLE already handled above
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
2015-07-02 14:09:43 +00:00
|
|
|
if( sz.x == sz.y )
|
|
|
|
solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint start;
|
|
|
|
wxPoint end;
|
|
|
|
wxPoint corner;
|
|
|
|
|
|
|
|
SHAPE_CONVEX* shape = new SHAPE_CONVEX();
|
|
|
|
|
|
|
|
int w = aPad->BuildSegmentFromOvalShape( start, end, 0.0, wxSize( 0, 0 ) );
|
|
|
|
|
|
|
|
if( start.y == 0 )
|
2015-08-10 15:50:10 +00:00
|
|
|
corner = wxPoint( start.x, -( w / 2 ) );
|
2015-07-02 14:09:43 +00:00
|
|
|
else
|
|
|
|
corner = wxPoint( w / 2, start.y );
|
2015-08-10 15:50:10 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
RotatePoint( &start, aPad->GetOrientation() );
|
|
|
|
RotatePoint( &corner, aPad->GetOrientation() );
|
|
|
|
shape->Append( wx_c + corner );
|
|
|
|
|
|
|
|
for( int rot = 100; rot <= 1800; rot += 100 )
|
|
|
|
{
|
|
|
|
wxPoint p( corner );
|
|
|
|
RotatePoint( &p, start, rot );
|
|
|
|
shape->Append( wx_c + p );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( end.y == 0 )
|
|
|
|
corner = wxPoint( end.x, w / 2 );
|
|
|
|
else
|
2015-08-10 15:50:10 +00:00
|
|
|
corner = wxPoint( -( w / 2 ), end.y );
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
RotatePoint( &end, aPad->GetOrientation() );
|
|
|
|
RotatePoint( &corner, aPad->GetOrientation() );
|
|
|
|
shape->Append( wx_c + corner );
|
|
|
|
|
|
|
|
for( int rot = 100; rot <= 1800; rot += 100 )
|
|
|
|
{
|
|
|
|
wxPoint p( corner );
|
|
|
|
RotatePoint( &p, end, rot );
|
|
|
|
shape->Append( wx_c + p );
|
|
|
|
}
|
|
|
|
|
|
|
|
solid->SetShape( shape );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-08-23 19:40:33 +00:00
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
2015-07-02 14:09:43 +00:00
|
|
|
{
|
|
|
|
wxPoint coords[4];
|
|
|
|
aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
|
|
|
|
|
|
|
|
SHAPE_CONVEX* shape = new SHAPE_CONVEX();
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
|
|
|
{
|
|
|
|
shape->Append( wx_c + coords[ii] );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
solid->SetShape( shape );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
TRACEn( 0, "unsupported pad shape" );
|
|
|
|
delete solid;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
return solid;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
PNS_ITEM* PNS_ROUTER::syncTrack( TRACK* aTrack )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_SEGMENT* s =
|
2014-02-25 10:47:27 +00:00
|
|
|
new PNS_SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
s->SetWidth( aTrack->GetWidth() );
|
|
|
|
s->SetLayers( PNS_LAYERSET( aTrack->GetLayer() ) );
|
|
|
|
s->SetParent( aTrack );
|
|
|
|
return s;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-25 06:00:04 +00:00
|
|
|
PNS_ITEM* PNS_ROUTER::syncVia( VIA* aVia )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-07-27 19:01:06 +00:00
|
|
|
LAYER_ID top, bottom;
|
2014-07-28 09:32:15 +00:00
|
|
|
aVia->LayerPair( &top, &bottom );
|
2013-09-26 21:53:54 +00:00
|
|
|
PNS_VIA* v = new PNS_VIA(
|
|
|
|
aVia->GetPosition(),
|
2014-07-27 19:01:06 +00:00
|
|
|
PNS_LAYERSET( top, bottom ),
|
2013-09-26 21:53:54 +00:00
|
|
|
aVia->GetWidth(),
|
2014-05-28 17:21:12 +00:00
|
|
|
aVia->GetDrillValue(),
|
2014-07-27 19:01:06 +00:00
|
|
|
aVia->GetNetCode(),
|
|
|
|
aVia->GetViaType() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
v->SetParent( aVia );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return v;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
void PNS_ROUTER::SetBoard( BOARD* aBoard )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
m_board = aBoard;
|
|
|
|
TRACE( 1, "m_board = %p\n", m_board );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
void PNS_ROUTER::SyncWorld()
|
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !m_board )
|
|
|
|
{
|
|
|
|
TRACEn( 0, "No board attached, aborting sync." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearWorld();
|
|
|
|
|
|
|
|
m_world = new PNS_NODE();
|
|
|
|
|
2014-01-07 13:23:46 +00:00
|
|
|
for( MODULE* module = m_board->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
|
|
|
|
{
|
|
|
|
PNS_ITEM* solid = syncPad( pad );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-01-07 13:23:46 +00:00
|
|
|
if( solid )
|
|
|
|
m_world->Add( solid );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( TRACK* t = m_board->m_Track; t; t = t->Next() )
|
|
|
|
{
|
|
|
|
KICAD_T type = t->Type();
|
|
|
|
PNS_ITEM* item = NULL;
|
|
|
|
|
|
|
|
if( type == PCB_TRACE_T )
|
|
|
|
item = syncTrack( t );
|
|
|
|
else if( type == PCB_VIA_T )
|
2014-04-25 06:00:04 +00:00
|
|
|
item = syncVia( static_cast<VIA*>( t ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
m_world->Add( item );
|
|
|
|
}
|
2015-02-26 15:34:10 +00:00
|
|
|
|
|
|
|
int worstClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
|
|
|
|
m_clearanceFunc = new PNS_PCBNEW_CLEARANCE_FUNC( this );
|
|
|
|
m_world->SetClearanceFunctor( m_clearanceFunc );
|
|
|
|
m_world->SetMaxClearance( 4 * worstClearance );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
PNS_ROUTER::PNS_ROUTER()
|
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
theRouter = this;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
m_clearanceFunc = NULL;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
m_state = IDLE;
|
|
|
|
m_world = NULL;
|
|
|
|
m_placer = NULL;
|
|
|
|
m_previewItems = NULL;
|
|
|
|
m_board = NULL;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_dragger = NULL;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_mode = PNS_MODE_ROUTE_SINGLE;
|
2015-04-20 14:59:25 +00:00
|
|
|
|
|
|
|
// Initialize all other variables:
|
|
|
|
m_lastNode = NULL;
|
|
|
|
m_shove = NULL;
|
|
|
|
m_iterLimit = 0;
|
|
|
|
m_showInterSteps = false;
|
|
|
|
m_snapshotIter = 0;
|
|
|
|
m_view = NULL;
|
|
|
|
m_snappingEnabled = false;
|
|
|
|
m_violation = false;
|
2015-11-11 18:47:51 +00:00
|
|
|
m_gridHelper = NULL;
|
2015-04-20 14:59:25 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
void PNS_ROUTER::SetView( KIGFX::VIEW* aView )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_previewItems )
|
|
|
|
{
|
|
|
|
m_previewItems->FreeItems();
|
|
|
|
delete m_previewItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_view = aView;
|
2013-10-14 14:13:35 +00:00
|
|
|
m_previewItems = new KIGFX::VIEW_GROUP( m_view );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_previewItems->SetLayer( ITEM_GAL_LAYER( GP_OVERLAY ) );
|
|
|
|
m_view->Add( m_previewItems );
|
|
|
|
m_previewItems->ViewSetVisible( true );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
PNS_ROUTER* PNS_ROUTER::GetInstance()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
return theRouter;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
PNS_ROUTER::~PNS_ROUTER()
|
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
ClearWorld();
|
|
|
|
theRouter = NULL;
|
2014-03-05 15:44:08 +00:00
|
|
|
|
|
|
|
if( m_previewItems )
|
|
|
|
delete m_previewItems;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
void PNS_ROUTER::ClearWorld()
|
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_world )
|
2014-08-13 15:25:54 +00:00
|
|
|
{
|
|
|
|
m_world->KillChildren();
|
2013-09-26 21:53:54 +00:00
|
|
|
delete m_world;
|
2014-08-13 15:25:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( m_clearanceFunc )
|
|
|
|
delete m_clearanceFunc;
|
|
|
|
|
|
|
|
if( m_placer )
|
|
|
|
delete m_placer;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-02-17 13:36:51 +00:00
|
|
|
if( m_previewItems )
|
|
|
|
delete m_previewItems;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
m_clearanceFunc = NULL;
|
|
|
|
m_world = NULL;
|
|
|
|
m_placer = NULL;
|
2014-02-17 13:36:51 +00:00
|
|
|
m_previewItems = NULL;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
bool PNS_ROUTER::RoutingInProgress() const
|
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
return m_state != IDLE;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
const PNS_ITEMSET PNS_ROUTER::QueryHoverItems( const VECTOR2I& aP )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_state == IDLE )
|
|
|
|
return m_world->HitTest( aP );
|
|
|
|
else
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_placer->CurrentNode()->HitTest( aP );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const VECTOR2I PNS_ROUTER::SnapToItem( PNS_ITEM* aItem, VECTOR2I aP, bool& aSplitsSegment )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I anchor;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !aItem )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
aSplitsSegment = false;
|
|
|
|
return aP;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( aItem->Kind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
case PNS_ITEM::SOLID:
|
2014-05-16 11:37:31 +00:00
|
|
|
anchor = static_cast<PNS_SOLID*>( aItem )->Pos();
|
2013-09-26 21:53:54 +00:00
|
|
|
aSplitsSegment = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_ITEM::VIA:
|
2014-05-16 11:37:31 +00:00
|
|
|
anchor = static_cast<PNS_VIA*>( aItem )->Pos();
|
2013-09-26 21:53:54 +00:00
|
|
|
aSplitsSegment = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_ITEM::SEGMENT:
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( aItem );
|
|
|
|
const SEG& s = seg->Seg();
|
|
|
|
int w = seg->Width();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
aSplitsSegment = false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( ( aP - s.A ).EuclideanNorm() < w / 2 )
|
|
|
|
anchor = s.A;
|
|
|
|
else if( ( aP - s.B ).EuclideanNorm() < w / 2 )
|
|
|
|
anchor = s.B;
|
|
|
|
else
|
|
|
|
{
|
2015-11-03 16:19:42 +00:00
|
|
|
anchor = m_gridHelper->AlignToSegment ( aP, s );
|
|
|
|
aSplitsSegment = (anchor != s.A && anchor != s.B );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return anchor;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool PNS_ROUTER::StartDragging( const VECTOR2I& aP, PNS_ITEM* aStartItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !aStartItem || aStartItem->OfKind( PNS_ITEM::SOLID ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-31 14:04:25 +00:00
|
|
|
m_dragger = new PNS_DRAGGER( this );
|
2014-05-14 13:53:54 +00:00
|
|
|
m_dragger->SetWorld( m_world );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( m_dragger->Start ( aP, aStartItem ) )
|
|
|
|
m_state = DRAG_SEGMENT;
|
2013-09-26 21:53:54 +00:00
|
|
|
else
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
delete m_dragger;
|
|
|
|
m_state = IDLE;
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
bool PNS_ROUTER::StartRouting( const VECTOR2I& aP, PNS_ITEM* aStartItem, int aLayer )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-21 14:37:44 +00:00
|
|
|
m_clearanceFunc->UseDpGap( false );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( m_mode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case PNS_MODE_ROUTE_SINGLE:
|
|
|
|
m_placer = new PNS_LINE_PLACER( this );
|
|
|
|
break;
|
|
|
|
case PNS_MODE_ROUTE_DIFF_PAIR:
|
|
|
|
m_placer = new PNS_DIFF_PAIR_PLACER( this );
|
|
|
|
m_clearanceFunc->UseDpGap( true );
|
|
|
|
break;
|
|
|
|
case PNS_MODE_TUNE_SINGLE:
|
|
|
|
m_placer = new PNS_MEANDER_PLACER( this );
|
|
|
|
break;
|
|
|
|
case PNS_MODE_TUNE_DIFF_PAIR:
|
|
|
|
m_placer = new PNS_DP_MEANDER_PLACER( this );
|
|
|
|
break;
|
|
|
|
case PNS_MODE_TUNE_DIFF_PAIR_SKEW:
|
|
|
|
m_placer = new PNS_MEANDER_SKEW_PLACER( this );
|
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
m_placer->UpdateSizes ( m_sizes );
|
|
|
|
m_placer->SetLayer( aLayer );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool rv = m_placer->Start( aP, aStartItem );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !rv )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentEnd = aP;
|
2014-11-14 18:15:58 +00:00
|
|
|
m_state = ROUTE_TRACK;
|
2015-02-18 00:29:54 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
BOARD* PNS_ROUTER::GetBoard()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_board;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_ROUTER::eraseView()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
BOOST_FOREACH( BOARD_ITEM* item, m_hiddenItems )
|
2014-06-24 16:17:18 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
item->ViewSetVisible( true );
|
|
|
|
}
|
|
|
|
|
2014-05-04 18:20:49 +00:00
|
|
|
m_hiddenItems.clear();
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_previewItems )
|
2014-03-05 15:44:08 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
m_previewItems->FreeItems();
|
2014-03-05 15:44:08 +00:00
|
|
|
m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_ROUTER::DisplayItem( const PNS_ITEM* aItem, int aColor, int aClearance )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_previewItems );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aColor >= 0 )
|
2015-07-07 16:36:38 +00:00
|
|
|
pitem->SetColor( KIGFX::COLOR4D( aColor ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aClearance >= 0 )
|
|
|
|
pitem->SetClearance( aClearance );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
m_previewItems->Add( pitem );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
pitem->ViewSetVisible( true );
|
2013-10-14 14:13:35 +00:00
|
|
|
m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY | KIGFX::VIEW_ITEM::APPEARANCE );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_ROUTER::DisplayItems( const PNS_ITEMSET& aItems )
|
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
BOOST_FOREACH( const PNS_ITEM* item, aItems.CItems() )
|
2014-05-16 11:37:31 +00:00
|
|
|
DisplayItem( item );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
void PNS_ROUTER::DisplayDebugLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_previewItems );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
pitem->Line( aLine, aWidth, aType );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_previewItems->Add( pitem );
|
|
|
|
pitem->ViewSetVisible( true );
|
2013-10-14 14:13:35 +00:00
|
|
|
m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY | KIGFX::VIEW_ITEM::APPEARANCE );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void PNS_ROUTER::DisplayDebugPoint( const VECTOR2I aPos, int aType )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_previewItems );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
pitem->Point( aPos, aType );
|
2014-05-14 13:53:54 +00:00
|
|
|
m_previewItems->Add( pitem );
|
|
|
|
pitem->ViewSetVisible( true );
|
|
|
|
m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY | KIGFX::VIEW_ITEM::APPEARANCE );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
void PNS_ROUTER::Move( const VECTOR2I& aP, PNS_ITEM* endItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentEnd = aP;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( m_state )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case ROUTE_TRACK:
|
|
|
|
movePlacing( aP, endItem );
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case DRAG_SEGMENT:
|
|
|
|
moveDragging( aP, endItem );
|
|
|
|
break;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void PNS_ROUTER::moveDragging( const VECTOR2I& aP, PNS_ITEM* aEndItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
eraseView();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_dragger->Drag( aP );
|
|
|
|
PNS_ITEMSET dragged = m_dragger->Traces();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
updateView( m_dragger->CurrentNode(), dragged );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void PNS_ROUTER::markViolations( PNS_NODE* aNode, PNS_ITEMSET& aCurrent,
|
|
|
|
PNS_NODE::ITEM_VECTOR& aRemoved )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-31 14:04:25 +00:00
|
|
|
BOOST_FOREACH( PNS_ITEM* item, aCurrent.Items() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE::OBSTACLES obstacles;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aNode->QueryColliding( item, obstacles, PNS_ITEM::ANY );
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( item->OfKind( PNS_ITEM::LINE ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-31 14:04:25 +00:00
|
|
|
PNS_LINE* l = static_cast<PNS_LINE*>( item );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( l->EndsWithVia() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-31 14:04:25 +00:00
|
|
|
PNS_VIA v( l->Via() );
|
2014-05-16 11:37:31 +00:00
|
|
|
aNode->QueryColliding( &v, obstacles, PNS_ITEM::ANY );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
BOOST_FOREACH( PNS_OBSTACLE& obs, obstacles )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-29 11:48:14 +00:00
|
|
|
int clearance = aNode->GetClearance( item, obs.m_item );
|
2014-05-16 11:37:31 +00:00
|
|
|
std::auto_ptr<PNS_ITEM> tmp( obs.m_item->Clone() );
|
|
|
|
tmp->Mark( MK_VIOLATION );
|
2014-05-14 13:53:54 +00:00
|
|
|
DisplayItem( tmp.get(), -1, clearance );
|
2014-05-16 11:37:31 +00:00
|
|
|
aRemoved.push_back( obs.m_item );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void PNS_ROUTER::updateView( PNS_NODE* aNode, PNS_ITEMSET& aCurrent )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE::ITEM_VECTOR removed, added;
|
|
|
|
PNS_NODE::OBSTACLES obstacles;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !aNode )
|
2014-05-14 13:53:54 +00:00
|
|
|
return;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( Settings().Mode() == RM_MarkObstacles )
|
2014-11-14 19:19:00 +00:00
|
|
|
markViolations( aNode, aCurrent, removed );
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aNode->GetUpdatedItems( removed, added );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
BOOST_FOREACH( PNS_ITEM* item, added )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
DisplayItem( item );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
BOOST_FOREACH( PNS_ITEM* item, removed )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
BOARD_CONNECTED_ITEM* parent = item->Parent();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( parent )
|
|
|
|
{
|
|
|
|
if( parent->ViewIsVisible() )
|
|
|
|
m_hiddenItems.insert( parent );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
parent->ViewSetVisible( false );
|
2013-10-14 14:13:35 +00:00
|
|
|
parent->ViewUpdate( KIGFX::VIEW_ITEM::APPEARANCE );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
void PNS_ROUTER::UpdateSizes ( const PNS_SIZES_SETTINGS& aSizes )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
m_sizes = aSizes;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// Change track/via size settings
|
|
|
|
if( m_state == ROUTE_TRACK)
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
m_placer->UpdateSizes( m_sizes );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void PNS_ROUTER::movePlacing( const VECTOR2I& aP, PNS_ITEM* aEndItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
eraseView();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
m_placer->Move( aP, aEndItem );
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_ITEMSET current = m_placer->Traces();
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
BOOST_FOREACH( const PNS_ITEM* item, current.CItems() )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !item->OfKind( PNS_ITEM::LINE ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
continue;
|
|
|
|
|
2015-07-07 16:36:38 +00:00
|
|
|
const PNS_LINE* l = static_cast<const PNS_LINE*>( item );
|
2015-02-18 16:53:46 +00:00
|
|
|
DisplayItem( l );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( l->EndsWithVia() )
|
|
|
|
DisplayItem( &l->Via() );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
//PNS_ITEMSET tmp( ¤t );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
updateView( m_placer->CurrentNode( true ), current );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_ROUTER::CommitRouting( PNS_NODE* aNode )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE::ITEM_VECTOR removed, added;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
aNode->GetUpdatedItems( removed, added );
|
|
|
|
|
|
|
|
for( unsigned int i = 0; i < removed.size(); i++ )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
BOARD_CONNECTED_ITEM* parent = removed[i]->Parent();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( parent )
|
|
|
|
{
|
2014-01-30 10:32:08 +00:00
|
|
|
m_view->Remove( parent );
|
2014-05-14 13:53:54 +00:00
|
|
|
m_board->Remove( parent );
|
|
|
|
m_undoBuffer.PushItem( ITEM_PICKER( parent, UR_DELETED ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH( PNS_ITEM* item, added )
|
|
|
|
{
|
2014-01-29 14:35:25 +00:00
|
|
|
BOARD_CONNECTED_ITEM* newBI = NULL;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( item->Kind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
case PNS_ITEM::SEGMENT:
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
PNS_SEGMENT* seg = static_cast<PNS_SEGMENT*>( item );
|
|
|
|
TRACK* track = new TRACK( m_board );
|
|
|
|
const SEG& s = seg->Seg();
|
|
|
|
|
|
|
|
track->SetStart( wxPoint( s.A.x, s.A.y ) );
|
|
|
|
track->SetEnd( wxPoint( s.B.x, s.B.y ) );
|
|
|
|
track->SetWidth( seg->Width() );
|
2014-06-29 13:05:51 +00:00
|
|
|
track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) );
|
2014-11-27 10:47:17 +00:00
|
|
|
track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 );
|
2014-05-16 11:37:31 +00:00
|
|
|
newBI = track;
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
case PNS_ITEM::VIA:
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
VIA* via_board = new VIA( m_board );
|
|
|
|
PNS_VIA* via = static_cast<PNS_VIA*>( item );
|
|
|
|
via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
|
|
|
|
via_board->SetWidth( via->Diameter() );
|
|
|
|
via_board->SetDrill( via->Drill() );
|
2014-11-27 10:51:16 +00:00
|
|
|
via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
|
2014-07-28 09:32:15 +00:00
|
|
|
via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
|
2014-07-27 19:01:06 +00:00
|
|
|
via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
|
|
|
|
ToLAYER_ID( via->Layers().End() ) );
|
2014-05-16 11:37:31 +00:00
|
|
|
newBI = via_board;
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( newBI )
|
|
|
|
{
|
|
|
|
item->SetParent( newBI );
|
|
|
|
newBI->ClearFlags();
|
|
|
|
m_view->Add( newBI );
|
|
|
|
m_board->Add( newBI );
|
2014-01-30 10:32:08 +00:00
|
|
|
m_undoBuffer.PushItem( ITEM_PICKER( newBI, UR_NEW ) );
|
2013-10-14 14:13:35 +00:00
|
|
|
newBI->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-09 18:04:54 +00:00
|
|
|
m_board->GetRatsnest()->Recalculate();
|
2013-09-26 21:53:54 +00:00
|
|
|
m_world->Commit( aNode );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
bool PNS_ROUTER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
bool rv = false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( m_state )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case ROUTE_TRACK:
|
|
|
|
rv = m_placer->FixRoute( aP, aEndItem );
|
|
|
|
break;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case DRAG_SEGMENT:
|
|
|
|
rv = m_dragger->FixRoute();
|
|
|
|
break;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-05-29 11:48:14 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( rv )
|
2014-05-14 13:53:54 +00:00
|
|
|
StopRouting();
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return rv;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
void PNS_ROUTER::StopRouting()
|
|
|
|
{
|
2014-01-07 13:22:37 +00:00
|
|
|
// Update the ratsnest with new changes
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( m_placer )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
std::vector<int> nets;
|
|
|
|
m_placer->GetModifiedNets( nets );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
BOOST_FOREACH ( int n, nets )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
// Update the ratsnest with new changes
|
|
|
|
m_board->GetRatsnest()->Recalculate( n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !RoutingInProgress() )
|
|
|
|
return;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_placer )
|
2014-05-14 13:53:54 +00:00
|
|
|
delete m_placer;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_dragger )
|
2014-05-14 13:53:54 +00:00
|
|
|
delete m_dragger;
|
|
|
|
|
|
|
|
m_placer = NULL;
|
|
|
|
m_dragger = NULL;
|
|
|
|
|
|
|
|
eraseView();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
m_state = IDLE;
|
|
|
|
m_world->KillChildren();
|
2014-05-14 13:53:54 +00:00
|
|
|
m_world->ClearRanks();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
void PNS_ROUTER::FlipPosture()
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_state == ROUTE_TRACK )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
m_placer->FlipPosture();
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
void PNS_ROUTER::SwitchLayer( int aLayer )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
switch( m_state )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case ROUTE_TRACK:
|
|
|
|
m_placer->SetLayer( aLayer );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
void PNS_ROUTER::ToggleViaPlacement()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_state == ROUTE_TRACK )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
bool toggle = !m_placer->IsPlacingVia();
|
2014-11-14 18:15:58 +00:00
|
|
|
m_placer->ToggleVia( toggle );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-21 14:35:34 +00:00
|
|
|
const std::vector<int> PNS_ROUTER::GetCurrentNets() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
if( m_placer )
|
2015-08-21 14:35:34 +00:00
|
|
|
return m_placer->CurrentNets();
|
|
|
|
|
|
|
|
return std::vector<int>();
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int PNS_ROUTER::GetCurrentLayer() const
|
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
if( m_placer )
|
|
|
|
return m_placer->CurrentLayer();
|
|
|
|
return -1;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void PNS_ROUTER::DumpLog()
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_LOGGER* logger = NULL;
|
|
|
|
|
|
|
|
switch( m_state )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case DRAG_SEGMENT:
|
|
|
|
logger = m_dragger->Logger();
|
|
|
|
break;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case ROUTE_TRACK:
|
|
|
|
logger = m_placer->Logger();
|
|
|
|
break;
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-05-29 11:48:14 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( logger )
|
2014-05-31 14:04:25 +00:00
|
|
|
logger->Save( "/tmp/shove.log" );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
bool PNS_ROUTER::IsPlacingVia() const
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_placer )
|
2015-03-09 10:06:54 +00:00
|
|
|
return false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
return m_placer->IsPlacingVia();
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void PNS_ROUTER::SetOrthoMode( bool aEnable )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_placer )
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_placer->SetOrthoMode( aEnable );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
void PNS_ROUTER::SetMode( PNS_ROUTER_MODE aMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_mode = aMode;
|
|
|
|
}
|