2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2017-01-19 12:55:22 +00:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2024-01-24 02:47:36 +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
|
|
|
*/
|
|
|
|
|
2022-08-25 22:50:47 +00:00
|
|
|
#include <optional>
|
2020-12-01 13:05:31 +00:00
|
|
|
#include <memory>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_arc.h"
|
|
|
|
#include "pns_debug_decorator.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_line_placer.h"
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_node.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_router.h"
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_shove.h"
|
2020-12-29 06:06:46 +00:00
|
|
|
#include "pns_solid.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_topology.h"
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_walkaround.h"
|
2020-10-19 19:42:06 +00:00
|
|
|
#include "pns_mouse_trail_tracer.h"
|
2019-12-05 13:43:55 +00:00
|
|
|
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE_PLACER::LINE_PLACER( ROUTER* aRouter ) :
|
|
|
|
PLACEMENT_ALGO( aRouter )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_initial_direction = DIRECTION_45::N;
|
2021-03-02 13:10:37 +00:00
|
|
|
m_world = nullptr;
|
|
|
|
m_shove = nullptr;
|
|
|
|
m_currentNode = nullptr;
|
2014-11-14 18:15:58 +00:00
|
|
|
m_idle = true;
|
2015-05-15 12:49:11 +00:00
|
|
|
|
|
|
|
// Init temporary variables (do not leave uninitialized members)
|
2021-03-02 13:10:37 +00:00
|
|
|
m_lastNode = nullptr;
|
2015-05-15 12:49:11 +00:00
|
|
|
m_placingVia = false;
|
2023-08-22 12:06:33 +00:00
|
|
|
m_currentNet = nullptr;
|
2015-05-15 12:49:11 +00:00
|
|
|
m_currentLayer = 0;
|
2021-03-02 13:10:37 +00:00
|
|
|
m_startItem = nullptr;
|
2021-12-30 23:42:06 +00:00
|
|
|
m_endItem = nullptr;
|
2015-05-15 12:49:11 +00:00
|
|
|
m_chainedPlacement = false;
|
|
|
|
m_orthoMode = false;
|
2020-03-03 00:04:32 +00:00
|
|
|
m_placementCorrect = false;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE_PLACER::~LINE_PLACER()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
}
|
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 LINE_PLACER::setWorld( NODE* aWorld )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_world = aWorld;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:38 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const VIA LINE_PLACER::makeVia( const VECTOR2I& aP )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-03-07 16:25:47 +00:00
|
|
|
const LAYER_RANGE layers( m_sizes.ViaType() == VIATYPE::THROUGH ? F_Cu : m_sizes.GetLayerTop(),
|
|
|
|
m_sizes.ViaType() == VIATYPE::THROUGH ? B_Cu : m_sizes.GetLayerBottom() );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
return VIA( aP, layers, m_sizes.ViaDiameter(), m_sizes.ViaDrill(), nullptr, m_sizes.ViaType() );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::ToggleVia( bool aEnabled )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
m_placingVia = aEnabled;
|
2015-07-07 16:36:38 +00:00
|
|
|
|
2015-07-07 16:36:41 +00:00
|
|
|
if( !aEnabled )
|
|
|
|
m_head.RemoveVia();
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
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 LINE_PLACER::setInitialDirection( const DIRECTION_45& aDirection )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
m_initial_direction = aDirection;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_tail.SegmentCount() == 0 )
|
|
|
|
m_direction = aDirection;
|
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 LINE_PLACER::handleSelfIntersections()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-10-14 18:40:36 +00:00
|
|
|
SHAPE_LINE_CHAIN::INTERSECTIONS ips;
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& head = m_head.Line();
|
|
|
|
SHAPE_LINE_CHAIN& tail = m_tail.Line();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
// if there is no tail, there is nothing to intersect with
|
|
|
|
if( tail.PointCount() < 2 )
|
|
|
|
return false;
|
|
|
|
|
2019-03-04 17:33:01 +00:00
|
|
|
if( head.PointCount() < 2 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// completely new head trace? chop off the tail
|
|
|
|
if( tail.CPoint(0) == head.CPoint(0) )
|
|
|
|
{
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
tail.Clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
tail.Intersect( head, ips );
|
|
|
|
|
|
|
|
// no intesection points - nothing to reduce
|
|
|
|
if( ips.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int n = INT_MAX;
|
|
|
|
VECTOR2I ipoint;
|
|
|
|
|
|
|
|
// if there is more than one intersection, find the one that is
|
|
|
|
// closest to the beginning of the tail.
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const SHAPE_LINE_CHAIN::INTERSECTION& i : ips )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-05-27 21:55:53 +00:00
|
|
|
if( i.index_our < n )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-05-27 21:55:53 +00:00
|
|
|
n = i.index_our;
|
2013-09-26 21:53:54 +00:00
|
|
|
ipoint = i.p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore the point where head and tail meet
|
|
|
|
if( ipoint == head.CPoint( 0 ) || ipoint == tail.CPoint( -1 ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Intersection point is on the first or the second segment: just start routing
|
|
|
|
// from the beginning
|
|
|
|
if( n < 2 )
|
|
|
|
{
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
tail.Clear();
|
|
|
|
head.Clear();
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Clip till the last tail segment before intersection.
|
|
|
|
// Set the direction to the one of this segment.
|
|
|
|
const SEG last = tail.CSegment( n - 1 );
|
|
|
|
m_direction = DIRECTION_45( last );
|
|
|
|
tail.Remove( n, -1 );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::handlePullback()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& head = m_head.Line();
|
|
|
|
SHAPE_LINE_CHAIN& tail = m_tail.Line();
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( head.PointCount() < 2 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
int n = tail.PointCount();
|
|
|
|
|
|
|
|
if( n == 0 )
|
2020-12-01 13:05:31 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
return false;
|
2020-12-01 13:05:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
else if( n == 1 )
|
|
|
|
{
|
|
|
|
tail.Clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
DIRECTION_45 first_head, last_tail;
|
|
|
|
|
|
|
|
wxASSERT( tail.PointCount() >= 2 );
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2021-05-06 22:10:39 +00:00
|
|
|
if( !head.IsPtOnArc( 0 ) )
|
2021-01-04 02:37:24 +00:00
|
|
|
first_head = DIRECTION_45( head.CSegment( 0 ) );
|
|
|
|
else
|
2021-05-06 22:10:39 +00:00
|
|
|
first_head = DIRECTION_45( head.CArcs()[head.ArcIndex(0)] );
|
2021-01-04 02:37:24 +00:00
|
|
|
|
|
|
|
int lastSegIdx = tail.PointCount() - 2;
|
|
|
|
|
2021-05-06 22:10:39 +00:00
|
|
|
if( !tail.IsPtOnArc( lastSegIdx ) )
|
2021-01-04 02:37:24 +00:00
|
|
|
last_tail = DIRECTION_45( tail.CSegment( lastSegIdx ) );
|
|
|
|
else
|
2021-05-06 22:10:39 +00:00
|
|
|
last_tail = DIRECTION_45( tail.CArcs()[tail.ArcIndex(lastSegIdx)] );
|
2021-01-04 02:37:24 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
DIRECTION_45::AngleType angle = first_head.Angle( last_tail );
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// case 1: we have a defined routing direction, and the currently computed
|
2013-09-26 21:53:54 +00:00
|
|
|
// head goes in different one.
|
|
|
|
bool pullback_1 = false; // (m_direction != DIRECTION_45::UNDEFINED && m_direction != first_head);
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// case 2: regardless of the current routing direction, if the tail/head
|
2013-09-26 21:53:54 +00:00
|
|
|
// extremities form an acute or right angle, reduce the tail by one segment
|
|
|
|
// (and hope that further iterations) will result with a cleaner trace
|
2014-05-16 11:37:31 +00:00
|
|
|
bool pullback_2 = ( angle == DIRECTION_45::ANG_RIGHT || angle == DIRECTION_45::ANG_ACUTE );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( pullback_1 || pullback_2 )
|
|
|
|
{
|
2023-10-06 09:28:39 +00:00
|
|
|
if( !tail.IsArcSegment( lastSegIdx ) )
|
2021-01-04 02:37:24 +00:00
|
|
|
{
|
|
|
|
const SEG& seg = tail.CSegment( lastSegIdx );
|
|
|
|
m_direction = DIRECTION_45( seg );
|
2022-06-03 20:53:13 +00:00
|
|
|
PNS_DBG( Dbg(), AddPoint, m_p_start, WHITE, 10000, wxT( "new-pstart [pullback3]" ) );
|
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-06 22:10:39 +00:00
|
|
|
const SHAPE_ARC& arc = tail.CArcs()[tail.ArcIndex( lastSegIdx )];
|
2021-01-04 02:37:24 +00:00
|
|
|
m_direction = DIRECTION_45( arc );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "Placer: pullback triggered [%d] [%s %s]",
|
|
|
|
n, last_tail.Format(), first_head.Format() ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
// erase the last point in the tail, hoping that the next iteration will
|
2013-10-14 11:43:57 +00:00
|
|
|
// result with a head trace that starts with a segment following our
|
2013-09-26 21:53:54 +00:00
|
|
|
// current direction.
|
|
|
|
if( n < 2 )
|
|
|
|
tail.Clear(); // don't leave a single-point tail
|
|
|
|
else
|
2021-01-04 02:37:24 +00:00
|
|
|
tail.RemoveShape( -1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( !tail.SegmentCount() )
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
bool LINE_PLACER::reduceTail( const VECTOR2I& aEnd )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& head = m_head.Line();
|
|
|
|
SHAPE_LINE_CHAIN& tail = m_tail.Line();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
int n = tail.SegmentCount();
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( head.SegmentCount() < 1 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
// Don't attempt this for too short tails
|
|
|
|
if( n < 2 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Start from the segment farthest from the end of the tail
|
|
|
|
// int start_index = std::max(n - 1 - ReductionDepth, 0);
|
|
|
|
|
|
|
|
DIRECTION_45 new_direction;
|
|
|
|
VECTOR2I new_start;
|
|
|
|
int reduce_index = -1;
|
|
|
|
|
|
|
|
for( int i = tail.SegmentCount() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
const SEG s = tail.CSegment( i );
|
|
|
|
DIRECTION_45 dir( s );
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// calculate a replacement route and check if it matches
|
2013-09-26 21:53:54 +00:00
|
|
|
// the direction of the segment to be replaced
|
2013-10-14 18:40:36 +00:00
|
|
|
SHAPE_LINE_CHAIN replacement = dir.BuildInitialTrace( s.A, aEnd );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2018-11-25 22:40:22 +00:00
|
|
|
if( replacement.SegmentCount() < 1 )
|
|
|
|
continue;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE tmp( m_tail, replacement );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( m_currentNode->CheckColliding( &tmp, ITEM::ANY_T ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( DIRECTION_45( replacement.CSegment( 0 ) ) == dir )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2013-10-14 18:40:36 +00:00
|
|
|
new_start = s.A;
|
2013-09-26 21:53:54 +00:00
|
|
|
new_direction = dir;
|
|
|
|
reduce_index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reduce_index >= 0 )
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "Placer: reducing tail: %d" , reduce_index ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN reducedLine = new_direction.BuildInitialTrace( new_start, aEnd );
|
|
|
|
|
|
|
|
m_direction = new_direction;
|
|
|
|
tail.Remove( reduce_index + 1, -1 );
|
|
|
|
head.Clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !tail.SegmentCount() )
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
|
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::mergeHead()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& head = m_head.Line();
|
|
|
|
SHAPE_LINE_CHAIN& tail = m_tail.Line();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-12-01 13:05:31 +00:00
|
|
|
const int ForbiddenAngles = DIRECTION_45::ANG_ACUTE
|
|
|
|
| DIRECTION_45::ANG_HALF_FULL
|
|
|
|
| DIRECTION_45::ANG_UNDEFINED;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
head.Simplify();
|
|
|
|
tail.Simplify();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
int n_head = head.ShapeCount();
|
|
|
|
int n_tail = tail.ShapeCount();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( n_head < 3 )
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxT( "Merge failed: not enough head segs." ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( n_tail && head.CPoint( 0 ) != tail.CPoint( -1 ) )
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxT( "Merge failed: head and tail discontinuous." ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( m_head.CountCorners( ForbiddenAngles ) != 0 )
|
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
DIRECTION_45 dir_tail, dir_head;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-05-06 22:10:39 +00:00
|
|
|
if( !head.IsPtOnArc( 0 ) )
|
2021-01-04 02:37:24 +00:00
|
|
|
dir_head = DIRECTION_45( head.CSegment( 0 ) );
|
|
|
|
else
|
2021-05-06 22:10:39 +00:00
|
|
|
dir_head = DIRECTION_45( head.CArcs()[head.ArcIndex( 0 )] );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( n_tail )
|
|
|
|
{
|
2021-01-04 02:37:24 +00:00
|
|
|
wxASSERT( tail.PointCount() >= 2 );
|
|
|
|
int lastSegIdx = tail.PointCount() - 2;
|
|
|
|
|
2021-05-06 22:10:39 +00:00
|
|
|
if( !tail.IsPtOnArc( lastSegIdx ) )
|
2021-01-04 02:37:24 +00:00
|
|
|
dir_tail = DIRECTION_45( tail.CSegment( -1 ) );
|
|
|
|
else
|
2021-05-06 22:10:39 +00:00
|
|
|
dir_tail = DIRECTION_45( tail.CArcs()[tail.ArcIndex( lastSegIdx )] );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( dir_head.Angle( dir_tail ) & ForbiddenAngles )
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
tail.Append( head );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
tail.Simplify();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
int lastSegIdx = tail.PointCount() - 2;
|
|
|
|
|
2021-05-06 22:10:39 +00:00
|
|
|
if( !tail.IsArcSegment( lastSegIdx ) )
|
2021-01-04 02:37:24 +00:00
|
|
|
m_direction = DIRECTION_45( tail.CSegment( -1 ) );
|
|
|
|
else
|
2021-05-06 22:10:39 +00:00
|
|
|
m_direction = DIRECTION_45( tail.CArcs()[tail.ArcIndex( lastSegIdx )] );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
head.Remove( 0, -1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "Placer: merge %d, new direction: %s" , n_head,
|
|
|
|
m_direction.Format() ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
head.Simplify();
|
|
|
|
tail.Simplify();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
bool LINE_PLACER::clipAndCheckCollisions( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aL,
|
|
|
|
SHAPE_LINE_CHAIN& aOut, int &thresholdDist )
|
2022-10-26 22:35:41 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN l( aL );
|
|
|
|
int idx = l.Split( aP );
|
|
|
|
|
|
|
|
if( idx < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool rv = true;
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN l2 = l.Slice( 0, idx );
|
|
|
|
int dist = l2.Length();
|
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddPoint, aP, BLUE, 500000, wxString::Format( "hug-target-check-%d", idx ) );
|
|
|
|
PNS_DBG( Dbg(), AddShape, &l2, BLUE, 500000, wxT( "hug-target-line" ) );
|
|
|
|
|
|
|
|
if( dist < thresholdDist )
|
|
|
|
rv = false;
|
|
|
|
|
|
|
|
LINE ctest( m_head, l2 );
|
|
|
|
|
|
|
|
if( m_currentNode->CheckColliding( &ctest ).has_value() )
|
|
|
|
rv = false;
|
|
|
|
|
|
|
|
if( rv )
|
|
|
|
{
|
|
|
|
aOut = l2;
|
|
|
|
thresholdDist = dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
bool LINE_PLACER::cursorDistMinimum( const SHAPE_LINE_CHAIN& aL, const VECTOR2I& aCursor,
|
|
|
|
double lengthThreshold, SHAPE_LINE_CHAIN &aOut )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
|
|
|
std::vector<int> dists;
|
|
|
|
std::vector<VECTOR2I> pts;
|
|
|
|
|
|
|
|
if( aL.PointCount() == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
VECTOR2I lastP = aL.CPoint(-1);
|
|
|
|
int accumulatedDist = 0;
|
|
|
|
|
|
|
|
dists.reserve( 2 * aL.PointCount() );
|
|
|
|
|
|
|
|
for( int i = 0; i < aL.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
const SEG& s = aL.CSegment( i );
|
|
|
|
|
|
|
|
dists.push_back( ( aCursor - s.A ).EuclideanNorm() );
|
|
|
|
pts.push_back( s.A );
|
|
|
|
auto pn = s.NearestPoint( aCursor );
|
|
|
|
|
|
|
|
if( pn != s.A && pn != s.B )
|
|
|
|
{
|
|
|
|
dists.push_back( ( pn - aCursor ).EuclideanNorm() );
|
|
|
|
pts.push_back( pn );
|
|
|
|
}
|
|
|
|
|
|
|
|
accumulatedDist += s.Length();
|
|
|
|
|
|
|
|
if ( accumulatedDist > lengthThreshold )
|
|
|
|
{
|
|
|
|
lastP = s.B;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dists.push_back( ( aCursor - lastP ).EuclideanNorm() );
|
|
|
|
pts.push_back( lastP );
|
|
|
|
|
|
|
|
int minDistLoc = std::numeric_limits<int>::max();
|
|
|
|
int minPLoc = -1;
|
|
|
|
int minDistGlob = std::numeric_limits<int>::max();
|
|
|
|
int minPGlob = -1;
|
|
|
|
|
2021-05-29 16:39:14 +00:00
|
|
|
for( int i = 0; i < dists.size(); i++ )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2021-05-29 16:39:14 +00:00
|
|
|
int d = dists[i];
|
|
|
|
|
|
|
|
if( d < minDistGlob )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2021-05-29 16:39:14 +00:00
|
|
|
minDistGlob = d;
|
|
|
|
minPGlob = i;
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-29 16:39:14 +00:00
|
|
|
if( dists.size() >= 3 )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2021-05-29 16:39:14 +00:00
|
|
|
for( int i = 0; i < dists.size() - 3; i++ )
|
|
|
|
{
|
|
|
|
if( dists[i + 2] > dists[i + 1] && dists[i] > dists[i + 1] )
|
|
|
|
{
|
|
|
|
int d = dists[i + 1];
|
|
|
|
if( d < minDistLoc )
|
|
|
|
{
|
|
|
|
minDistLoc = d;
|
|
|
|
minPLoc = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 22:08:31 +00:00
|
|
|
|
2021-05-29 16:39:14 +00:00
|
|
|
if( dists.back() < minDistLoc && minPLoc >= 0 )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2021-05-29 16:39:14 +00:00
|
|
|
minDistLoc = dists.back();
|
|
|
|
minPLoc = dists.size() - 1;
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-29 16:39:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Too few points: just use the global
|
|
|
|
minDistLoc = minDistGlob;
|
|
|
|
minPLoc = minPGlob;
|
|
|
|
}
|
2021-05-27 22:08:31 +00:00
|
|
|
|
|
|
|
// fixme: I didn't make my mind yet if local or global minimum feels better. I'm leaving both
|
|
|
|
// in the code, enabling the global one by default
|
|
|
|
minPLoc = -1;
|
2022-10-26 22:35:41 +00:00
|
|
|
int preferred;
|
2021-05-27 22:08:31 +00:00
|
|
|
|
|
|
|
if( minPLoc < 0 )
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
preferred = minPGlob;
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
preferred = minPLoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int thresholdDist = 0;
|
|
|
|
|
|
|
|
if( clipAndCheckCollisions( pts[preferred], aL, aOut, thresholdDist ) )
|
2021-05-27 22:08:31 +00:00
|
|
|
return true;
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
thresholdDist = 0;
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN l( aL ), prefL;
|
|
|
|
int minDist = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
for( int i = 0; i < pts.size() ; i++)
|
|
|
|
{
|
|
|
|
//PNS_DBG( Dbg(), AddPoint, pts[i], BLUE, 500000, wxT( "hug-target-fallback" ) );
|
|
|
|
|
|
|
|
ok |= clipAndCheckCollisions( pts[i], aL, aOut, thresholdDist );
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
return ok;
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
bool LINE_PLACER::rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisionMask,
|
|
|
|
bool& aViaOk )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2020-02-19 17:22:37 +00:00
|
|
|
LINE walkFull( m_head );
|
2022-10-26 22:35:41 +00:00
|
|
|
LINE l1( m_head );
|
2021-05-29 22:34:08 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, GREEN, 100000, wxT( "walk-base-old-tail" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, BLUE, 100000, wxT( "walk-base-old-head" ) );
|
2015-07-02 14:09:24 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
VECTOR2I walkP = aP;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND walkaround( m_currentNode, Router() );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
walkaround.SetSolidsOnly( false );
|
2019-02-03 10:21:48 +00:00
|
|
|
walkaround.SetDebugDecorator( Dbg() );
|
2020-02-19 17:22:37 +00:00
|
|
|
walkaround.SetLogger( Logger() );
|
2014-05-14 13:53:54 +00:00
|
|
|
walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
|
2022-10-26 22:35:41 +00:00
|
|
|
walkaround.SetItemMask( aCollisionMask );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
int round = 0;
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
l1.Clear();
|
|
|
|
|
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "walk-round-%d", round ), 0 );
|
|
|
|
round++;
|
|
|
|
|
|
|
|
aViaOk = buildInitialLine( walkP, l1, round == 0 );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &l1, BLUE, 20000, wxT( "walk-base-l1" ) );
|
2023-05-14 21:20:59 +00:00
|
|
|
|
|
|
|
if( l1.EndsWithVia() )
|
|
|
|
PNS_DBG( Dbg(), AddPoint, l1.Via().Pos(), BLUE, 100000, wxT( "walk-base-l1-via" ) );
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
LINE initTrack( m_tail );
|
|
|
|
initTrack.Line().Append( l1.CLine() );
|
|
|
|
initTrack.Line().Simplify();
|
2021-06-06 19:44:42 +00:00
|
|
|
|
2021-05-27 22:19:36 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
double initialLength = initTrack.CLine().Length();
|
|
|
|
double hugThresholdLength = initialLength * Settings().WalkaroundHugLengthThreshold();
|
2022-10-26 22:35:41 +00:00
|
|
|
double hugThresholdLengthComplete =
|
|
|
|
2.0 * initialLength * Settings().WalkaroundHugLengthThreshold();
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
WALKAROUND::RESULT wr = walkaround.Route( initTrack );
|
2022-10-26 22:35:41 +00:00
|
|
|
std::optional<LINE> bestLine;
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
OPTIMIZER optimizer( m_currentNode );
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
optimizer.SetEffortLevel( OPTIMIZER::MERGE_SEGMENTS );
|
|
|
|
optimizer.SetCollisionMask( aCollisionMask );
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
int len_cw = wr.statusCw != WALKAROUND::STUCK ? wr.lineCw.CLine().Length()
|
|
|
|
: std::numeric_limits<int>::max();
|
|
|
|
int len_ccw = wr.statusCcw != WALKAROUND::STUCK ? wr.lineCcw.CLine().Length()
|
|
|
|
: std::numeric_limits<int>::max();
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( wr.statusCw == WALKAROUND::DONE )
|
|
|
|
{
|
|
|
|
PNS_DBG( Dbg(), AddItem, &wr.lineCw, BLUE, 20000, wxT( "wf-result-cw-preopt" ) );
|
|
|
|
LINE tmpHead, tmpTail;
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( splitHeadTail( wr.lineCw, m_tail, tmpHead, tmpTail ) )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
optimizer.Optimize( &tmpHead );
|
|
|
|
wr.lineCw.SetShape( tmpTail.CLine () );
|
|
|
|
wr.lineCw.Line().Append( tmpHead.CLine( ) );
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &wr.lineCw, RED, 20000, wxT( "wf-result-cw-postopt" ) );
|
|
|
|
len_cw = wr.lineCw.CLine().Length();
|
|
|
|
bestLine = wr.lineCw;
|
2021-05-27 22:08:31 +00:00
|
|
|
}
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( wr.statusCcw == WALKAROUND::DONE )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &wr.lineCcw, BLUE, 20000, wxT( "wf-result-ccw-preopt" ) );
|
2021-05-27 22:19:36 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
LINE tmpHead, tmpTail;
|
|
|
|
|
|
|
|
if( splitHeadTail( wr.lineCw, m_tail, tmpHead, tmpTail ) )
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
optimizer.Optimize( &tmpHead );
|
|
|
|
wr.lineCw.SetShape( tmpTail.CLine () );
|
|
|
|
wr.lineCw.Line().Append( tmpHead.CLine( ) );
|
|
|
|
}
|
2021-07-08 12:33:08 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &wr.lineCcw, RED, 20000, wxT( "wf-result-ccw-postopt" ) );
|
|
|
|
len_ccw = wr.lineCcw.CLine().Length();
|
2023-07-17 11:51:41 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( len_ccw < len_cw )
|
|
|
|
bestLine = wr.lineCcw;
|
2023-07-17 11:51:41 +00:00
|
|
|
}
|
2021-07-08 12:33:08 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
int bestLength = len_cw < len_ccw ? len_cw : len_ccw;
|
|
|
|
|
|
|
|
if( bestLength < hugThresholdLengthComplete && bestLine.has_value() )
|
2023-07-17 11:51:41 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
walkFull.SetShape( bestLine->CLine() );
|
|
|
|
walkP = walkFull.CLine().CPoint(-1);
|
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
continue;
|
|
|
|
}
|
2021-07-08 12:33:08 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
bool validCw = false;
|
|
|
|
bool validCcw = false;
|
|
|
|
int distCcw = std::numeric_limits<int>::max();
|
|
|
|
int distCw = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN l_cw, l_ccw;
|
|
|
|
|
|
|
|
if( wr.statusCw != WALKAROUND::STUCK )
|
2023-07-17 11:51:41 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
validCw = cursorDistMinimum( wr.lineCw.CLine(), aP, hugThresholdLength, l_cw );
|
2023-07-17 11:51:41 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( validCw )
|
|
|
|
distCw = ( aP - l_cw.CPoint( -1 ) ).EuclideanNorm();
|
2023-07-17 11:51:41 +00:00
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddShape, &l_cw, MAGENTA, 200000, wxString::Format( "wh-result-cw %s",
|
|
|
|
validCw ? "non-colliding"
|
|
|
|
: "colliding" ) );
|
|
|
|
}
|
2021-05-27 22:08:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( wr.statusCcw != WALKAROUND::STUCK )
|
|
|
|
{
|
|
|
|
validCcw = cursorDistMinimum( wr.lineCcw.CLine(), aP, hugThresholdLength, l_ccw );
|
2023-07-17 11:51:41 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( validCcw )
|
|
|
|
distCcw = ( aP - l_ccw.CPoint( -1 ) ).EuclideanNorm();
|
2023-07-17 11:51:41 +00:00
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddShape, &l_ccw, MAGENTA, 200000, wxString::Format( "wh-result-ccw %s",
|
|
|
|
validCcw ? "non-colliding"
|
|
|
|
: "colliding" ) );
|
2022-10-26 22:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( distCw < distCcw && validCw )
|
2023-07-17 11:51:41 +00:00
|
|
|
{
|
|
|
|
walkFull.SetShape( l_cw );
|
2022-10-26 22:35:41 +00:00
|
|
|
walkP = l_cw.CPoint(-1);
|
2023-07-17 11:51:41 +00:00
|
|
|
}
|
2022-10-26 22:35:41 +00:00
|
|
|
else if( validCcw )
|
2023-07-17 11:51:41 +00:00
|
|
|
{
|
|
|
|
walkFull.SetShape( l_ccw );
|
2022-10-26 22:35:41 +00:00
|
|
|
walkP = l_ccw.CPoint(-1);
|
2023-07-17 11:51:41 +00:00
|
|
|
}
|
|
|
|
else
|
2021-05-27 22:08:31 +00:00
|
|
|
{
|
2021-06-06 19:44:42 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
2021-05-27 22:08:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-06 19:44:42 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
2021-05-27 22:08:31 +00:00
|
|
|
} while( round < 2 && m_placingVia );
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
if( l1.EndsWithVia() )
|
|
|
|
{
|
|
|
|
VIA v ( l1.Via() );
|
|
|
|
v.SetPos( walkFull.CPoint( -1 ) );
|
|
|
|
walkFull.AppendVia( v );
|
|
|
|
}
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &walkFull, GREEN, 200000, wxT( "walk-full" ) );
|
2023-05-14 21:20:59 +00:00
|
|
|
|
|
|
|
if( walkFull.EndsWithVia() )
|
|
|
|
{
|
|
|
|
PNS_DBG( Dbg(), AddPoint, walkFull.Via().Pos(), GREEN, 200000,
|
|
|
|
wxString::Format( "walk-via ok %d", aViaOk ? 1 : 0 ) );
|
|
|
|
}
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
aWalkLine = walkFull;
|
|
|
|
|
2023-08-07 22:42:44 +00:00
|
|
|
return !walkFull.EndsWithVia() || aViaOk;
|
2022-10-26 22:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail )
|
|
|
|
{
|
|
|
|
LINE walkFull;
|
|
|
|
|
|
|
|
int effort = 0;
|
|
|
|
bool viaOk = false;
|
|
|
|
|
|
|
|
if( ! rhWalkBase( aP, walkFull, ITEM::ANY_T, viaOk ) )
|
|
|
|
return false;
|
2020-02-19 17:22:37 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( Settings().OptimizerEffort() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case OE_LOW:
|
|
|
|
effort = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OE_MEDIUM:
|
|
|
|
case OE_FULL:
|
2016-08-29 17:31:13 +00:00
|
|
|
effort = OPTIMIZER::MERGE_SEGMENTS;
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2022-01-14 01:21:19 +00:00
|
|
|
DIRECTION_45::CORNER_MODE cornerMode = Settings().GetCornerMode();
|
|
|
|
|
|
|
|
// Smart Pads is incompatible with 90-degree mode for now
|
|
|
|
if( Settings().SmartPads()
|
|
|
|
&& ( cornerMode == DIRECTION_45::MITERED_45 || cornerMode == DIRECTION_45::ROUNDED_45 )
|
|
|
|
&& !m_mouseTrailTracer.IsManuallyForced() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
effort |= OPTIMIZER::SMART_PADS;
|
2022-01-14 01:21:19 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( m_currentNode->CheckColliding( &walkFull ) )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &walkFull, GREEN, 100000, wxString::Format( "collision check fail" ) );
|
|
|
|
return false;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
// OK, this deserves a bit of explanation. We used to calculate the walk path for the head only,
|
|
|
|
// but then the clearance epsilon was added, with the intent of improving collision resolution robustness
|
|
|
|
// (now a hull or a walk/shove line cannot collide with the 'owner' of the hull under any circumstances).
|
|
|
|
// This, however, introduced a subtle bug. For a row/column/any other 'regular' arrangement
|
|
|
|
// of overlapping hulls (think of pads of a SOP/SOIC chip or a regular via grid), walking around may
|
2024-01-24 02:47:36 +00:00
|
|
|
// produce a new 'head' that is not considered colliding (due to the clearance epsilon), but with
|
2022-10-26 22:35:41 +00:00
|
|
|
// its start point inside one of the subsequent hulls to process.
|
|
|
|
// We can't have head[0] inside any hull for the algorithm to work - therefore, we now consider the entire
|
|
|
|
// 'tail+head' trace when walking around and in case of success, reconstruct the
|
|
|
|
// 'head' and 'tail' by splitting the walk line at a point that is as close as possible to the original
|
|
|
|
// head[0], but not inside any obstacle hull.
|
|
|
|
//
|
|
|
|
// EXECUTIVE SUMMARY: asinine heuristic to make the router get stuck much less often.
|
|
|
|
|
|
|
|
if( ! splitHeadTail( walkFull, m_tail, aNewHead, aNewTail ) )
|
|
|
|
return false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( m_placingVia && viaOk )
|
2015-07-10 21:42:13 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddPoint, aNewHead.CPoint(-1), RED, 1000000, wxString::Format( "VIA" ) );
|
|
|
|
|
|
|
|
aNewHead.AppendVia( makeVia( aNewHead.CPoint( -1 ) ) );
|
2015-07-10 21:42:13 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
OPTIMIZER::Optimize( &aNewHead, effort, m_currentNode );
|
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddItem, &aNewHead, GREEN, 100000, wxString::Format( "walk-new-head" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &aNewTail, BLUE, 100000, wxT( "walk-new-tail" ) );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
return true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
bool LINE_PLACER::rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
buildInitialLine( aP, m_head );
|
2021-01-01 17:17:55 +00:00
|
|
|
m_head.SetBlockingObstacle( nullptr );
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2022-07-03 21:59:20 +00:00
|
|
|
auto obs = m_currentNode->NearestObstacle( &m_head );
|
|
|
|
|
2022-09-02 09:17:28 +00:00
|
|
|
// If the head is in colliding state, snap to the hull of the first obstacle.
|
|
|
|
// This way, one can route tracks as tightly as possible without enabling
|
2022-07-03 21:59:20 +00:00
|
|
|
// the shove/walk mode that certain users find too intrusive.
|
|
|
|
if( obs )
|
|
|
|
{
|
2023-10-26 13:18:14 +00:00
|
|
|
int clearance = m_currentNode->GetClearance( obs->m_item, &m_head, false );
|
|
|
|
SHAPE_LINE_CHAIN hull = obs->m_item->Hull( clearance, m_head.Width() );
|
|
|
|
VECTOR2I nearest;
|
2022-07-03 21:59:20 +00:00
|
|
|
|
2023-10-26 13:18:14 +00:00
|
|
|
DIRECTION_45::CORNER_MODE cornerMode = Settings().GetCornerMode();
|
|
|
|
|
|
|
|
if( cornerMode == DIRECTION_45::MITERED_90 || cornerMode == DIRECTION_45::ROUNDED_90 )
|
|
|
|
nearest = hull.BBox().ClosestPointTo( aP );
|
|
|
|
else
|
|
|
|
nearest = hull.NearestPoint( aP );
|
2022-07-03 21:59:20 +00:00
|
|
|
|
|
|
|
if( ( nearest - aP ).EuclideanNorm() < m_head.Width() / 2 )
|
|
|
|
buildInitialLine( nearest, m_head );
|
|
|
|
}
|
|
|
|
|
2021-04-19 01:01:07 +00:00
|
|
|
// Note: Something like the below could be used to implement a "stop at first obstacle" mode,
|
|
|
|
// but we don't have one right now and there isn't a lot of demand for one. If we do end up
|
|
|
|
// doing that, put it in a new routing mode as "highlight collisions" mode should not have
|
|
|
|
// collision handling other than highlighting.
|
|
|
|
#if 0
|
2021-04-10 09:31:42 +00:00
|
|
|
if( !Settings().AllowDRCViolations() )
|
2017-01-19 12:55:22 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
NODE::OPT_OBSTACLE obs = m_currentNode->NearestObstacle( &m_head );
|
2020-12-20 20:35:31 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( obs && obs->m_distFirst != INT_MAX )
|
2021-01-01 17:17:55 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
buildInitialLine( obs->m_ipFirst, m_head );
|
2021-01-01 17:17:55 +00:00
|
|
|
m_head.SetBlockingObstacle( obs->m_item );
|
|
|
|
}
|
2017-01-19 12:55:22 +00:00
|
|
|
}
|
2021-04-19 01:01:07 +00:00
|
|
|
#endif
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aNewHead = m_head;
|
2022-10-26 22:35:41 +00:00
|
|
|
aNewTail = m_tail;
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2021-06-04 21:57:07 +00:00
|
|
|
return true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
bool LINE_PLACER::splitHeadTail( const LINE& aNewLine, const LINE& aOldTail, LINE& aNewHead,
|
|
|
|
LINE& aNewTail )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
LINE newTail( aOldTail );
|
|
|
|
LINE newHead( aOldTail );
|
|
|
|
LINE l2( aNewLine );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
newTail.RemoveVia();
|
|
|
|
newHead.Clear();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
int i;
|
|
|
|
bool found = false;
|
|
|
|
int n = l2.PointCount();
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( n > 1 && aOldTail.PointCount() > 1 )
|
|
|
|
{
|
|
|
|
if( l2.CLine().PointOnEdge( aOldTail.CPoint( -1 ) ) )
|
|
|
|
{
|
|
|
|
l2.Line().Split( aOldTail.CPoint( -1 ) );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
for( i = 0; i < aOldTail.PointCount(); i++ )
|
|
|
|
{
|
|
|
|
if( l2.CLine().Find( aOldTail.CPoint( i ) ) < 0 )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( !found )
|
|
|
|
i--;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2024-04-20 00:51:47 +00:00
|
|
|
// If the old tail doesn't have any points of the new line, we can't split it.
|
|
|
|
if( i >= l2.PointCount() )
|
|
|
|
i = l2.PointCount() - 1;
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
newHead.Clear();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( i == 0 )
|
|
|
|
newTail.Clear();
|
2023-07-17 11:51:41 +00:00
|
|
|
else
|
2022-10-26 22:35:41 +00:00
|
|
|
newTail.SetShape( l2.CLine().Slice( 0, i ) );
|
2015-10-12 08:02:03 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
newHead.SetShape( l2.CLine().Slice( i, -1 ) );
|
|
|
|
}
|
|
|
|
else
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
newTail.Clear();
|
|
|
|
newHead = l2;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &newHead, BLUE, 500000, wxT( "head-post-split" ) );
|
|
|
|
|
|
|
|
aNewHead = newHead;
|
|
|
|
aNewTail = newTail;
|
|
|
|
|
|
|
|
return true;
|
2023-07-17 11:51:41 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
bool LINE_PLACER::rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail )
|
2023-07-17 11:51:41 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
LINE walkSolids;
|
|
|
|
|
|
|
|
bool viaOk = false;
|
|
|
|
|
|
|
|
if( ! rhWalkBase( aP, walkSolids, ITEM::SOLID_T, viaOk ) )
|
2014-11-14 19:19:00 +00:00
|
|
|
return false;
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
|
|
|
|
m_shove->SetLogger( Logger() );
|
|
|
|
m_shove->SetDebugDecorator( Dbg() );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-12-15 00:32:05 +00:00
|
|
|
if( m_endItem )
|
|
|
|
{
|
|
|
|
// Make sure the springback algorithm won't erase the NODE that owns m_endItem.
|
2022-08-29 20:21:46 +00:00
|
|
|
m_shove->SetSpringbackDoNotTouchNode( static_cast<const NODE*>( m_endItem->Owner() ) );
|
2021-12-15 00:32:05 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
LINE newHead( walkSolids );
|
|
|
|
|
|
|
|
if( walkSolids.EndsWithVia() )
|
|
|
|
PNS_DBG( Dbg(), AddPoint, newHead.Via().Pos(), RED, 1000000, wxString::Format( "SVIA [%d]", viaOk?1:0 ) );
|
|
|
|
|
|
|
|
if( m_placingVia && viaOk )
|
|
|
|
{
|
|
|
|
newHead.AppendVia( makeVia( newHead.CPoint( -1 ) ) );
|
|
|
|
PNS_DBG( Dbg(), AddPoint, newHead.Via().Pos(), GREEN, 1000000, "shove-new-via" );
|
2024-01-24 02:47:36 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SHOVE::SHOVE_STATUS status = m_shove->ShoveLines( newHead );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
int effort = 0;
|
|
|
|
|
|
|
|
switch( Settings().OptimizerEffort() )
|
|
|
|
{
|
|
|
|
case OE_LOW:
|
|
|
|
effort = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OE_MEDIUM:
|
|
|
|
case OE_FULL:
|
|
|
|
effort = OPTIMIZER::MERGE_SEGMENTS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
DIRECTION_45::CORNER_MODE cornerMode = Settings().GetCornerMode();
|
|
|
|
|
|
|
|
// Smart Pads is incompatible with 90-degree mode for now
|
|
|
|
if( Settings().SmartPads()
|
|
|
|
&& ( cornerMode == DIRECTION_45::MITERED_45 || cornerMode == DIRECTION_45::ROUNDED_45 )
|
|
|
|
&& !m_mouseTrailTracer.IsManuallyForced() )
|
|
|
|
{
|
|
|
|
effort |= OPTIMIZER::SMART_PADS;
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( status == SHOVE::SH_OK || status == SHOVE::SH_HEAD_MODIFIED )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( status == SHOVE::SH_HEAD_MODIFIED )
|
2022-10-26 22:35:41 +00:00
|
|
|
newHead = m_shove->NewHead();
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
OPTIMIZER optimizer( m_currentNode );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2023-05-14 21:20:59 +00:00
|
|
|
if( newHead.EndsWithVia() )
|
|
|
|
{
|
|
|
|
PNS_DBG( Dbg(), AddPoint, newHead.Via().Pos(), GREEN, 1000000, "shove-via-preopt" );
|
|
|
|
PNS_DBG( Dbg(), AddPoint, newHead.Via().Pos(), GREEN, 1000000, "shove-via-postopt" );
|
|
|
|
}
|
2020-12-01 13:05:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( ! splitHeadTail( newHead, m_tail, aNewHead, aNewTail ) )
|
|
|
|
return false;
|
2020-12-01 13:05:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( newHead.EndsWithVia() )
|
|
|
|
aNewHead.AppendVia( newHead.Via() );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
optimizer.SetEffortLevel( effort );
|
2016-08-29 17:31:13 +00:00
|
|
|
optimizer.SetCollisionMask( ITEM::ANY_T );
|
2022-10-26 22:35:41 +00:00
|
|
|
optimizer.Optimize( &aNewHead );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
return rhWalkOnly( aP, aNewHead, aNewTail );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
bool LINE_PLACER::routeHead( const VECTOR2I& aP, LINE& aNewHead, LINE& aNewTail )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-10-12 16:53:52 +00:00
|
|
|
switch( Settings().Mode() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_MarkObstacles:
|
2022-10-26 22:35:41 +00:00
|
|
|
return rhMarkObstacles( aP, aNewHead, aNewTail );
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_Walkaround:
|
2022-10-26 22:35:41 +00:00
|
|
|
return rhWalkOnly( aP, aNewHead, aNewTail );
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_Shove:
|
2022-10-26 22:35:41 +00:00
|
|
|
return rhShoveOnly( aP, aNewHead, aNewTail );
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::optimizeTailHeadTransition()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-11-25 14:07:23 +00:00
|
|
|
LINE linetmp = Trace();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-05-30 22:18:42 +00:00
|
|
|
PNS_DBG( Dbg(), Message, "optimize HT" );
|
|
|
|
|
2021-07-08 23:56:29 +00:00
|
|
|
// NOTE: FANOUT_CLEANUP can override posture setting at the moment
|
|
|
|
if( !m_mouseTrailTracer.IsManuallyForced() &&
|
|
|
|
OPTIMIZER::Optimize( &linetmp, OPTIMIZER::FANOUT_CLEANUP, m_currentNode ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-11-25 14:07:23 +00:00
|
|
|
if( linetmp.SegmentCount() < 1 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
|
|
|
|
2016-11-25 14:07:23 +00:00
|
|
|
m_head = linetmp;
|
2022-06-03 20:53:13 +00:00
|
|
|
m_direction = DIRECTION_45( linetmp.CSegment( 0 ) );
|
|
|
|
m_tail.Line().Clear();
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& head = m_head.Line();
|
|
|
|
SHAPE_LINE_CHAIN& tail = m_tail.Line();
|
|
|
|
|
|
|
|
int tailLookbackSegments = 3;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
//if(m_currentMode() == RM_Walkaround)
|
|
|
|
// tailLookbackSegments = 10000;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int threshold = std::min( tail.PointCount(), tailLookbackSegments + 1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
if( tail.ShapeCount() < 3 )
|
2013-09-26 21:53:54 +00:00
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
// assemble TailLookbackSegments tail segments with the current head
|
|
|
|
SHAPE_LINE_CHAIN opt_line = tail.Slice( -threshold, -1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int end = std::min(2, head.PointCount() - 1 );
|
|
|
|
|
|
|
|
opt_line.Append( head.Slice( 0, end ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE new_head( m_tail, opt_line );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
// and see if it could be made simpler by merging obtuse/collnear segments.
|
2013-10-14 11:43:57 +00:00
|
|
|
// If so, replace the (threshold) last tail points and the head with
|
2013-09-26 21:53:54 +00:00
|
|
|
// the optimized line
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &new_head, LIGHTCYAN, 10000, wxT( "ht-newline" ) );
|
2021-05-30 22:18:42 +00:00
|
|
|
|
|
|
|
if( OPTIMIZER::Optimize( &new_head, OPTIMIZER::MERGE_SEGMENTS, m_currentNode ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE tmp( m_tail, opt_line );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
head.Clear();
|
2014-05-14 13:53:54 +00:00
|
|
|
tail.Replace( -threshold, -1, new_head.CLine() );
|
2013-09-26 21:53:54 +00:00
|
|
|
tail.Simplify();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_direction = DIRECTION_45( new_head.CSegment( -1 ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
void LINE_PLACER::updatePStart( const LINE& tail )
|
|
|
|
{
|
|
|
|
if( tail.CLine().PointCount() )
|
2023-07-17 11:51:41 +00:00
|
|
|
m_p_start = tail.CLine().CPoint(-1);
|
|
|
|
else
|
|
|
|
m_p_start = m_currentStart;
|
2022-10-26 22:35:41 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::routeStep( const VECTOR2I& aP )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
bool fail = false;
|
|
|
|
bool go_back = false;
|
|
|
|
|
|
|
|
int i, n_iter = 1;
|
|
|
|
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "routeStep: direction: %s head: %d, tail: %d shapes" ,
|
2023-07-17 11:51:41 +00:00
|
|
|
m_direction.Format(),
|
|
|
|
m_head.ShapeCount(),
|
|
|
|
m_tail.ShapeCount() ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxT( "route-step" ), 0 );
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-init" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-init" ) );
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
for( i = 0; i < n_iter; i++ )
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
LINE prevTail( m_tail );
|
|
|
|
LINE prevHead( m_head );
|
|
|
|
LINE newHead, newTail;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( !go_back && Settings().FollowMouse() )
|
2013-09-26 21:53:54 +00:00
|
|
|
reduceTail( aP );
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-after-reduce" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-after-reduce" ) );
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
go_back = false;
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
updatePStart( m_tail );
|
|
|
|
|
|
|
|
if( !routeHead( aP, newHead, newTail ) )
|
2022-02-26 01:42:16 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
m_tail = prevTail;
|
|
|
|
m_head = prevHead;
|
2023-05-26 03:10:00 +00:00
|
|
|
|
|
|
|
// If we fail to walk out of the initial point (no tail), instead of returning an empty
|
|
|
|
// line, return a zero-length line so that the user gets some feedback that routing is
|
|
|
|
// happening. This will get pruned later.
|
|
|
|
if( m_tail.PointCount() == 0 )
|
|
|
|
{
|
|
|
|
m_tail.Line().Append( m_p_start );
|
|
|
|
m_tail.Line().Append( m_p_start, true );
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
fail = true;
|
2022-02-26 01:42:16 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
updatePStart( m_tail );
|
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddItem, &newHead, LIGHTGREEN, 100000, wxString::Format( "new_head [fail: %d]", fail?1:0 ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
if( fail )
|
2021-05-30 22:18:42 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "N VIA H %d T %d\n", m_head.EndsWithVia() ? 1 : 0, m_tail.EndsWithVia() ? 1 : 0 ) );
|
|
|
|
|
|
|
|
m_head = newHead;
|
|
|
|
m_tail = newTail;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( handleSelfIntersections() )
|
|
|
|
{
|
|
|
|
n_iter++;
|
|
|
|
go_back = true;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "SI VIA H %d T %d\n", m_head.EndsWithVia() ? 1 : 0, m_tail.EndsWithVia() ? 1 : 0 ) );
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-after-si" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-after-si" ) );
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !go_back && handlePullback() )
|
|
|
|
{
|
|
|
|
n_iter++;
|
2022-10-26 22:35:41 +00:00
|
|
|
m_head.Clear();
|
2013-09-26 21:53:54 +00:00
|
|
|
go_back = true;
|
|
|
|
}
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "PB VIA H %d T %d\n", m_head.EndsWithVia() ? 1 : 0, m_tail.EndsWithVia() ? 1 : 0 ) );
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 100000, wxT( "tail-after-pb" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 100000, wxT( "head-after-pb" ) );
|
2021-05-30 22:18:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-05-30 22:18:42 +00:00
|
|
|
if( !fail && Settings().FollowMouse() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-pre-merge" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-pre-merge" ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-05-30 22:18:42 +00:00
|
|
|
if( !optimizeTailHeadTransition() )
|
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "PreM VIA H %d T %d\n", m_head.EndsWithVia() ? 1 : 0, m_tail.EndsWithVia() ? 1 : 0 ) );
|
|
|
|
|
2021-05-30 22:18:42 +00:00
|
|
|
mergeHead();
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "PostM VIA H %d T %d\n", m_head.EndsWithVia() ? 1 : 0, m_tail.EndsWithVia() ? 1 : 0 ) );
|
2021-05-30 22:18:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 100000, wxT( "tail-post-merge" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 100000, wxT( "head-post-merge" ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2021-05-30 22:18:42 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
m_last_p_end = aP;
|
|
|
|
|
2021-05-30 22:18:42 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::route( const VECTOR2I& aP )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
routeStep( aP );
|
2019-02-03 11:37:17 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
if( !m_head.PointCount() )
|
2019-02-03 11:37:17 +00:00
|
|
|
return false;
|
2019-03-04 17:33:01 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
return m_head.CPoint( -1 ) == aP;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE LINE_PLACER::Trace() const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2022-10-26 22:35:41 +00:00
|
|
|
SHAPE_LINE_CHAIN l( m_tail.CLine() );
|
|
|
|
l.Append( m_head.CLine() );
|
2023-05-26 03:10:00 +00:00
|
|
|
|
|
|
|
// Only simplify if we have more than two points, because if we have a zero-length seg as the
|
|
|
|
// only part of the trace, we don't want it to be removed at this stage (will be the case if
|
|
|
|
// the routing start point violates DRC due to track width in shove/walk mode, for example).
|
|
|
|
if( l.PointCount() > 2 )
|
|
|
|
l.Simplify();
|
2022-10-26 22:35:41 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE tmp( m_head );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
tmp.SetShape( l );
|
2022-01-21 23:27:56 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &m_tail, GREEN, 100000, wxT( "tmp-tail" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &m_head, LIGHTGREEN, 100000, wxT( "tmp-head" ) );
|
2022-01-21 23:27:56 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return tmp;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET LINE_PLACER::Traces()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
m_currentTrace = Trace();
|
2016-08-29 17:31:13 +00:00
|
|
|
return ITEM_SET( &m_currentTrace );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
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 LINE_PLACER::FlipPosture()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2023-05-11 23:35:21 +00:00
|
|
|
// In order to fix issue 12369 get the current line placer first direction
|
|
|
|
// and copy it to the mouse trail tracer, as the current placer may have
|
|
|
|
// changed the route.
|
|
|
|
if( m_mouseTrailTracer.IsManuallyForced() == false && m_currentTrace.SegmentCount() > 0 )
|
|
|
|
{
|
|
|
|
DIRECTION_45 firstDirection( m_currentTrace.CSegment( 0 ) );
|
|
|
|
|
|
|
|
m_mouseTrailTracer.SetDefaultDirections( firstDirection, DIRECTION_45::UNDEFINED );
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:42:06 +00:00
|
|
|
m_mouseTrailTracer.FlipPosture();
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* LINE_PLACER::CurrentNode( bool aLoopsRemoved ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aLoopsRemoved && m_lastNode )
|
2014-05-14 13:53:54 +00:00
|
|
|
return m_lastNode;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return m_currentNode;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
bool LINE_PLACER::SplitAdjacentSegments( NODE* aNode, ITEM* aSeg, const VECTOR2I& aP )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:51 +00:00
|
|
|
if( !aSeg )
|
2017-08-03 15:53:07 +00:00
|
|
|
return false;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( !aSeg->OfKind( ITEM::SEGMENT_T ) )
|
2017-08-03 15:53:07 +00:00
|
|
|
return false;
|
2016-08-15 15:16:51 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jt = aNode->FindJoint( aP, aSeg );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-15 15:16:51 +00:00
|
|
|
if( jt && jt->LinkCount() >= 1 )
|
2017-08-03 15:53:07 +00:00
|
|
|
return false;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* s_old = static_cast<SEGMENT*>( aSeg );
|
2016-09-06 14:40:40 +00:00
|
|
|
|
2020-12-01 13:05:31 +00:00
|
|
|
std::unique_ptr<SEGMENT> s_new[2] = { Clone( *s_old ), Clone( *s_old ) };
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-15 15:16:51 +00:00
|
|
|
s_new[0]->SetEnds( s_old->Seg().A, aP );
|
|
|
|
s_new[1]->SetEnds( aP, s_old->Seg().B );
|
|
|
|
|
|
|
|
aNode->Remove( s_old );
|
2016-08-30 15:28:35 +00:00
|
|
|
aNode->Add( std::move( s_new[0] ), true );
|
|
|
|
aNode->Add( std::move( s_new[1] ), true );
|
2017-08-03 15:53:07 +00:00
|
|
|
|
|
|
|
return true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2024-01-24 02:47:36 +00:00
|
|
|
bool LINE_PLACER::SplitAdjacentArcs( NODE* aNode, ITEM* aArc, const VECTOR2I& aP )
|
|
|
|
{
|
|
|
|
if( !aArc )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( !aArc->OfKind( ITEM::ARC_T ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const JOINT* jt = aNode->FindJoint( aP, aArc );
|
|
|
|
|
|
|
|
if( jt && jt->LinkCount() >= 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ARC* a_old = static_cast<ARC*>( aArc );
|
|
|
|
const SHAPE_ARC& o_arc = a_old->Arc();
|
|
|
|
|
|
|
|
std::unique_ptr<ARC> a_new[2] = { Clone( *a_old ), Clone( *a_old ) };
|
|
|
|
|
|
|
|
a_new[0]->Arc().ConstructFromStartEndCenter( o_arc.GetP0(), aP, o_arc.GetCenter(),
|
|
|
|
o_arc.IsClockwise(), o_arc.GetWidth() );
|
|
|
|
|
|
|
|
a_new[1]->Arc().ConstructFromStartEndCenter( aP, o_arc.GetP1(), o_arc.GetCenter(),
|
|
|
|
o_arc.IsClockwise(), o_arc.GetWidth() );
|
|
|
|
|
|
|
|
aNode->Remove( a_old );
|
|
|
|
aNode->Add( std::move( a_new[0] ), true );
|
|
|
|
aNode->Add( std::move( a_new[1] ), true );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::SetLayer( int aLayer )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
if( m_idle )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
m_currentLayer = aLayer;
|
|
|
|
return true;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( m_chainedPlacement )
|
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
return false;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2020-12-01 13:05:31 +00:00
|
|
|
else if( !m_startItem
|
2020-12-02 21:16:48 +00:00
|
|
|
|| ( m_startItem->OfKind( ITEM::VIA_T ) && m_startItem->Layers().Overlaps( aLayer ) )
|
|
|
|
|| ( m_startItem->OfKind( ITEM::SOLID_T ) && m_startItem->Layers().Overlaps( aLayer ) ) )
|
2016-08-15 15:16:53 +00:00
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
m_currentLayer = aLayer;
|
2021-12-15 23:54:52 +00:00
|
|
|
m_p_start = m_currentStart;
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
m_mouseTrailTracer.Clear();
|
2020-02-07 19:57:24 +00:00
|
|
|
m_head.Line().Clear();
|
|
|
|
m_tail.Line().Clear();
|
2021-06-24 02:13:35 +00:00
|
|
|
m_head.RemoveVia();
|
|
|
|
m_tail.RemoveVia();
|
2020-02-07 19:57:24 +00:00
|
|
|
m_head.SetLayer( m_currentLayer );
|
|
|
|
m_tail.SetLayer( m_currentLayer );
|
2021-03-02 13:10:37 +00:00
|
|
|
Move( m_currentEnd, nullptr );
|
2014-11-14 18:15:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-07-09 14:50:31 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
return false;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2020-02-29 19:40:19 +00:00
|
|
|
m_placementCorrect = false;
|
2018-04-25 09:52:23 +00:00
|
|
|
m_currentStart = VECTOR2I( aP );
|
2022-11-15 21:59:54 +00:00
|
|
|
m_fixStart = VECTOR2I( aP );
|
2018-04-25 09:52:23 +00:00
|
|
|
m_currentEnd = VECTOR2I( aP );
|
2023-09-12 13:59:20 +00:00
|
|
|
m_currentNet = aStartItem ? aStartItem->Net() : Router()->GetInterface()->GetOrphanedNetHandle();
|
2014-11-14 18:15:58 +00:00
|
|
|
m_startItem = aStartItem;
|
|
|
|
m_placingVia = false;
|
|
|
|
m_chainedPlacement = false;
|
2020-02-07 19:57:24 +00:00
|
|
|
m_fixedTail.Clear();
|
2021-12-15 00:32:05 +00:00
|
|
|
m_endItem = nullptr;
|
2014-11-14 18:15:58 +00:00
|
|
|
|
|
|
|
setInitialDirection( Settings().InitialDirection() );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
initPlacement();
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2020-12-31 19:08:57 +00:00
|
|
|
DIRECTION_45 initialDir = m_initial_direction;
|
2020-12-29 04:51:05 +00:00
|
|
|
DIRECTION_45 lastSegDir = DIRECTION_45::UNDEFINED;
|
|
|
|
|
|
|
|
if( aStartItem && aStartItem->Kind() == ITEM::SEGMENT_T )
|
|
|
|
{
|
2020-12-31 18:03:52 +00:00
|
|
|
// If we land on a segment endpoint, assume the starting direction is continuing along
|
|
|
|
// the same direction as the endpoint. If we started in the middle, don't set a
|
|
|
|
// direction so that the posture solver is not biased.
|
|
|
|
SEG seg = static_cast<SEGMENT*>( aStartItem )->Seg();
|
|
|
|
|
|
|
|
if( aP == seg.A )
|
|
|
|
lastSegDir = DIRECTION_45( seg.Reversed() );
|
2021-01-07 02:47:06 +00:00
|
|
|
else if( aP == seg.B )
|
|
|
|
lastSegDir = DIRECTION_45( seg );
|
2020-12-29 04:51:05 +00:00
|
|
|
}
|
2020-12-29 06:06:46 +00:00
|
|
|
else if( aStartItem && aStartItem->Kind() == ITEM::SOLID_T &&
|
|
|
|
static_cast<SOLID*>( aStartItem )->Parent()->Type() == PCB_PAD_T )
|
|
|
|
{
|
2022-01-16 21:15:20 +00:00
|
|
|
double angle = static_cast<SOLID*>( aStartItem )->GetOrientation().AsDegrees();
|
2020-12-29 06:06:46 +00:00
|
|
|
angle = ( angle + 22.5 ) / 45.0;
|
2020-12-31 19:08:57 +00:00
|
|
|
initialDir = DIRECTION_45( static_cast<DIRECTION_45::Directions>( int( angle ) ) );
|
2020-12-29 06:06:46 +00:00
|
|
|
}
|
2020-12-29 04:51:05 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "Posture: init %s, last seg %s",
|
|
|
|
initialDir.Format(), lastSegDir.Format() ) );
|
2021-01-07 02:47:06 +00:00
|
|
|
|
2020-10-19 19:42:06 +00:00
|
|
|
m_mouseTrailTracer.Clear();
|
|
|
|
m_mouseTrailTracer.AddTrailPoint( aP );
|
|
|
|
m_mouseTrailTracer.SetTolerance( m_head.Width() );
|
|
|
|
m_mouseTrailTracer.SetDefaultDirections( m_initial_direction, DIRECTION_45::UNDEFINED );
|
|
|
|
m_mouseTrailTracer.SetMouseDisabled( !Settings().GetAutoPosture() );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
NODE *n;
|
|
|
|
|
2021-12-01 09:52:37 +00:00
|
|
|
if ( Settings().Mode() == PNS::RM_Shove )
|
2020-02-07 19:57:24 +00:00
|
|
|
n = m_shove->CurrentNode();
|
|
|
|
else
|
|
|
|
n = m_currentNode;
|
|
|
|
|
2022-11-15 21:59:54 +00:00
|
|
|
m_fixedTail.AddStage( m_fixStart, m_currentLayer, m_placingVia, m_direction, n );
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::initPlacement()
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
m_idle = false;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
m_head.Line().Clear();
|
|
|
|
m_tail.Line().Clear();
|
|
|
|
m_head.SetNet( m_currentNet );
|
|
|
|
m_tail.SetNet( m_currentNet );
|
|
|
|
m_head.SetLayer( m_currentLayer );
|
|
|
|
m_tail.SetLayer( m_currentLayer );
|
|
|
|
m_head.SetWidth( m_sizes.TrackWidth() );
|
|
|
|
m_tail.SetWidth( m_sizes.TrackWidth() );
|
2015-07-07 16:36:43 +00:00
|
|
|
m_head.RemoveVia();
|
|
|
|
m_tail.RemoveVia();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
m_last_p_end.reset();
|
2014-11-14 18:15:58 +00:00
|
|
|
m_p_start = m_currentStart;
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* world = Router()->GetWorld();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
world->KillChildren();
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* rootNode = world->Branch();
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
SplitAdjacentSegments( rootNode, m_startItem, m_currentStart );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
setWorld( rootNode );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "world %p, intitial-direction %s layer %d" ),
|
2020-12-01 13:05:31 +00:00
|
|
|
m_world,
|
|
|
|
m_direction.Format().c_str(),
|
|
|
|
m_currentLayer );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
m_lastNode = nullptr;
|
2014-11-14 18:15:58 +00:00
|
|
|
m_currentNode = m_world;
|
|
|
|
|
2021-10-12 16:53:52 +00:00
|
|
|
m_shove = std::make_unique<SHOVE>( m_world->Branch(), Router() );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE current;
|
2023-07-17 11:51:41 +00:00
|
|
|
int eiDepth = -1;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aEndItem && aEndItem->Owner() )
|
2022-08-29 20:21:46 +00:00
|
|
|
eiDepth = static_cast<const NODE*>( aEndItem->Owner() )->Depth();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( m_lastNode )
|
|
|
|
{
|
|
|
|
delete m_lastNode;
|
2021-03-02 13:10:37 +00:00
|
|
|
m_lastNode = nullptr;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-12-15 00:32:05 +00:00
|
|
|
m_endItem = aEndItem;
|
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
bool reachesEnd = route( aP );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
current = Trace();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !current.PointCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentEnd = m_p_start;
|
|
|
|
else
|
2014-05-31 14:04:25 +00:00
|
|
|
m_currentEnd = current.CLine().CPoint( -1 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* latestNode = m_currentNode;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_lastNode = latestNode->Branch();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-12-01 13:05:31 +00:00
|
|
|
if( reachesEnd
|
|
|
|
&& eiDepth >= 0
|
2021-11-27 20:21:47 +00:00
|
|
|
&& aEndItem && latestNode->Depth() >= eiDepth
|
2020-12-01 13:05:31 +00:00
|
|
|
&& current.SegmentCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2024-02-19 22:28:55 +00:00
|
|
|
if ( aEndItem->Net() == m_currentNet )
|
|
|
|
SplitAdjacentSegments( m_lastNode, aEndItem, current.CPoint( -1 ) );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( Settings().RemoveLoops() )
|
2015-08-03 19:11:51 +00:00
|
|
|
removeLoops( m_lastNode, current );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateLeadingRatLine();
|
2020-10-19 19:42:06 +00:00
|
|
|
m_mouseTrailTracer.AddTrailPoint( aP );
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
bool LINE_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-12-24 02:55:43 +00:00
|
|
|
bool fixAll = Settings().GetFixAllSegments();
|
2014-05-14 13:53:54 +00:00
|
|
|
bool realEnd = false;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE pl = Trace();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-10-12 16:53:52 +00:00
|
|
|
if( Settings().Mode() == RM_MarkObstacles )
|
2018-04-08 20:20:51 +00:00
|
|
|
{
|
|
|
|
// Mark Obstacles is sort of a half-manual, half-automated mode in which the
|
|
|
|
// user has more responsibility and authority.
|
|
|
|
|
|
|
|
if( aEndItem )
|
|
|
|
{
|
2020-12-02 18:42:37 +00:00
|
|
|
// The user has indicated a connection should be made. If either the trace or
|
|
|
|
// endItem is net-less, then allow the connection by adopting the net of the other.
|
2023-08-22 12:06:33 +00:00
|
|
|
if( m_router->GetInterface()->GetNetCode( m_currentNet ) <= 0 )
|
2018-04-08 20:20:51 +00:00
|
|
|
{
|
|
|
|
m_currentNet = aEndItem->Net();
|
|
|
|
pl.SetNet( m_currentNet );
|
|
|
|
}
|
2023-08-22 12:06:33 +00:00
|
|
|
else if( m_router->GetInterface()->GetNetCode( aEndItem->Net() ) <= 0 )
|
2020-12-01 13:05:31 +00:00
|
|
|
{
|
2018-04-08 20:20:51 +00:00
|
|
|
aEndItem->SetNet( m_currentNet );
|
2020-12-01 13:05:31 +00:00
|
|
|
}
|
2018-04-08 20:20:51 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2023-05-26 03:10:00 +00:00
|
|
|
// Collisions still prevent fixing unless "Allow DRC violations" is checked
|
|
|
|
// Note that collisions can occur even in walk/shove modes if the beginning of the trace
|
2023-05-29 22:19:29 +00:00
|
|
|
// collides (for example if the starting track width is too high).
|
|
|
|
|
|
|
|
if( !Settings().AllowDRCViolations() )
|
|
|
|
{
|
|
|
|
NODE* checkNode = ( Settings().Mode() == RM_Shove ) ? m_shove->CurrentNode() : m_world;
|
|
|
|
std::optional<OBSTACLE> obs = checkNode->CheckColliding( &pl );
|
|
|
|
|
|
|
|
if( obs )
|
|
|
|
{
|
|
|
|
// TODO: Determine why the shove node sometimes reports collisions against shoved objects.
|
|
|
|
// For now, to work around this issue, we consider only solids in shove mode.
|
|
|
|
if( Settings().Mode() != RM_Shove || obs->m_item->OfKind( ITEM::SOLID_T ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 03:10:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN& l = pl.CLine();
|
|
|
|
|
|
|
|
if( !l.SegmentCount() )
|
2015-07-02 14:09:24 +00:00
|
|
|
{
|
2020-12-30 18:44:05 +00:00
|
|
|
if( m_lastNode )
|
|
|
|
{
|
|
|
|
// Do a final optimization to the stored state
|
|
|
|
NODE::ITEM_VECTOR removed, added;
|
|
|
|
m_lastNode->GetUpdatedItems( removed, added );
|
2020-12-30 02:14:14 +00:00
|
|
|
|
2020-12-30 18:44:05 +00:00
|
|
|
if( !added.empty() && added.back()->Kind() == ITEM::SEGMENT_T )
|
|
|
|
simplifyNewLine( m_lastNode, static_cast<SEGMENT*>( added.back() ) );
|
|
|
|
}
|
2020-12-30 02:14:14 +00:00
|
|
|
|
2020-03-02 15:09:42 +00:00
|
|
|
// Nothing to commit if we have an empty line
|
|
|
|
if( !pl.EndsWithVia() )
|
|
|
|
return false;
|
2015-09-14 16:40:29 +00:00
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
///< @todo Determine what to do if m_lastNode is a null pointer. I'm guessing return
|
|
|
|
///< false but someone with more knowledge of the code will need to determine that..
|
|
|
|
if( m_lastNode )
|
2021-11-20 23:17:20 +00:00
|
|
|
{
|
2021-03-02 13:10:37 +00:00
|
|
|
m_lastNode->Add( Clone( pl.Via() ) );
|
2021-11-20 23:17:20 +00:00
|
|
|
m_shove->AddLockedSpringbackNode( m_lastNode );
|
|
|
|
}
|
2021-03-02 13:10:37 +00:00
|
|
|
|
|
|
|
m_currentNode = nullptr;
|
2015-07-07 16:36:38 +00:00
|
|
|
|
2020-03-02 15:09:42 +00:00
|
|
|
m_idle = true;
|
|
|
|
m_placementCorrect = true;
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
2015-07-02 14:09:24 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
VECTOR2I p_pre_last = l.CPoint( -1 );
|
|
|
|
const VECTOR2I p_last = l.CPoint( -1 );
|
2020-12-29 04:51:05 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( l.PointCount() > 2 )
|
|
|
|
p_pre_last = l.CPoint( -2 );
|
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
if( aEndItem && m_currentNet && m_currentNet == aEndItem->Net() )
|
2014-05-14 13:53:54 +00:00
|
|
|
realEnd = true;
|
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
if( aForceFinish )
|
|
|
|
realEnd = true;
|
|
|
|
|
2020-12-30 21:10:46 +00:00
|
|
|
// TODO: Rollback doesn't work properly if fix-all isn't enabled and we are placing arcs,
|
|
|
|
// so if we are, act as though we are in fix-all mode.
|
|
|
|
if( !fixAll && l.ArcCount() )
|
|
|
|
fixAll = true;
|
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
// TODO: lastDirSeg will be calculated incorrectly if we end on an arc
|
2020-12-30 21:10:46 +00:00
|
|
|
SEG lastDirSeg = ( !fixAll && l.SegmentCount() > 1 ) ? l.CSegment( -2 ) : l.CSegment( -1 );
|
|
|
|
DIRECTION_45 d_last( lastDirSeg );
|
|
|
|
|
|
|
|
int lastV;
|
|
|
|
|
2020-12-24 02:55:43 +00:00
|
|
|
if( realEnd || m_placingVia || fixAll )
|
2014-05-14 13:53:54 +00:00
|
|
|
lastV = l.SegmentCount();
|
|
|
|
else
|
2014-05-16 11:37:31 +00:00
|
|
|
lastV = std::max( 1, l.SegmentCount() - 1 );
|
|
|
|
|
2021-01-04 03:36:42 +00:00
|
|
|
ARC arc;
|
|
|
|
SEGMENT seg;
|
|
|
|
LINKED_ITEM* lastItem = nullptr;
|
|
|
|
int lastArc = -1;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < lastV; i++ )
|
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
ssize_t arcIndex = l.ArcIndex( i );
|
|
|
|
|
2021-05-06 22:10:39 +00:00
|
|
|
if( arcIndex < 0 || ( lastArc >= 0 && i == lastV - 1 && !l.IsPtOnArc( lastV ) ) )
|
2018-02-08 10:32:13 +00:00
|
|
|
{
|
2020-12-30 02:14:14 +00:00
|
|
|
seg = SEGMENT( pl.CSegment( i ), m_currentNet );
|
|
|
|
seg.SetWidth( pl.Width() );
|
|
|
|
seg.SetLayer( m_currentLayer );
|
2020-12-01 13:05:31 +00:00
|
|
|
|
2021-06-08 00:34:00 +00:00
|
|
|
std::unique_ptr<SEGMENT> sp = std::make_unique<SEGMENT>( seg );
|
|
|
|
lastItem = sp.get();
|
|
|
|
|
|
|
|
if( !m_lastNode->Add( std::move( sp ) ) )
|
|
|
|
lastItem = nullptr;
|
2019-05-17 00:13:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( arcIndex == lastArc )
|
|
|
|
continue;
|
|
|
|
|
2021-01-04 03:36:42 +00:00
|
|
|
arc = ARC( l.Arc( arcIndex ), m_currentNet );
|
|
|
|
arc.SetWidth( pl.Width() );
|
|
|
|
arc.SetLayer( m_currentLayer );
|
|
|
|
|
2021-06-08 00:34:00 +00:00
|
|
|
std::unique_ptr<ARC> ap = std::make_unique<ARC>( arc );
|
|
|
|
lastItem = ap.get();
|
|
|
|
|
2021-07-14 01:13:40 +00:00
|
|
|
if( !m_lastNode->Add( std::move( ap ) ) )
|
|
|
|
lastItem = nullptr;
|
|
|
|
|
2021-01-04 03:36:42 +00:00
|
|
|
lastArc = arcIndex;
|
2018-02-08 10:32:13 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( pl.EndsWithVia() )
|
2016-08-30 15:28:35 +00:00
|
|
|
m_lastNode->Add( Clone( pl.Via() ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-01-04 03:36:42 +00:00
|
|
|
if( realEnd && lastItem )
|
|
|
|
simplifyNewLine( m_lastNode, lastItem );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !realEnd )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-12-30 21:10:46 +00:00
|
|
|
setInitialDirection( d_last );
|
2020-12-24 02:55:43 +00:00
|
|
|
m_currentStart = ( m_placingVia || fixAll ) ? p_last : p_pre_last;
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2022-11-15 21:59:54 +00:00
|
|
|
m_fixedTail.AddStage( m_fixStart, m_currentLayer, m_placingVia, m_direction, m_currentNode );
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2022-11-15 21:59:54 +00:00
|
|
|
m_fixStart = m_currentStart;
|
2021-03-02 13:10:37 +00:00
|
|
|
m_startItem = nullptr;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_placingVia = false;
|
2014-11-14 18:15:58 +00:00
|
|
|
m_chainedPlacement = !pl.EndsWithVia();
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
m_p_start = m_currentStart;
|
|
|
|
m_direction = m_initial_direction;
|
|
|
|
|
|
|
|
m_head.Line().Clear();
|
|
|
|
m_tail.Line().Clear();
|
2020-03-03 00:21:34 +00:00
|
|
|
m_head.RemoveVia();
|
|
|
|
m_tail.RemoveVia();
|
2020-02-07 19:57:24 +00:00
|
|
|
m_currentNode = m_lastNode;
|
|
|
|
m_lastNode = m_lastNode->Branch();
|
|
|
|
|
2021-10-12 16:53:52 +00:00
|
|
|
m_shove->AddLockedSpringbackNode( m_currentNode );
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-12-30 02:14:14 +00:00
|
|
|
DIRECTION_45 lastSegDir = pl.EndsWithVia() ? DIRECTION_45::UNDEFINED : d_last;
|
|
|
|
|
2020-10-19 19:42:06 +00:00
|
|
|
m_mouseTrailTracer.Clear();
|
|
|
|
m_mouseTrailTracer.SetTolerance( m_head.Width() );
|
|
|
|
m_mouseTrailTracer.AddTrailPoint( m_currentStart );
|
2023-01-12 22:35:41 +00:00
|
|
|
m_mouseTrailTracer.SetDefaultDirections( lastSegDir, DIRECTION_45::UNDEFINED );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2020-02-29 19:40:19 +00:00
|
|
|
m_placementCorrect = true;
|
2015-03-10 14:38:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-10 23:17:47 +00:00
|
|
|
m_shove->AddLockedSpringbackNode( m_lastNode );
|
2020-02-29 19:40:19 +00:00
|
|
|
m_placementCorrect = true;
|
2014-11-14 18:15:58 +00:00
|
|
|
m_idle = true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return realEnd;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
std::optional<VECTOR2I> LINE_PLACER::UnfixRoute()
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
2023-06-19 16:09:03 +00:00
|
|
|
FIXED_TAIL::STAGE st;
|
|
|
|
std::optional<VECTOR2I> ret;
|
2020-02-07 19:57:24 +00:00
|
|
|
|
|
|
|
if ( !m_fixedTail.PopStage( st ) )
|
2023-06-19 16:09:03 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
if( m_head.Line().PointCount() )
|
|
|
|
ret = m_head.Line().CPoint( 0 );
|
2020-02-07 19:57:24 +00:00
|
|
|
|
|
|
|
m_head.Line().Clear();
|
|
|
|
m_tail.Line().Clear();
|
2021-03-02 13:10:37 +00:00
|
|
|
m_startItem = nullptr;
|
2020-02-07 19:57:24 +00:00
|
|
|
m_p_start = st.pts[0].p;
|
2022-11-15 21:59:54 +00:00
|
|
|
m_fixStart = m_p_start;
|
2020-02-07 19:57:24 +00:00
|
|
|
m_direction = st.pts[0].direction;
|
|
|
|
m_placingVia = st.pts[0].placingVias;
|
|
|
|
m_currentNode = st.commit;
|
|
|
|
m_currentLayer = st.pts[0].layer;
|
2022-11-15 21:59:54 +00:00
|
|
|
m_currentStart = m_p_start;
|
2020-02-07 19:57:24 +00:00
|
|
|
m_head.SetLayer( m_currentLayer );
|
|
|
|
m_tail.SetLayer( m_currentLayer );
|
2020-12-02 18:42:37 +00:00
|
|
|
m_head.RemoveVia();
|
|
|
|
m_tail.RemoveVia();
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-10-19 19:42:06 +00:00
|
|
|
m_mouseTrailTracer.Clear();
|
|
|
|
m_mouseTrailTracer.SetDefaultDirections( m_initial_direction, m_direction );
|
|
|
|
m_mouseTrailTracer.AddTrailPoint( m_p_start );
|
2020-12-30 21:10:46 +00:00
|
|
|
|
2021-10-12 16:53:52 +00:00
|
|
|
m_shove->RewindSpringbackTo( m_currentNode );
|
|
|
|
m_shove->UnlockSpringbackNode( m_currentNode );
|
|
|
|
|
2021-12-01 09:52:37 +00:00
|
|
|
if( Settings().Mode() == PNS::RM_Shove )
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
m_currentNode->KillChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastNode = m_currentNode->Branch();
|
|
|
|
|
2023-06-19 16:09:03 +00:00
|
|
|
return ret;
|
2020-02-07 19:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LINE_PLACER::HasPlacedAnything() const
|
|
|
|
{
|
2020-02-29 19:40:19 +00:00
|
|
|
return m_placementCorrect || m_fixedTail.StageCount() > 1;
|
2020-02-07 19:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LINE_PLACER::CommitPlacement()
|
|
|
|
{
|
2021-12-01 09:52:37 +00:00
|
|
|
if( Settings().Mode() == PNS::RM_Shove )
|
2021-11-09 05:00:54 +00:00
|
|
|
{
|
|
|
|
m_shove->RewindToLastLockedNode();
|
|
|
|
m_lastNode = m_shove->CurrentNode();
|
|
|
|
m_lastNode->KillChildren();
|
|
|
|
}
|
|
|
|
|
2020-03-03 21:45:07 +00:00
|
|
|
if( m_lastNode )
|
|
|
|
Router()->CommitRouting( m_lastNode );
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
m_lastNode = nullptr;
|
|
|
|
m_currentNode = nullptr;
|
2020-02-07 19:57:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::removeLoops( NODE* aNode, LINE& aLatest )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !aLatest.SegmentCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
return;
|
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
if( aLatest.CLine().CPoint( 0 ) == aLatest.CLine().CPoint( -1 ) )
|
2015-07-02 14:09:24 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
std::set<LINKED_ITEM *> toErase;
|
2016-08-30 15:28:35 +00:00
|
|
|
aNode->Add( aLatest, true );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-20 13:11:16 +00:00
|
|
|
for( int s = 0; s < aLatest.LinkCount(); s++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-12-01 13:05:31 +00:00
|
|
|
LINKED_ITEM* seg = aLatest.GetLink(s);
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE ourLine = aNode->AssembleLine( seg );
|
|
|
|
JOINT a, b;
|
|
|
|
std::vector<LINE> lines;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
aNode->FindLineEnds( ourLine, a, b );
|
|
|
|
|
|
|
|
if( a == b )
|
2015-03-10 14:38:27 +00:00
|
|
|
aNode->FindLineEnds( aLatest, a, b );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aNode->FindLinesBetweenJoints( a, b, lines );
|
|
|
|
|
|
|
|
int removedCount = 0;
|
|
|
|
int total = 0;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( LINE& line : lines )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
total++;
|
|
|
|
|
2020-04-15 20:16:24 +00:00
|
|
|
if( !( line.ContainsLink( seg ) ) && line.SegmentCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-12-02 18:42:37 +00:00
|
|
|
for( LINKED_ITEM* ss : line.Links() )
|
2015-11-03 16:19:42 +00:00
|
|
|
toErase.insert( ss );
|
|
|
|
|
2015-07-22 08:46:56 +00:00
|
|
|
removedCount++;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "total segs removed: %d/%d", removedCount, total ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-12-01 13:05:31 +00:00
|
|
|
for( LINKED_ITEM* s : toErase )
|
2015-11-03 16:19:42 +00:00
|
|
|
aNode->Remove( s );
|
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
aNode->Remove( aLatest );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2021-01-04 03:36:42 +00:00
|
|
|
void LINE_PLACER::simplifyNewLine( NODE* aNode, LINKED_ITEM* aLatest )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-04 03:36:42 +00:00
|
|
|
wxASSERT( aLatest->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) );
|
2021-06-07 01:52:35 +00:00
|
|
|
|
|
|
|
// Before we assemble the final line and run the optimizer, do a separate pass to clean up
|
|
|
|
// colinear segments that exist on non-line-corner joints, as these will prevent proper assembly
|
|
|
|
// of the line and won't get cleaned up by the optimizer.
|
|
|
|
NODE::ITEM_VECTOR removed, added;
|
|
|
|
aNode->GetUpdatedItems( removed, added );
|
|
|
|
|
|
|
|
std::set<ITEM*> cleanup;
|
|
|
|
|
|
|
|
auto processJoint =
|
2022-08-29 20:21:46 +00:00
|
|
|
[&]( const JOINT* aJoint, ITEM* aItem )
|
2021-06-07 01:52:35 +00:00
|
|
|
{
|
|
|
|
if( !aJoint || aJoint->IsLineCorner() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SEG refSeg = static_cast<SEGMENT*>( aItem )->Seg();
|
|
|
|
|
|
|
|
NODE::ITEM_VECTOR toRemove;
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
for( ITEM* neighbor : aJoint->CLinks().CItems() )
|
2021-06-07 01:52:35 +00:00
|
|
|
{
|
2021-11-27 20:21:47 +00:00
|
|
|
if( neighbor == aItem
|
|
|
|
|| !neighbor->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T )
|
|
|
|
|| !neighbor->LayersOverlap( aItem ) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
if( static_cast<const SEGMENT*>( neighbor )->Width()
|
|
|
|
!= static_cast<const SEGMENT*>( aItem )->Width() )
|
2021-11-27 20:21:47 +00:00
|
|
|
{
|
2021-06-07 01:52:35 +00:00
|
|
|
continue;
|
2021-11-27 20:21:47 +00:00
|
|
|
}
|
2021-06-07 01:52:35 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const SEG& testSeg = static_cast<const SEGMENT*>( neighbor )->Seg();
|
2021-06-07 01:52:35 +00:00
|
|
|
|
|
|
|
if( refSeg.Contains( testSeg ) )
|
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* nA = aNode->FindJoint( neighbor->Anchor( 0 ), neighbor );
|
|
|
|
const JOINT* nB = aNode->FindJoint( neighbor->Anchor( 1 ), neighbor );
|
2021-06-07 01:52:35 +00:00
|
|
|
|
|
|
|
if( ( nA == aJoint && nB->LinkCount() == 1 ) ||
|
|
|
|
( nB == aJoint && nA->LinkCount() == 1 ) )
|
|
|
|
{
|
|
|
|
cleanup.insert( neighbor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for( ITEM* item : added )
|
|
|
|
{
|
|
|
|
if( !item->OfKind( ITEM::SEGMENT_T ) || cleanup.count( item ) )
|
|
|
|
continue;
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jA = aNode->FindJoint( item->Anchor( 0 ), item );
|
|
|
|
const JOINT* jB = aNode->FindJoint( item->Anchor( 1 ), item );
|
2021-06-07 01:52:35 +00:00
|
|
|
|
|
|
|
processJoint( jA, item );
|
|
|
|
processJoint( jB, item );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ITEM* seg : cleanup )
|
|
|
|
aNode->Remove( seg );
|
|
|
|
|
|
|
|
// And now we can proceed with assembling the final line and optimizing it.
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE l = aNode->AssembleLine( aLatest );
|
2020-12-30 02:14:14 +00:00
|
|
|
|
|
|
|
bool optimized = OPTIMIZER::Optimize( &l, OPTIMIZER::MERGE_COLINEAR, aNode );
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
SHAPE_LINE_CHAIN simplified( l.CLine() );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
simplified.Simplify();
|
|
|
|
|
2020-12-30 02:14:14 +00:00
|
|
|
if( optimized || simplified.PointCount() != l.PointCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-30 17:01:30 +00:00
|
|
|
aNode->Remove( l );
|
2016-09-06 14:40:40 +00:00
|
|
|
l.SetShape( simplified );
|
|
|
|
aNode->Add( l );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::UpdateSizes( const SIZES_SETTINGS& aSizes )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-12-11 17:54:55 +00:00
|
|
|
m_sizes = aSizes;
|
|
|
|
|
|
|
|
if( !m_idle )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2021-10-12 16:52:24 +00:00
|
|
|
// If the track width continues from an existing track, we don't want to change the width.
|
2021-10-14 16:19:39 +00:00
|
|
|
// Disallow changing width after the first segment has been fixed because we don't want to
|
|
|
|
// go back and rip up tracks or allow DRC errors
|
2023-07-17 11:51:41 +00:00
|
|
|
if( m_sizes.TrackWidthIsExplicit()
|
|
|
|
|| ( !HasPlacedAnything() && ( !m_startItem || m_startItem->Kind() != ITEM::SEGMENT_T ) ) )
|
2021-06-07 00:18:09 +00:00
|
|
|
{
|
|
|
|
m_head.SetWidth( m_sizes.TrackWidth() );
|
|
|
|
m_tail.SetWidth( m_sizes.TrackWidth() );
|
2021-10-14 16:19:39 +00:00
|
|
|
m_currentTrace.SetWidth( m_sizes.TrackWidth() );
|
2021-06-07 00:18:09 +00:00
|
|
|
}
|
2020-02-06 17:03:34 +00:00
|
|
|
|
2020-12-11 17:54:55 +00:00
|
|
|
if( m_head.EndsWithVia() )
|
|
|
|
{
|
|
|
|
m_head.SetViaDiameter( m_sizes.ViaDiameter() );
|
|
|
|
m_head.SetViaDrill( m_sizes.ViaDrill() );
|
|
|
|
}
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::updateLeadingRatLine()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE current = Trace();
|
2015-02-18 00:29:54 +00:00
|
|
|
SHAPE_LINE_CHAIN ratLine;
|
2016-08-29 17:31:13 +00:00
|
|
|
TOPOLOGY topo( m_lastNode );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
if( topo.LeadingRatLine( ¤t, ratLine ) )
|
2022-10-16 21:21:14 +00:00
|
|
|
m_router->GetInterface()->DisplayRatline( ratLine, m_currentNet );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::SetOrthoMode( bool aOrthoMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_orthoMode = aOrthoMode;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
bool LINE_PLACER::buildInitialLine( const VECTOR2I& aP, LINE& aHead, bool aForceNoVia )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-02 14:09:24 +00:00
|
|
|
SHAPE_LINE_CHAIN l;
|
2020-10-19 19:42:06 +00:00
|
|
|
DIRECTION_45 guessedDir = m_mouseTrailTracer.GetPosture( aP );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "buildInitialLine: m_direction %s, guessedDir %s, tail points %d" ),
|
|
|
|
m_direction.Format(), guessedDir.Format(), m_tail.PointCount() ) );
|
2021-01-04 02:37:24 +00:00
|
|
|
|
2021-11-03 02:14:23 +00:00
|
|
|
DIRECTION_45::CORNER_MODE cornerMode = Settings().GetCornerMode();
|
2020-12-30 05:06:49 +00:00
|
|
|
// Rounded corners don't make sense when routing orthogonally (single track at a time)
|
2021-11-03 02:14:23 +00:00
|
|
|
if( m_orthoMode )
|
|
|
|
cornerMode = DIRECTION_45::CORNER_MODE::MITERED_45;
|
2020-12-30 05:06:49 +00:00
|
|
|
|
2022-06-03 20:53:13 +00:00
|
|
|
PNS_DBG( Dbg(), AddPoint, m_p_start, WHITE, 10000, wxT( "pstart [buildInitial]" ) );
|
|
|
|
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( m_p_start == aP )
|
2015-07-02 14:09:24 +00:00
|
|
|
{
|
|
|
|
l.Clear();
|
2015-07-02 14:11:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-02 14:09:51 +00:00
|
|
|
if( Settings().GetFreeAngleMode() && Settings().Mode() == RM_MarkObstacles )
|
|
|
|
{
|
2019-03-24 13:54:56 +00:00
|
|
|
l = SHAPE_LINE_CHAIN( { m_p_start, aP } );
|
2015-07-02 14:11:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-24 22:31:45 +00:00
|
|
|
if( !m_tail.PointCount() )
|
2021-11-03 02:14:23 +00:00
|
|
|
l = guessedDir.BuildInitialTrace( m_p_start, aP, false, cornerMode );
|
2017-01-19 12:55:22 +00:00
|
|
|
else
|
2021-11-03 02:14:23 +00:00
|
|
|
l = m_direction.BuildInitialTrace( m_p_start, aP, false, cornerMode );
|
2015-07-02 14:09:51 +00:00
|
|
|
}
|
2015-07-02 14:09:24 +00:00
|
|
|
|
|
|
|
if( l.SegmentCount() > 1 && m_orthoMode )
|
|
|
|
{
|
|
|
|
VECTOR2I newLast = l.CSegment( 0 ).LineProject( l.CPoint( -1 ) );
|
|
|
|
|
|
|
|
l.Remove( -1, -1 );
|
2019-03-23 18:26:44 +00:00
|
|
|
l.SetPoint( 1, newLast );
|
2015-07-02 14:09:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
aHead.SetLayer( m_currentLayer );
|
2015-07-02 14:09:24 +00:00
|
|
|
aHead.SetShape( l );
|
|
|
|
|
2022-06-03 20:53:13 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &aHead, CYAN, 10000, wxT( "initial-trace" ) );
|
|
|
|
|
|
|
|
|
2021-05-27 22:08:31 +00:00
|
|
|
if( !m_placingVia || aForceNoVia )
|
2015-07-02 14:09:24 +00:00
|
|
|
return true;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA v( makeVia( aP ) );
|
2015-07-02 14:11:15 +00:00
|
|
|
v.SetNet( aHead.Net() );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-10-12 16:53:52 +00:00
|
|
|
if( Settings().Mode() == RM_MarkObstacles )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-07-02 14:11:15 +00:00
|
|
|
aHead.AppendVia( v );
|
2015-07-02 14:09:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
const int collMask = ( Settings().Mode() == RM_Walkaround ) ? ITEM::ANY_T : ITEM::SOLID_T;
|
|
|
|
const int iterLimit = Settings().ViaForcePropIterationLimit();
|
|
|
|
|
|
|
|
for( int attempt = 0; attempt < 2; attempt++)
|
|
|
|
{
|
|
|
|
VECTOR2I lead = aP - m_p_start;
|
2023-07-17 11:51:41 +00:00
|
|
|
VECTOR2I force;
|
2015-07-02 14:09:24 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( attempt == 1 && m_last_p_end.has_value() )
|
|
|
|
lead = aP - m_last_p_end.value();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-10-26 22:35:41 +00:00
|
|
|
if( v.PushoutForce( m_currentNode, lead, force, collMask, iterLimit ) )
|
2023-07-17 11:51:41 +00:00
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN line = guessedDir.BuildInitialTrace( m_p_start, aP + force, false, cornerMode );
|
|
|
|
aHead = LINE( aHead, line );
|
2015-07-02 14:09:24 +00:00
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
v.SetPos( v.Pos() + force );
|
2022-10-26 22:35:41 +00:00
|
|
|
|
|
|
|
aHead.AppendVia( v );
|
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
PNS_DBG( Dbg(), AddPoint, v.Pos(), GREEN, 1000000, "via-force-coll-2" );
|
2022-10-26 22:35:41 +00:00
|
|
|
|
2023-07-17 11:51:41 +00:00
|
|
|
return true;
|
2022-10-26 22:35:41 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-07-02 14:09:24 +00:00
|
|
|
return false; // via placement unsuccessful
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
void LINE_PLACER::GetModifiedNets( std::vector<NET_HANDLE>& aNets ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
aNets.push_back( m_currentNet );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
bool LINE_PLACER::AbortPlacement()
|
|
|
|
{
|
|
|
|
m_world->KillChildren();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2020-12-01 13:05:31 +00:00
|
|
|
FIXED_TAIL::FIXED_TAIL( int aLineCount )
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2020-07-29 07:21:31 +00:00
|
|
|
FIXED_TAIL::~FIXED_TAIL()
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
void FIXED_TAIL::Clear()
|
|
|
|
{
|
|
|
|
m_stages.clear();
|
|
|
|
}
|
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void FIXED_TAIL::AddStage( const VECTOR2I& aStart, int aLayer, bool placingVias,
|
|
|
|
DIRECTION_45 direction, NODE* aNode )
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
|
|
|
STAGE st;
|
|
|
|
FIX_POINT pt;
|
|
|
|
|
|
|
|
pt.p = aStart;
|
|
|
|
pt.layer = aLayer;
|
|
|
|
pt.direction = direction;
|
|
|
|
pt.placingVias = placingVias;
|
|
|
|
|
|
|
|
st.pts.push_back(pt);
|
|
|
|
st.commit = aNode;
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
m_stages.push_back( st );
|
|
|
|
}
|
|
|
|
|
2021-03-02 13:10:37 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
bool FIXED_TAIL::PopStage( FIXED_TAIL::STAGE& aStage )
|
|
|
|
{
|
|
|
|
if( !m_stages.size() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
aStage = m_stages.back();
|
|
|
|
|
|
|
|
if( m_stages.size() > 1 )
|
|
|
|
m_stages.pop_back();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int FIXED_TAIL::StageCount() const
|
|
|
|
{
|
|
|
|
return m_stages.size();
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
}
|
|
|
|
|