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
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2016-2021 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <cassert>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/box2.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
#include <geometry/shape_compound.h>
|
|
|
|
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_arc.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_node.h"
|
2019-08-07 21:48:09 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#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"
|
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
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
// fixme - move all logger calls to debug decorator
|
2019-07-24 15:19:03 +00:00
|
|
|
|
|
|
|
typedef VECTOR2I::extended_type ecoord;
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void SHOVE::replaceItems( ITEM* aOld, std::unique_ptr< ITEM > aNew )
|
|
|
|
{
|
|
|
|
OPT_BOX2I changed_area = ChangedArea( aOld, aNew.get() );
|
|
|
|
|
|
|
|
if( changed_area )
|
2019-07-22 23:39:33 +00:00
|
|
|
m_affectedArea = m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
|
2016-08-30 15:28:35 +00:00
|
|
|
|
|
|
|
m_currentNode->Replace( aOld, std::move( aNew ) );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NODE* aNode )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-04-26 22:27:30 +00:00
|
|
|
if( aIncludeInChangedArea )
|
|
|
|
{
|
|
|
|
OPT_BOX2I changed_area = ChangedArea( aOld, aNew );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
if( changed_area )
|
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
SHAPE_RECT r( *changed_area );
|
|
|
|
PNS_DBG(Dbg(), AddShape, &r, BLUE, 0, wxT( "shove-changed-area" ) );
|
2021-04-26 22:27:30 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_affectedArea =
|
|
|
|
m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
|
2021-04-26 22:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool foundPredecessor = false;
|
|
|
|
LINE* rootLine = nullptr;
|
|
|
|
|
|
|
|
// Keep track of the 'root lines', i.e. the unmodified (pre-shove) versions
|
|
|
|
// of the affected tracks in a map. The optimizer can then query the pre-shove shape
|
2021-07-19 23:56:05 +00:00
|
|
|
// for each shoved line and perform additional constraint checks (i.e. prevent overzealous
|
|
|
|
// optimizations)
|
2021-04-26 22:27:30 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
// Check if the shoved line already has an ancestor (e.g. line from a previous shove
|
|
|
|
// iteration/cursor movement)
|
2021-04-26 22:27:30 +00:00
|
|
|
for( auto link : aOld.Links() )
|
2021-02-23 21:52:33 +00:00
|
|
|
{
|
2021-04-26 22:27:30 +00:00
|
|
|
auto oldLineIter = m_rootLineHistory.find( link );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
if( oldLineIter != m_rootLineHistory.end() )
|
2021-02-23 21:52:33 +00:00
|
|
|
{
|
2021-04-26 22:27:30 +00:00
|
|
|
rootLine = oldLineIter->second;
|
|
|
|
foundPredecessor = true;
|
|
|
|
break;
|
2021-02-23 21:52:33 +00:00
|
|
|
}
|
2021-04-26 22:27:30 +00:00
|
|
|
}
|
2021-02-23 21:52:33 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
// If found, use it, otherwise, create new entry in the map (we have a genuine new 'root' line)
|
|
|
|
if( !foundPredecessor )
|
|
|
|
{
|
|
|
|
for( auto link : aOld.Links() )
|
|
|
|
{
|
|
|
|
if( ! rootLine )
|
|
|
|
{
|
|
|
|
rootLine = aOld.Clone();
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
m_rootLineHistory[link] = rootLine;
|
|
|
|
}
|
2021-02-23 21:52:33 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
// Now update the NODE (calling Replace invalidates the Links() in a LINE)
|
|
|
|
if( aNode )
|
|
|
|
{
|
|
|
|
aNode->Replace( aOld, aNew );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_currentNode->Replace( aOld, aNew );
|
|
|
|
}
|
|
|
|
|
|
|
|
// point the Links() of the new line to its oldest ancestor
|
|
|
|
for( auto link : aNew.Links() )
|
|
|
|
{
|
|
|
|
m_rootLineHistory[ link ] = rootLine;
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int SHOVE::getClearance( const ITEM* aA, const 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 );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
int SHOVE::getHoleClearance( const ITEM* aA, const ITEM* aB ) const
|
|
|
|
{
|
|
|
|
if( m_forceClearance >= 0 )
|
|
|
|
return m_forceClearance;
|
|
|
|
|
|
|
|
return m_currentNode->GetHoleClearance( aA, aB );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SHOVE::sanityCheck( LINE* aOld, 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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE( NODE* aWorld, ROUTER* aRouter ) :
|
|
|
|
ALGO_BASE( aRouter )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2021-11-21 21:56:26 +00:00
|
|
|
m_optFlagDisableMask = 0;
|
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;
|
2019-08-07 21:48:09 +00:00
|
|
|
SetDebugDecorator( aRouter->GetInterface()->GetDebugDecorator() );
|
2015-04-20 14:59:25 +00:00
|
|
|
|
|
|
|
// Initialize other temporary variables:
|
2021-07-19 23:56:05 +00:00
|
|
|
m_draggedVia = nullptr;
|
2015-04-20 14:59:25 +00:00
|
|
|
m_iter = 0;
|
|
|
|
m_multiLineMode = false;
|
2020-03-30 07:24:56 +00:00
|
|
|
m_restrictSpringbackTagId = 0;
|
2021-12-15 00:32:05 +00:00
|
|
|
m_springbackDoNotTouchNode = nullptr;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::~SHOVE()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2021-04-26 22:27:30 +00:00
|
|
|
std::unordered_set<LINE*> alreadyDeleted;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
for( auto it : m_rootLineHistory )
|
|
|
|
{
|
|
|
|
auto it2 = alreadyDeleted.find( it.second );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
if( it2 == alreadyDeleted.end() )
|
|
|
|
{
|
|
|
|
alreadyDeleted.insert( it.second );
|
|
|
|
delete it.second;
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
LINE SHOVE::assembleLine( const LINKED_ITEM* aSeg, int* aIndex )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
return m_currentNode->AssembleLine( const_cast<LINKED_ITEM*>( aSeg ), aIndex, true );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-05 16:40:34 +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.
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
// Update: there's no concept of an orientation of an open curve, but nonetheless Tom's dumb
|
|
|
|
// as.... (censored)
|
2020-04-14 23:11:42 +00:00
|
|
|
// Two open curves put together make a closed polygon... Tom should learn high school geometry!
|
2021-01-05 16:40:34 +00:00
|
|
|
bool SHOVE::checkShoveDirection( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
const LINE& aShovedLine ) const
|
2020-04-14 23:11:42 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
SHAPE_LINE_CHAIN::POINT_INSIDE_TRACKER checker( aCurLine.CPoint( 0) );
|
|
|
|
checker.AddPolyline( aObstacleLine.CLine() );
|
|
|
|
checker.AddPolyline( aShovedLine.CLine().Reverse() );
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-04-14 23:11:42 +00:00
|
|
|
bool inside = checker.IsInside();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-04-14 23:11:42 +00:00
|
|
|
return !inside;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
/*
|
|
|
|
* Push aObstacleLine away from aCurLine's via by the clearance distance, returning the result
|
|
|
|
* in aResultLine.
|
|
|
|
*
|
|
|
|
* Must be called only when aCurLine itself is on another layer (or has no segments) so that it
|
|
|
|
* can be ignored.
|
|
|
|
*/
|
|
|
|
SHOVE::SHOVE_STATUS SHOVE::shoveLineFromLoneVia( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
LINE& aResultLine )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
// Build a hull for aCurLine's via and re-walk aObstacleLine around it.
|
|
|
|
|
|
|
|
int obstacleLineWidth = aObstacleLine.Width();
|
|
|
|
int clearance = getClearance( &aCurLine, &aObstacleLine );
|
|
|
|
int holeClearance = getHoleClearance( &aCurLine.Via(), &aObstacleLine );
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( holeClearance + aCurLine.Via().Drill() / 2 > clearance + aCurLine.Via().Diameter() / 2 )
|
|
|
|
clearance = holeClearance + aCurLine.Via().Drill() / 2 - aCurLine.Via().Diameter() / 2;
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHAPE_LINE_CHAIN hull = aCurLine.Via().Hull( clearance, obstacleLineWidth, aCurLine.Layer() );
|
2019-07-21 22:36:08 +00:00
|
|
|
SHAPE_LINE_CHAIN path_cw;
|
|
|
|
SHAPE_LINE_CHAIN path_ccw;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( ! aObstacleLine.Walkaround( hull, path_cw, true ) )
|
2018-05-02 22:05:39 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( ! aObstacleLine.Walkaround( hull, path_ccw, false ) )
|
2018-05-02 22:05:39 +00:00
|
|
|
return SH_INCOMPLETE;
|
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
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( aObstacleLine.CPoint( -1 ) != shortest.CPoint( -1 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( aObstacleLine.CPoint( 0 ) != shortest.CPoint( 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_INCOMPLETE;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
aResultLine.SetShape( shortest );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( aResultLine.Collide( &aCurLine, m_currentNode ) )
|
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
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
2021-01-05 16:40:34 +00:00
|
|
|
* Re-walk aObstacleLine around the given set of hulls, returning the result in aResultLine.
|
2019-07-24 15:19:03 +00:00
|
|
|
*/
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
LINE& aResultLine, const HULL_SET& aHulls )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
const SHAPE_LINE_CHAIN& obs = aObstacleLine.CLine();
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int attempt;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, "shove-details", 1 );
|
|
|
|
|
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
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
LINE l( aObstacleLine );
|
2021-06-03 20:35:42 +00:00
|
|
|
SHAPE_LINE_CHAIN path( l.CLine() );
|
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
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddShape, &hull, YELLOW, 10000, wxT( "hull" ) );
|
|
|
|
PNS_DBG( Dbg(), AddShape, &path, WHITE, l.Width(), wxT( "path" ) );
|
|
|
|
PNS_DBG( Dbg(), AddShape, &obs, LIGHTGRAY, aObstacleLine.Width(), wxT( "obs" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
if( !l.Walkaround( hull, path, clockwise ) )
|
2021-02-11 22:07:40 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "Fail-Walk %s %s %d\n" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
hull.Format().c_str(),
|
|
|
|
l.CLine().Format().c_str(),
|
|
|
|
clockwise? 1 : 0) );
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
2018-05-02 22:05:39 +00:00
|
|
|
return SH_INCOMPLETE;
|
2021-02-11 22:07:40 +00:00
|
|
|
}
|
2018-05-02 22:05:39 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
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;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
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
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( ( vFirst < 0 || vLast < 0 ) && !path.CompareGeometry( aObstacleLine.CLine() ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "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
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail vend-start\n" ),
|
|
|
|
attempt ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( !checkShoveDirection( aCurLine, aObstacleLine, l ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail direction-check" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
attempt ) );
|
2021-01-05 16:40:34 +00:00
|
|
|
aResultLine.SetShape( l.CLine() );
|
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
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail self-intersect" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
attempt ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
bool colliding = l.Collide( &aCurLine, m_currentNode );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if(( aCurLine.Marker() & MK_HEAD ) && !colliding )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
JOINT* jtStart = m_currentNode->FindJoint( aCurLine.CPoint( 0 ), &aCurLine );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : jtStart->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
if( item->Collide( &l, m_currentNode ) )
|
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 )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "attempt %d fail coll-check" ),
|
|
|
|
attempt ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
aResultLine.SetShape( l.CLine() );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_OK;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
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
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
2021-01-05 16:40:34 +00:00
|
|
|
* Push aObstacleLine line away from aCurLine by the clearance distance, and return the result in
|
|
|
|
* aResultLine.
|
2019-07-24 15:19:03 +00:00
|
|
|
*/
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::ShoveObstacleLine( const LINE& aCurLine, const LINE& aObstacleLine,
|
|
|
|
LINE& aResultLine )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
aResultLine.ClearLinks();
|
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
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
for( LINKED_ITEM* s : aObstacleLine.Links() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
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;
|
2021-01-05 16:40:34 +00:00
|
|
|
bool viaOnEnd = aCurLine.EndsWithVia();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( viaOnEnd && ( !aCurLine.LayersOverlap( &aObstacleLine ) || aCurLine.SegmentCount() == 0 ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
// Shove aObstacleLine to the hull of aCurLine's via.
|
|
|
|
|
|
|
|
rv = shoveLineFromLoneVia( aCurLine, aObstacleLine, aResultLine );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
// Build a set of hulls around the segments of aCurLine. Hulls are at the clearance
|
|
|
|
// distance + aObstacleLine's linewidth so that when re-walking aObstacleLine along the
|
|
|
|
// hull it will be at the appropriate clearance.
|
|
|
|
|
|
|
|
int obstacleLineWidth = aObstacleLine.Width();
|
|
|
|
int clearance = getClearance( &aCurLine, &aObstacleLine ) + 1;
|
|
|
|
int currentLineSegmentCount = aCurLine.SegmentCount();
|
|
|
|
HULL_SET hulls;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
hulls.reserve( currentLineSegmentCount + 1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
#ifdef DEBUG
|
2022-02-05 02:06:25 +00:00
|
|
|
Dbg()->Message( wxString::Format( wxT( "shove process-single: cur net %d obs %d cl %d" ),
|
2021-07-19 23:56:05 +00:00
|
|
|
aCurLine.Net(), aObstacleLine.Net(), clearance ) );
|
2020-04-16 22:29:28 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
for( int i = 0; i < currentLineSegmentCount; i++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
SEGMENT seg( aCurLine, aCurLine.CSegment( i ) );
|
2021-11-21 17:12:13 +00:00
|
|
|
int extra = 0;
|
|
|
|
|
|
|
|
// Arcs need additional clearance to ensure the hulls are always bigger than the arc
|
|
|
|
if( aCurLine.CLine().IsArcSegment( i ) )
|
|
|
|
extra = SHAPE_ARC::DefaultAccuracyForPCB();
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN hull =
|
|
|
|
seg.Hull( clearance + extra, obstacleLineWidth, aObstacleLine.Layer() );
|
2015-08-03 19:11:51 +00:00
|
|
|
|
|
|
|
hulls.push_back( hull );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( viaOnEnd )
|
2021-01-01 00:29:05 +00:00
|
|
|
{
|
2021-01-05 16:40:34 +00:00
|
|
|
const VIA& via = aCurLine.Via();
|
|
|
|
int viaClearance = getClearance( &via, &aObstacleLine );
|
|
|
|
int holeClearance = getHoleClearance( &via, &aObstacleLine );
|
2021-01-01 00:29:05 +00:00
|
|
|
|
|
|
|
if( holeClearance + via.Drill() / 2 > viaClearance + via.Diameter() / 2 )
|
|
|
|
viaClearance = holeClearance + via.Drill() / 2 - via.Diameter() / 2;
|
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
hulls.push_back( aCurLine.Via().Hull( viaClearance, obstacleLineWidth ) );
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
rv = shoveLineToHullSet( aCurLine, aObstacleLine, aResultLine, 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 )
|
2021-01-05 16:40:34 +00:00
|
|
|
aResultLine.Mark( aResultLine.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
|
|
|
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* TODO describe....
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacleSeg )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
int segIndex;
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE obstacleLine = assembleLine( aObstacleSeg, &segIndex );
|
|
|
|
LINE shovedLine( obstacleLine );
|
|
|
|
SEGMENT tmp( *aObstacleSeg );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-15 15:16:48 +00:00
|
|
|
if( obstacleLine.HasLockedSegments() )
|
2022-02-26 01:42:16 +00:00
|
|
|
{
|
|
|
|
PNS_DBG(Dbg(), Message, "try walk (locked segments)");
|
2016-08-15 15:16:48 +00:00
|
|
|
return SH_TRY_WALK;
|
2022-02-26 01:42:16 +00:00
|
|
|
}
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS rv = ShoveObstacleLine( 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 ) );
|
|
|
|
|
2021-02-11 22:07:40 +00:00
|
|
|
if( Dbg() )
|
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, aObstacleSeg, BLUE, 0, wxT( "shove-changed-area" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &obstacleLine, GREEN, 10000, wxT( "obstacle-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 10000, wxT( "shoved-line" ) );
|
2021-02-11 22:07:40 +00:00
|
|
|
}
|
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 );
|
2016-08-30 15:28:35 +00:00
|
|
|
replaceLine( obstacleLine, shovedLine );
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
/*
|
|
|
|
* TODO describe....
|
|
|
|
*/
|
|
|
|
SHOVE::SHOVE_STATUS SHOVE::onCollidingArc( LINE& aCurrent, ARC* aObstacleArc )
|
|
|
|
{
|
|
|
|
int segIndex;
|
|
|
|
LINE obstacleLine = assembleLine( aObstacleArc, &segIndex );
|
|
|
|
LINE shovedLine( obstacleLine );
|
|
|
|
ARC tmp( *aObstacleArc );
|
|
|
|
|
|
|
|
if( obstacleLine.HasLockedSegments() )
|
|
|
|
return SH_TRY_WALK;
|
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, obstacleLine, shovedLine );
|
2019-05-17 00:13:21 +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;
|
|
|
|
|
|
|
|
assert( obstacleLine.LayersOverlap( &shovedLine ) );
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &tmp, WHITE, 10000, wxT( "obstacle-arc" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &obstacleLine, GREEN, 10000, wxT( "obstacle-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 10000, wxT( "shoved-line" ) );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
if( rv == SH_OK )
|
|
|
|
{
|
|
|
|
if( shovedLine.Marker() & MK_HEAD )
|
|
|
|
{
|
|
|
|
if( m_multiLineMode )
|
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
|
|
|
m_newHead = shovedLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rank = aCurrent.Rank();
|
|
|
|
shovedLine.SetRank( rank - 1 );
|
|
|
|
|
|
|
|
sanityCheck( &obstacleLine, &shovedLine );
|
|
|
|
replaceLine( obstacleLine, shovedLine );
|
|
|
|
|
|
|
|
if( !pushLineStack( shovedLine ) )
|
|
|
|
rv = SH_INCOMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* TODO describe....
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::onCollidingLine( LINE& aCurrent, LINE& aObstacle )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE shovedLine( aObstacle );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, aObstacle, shovedLine );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &aObstacle, RED, 100000, wxT( "obstacle-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &aCurrent, GREEN, 150000, wxT( "current-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 200000, wxT( "shoved-line" ) );
|
2021-04-08 00:28:30 +00:00
|
|
|
|
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 );
|
2016-08-30 15:28:35 +00:00
|
|
|
replaceLine( aObstacle, shovedLine );
|
2015-08-03 19:11:51 +00:00
|
|
|
|
|
|
|
int rank = aObstacle.Rank();
|
|
|
|
shovedLine.SetRank( rank - 1 );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO describe....
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::onCollidingSolid( LINE& aCurrent, ITEM* aObstacle )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
WALKAROUND walkaround( m_currentNode, Router() );
|
|
|
|
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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA vh = aCurrent.Via();
|
2021-07-19 23:56:05 +00:00
|
|
|
VIA* via = nullptr;
|
2016-08-29 17:31:13 +00:00
|
|
|
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-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : jtStart->LinkList() )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( item->OfKind( ITEM::VIA_T ) )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
via = (VIA*) item;
|
2014-05-16 11:37:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( via && via->Collide( aObstacle, m_currentNode ) )
|
2015-08-19 16:07:16 +00:00
|
|
|
return onCollidingVia( aObstacle, via );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
TOPOLOGY topo( m_currentNode );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
std::set<ITEM*> cluster = topo.AssembleCluster( aObstacle, aCurrent.Layers().Start() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
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-29 17:31:13 +00:00
|
|
|
WALKAROUND::WALKAROUND_STATUS status = walkaround.Route( aCurrent, walkaroundLine, false );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( status != WALKAROUND::DONE )
|
2016-08-15 15:16:48 +00:00
|
|
|
continue;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-04-15 20:16:24 +00:00
|
|
|
walkaroundLine.ClearLinks();
|
2015-08-19 16:07:16 +00:00
|
|
|
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() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE lastLine = m_lineStack.front();
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( lastLine.Collide( &walkaroundLine, m_currentNode ) )
|
2015-08-19 16:07:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE dummy( lastLine );
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
if( ShoveObstacleLine( 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
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
}
|
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;
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
replaceLine( aCurrent, walkaroundLine );
|
2015-08-03 19:11:51 +00:00
|
|
|
walkaroundLine.SetRank( nextRank );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &walkaroundLine, BLUE, 10000, wxT( "walk-line" ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
popLineStack();
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
/*
|
|
|
|
* Pops NODE stackframes which no longer collide with aHeadSet. Optionally sets aDraggedVia
|
|
|
|
* to the dragged via of the last unpopped state.
|
|
|
|
*/
|
2019-08-07 21:48:09 +00:00
|
|
|
NODE* SHOVE::reduceSpringback( const ITEM_SET& aHeadSet, VIA_HANDLE& aDraggedVia )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
while( !m_nodeStack.empty() )
|
|
|
|
{
|
2019-08-07 21:48:09 +00:00
|
|
|
SPRINGBACK_TAG& spTag = m_nodeStack.back();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-12-15 00:32:05 +00:00
|
|
|
// Prevent the springback algo from erasing NODEs that might contain items used by the ROUTER_TOOL/LINE_PLACER.
|
|
|
|
// I noticed this can happen for the endItem provided to LINE_PLACER::Move() and cause a nasty crash.
|
|
|
|
if( spTag.m_node == m_springbackDoNotTouchNode )
|
|
|
|
break;
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
OPT<OBSTACLE> obs = spTag.m_node->CheckColliding( aHeadSet );
|
2019-08-07 21:48:09 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
if( !obs && !spTag.m_locked )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2019-08-07 21:48:09 +00:00
|
|
|
aDraggedVia = spTag.m_draggedVia;
|
|
|
|
aDraggedVia.valid = 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
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
return m_nodeStack.empty() ? m_root : m_nodeStack.back().m_node;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
/*
|
|
|
|
* Push the current NODE on to the stack. aDraggedVia is the dragged via *before* the push
|
|
|
|
* (which will be restored in the event the stackframe is popped).
|
|
|
|
*/
|
|
|
|
bool SHOVE::pushSpringback( NODE* aNode, const OPT_BOX2I& aAffectedArea, VIA* aDraggedVia )
|
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
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
if( aDraggedVia )
|
|
|
|
{
|
|
|
|
st.m_draggedVia = aDraggedVia->MakeHandle();
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
st.m_node = aNode;
|
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;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
st.m_affectedArea = prev_area;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
st.m_seq = ( m_nodeStack.empty() ? 1 : m_nodeStack.back().m_seq + 1 );
|
2020-02-07 19:57:24 +00:00
|
|
|
st.m_locked = false;
|
2020-03-30 07:24:56 +00:00
|
|
|
|
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
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* Push or shove a via by at least aForce. (The via might be pushed or shoved slightly further
|
|
|
|
* to keep it from landing on an existing joint.)
|
|
|
|
*/
|
2019-07-23 23:28:29 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, int aCurrentRank )
|
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() );
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* jt = m_currentNode->FindJoint( p0, aVia );
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I p0_pushed( p0 + aForce );
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( wxT( "via force [%d %d]\n" ), aForce.x, aForce.y ) );
|
2021-06-03 20:35:42 +00:00
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
// nothing to do...
|
|
|
|
if ( aForce.x == 0 && aForce.y == 0 )
|
|
|
|
return SH_OK;
|
|
|
|
|
2015-08-07 15:07:06 +00:00
|
|
|
if( !jt )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
PNS_DBG( Dbg(), Message,
|
2022-02-05 02:06:25 +00:00
|
|
|
wxString::Format( wxT( "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;
|
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
// make sure pushed via does not overlap with any existing joint
|
|
|
|
while( true )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
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
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
p0_pushed += aForce.Resize( 2 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
std::unique_ptr<VIA> pushedVia = Clone( *aVia );
|
2015-02-18 00:29:54 +00:00
|
|
|
pushedVia->SetPos( p0_pushed );
|
2014-05-16 11:37:31 +00:00
|
|
|
pushedVia->Mark( aVia->Marker() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : jt->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
LINKED_ITEM* li = static_cast<LINKED_ITEM*>( item );
|
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
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
lp.first = assembleLine( li, &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;
|
2020-04-15 20:16:24 +00:00
|
|
|
lp.second.ClearLinks();
|
2015-08-03 19:11:51 +00:00
|
|
|
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 );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
pushedVia->SetRank( aCurrentRank - 1 );
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format("PushViaRank %d\n", pushedVia->Rank() ) );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
if( aVia->Marker() & MK_HEAD ) // push
|
|
|
|
{
|
2016-09-21 12:47:07 +00:00
|
|
|
m_draggedVia = pushedVia.get();
|
2019-07-24 15:19:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // shove
|
|
|
|
if( jt->IsStitchingVia() )
|
|
|
|
pushLineStack( LINE( *pushedVia ) );
|
|
|
|
}
|
2016-09-21 12:47:07 +00:00
|
|
|
|
2021-06-03 20:35:42 +00:00
|
|
|
PNS_DBG( Dbg(), AddPoint, aVia->Pos(), LIGHTGREEN, 100000, "via-pre" );
|
|
|
|
PNS_DBG( Dbg(), AddPoint, pushedVia->Pos(), LIGHTRED, 100000, "via-post" );
|
|
|
|
|
2016-09-06 14:27:35 +00:00
|
|
|
replaceItems( aVia, std::move( pushedVia ) );
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
unwindLineStack( &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
|
|
|
{
|
2016-08-30 15:28:35 +00:00
|
|
|
replaceLine( lp.first, lp.second );
|
2015-08-03 19:11:51 +00:00
|
|
|
lp.second.SetRank( aCurrentRank - 1 );
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format("PushViaF %p %d\n", &lp.second, lp.second.SegmentCount() ) );
|
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
|
|
{
|
2016-08-30 17:01:30 +00:00
|
|
|
m_currentNode->Remove( lp.first );
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &lp.first, LIGHTGREEN, 10000, wxT( "fan-pre" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &lp.second, LIGHTRED, 10000, wxT( "fan-post" ) );
|
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
|
|
|
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* Calculate the minimum translation vector required to resolve a collision with a via and
|
|
|
|
* shove the via by that distance.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
int clearance = getClearance( aCurrent, aObstacleVia );
|
|
|
|
VECTOR2I mtv;
|
2014-05-14 13:53:54 +00:00
|
|
|
int rank = -1;
|
|
|
|
|
2021-04-18 22:43:30 +00:00
|
|
|
bool lineCollision = false;
|
|
|
|
bool viaCollision = false;
|
|
|
|
VECTOR2I mtvLine, mtvVia;
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, "push-via-by-line", 1 );
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( aCurrent->OfKind( ITEM::LINE_T ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
VIA vtmp ( *aObstacleVia );
|
2021-01-01 00:29:05 +00:00
|
|
|
LINE* currentLine = (LINE*) aCurrent;
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, currentLine, LIGHTRED, 10000, wxT( "current-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &vtmp, LIGHTRED, 100000, wxT( "orig-via" ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
lineCollision = aObstacleVia->Shape()->Collide( currentLine->Shape(),
|
|
|
|
clearance + currentLine->Width() / 2,
|
|
|
|
&mtvLine );
|
2021-06-01 05:17:57 +00:00
|
|
|
|
2021-04-18 22:43:30 +00:00
|
|
|
// Check the via if present. Via takes priority.
|
2014-05-16 11:37:31 +00:00
|
|
|
if( currentLine->EndsWithVia() )
|
2019-07-21 22:36:08 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
const VIA& currentVia = currentLine->Via();
|
|
|
|
int viaClearance = getClearance( ¤tVia, aObstacleVia );
|
2021-04-18 22:43:30 +00:00
|
|
|
|
2022-01-12 23:43:25 +00:00
|
|
|
viaCollision = aObstacleVia->PushoutForce( m_currentNode, ¤tVia, mtvVia );
|
2019-07-21 22:36:08 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2016-08-29 17:31:13 +00:00
|
|
|
else if( aCurrent->OfKind( ITEM::SOLID_T ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-04-18 22:43:30 +00:00
|
|
|
// TODO: is this possible at all? We don't shove solids.
|
|
|
|
return SH_INCOMPLETE;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-04-18 22:43:30 +00:00
|
|
|
// fixme: we may have a sign issue in Collide(CIRCLE, LINE_CHAIN)
|
|
|
|
if( viaCollision )
|
2022-01-12 23:43:25 +00:00
|
|
|
mtv = -mtvVia;
|
2021-04-18 22:43:30 +00:00
|
|
|
else if ( lineCollision )
|
|
|
|
mtv = -mtvLine;
|
|
|
|
else
|
|
|
|
mtv = VECTOR2I(0, 0);
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2021-06-03 20:35:42 +00:00
|
|
|
SHOVE::SHOVE_STATUS st = pushOrShoveVia( aObstacleVia, -mtv, rank );
|
|
|
|
|
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
|
|
|
return st;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* TODO describe....
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::onReverseCollidingVia( LINE& aCurrent, VIA* aObstacleVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE cur( aCurrent );
|
2020-04-15 20:16:24 +00:00
|
|
|
cur.ClearLinks();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* jt = m_currentNode->FindJoint( aObstacleVia->Pos(), aObstacleVia );
|
|
|
|
LINE shoved( aCurrent );
|
2020-04-15 20:16:24 +00:00
|
|
|
shoved.ClearLinks();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
cur.RemoveVia();
|
2019-07-23 23:28:29 +00:00
|
|
|
unwindLineStack( &aCurrent );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : jt->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) && item->LayersOverlap( &aCurrent ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
LINKED_ITEM* li = static_cast<LINKED_ITEM*>( item );
|
|
|
|
LINE head = assembleLine( li );
|
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
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS st = ShoveObstacleLine( head, cur, shoved );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( st != SH_OK )
|
|
|
|
{
|
2020-04-16 22:29:28 +00:00
|
|
|
#if 0
|
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
|
|
|
{
|
2020-04-16 22:29:28 +00:00
|
|
|
#if 0
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE head( aCurrent );
|
2014-05-14 13:53:54 +00:00
|
|
|
head.Line().Clear();
|
|
|
|
head.AppendVia( *aObstacleVia );
|
2020-04-15 20:16:24 +00:00
|
|
|
head.ClearLinks();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-01-05 16:40:34 +00:00
|
|
|
SHOVE_STATUS st = ShoveObstacleLine( 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
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
#if 0
|
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
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddItem, aObstacleVia, YELLOW, 0, wxT( "rr-the-via" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &aCurrent, BLUE, 0, wxT( "rr-current-line" ) );
|
|
|
|
PNS_DBG( Dbg(), AddItem, &shoved, GREEN, 0, wxT( "rr-shoved-line" ) );
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int currentRank = aCurrent.Rank();
|
2016-08-30 15:28:35 +00:00
|
|
|
replaceLine( aCurrent, shoved );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
|
|
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
void SHOVE::unwindLineStack( LINKED_ITEM* aSeg )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
int d = 0;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( std::vector<LINE>::iterator i = m_lineStack.begin(); i != m_lineStack.end() ; )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-04-15 20:16:24 +00:00
|
|
|
if( i->ContainsLink( aSeg ) )
|
2022-02-26 01:42:16 +00:00
|
|
|
{
|
|
|
|
PNS_DBG(Dbg(), Message, wxString::Format("Unwind lc %d (depth %d/%d)", i->SegmentCount(), d, (int)m_lineStack.size() ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
i = m_lineStack.erase( i );
|
2022-02-26 01:42:16 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
else
|
|
|
|
i++;
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
d++;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( std::vector<LINE>::iterator i = m_optimizerQueue.begin(); i != m_optimizerQueue.end() ; )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-04-15 20:16:24 +00:00
|
|
|
if( i->ContainsLink( 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
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
void SHOVE::unwindLineStack( ITEM* aItem )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
if( aItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
|
|
|
unwindLineStack( static_cast<LINKED_ITEM*>( aItem ) );
|
2016-08-29 17:31:13 +00:00
|
|
|
else if( aItem->OfKind( ITEM::LINE_T ) )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE* l = static_cast<LINE*>( aItem );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
for( LINKED_ITEM* seg : l->Links() )
|
2019-07-23 23:28:29 +00:00
|
|
|
unwindLineStack( 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
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
bool SHOVE::pushLineStack( const LINE& aL, bool aKeepCurrentOnTop )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2018-05-08 13:17:33 +00:00
|
|
|
if( !aL.IsLinkedChecked() && aL.SegmentCount() != 0 )
|
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
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
void SHOVE::popLineStack( )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE& l = m_lineStack.back();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( std::vector<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;
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
for( LINKED_ITEM* s : l.Links() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-04-15 20:16:24 +00:00
|
|
|
if( i->ContainsLink( s ) )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* Resolve the next collision.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE currentLine = m_lineStack.back();
|
|
|
|
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
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
if( Dbg() )
|
|
|
|
{
|
2020-04-16 22:29:28 +00:00
|
|
|
Dbg()->SetIteration( aIter );
|
2022-02-26 01:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddItem, ¤tLine, RED, currentLine.Width(), wxString::Format( "current-coll-chk rank %d", currentLine.Rank() ) );
|
2020-04-16 22:29:28 +00:00
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
for( ITEM::PnsKind search_order : { ITEM::SOLID_T, ITEM::VIA_T, ITEM::SEGMENT_T } )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-07-22 23:39:33 +00:00
|
|
|
nearest = m_currentNode->NearestObstacle( ¤tLine, search_order );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
if( nearest )
|
|
|
|
PNS_DBG( Dbg(), Message,
|
2022-02-26 01:42:16 +00:00
|
|
|
wxString::Format( wxT( "nearest %p %s rank %d" ), nearest->m_item,
|
|
|
|
nearest->m_item->KindStr(), nearest->m_item->Rank() ) );
|
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();
|
2021-06-03 20:35:42 +00:00
|
|
|
PNS_DBG( Dbg(), Message, "no-nearest-item ");
|
2014-05-14 13:53:54 +00:00
|
|
|
return SH_OK;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM* ni = nearest->m_item;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
unwindLineStack( ni );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( !ni->OfKind( ITEM::SOLID_T ) && ni->Rank() >= 0 && ni->Rank() > currentLine.Rank() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-07-24 15:19:03 +00:00
|
|
|
// Collision with a higher-ranking object (ie: one that we've already shoved)
|
|
|
|
//
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( ni->Kind() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-via", aIter ).ToStdString(), 0 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( currentLine.EndsWithVia() )
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2019-07-24 15:19:03 +00:00
|
|
|
st = onReverseCollidingVia( currentLine, (VIA*) ni );
|
2015-10-05 16:28:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-segment ",
|
|
|
|
aIter ).ToStdString(), 0 );
|
2019-05-17 00:13:21 +00:00
|
|
|
LINE revLine = assembleLine( static_cast<SEGMENT*>( ni ) );
|
|
|
|
|
|
|
|
popLineStack();
|
|
|
|
st = onCollidingLine( revLine, currentLine );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
if( !pushLineStack( revLine ) )
|
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ITEM::ARC_T:
|
|
|
|
{
|
|
|
|
//TODO(snh): Handle Arc shove separate from track
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-arc ", aIter ).ToStdString(), 0 );
|
2019-05-17 00:13:21 +00:00
|
|
|
LINE revLine = assembleLine( static_cast<ARC*>( ni ) );
|
2015-07-02 14:09:32 +00:00
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
popLineStack();
|
2015-10-05 16:28:41 +00:00
|
|
|
st = onCollidingLine( revLine, currentLine );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
2019-07-24 15:19:03 +00:00
|
|
|
{
|
|
|
|
// Collision with a lower-ranking object or a solid
|
|
|
|
//
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( ni->Kind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-segment ", aIter ), 0 );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
st = onCollidingSegment( currentLine, (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 );
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
2019-07-21 22:36:08 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
//TODO(snh): Customize Arc collide
|
|
|
|
case ITEM::ARC_T:
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-arc ", aIter ), 0 );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
st = onCollidingArc( currentLine, static_cast<ARC*>( ni ) );
|
|
|
|
|
|
|
|
if( st == SH_TRY_WALK )
|
|
|
|
st = onCollidingSolid( currentLine, ni );
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
break;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-via (fixup: %d)", aIter, 0 ), 0 );
|
2016-08-29 17:31:13 +00:00
|
|
|
st = onCollidingVia( ¤tLine, (VIA*) ni );
|
2016-08-15 15:16:48 +00:00
|
|
|
|
|
|
|
if( st == SH_TRY_WALK )
|
|
|
|
st = onCollidingSolid( currentLine, ni );
|
2019-07-21 22:36:08 +00:00
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SOLID_T:
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: walk-solid ", aIter ), 0);
|
2016-08-29 17:31:13 +00:00
|
|
|
st = onCollidingSolid( currentLine, (SOLID*) ni );
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBGN( Dbg(), EndGroup );
|
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
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
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
/*
|
|
|
|
* Resolve collisions.
|
|
|
|
* Each iteration pushes the next colliding object out of the way. Iterations are continued as
|
|
|
|
* long as they propagate further collisions, or until the iteration timeout or max iteration
|
|
|
|
* count is reached.
|
|
|
|
*/
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS 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
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
m_affectedArea = OPT_BOX2I();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "ShoveStart [root: %d jts, current: %d jts]",
|
|
|
|
m_root->JointCount(),
|
|
|
|
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
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
if( m_lineStack.empty() && m_draggedVia )
|
|
|
|
{
|
|
|
|
// If we're shoving a free via then push a proxy LINE (with the via on the end) onto
|
|
|
|
// the stack.
|
2020-11-24 22:16:41 +00:00
|
|
|
pushLineStack( LINE( *m_draggedVia ) );
|
2019-07-22 23:46:20 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
while( !m_lineStack.empty() )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: node %p stack %d ", m_iter,
|
|
|
|
m_currentNode, (int) m_lineStack.size() ) );
|
2021-06-03 20:35:42 +00:00
|
|
|
|
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
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "Fail [time limit expired: %d iter %d iter limit %d",
|
|
|
|
timeLimit.Expired()?1:0, 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
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OPT_BOX2I SHOVE::totalAffectedArea() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
OPT_BOX2I area;
|
2019-07-22 23:39:33 +00:00
|
|
|
|
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
|
|
|
|
2019-07-22 23:39:33 +00:00
|
|
|
if( area && m_affectedArea)
|
|
|
|
area->Merge( *m_affectedArea );
|
|
|
|
else if( !area )
|
|
|
|
area = m_affectedArea;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const 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
|
|
|
|
2021-09-20 19:32:38 +00:00
|
|
|
PNS_DBG( Dbg(), Message,
|
|
|
|
wxString::Format( "Shove start, lc = %d", aCurrentHead.SegmentCount() ) )
|
2021-02-11 22:07:40 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// empty head? nothing to shove...
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !aCurrentHead.SegmentCount() && !aCurrentHead.EndsWithVia() )
|
2015-07-07 16:37:03 +00:00
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE head( aCurrentHead );
|
2020-04-15 20:16:24 +00:00
|
|
|
head.ClearLinks();
|
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();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
#if 0
|
2014-05-14 13:53:54 +00:00
|
|
|
m_logger.Clear();
|
2020-04-16 22:29:28 +00:00
|
|
|
#endif
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
// Pop NODEs containing previous shoves which are no longer necessary
|
|
|
|
//
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET headSet;
|
2015-08-03 19:11:51 +00:00
|
|
|
headSet.Add( aCurrentHead );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
VIA_HANDLE dummyVia;
|
|
|
|
|
|
|
|
NODE* parent = reduceSpringback( headSet, dummyVia );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
// Create a new NODE to store this version of the world
|
2014-05-14 13:53:54 +00:00
|
|
|
m_currentNode = parent->Branch();
|
|
|
|
m_currentNode->ClearRanks();
|
2016-08-30 15:28:35 +00:00
|
|
|
m_currentNode->Add( head );
|
2015-08-03 19:11:51 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, &head, CYAN, 0, wxT( "head, after shove" ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( head.EndsWithVia() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-30 15:28:35 +00:00
|
|
|
std::unique_ptr< VIA >headVia = Clone( head.Via() );
|
2014-05-14 13:53:54 +00:00
|
|
|
headVia->Mark( MK_HEAD );
|
2014-05-16 11:37:31 +00:00
|
|
|
headVia->SetRank( 100000 );
|
2016-08-30 15:28:35 +00:00
|
|
|
m_currentNode->Add( std::move( headVia ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( 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
|
|
|
|
2021-05-28 22:09:21 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "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 )
|
|
|
|
{
|
2019-07-22 23:46:20 +00:00
|
|
|
pushSpringback( m_currentNode, m_affectedArea, nullptr );
|
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() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
VIA v = head.Via();
|
2015-11-03 16:19:42 +00:00
|
|
|
v.SetPos( m_newHead->CPoint( -1 ) );
|
|
|
|
m_newHead->AppendVia(v);
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS SHOVE::ShoveMultiLines( const ITEM_SET& aHeadSet )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
SHOVE_STATUS st = SH_OK;
|
|
|
|
|
|
|
|
m_multiLineMode = true;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET headSet;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : aHeadSet.CItems() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE* headOrig = static_cast<const LINE*>( item );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
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();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-04-16 22:29:28 +00:00
|
|
|
#if 0
|
2015-02-18 00:29:54 +00:00
|
|
|
m_logger.Clear();
|
2020-04-16 22:29:28 +00:00
|
|
|
#endif
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
VIA_HANDLE dummyVia;
|
|
|
|
|
|
|
|
NODE* parent = reduceSpringback( headSet, dummyVia );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_currentNode = parent->Branch();
|
|
|
|
m_currentNode->ClearRanks();
|
|
|
|
int n = 0;
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : aHeadSet.CItems() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE* headOrig = static_cast<const LINE*>( item );
|
|
|
|
LINE head( *headOrig );
|
2020-04-15 20:16:24 +00:00
|
|
|
head.ClearLinks();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-30 15:28:35 +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
|
|
|
|
2019-07-23 23:28:29 +00:00
|
|
|
if( !pushLineStack( head ) )
|
2015-07-02 14:09:32 +00:00
|
|
|
return SH_INCOMPLETE;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( head.EndsWithVia() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-30 15:28:35 +00:00
|
|
|
std::unique_ptr< VIA > headVia = Clone( head.Via() );
|
2015-02-18 00:29:54 +00:00
|
|
|
headVia->Mark( MK_HEAD );
|
|
|
|
headVia->SetRank( 100000 );
|
2016-08-30 15:28:35 +00:00
|
|
|
m_currentNode->Add( std::move( headVia ) );
|
2015-02-18 00:29: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 );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_currentNode->RemoveByMarker( MK_HEAD );
|
|
|
|
|
2021-05-28 22:09:21 +00:00
|
|
|
PNS_DBG( Dbg(), Message, wxString::Format( "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 )
|
|
|
|
{
|
2019-07-22 23:46:20 +00:00
|
|
|
pushSpringback( m_currentNode, m_affectedArea, nullptr );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete m_currentNode;
|
|
|
|
m_currentNode = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
static VIA* findViaByHandle ( NODE *aNode, const VIA_HANDLE& handle )
|
|
|
|
{
|
|
|
|
JOINT* jt = aNode->FindJoint( handle.pos, handle.layers.Start(), handle.net );
|
|
|
|
|
|
|
|
if( !jt )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
for( ITEM* item : jt->LinkList() )
|
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
if( item->OfKind( ITEM::VIA_T ) )
|
2019-08-07 21:48:09 +00:00
|
|
|
{
|
|
|
|
if( item->Net() == handle.net && item->Layers().Overlaps(handle.layers) )
|
|
|
|
return static_cast<VIA*>( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
|
|
|
SHOVE::SHOVE_STATUS SHOVE::ShoveDraggingVia( const VIA_HANDLE aOldVia, const VECTOR2I& aWhere,
|
|
|
|
VIA_HANDLE& aNewVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +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();
|
2021-07-19 23:56:05 +00:00
|
|
|
m_draggedVia = nullptr;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
VIA* viaToDrag = findViaByHandle( m_currentNode, aOldVia );
|
2019-08-07 21:48:09 +00:00
|
|
|
|
|
|
|
if( !viaToDrag )
|
|
|
|
return SH_INCOMPLETE;
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
// Pop NODEs containing previous shoves which are no longer necessary
|
2019-07-22 23:46:20 +00:00
|
|
|
ITEM_SET headSet;
|
2020-01-07 17:12:59 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
VIA headVia ( *viaToDrag );
|
|
|
|
headVia.SetPos( aWhere );
|
|
|
|
headSet.Add( headVia );
|
|
|
|
VIA_HANDLE prevViaHandle;
|
|
|
|
NODE* parent = reduceSpringback( headSet, prevViaHandle );
|
|
|
|
|
|
|
|
if( prevViaHandle.valid )
|
|
|
|
{
|
|
|
|
aNewVia = prevViaHandle;
|
|
|
|
viaToDrag = findViaByHandle( parent, prevViaHandle );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
// Create a new NODE to store this version of the world
|
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
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
viaToDrag->Mark( MK_HEAD );
|
|
|
|
viaToDrag->SetRank( 100000 );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-07-22 23:46:20 +00:00
|
|
|
// Push the via to its new location
|
2020-11-24 22:16:41 +00:00
|
|
|
st = pushOrShoveVia( viaToDrag, ( aWhere - viaToDrag->Pos() ), 0 );
|
2019-07-22 23:46:20 +00:00
|
|
|
|
|
|
|
// Shove any colliding objects out of the way
|
|
|
|
if( st == SH_OK )
|
|
|
|
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
|
|
|
{
|
2019-07-22 23:39:33 +00:00
|
|
|
wxLogTrace( "PNS","setNewV %p", m_draggedVia );
|
2016-08-15 15:16:50 +00:00
|
|
|
|
2019-08-07 21:48:09 +00:00
|
|
|
if (!m_draggedVia)
|
|
|
|
m_draggedVia = viaToDrag;
|
|
|
|
|
|
|
|
aNewVia = m_draggedVia->MakeHandle();
|
|
|
|
|
|
|
|
pushSpringback( m_currentNode, m_affectedArea, viaToDrag );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
delete m_currentNode;
|
|
|
|
m_currentNode = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
LINE* SHOVE::findRootLine( LINE *aLine )
|
|
|
|
{
|
|
|
|
for( auto link : aLine->Links() )
|
|
|
|
{
|
|
|
|
if( auto seg = dyn_cast<SEGMENT*>( link ) )
|
|
|
|
{
|
|
|
|
auto it = m_rootLineHistory.find( seg );
|
|
|
|
|
|
|
|
if( it != m_rootLineHistory.end() )
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SHOVE::runOptimizer( NODE* aNode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
OPTIMIZER optimizer( aNode );
|
2021-02-25 16:18:13 +00:00
|
|
|
int optFlags = 0;
|
2019-07-21 22:36:08 +00:00
|
|
|
int 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;
|
|
|
|
|
2019-07-21 22:36:08 +00:00
|
|
|
for( LINE& line : m_optimizerQueue )
|
|
|
|
maxWidth = std::max( line.Width(), maxWidth );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( area )
|
2021-02-23 21:52:33 +00:00
|
|
|
{
|
|
|
|
area->Inflate( maxWidth );
|
|
|
|
area = area->Intersect( VisibleViewArea() );
|
|
|
|
}
|
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:
|
2021-02-23 21:52:33 +00:00
|
|
|
optFlags |= OPTIMIZER::MERGE_OBTUSE;
|
2014-11-15 13:43:23 +00:00
|
|
|
n_passes = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OE_MEDIUM:
|
2021-02-23 21:52:33 +00:00
|
|
|
optFlags |= OPTIMIZER::MERGE_SEGMENTS;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2014-11-15 13:43:23 +00:00
|
|
|
n_passes = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OE_FULL:
|
2016-08-29 17:31:13 +00:00
|
|
|
optFlags = OPTIMIZER::MERGE_SEGMENTS;
|
2014-11-15 13:43:23 +00:00
|
|
|
n_passes = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
optFlags |= OPTIMIZER::LIMIT_CORNER_COUNT;
|
|
|
|
|
2021-02-23 21:52:33 +00:00
|
|
|
if( area )
|
2021-02-25 16:18:13 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
SHAPE_RECT r( *area );
|
|
|
|
|
|
|
|
PNS_DBG( Dbg(), AddShape, &r, BLUE, 0, wxT( "opt-area" ) );
|
2021-02-23 21:52:33 +00:00
|
|
|
|
2021-02-25 16:18:13 +00:00
|
|
|
optFlags |= OPTIMIZER::RESTRICT_AREA;
|
|
|
|
optimizer.SetRestrictArea( *area, false );
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( Settings().SmartPads() )
|
2016-08-29 17:31:13 +00:00
|
|
|
optFlags |= OPTIMIZER::SMART_PADS;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-11-21 21:56:26 +00:00
|
|
|
|
|
|
|
optimizer.SetEffortLevel( optFlags & ~m_optFlagDisableMask );
|
2016-08-29 17:31:13 +00:00
|
|
|
optimizer.SetCollisionMask( ITEM::ANY_T );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
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() );
|
|
|
|
|
2019-07-21 22:36:08 +00:00
|
|
|
for( LINE& line : m_optimizerQueue)
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
if( !( line.Marker() & MK_HEAD ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE optimized;
|
2021-04-26 22:27:30 +00:00
|
|
|
LINE* root = findRootLine( &line );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-04-26 22:27:30 +00:00
|
|
|
if( optimizer.Optimize( &line, &optimized, root ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-04-26 22:27:30 +00:00
|
|
|
replaceLine( line, optimized, false, aNode );
|
|
|
|
line = optimized; // keep links in the lines in the queue up to date
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* SHOVE::CurrentNode()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE SHOVE::NewHead() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void SHOVE::SetInitialLine( LINE& aInitial )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_root = m_root->Branch();
|
2016-08-30 17:01:30 +00:00
|
|
|
m_root->Remove( aInitial );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
|
|
|
|
bool SHOVE::AddLockedSpringbackNode( NODE* aNode )
|
|
|
|
{
|
|
|
|
SPRINGBACK_TAG sp;
|
|
|
|
sp.m_node = aNode;
|
|
|
|
sp.m_locked = true;
|
|
|
|
|
|
|
|
m_nodeStack.push_back(sp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SHOVE::RewindSpringbackTo( NODE* aNode )
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
auto iter = m_nodeStack.begin();
|
|
|
|
|
|
|
|
while( iter != m_nodeStack.end() )
|
|
|
|
{
|
|
|
|
if ( iter->m_node == aNode )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto start = iter;
|
|
|
|
|
|
|
|
aNode->KillChildren();
|
|
|
|
m_nodeStack.erase( start, m_nodeStack.end() );
|
|
|
|
|
|
|
|
return true;
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|
2020-02-07 19:57:24 +00:00
|
|
|
|
|
|
|
|
2021-11-09 05:00:54 +00:00
|
|
|
bool SHOVE::RewindToLastLockedNode()
|
|
|
|
{
|
|
|
|
if( m_nodeStack.empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
while( !m_nodeStack.back().m_locked && m_nodeStack.size() > 1 )
|
|
|
|
m_nodeStack.pop_back();
|
|
|
|
|
|
|
|
return m_nodeStack.back().m_locked;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
void SHOVE::UnlockSpringbackNode( NODE* aNode )
|
|
|
|
{
|
|
|
|
auto iter = m_nodeStack.begin();
|
|
|
|
|
|
|
|
while( iter != m_nodeStack.end() )
|
|
|
|
{
|
|
|
|
if ( iter->m_node == aNode )
|
|
|
|
{
|
|
|
|
iter->m_locked = false;
|
|
|
|
break;
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-21 21:56:26 +00:00
|
|
|
|
|
|
|
void SHOVE::DisablePostShoveOptimizations( int aMask )
|
|
|
|
{
|
|
|
|
m_optFlagDisableMask = aMask;
|
|
|
|
}
|
|
|
|
|
2021-12-15 00:32:05 +00:00
|
|
|
|
|
|
|
void SHOVE::SetSpringbackDoNotTouchNode( NODE *aNode )
|
|
|
|
{
|
|
|
|
m_springbackDoNotTouchNode = aNode;
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
}
|
|
|
|
|