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
|
2024-01-02 14:54:11 +00:00
|
|
|
* Copyright (C) 2016-2024 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 <gal/graphics_abstraction_layer.h>
|
|
|
|
|
2023-08-07 16:58:41 +00:00
|
|
|
#include <advanced_config.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <pcb_painter.h>
|
2021-01-05 18:45:32 +00:00
|
|
|
#include <pad.h>
|
|
|
|
#include <zone.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <geometry/shape.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"
|
2020-02-28 22:13:25 +00:00
|
|
|
#include "pns_component_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"
|
2023-12-08 16:01:27 +00:00
|
|
|
#include "router_preview_item.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
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
|
|
|
|
2023-08-07 16:58:41 +00:00
|
|
|
m_logger = nullptr;
|
|
|
|
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_EnableRouterDump )
|
|
|
|
m_logger = new LOGGER;
|
2020-04-16 22:29:28 +00:00
|
|
|
|
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;
|
2020-01-13 01:44:19 +00:00
|
|
|
m_settings = nullptr;
|
2016-12-30 11:39:41 +00:00
|
|
|
m_iface = nullptr;
|
2021-02-17 21:01:09 +00:00
|
|
|
m_visibleViewArea.SetMaximum();
|
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;
|
2020-04-16 22:29:28 +00:00
|
|
|
delete m_logger;
|
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() );
|
2021-06-03 20:36:06 +00:00
|
|
|
m_world->FixupVirtualVias();
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-06-03 20:36:06 +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
|
|
|
{
|
2023-05-31 21:20:28 +00:00
|
|
|
m_world->SetRuleResolver( nullptr );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-21 12:58:37 +00:00
|
|
|
const ITEM_SET ROUTER::QueryHoverItems( const VECTOR2I& aP, int aSlopRadius )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2023-12-21 12:58:37 +00:00
|
|
|
NODE* node = m_placer ? m_placer->CurrentNode() : m_world.get();
|
2023-10-16 21:04:01 +00:00
|
|
|
PNS::ITEM_SET ret;
|
|
|
|
|
|
|
|
wxCHECK( node, ret );
|
|
|
|
|
2023-12-21 12:58:37 +00:00
|
|
|
if( aSlopRadius > 0 )
|
2023-04-09 17:31:11 +00:00
|
|
|
{
|
|
|
|
NODE::OBSTACLES obs;
|
2023-08-22 12:06:33 +00:00
|
|
|
SEGMENT test( SEG( aP, aP ), nullptr );
|
2023-04-09 17:31:11 +00:00
|
|
|
COLLISION_SEARCH_OPTIONS opts;
|
2022-08-15 13:31:43 +00:00
|
|
|
|
2023-04-09 17:31:11 +00:00
|
|
|
test.SetWidth( 1 );
|
|
|
|
test.SetLayers( LAYER_RANGE::All() );
|
2022-08-15 13:31:43 +00:00
|
|
|
|
2023-04-09 17:31:11 +00:00
|
|
|
opts.m_differentNetsOnly = false;
|
2023-12-21 12:58:37 +00:00
|
|
|
opts.m_overrideClearance = aSlopRadius;
|
2021-06-06 18:16:31 +00:00
|
|
|
|
2023-08-27 19:16:29 +00:00
|
|
|
node->QueryColliding( &test, obs, opts );
|
|
|
|
|
|
|
|
for( const OBSTACLE& obstacle : obs )
|
|
|
|
ret.Add( obstacle.m_item, false );
|
2021-06-06 18:16:31 +00:00
|
|
|
|
2023-04-09 17:31:11 +00:00
|
|
|
return ret;
|
2021-06-06 18:16:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
else
|
2023-03-02 14:04:37 +00:00
|
|
|
{
|
2023-04-09 17:31:11 +00:00
|
|
|
return node->HitTest( aP );
|
2023-03-02 14:04:37 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2020-02-28 22:13:25 +00:00
|
|
|
bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM* aItem, int aDragMode )
|
|
|
|
{
|
|
|
|
return StartDragging( aP, ITEM_SET( aItem ), aDragMode );
|
|
|
|
}
|
|
|
|
|
2017-01-24 15:14:38 +00:00
|
|
|
|
2020-02-28 22:13:25 +00:00
|
|
|
bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragMode )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2020-02-28 22:13:25 +00:00
|
|
|
if( aStartItems.Empty() )
|
|
|
|
return false;
|
2017-08-03 15:53:07 +00:00
|
|
|
|
2022-11-16 21:05:12 +00:00
|
|
|
GetRuleResolver()->ClearCaches();
|
|
|
|
|
2020-02-28 22:13:25 +00:00
|
|
|
if( aStartItems.Count( ITEM::SOLID_T ) == aStartItems.Size() )
|
|
|
|
{
|
|
|
|
m_dragger = std::make_unique<COMPONENT_DRAGGER>( this );
|
2021-12-15 00:46:03 +00:00
|
|
|
m_state = DRAG_COMPONENT;
|
2020-02-28 22:13:25 +00:00
|
|
|
}
|
2017-08-03 15:53:07 +00:00
|
|
|
else
|
2020-02-28 22:13:25 +00:00
|
|
|
{
|
|
|
|
m_dragger = std::make_unique<DRAGGER>( this );
|
2021-12-15 00:46:03 +00:00
|
|
|
m_state = DRAG_SEGMENT;
|
2020-02-28 22:13:25 +00:00
|
|
|
}
|
2018-09-16 03:18:59 +00:00
|
|
|
|
2023-01-27 08:06:33 +00:00
|
|
|
m_dragger->SetMode( static_cast<PNS::DRAG_MODE>( aDragMode ) );
|
2016-08-29 17:48:16 +00:00
|
|
|
m_dragger->SetWorld( m_world.get() );
|
2020-04-16 22:29:28 +00:00
|
|
|
m_dragger->SetLogger( m_logger );
|
2021-02-25 16:18:13 +00:00
|
|
|
m_dragger->SetDebugDecorator( m_iface->GetDebugDecorator() );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
if( m_logger )
|
|
|
|
m_logger->Clear();
|
2020-10-18 21:00:33 +00:00
|
|
|
|
|
|
|
if( m_logger && aStartItems.Size() )
|
|
|
|
m_logger->Log( LOGGER::EVT_START_DRAG, aP, aStartItems[0] );
|
|
|
|
|
2021-02-25 16:18:13 +00:00
|
|
|
if( m_dragger->Start( aP, aStartItems ) )
|
2020-11-01 20:24:58 +00:00
|
|
|
{
|
2021-07-09 09:25:19 +00:00
|
|
|
return true;
|
2020-11-01 20:24:58 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-05 18:45:32 +00:00
|
|
|
|
2020-11-01 23:46:09 +00:00
|
|
|
bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aStartItem, int aLayer )
|
2018-02-03 09:39:46 +00:00
|
|
|
{
|
2021-04-10 09:31:42 +00:00
|
|
|
if( Settings().AllowDRCViolations() )
|
2019-02-23 16:07:04 +00:00
|
|
|
return true;
|
|
|
|
|
2021-03-30 18:48:36 +00:00
|
|
|
if( m_mode == PNS_MODE_ROUTE_DIFF_PAIR )
|
|
|
|
{
|
|
|
|
if( m_sizes.DiffPairGap() < m_sizes.MinClearance() )
|
|
|
|
{
|
|
|
|
SetFailureReason( _( "Diff pair gap is less than board minimum clearance." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-01 23:46:09 +00:00
|
|
|
ITEM_SET candidates = QueryHoverItems( aWhere );
|
2022-10-07 17:11:19 +00:00
|
|
|
wxString failureReason;
|
2018-02-03 09:39:46 +00:00
|
|
|
|
|
|
|
for( ITEM* item : candidates.Items() )
|
|
|
|
{
|
2022-10-07 17:11:19 +00:00
|
|
|
// Edge cuts are put on all layers, but they're not *really* on all layers
|
2023-04-06 16:59:43 +00:00
|
|
|
if( item->BoardItem() && item->BoardItem()->GetLayer() == Edge_Cuts )
|
2022-06-29 19:43:07 +00:00
|
|
|
continue;
|
|
|
|
|
2022-10-07 17:11:19 +00:00
|
|
|
if( !item->Layers().Overlaps( aLayer ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->IsRoutable() )
|
|
|
|
{
|
|
|
|
failureReason = wxEmptyString;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2021-01-05 18:45:32 +00:00
|
|
|
{
|
2023-04-06 16:59:43 +00:00
|
|
|
BOARD_ITEM* parent = item->BoardItem();
|
2021-01-05 18:45:32 +00:00
|
|
|
|
|
|
|
switch( parent->Type() )
|
|
|
|
{
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
PAD* pad = static_cast<PAD*>( parent );
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
|
2022-10-07 17:11:19 +00:00
|
|
|
failureReason = _( "Cannot start routing from a non-plated hole." );
|
2021-01-05 18:45:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_ZONE_T:
|
|
|
|
{
|
|
|
|
ZONE* zone = static_cast<ZONE*>( parent );
|
|
|
|
|
|
|
|
if( !zone->GetZoneName().IsEmpty() )
|
|
|
|
{
|
2022-10-07 17:11:19 +00:00
|
|
|
failureReason = wxString::Format( _( "Rule area '%s' disallows tracks." ),
|
|
|
|
zone->GetZoneName() );
|
2021-01-05 18:45:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-07 17:11:19 +00:00
|
|
|
failureReason = _( "Rule area disallows tracks." );
|
2021-01-05 18:45:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-06 15:09:34 +00:00
|
|
|
case PCB_FIELD_T:
|
2021-01-05 18:45:32 +00:00
|
|
|
case PCB_TEXT_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
2022-10-07 17:11:19 +00:00
|
|
|
failureReason = _( "Cannot start routing from a text item." );
|
2021-01-05 18:45:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-02-03 09:39:46 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 17:11:19 +00:00
|
|
|
if( !failureReason.IsEmpty() )
|
|
|
|
{
|
|
|
|
SetFailureReason( failureReason );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-21 14:30:28 +00:00
|
|
|
VECTOR2I startPoint = aWhere;
|
2021-01-05 18:45:32 +00:00
|
|
|
|
|
|
|
if( m_mode == PNS_MODE_ROUTE_SINGLE )
|
2020-11-01 23:46:09 +00:00
|
|
|
{
|
2021-01-04 17:51:50 +00:00
|
|
|
SHAPE_LINE_CHAIN dummyStartSeg;
|
|
|
|
LINE dummyStartLine;
|
2020-11-01 23:46:09 +00:00
|
|
|
|
2021-01-04 17:51:50 +00:00
|
|
|
dummyStartSeg.Append( startPoint );
|
|
|
|
dummyStartSeg.Append( startPoint, true );
|
|
|
|
|
|
|
|
dummyStartLine.SetShape( dummyStartSeg );
|
|
|
|
dummyStartLine.SetLayer( aLayer );
|
2021-01-05 18:45:32 +00:00
|
|
|
dummyStartLine.SetNet( aStartItem ? aStartItem->Net() : 0 );
|
2021-01-04 17:51:50 +00:00
|
|
|
dummyStartLine.SetWidth( m_sizes.TrackWidth() );
|
|
|
|
|
|
|
|
if( m_world->CheckColliding( &dummyStartLine, ITEM::ANY_T ) )
|
|
|
|
{
|
2023-05-26 03:10:00 +00:00
|
|
|
// If the only reason we collide is track width; it's better to allow the user to start
|
|
|
|
// anyway and just highlight the resulting collisions, so they can change width later.
|
|
|
|
dummyStartLine.SetWidth( m_sizes.BoardMinTrackWidth() );
|
2021-01-04 17:51:50 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
if( m_world->CheckColliding( &dummyStartLine, ITEM::ANY_T ) )
|
|
|
|
{
|
|
|
|
ITEM_SET dummyStartSet( &dummyStartLine );
|
|
|
|
NODE::ITEM_VECTOR highlightedItems;
|
2021-01-04 17:51:50 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
markViolations( m_world.get(), dummyStartSet, highlightedItems );
|
2020-11-01 23:46:09 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
for( ITEM* item : highlightedItems )
|
|
|
|
m_iface->HideItem( item );
|
|
|
|
|
|
|
|
SetFailureReason( _( "The routing start point violates DRC." ) );
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-04 17:51:50 +00:00
|
|
|
}
|
2020-11-01 23:46:09 +00:00
|
|
|
}
|
2021-01-05 18:45:32 +00:00
|
|
|
else if( m_mode == PNS_MODE_ROUTE_DIFF_PAIR )
|
2020-11-01 23:46:09 +00:00
|
|
|
{
|
2021-01-05 18:45:32 +00:00
|
|
|
if( !aStartItem )
|
|
|
|
{
|
|
|
|
SetFailureReason( _( "Cannot start a differential pair in the middle of nowhere." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DP_PRIMITIVE_PAIR dpPair;
|
|
|
|
wxString errorMsg;
|
|
|
|
|
|
|
|
if( !DIFF_PAIR_PLACER::FindDpPrimitivePair( m_world.get(), startPoint, aStartItem, dpPair,
|
|
|
|
&errorMsg ) )
|
|
|
|
{
|
|
|
|
SetFailureReason( errorMsg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN dummyStartSegA;
|
|
|
|
SHAPE_LINE_CHAIN dummyStartSegB;
|
|
|
|
LINE dummyStartLineA;
|
|
|
|
LINE dummyStartLineB;
|
|
|
|
|
|
|
|
dummyStartSegA.Append( dpPair.AnchorN() );
|
|
|
|
dummyStartSegA.Append( dpPair.AnchorN(), true );
|
|
|
|
|
|
|
|
dummyStartSegB.Append( dpPair.AnchorP() );
|
|
|
|
dummyStartSegB.Append( dpPair.AnchorP(), true );
|
|
|
|
|
|
|
|
dummyStartLineA.SetShape( dummyStartSegA );
|
|
|
|
dummyStartLineA.SetLayer( aLayer );
|
|
|
|
dummyStartLineA.SetNet( dpPair.PrimN()->Net() );
|
|
|
|
dummyStartLineA.SetWidth( m_sizes.DiffPairWidth() );
|
|
|
|
|
|
|
|
dummyStartLineB.SetShape( dummyStartSegB );
|
|
|
|
dummyStartLineB.SetLayer( aLayer );
|
|
|
|
dummyStartLineB.SetNet( dpPair.PrimP()->Net() );
|
|
|
|
dummyStartLineB.SetWidth( m_sizes.DiffPairWidth() );
|
|
|
|
|
|
|
|
if( m_world->CheckColliding( &dummyStartLineA, ITEM::ANY_T )
|
|
|
|
|| m_world->CheckColliding( &dummyStartLineB, ITEM::ANY_T ) )
|
|
|
|
{
|
2023-05-26 03:10:00 +00:00
|
|
|
// If the only reason we collide is track width; it's better to allow the user to start
|
|
|
|
// anyway and just highlight the resulting collisions, so they can change width later.
|
|
|
|
dummyStartLineA.SetWidth( m_sizes.BoardMinTrackWidth() );
|
|
|
|
dummyStartLineB.SetWidth( m_sizes.BoardMinTrackWidth() );
|
2021-01-05 18:45:32 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
if( m_world->CheckColliding( &dummyStartLineA, ITEM::ANY_T )
|
|
|
|
|| m_world->CheckColliding( &dummyStartLineB, ITEM::ANY_T ) )
|
|
|
|
{
|
|
|
|
ITEM_SET dummyStartSet;
|
|
|
|
NODE::ITEM_VECTOR highlightedItems;
|
2021-01-05 18:45:32 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
dummyStartSet.Add( dummyStartLineA );
|
|
|
|
dummyStartSet.Add( dummyStartLineB );
|
|
|
|
markViolations( m_world.get(), dummyStartSet, highlightedItems );
|
2021-01-05 18:45:32 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
for( ITEM* item : highlightedItems )
|
|
|
|
m_iface->HideItem( item );
|
|
|
|
|
|
|
|
SetFailureReason( _( "The routing start point violates DRC." ) );
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-05 18:45:32 +00:00
|
|
|
}
|
2020-11-01 23:46:09 +00:00
|
|
|
}
|
|
|
|
|
2018-02-03 09:39:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-01-24 15:14:38 +00:00
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool ROUTER::StartRouting( const VECTOR2I& aP, ITEM* aStartItem, int aLayer )
|
2021-02-08 01:06:56 +00:00
|
|
|
{
|
2022-11-16 21:05:12 +00:00
|
|
|
GetRuleResolver()->ClearCaches();
|
|
|
|
|
2021-01-04 17:51:50 +00:00
|
|
|
if( !isStartingPointRoutable( aP, aStartItem, aLayer ) )
|
2018-02-03 09:39:46 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( m_mode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-03-02 13:10:37 +00:00
|
|
|
case PNS_MODE_ROUTE_SINGLE:
|
|
|
|
m_placer = std::make_unique<LINE_PLACER>( this );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_MODE_ROUTE_DIFF_PAIR:
|
|
|
|
m_placer = std::make_unique<DIFF_PAIR_PLACER>( this );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_MODE_TUNE_SINGLE:
|
|
|
|
m_placer = std::make_unique<MEANDER_PLACER>( this );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_MODE_TUNE_DIFF_PAIR:
|
|
|
|
m_placer = std::make_unique<DP_MEANDER_PLACER>( this );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PNS_MODE_TUNE_DIFF_PAIR_SKEW:
|
|
|
|
m_placer = std::make_unique<MEANDER_SKEW_PLACER>( this );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-11-01 20:24:58 +00:00
|
|
|
m_placer->UpdateSizes( m_sizes );
|
2014-11-14 18:15:58 +00:00
|
|
|
m_placer->SetLayer( aLayer );
|
2021-02-25 16:18:13 +00:00
|
|
|
m_placer->SetDebugDecorator( m_iface->GetDebugDecorator() );
|
2020-04-16 22:29:28 +00:00
|
|
|
m_placer->SetLogger( m_logger );
|
|
|
|
|
2021-07-09 09:25:19 +00:00
|
|
|
if( m_placer->Start( aP, aStartItem ) )
|
|
|
|
{
|
|
|
|
m_state = ROUTE_TRACK;
|
2022-10-23 22:34:42 +00:00
|
|
|
|
|
|
|
if( m_logger )
|
|
|
|
{
|
|
|
|
m_logger->Clear();
|
|
|
|
m_logger->Log( LOGGER::EVT_START_ROUTE, aP, aStartItem, &m_sizes );
|
|
|
|
}
|
|
|
|
|
2021-07-09 09:25:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_state = IDLE;
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2021-07-09 09:25:19 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-05-29 11:48:14 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-06-03 21:02:32 +00:00
|
|
|
bool ROUTER::Move( const VECTOR2I& aP, ITEM* endItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2020-04-16 22:29:28 +00:00
|
|
|
if( m_logger )
|
|
|
|
m_logger->Log( LOGGER::EVT_MOVE, aP, endItem );
|
|
|
|
|
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:
|
2022-06-03 21:02:32 +00:00
|
|
|
return movePlacing( aP, endItem );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case DRAG_SEGMENT:
|
2021-12-15 22:18:53 +00:00
|
|
|
case DRAG_COMPONENT:
|
2022-06-03 21:02:32 +00:00
|
|
|
return moveDragging( aP, endItem );
|
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
|
|
|
}
|
2022-06-05 09:44:49 +00:00
|
|
|
|
2023-10-01 14:12:24 +00:00
|
|
|
GetRuleResolver()->ClearTemporaryCaches();
|
|
|
|
|
2022-06-05 09:44:49 +00:00
|
|
|
return false;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2023-03-06 19:48:42 +00:00
|
|
|
bool ROUTER::getNearestRatnestAnchor( VECTOR2I& aOtherEnd, LAYER_RANGE& aOtherEndLayers,
|
|
|
|
ITEM*& aOtherEndItem )
|
2022-09-12 13:12:11 +00:00
|
|
|
{
|
|
|
|
// Can't finish something with no connections
|
|
|
|
if( GetCurrentNets().empty() )
|
|
|
|
return false;
|
|
|
|
|
2023-03-03 21:48:40 +00:00
|
|
|
PLACEMENT_ALGO* placer = Placer();
|
2022-09-12 13:12:11 +00:00
|
|
|
|
2023-03-03 21:48:40 +00:00
|
|
|
if( placer == nullptr || placer->Traces().Size() == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LINE* trace = dynamic_cast<LINE*>( placer->Traces()[0] );
|
|
|
|
|
|
|
|
if( trace == nullptr )
|
2022-09-12 13:12:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
PNS::NODE* lastNode = placer->CurrentNode( true );
|
|
|
|
PNS::TOPOLOGY topo( lastNode );
|
|
|
|
|
|
|
|
// If the user has drawn a line, get the anchor nearest to the line end
|
2023-03-03 21:48:40 +00:00
|
|
|
if( trace->SegmentCount() > 0 )
|
2023-04-09 19:25:22 +00:00
|
|
|
{
|
2023-03-06 19:48:42 +00:00
|
|
|
return topo.NearestUnconnectedAnchorPoint( trace, aOtherEnd, aOtherEndLayers,
|
|
|
|
aOtherEndItem );
|
2023-04-09 19:25:22 +00:00
|
|
|
}
|
2022-09-12 13:12:11 +00:00
|
|
|
|
|
|
|
// Otherwise, find the closest anchor to our start point
|
|
|
|
|
|
|
|
// Get joint from placer start item
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jt = lastNode->FindJoint( placer->CurrentStart(), placer->CurrentLayer(),
|
|
|
|
placer->CurrentNets()[0] );
|
2022-09-12 13:12:11 +00:00
|
|
|
|
|
|
|
if( !jt )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get unconnected item from joint
|
|
|
|
int anchor;
|
|
|
|
PNS::ITEM* it = topo.NearestUnconnectedItem( jt, &anchor );
|
|
|
|
|
|
|
|
if( !it )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aOtherEnd = it->Anchor( anchor );
|
|
|
|
aOtherEndLayers = it->Layers();
|
2023-03-06 19:48:42 +00:00
|
|
|
aOtherEndItem = it;
|
2022-09-12 13:12:11 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ROUTER::Finish()
|
|
|
|
{
|
|
|
|
if( m_state != ROUTE_TRACK )
|
|
|
|
return false;
|
|
|
|
|
2023-03-06 19:48:42 +00:00
|
|
|
PLACEMENT_ALGO* placer = Placer();
|
|
|
|
|
|
|
|
if( placer == nullptr || placer->Traces().Size() == 0 )
|
|
|
|
return false;
|
2022-09-12 13:12:11 +00:00
|
|
|
|
2023-03-06 19:48:42 +00:00
|
|
|
LINE* current = dynamic_cast<LINE*>( placer->Traces()[0] );
|
|
|
|
|
|
|
|
if( current == nullptr )
|
2022-09-12 13:12:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get our current line and position and nearest ratsnest to them if it exists
|
|
|
|
VECTOR2I otherEnd;
|
|
|
|
LAYER_RANGE otherEndLayers;
|
2023-03-06 19:48:42 +00:00
|
|
|
ITEM* otherEndItem = nullptr;
|
2022-09-12 13:12:11 +00:00
|
|
|
|
|
|
|
// Get the anchor nearest to the end of the trace the user is routing
|
2023-03-06 19:48:42 +00:00
|
|
|
if( !getNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) )
|
2022-09-12 13:12:11 +00:00
|
|
|
return false;
|
|
|
|
|
2022-12-07 16:24:00 +00:00
|
|
|
// Keep moving until we don't change position or hit the limit
|
|
|
|
int triesLeft = 5;
|
2022-09-12 13:12:11 +00:00
|
|
|
VECTOR2I moveResultPoint;
|
2022-12-07 16:24:00 +00:00
|
|
|
|
2022-09-12 13:12:11 +00:00
|
|
|
do
|
|
|
|
{
|
2023-04-09 19:25:22 +00:00
|
|
|
moveResultPoint = placer->CurrentEnd();
|
2023-03-06 19:48:42 +00:00
|
|
|
Move( otherEnd, otherEndItem );
|
2022-12-07 16:24:00 +00:00
|
|
|
triesLeft--;
|
2023-04-09 19:25:22 +00:00
|
|
|
} while( placer->CurrentEnd() != moveResultPoint && triesLeft );
|
2022-09-12 13:12:11 +00:00
|
|
|
|
|
|
|
// If we've made it, fix the route and we're done
|
|
|
|
if( moveResultPoint == otherEnd && otherEndLayers.Overlaps( GetCurrentLayer() ) )
|
2024-01-02 14:54:11 +00:00
|
|
|
{
|
|
|
|
bool forceFinish = false;
|
|
|
|
bool allowViolations = false;
|
|
|
|
|
|
|
|
return FixRoute( otherEnd, otherEndItem, forceFinish, allowViolations );
|
|
|
|
}
|
2022-09-12 13:12:11 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-18 16:32:32 +00:00
|
|
|
bool ROUTER::ContinueFromEnd( ITEM** aNewStartItem )
|
2022-09-13 12:13:09 +00:00
|
|
|
{
|
2023-03-03 21:48:40 +00:00
|
|
|
PLACEMENT_ALGO* placer = Placer();
|
2022-09-13 12:13:09 +00:00
|
|
|
|
2023-03-03 21:48:40 +00:00
|
|
|
if( placer == nullptr || placer->Traces().Size() == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LINE* current = dynamic_cast<LINE*>( placer->Traces()[0] );
|
|
|
|
|
|
|
|
if( current == nullptr )
|
2022-09-13 12:13:09 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
int currentLayer = GetCurrentLayer();
|
|
|
|
VECTOR2I currentEnd = placer->CurrentEnd();
|
|
|
|
VECTOR2I otherEnd;
|
|
|
|
LAYER_RANGE otherEndLayers;
|
2023-03-06 19:48:42 +00:00
|
|
|
ITEM* otherEndItem = nullptr;
|
2022-09-13 12:13:09 +00:00
|
|
|
|
|
|
|
// Get the anchor nearest to the end of the trace the user is routing
|
2023-03-06 19:48:42 +00:00
|
|
|
if( !getNearestRatnestAnchor( otherEnd, otherEndLayers, otherEndItem ) )
|
2022-09-13 12:13:09 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
CommitRouting();
|
|
|
|
|
|
|
|
// Commit whatever we've fixed and restart routing from the other end
|
|
|
|
int nextLayer = otherEndLayers.Overlaps( currentLayer ) ? currentLayer : otherEndLayers.Start();
|
|
|
|
|
2023-03-06 19:48:42 +00:00
|
|
|
if( !StartRouting( otherEnd, otherEndItem, nextLayer ) )
|
2022-09-13 12:13:09 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Attempt to route to our current position
|
2023-10-18 16:32:32 +00:00
|
|
|
Move( currentEnd, nullptr );
|
|
|
|
|
|
|
|
*aNewStartItem = otherEndItem;
|
2022-09-13 12:13:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-03 21:02:32 +00:00
|
|
|
bool 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
|
|
|
|
2022-06-03 21:02:32 +00:00
|
|
|
bool ret = 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 );
|
2022-06-03 21:02:32 +00:00
|
|
|
return ret;
|
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
|
|
|
{
|
2021-01-01 17:17:55 +00:00
|
|
|
auto updateItem =
|
|
|
|
[&]( ITEM* currentItem, ITEM* itemToMark )
|
|
|
|
{
|
|
|
|
std::unique_ptr<ITEM> tmp( itemToMark->Clone() );
|
|
|
|
|
2021-08-08 19:41:39 +00:00
|
|
|
int clearance;
|
|
|
|
bool removeOriginal = true;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
clearance = aNode->GetClearance( currentItem, itemToMark );
|
2021-01-01 17:17:55 +00:00
|
|
|
|
2021-01-03 21:14:44 +00:00
|
|
|
if( itemToMark->Layers().IsMultilayer() && !currentItem->Layers().IsMultilayer() )
|
2021-02-25 23:38:54 +00:00
|
|
|
tmp->SetLayer( currentItem->Layer() );
|
2021-01-01 17:17:55 +00:00
|
|
|
|
2023-04-09 19:25:22 +00:00
|
|
|
if( itemToMark->IsCompoundShapePrimitive() )
|
2021-01-03 21:14:44 +00:00
|
|
|
{
|
2023-04-09 19:25:22 +00:00
|
|
|
// We're only highlighting one (or more) of several primitives so we don't
|
|
|
|
// want all the other parts of the object to disappear
|
|
|
|
removeOriginal = false;
|
2021-01-03 21:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_iface->DisplayItem( tmp.get(), clearance );
|
|
|
|
|
|
|
|
if( removeOriginal )
|
2021-01-01 17:17:55 +00:00
|
|
|
aRemoved.push_back( itemToMark );
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2022-08-15 13:31:43 +00:00
|
|
|
aNode->QueryColliding( item, obstacles );
|
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() );
|
2022-08-15 13:31:43 +00:00
|
|
|
aNode->QueryColliding( &v, obstacles );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-11-05 21:53:57 +00:00
|
|
|
ITEM_SET draggedItems;
|
|
|
|
|
|
|
|
if( GetDragger() )
|
|
|
|
draggedItems = GetDragger()->Traces();
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
for( const OBSTACLE& obs : obstacles )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-11-05 21:53:57 +00:00
|
|
|
// Don't mark items being dragged; only board items they collide with
|
|
|
|
if( draggedItems.Contains( obs.m_item ) )
|
|
|
|
continue;
|
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
obs.m_item->Mark( obs.m_item->Marker() | MK_VIOLATION );
|
|
|
|
updateItem( item, obs.m_item );
|
|
|
|
}
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
if( item->Kind() == ITEM::LINE_T )
|
|
|
|
{
|
|
|
|
LINE* line = static_cast<LINE*>( item );
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-01-01 17:17:55 +00:00
|
|
|
// Show clearance on any blocking obstacles
|
|
|
|
if( line->GetBlockingObstacle() )
|
|
|
|
updateItem( item, line->GetBlockingObstacle() );
|
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
|
|
|
|
2023-05-26 03:10: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
|
|
|
|
2023-05-31 21:20:28 +00:00
|
|
|
std::vector<const PNS::ITEM*> cacheCheckItems( added.begin(), added.end() );
|
|
|
|
GetRuleResolver()->ClearCacheForItems( cacheCheckItems );
|
|
|
|
|
2020-12-11 12:48:04 +00:00
|
|
|
for( ITEM* item : added )
|
2019-04-08 04:24:30 +00:00
|
|
|
{
|
2020-10-30 21:08:38 +00:00
|
|
|
int clearance = GetRuleResolver()->Clearance( item, nullptr );
|
2021-01-03 21:14:44 +00:00
|
|
|
m_iface->DisplayItem( item, clearance, aDragging );
|
2019-04-08 04:24:30 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
for( ITEM* item : removed )
|
2016-06-21 15:06:28 +00:00
|
|
|
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
|
2021-03-02 13:10:37 +00:00
|
|
|
if( m_state == ROUTE_TRACK )
|
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
|
|
|
|
|
|
|
|
2022-06-03 21:02:32 +00:00
|
|
|
bool 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
|
|
|
|
2022-06-03 21:02:32 +00:00
|
|
|
bool ret = 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 );
|
2020-10-30 21:08:38 +00:00
|
|
|
int clearance = GetRuleResolver()->Clearance( item, nullptr );
|
2017-01-25 09:33:49 +00:00
|
|
|
|
2023-12-08 16:01:27 +00:00
|
|
|
m_iface->DisplayItem( l, clearance, false, PNS_HEAD_TRACE );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( l->EndsWithVia() )
|
2021-01-01 00:29:05 +00:00
|
|
|
{
|
|
|
|
const VIA& via = l->Via();
|
2023-04-09 19:25:22 +00:00
|
|
|
clearance = GetRuleResolver()->Clearance( &via, nullptr );
|
|
|
|
|
|
|
|
if( via.HasHole() )
|
|
|
|
{
|
|
|
|
int holeClearance = GetRuleResolver()->Clearance( via.Hole(), nullptr );
|
|
|
|
int annularWidth = std::max( 0, via.Diameter() - via.Drill() ) / 2;
|
|
|
|
int excessHoleClearance = holeClearance - annularWidth;
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2023-04-09 19:25:22 +00:00
|
|
|
if( excessHoleClearance > clearance )
|
|
|
|
clearance = excessHoleClearance;
|
|
|
|
}
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2023-12-08 16:01:27 +00:00
|
|
|
m_iface->DisplayItem( &l->Via(), clearance, false, PNS_HEAD_TRACE );
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
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 );
|
2022-06-03 21:02:32 +00:00
|
|
|
|
|
|
|
return ret;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-09 22:17:50 +00:00
|
|
|
|
|
|
|
void ROUTER::GetUpdatedItems( std::vector<PNS::ITEM*>& aRemoved, std::vector<PNS::ITEM*>& aAdded,
|
|
|
|
std::vector<PNS::ITEM*>& aHeads )
|
2022-10-23 22:34:42 +00:00
|
|
|
{
|
2023-03-02 14:04:37 +00:00
|
|
|
NODE *node = nullptr;
|
2022-10-23 22:34:42 +00:00
|
|
|
ITEM_SET current;
|
|
|
|
|
|
|
|
if( m_state == ROUTE_TRACK )
|
|
|
|
{
|
|
|
|
node = m_placer->CurrentNode( true );
|
|
|
|
current = m_placer->Traces();
|
|
|
|
}
|
|
|
|
else if ( m_state == DRAG_SEGMENT )
|
|
|
|
{
|
|
|
|
node = m_dragger->CurrentNode();
|
|
|
|
current = m_dragger->Traces();
|
|
|
|
}
|
|
|
|
|
2023-03-02 14:04:37 +00:00
|
|
|
// There probably should be a debugging assertion and possibly a PNS_LOGGER call here but
|
|
|
|
// I'm not sure how to be proceed WLS.
|
|
|
|
if( !node )
|
|
|
|
return;
|
|
|
|
|
2023-01-09 22:17:50 +00:00
|
|
|
node->GetUpdatedItems( aRemoved, aAdded );
|
2022-10-23 22:34:42 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
for( const ITEM* item : current.CItems() )
|
|
|
|
aHeads.push_back( item->Clone() );
|
2022-10-23 22:34:42 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2023-01-09 22:17:50 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void ROUTER::CommitRouting( NODE* aNode )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-02-07 19:57:24 +00:00
|
|
|
if( m_state == ROUTE_TRACK && !m_placer->HasPlacedAnything() )
|
|
|
|
return;
|
|
|
|
|
2021-02-08 01:06:56 +00:00
|
|
|
NODE::ITEM_VECTOR removed;
|
|
|
|
NODE::ITEM_VECTOR added;
|
|
|
|
NODE::ITEM_VECTOR changed;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
aNode->GetUpdatedItems( removed, added );
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
for( ITEM* item : removed )
|
2021-02-08 01:06:56 +00:00
|
|
|
{
|
|
|
|
bool is_changed = false;
|
|
|
|
|
|
|
|
// Items in remove/add that share the same parent are just updated versions
|
|
|
|
// We move them to the updated vector to preserve attributes such as UUID and pad data
|
|
|
|
if( item->Parent() )
|
|
|
|
{
|
|
|
|
for( NODE::ITEM_VECTOR::iterator added_it = added.begin();
|
|
|
|
added_it != added.end(); ++added_it )
|
|
|
|
{
|
|
|
|
if( ( *added_it )->Parent() && ( *added_it )->Parent() == item->Parent() )
|
|
|
|
{
|
|
|
|
changed.push_back( *added_it );
|
|
|
|
added.erase( added_it );
|
|
|
|
is_changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 20:36:06 +00:00
|
|
|
if( !is_changed && !item->IsVirtual() )
|
2021-02-08 01:06:56 +00:00
|
|
|
m_iface->RemoveItem( item );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
for( ITEM* item : added )
|
2021-06-03 20:36:06 +00:00
|
|
|
{
|
|
|
|
if( !item->IsVirtual() )
|
|
|
|
m_iface->AddItem( item );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-02-08 01:06:56 +00:00
|
|
|
for( ITEM* item : changed )
|
2021-06-03 20:36:06 +00:00
|
|
|
{
|
|
|
|
if( !item->IsVirtual() )
|
|
|
|
m_iface->UpdateItem( item );
|
|
|
|
}
|
2021-02-08 01:06:56 +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
|
|
|
|
2024-01-02 14:54:11 +00:00
|
|
|
bool ROUTER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish, bool aForceCommit )
|
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
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
if( m_logger )
|
|
|
|
m_logger->Log( LOGGER::EVT_FIX, aP, aEndItem );
|
|
|
|
|
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:
|
2021-12-15 22:18:53 +00:00
|
|
|
case DRAG_COMPONENT:
|
2024-01-02 14:54:11 +00:00
|
|
|
rv = m_dragger->FixRoute( aForceCommit );
|
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
|
|
|
default:
|
|
|
|
break;
|
2014-05-29 11:48:14 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +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
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
std::optional<VECTOR2I> ROUTER::UndoLastSegment()
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
|
|
|
if( !RoutingInProgress() )
|
2023-06-19 16:09:03 +00:00
|
|
|
return std::nullopt;
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2023-08-07 16:58:41 +00:00
|
|
|
if( m_logger )
|
|
|
|
m_logger->Log( LOGGER::EVT_UNFIX );
|
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
return m_placer->UnfixRoute();
|
2020-02-07 19:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ROUTER::CommitRouting()
|
|
|
|
{
|
2020-02-28 22:13:25 +00:00
|
|
|
if( m_state == ROUTE_TRACK )
|
|
|
|
m_placer->CommitPlacement();
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
StopRouting();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2023-08-22 12:06:33 +00:00
|
|
|
std::vector<NET_HANDLE> nets;
|
2015-02-18 00:29:54 +00:00
|
|
|
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
|
2023-08-22 12:06:33 +00:00
|
|
|
for( NET_HANDLE 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
|
|
|
|
2021-01-04 17:51:50 +00:00
|
|
|
void ROUTER::ClearViewDecorations()
|
|
|
|
{
|
|
|
|
m_iface->EraseView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-12-02 21:16:48 +00:00
|
|
|
bool ROUTER::SwitchLayer( int aLayer )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-12-02 21:16:48 +00:00
|
|
|
if( m_state == ROUTE_TRACK )
|
|
|
|
return m_placer->SetLayer( aLayer );
|
|
|
|
|
|
|
|
return false;
|
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 );
|
2022-03-07 23:45:20 +00:00
|
|
|
|
|
|
|
if( m_logger )
|
2022-10-23 22:34:42 +00:00
|
|
|
m_logger->Log( LOGGER::EVT_TOGGLE_VIA, VECTOR2I(), nullptr, &m_sizes );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
const std::vector<NET_HANDLE> 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();
|
2020-11-01 19:56:54 +00:00
|
|
|
else if( m_dragger )
|
|
|
|
return m_dragger->CurrentNets();
|
2015-08-21 14:35:34 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
return std::vector<NET_HANDLE>();
|
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();
|
2020-11-08 17:16:00 +00:00
|
|
|
else if( m_dragger )
|
|
|
|
return m_dragger->CurrentLayer();
|
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
return -1;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
LOGGER* ROUTER::Logger()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-04-16 22:29:28 +00:00
|
|
|
return m_logger;
|
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
|
|
|
|
2021-11-03 02:14:23 +00:00
|
|
|
void ROUTER::ToggleCornerMode()
|
2019-05-17 00:13:21 +00:00
|
|
|
{
|
2021-11-03 02:14:23 +00:00
|
|
|
DIRECTION_45::CORNER_MODE mode = m_settings->GetCornerMode();
|
2020-12-30 05:06:49 +00:00
|
|
|
|
|
|
|
switch( m_settings->GetCornerMode() )
|
|
|
|
{
|
2021-11-03 02:14:23 +00:00
|
|
|
case DIRECTION_45::CORNER_MODE::MITERED_45: mode = DIRECTION_45::CORNER_MODE::ROUNDED_45; break;
|
|
|
|
case DIRECTION_45::CORNER_MODE::ROUNDED_45: mode = DIRECTION_45::CORNER_MODE::MITERED_90; break;
|
|
|
|
case DIRECTION_45::CORNER_MODE::MITERED_90: mode = DIRECTION_45::CORNER_MODE::ROUNDED_90; break;
|
|
|
|
case DIRECTION_45::CORNER_MODE::ROUNDED_90: mode = DIRECTION_45::CORNER_MODE::MITERED_45; break;
|
2020-12-30 05:06:49 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 02:14:23 +00:00
|
|
|
m_settings->SetCornerMode( mode );
|
2019-05-17 00:13:21 +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;
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2023-04-09 19:25:22 +00:00
|
|
|
|
2024-01-24 02:47:36 +00:00
|
|
|
void ROUTER::BreakSegmentOrArc( ITEM *aItem, const VECTOR2I& aP )
|
2017-08-03 15:53:07 +00:00
|
|
|
{
|
|
|
|
NODE *node = m_world->Branch();
|
|
|
|
|
|
|
|
LINE_PLACER placer( this );
|
|
|
|
|
2024-01-24 02:47:36 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if( aItem->OfKind( ITEM::SEGMENT_T ) )
|
|
|
|
ret = placer.SplitAdjacentSegments( node, aItem, aP );
|
|
|
|
else if( aItem->OfKind( ITEM::ARC_T ) )
|
|
|
|
ret = placer.SplitAdjacentArcs( node, aItem, aP );
|
|
|
|
|
|
|
|
if( ret )
|
2017-08-03 15:53:07 +00:00
|
|
|
{
|
|
|
|
CommitRouting( node );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|