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
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 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
|
|
|
*/
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <cstdio>
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <view/view.h>
|
|
|
|
#include <view/view_item.h>
|
|
|
|
#include <view/view_group.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2017-01-25 09:33:49 +00:00
|
|
|
#include <gal/color4d.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
#include <geometry/shape_circle.h>
|
2017-03-22 13:51:07 +00:00
|
|
|
#include <geometry/convex_hull.h>
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#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"
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
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.
|
2016-08-29 17:31:13 +00:00
|
|
|
static ROUTER* theRouter;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER::ROUTER()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
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_state = IDLE;
|
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:
|
2016-08-29 17:48:16 +00:00
|
|
|
m_lastNode = nullptr;
|
2015-04-20 14:59:25 +00:00
|
|
|
m_iterLimit = 0;
|
|
|
|
m_showInterSteps = false;
|
|
|
|
m_snapshotIter = 0;
|
|
|
|
m_violation = false;
|
2016-12-30 11:39:41 +00:00
|
|
|
m_iface = nullptr;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER* 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ROUTER::~ROUTER()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
ClearWorld();
|
2016-08-29 17:48:16 +00:00
|
|
|
theRouter = nullptr;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
|
|
|
|
void ROUTER::SyncWorld()
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
ClearWorld();
|
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
m_world = std::make_unique<NODE>( );
|
2016-08-29 17:48:16 +00:00
|
|
|
m_iface->SyncWorld( m_world.get() );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::ClearWorld()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_world )
|
2014-08-13 15:25:54 +00:00
|
|
|
{
|
|
|
|
m_world->KillChildren();
|
2016-08-29 17:48:16 +00:00
|
|
|
m_world.reset();
|
2014-08-13 15:25:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:48:16 +00:00
|
|
|
m_placer.reset();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool ROUTER::RoutingInProgress() const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
return m_state != IDLE;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2018-01-01 23:47:46 +00:00
|
|
|
if( m_state == IDLE || m_placer == nullptr )
|
2013-09-26 21:53:54 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM* aStartItem, int aDragMode )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
|
|
|
|
if( aDragMode & DM_FREE_ANGLE )
|
|
|
|
m_forceMarkObstaclesMode = true;
|
|
|
|
else
|
|
|
|
m_forceMarkObstaclesMode = false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( !aStartItem || aStartItem->OfKind( ITEM::SOLID_T ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
m_placer = std::make_unique<LINE_PLACER>( this );
|
2018-09-16 03:18:59 +00:00
|
|
|
m_placer->Start( aP, aStartItem );
|
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
m_dragger = std::make_unique<DRAGGER>( this );
|
2017-08-03 15:53:07 +00:00
|
|
|
m_dragger->SetMode( aDragMode );
|
2016-08-29 17:48:16 +00:00
|
|
|
m_dragger->SetWorld( m_world.get() );
|
2016-08-15 15:16:48 +00:00
|
|
|
m_dragger->SetDebugDecorator ( m_iface->GetDebugDecorator () );
|
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
|
|
|
{
|
2016-08-29 17:48:16 +00:00
|
|
|
m_dragger.reset();
|
2014-05-14 13:53:54 +00:00
|
|
|
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
|
|
|
|
2018-02-03 09:39:46 +00:00
|
|
|
bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, int aLayer )
|
|
|
|
{
|
2019-02-23 16:07:04 +00:00
|
|
|
if( Settings().CanViolateDRC() && Settings().Mode() == RM_MarkObstacles )
|
|
|
|
return true;
|
|
|
|
|
2018-02-03 09:39:46 +00:00
|
|
|
auto candidates = QueryHoverItems( aWhere );
|
|
|
|
|
|
|
|
for( ITEM* item : candidates.Items() )
|
|
|
|
{
|
|
|
|
if( ! item->IsRoutable() && item->Layers().Overlaps( aLayer ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-24 15:14:38 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool ROUTER::StartRouting( const VECTOR2I& aP, ITEM* aStartItem, int aLayer )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2018-02-03 09:39:46 +00:00
|
|
|
|
|
|
|
if( ! isStartingPointRoutable( aP, aLayer ) )
|
|
|
|
{
|
2018-02-04 12:09:30 +00:00
|
|
|
SetFailureReason( _("Cannot start routing inside a keepout area or board outline." ) );
|
2018-02-03 09:39:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
m_forceMarkObstaclesMode = false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( m_mode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
case PNS_MODE_ROUTE_SINGLE:
|
2019-12-05 13:43:55 +00:00
|
|
|
m_placer = std::make_unique<LINE_PLACER>( this );
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
|
|
|
case PNS_MODE_ROUTE_DIFF_PAIR:
|
2019-12-05 13:43:55 +00:00
|
|
|
m_placer = std::make_unique<DIFF_PAIR_PLACER>( this );
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
|
|
|
case PNS_MODE_TUNE_SINGLE:
|
2019-12-05 13:43:55 +00:00
|
|
|
m_placer = std::make_unique<MEANDER_PLACER>( this );
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
|
|
|
case PNS_MODE_TUNE_DIFF_PAIR:
|
2019-12-05 13:43:55 +00:00
|
|
|
m_placer = std::make_unique<DP_MEANDER_PLACER>( this );
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
|
|
|
case PNS_MODE_TUNE_DIFF_PAIR_SKEW:
|
2019-12-05 13:43:55 +00:00
|
|
|
m_placer = std::make_unique<MEANDER_SKEW_PLACER>( this );
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-15 15:16:47 +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 );
|
2016-08-15 15:16:48 +00:00
|
|
|
m_placer->SetDebugDecorator ( m_iface->GetDebugDecorator () );
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::DisplayItems( const ITEM_SET& aItems )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : aItems.CItems() )
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->DisplayItem( item );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::Move( const VECTOR2I& aP, 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
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::moveDragging( const VECTOR2I& aP, ITEM* aEndItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->EraseView();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_dragger->Drag( aP );
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET dragged = m_dragger->Traces();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-04-08 04:24:30 +00:00
|
|
|
updateView( m_dragger->CurrentNode(), dragged, true );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
void ROUTER::markViolations( NODE* aNode, ITEM_SET& aCurrent, NODE::ITEM_VECTOR& aRemoved )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : aCurrent.Items() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OBSTACLES obstacles;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
aNode->QueryColliding( item, obstacles, ITEM::ANY_T );
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( item->OfKind( ITEM::LINE_T ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE* l = static_cast<LINE*>( item );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( l->EndsWithVia() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA v( l->Via() );
|
|
|
|
aNode->QueryColliding( &v, obstacles, ITEM::ANY_T );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( 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 );
|
2016-08-29 17:31:13 +00:00
|
|
|
std::unique_ptr<ITEM> tmp( obs.m_item->Clone() );
|
2014-05-16 11:37:31 +00:00
|
|
|
tmp->Mark( MK_VIOLATION );
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->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
|
|
|
|
|
|
|
|
2019-04-08 04:24:30 +00:00
|
|
|
void ROUTER::updateView( NODE* aNode, ITEM_SET& aCurrent, bool aDragging )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::ITEM_VECTOR removed, added;
|
|
|
|
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
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
if( Settings().Mode() == RM_MarkObstacles || m_forceMarkObstaclesMode )
|
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
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
for( auto item : added )
|
2019-04-08 04:24:30 +00:00
|
|
|
{
|
|
|
|
int clearance = GetRuleResolver()->Clearance( item->Net() );
|
|
|
|
|
|
|
|
m_iface->DisplayItem( item, -1, clearance, aDragging );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
for( auto item : removed )
|
|
|
|
m_iface->HideItem( item );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
void ROUTER::UpdateSizes( const 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
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->EraseView();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
m_placer->Move( aP, aEndItem );
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET current = m_placer->Traces();
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : current.CItems() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( !item->OfKind( ITEM::LINE_T ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
continue;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE* l = static_cast<const LINE*>( item );
|
2017-01-25 09:33:49 +00:00
|
|
|
int clearance = GetRuleResolver()->Clearance( item->Net() );
|
|
|
|
|
|
|
|
m_iface->DisplayItem( l, -1, clearance );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( l->EndsWithVia() )
|
2017-01-25 09:33:49 +00:00
|
|
|
m_iface->DisplayItem( &l->Via(), -1, clearance );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
//ITEM_SET 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::CommitRouting( NODE* aNode )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::ITEM_VECTOR removed, added;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
aNode->GetUpdatedItems( removed, added );
|
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
for( auto item : removed )
|
|
|
|
m_iface->RemoveItem( item );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2017-01-25 09:33:49 +00:00
|
|
|
for( auto item : added )
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->AddItem( item );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->Commit();
|
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
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
bool ROUTER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
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:
|
2018-06-19 17:29:36 +00:00
|
|
|
rv = m_placer->FixRoute( aP, aEndItem, aForceFinish );
|
2015-10-05 16:28:41 +00:00
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::StopRouting()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
// Update the ratsnest with new changes
|
2016-08-29 14:38:11 +00:00
|
|
|
for ( auto n : nets )
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->UpdateNet( n );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !RoutingInProgress() )
|
|
|
|
return;
|
|
|
|
|
2016-08-29 17:48:16 +00:00
|
|
|
m_placer.reset();
|
|
|
|
m_dragger.reset();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
m_iface->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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::FlipPosture()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const std::vector<int> 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int ROUTER::GetCurrentLayer() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
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
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::DumpLog()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:48:16 +00:00
|
|
|
LOGGER* logger = nullptr;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool ROUTER::IsPlacingVia() const
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::SetOrthoMode( bool aEnable )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::SetMode( ROUTER_MODE aMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_mode = aMode;
|
|
|
|
}
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::SetInterface( ROUTER_IFACE *aIface )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
|
|
|
m_iface = aIface;
|
|
|
|
m_iface->SetRouter( this );
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
void ROUTER::BreakSegment( ITEM *aItem, const VECTOR2I& aP )
|
|
|
|
{
|
|
|
|
NODE *node = m_world->Branch();
|
|
|
|
|
|
|
|
LINE_PLACER placer( this );
|
|
|
|
|
|
|
|
if ( placer.SplitAdjacentSegments( node, aItem, aP ) )
|
|
|
|
{
|
|
|
|
CommitRouting( node );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|