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
|
2020-01-17 03:54:51 +00:00
|
|
|
* Copyright (C) 2016-2020 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
|
|
|
*/
|
|
|
|
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
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"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_topology.h"
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_utils.h"
|
|
|
|
#include "pns_walkaround.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <class_board_item.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
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;
|
|
|
|
m_world = NULL;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_shove = NULL;
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = NULL;
|
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)
|
|
|
|
m_lastNode = NULL;
|
|
|
|
m_placingVia = false;
|
|
|
|
m_currentNet = 0;
|
|
|
|
m_currentLayer = 0;
|
|
|
|
m_currentMode = RM_MarkObstacles;
|
|
|
|
m_startItem = NULL;
|
|
|
|
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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const LAYER_RANGE layers( m_sizes.GetLayerTop(), m_sizes.GetLayerBottom() );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
return VIA( aP, layers, m_sizes.ViaDiameter(), m_sizes.ViaDrill(), -1, 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_p_start = tail.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
|
|
|
{
|
|
|
|
if( i.our.Index() < n )
|
|
|
|
{
|
|
|
|
n = i.our.Index();
|
|
|
|
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 )
|
|
|
|
{
|
2019-03-23 18:26:44 +00:00
|
|
|
m_p_start = tail.CPoint( 0 );
|
2013-09-26 21:53:54 +00:00
|
|
|
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 );
|
2013-10-14 18:40:36 +00:00
|
|
|
m_p_start = last.A;
|
2013-09-26 21:53:54 +00:00
|
|
|
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 )
|
|
|
|
return false;
|
|
|
|
else if( n == 1 )
|
|
|
|
{
|
|
|
|
m_p_start = tail.CPoint( 0 );
|
|
|
|
tail.Clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
DIRECTION_45 first_head( head.CSegment( 0 ) );
|
|
|
|
DIRECTION_45 last_tail( tail.CSegment( -1 ) );
|
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 )
|
|
|
|
{
|
|
|
|
const SEG last = tail.CSegment( -1 );
|
|
|
|
m_direction = DIRECTION_45( last );
|
2013-10-14 18:40:36 +00:00
|
|
|
m_p_start = last.A;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "Placer: pullback triggered [%d] [%s %s]",
|
|
|
|
n, last_tail.Format().c_str(), first_head.Format().c_str() );
|
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
|
|
|
|
tail.Remove( -1, -1 );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "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_p_start = new_start;
|
|
|
|
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::checkObtusity( const SEG& aA, const SEG& aB ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
const DIRECTION_45 dir_a( aA );
|
|
|
|
const DIRECTION_45 dir_b( aB );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
return dir_a.IsObtuse( dir_b ) || dir_a == dir_b;
|
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
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
const int ForbiddenAngles = DIRECTION_45::ANG_ACUTE |
|
2013-09-26 21:53:54 +00:00
|
|
|
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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
int n_head = head.SegmentCount();
|
|
|
|
int n_tail = tail.SegmentCount();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( n_head < 3 )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "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 ) )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
dir_head = DIRECTION_45( head.CSegment( 0 ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( n_tail )
|
|
|
|
{
|
|
|
|
dir_tail = DIRECTION_45( tail.CSegment( -1 ) );
|
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 );
|
|
|
|
tail.Remove( -1 );
|
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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
SEG last = tail.CSegment( -1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
m_p_start = last.B;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_direction = DIRECTION_45( last ).Right();
|
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
|
|
|
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "Placer: merge %d, new direction: %s", n_head, m_direction.Format().c_str() );
|
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
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
VECTOR2I closestProjectedPoint( const SHAPE_LINE_CHAIN& line, const VECTOR2I& p )
|
|
|
|
{
|
|
|
|
int min_dist = INT_MAX;
|
|
|
|
VECTOR2I closest;
|
|
|
|
|
|
|
|
for(int i = 0; i < line.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
const auto& s = line.CSegment(i);
|
|
|
|
auto a = s.NearestPoint( p );
|
|
|
|
auto d = (a - p).EuclideanNorm();
|
|
|
|
|
|
|
|
if( d < min_dist )
|
|
|
|
{
|
|
|
|
min_dist = d;
|
|
|
|
closest = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE initTrack( m_head );
|
2020-02-19 17:22:37 +00:00
|
|
|
LINE walkFull( m_head );
|
2014-05-14 13:53:54 +00:00
|
|
|
int effort = 0;
|
2015-07-02 14:09:24 +00:00
|
|
|
bool rv = true, viaOk;
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
viaOk = buildInitialLine( aP, initTrack );
|
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() );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
WALKAROUND::RESULT wr = walkaround.Route( initTrack );
|
|
|
|
//WALKAROUND::WALKAROUND_STATUS wf = walkaround.Route( initTrack, walkFull, false );
|
|
|
|
|
|
|
|
auto l_cw = wr.lineCw.CLine();
|
|
|
|
auto l_ccw = wr.lineCcw.CLine();
|
|
|
|
|
|
|
|
if( wr.statusCcw == WALKAROUND::ALMOST_DONE || wr.statusCw == WALKAROUND::ALMOST_DONE )
|
|
|
|
{
|
|
|
|
|
|
|
|
auto p_cw = closestProjectedPoint( l_cw, aP );
|
|
|
|
auto p_ccw = closestProjectedPoint( l_ccw, aP );
|
|
|
|
|
|
|
|
int idx_cw = l_cw.Split( p_cw );
|
|
|
|
int idx_ccw = l_ccw.Split( p_ccw );
|
|
|
|
|
|
|
|
l_cw = l_cw.Slice( 0, idx_cw );
|
|
|
|
l_ccw = l_ccw.Slice( 0, idx_ccw );
|
|
|
|
|
|
|
|
//Dbg()->AddLine( wr.lineCw.CLine(), 3, 40000 );
|
|
|
|
|
|
|
|
//Dbg()->AddPoint( p_cw, 4 );
|
|
|
|
//Dbg()->AddPoint( p_ccw, 5 );
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
Dbg()->AddLine( wr.lineCw.CLine(), 4, 1000 );
|
|
|
|
Dbg()->AddLine( wr.lineCcw.CLine(), 5, 1000 );
|
2020-02-19 17:22:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
walkFull.SetShape( l_ccw.Length() < l_cw.Length() ? l_ccw : l_cw );
|
|
|
|
|
|
|
|
Dbg()->AddLine( walkFull.CLine(), 2, 100000, "walk-full" );
|
2014-05-14 13:53:54 +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
|
|
|
|
|
|
|
if( Settings().SmartPads() )
|
2016-08-29 17:31:13 +00:00
|
|
|
effort |= OPTIMIZER::SMART_PADS;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2020-02-19 17:22:37 +00:00
|
|
|
if( wr.statusCw == WALKAROUND::STUCK || wr.statusCcw == WALKAROUND::STUCK )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
walkFull = walkFull.ClipToNearestObstacle( m_currentNode );
|
|
|
|
rv = true;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else if( m_placingVia && viaOk )
|
|
|
|
{
|
2015-07-07 16:36:38 +00:00
|
|
|
walkFull.AppendVia( makeVia( walkFull.CPoint( -1 ) ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OPTIMIZER::Optimize( &walkFull, effort, m_currentNode );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( m_currentNode->CheckColliding( &walkFull ) )
|
2015-07-10 21:42:13 +00:00
|
|
|
{
|
|
|
|
aNewHead = m_head;
|
2015-07-02 14:11:15 +00:00
|
|
|
return false;
|
2015-07-10 21:42:13 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_head = walkFull;
|
|
|
|
aNewHead = walkFull;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return rv;
|
|
|
|
}
|
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::rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2018-12-25 01:29:23 +00:00
|
|
|
LINE newHead( m_head ), bestHead( m_head );
|
|
|
|
bool hasBest = false;
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2018-12-25 01:29:23 +00:00
|
|
|
buildInitialLine( aP, newHead );
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2018-12-25 01:29:23 +00:00
|
|
|
NODE::OBSTACLES obstacles;
|
|
|
|
|
|
|
|
m_currentNode->QueryColliding( &newHead, obstacles );
|
|
|
|
|
2019-06-09 19:59:37 +00:00
|
|
|
// If we are allowing DRC violations, we don't push back to the hull
|
|
|
|
if( !Settings().CanViolateDRC() )
|
2017-01-19 12:55:22 +00:00
|
|
|
{
|
2019-06-09 19:59:37 +00:00
|
|
|
for( auto& obs : obstacles )
|
|
|
|
{
|
|
|
|
int cl = m_currentNode->GetClearance( obs.m_item, &newHead );
|
2020-08-25 16:39:56 +00:00
|
|
|
auto hull = obs.m_item->Hull( cl, newHead.Width(), newHead.Layer() );
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2019-06-09 19:59:37 +00:00
|
|
|
auto nearest = hull.NearestPoint( aP );
|
|
|
|
Dbg()->AddLine( hull, 2, 10000 );
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2019-06-09 19:59:37 +00:00
|
|
|
if( ( nearest - aP ).EuclideanNorm() < newHead.Width() + cl )
|
2018-12-25 01:29:23 +00:00
|
|
|
{
|
2019-06-09 19:59:37 +00:00
|
|
|
buildInitialLine( nearest, newHead );
|
2020-01-17 03:54:51 +00:00
|
|
|
|
|
|
|
// We want the shortest line here to ensure we don't break a clearance
|
|
|
|
// rule on larger, overlapping items (e.g. vias)
|
|
|
|
if( newHead.CLine().Length() < bestHead.CLine().Length() )
|
2019-06-09 19:59:37 +00:00
|
|
|
{
|
|
|
|
bestHead = newHead;
|
|
|
|
hasBest = true;
|
|
|
|
}
|
2018-12-25 01:29:23 +00:00
|
|
|
}
|
2017-01-19 12:55:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 01:29:23 +00:00
|
|
|
if( hasBest )
|
|
|
|
m_head = bestHead;
|
|
|
|
else
|
|
|
|
m_head = newHead;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
aNewHead = m_head;
|
2017-01-19 12:55:22 +00:00
|
|
|
|
2015-07-22 08:46:45 +00:00
|
|
|
return static_cast<bool>( m_currentNode->CheckColliding( &m_head ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2017-01-19 12:55:22 +00:00
|
|
|
const LINE LINE_PLACER::reduceToNearestObstacle( const LINE& aOriginalLine )
|
|
|
|
{
|
2017-09-22 17:11:11 +00:00
|
|
|
const auto& l0 = aOriginalLine.CLine();
|
2017-01-19 12:55:22 +00:00
|
|
|
|
|
|
|
if ( !l0.PointCount() )
|
|
|
|
return aOriginalLine;
|
|
|
|
|
|
|
|
int l = l0.Length();
|
|
|
|
int step = l / 2;
|
|
|
|
VECTOR2I target;
|
|
|
|
|
|
|
|
LINE l_test( aOriginalLine );
|
|
|
|
|
|
|
|
while( step > 0 )
|
|
|
|
{
|
|
|
|
target = l0.PointAlong( l );
|
|
|
|
SHAPE_LINE_CHAIN l_cur( l0 );
|
|
|
|
|
|
|
|
int index = l_cur.Split( target );
|
|
|
|
|
|
|
|
l_test.SetShape( l_cur.Slice( 0, index ) );
|
|
|
|
|
|
|
|
if ( m_currentNode->CheckColliding( &l_test ) )
|
|
|
|
l -= step;
|
|
|
|
else
|
|
|
|
l += step;
|
|
|
|
|
|
|
|
step /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = l_test.CLine().Length();
|
|
|
|
|
|
|
|
while( m_currentNode->CheckColliding( &l_test ) && l > 0 )
|
|
|
|
{
|
|
|
|
l--;
|
|
|
|
target = l0.PointAlong( l );
|
|
|
|
SHAPE_LINE_CHAIN l_cur( l0 );
|
|
|
|
|
|
|
|
int index = l_cur.Split( target );
|
|
|
|
|
|
|
|
l_test.SetShape( l_cur.Slice( 0, index ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_test;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LINE_PLACER::rhStopAtNearestObstacle( const VECTOR2I& aP, LINE& aNewHead )
|
|
|
|
{
|
|
|
|
LINE l0;
|
|
|
|
l0 = m_head;
|
|
|
|
|
|
|
|
buildInitialLine( aP, l0 );
|
|
|
|
|
|
|
|
LINE l_cur = reduceToNearestObstacle( l0 );
|
|
|
|
|
|
|
|
const auto l_shape = l_cur.CLine();
|
|
|
|
|
|
|
|
if( l_shape.SegmentCount() == 0 )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( l_shape.SegmentCount() == 1 )
|
|
|
|
{
|
|
|
|
auto s = l_shape.CSegment( 0 );
|
|
|
|
|
|
|
|
VECTOR2I dL( DIRECTION_45( s ).Left().ToVector() );
|
|
|
|
VECTOR2I dR( DIRECTION_45( s ).Right().ToVector() );
|
|
|
|
|
|
|
|
SEG leadL( s.B, s.B + dL );
|
|
|
|
SEG leadR( s.B, s.B + dR );
|
|
|
|
|
|
|
|
SEG segL( s.B, leadL.LineProject( aP ) );
|
|
|
|
SEG segR( s.B, leadR.LineProject( aP ) );
|
|
|
|
|
2019-03-24 13:54:56 +00:00
|
|
|
LINE finishL( l0, SHAPE_LINE_CHAIN( { segL.A, segL.B } ) );
|
|
|
|
LINE finishR( l0, SHAPE_LINE_CHAIN( { segR.A, segR.B } ) );
|
2017-01-19 12:55:22 +00:00
|
|
|
|
|
|
|
LINE reducedL = reduceToNearestObstacle( finishL );
|
|
|
|
LINE reducedR = reduceToNearestObstacle( finishR );
|
|
|
|
|
|
|
|
int lL = reducedL.CLine().Length();
|
|
|
|
int lR = reducedR.CLine().Length();
|
|
|
|
|
|
|
|
if( lL > lR )
|
|
|
|
l_cur.Line().Append( reducedL.CLine() );
|
|
|
|
else
|
|
|
|
l_cur.Line().Append( reducedR.CLine() );
|
|
|
|
|
|
|
|
l_cur.Line().Simplify();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_head = l_cur;
|
|
|
|
aNewHead = m_head;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE initTrack( m_head );
|
|
|
|
LINE walkSolids, l2;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-02 14:09:24 +00:00
|
|
|
bool viaOk = buildInitialLine( aP, initTrack );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = m_shove->CurrentNode();
|
2020-02-19 17:22:37 +00:00
|
|
|
|
|
|
|
m_shove->SetLogger( Logger() );
|
|
|
|
m_shove->SetDebugDecorator( Dbg() );
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OPTIMIZER optimizer( m_currentNode );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND walkaround( m_currentNode, Router() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
walkaround.SetSolidsOnly( true );
|
|
|
|
walkaround.SetIterationLimit( 10 );
|
2019-02-03 10:21:48 +00:00
|
|
|
walkaround.SetDebugDecorator( Dbg() );
|
2020-02-19 17:22:37 +00:00
|
|
|
walkaround.SetLogger( Logger() );
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND::WALKAROUND_STATUS stat_solids = walkaround.Route( initTrack, walkSolids );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
optimizer.SetEffortLevel( OPTIMIZER::MERGE_SEGMENTS );
|
|
|
|
optimizer.SetCollisionMask( ITEM::SOLID_T );
|
2013-09-26 21:53:54 +00:00
|
|
|
optimizer.Optimize( &walkSolids );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( stat_solids == WALKAROUND::DONE )
|
2014-05-16 11:37:31 +00:00
|
|
|
l2 = walkSolids;
|
|
|
|
else
|
|
|
|
l2 = initTrack.ClipToNearestObstacle( m_shove->CurrentNode() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE l( m_tail );
|
2014-05-14 13:53:54 +00:00
|
|
|
l.Line().Append( l2.CLine() );
|
|
|
|
l.Line().Simplify();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-10-12 08:02:03 +00:00
|
|
|
if( l.PointCount() == 0 || l2.PointCount() == 0 )
|
|
|
|
{
|
|
|
|
aNewHead = m_head;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:09:24 +00:00
|
|
|
if( m_placingVia && viaOk )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA v1( makeVia( l.CPoint( -1 ) ) );
|
|
|
|
VIA v2( makeVia( l2.CPoint( -1 ) ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
l.AppendVia( v1 );
|
|
|
|
l2.AppendVia( v2 );
|
|
|
|
}
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
l.Line().Simplify();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// in certain, uncommon cases there may be loops in the head+tail, In such case, we don't shove to avoid
|
|
|
|
// screwing up the database.
|
2014-05-16 11:37:31 +00:00
|
|
|
if( l.HasLoops() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
aNewHead = m_head;
|
2014-11-14 19:19:00 +00:00
|
|
|
return false;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS status = m_shove->ShoveLines( l );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
|
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 )
|
2015-08-19 16:07:16 +00:00
|
|
|
{
|
|
|
|
l2 = m_shove->NewHead();
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
optimizer.SetWorld( m_currentNode );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
int effortLevel = OPTIMIZER::MERGE_OBTUSE;
|
|
|
|
if( Settings().SmartPads() )
|
|
|
|
{
|
|
|
|
effortLevel = OPTIMIZER::SMART_PADS;
|
|
|
|
}
|
|
|
|
optimizer.SetEffortLevel( effortLevel );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
optimizer.SetCollisionMask( ITEM::ANY_T );
|
2014-05-16 11:37:31 +00:00
|
|
|
optimizer.Optimize( &l2 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
aNewHead = l2;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
walkaround.SetWorld( m_currentNode );
|
|
|
|
walkaround.SetSolidsOnly( false );
|
|
|
|
walkaround.SetIterationLimit( 10 );
|
|
|
|
walkaround.SetApproachCursor( true, aP );
|
|
|
|
walkaround.Route( initTrack, l2 );
|
|
|
|
aNewHead = l2.ClipToNearestObstacle( m_shove->CurrentNode() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool LINE_PLACER::routeHead( const VECTOR2I& aP, LINE& aNewHead )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
switch( m_currentMode )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_MarkObstacles:
|
|
|
|
return rhMarkObstacles( aP, aNewHead );
|
|
|
|
case RM_Walkaround:
|
|
|
|
return rhWalkOnly( aP, aNewHead );
|
|
|
|
case RM_Shove:
|
|
|
|
return rhShoveOnly( aP, aNewHead );
|
|
|
|
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
|
|
|
|
2016-11-25 14:07:23 +00:00
|
|
|
if( 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;
|
|
|
|
m_p_start = linetmp.CLine().CPoint( 0 );
|
|
|
|
m_direction = DIRECTION_45( linetmp.CSegment( 0 ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
m_tail.Line().Clear();
|
2014-05-16 11:37:31 +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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( tail.SegmentCount() < 3 )
|
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( OPTIMIZER::Optimize( &new_head, OPTIMIZER::MERGE_OBTUSE, 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
|
|
|
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "Placer: optimize tail-head [%d]", threshold );
|
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_p_start = new_head.CLine().CPoint( -1 );
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE new_head;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "INIT-DIR: %s head: %d, tail: %d segs",
|
2016-08-17 14:00:21 +00:00
|
|
|
m_initial_direction.Format().c_str(), m_head.SegmentCount(), m_tail.SegmentCount() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
for( i = 0; i < n_iter; i++ )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
if( !go_back && Settings().FollowMouse() )
|
2013-09-26 21:53:54 +00:00
|
|
|
reduceTail( aP );
|
|
|
|
|
|
|
|
go_back = false;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( !routeHead( aP, new_head ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
fail = true;
|
|
|
|
|
|
|
|
if( !new_head.Is45Degree() )
|
|
|
|
fail = true;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( !Settings().FollowMouse() )
|
2013-09-26 21:53:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_head = new_head;
|
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
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !go_back && handlePullback() )
|
|
|
|
{
|
|
|
|
n_iter++;
|
|
|
|
go_back = true;
|
|
|
|
}
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !fail )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
if( optimizeTailHeadTransition() )
|
|
|
|
return;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
mergeHead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (!m_head.PointCount() )
|
|
|
|
return false;
|
2019-03-04 17:33:01 +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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE tmp( m_head );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
tmp.SetShape( m_tail.CLine() );
|
|
|
|
tmp.Line().Append( m_head.CLine() );
|
|
|
|
tmp.Line().Simplify();
|
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
|
|
|
{
|
2020-04-16 21:54:09 +00:00
|
|
|
m_postureSolver.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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
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
|
|
|
|
2016-08-30 15:28:35 +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
|
|
|
|
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
|
|
|
}
|
2016-08-29 17:31:13 +00:00
|
|
|
else if( !m_startItem || ( m_startItem->OfKind( ITEM::VIA_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;
|
2020-02-07 19:57:24 +00:00
|
|
|
m_head.Line().Clear();
|
|
|
|
m_tail.Line().Clear();
|
|
|
|
m_head.SetLayer( m_currentLayer );
|
|
|
|
m_tail.SetLayer( m_currentLayer );
|
2016-08-15 15:16:53 +00:00
|
|
|
Move( m_currentEnd, NULL );
|
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 );
|
|
|
|
m_currentEnd = VECTOR2I( aP );
|
|
|
|
m_currentNet = std::max( 0, aStartItem ? aStartItem->Net() : 0 );
|
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();
|
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-04-16 21:54:09 +00:00
|
|
|
m_postureSolver.Clear();
|
|
|
|
m_postureSolver.AddTrailPoint( aP );
|
2020-08-30 23:53:56 +00:00
|
|
|
m_postureSolver.SetTolerance( m_head.Width() );
|
2020-04-16 21:54:09 +00:00
|
|
|
m_postureSolver.SetDefaultDirections( m_initial_direction, DIRECTION_45::UNDEFINED );
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
NODE *n;
|
|
|
|
|
|
|
|
if ( m_shove )
|
|
|
|
n = m_shove->CurrentNode();
|
|
|
|
else
|
|
|
|
n = m_currentNode;
|
|
|
|
|
|
|
|
m_fixedTail.AddStage( m_currentStart, m_currentLayer, m_placingVia, m_direction, n );
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "world %p, intitial-direction %s layer %d",
|
2016-08-17 14:00:21 +00:00
|
|
|
m_world, m_direction.Format().c_str(), m_currentLayer );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
|
|
|
m_lastNode = NULL;
|
2014-11-14 18:15:58 +00:00
|
|
|
m_currentNode = m_world;
|
|
|
|
m_currentMode = Settings().Mode();
|
|
|
|
|
2016-08-29 18:42:56 +00:00
|
|
|
m_shove.reset();
|
2014-11-14 18:15:58 +00:00
|
|
|
|
|
|
|
if( m_currentMode == RM_Shove || m_currentMode == RM_Smart )
|
|
|
|
{
|
2019-12-05 13:43:55 +00:00
|
|
|
m_shove = std::make_unique<SHOVE>( m_world->Branch(), Router() );
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
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;
|
2014-05-14 13:53:54 +00:00
|
|
|
VECTOR2I p = aP;
|
|
|
|
int eiDepth = -1;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aEndItem && aEndItem->Owner() )
|
2016-08-29 17:31:13 +00:00
|
|
|
eiDepth = static_cast<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;
|
|
|
|
m_lastNode = NULL;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2019-02-03 11:37:17 +00:00
|
|
|
bool reachesEnd = route( p );
|
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
|
|
|
|
2019-02-03 11:37:17 +00:00
|
|
|
if( reachesEnd && eiDepth >= 0 && aEndItem && latestNode->Depth() > eiDepth && current.SegmentCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
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-04-16 21:54:09 +00:00
|
|
|
m_postureSolver.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
|
|
|
{
|
|
|
|
bool realEnd = false;
|
|
|
|
int lastV;
|
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
|
|
|
|
2018-04-08 20:20:51 +00:00
|
|
|
if( m_currentMode == RM_MarkObstacles )
|
|
|
|
{
|
|
|
|
// Mark Obstacles is sort of a half-manual, half-automated mode in which the
|
|
|
|
// user has more responsibility and authority.
|
|
|
|
|
|
|
|
if( aEndItem )
|
|
|
|
{
|
|
|
|
// The user has indicated a connection should be made. If either the
|
|
|
|
// trace or endItem is netless, then allow the connection by adopting the net of the other.
|
|
|
|
if( m_currentNet <= 0 )
|
|
|
|
{
|
|
|
|
m_currentNet = aEndItem->Net();
|
|
|
|
pl.SetNet( m_currentNet );
|
|
|
|
}
|
|
|
|
else if (aEndItem->Net() <= 0 )
|
|
|
|
aEndItem->SetNet( m_currentNet );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collisions still prevent fixing unless "Allow DRC violations" is checked
|
|
|
|
if( !Settings().CanViolateDRC() && m_world->CheckColliding( &pl ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return false;
|
2018-04-08 20:20:51 +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-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
|
|
|
|
2020-03-02 15:09:42 +00:00
|
|
|
m_lastNode->Add( Clone( pl.Via() ) );
|
|
|
|
m_currentNode = NULL;
|
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 );
|
|
|
|
DIRECTION_45 d_last( l.CSegment( -1 ) );
|
|
|
|
|
|
|
|
if( l.PointCount() > 2 )
|
|
|
|
p_pre_last = l.CPoint( -2 );
|
|
|
|
|
|
|
|
if( aEndItem && m_currentNet >= 0 && m_currentNet == aEndItem->Net() )
|
|
|
|
realEnd = true;
|
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
if( aForceFinish )
|
|
|
|
realEnd = true;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( realEnd || m_placingVia )
|
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 );
|
|
|
|
|
2018-02-08 10:32:13 +00:00
|
|
|
SEGMENT* lastSeg = nullptr;
|
2019-05-17 00:13:21 +00:00
|
|
|
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 );
|
|
|
|
|
|
|
|
if( arcIndex < 0 )
|
2018-02-08 10:32:13 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
const SEG& s = pl.CSegment( i );
|
|
|
|
auto seg = std::make_unique<SEGMENT>( s, m_currentNet );
|
|
|
|
seg->SetWidth( pl.Width() );
|
|
|
|
seg->SetLayer( m_currentLayer );
|
|
|
|
if( !m_lastNode->Add( std::move( seg ) ) )
|
|
|
|
lastSeg = nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( arcIndex == lastArc )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
auto arc = std::make_unique<ARC>( l.Arc( arcIndex ), m_currentNet );
|
|
|
|
arc->SetWidth( pl.Width() );
|
|
|
|
arc->SetLayer( m_currentLayer );
|
|
|
|
m_lastNode->Add( std::move( arc ) );
|
2018-02-08 10:32:13 +00:00
|
|
|
lastSeg = nullptr;
|
2019-05-17 00:13:21 +00:00
|
|
|
lastArc = arcIndex;
|
2018-02-08 10:32:13 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( pl.EndsWithVia() )
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
2016-08-30 15:28:35 +00:00
|
|
|
m_lastNode->Add( Clone( pl.Via() ) );
|
2020-02-07 19:57:24 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2018-02-08 10:32:13 +00:00
|
|
|
if( realEnd && lastSeg )
|
2014-07-09 14:25:50 +00:00
|
|
|
simplifyNewLine( m_lastNode, lastSeg );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !realEnd )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
setInitialDirection( d_last );
|
2014-11-14 18:15:58 +00:00
|
|
|
m_currentStart = m_placingVia ? p_last : p_pre_last;
|
2020-02-07 19:57:24 +00:00
|
|
|
|
|
|
|
m_fixedTail.AddStage( m_p_start, m_currentLayer, m_placingVia, m_direction, m_currentNode );
|
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
m_startItem = NULL;
|
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();
|
|
|
|
|
|
|
|
if ( m_shove )
|
|
|
|
{
|
|
|
|
m_shove->AddLockedSpringbackNode( m_currentNode );
|
|
|
|
}
|
2020-07-29 07:21:31 +00:00
|
|
|
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
m_postureSolver.Clear();
|
2020-08-30 23:53:56 +00:00
|
|
|
m_postureSolver.SetTolerance( m_head.Width() );
|
2020-04-16 21:54:09 +00:00
|
|
|
m_postureSolver.AddTrailPoint( m_currentStart );
|
|
|
|
m_postureSolver.SetDefaultDirections( m_initial_direction, d_last );
|
|
|
|
|
2020-02-29 19:40:19 +00:00
|
|
|
m_placementCorrect = true;
|
2015-03-10 14:38:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
bool LINE_PLACER::UnfixRoute()
|
|
|
|
{
|
|
|
|
FIXED_TAIL::STAGE st;
|
|
|
|
|
|
|
|
if ( !m_fixedTail.PopStage( st ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_head.Line().Clear();
|
|
|
|
m_tail.Line().Clear();
|
|
|
|
m_startItem = NULL;
|
|
|
|
m_p_start = st.pts[0].p;
|
|
|
|
m_direction = st.pts[0].direction;
|
|
|
|
m_placingVia = st.pts[0].placingVias;
|
|
|
|
m_currentNode = st.commit;
|
|
|
|
m_currentLayer = st.pts[0].layer;
|
|
|
|
m_head.SetLayer( m_currentLayer );
|
|
|
|
m_tail.SetLayer( m_currentLayer );
|
|
|
|
m_head.RemoveVia( );
|
|
|
|
m_tail.RemoveVia( );
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
if (m_shove)
|
|
|
|
{
|
|
|
|
m_shove->RewindSpringbackTo( m_currentNode );
|
|
|
|
m_shove->UnlockSpringbackNode( m_currentNode );
|
|
|
|
m_currentNode = m_shove->CurrentNode();
|
|
|
|
m_currentNode->KillChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastNode = m_currentNode->Branch();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2020-03-03 21:45:07 +00:00
|
|
|
if( m_lastNode )
|
|
|
|
Router()->CommitRouting( m_lastNode );
|
2020-02-07 19:57:24 +00:00
|
|
|
|
|
|
|
m_lastNode = NULL;
|
|
|
|
m_currentNode = NULL;
|
|
|
|
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
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
auto 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-05-14 13:53:54 +00:00
|
|
|
}
|
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-04-15 20:16:24 +00:00
|
|
|
for( auto 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "total segs removed: %d/%d", removedCount, total );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
for( auto 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::simplifyNewLine( NODE* aNode, SEGMENT* aLatest )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE l = aNode->AssembleLine( aLatest );
|
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();
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( 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-02-06 17:03:34 +00:00
|
|
|
// initPlacement will kill the tail, don't do that unless the track size has changed
|
|
|
|
if( !m_idle && aSizes.TrackWidth() != m_sizes.TrackWidth() )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2020-02-07 19:57:24 +00:00
|
|
|
m_sizes = aSizes;
|
2016-08-15 15:16:53 +00:00
|
|
|
initPlacement();
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
2020-02-06 17:03:34 +00:00
|
|
|
|
|
|
|
m_sizes = aSizes;
|
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 ) )
|
|
|
|
Dbg()->AddLine( ratLine, 5, 10000 );
|
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
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
bool LINE_PLACER::buildInitialLine( const VECTOR2I& aP, LINE& aHead )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-02 14:09:24 +00:00
|
|
|
SHAPE_LINE_CHAIN l;
|
2019-05-17 00:13:21 +00:00
|
|
|
int initial_radius = 0;
|
2015-07-02 14:09:24 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
auto guessedDir = m_postureSolver.GetPosture( aP );
|
|
|
|
|
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
|
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
// Rounded corners don't make sense when routing orthogonally (single track at a time)
|
|
|
|
if( Settings().GetRounded() && !m_orthoMode )
|
|
|
|
initial_radius = Settings().GetMaxRadius();
|
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
if( !m_tail.PointCount() )
|
|
|
|
l = guessedDir.BuildInitialTrace( m_p_start, aP, false, initial_radius );
|
2017-01-19 12:55:22 +00:00
|
|
|
else
|
2019-05-17 00:13:21 +00:00
|
|
|
l = m_direction.BuildInitialTrace( m_p_start, aP, false, initial_radius );
|
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 );
|
|
|
|
|
|
|
|
if( !m_placingVia )
|
|
|
|
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
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( m_currentMode == 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I force;
|
|
|
|
VECTOR2I lead = aP - m_p_start;
|
|
|
|
|
|
|
|
bool solidsOnly = ( m_currentMode != RM_Walkaround );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-07-02 14:09:24 +00:00
|
|
|
if( v.PushoutForce( m_currentNode, lead, force, solidsOnly, 40 ) )
|
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
SHAPE_LINE_CHAIN line = m_direction.BuildInitialTrace( m_p_start, aP + force, initial_radius );
|
2016-08-29 17:31:13 +00:00
|
|
|
aHead = LINE( aHead, line );
|
2015-07-02 14:09:24 +00:00
|
|
|
|
|
|
|
v.SetPos( v.Pos() + force );
|
|
|
|
return true;
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void LINE_PLACER::GetModifiedNets( std::vector<int>& 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXED_TAIL::FIXED_TAIL ( int aLineCount )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-29 07:21:31 +00:00
|
|
|
FIXED_TAIL::~FIXED_TAIL()
|
2020-02-07 19:57:24 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void FIXED_TAIL::Clear()
|
|
|
|
{
|
|
|
|
m_stages.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FIXED_TAIL::AddStage( VECTOR2I aStart, int aLayer, bool placingVias, DIRECTION_45 direction, NODE *aNode )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FIXED_TAIL::PopStage( FIXED_TAIL::STAGE& aStage )
|
|
|
|
{
|
|
|
|
if( !m_stages.size() )
|
|
|
|
return false;
|
|
|
|
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
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-08-30 23:53:56 +00:00
|
|
|
|
2020-07-29 07:21:31 +00:00
|
|
|
POSTURE_SOLVER::POSTURE_SOLVER()
|
2020-04-16 21:54:09 +00:00
|
|
|
{
|
|
|
|
m_forced = false;
|
2020-08-30 23:53:56 +00:00
|
|
|
m_tolerance = 0;
|
2020-04-16 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
POSTURE_SOLVER::~POSTURE_SOLVER() {}
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
void POSTURE_SOLVER::Clear()
|
|
|
|
{
|
|
|
|
m_forced = false;
|
|
|
|
m_trail.Clear();
|
|
|
|
}
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
void POSTURE_SOLVER::AddTrailPoint( const VECTOR2I& aP )
|
|
|
|
{
|
|
|
|
if( m_trail.SegmentCount() == 0 )
|
|
|
|
{
|
2020-08-30 23:53:56 +00:00
|
|
|
m_trail.Append( aP );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SEG s_new( m_trail.CPoint( -1 ), aP );
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
for( int i = 0; i < m_trail.SegmentCount() - 1; i++ )
|
|
|
|
{
|
2020-08-30 23:53:56 +00:00
|
|
|
const auto& s_trail = m_trail.CSegment( i );
|
|
|
|
|
|
|
|
if( s_trail.Distance( s_new ) <= m_tolerance )
|
2020-04-16 21:54:09 +00:00
|
|
|
{
|
|
|
|
m_trail = m_trail.Slice( 0, i );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
m_trail.Append( aP );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_trail.Simplify();
|
|
|
|
|
|
|
|
auto dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
dbg->AddLine( m_trail, 5, 100000 );
|
2020-04-16 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
|
2020-04-16 21:54:09 +00:00
|
|
|
DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP )
|
|
|
|
{
|
2020-08-30 23:53:56 +00:00
|
|
|
// Adjusts how far away from p0 we get before whatever posture we solved is locked in
|
|
|
|
const int lockDistanceFactor = 40;
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
// Adjusts how close to p0 we unlock the posture again if one was locked already
|
|
|
|
const int unlockDistanceFactor = 4;
|
|
|
|
|
|
|
|
if( m_trail.PointCount() < 2 )
|
|
|
|
return m_direction;
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
auto dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
auto p0 = m_trail.CPoint( 0 );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
double refLength = SEG( p0, aP ).Length();
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN straight( DIRECTION_45().BuildInitialTrace( p0, aP, false ) );
|
2020-08-30 23:53:56 +00:00
|
|
|
straight.SetClosed( true );
|
|
|
|
straight.Append( m_trail.Reverse() );
|
|
|
|
dbg->AddLine( straight, m_forced ? 3 : 2, 100000 );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
double areaS = straight.Area();
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
SHAPE_LINE_CHAIN diag( DIRECTION_45().BuildInitialTrace( p0, aP, true ) );
|
|
|
|
diag.Append( m_trail.Reverse() );
|
|
|
|
diag.SetClosed( true );
|
|
|
|
dbg->AddLine( diag, 1, 100000 );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
double areaDiag = diag.Area();
|
2020-08-30 23:53:56 +00:00
|
|
|
double ratio = abs( areaS ) / ( fabs( areaDiag ) + 1.0 );
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
// heuristic to detect that the user dragged back the cursor to the beginning of the trace
|
2020-08-30 23:53:56 +00:00
|
|
|
// in this case, we cancel any forced posture and restart the trail
|
|
|
|
if( m_forced && refLength < unlockDistanceFactor * m_tolerance )
|
2020-04-16 21:54:09 +00:00
|
|
|
{
|
|
|
|
m_forced = false;
|
2020-08-30 23:53:56 +00:00
|
|
|
VECTOR2I start = p0;
|
|
|
|
m_trail.Clear();
|
|
|
|
m_trail.Append( start );
|
2020-04-16 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
// If we get far away from the initial point, lock in the current solution to prevent flutter
|
|
|
|
if( !m_forced && refLength > lockDistanceFactor * m_tolerance )
|
|
|
|
m_forced = true;
|
2020-07-29 07:21:31 +00:00
|
|
|
|
2020-08-30 23:53:56 +00:00
|
|
|
if( m_forced )
|
|
|
|
return m_direction;
|
|
|
|
else if( ratio > areaRatioThreshold + areaRatioEpsilon )
|
|
|
|
m_direction = DIRECTION_45::NE;
|
|
|
|
else if( ratio < ( 1.0 / areaRatioThreshold ) - areaRatioEpsilon )
|
|
|
|
m_direction = DIRECTION_45::N;
|
|
|
|
else if( m_lastSegDirection != DIRECTION_45::UNDEFINED )
|
|
|
|
m_direction = m_lastSegDirection;
|
|
|
|
|
|
|
|
return m_direction;
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
2020-04-16 21:54:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
void POSTURE_SOLVER::FlipPosture()
|
2020-07-29 07:21:31 +00:00
|
|
|
{
|
2020-08-30 23:53:56 +00:00
|
|
|
m_direction = m_direction.Right();
|
2020-04-16 21:54:09 +00:00
|
|
|
m_forced = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|