2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2013-09-18 17:55:16 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
2015-02-26 15:34:10 +00:00
|
|
|
#define PNS_DEBUG
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <deque>
|
|
|
|
#include <cassert>
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "range.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_walkaround.h"
|
|
|
|
#include "pns_shove.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_solid.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_optimizer.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_utils.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_router.h"
|
|
|
|
#include "pns_shove.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_utils.h"
|
2015-08-19 16:07:16 +00:00
|
|
|
#include "pns_topology.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
#include "time_limit.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <profile.h>
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
void PNS_SHOVE::replaceItems( PNS_ITEM* aOld, PNS_ITEM* aNew )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
OPT_BOX2I changed_area = ChangedArea( aOld, aNew );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( changed_area )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
m_affectedAreaSum = m_affectedAreaSum ? m_affectedAreaSum->Merge( *changed_area ) : *changed_area;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_currentNode->Replace( aOld, aNew );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int PNS_SHOVE::getClearance( const PNS_ITEM* aA, const PNS_ITEM* aB ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_forceClearance >= 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return m_forceClearance;
|
|
|
|
|
|
|
|
return m_currentNode->GetClearance( aA, aB );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
void PNS_SHOVE::sanityCheck( PNS_LINE* aOld, PNS_LINE* aNew )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
assert( aOld->CPoint( 0 ) == aNew->CPoint( 0 ) );
|
|
|
|
assert( aOld->CPoint( -1 ) == aNew->CPoint( -1 ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
PNS_SHOVE::PNS_SHOVE( PNS_NODE* aWorld, PNS_ROUTER* aRouter ) :
|
2016-08-15 15:16:53 +00:00
|
|
|
PNS_ALGO_BASE( aRouter )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_forceClearance = -1;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_root = aWorld;
|
2015-08-03 19:11:51 +00:00
|
|
|
m_currentNode = aWorld;
|
2015-04-20 14:59:25 +00:00
|
|
|
|
|
|
|
// Initialize other temporary variables:
|
|
|
|
m_draggedVia = NULL;
|
|
|
|
m_iter = 0;
|
|
|
|
m_multiLineMode = false;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
PNS_SHOVE::~PNS_SHOVE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE PNS_SHOVE::assembleLine( const PNS_SEGMENT* aSeg, int* aIndex )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-10-09 12:31:06 +00:00
|
|
|
return m_currentNode->AssembleLine( const_cast<PNS_SEGMENT*>( aSeg ), aIndex, true );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// A dumb function that checks if the shoved line is shoved the right way, e.g.
|
|
|
|
// visually "outwards" of the line/via applying pressure on it. Unfortunately there's no
|
|
|
|
// mathematical concept of orientation of an open curve, so we use some primitive heuristics:
|
|
|
|
// if the shoved line wraps around the start of the "pusher", it's likely shoved in wrong direction.
|
2015-08-03 19:11:51 +00:00
|
|
|
bool PNS_SHOVE::checkBumpDirection( const PNS_LINE& aCurrent, const PNS_LINE& aShoved ) const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
const SEG& ss = aCurrent.CSegment( 0 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int dist = getClearance( &aCurrent, &aShoved ) + PNS_HULL_MARGIN;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
dist += aCurrent.Width() / 2;
|
|
|
|
dist += aShoved.Width() / 2;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const VECTOR2I ps = ss.A - ( ss.B - ss.A ).Resize( dist );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
return !aShoved.CLine().PointOnEdge( ps );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::walkaroundLoneVia( PNS_LINE& aCurrent, PNS_LINE& aObstacle,
|
|
|
|
PNS_LINE& aShoved )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
int clearance = getClearance( &aCurrent, &aObstacle );
|
|
|
|
const SHAPE_LINE_CHAIN hull = aCurrent.Via().Hull( clearance, aObstacle.Width() );
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN path_cw, path_ccw;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
aObstacle.Walkaround( hull, path_cw, true );
|
|
|
|
aObstacle.Walkaround( hull, path_ccw, false );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
const SHAPE_LINE_CHAIN& shortest = path_ccw.Length() < path_cw.Length() ? path_ccw : path_cw;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( shortest.PointCount() < 2 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aObstacle.CPoint( -1 ) != shortest.CPoint( -1 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aObstacle.CPoint( 0 ) != shortest.CPoint( 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
aShoved.SetShape( shortest );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( m_currentNode->CheckColliding( &aShoved, &aCurrent ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::processHullSet( PNS_LINE& aCurrent, PNS_LINE& aObstacle,
|
|
|
|
PNS_LINE& aShoved, const HULL_SET& aHulls )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
const SHAPE_LINE_CHAIN& obs = aObstacle.CLine();
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int attempt;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( attempt = 0; attempt < 4; attempt++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
bool invertTraversal = ( attempt >= 2 );
|
2014-05-14 13:53:54 +00:00
|
|
|
bool clockwise = attempt % 2;
|
|
|
|
int vFirst = -1, vLast = -1;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN path;
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE l( aObstacle );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = 0; i < (int) aHulls.size(); i++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
const SHAPE_LINE_CHAIN& hull = aHulls[invertTraversal ? aHulls.size() - 1 - i : i];
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
l.Walkaround( hull, path, clockwise );
|
|
|
|
path.Simplify();
|
|
|
|
l.SetShape( path );
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
for( int i = 0; i < std::min( path.PointCount(), obs.PointCount() ); i++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( path.CPoint( i ) != obs.CPoint( i ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
vFirst = i;
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int k = obs.PointCount() - 1;
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = path.PointCount() - 1; i >= 0 && k >= 0; i--, k-- )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( path.CPoint( i ) != obs.CPoint( k ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
vLast = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( ( vFirst < 0 || vLast < 0 ) && !path.CompareGeometry( aObstacle.CLine() ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "attempt %d fail vfirst-last", attempt );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( path.CPoint( -1 ) != obs.CPoint( -1 ) || path.CPoint( 0 ) != obs.CPoint( 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "attempt %d fail vend-start\n", attempt );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !checkBumpDirection( aCurrent, l ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "attempt %d fail direction-check", attempt );
|
2015-08-03 19:11:51 +00:00
|
|
|
aShoved.SetShape( l.CLine() );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( path.SelfIntersecting() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "attempt %d fail self-intersect", attempt );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
bool colliding = m_currentNode->CheckColliding( &l, &aCurrent, PNS_ITEM::ANY, m_forceClearance );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( ( aCurrent.Marker() & MK_HEAD ) && !colliding )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_JOINT* jtStart = m_currentNode->FindJoint( aCurrent.CPoint( 0 ), &aCurrent );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : jtStart->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_currentNode->CheckColliding( item, &l ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
colliding = true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( colliding )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "attempt %d fail coll-check", attempt );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
aShoved.SetShape( l.CLine() );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_OK;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::ProcessSingleLine( PNS_LINE& aCurrent, PNS_LINE& aObstacle,
|
|
|
|
PNS_LINE& aShoved )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
aShoved.ClearSegmentLinks();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool obstacleIsHead = false;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aObstacle.LinkedSegments() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_SEGMENT* s : *aObstacle.LinkedSegments() )
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( s->Marker() & MK_HEAD )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
obstacleIsHead = true;
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS rv;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
bool viaOnEnd = aCurrent.EndsWithVia();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( viaOnEnd && ( !aCurrent.LayersOverlap( &aObstacle ) || aCurrent.SegmentCount() == 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
rv = walkaroundLoneVia( aCurrent, aObstacle, aShoved );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
int w = aObstacle.Width();
|
|
|
|
int n_segs = aCurrent.SegmentCount();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
int clearance = getClearance( &aCurrent, &aObstacle ) + 1;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
HULL_SET hulls;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
hulls.reserve( n_segs + 1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
for( int i = 0; i < n_segs; i++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SEGMENT seg( aCurrent, aCurrent.CSegment( i ) );
|
|
|
|
SHAPE_LINE_CHAIN hull = seg.Hull( clearance, w );
|
|
|
|
|
|
|
|
hulls.push_back( hull );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( viaOnEnd )
|
2016-08-15 15:16:53 +00:00
|
|
|
hulls.push_back( aCurrent.Via().Hull( clearance, w ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
rv = processHullSet( aCurrent, aObstacle, aShoved, hulls );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( obstacleIsHead )
|
2015-08-03 19:11:51 +00:00
|
|
|
aShoved.Mark( aShoved.Marker() | MK_HEAD );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::onCollidingSegment( PNS_LINE& aCurrent, PNS_SEGMENT* aObstacleSeg )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
int segIndex;
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE obstacleLine = assembleLine( aObstacleSeg, &segIndex );
|
|
|
|
PNS_LINE shovedLine( obstacleLine );
|
|
|
|
PNS_SEGMENT tmp( *aObstacleSeg );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
if( obstacleLine.HasLockedSegments() )
|
|
|
|
return SH_TRY_WALK;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
SHOVE_STATUS rv = ProcessSingleLine( aCurrent, obstacleLine, shovedLine );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
const double extensionWalkThreshold = 1.0;
|
|
|
|
|
|
|
|
double obsLen = obstacleLine.CLine().Length();
|
|
|
|
double shovedLen = shovedLine.CLine().Length();
|
|
|
|
double extensionFactor = 0.0;
|
|
|
|
|
|
|
|
if( obsLen != 0.0f )
|
|
|
|
extensionFactor = shovedLen / obsLen - 1.0;
|
|
|
|
|
|
|
|
if( extensionFactor > extensionWalkThreshold )
|
|
|
|
return SH_TRY_WALK;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
assert( obstacleLine.LayersOverlap( &shovedLine ) );
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
m_logger.NewGroup( "on-colliding-segment", m_iter );
|
|
|
|
m_logger.Log( &tmp, 0, "obstacle-segment" );
|
|
|
|
m_logger.Log( &aCurrent, 1, "current-line" );
|
|
|
|
m_logger.Log( &obstacleLine, 2, "obstacle-line" );
|
|
|
|
m_logger.Log( &shovedLine, 3, "shoved-line" );
|
|
|
|
#endif
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( rv == SH_OK )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( shovedLine.Marker() & MK_HEAD )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m_multiLineMode )
|
|
|
|
return SH_INCOMPLETE;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_newHead = shovedLine;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int rank = aCurrent.Rank();
|
|
|
|
shovedLine.SetRank( rank - 1 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
sanityCheck( &obstacleLine, &shovedLine );
|
|
|
|
replaceItems( &obstacleLine, &shovedLine );
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( !pushLine( shovedLine ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
rv = SH_INCOMPLETE;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return rv;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::onCollidingLine( PNS_LINE& aCurrent, PNS_LINE& aObstacle )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE shovedLine( aObstacle );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
SHOVE_STATUS rv = ProcessSingleLine( aCurrent, aObstacle, shovedLine );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
m_logger.NewGroup( "on-colliding-line", m_iter );
|
|
|
|
m_logger.Log( &aObstacle, 0, "obstacle-line" );
|
|
|
|
m_logger.Log( &aCurrent, 1, "current-line" );
|
|
|
|
m_logger.Log( &shovedLine, 3, "shoved-line" );
|
|
|
|
#endif
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( rv == SH_OK )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( shovedLine.Marker() & MK_HEAD )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_multiLineMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_newHead = shovedLine;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
sanityCheck( &aObstacle, &shovedLine );
|
|
|
|
replaceItems( &aObstacle, &shovedLine );
|
|
|
|
|
|
|
|
int rank = aObstacle.Rank();
|
|
|
|
shovedLine.SetRank( rank - 1 );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-07-02 14:09:32 +00:00
|
|
|
if( !pushLine( shovedLine ) )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
2015-07-02 14:09:32 +00:00
|
|
|
rv = SH_INCOMPLETE;
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::onCollidingSolid( PNS_LINE& aCurrent, PNS_ITEM* aObstacle )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
PNS_WALKAROUND walkaround( m_currentNode, Router() );
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE walkaroundLine( aCurrent );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aCurrent.EndsWithVia() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_VIA vh = aCurrent.Via();
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_VIA* via = NULL;
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_JOINT* jtStart = m_currentNode->FindJoint( vh.Pos(), &aCurrent );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !jtStart )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : jtStart->LinkList() )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
if( item->OfKind( PNS_ITEM::VIA ) )
|
|
|
|
{
|
|
|
|
via = (PNS_VIA*) item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( via && m_currentNode->CheckColliding( via, aObstacle ) )
|
|
|
|
return onCollidingVia( aObstacle, via );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
PNS_TOPOLOGY topo( m_currentNode );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
std::set<PNS_ITEM*> cluster = topo.AssembleCluster( aObstacle, aCurrent.Layers().Start() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
m_logger.NewGroup( "on-colliding-solid-cluster", m_iter );
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : cluster )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-19 16:07:16 +00:00
|
|
|
m_logger.Log( item, 0, "cluster-entry" );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2015-08-19 16:07:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
walkaround.SetSolidsOnly( false );
|
|
|
|
walkaround.RestrictToSet( true, cluster );
|
|
|
|
walkaround.SetIterationLimit( 16 ); // fixme: make configurable
|
|
|
|
|
|
|
|
int currentRank = aCurrent.Rank();
|
|
|
|
int nextRank;
|
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
bool success = false;
|
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
for( int attempt = 0; attempt < 2; attempt++ )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2015-08-19 16:07:16 +00:00
|
|
|
if( attempt == 1 || Settings().JumpOverObstacles() )
|
|
|
|
{
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
nextRank = currentRank - 1;
|
|
|
|
walkaround.SetSingleDirection( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nextRank = currentRank + 10000;
|
|
|
|
walkaround.SetSingleDirection( false );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
PNS_WALKAROUND::WALKAROUND_STATUS status = walkaround.Route( aCurrent, walkaroundLine, false );
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( status != PNS_WALKAROUND::DONE )
|
2016-08-15 15:16:48 +00:00
|
|
|
continue;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
walkaroundLine.ClearSegmentLinks();
|
|
|
|
walkaroundLine.Unmark();
|
|
|
|
walkaroundLine.Line().Simplify();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( walkaroundLine.HasLoops() )
|
2016-08-15 15:16:48 +00:00
|
|
|
continue;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( aCurrent.Marker() & MK_HEAD )
|
|
|
|
{
|
|
|
|
walkaroundLine.Mark( MK_HEAD );
|
|
|
|
|
|
|
|
if( m_multiLineMode )
|
2016-08-15 15:16:48 +00:00
|
|
|
continue;
|
2015-08-19 16:07:16 +00:00
|
|
|
|
|
|
|
m_newHead = walkaroundLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
sanityCheck( &aCurrent, &walkaroundLine );
|
|
|
|
|
|
|
|
if( !m_lineStack.empty() )
|
|
|
|
{
|
|
|
|
PNS_LINE lastLine = m_lineStack.front();
|
|
|
|
|
|
|
|
if( m_currentNode->CheckColliding( &lastLine, &walkaroundLine ) )
|
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
PNS_LINE dummy( lastLine );
|
2015-08-19 16:07:16 +00:00
|
|
|
|
|
|
|
if( ProcessSingleLine( walkaroundLine, lastLine, dummy ) == SH_OK )
|
2016-08-15 15:16:48 +00:00
|
|
|
{
|
|
|
|
success = true;
|
2015-08-19 16:07:16 +00:00
|
|
|
break;
|
2016-08-15 15:16:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
success = true;
|
2015-08-19 16:07:16 +00:00
|
|
|
break;
|
2016-08-15 15:16:48 +00:00
|
|
|
}
|
2015-08-19 16:07:16 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
if(!success)
|
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
replaceItems( &aCurrent, &walkaroundLine );
|
|
|
|
walkaroundLine.SetRank( nextRank );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-16 11:37:31 +00:00
|
|
|
m_logger.NewGroup( "on-colliding-solid", m_iter );
|
2015-08-19 16:07:16 +00:00
|
|
|
m_logger.Log( aObstacle, 0, "obstacle-solid" );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_logger.Log( &aCurrent, 1, "current-line" );
|
|
|
|
m_logger.Log( &walkaroundLine, 3, "walk-line" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
popLine();
|
2015-07-02 14:11:15 +00:00
|
|
|
|
|
|
|
if( !pushLine( walkaroundLine ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
return SH_OK;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
bool PNS_SHOVE::reduceSpringback( const PNS_ITEMSET& aHeadSet )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
bool rv = false;
|
|
|
|
|
|
|
|
while( !m_nodeStack.empty() )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SPRINGBACK_TAG spTag = m_nodeStack.back();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !spTag.m_node->CheckColliding( aHeadSet ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
rv = true;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
delete spTag.m_node;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_nodeStack.pop_back();
|
|
|
|
}
|
|
|
|
else
|
2014-05-14 13:53:54 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
bool PNS_SHOVE::pushSpringback( PNS_NODE* aNode, const PNS_ITEMSET& aHeadItems,
|
2015-02-18 00:29:54 +00:00
|
|
|
const PNS_COST_ESTIMATOR& aCost, const OPT_BOX2I& aAffectedArea )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SPRINGBACK_TAG st;
|
2015-02-18 00:29:54 +00:00
|
|
|
OPT_BOX2I prev_area;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_nodeStack.empty() )
|
2015-02-18 00:29:54 +00:00
|
|
|
prev_area = m_nodeStack.back().m_affectedArea;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
st.m_node = aNode;
|
|
|
|
st.m_cost = aCost;
|
|
|
|
st.m_headItems = aHeadItems;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( aAffectedArea )
|
|
|
|
{
|
|
|
|
if( prev_area )
|
2016-08-15 15:16:53 +00:00
|
|
|
st.m_affectedArea = prev_area->Merge( *aAffectedArea );
|
2015-02-18 00:29:54 +00:00
|
|
|
else
|
|
|
|
st.m_affectedArea = aAffectedArea;
|
|
|
|
} else
|
|
|
|
st.m_affectedArea = prev_area;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
m_nodeStack.push_back( st );
|
2014-05-16 11:37:31 +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
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::pushVia( PNS_VIA* aVia, const VECTOR2I& aForce, int aCurrentRank, bool aDryRun )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
LINE_PAIR_VEC draggedLines;
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I p0( aVia->Pos() );
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_JOINT* jt = m_currentNode->FindJoint( p0, aVia );
|
|
|
|
VECTOR2I p0_pushed( p0 + aForce );
|
|
|
|
|
2015-08-07 15:07:06 +00:00
|
|
|
if( !jt )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "weird, can't find the center-of-via joint\n" );
|
2015-08-07 15:07:06 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( aVia->IsLocked() )
|
2016-08-15 15:16:50 +00:00
|
|
|
return SH_TRY_WALK;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( jt->IsLocked() )
|
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
while( aForce.x != 0 || aForce.y != 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_JOINT* jt_next = m_currentNode->FindJoint( p0_pushed, aVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !jt_next )
|
2015-02-18 00:29:54 +00:00
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
p0_pushed += aForce.Resize( 2 ); // make sure pushed via does not overlap with any existing joint
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_VIA* pushedVia = aVia->Clone();
|
|
|
|
pushedVia->SetPos( p0_pushed );
|
2014-05-16 11:37:31 +00:00
|
|
|
pushedVia->Mark( aVia->Marker() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aVia->Marker() & MK_HEAD )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_draggedVia = pushedVia;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_draggedViaHeadSet.Clear();
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : jt->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( PNS_SEGMENT* seg = dyn_cast<PNS_SEGMENT*>( item ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
LINE_PAIR lp;
|
2014-05-14 13:53:54 +00:00
|
|
|
int segIndex;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
lp.first = assembleLine( seg, &segIndex );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
if( lp.first.HasLockedSegments() )
|
|
|
|
return SH_TRY_WALK;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
assert( segIndex == 0 || ( segIndex == ( lp.first.SegmentCount() - 1 ) ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( segIndex == 0 )
|
2015-08-03 19:11:51 +00:00
|
|
|
lp.first.Reverse();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
lp.second = lp.first;
|
|
|
|
lp.second.ClearSegmentLinks();
|
|
|
|
lp.second.DragCorner( p0_pushed, lp.second.CLine().Find( p0 ) );
|
|
|
|
lp.second.AppendVia( *pushedVia );
|
2014-05-16 11:37:31 +00:00
|
|
|
draggedLines.push_back( lp );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aVia->Marker() & MK_HEAD )
|
2015-08-03 19:11:51 +00:00
|
|
|
m_draggedViaHeadSet.Add( lp.second );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-09-30 09:18:19 +00:00
|
|
|
m_draggedViaHeadSet.Add( pushedVia );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-09-30 09:18:19 +00:00
|
|
|
if( aDryRun )
|
2015-02-18 00:29:54 +00:00
|
|
|
return SH_OK;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-09-30 09:18:19 +00:00
|
|
|
replaceItems( aVia, pushedVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-02-21 00:41:10 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
m_logger.Log( aVia, 0, "obstacle-via" );
|
|
|
|
#endif
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
pushedVia->SetRank( aCurrentRank - 1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2014-11-15 13:43:23 +00:00
|
|
|
m_logger.Log( pushedVia, 1, "pushed-via" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( LINE_PAIR lp : draggedLines )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( lp.first.Marker() & MK_HEAD )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
lp.second.Mark( MK_HEAD );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-09-30 09:18:19 +00:00
|
|
|
if( m_multiLineMode )
|
2015-02-18 00:29:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_newHead = lp.second;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
unwindStack( &lp.first );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( lp.second.SegmentCount() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
replaceItems( &lp.first, &lp.second );
|
|
|
|
lp.second.SetRank( aCurrentRank - 1 );
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( !pushLine( lp.second, true ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
|
|
|
m_currentNode->Remove( &lp.first );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-08-03 19:11:51 +00:00
|
|
|
m_logger.Log( &lp.first, 2, "fan-pre" );
|
|
|
|
m_logger.Log( &lp.second, 3, "fan-post" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_OK;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::onCollidingVia( PNS_ITEM* aCurrent, PNS_VIA* aObstacleVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
int clearance = getClearance( aCurrent, aObstacleVia ) ;
|
2014-05-16 11:37:31 +00:00
|
|
|
LINE_PAIR_VEC draggedLines;
|
2014-05-14 13:53:54 +00:00
|
|
|
bool colLine = false, colVia = false;
|
2014-11-14 19:19:00 +00:00
|
|
|
PNS_LINE* currentLine = NULL;
|
2014-05-14 13:53:54 +00:00
|
|
|
VECTOR2I mtvLine, mtvVia, mtv, mtvSolid;
|
|
|
|
int rank = -1;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aCurrent->OfKind( PNS_ITEM::LINE ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2014-05-16 11:37:31 +00:00
|
|
|
m_logger.NewGroup( "push-via-by-line", m_iter );
|
|
|
|
m_logger.Log( aCurrent, 4, "current" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
currentLine = (PNS_LINE*) aCurrent;
|
2014-11-14 19:19:00 +00:00
|
|
|
colLine = CollideShapes( aObstacleVia->Shape(), currentLine->Shape(),
|
|
|
|
clearance + currentLine->Width() / 2 + PNS_HULL_MARGIN,
|
2014-05-16 11:37:31 +00:00
|
|
|
true, mtvLine );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( currentLine->EndsWithVia() )
|
2014-11-14 19:19:00 +00:00
|
|
|
colVia = CollideShapes( currentLine->Via().Shape(), aObstacleVia->Shape(),
|
2014-05-16 11:37:31 +00:00
|
|
|
clearance + PNS_HULL_MARGIN, true, mtvVia );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !colLine && !colVia )
|
|
|
|
return SH_OK;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( colLine && colVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
mtv = mtvVia.EuclideanNorm() > mtvLine.EuclideanNorm() ? mtvVia : mtvLine;
|
2014-05-16 11:37:31 +00:00
|
|
|
else if( colLine )
|
2014-05-14 13:53:54 +00:00
|
|
|
mtv = mtvLine;
|
|
|
|
else
|
|
|
|
mtv = mtvVia;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
rank = currentLine->Rank();
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
else if( aCurrent->OfKind( PNS_ITEM::SOLID ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-11-14 19:19:00 +00:00
|
|
|
CollideShapes( aObstacleVia->Shape(), aCurrent->Shape(),
|
2014-05-16 11:37:31 +00:00
|
|
|
clearance + PNS_HULL_MARGIN, true, mtvSolid );
|
2014-11-14 18:17:52 +00:00
|
|
|
mtv = -mtvSolid;
|
2014-05-14 13:53:54 +00:00
|
|
|
rank = aCurrent->Rank() + 10000;
|
|
|
|
}
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
return pushVia( aObstacleVia, mtv, rank );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::onReverseCollidingVia( PNS_LINE& aCurrent, PNS_VIA* aObstacleVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE cur( aCurrent );
|
|
|
|
cur.ClearSegmentLinks();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_JOINT* jt = m_currentNode->FindJoint( aObstacleVia->Pos(), aObstacleVia );
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE shoved( aCurrent );
|
|
|
|
shoved.ClearSegmentLinks();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
cur.RemoveVia();
|
|
|
|
unwindStack( &aCurrent );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_ITEM* item : jt->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( item->OfKind( PNS_ITEM::SEGMENT ) && item->LayersOverlap( &aCurrent ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_SEGMENT* seg = (PNS_SEGMENT*) item;
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE head = assembleLine( seg );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
head.AppendVia( *aObstacleVia );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
SHOVE_STATUS st = ProcessSingleLine( head, cur, shoved );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( st != SH_OK )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2014-05-16 11:37:31 +00:00
|
|
|
m_logger.NewGroup( "on-reverse-via-fail-shove", m_iter );
|
|
|
|
m_logger.Log( aObstacleVia, 0, "the-via" );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_logger.Log( &aCurrent, 1, "current-line" );
|
|
|
|
m_logger.Log( &shoved, 3, "shoved-line" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
cur.SetShape( shoved.CLine() );
|
2014-05-14 13:53:54 +00:00
|
|
|
n++;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !n )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2014-05-16 11:37:31 +00:00
|
|
|
m_logger.NewGroup( "on-reverse-via-fail-lonevia", m_iter );
|
|
|
|
m_logger.Log( aObstacleVia, 0, "the-via" );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_logger.Log( &aCurrent, 1, "current-line" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE head( aCurrent );
|
2014-05-14 13:53:54 +00:00
|
|
|
head.Line().Clear();
|
|
|
|
head.AppendVia( *aObstacleVia );
|
|
|
|
head.ClearSegmentLinks();
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
SHOVE_STATUS st = ProcessSingleLine( head, aCurrent, shoved );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
if( st != SH_OK )
|
|
|
|
return st;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
cur.SetShape( shoved.CLine() );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aCurrent.EndsWithVia() )
|
|
|
|
shoved.AppendVia( aCurrent.Via() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-05-16 11:37:31 +00:00
|
|
|
m_logger.NewGroup( "on-reverse-via", m_iter );
|
|
|
|
m_logger.Log( aObstacleVia, 0, "the-via" );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_logger.Log( &aCurrent, 1, "current-line" );
|
|
|
|
m_logger.Log( &shoved, 3, "shoved-line" );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2015-08-03 19:11:51 +00:00
|
|
|
int currentRank = aCurrent.Rank();
|
|
|
|
replaceItems( &aCurrent, &shoved );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
if( !pushLine( shoved ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
shoved.SetRank( currentRank );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
return SH_OK;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
void PNS_SHOVE::unwindStack( PNS_SEGMENT* aSeg )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
for( std::vector<PNS_LINE>::iterator i = m_lineStack.begin(); i != m_lineStack.end() ; )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( i->ContainsSegment( aSeg ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
i = m_lineStack.erase( i );
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
for( std::vector<PNS_LINE>::iterator i = m_optimizerQueue.begin(); i != m_optimizerQueue.end() ; )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( i->ContainsSegment( aSeg ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
i = m_optimizerQueue.erase( i );
|
|
|
|
else
|
|
|
|
i++;
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
void PNS_SHOVE::unwindStack( PNS_ITEM* aItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aItem->OfKind( PNS_ITEM::SEGMENT ) )
|
|
|
|
unwindStack( static_cast<PNS_SEGMENT*>( aItem ) );
|
|
|
|
else if( aItem->OfKind( PNS_ITEM::LINE ) )
|
|
|
|
{
|
|
|
|
PNS_LINE* l = static_cast<PNS_LINE*>( aItem );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( !l->LinkedSegments() )
|
2014-05-14 13:53:54 +00:00
|
|
|
return;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_SEGMENT* seg : *l->LinkedSegments() )
|
2014-05-16 11:37:31 +00:00
|
|
|
unwindStack( seg );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
bool PNS_SHOVE::pushLine( const PNS_LINE& aL, bool aKeepCurrentOnTop )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( aL.LinkCount() >= 0 && ( aL.LinkCount() != aL.SegmentCount() ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
return false;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( aKeepCurrentOnTop && m_lineStack.size() > 0)
|
|
|
|
{
|
|
|
|
m_lineStack.insert( m_lineStack.begin() + m_lineStack.size() - 1, aL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lineStack.push_back( aL );
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
m_optimizerQueue.push_back( aL );
|
2015-07-02 14:09:32 +00:00
|
|
|
|
|
|
|
return true;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PNS_SHOVE::popLine( )
|
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE& l = m_lineStack.back();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
for( std::vector<PNS_LINE>::iterator i = m_optimizerQueue.begin(); i != m_optimizerQueue.end(); )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if( !l.LinkedSegments() )
|
|
|
|
continue;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( PNS_SEGMENT *s : *l.LinkedSegments() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( i->ContainsSegment( s ) )
|
|
|
|
{
|
|
|
|
i = m_optimizerQueue.erase( i );
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2015-08-03 19:11:51 +00:00
|
|
|
|
|
|
|
if( !found )
|
2014-05-14 13:53:54 +00:00
|
|
|
i++;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_lineStack.pop_back();
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::shoveIteration( int aIter )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE currentLine = m_lineStack.back();
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE::OPT_OBSTACLE nearest;
|
2014-11-15 13:43:23 +00:00
|
|
|
SHOVE_STATUS st = SH_NULL;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_ITEM::PnsKind search_order[] = { PNS_ITEM::SOLID, PNS_ITEM::VIA, PNS_ITEM::SEGMENT };
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int i = 0; i < 3; i++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
nearest = m_currentNode->NearestObstacle( ¤tLine, search_order[i] );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
if( nearest )
|
2014-05-14 13:53:54 +00:00
|
|
|
break;
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( !nearest )
|
|
|
|
{
|
|
|
|
m_lineStack.pop_back();
|
|
|
|
return SH_OK;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_ITEM* ni = nearest->m_item;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
unwindStack( ni );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !ni->OfKind( PNS_ITEM::SOLID ) && ni->Rank() >= 0 && ni->Rank() > currentLine.Rank() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
switch( ni->Kind() )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case PNS_ITEM::VIA:
|
|
|
|
{
|
|
|
|
PNS_VIA* revVia = (PNS_VIA*) ni;
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "iter %d: reverse-collide-via", aIter );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
if( currentLine.EndsWithVia() && m_currentNode->CheckColliding( ¤tLine.Via(), revVia ) )
|
|
|
|
{
|
|
|
|
st = SH_INCOMPLETE;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-10-05 16:28:41 +00:00
|
|
|
else
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
st = onReverseCollidingVia( currentLine, revVia );
|
2015-10-05 16:28:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case PNS_ITEM::SEGMENT:
|
|
|
|
{
|
|
|
|
PNS_SEGMENT* seg = (PNS_SEGMENT*) ni;
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "iter %d: reverse-collide-segment ", aIter );
|
2015-10-05 16:28:41 +00:00
|
|
|
PNS_LINE revLine = assembleLine( seg );
|
2015-07-02 14:09:32 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
popLine();
|
|
|
|
st = onCollidingLine( revLine, currentLine );
|
2015-11-03 16:19:42 +00:00
|
|
|
if( !pushLine( revLine ) )
|
2015-10-05 16:28:41 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
assert( false );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-09-14 16:40:29 +00:00
|
|
|
{ // "forward" collisions
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( ni->Kind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-11-15 13:43:23 +00:00
|
|
|
case PNS_ITEM::SEGMENT:
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "iter %d: collide-segment ", aIter );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
st = onCollidingSegment( currentLine, (PNS_SEGMENT*) ni );
|
2015-08-19 16:07:16 +00:00
|
|
|
|
|
|
|
if( st == SH_TRY_WALK )
|
|
|
|
{
|
2016-08-15 15:16:48 +00:00
|
|
|
st = onCollidingSolid( currentLine, ni );
|
2015-08-19 16:07:16 +00:00
|
|
|
}
|
2014-11-15 13:43:23 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
case PNS_ITEM::VIA:
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "iter %d: shove-via ", aIter );
|
2015-08-03 19:11:51 +00:00
|
|
|
st = onCollidingVia( ¤tLine, (PNS_VIA*) ni );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
|
|
|
if( st == SH_TRY_WALK )
|
|
|
|
{
|
|
|
|
st = onCollidingSolid( currentLine, ni );
|
|
|
|
}
|
2014-11-15 13:43:23 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
case PNS_ITEM::SOLID:
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "iter %d: walk-solid ", aIter );
|
2014-11-15 13:43:23 +00:00
|
|
|
st = onCollidingSolid( currentLine, (PNS_SOLID*) ni );
|
|
|
|
break;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return st;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::shoveMainLoop()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS st = SH_OK;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_affectedAreaSum = OPT_BOX2I();
|
|
|
|
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "ShoveStart [root: %d jts, current: %d jts]", m_root->JointCount(),
|
2014-05-16 11:37:31 +00:00
|
|
|
m_currentNode->JointCount() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int iterLimit = Settings().ShoveIterationLimit();
|
|
|
|
TIME_LIMIT timeLimit = Settings().ShoveTimeLimit();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_iter = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
timeLimit.Restart();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
while( !m_lineStack.empty() )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
st = shoveIteration( m_iter );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_iter++;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( st == SH_INCOMPLETE || timeLimit.Expired() || m_iter >= iterLimit )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
st = SH_INCOMPLETE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return st;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
OPT_BOX2I PNS_SHOVE::totalAffectedArea() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
OPT_BOX2I area;
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_nodeStack.empty() )
|
|
|
|
area = m_nodeStack.back().m_affectedArea;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( area )
|
|
|
|
{
|
2015-11-03 16:19:42 +00:00
|
|
|
if( m_affectedAreaSum )
|
2016-08-15 15:16:53 +00:00
|
|
|
area->Merge( *m_affectedAreaSum );
|
2015-02-18 00:29:54 +00:00
|
|
|
} else
|
|
|
|
area = m_affectedAreaSum;
|
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::ShoveLines( const PNS_LINE& aCurrentHead )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS st = SH_OK;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_multiLineMode = false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// empty head? nothing to shove...
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !aCurrentHead.SegmentCount() && !aCurrentHead.EndsWithVia() )
|
2015-07-07 16:37:03 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE head( aCurrentHead );
|
|
|
|
head.ClearSegmentLinks();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_lineStack.clear();
|
|
|
|
m_optimizerQueue.clear();
|
2014-05-16 11:37:31 +00:00
|
|
|
m_newHead = OPT_LINE();
|
2014-05-14 13:53:54 +00:00
|
|
|
m_logger.Clear();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_ITEMSET headSet;
|
|
|
|
headSet.Add( aCurrentHead );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
reduceSpringback( headSet );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE* parent = m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = parent->Branch();
|
|
|
|
m_currentNode->ClearRanks();
|
2015-08-03 19:11:51 +00:00
|
|
|
m_currentNode->Add( &head );
|
|
|
|
|
|
|
|
m_currentNode->LockJoint( head.CPoint(0), &head, true );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !head.EndsWithVia() )
|
|
|
|
m_currentNode->LockJoint( head.CPoint( -1 ), &head, true );
|
|
|
|
|
|
|
|
head.Mark( MK_HEAD );
|
|
|
|
head.SetRank( 100000 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
m_logger.NewGroup( "initial", 0 );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_logger.Log( &head, 0, "head" );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
PNS_VIA* headVia = NULL;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( head.EndsWithVia() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
headVia = head.Via().Clone();
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode->Add( headVia );
|
|
|
|
headVia->Mark( MK_HEAD );
|
2014-05-16 11:37:31 +00:00
|
|
|
headVia->SetRank( 100000 );
|
|
|
|
m_logger.Log( headVia, 0, "head-via" );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:37:03 +00:00
|
|
|
if( !pushLine( head ) )
|
2015-09-14 16:40:29 +00:00
|
|
|
{
|
|
|
|
delete m_currentNode;
|
|
|
|
m_currentNode = parent;
|
|
|
|
|
2015-07-02 14:09:32 +00:00
|
|
|
return SH_INCOMPLETE;
|
2015-09-14 16:40:29 +00:00
|
|
|
}
|
2015-07-02 14:09:32 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
st = shoveMainLoop();
|
2015-07-02 14:09:38 +00:00
|
|
|
|
2015-09-14 16:40:29 +00:00
|
|
|
if( st == SH_OK )
|
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
runOptimizer( m_currentNode );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-09-14 16:40:29 +00:00
|
|
|
if( m_newHead )
|
2016-08-15 15:16:53 +00:00
|
|
|
st = m_currentNode->CheckColliding( &( *m_newHead ) ) ? SH_INCOMPLETE : SH_HEAD_MODIFIED;
|
2015-09-14 16:40:29 +00:00
|
|
|
else
|
|
|
|
st = m_currentNode->CheckColliding( &head ) ? SH_INCOMPLETE : SH_OK;
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
m_currentNode->RemoveByMarker( MK_HEAD );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "Shove status : %s after %d iterations",
|
|
|
|
( ( st == SH_OK || st == SH_HEAD_MODIFIED ) ? "OK" : "FAILURE"), m_iter );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
if( st == SH_OK || st == SH_HEAD_MODIFIED )
|
|
|
|
{
|
2015-11-03 16:19:42 +00:00
|
|
|
pushSpringback( m_currentNode, headSet, PNS_COST_ESTIMATOR(), m_affectedAreaSum );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete m_currentNode;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = parent;
|
2014-11-14 19:19:00 +00:00
|
|
|
m_newHead = OPT_LINE();
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
if(m_newHead)
|
|
|
|
m_newHead->Unmark();
|
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
if( m_newHead && head.EndsWithVia() )
|
|
|
|
{
|
|
|
|
PNS_VIA v = head.Via();
|
|
|
|
v.SetPos( m_newHead->CPoint( -1 ) );
|
|
|
|
m_newHead->AppendVia(v);
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::ShoveMultiLines( const PNS_ITEMSET& aHeadSet )
|
|
|
|
{
|
|
|
|
SHOVE_STATUS st = SH_OK;
|
|
|
|
|
|
|
|
m_multiLineMode = true;
|
|
|
|
|
|
|
|
PNS_ITEMSET headSet;
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( const PNS_ITEM* item : aHeadSet.CItems() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
const PNS_LINE* headOrig = static_cast<const PNS_LINE*>( item );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
// empty head? nothing to shove...
|
|
|
|
if( !headOrig->SegmentCount() )
|
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
headSet.Add( *headOrig );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_lineStack.clear();
|
|
|
|
m_optimizerQueue.clear();
|
|
|
|
m_logger.Clear();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
reduceSpringback( headSet );
|
|
|
|
|
|
|
|
PNS_NODE* parent = m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
|
|
|
|
|
|
|
|
m_currentNode = parent->Branch();
|
|
|
|
m_currentNode->ClearRanks();
|
|
|
|
int n = 0;
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( const PNS_ITEM* item : aHeadSet.CItems() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
const PNS_LINE* headOrig = static_cast<const PNS_LINE*>( item );
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE head( *headOrig );
|
|
|
|
head.ClearSegmentLinks();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_currentNode->Add( &head );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
head.Mark( MK_HEAD );
|
|
|
|
head.SetRank( 100000 );
|
2015-02-18 00:29:54 +00:00
|
|
|
n++;
|
2015-09-30 09:18:19 +00:00
|
|
|
|
|
|
|
if( !pushLine( head ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
return SH_INCOMPLETE;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
PNS_VIA* headVia = NULL;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( head.EndsWithVia() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
headVia = head.Via().Clone(); // fixme: leak
|
2015-02-18 00:29:54 +00:00
|
|
|
m_currentNode->Add( headVia );
|
|
|
|
headVia->Mark( MK_HEAD );
|
|
|
|
headVia->SetRank( 100000 );
|
|
|
|
m_logger.Log( headVia, 0, "head-via" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_logger.NewGroup( "initial", 0 );
|
|
|
|
//m_logger.Log( head, 0, "head" );
|
|
|
|
|
|
|
|
st = shoveMainLoop();
|
2015-07-02 14:09:38 +00:00
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( st == SH_OK )
|
2015-08-03 19:11:51 +00:00
|
|
|
runOptimizer( m_currentNode );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_currentNode->RemoveByMarker( MK_HEAD );
|
|
|
|
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "Shove status : %s after %d iterations",
|
|
|
|
( st == SH_OK ? "OK" : "FAILURE"), m_iter );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( st == SH_OK )
|
|
|
|
{
|
|
|
|
pushSpringback( m_currentNode, PNS_ITEMSET(), PNS_COST_ESTIMATOR(), m_affectedAreaSum );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete m_currentNode;
|
|
|
|
m_currentNode = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::ShoveDraggingVia( PNS_VIA* aVia, const VECTOR2I& aWhere,
|
|
|
|
PNS_VIA** aNewVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
SHOVE_STATUS st = SH_OK;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_lineStack.clear();
|
|
|
|
m_optimizerQueue.clear();
|
2014-05-16 11:37:31 +00:00
|
|
|
m_newHead = OPT_LINE();
|
2014-05-14 13:53:54 +00:00
|
|
|
m_draggedVia = NULL;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_draggedViaHeadSet.Clear();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_NODE* parent = m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_currentNode = parent;
|
|
|
|
|
|
|
|
parent = m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = parent->Branch();
|
2014-05-16 11:37:31 +00:00
|
|
|
m_currentNode->ClearRanks();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
aVia->Mark( MK_HEAD );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
st = pushVia( aVia, ( aWhere - aVia->Pos() ), 0 );
|
2014-05-14 13:53:54 +00:00
|
|
|
st = shoveMainLoop();
|
2015-07-02 14:09:38 +00:00
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( st == SH_OK )
|
2015-08-03 19:11:51 +00:00
|
|
|
runOptimizer( m_currentNode );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( st == SH_OK || st == SH_HEAD_MODIFIED )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:50 +00:00
|
|
|
if( aNewVia )
|
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS","setNewV %p", m_draggedVia );
|
2016-08-15 15:16:50 +00:00
|
|
|
*aNewVia = m_draggedVia;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
pushSpringback( m_currentNode, m_draggedViaHeadSet, PNS_COST_ESTIMATOR(), m_affectedAreaSum );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-15 15:16:50 +00:00
|
|
|
if( aNewVia )
|
|
|
|
{
|
|
|
|
*aNewVia = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
delete m_currentNode;
|
|
|
|
m_currentNode = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
void PNS_SHOVE::runOptimizer( PNS_NODE* aNode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
PNS_OPTIMIZER optimizer( aNode );
|
2015-02-18 00:29:54 +00:00
|
|
|
int optFlags = 0, n_passes = 0;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
PNS_OPTIMIZATION_EFFORT effort = Settings().OptimizerEffort();
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
OPT_BOX2I area = totalAffectedArea();
|
|
|
|
|
|
|
|
int maxWidth = 0;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
for( std::vector<PNS_LINE>::iterator i = m_optimizerQueue.begin();
|
2015-02-18 00:29:54 +00:00
|
|
|
i != m_optimizerQueue.end(); ++i )
|
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
maxWidth = std::max( i->Width(), maxWidth );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( area )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
area->Inflate( 10 * maxWidth );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( effort )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-11-15 13:43:23 +00:00
|
|
|
case OE_LOW:
|
|
|
|
optFlags = PNS_OPTIMIZER::MERGE_OBTUSE;
|
|
|
|
n_passes = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OE_MEDIUM:
|
2015-02-18 00:29:54 +00:00
|
|
|
optFlags = PNS_OPTIMIZER::MERGE_SEGMENTS;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( area )
|
2015-02-18 16:53:46 +00:00
|
|
|
optimizer.SetRestrictArea( *area );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
n_passes = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OE_FULL:
|
|
|
|
optFlags = PNS_OPTIMIZER::MERGE_SEGMENTS;
|
|
|
|
n_passes = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( Settings().SmartPads() )
|
2015-07-22 08:46:56 +00:00
|
|
|
optFlags |= PNS_OPTIMIZER::SMART_PADS;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
optimizer.SetEffortLevel( optFlags );
|
|
|
|
optimizer.SetCollisionMask( PNS_ITEM::ANY );
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( int pass = 0; pass < n_passes; pass++ )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
std::reverse( m_optimizerQueue.begin(), m_optimizerQueue.end() );
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
for( std::vector<PNS_LINE>::iterator i = m_optimizerQueue.begin();
|
2014-11-15 13:43:23 +00:00
|
|
|
i != m_optimizerQueue.end(); ++i )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
PNS_LINE& line = *i;
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !( line.Marker() & MK_HEAD ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
PNS_LINE optimized;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( optimizer.Optimize( &line, &optimized ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
aNode->Remove( &line );
|
|
|
|
line.SetShape( optimized.CLine() );
|
|
|
|
aNode->Add( &line );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
PNS_NODE* PNS_SHOVE::CurrentNode()
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
return m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const PNS_LINE PNS_SHOVE::NewHead() const
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
assert( m_newHead );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return *m_newHead;
|
|
|
|
}
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
void PNS_SHOVE::SetInitialLine( PNS_LINE& aInitial )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_root = m_root->Branch();
|
2015-08-03 19:11:51 +00:00
|
|
|
m_root->Remove( &aInitial );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|